

Definition at line 13 of file SDLSoundAgent.h.
Public Member Functions | |
| virtual int | playSound (Mix_Chunk *sound, int volume, int loops=0) |
| Play this sound. | |
| virtual void | playMusic (const Path &file, BaseMsg *finished) |
| Play music. | |
| virtual void | stopMusic () |
Protected Member Functions | |
| virtual void | own_init () |
| Init sound subsystem. | |
| virtual void | own_shutdown () |
| virtual void | setSoundVolume (int volume) |
| Set sound volume. | |
| virtual void | setMusicVolume (int volume) |
|
|
Init sound subsystem.
Reimplemented from SoundAgent. Definition at line 28 of file SDLSoundAgent.cpp. 00029 {
00030 m_music = NULL;
00031 m_soundVolume = MIX_MAX_VOLUME;
00032 if(SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) {
00033 throw SDLException(ExInfo("SDL_InitSubSystem"));
00034 }
00035
00036 int frequency =
00037 OptionAgent::agent()->getAsInt("sound_frequency", MIX_DEFAULT_FREQUENCY);
00038 if(Mix_OpenAudio(frequency, MIX_DEFAULT_FORMAT, 2, 1024) < 0) {
00039 throw MixException(ExInfo("Mix_OpenAudio"));
00040 }
00041 Mix_AllocateChannels(16);
00042
00043 SoundAgent::own_init();
00044 }
|
|
|
Reimplemented from BaseAgent. Definition at line 47 of file SDLSoundAgent.cpp. 00048 {
00049 stopMusic();
00050 Mix_CloseAudio();
00051 SDL_QuitSubSystem(SDL_INIT_AUDIO);
00052 }
|
|
||||||||||||
|
Play music.
Implements SoundAgent. Definition at line 112 of file SDLSoundAgent.cpp. 00114 {
00115 stopMusic();
00116
00117 int loops = -1;
00118 if (finished) {
00119 ms_finished = finished;
00120 loops = 1;
00121 }
00122
00123 m_music = Mix_LoadMUS(file.getNative().c_str());
00124 if (m_music && (0 == Mix_PlayMusic(m_music, loops))) {
00125 Mix_HookMusicFinished(musicFinished);
00126 }
00127 else {
00128 LOG_WARNING(ExInfo("cannot play music")
00129 .addInfo("music", file.getNative())
00130 .addInfo("Mix", Mix_GetError()));
00131 }
00132 }
|
|
||||||||||||||||
|
Play this sound.
Implements SoundAgent. Definition at line 64 of file SDLSoundAgent.cpp. 00065 {
00066 int channel = -1;
00067 if (sound) {
00068 channel = Mix_PlayChannel(-1, sound, loops);
00069 if (-1 == channel) {
00070 //NOTE: maybe there are too few open channels
00071 LOG_WARNING(ExInfo("cannot play sound")
00072 .addInfo("Mix", Mix_GetError()));
00073 }
00074 else {
00075 Mix_Volume(channel, m_soundVolume * volume / 100);
00076 }
00077 }
00078
00079 return channel;
00080 }
|
|
|
Implements SoundAgent. Definition at line 138 of file SDLSoundAgent.cpp. 00139 {
00140 Mix_VolumeMusic(MIX_MAX_VOLUME * volume / 100);
00141 }
|
|
|
Set sound volume. NOTE: all already running sound will get equals volume
Implements SoundAgent. Definition at line 89 of file SDLSoundAgent.cpp. 00090 {
00091 m_soundVolume = MIX_MAX_VOLUME * volume / 100;
00092 if (m_soundVolume > MIX_MAX_VOLUME) {
00093 m_soundVolume = MIX_MAX_VOLUME;
00094 }
00095 else if (m_soundVolume < 0) {
00096 m_soundVolume = 0;
00097 }
00098 Mix_Volume(-1, m_soundVolume);
00099 }
|
|
|
Implements SoundAgent. Definition at line 144 of file SDLSoundAgent.cpp. 00145 {
00146 if(Mix_PlayingMusic()) {
00147 Mix_HookMusicFinished(NULL);
00148 Mix_HaltMusic();
00149 }
00150 if (m_music) {
00151 Mix_FreeMusic(m_music);
00152 m_music = NULL;
00153 }
00154 if (ms_finished) {
00155 delete ms_finished;
00156 ms_finished = NULL;
00157 }
00158 }
|
1.4.2