YSE sound engine
1.0
cross platform sound engine
|
A sound object is needed for every kind of sound you want to use.
Sounds can use audio files (wav, ogg, flac, and more on some systems) or can be linked to a DSP source. Sounds can be mono, stereo or multichannel.
If a soundfile is streamed, it will use its own soundbuffer. Otherwise YSE will create a new buffer only if needed or re-use and existing buffer if another file with the same filename has already been loaded. Unloading of soundfiles and clearing memory is done internally: when a buffer is not used by any sound any more, it will be flagged for deletion.
Definition at line 36 of file soundInterface.hpp.
interfaceObject& YSE::SOUND::interfaceObject::create | ( | const char * | fileName, |
channel * | ch = nullptr , |
||
Bool | loop = false , |
||
Flt | volume = 1.0f , |
||
Bool | streaming = false |
||
) |
Create a filebased sound and register it with the soundsystem.
Other functions will not work as long as a sound hasn't been created. In debug mode, an assertion will be called if you try to do so. On the other hand, create cannot be called twice. If you need another sound, create a new sound object.
fileName | This can be an absolute path or something relative to the working directory. |
channel | The sound channel you want to attach the sound to. Sounds can be moved to other channels at any time. If no channel is provided, the sound will be added to the global channel (mainMix). |
loop | Use true to loop this sound continuously. If not provided, the sound will not loop. |
volume | The initial volume to play this sound. This should be a value between 0.0 and 1.0. Default is 1.0. |
streaming | Whether or not this sound should be streamed. Defaults to false. Streaming is mainly intended for big audio files that are only used by a single sound. When a sound is used repeatedly, avoid streaming. |
interfaceObject& YSE::SOUND::interfaceObject::create | ( | DSP::dspSourceObject & | dsp, |
channel * | ch = nullptr , |
||
Flt | volume = 1.0f |
||
) |
Create a DSP sound and register it with the soundsystem.
In contrast to a filebased sound, the source if this soundobject will be generated by a dspSourceObject you provide yourself.
dsp | You provide a reference to an object for sound generation. Such objects must be based on dspSourceOBject. |
channel | The channel to attach the sound to. If no channel is provided, the sound will be added to the global channel (mainMix). |
volume | The volume at which to start playing this sound. |
interfaceObject& YSE::SOUND::interfaceObject::create | ( | SYNTH::interfaceObject & | synth, |
channel * | ch = nullptr , |
||
Flt | volume = 1.0f |
||
) |
Registers a synth with the soundsystem.
In contrast to a filebased sound, the source if this soundobject will be generated by a synth you provide yourself.
synth | You provide a reference to an synth for sound generation. |
channel | The channel to attach the sound to. If no channel is provided, the sound will be added to the global channel (mainMix). |
volume | The volume at which to start playing this sound. |
interfaceObject& YSE::SOUND::interfaceObject::setSpread | ( | Flt | value | ) |
This is only useful for multichannel sounds.
If a sound has more than one channel, the channels can be spread out over the stereo or surround field. This defines how much space there is between the position of the channels.
interfaceObject& YSE::SOUND::interfaceObject::setSpeed | ( | Flt | value | ) |
The speed at which a sound plays back alters it's pitch.
The actual speed will also be affected by velocity (doppler effect) unless doppler is disabled.
Internally this value will never be set entirely to zero, because that would result in static output that might damage speakers.
A negative value is also possible and will result in the sound being played backwards. Streaming sounds will not be played backwards though, because this would require an insane amount of disk activity. (This might change later on because SSD disks do not suffer from this.
interfaceObject& YSE::SOUND::interfaceObject::setSize | ( | Flt | value | ) |
Set the 'size' of the sound.
This defines from how far away in the virtual space a sound will be heard.
Flt YSE::SOUND::interfaceObject::getSize | ( | ) |
Returns the current size of the sound, ie.
how far away it will be heard.
interfaceObject& YSE::SOUND::interfaceObject::setLooping | ( | Bool | value | ) |
Set if this sound is looping or one-shot.
Should be obvious, right?
interfaceObject& YSE::SOUND::interfaceObject::setVolume | ( | Flt | value, |
UInt | time = 0 |
||
) |
Sets the volume for this sound.
You can use this as a fader by supplying a time value.
value | The target volume. |
time | If supplied, do a smooth change to the target volume over 'time' milliseconds. (Default is 0.) |
Flt YSE::SOUND::interfaceObject::getVolume | ( | ) |
Get the current volume.
This can be different from the current target volume if a time has been supplied when setVolume() is used.
interfaceObject& YSE::SOUND::interfaceObject::fadeAndStop | ( | UInt | time | ) |
Fadeout the over 'time' milliseconds.
Then stop the sound.
interfaceObject& YSE::SOUND::interfaceObject::pause | ( | ) |
Pause this sound.
Starting it again will continue from the current position.
interfaceObject& YSE::SOUND::interfaceObject::stop | ( | ) |
Stop this sound.
The position in the source file will be reset to zero. If started again, the sound will start from the beginning.
interfaceObject& YSE::SOUND::interfaceObject::setTime | ( | Flt | value | ) |
Set the current plahing position in the file.
Don't get confused here with setPosition, which sets the position in the virtual space where the sound will be rendered.
value | The new position in samples. Must be between 0 and the length of the file. |
Flt YSE::SOUND::interfaceObject::getTime | ( | ) |
Get the current playing position in the file.
Don't get confused here with getPosition, which gets the position in the virtual space where the sound will be rendered.
UInt YSE::SOUND::interfaceObject::getLength | ( | ) |
Get the length of the file.
interfaceObject& YSE::SOUND::interfaceObject::setRelative | ( | Bool | value | ) |
Make a sound relative to the Listener() object.
This is YSE's alternative to '2D' sounds. Relative sounds can still move, but they move along with the player. By default this is how Gui sounds and music are used in most gaming sound setups.
But there's more: by making the sounds relative instead of fixed, you can still to other stuff with them. The sound can still be moving.
interfaceObject& YSE::SOUND::interfaceObject::setDoppler | ( | Bool | value | ) |
Enable / disable doppler for this sound.
Bool YSE::SOUND::interfaceObject::isReady | ( | ) |
Will be true if the sound is ready to be played (or if it is already playing).
This can take a while if a sound is not streaming because loading sounds into memory is done in a seperate time as not to obstruct the audio callback. Not that it is not needed to wait for this result to be true before you can use most other functions with this sound. For instance, if you use the play() function, the sound will be played when it becomes ready.
interfaceObject& YSE::SOUND::interfaceObject::setOcclusion | ( | Bool | value | ) |
This will enable sound occlusion for this sound.
Remember to setup an occlusion callback function in System() first.
interfaceObject& YSE::SOUND::interfaceObject::moveTo | ( | channel & | target | ) |
Moves the sound to another channel.
target | The target channel |