diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-03-16 00:18:26 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-03-16 00:18:26 +0000 |
commit | f8e5e4afaa9e4299ade0a3892fa213a8ed29cb6c (patch) | |
tree | 5e0efba496efa0474bc2de9fc96baea7a63bc992 /src/sound.cpp | |
parent | 020ae4ba6537fdce87209f07ea21cc002aaa52ba (diff) | |
download | mana-client-f8e5e4afaa9e4299ade0a3892fa213a8ed29cb6c.tar.gz mana-client-f8e5e4afaa9e4299ade0a3892fa213a8ed29cb6c.tar.bz2 mana-client-f8e5e4afaa9e4299ade0a3892fa213a8ed29cb6c.tar.xz mana-client-f8e5e4afaa9e4299ade0a3892fa213a8ed29cb6c.zip |
Advanced version to 0.0.11, updated desert tilesets and made sound code log a
bit more.
Diffstat (limited to 'src/sound.cpp')
-rw-r--r-- | src/sound.cpp | 54 |
1 files changed, 18 insertions, 36 deletions
diff --git a/src/sound.cpp b/src/sound.cpp index 6e2c19fe..74222c8c 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -24,10 +24,6 @@ #include "sound.h" #include "log.h" -#ifdef __DEBUG -#include <iostream> -#endif - void Sound::init(int voices, int mod_voices) { // Don't initialize sound engine twice @@ -39,9 +35,10 @@ void Sound::init(int voices, int mod_voices) int audio_channels = 2; int audio_buffers = 4096; - if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)) { + if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)) + { #ifndef __DEBUG - throw("Unable to open audio device!\n"); + throw("Unable to open audio device!"); #else throw(Mix_GetError()); #endif @@ -58,10 +55,9 @@ void Sound::init(int voices, int mod_voices) void Sound::setVolume(int music) { - if (isOk == -1) - return; + if (isOk == -1) return; - if (isMaxVol(music) == false) { + if (!isMaxVol(music)) { vol_music = music; Mix_VolumeMusic(vol_music); } @@ -69,8 +65,7 @@ void Sound::setVolume(int music) void Sound::adjustVolume(int amusic) { - if (isOk == -1) - return; + if (isOk == -1) return; if (!isMaxVol(vol_music + amusic)) { vol_music += amusic; @@ -78,31 +73,25 @@ void Sound::adjustVolume(int amusic) } } -void Sound::startBgm(char * in, int loop) +void Sound::startBgm(char *in, int loop) { - if (isOk == -1) - return; + if (isOk == -1) return; if (bgm != NULL) { stopBgm(); } + log("Sound::startBgm() playing \"%s\" %d times", in, loop); + bgm = Mix_LoadMUS(in); Mix_PlayMusic(bgm, loop); -#ifdef __DEBUG - std::cout << "Sound::startBgm() Playing \"" << in << "\" " << loop << " times\n"; -#endif } void Sound::stopBgm() { - if (isOk == -1) { - return; - } + if (isOk == -1) return; -#ifdef __DEBUG - std::cout << "Sound::stopBgm()\n"; -#endif + log("Sound::stopBgm()"); if (bgm != NULL) { Mix_HaltMusic(); @@ -113,15 +102,12 @@ void Sound::stopBgm() SOUND_SID Sound::loadItem(char *fpath) { -#ifdef __DEBUG - std::cout << "Sound::loadItem() precaching \"" << fpath << "\"\n"; -#endif + log("Sound::loadItem() precaching \"%s\"", fpath); + Mix_Chunk *newItem; if ((newItem = Mix_LoadWAV(fpath))) { soundpool[++items] = newItem; -#ifdef __DEBUG - std::cout << "Sound::loadItem() success SOUND_SID = " << items << std::endl; -#endif + log("Sound::loadItem() success SOUND_SID = %d", items); return items; } @@ -131,9 +117,7 @@ SOUND_SID Sound::loadItem(char *fpath) void Sound::startItem(SOUND_SID id, int volume) { if (soundpool[id]) { -#ifdef __DEBUG - std::cout << "Sound::startItem() playing SOUND_SID = " << id << std::endl; -#endif + log("Sound::startItem() playing SOUND_SID = %d", id); Mix_VolumeChunk(soundpool[id], volume); Mix_PlayChannel(-1, soundpool[id], 0); } @@ -141,15 +125,13 @@ void Sound::startItem(SOUND_SID id, int volume) void Sound::clearCache() { - for(SOUND_SID i = 0; i == items; i++) { + for (SOUND_SID i = 0; i == items; i++) { Mix_FreeChunk(soundpool[i]); soundpool[i] = NULL; } soundpool.clear(); -#ifdef __DEBUG - std::cout << "Sound::clearCache() wiped all items off the cache\n"; -#endif + log("Sound::clearCache() wiped all items off the cache"); } void Sound::close() |