-
-
Notifications
You must be signed in to change notification settings - Fork 29
Sound effects
Romain Milbert edited this page Feb 19, 2023
·
2 revisions
To use sound effects, you must use the SoundEffect
& SoundEffectSlot
types; the former will hold an effect's parameters, while the latter is used to apply an effect to any number of Sound
objects.
First, create a Sound as you would usually do:
#include <RaZ/Audio/Sound.hpp>
// ...
Raz::Sound& sound = entity.addComponent<Raz::Sound>(Raz::WavFormat::load("sound.wav"));
Next, we will need to use the classes mentioned above. First, let us create a SoundEffect which will apply a reverberation effect to our sound:
#include <RaZ/Audio/SoundEffect.hpp>
// ...
Raz::SoundEffect reverb;
// Creating a ReverberationParams object, which holds all parameters for our effect
Raz::ReverberationParams reverbParams {};
reverbParams.gain = 2.f; // Setting the reverb volume
reverb.load(reverbParams); // Applying the parameters to our sound effect
The SoundEffect is now ready to be used. We can finally create a SoundEffectSlot:
#include <RaZ/Audio/SoundEffectSlot.hpp>
// ...
Raz::SoundEffectSlot effectSlot;
effectSlot.loadEffect(reverb); // Loading the effect in the slot
// Finally, we can link the slot to our sound, which will instantly make it effective
sound.linkSlot(effectSlot);
// You can conversely unlink the slot to remove the effect from the sound
sound.unlinkSlot();
reverbParams.decayTime = 3.f;
reverb.load(reverbParams); // Reloading parameters
effectSlot.loadEffect(reverb); // Reapplying the effect to the slot
If the slot is still linked to the sound, the changes will be applied automatically.
- Home
- How to build RaZ
- Getting started
- General usage knowledge
- Some examples...
- Playground
- Tutorials
- File formats
- Modules
- Debug