|
libSDL2pp
C++ bindings/wrapper for SDL2
|
Audio mixer. More...
#include <SDL2pp/Mixer.hh>
Public Member Functions | |
Construction and destruction | |
| Mixer (int frequency, Uint16 format, int channels, int chunksize) | |
| Construct a mixer and open an audio device. | |
| ~Mixer () | |
| Destructor. | |
Copy and move | |
| Mixer (Mixer &&other) noexcept | |
| Move constructor. | |
| Mixer & | operator= (Mixer &&other) noexcept |
| Move assignment operator. | |
| Mixer (const Mixer &other)=delete | |
| Deleted copy constructor. | |
| Mixer & | operator= (const Mixer &other)=delete |
| Deleted assignment operator. | |
Channels: setup | |
| int | AllocateChannels (int numchans) |
| Set the number of channels to mix. | |
| int | GetNumChannels () const |
| Get the number of channels being mixed. | |
| int | SetVolume (int channel, int volume) |
| Set the mix volume of a channel. | |
| int | GetVolume (int channel) const |
| Get the mix volume of a channel. | |
Channels: playing | |
| int | PlayChannel (int channel, const Chunk &chunk, int loops=0) |
| Play loop. | |
| int | PlayChannel (int channel, const Chunk &chunk, int loops, int ticks) |
| Play loop and limit by time. | |
| int | FadeInChannel (int channel, const Chunk &chunk, int loops, int ms) |
| Play loop with fade in. | |
| int | FadeInChannel (int channel, const Chunk &chunk, int loops, int ms, int ticks) |
| loop with fade in and limit by time | |
Channels: pausing | |
| void | PauseChannel (int channel=-1) |
| Pause a channel. | |
| void | ResumeChannel (int channel=-1) |
| Resume a paused channel. | |
Channels: stopping | |
| void | HaltChannel (int channel=-1) |
| Stop playing on a channel. | |
| int | ExpireChannel (int channel, int ticks) |
| Change the timed stoppage of a channel. | |
| int | FadeOutChannel (int channel, int ms) |
| Stop playing channel after timed fade out. | |
| void | SetChannelFinishedHandler (ChannelFinishedHandler channel_finished) |
| Set callback for when channel finishes playing. | |
| void | RemoveChannelFinishedHandler () |
| Remove callback for when channel finishes playing. | |
Channels: info | |
| int | IsChannelPlaying (int channel) const |
| Get the active playing status of a channel. | |
| int | IsChannelPaused (int channel) const |
| Get the pause status of a channel. | |
| Mix_Fading | GetChannelFading (int which) const |
| Get the fade status of a channel. | |
Groups: setup | |
| int | ReserveChannels (int num) |
| Prevent channels from being used in default group. | |
| void | GroupChannel (int which, int tag) |
| Add/remove channel to/from group. | |
| void | GroupChannels (int from, int to, int tag) |
| Add/remove segment of channels to/from group. | |
Groups: info | |
| int | GetGroupNumChannels (int tag) const |
| Get number of channels in group. | |
| int | GetGroupAvailableChannel (int tag) const |
| Get first inactive channel in group. | |
| int | GetGroupOldestChannel (int tag) const |
| Get oldest busy channel in group. | |
| int | GetGroupNewestChannel (int tag) const |
| Get youngest busy channel in group. | |
Groups: stopping | |
| int | FadeOutGroup (int tag, int ms) |
| Fade out a group over time. | |
| void | HaltGroup (int tag) |
| Stop a group. | |
Music: playing | |
| void | PlayMusic (const Music &music, int loops=-1) |
| Play music. | |
| void | FadeInMusic (const Music &music, int loops=-1, int ms=0) |
| Play music, with looping, and fade in. | |
| void | SetMusicHook (MusicHook &&hook) |
| Hook for a custom music player. | |
Music: settings | |
| int | SetMusicVolume (int volume) |
| Set music volume. | |
| int | GetMusicVolume () const |
| Get music volume. | |
| void | PauseMusic () |
| Pause music. | |
| void | ResumeMusic () |
| Resume paused music. | |
| void | RewindMusic () |
| Rewind music to beginning. | |
| void | SetMusicPosition (double position) |
| Set position of playback in stream. | |
Music: stopping | |
| void | HaltMusic () |
| Stop music playback. | |
| bool | FadeOutMusic (int ms) |
| Stop music, with fade out. | |
| void | SetMusicFinishedHandler (MusicFinishedHandler music_finished) |
| Set a callback for when music stops. | |
| void | RemoveMusicFinishedHandler () |
| Remove a callback for when music stops. | |
Music: info | |
| bool | IsMusicPlaying () const |
| Test whether music is playing. | |
| bool | IsMusicPaused () const |
| Test whether music is paused. | |
| Mix_Fading | GetMusicFading () const |
| Get status of current music fade activity. | |
Effects | |
| void | SetPanning (int channel, Uint8 left, Uint8 right) |
| Stereo panning. | |
| void | UnsetPanning (int channel) |
| Disable stereo panning. | |
| void | SetDistance (int channel, Uint8 distance) |
| Distance attenuation (volume) | |
| void | UnsetDistance (int channel) |
| Disable distance attenuation. | |
| void | SetPosition (int channel, Sint16 angle, Uint8 distance) |
| Panning (angular) and distance. | |
| void | UnsetPosition (int channel) |
| Disable panning and distance. | |
| void | SetReverseStereo (int channel) |
| Swap stereo left and right. | |
| void | UnsetReverseStereo (int channel) |
| Disable stereo swapping. | |
Audio mixer.
This class represents open SDL_mixer audio device. Object of this class must be constructed before calling any other mixer functions.
| SDL2pp::Mixer::Mixer | ( | int | frequency, |
| Uint16 | format, | ||
| int | channels, | ||
| int | chunksize | ||
| ) |
Construct a mixer and open an audio device.
| [in] | frequency | Output sampling frequency in samples per second (Hz). You might use MIX_DEFAULT_FREQUENCY(22050) since that is a good value for most games |
| [in] | format | Output sample format |
| [in] | channels | Number of sound channels in output. Set to 2 for stereo, 1 for mono. This has nothing to do with mixing channels |
| [in] | chunksize | Bytes used per output sample |
| SDL2pp::Exception |
| SDL2pp::Mixer::~Mixer | ( | ) |
Destructor.
|
noexcept |
Move constructor.
| [in] | other | SDL2pp::Mixer object to move data from |
|
delete |
Deleted copy constructor.
This class is not copyable
| int SDL2pp::Mixer::AllocateChannels | ( | int | numchans | ) |
Set the number of channels to mix.
| [in] | numchans | Number of channels to allocate for mixing |
| int SDL2pp::Mixer::ExpireChannel | ( | int | channel, |
| int | ticks | ||
| ) |
Change the timed stoppage of a channel.
| [in] | channel | Channel to stop playing, or -1 for all channels |
| [in] | ticks | Millisecons until channel(s) halt playback |
| int SDL2pp::Mixer::FadeInChannel | ( | int | channel, |
| const Chunk & | chunk, | ||
| int | loops, | ||
| int | ms | ||
| ) |
Play loop with fade in.
| [in] | channel | Channel to play on, or -1 for the first free unreserved channel |
| [in] | chunk | Sample to play |
| [in] | loops | Number of loops, -1 is infinite loops. Passing one here plays the sample twice (1 loop). |
| [in] | ms | Milliseconds of time that the fade-in effect should take to go from silence to full volume |
| SDL2pp::Exception |
| int SDL2pp::Mixer::FadeInChannel | ( | int | channel, |
| const Chunk & | chunk, | ||
| int | loops, | ||
| int | ms, | ||
| int | ticks | ||
| ) |
loop with fade in and limit by time
| [in] | channel | Channel to play on, or -1 for the first free unreserved channel |
| [in] | chunk | Sample to play |
| [in] | loops | Number of loops, -1 is infinite loops. Passing one here plays the sample twice (1 loop). |
| [in] | ms | Milliseconds of time that the fade-in effect should take to go from silence to full volume |
| [in] | ticks | Millisecond limit to play sample, at most. If not enough loops or the sample chunk is not long enough, then the sample may stop before this timeout occurs. -1 means play forever |
| SDL2pp::Exception |
| void SDL2pp::Mixer::FadeInMusic | ( | const Music & | music, |
| int | loops = -1, |
||
| int | ms = 0 |
||
| ) |
Play music, with looping, and fade in.
| [in] | music | Music to play |
| [in] | loops | number of times to play through the music. 0 plays the music zero times... -1 plays the music forever |
| [in] | ms | Milliseconds for the fade-in effect to complete |
| int SDL2pp::Mixer::FadeOutChannel | ( | int | channel, |
| int | ms | ||
| ) |
Stop playing channel after timed fade out.
| [in] | channel | Channel to fade out, or -1 to fade all channels out |
| [in] | ms | Milliseconds of time that the fade-out effect should take to go to silence, starting now |
| int SDL2pp::Mixer::FadeOutGroup | ( | int | tag, |
| int | ms | ||
| ) |
Fade out a group over time.
| [in] | tag | Group to fade out |
| [in] | ms | Milliseconds of time that the fade-out effect should take to go to silence, starting now |
| bool SDL2pp::Mixer::FadeOutMusic | ( | int | ms | ) |
Stop music, with fade out.
| [in] | ms | Milliseconds of time that the fade-out effect should take to go to silence, starting now. |
| Mix_Fading SDL2pp::Mixer::GetChannelFading | ( | int | which | ) | const |
Get the fade status of a channel.
| [in] | which | Channel to get the fade activity status from |
| int SDL2pp::Mixer::GetGroupAvailableChannel | ( | int | tag | ) | const |
Get first inactive channel in group.
| [in] | tag | A group number |
| int SDL2pp::Mixer::GetGroupNewestChannel | ( | int | tag | ) | const |
Get youngest busy channel in group.
| [in] | tag | A group number |
| int SDL2pp::Mixer::GetGroupNumChannels | ( | int | tag | ) | const |
Get number of channels in group.
| [in] | tag | A group number |
| int SDL2pp::Mixer::GetGroupOldestChannel | ( | int | tag | ) | const |
Get oldest busy channel in group.
| [in] | tag | A group number |
| Mix_Fading SDL2pp::Mixer::GetMusicFading | ( | ) | const |
Get status of current music fade activity.
| int SDL2pp::Mixer::GetMusicVolume | ( | ) | const |
Get music volume.
| int SDL2pp::Mixer::GetNumChannels | ( | ) | const |
Get the number of channels being mixed.
| int SDL2pp::Mixer::GetVolume | ( | int | channel | ) | const |
Get the mix volume of a channel.
| [in] | channel | Channel to set mix volume for. -1 will return the average volume. |
| void SDL2pp::Mixer::GroupChannel | ( | int | which, |
| int | tag | ||
| ) |
Add/remove channel to/from group.
| [in] | which | Channel number to assign tag to. |
| [in] | tag | A group number. Any positive numbers (including zero). -1 is the default group. Use -1 to remove a group tag essentially. |
| SDL2pp::Exception |
| void SDL2pp::Mixer::GroupChannels | ( | int | from, |
| int | to, | ||
| int | tag | ||
| ) |
Add/remove segment of channels to/from group.
| [in] | from | First Channel number of channels to assign tag to. |
| [in] | to | Last Channel number of channels to assign tag to |
| [in] | tag | A group number. Any positive numbers (including zero). -1 is the default group. Use -1 to remove a group tag essentially. |
| SDL2pp::Exception |
| void SDL2pp::Mixer::HaltChannel | ( | int | channel = -1 | ) |
Stop playing on a channel.
| [in] | channel | Channel to stop playing, or -1 for all channels |
| void SDL2pp::Mixer::HaltGroup | ( | int | tag | ) |
Stop a group.
| [in] | tag | Group to fade out |
| void SDL2pp::Mixer::HaltMusic | ( | ) |
Stop music playback.
| int SDL2pp::Mixer::IsChannelPaused | ( | int | channel | ) | const |
Get the pause status of a channel.
| [in] | channel | Channel to test whether it is paused or not. -1 will tell you how many channels are playing |
| int SDL2pp::Mixer::IsChannelPlaying | ( | int | channel | ) | const |
Get the active playing status of a channel.
| [in] | channel | Channel to test whether it is playing or not. -1 will tell you how many channels are playing |
| bool SDL2pp::Mixer::IsMusicPaused | ( | ) | const |
Test whether music is paused.
| bool SDL2pp::Mixer::IsMusicPlaying | ( | ) | const |
Test whether music is playing.
Deleted assignment operator.
This class is not copyable
Move assignment operator.
| [in] | other | SDL2pp::Mixer object to move data from |
| void SDL2pp::Mixer::PauseChannel | ( | int | channel = -1 | ) |
Pause a channel.
| [in] | channel | Channel to pause on, or -1 for all channels |
| void SDL2pp::Mixer::PauseMusic | ( | ) |
Pause music.
| int SDL2pp::Mixer::PlayChannel | ( | int | channel, |
| const Chunk & | chunk, | ||
| int | loops, | ||
| int | ticks | ||
| ) |
Play loop and limit by time.
| [in] | channel | Channel to play on, or -1 for the first free unreserved channel |
| [in] | chunk | Sample to play |
| [in] | loops | Number of loops, -1 is infinite loops. Passing one here plays the sample twice (1 loop). |
| [in] | ticks | Millisecond limit to play sample, at most. If not enough loops or the sample chunk is not long enough, then the sample may stop before this timeout occurs. -1 means play forever |
| SDL2pp::Exception |
| int SDL2pp::Mixer::PlayChannel | ( | int | channel, |
| const Chunk & | chunk, | ||
| int | loops = 0 |
||
| ) |
Play loop.
| [in] | channel | Channel to play on, or -1 for the first free unreserved channel |
| [in] | chunk | Sample to play |
| [in] | loops | Number of loops, -1 is infinite loops. Passing one here plays the sample twice (1 loop). |
| SDL2pp::Exception |
| void SDL2pp::Mixer::PlayMusic | ( | const Music & | music, |
| int | loops = -1 |
||
| ) |
Play music.
| [in] | music | Music to play |
| [in] | loops | number of times to play through the music. 0 plays the music zero times... -1 plays the music forever |
| void SDL2pp::Mixer::RemoveChannelFinishedHandler | ( | ) |
Remove callback for when channel finishes playing.
| void SDL2pp::Mixer::RemoveMusicFinishedHandler | ( | ) |
Remove a callback for when music stops.
| int SDL2pp::Mixer::ReserveChannels | ( | int | num | ) |
Prevent channels from being used in default group.
| [in] | num | Number of channels to reserve from default mixing. Zero removes all reservations |
| void SDL2pp::Mixer::ResumeChannel | ( | int | channel = -1 | ) |
Resume a paused channel.
| [in] | channel | Channel to resume playing, or -1 for all channels |
| void SDL2pp::Mixer::ResumeMusic | ( | ) |
Resume paused music.
| void SDL2pp::Mixer::RewindMusic | ( | ) |
Rewind music to beginning.
| void SDL2pp::Mixer::SetChannelFinishedHandler | ( | ChannelFinishedHandler | channel_finished | ) |
Set callback for when channel finishes playing.
| [in] | channel_finished | Function to call when any channel finishes playback |
| void SDL2pp::Mixer::SetDistance | ( | int | channel, |
| Uint8 | distance | ||
| ) |
Distance attenuation (volume)
| [in] | channel | Channel number to register this effect on or MIX_CHANNEL_POST to process the postmix stream |
| [in] | distance | Specify the distance from the listener, from 0 (close/loud) to 255 (far/quiet) |
| SDL2pp::Exception |
| void SDL2pp::Mixer::SetMusicFinishedHandler | ( | MusicFinishedHandler | music_finished | ) |
Set a callback for when music stops.
| [in] | music_finished | Function to call when music stops |
| void SDL2pp::Mixer::SetMusicHook | ( | MusicHook && | hook | ) |
Hook for a custom music player.
| [in] | hook | Music player mixer function |
| void SDL2pp::Mixer::SetMusicPosition | ( | double | position | ) |
Set position of playback in stream.
| [in] | position | Posistion to play from |
| int SDL2pp::Mixer::SetMusicVolume | ( | int | volume | ) |
Set music volume.
| [in] | volume | The volume to use from 0 to MIX_MAX_VOLUME(128) |
| void SDL2pp::Mixer::SetPanning | ( | int | channel, |
| Uint8 | left, | ||
| Uint8 | right | ||
| ) |
Stereo panning.
| [in] | channel | Channel number to register this effect on or MIX_CHANNEL_POST to process the postmix stream |
| [in] | left | Volume for the left channel, range is 0 (silence) to 255 (loud) |
| [in] | right | Volume for the right channel, range is 0 (silence) to 255 (loud) |
| SDL2pp::Exception |
| void SDL2pp::Mixer::SetPosition | ( | int | channel, |
| Sint16 | angle, | ||
| Uint8 | distance | ||
| ) |
Panning (angular) and distance.
| [in] | channel | Channel number to register this effect on or MIX_CHANNEL_POST to process the postmix stream |
| [in] | angle | Direction in relation to forward from 0 to 360 degrees. Larger angles will be reduced to this range using angles % 360. 0 = directly in front, 90 = directly to the right etc. |
| [in] | distance | Specify the distance from the listener, from 0 (close/loud) to 255 (far/quiet) |
| SDL2pp::Exception |
| void SDL2pp::Mixer::SetReverseStereo | ( | int | channel | ) |
Swap stereo left and right.
| [in] | channel | Channel number to register this effect on or MIX_CHANNEL_POST to process the postmix stream |
| SDL2pp::Exception |
| int SDL2pp::Mixer::SetVolume | ( | int | channel, |
| int | volume | ||
| ) |
Set the mix volume of a channel.
| [in] | channel | Channel to set mix volume for. -1 will set the volume for all allocated channels. |
| [in] | volume | The volume to use from 0 to MIX_MAX_VOLUME(128) |
| void SDL2pp::Mixer::UnsetDistance | ( | int | channel | ) |
Disable distance attenuation.
| [in] | channel | Channel number to unregister this effect from or MIX_CHANNEL_POST to unregister from the postmix stream |
| SDL2pp::Exception |
| void SDL2pp::Mixer::UnsetPanning | ( | int | channel | ) |
Disable stereo panning.
| [in] | channel | Channel number to unregister this effect from or MIX_CHANNEL_POST to unregister from the postmix stream |
| SDL2pp::Exception |
| void SDL2pp::Mixer::UnsetPosition | ( | int | channel | ) |
Disable panning and distance.
| [in] | channel | Channel number to unregister this effect from or MIX_CHANNEL_POST to unregister from the postmix stream |
| SDL2pp::Exception |
| void SDL2pp::Mixer::UnsetReverseStereo | ( | int | channel | ) |
Disable stereo swapping.
| [in] | channel | Channel number to unregister this effect from or MIX_CHANNEL_POST to unregister from the postmix stream |
| SDL2pp::Exception |