 |
BARE2D
|
|
Go to the documentation of this file.
3 #include <SDL2/SDL_mixer.h>
40 int initedFlags = Mix_Init(MIX_INIT_FLAC | MIX_INIT_MOD | MIX_INIT_MP3 | MIX_INIT_OGG);
43 if(!(initedFlags & MIX_INIT_FLAC)) {
47 if(!(initedFlags & MIX_INIT_MOD)) {
51 if(!(initedFlags & MIX_INIT_MP3)) {
55 if(!(initedFlags & MIX_INIT_OGG)) {
65 Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024);
68 Mix_AllocateChannels(32);
75 unsigned int numTimesOpened;
78 numTimesOpened = Mix_QuerySpec(&dummyA, &dummyB, &dummyC);
80 if(numTimesOpened == 0) {
85 for(
unsigned int i = 0; i < numTimesOpened; i++)
100 channel = Mix_FadeInChannelTimed(-1, sound.
chunk, 0, fadeTime, timeOut);
104 channel = Mix_FadeInChannel(-1, sound.
chunk, 0, fadeTime);
108 channel = Mix_PlayChannelTimed(-1, sound.
chunk, 0, timeOut);
110 channel = Mix_PlayChannel(-1, sound.
chunk, 0);
116 return (
unsigned int)channel;
121 if(!Mix_SetPosition(soundID, angle,
distance)) {
129 Mix_FadeOutChannel(soundID, fadeTime);
131 Mix_HaltChannel(soundID);
150 error = Mix_FadeInMusic(music.
music, 0, fadeTime);
153 error = Mix_PlayMusic(music.
music, 0);
163 Mix_FadeOutMusic(fadeTime);
225 return Mix_PlayingMusic();
std::iterator_traits< octet_iterator >::difference_type distance(octet_iterator first, octet_iterator last)
void resumeMusic()
Resumes the paused music.
unsigned char m_masterVolume
void resumeSound(unsigned int &soundID)
Resumes a paused sound.
@ SDL_MIXER_SOUND_FAILURE
void playMusic(Music &music, unsigned int fadeTime=0)
Plays some music! Only one "music" can be played at a time.
static AudioManager * m_instance
void setMusicVolume(unsigned char volumeLevel)
Sets the volume level of all music.
@ SDL_MIXER_CLOSE_FAILURE
void setSoundVolume(unsigned char volumeLevel)
Sets the volume level of all sounds.
The AudioManager acts as a friendly wrapper for the SDL_Mixer library. It basically just plays sounds...
void pauseSound(unsigned int &soundID)
Pauses a sound.
void throwError(BAREError err, std::string message)
Throws an error silently. Adds it to the pile.
void init()
Initializes all necessary bits and pieces.
void pauseMusic()
Pauses the music.
void unmute()
Unmutes all sounds and music.
void stopSound(unsigned int &soundID, unsigned int fadeTime=0)
Stops a sound.
unsigned int playSound(Sound &sound, unsigned int fadeTime=0, unsigned int timeOut=0, int angle=0, unsigned char distance=128)
Plays a sound at a position.
static AudioManager * getInstance()
void setMasterVolumeModifier(unsigned char masterLevel)
Sets the modifier of all sound levels - eg., if sounds were set at 40% and music at 60%,...
void stopMusic(unsigned int fadeTime=0)
Stops the music.
unsigned char m_soundVolume
void mute()
Mutes all sounds and music.
void throwFatalError(BAREError err, std::string message)
Throws an error (fatal). Also calls displayErrors and exits the program.
void destroy()
Destroys/quits all necessary bits and pieces.
void moveSound(unsigned int &soundID, int angle, unsigned char distance=128)
Resets the sound's position for positional audio.
unsigned char m_musicVolume