From 890349c3d1ad29ff668a3ef7fd7c535ed9a876ef Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 24 Mar 2013 02:09:36 +0300 Subject: improve soundmanager class. --- src/resources/soundeffect.cpp | 3 ++- src/resources/soundeffect.h | 2 +- src/soundmanager.cpp | 32 +++++++++++++++++++++----------- src/soundmanager.h | 2 +- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/resources/soundeffect.cpp b/src/resources/soundeffect.cpp index 48772291b..2da3319e8 100644 --- a/src/resources/soundeffect.cpp +++ b/src/resources/soundeffect.cpp @@ -49,7 +49,8 @@ Resource *SoundEffect::load(SDL_RWops *const rw) } } -bool SoundEffect::play(const int loops, const int volume, const int channel) +bool SoundEffect::play(const int loops, const int volume, + const int channel) const { Mix_VolumeChunk(mChunk, volume); diff --git a/src/resources/soundeffect.h b/src/resources/soundeffect.h index 67c28591b..50ddd562d 100644 --- a/src/resources/soundeffect.h +++ b/src/resources/soundeffect.h @@ -63,7 +63,7 @@ class SoundEffect final : public Resource * false otherwise. */ virtual bool play(const int loops, const int volume, - const int channel = -1); + const int channel = -1) const; protected: /** diff --git a/src/soundmanager.cpp b/src/soundmanager.cpp index 62471f07d..6eca843cd 100644 --- a/src/soundmanager.cpp +++ b/src/soundmanager.cpp @@ -163,7 +163,6 @@ void SoundManager::init() void SoundManager::info() const { SDL_version compiledVersion; - const SDL_version *linkedVersion; char driver[40] = "Unknown"; const char *format = "Unknown"; int rate = 0; @@ -171,19 +170,30 @@ void SoundManager::info() const int channels = 0; MIX_VERSION(&compiledVersion); - linkedVersion = Mix_Linked_Version(); + const SDL_version *const linkedVersion = Mix_Linked_Version(); SDL_AudioDriverName(driver, 40); Mix_QuerySpec(&rate, &audioFormat, &channels); switch (audioFormat) { - case AUDIO_U8: format = "U8"; break; - case AUDIO_S8: format = "S8"; break; - case AUDIO_U16LSB: format = "U16LSB"; break; - case AUDIO_S16LSB: format = "S16LSB"; break; - case AUDIO_U16MSB: format = "U16MSB"; break; - case AUDIO_S16MSB: format = "S16MSB"; break; + case AUDIO_U8: + format = "U8"; + break; + case AUDIO_S8: + format = "S8"; break; + case AUDIO_U16LSB: + format = "U16LSB"; + break; + case AUDIO_S16LSB: + format = "S16LSB"; + break; + case AUDIO_U16MSB: + format = "U16MSB"; + break; + case AUDIO_S16MSB: + format = "S16MSB"; + break; default: break; } @@ -337,7 +347,7 @@ void SoundManager::playSfx(const std::string &path, else tmpPath = paths.getValue("sfx", "sfx/").append(path); ResourceManager *const resman = ResourceManager::getInstance(); - SoundEffect *const sample = resman->getSoundEffect(tmpPath); + const SoundEffect *const sample = resman->getSoundEffect(tmpPath); if (sample) { logger->log("SoundManager::playSfx() Playing: %s", path.c_str()); @@ -377,7 +387,7 @@ void SoundManager::playGuiSfx(const std::string &path) else tmpPath = paths.getValue("sfx", "sfx/").append(path); ResourceManager *const resman = ResourceManager::getInstance(); - SoundEffect *const sample = resman->getSoundEffect(tmpPath); + const SoundEffect *const sample = resman->getSoundEffect(tmpPath); if (sample) { logger->log("SoundManager::playGuiSfx() Playing: %s", path.c_str()); @@ -430,7 +440,7 @@ void SoundManager::volumeOff() const } } -void SoundManager::volumeRestore() +void SoundManager::volumeRestore() const { if (mInstalled) { diff --git a/src/soundmanager.h b/src/soundmanager.h index 710e357f1..32fe27fbc 100644 --- a/src/soundmanager.h +++ b/src/soundmanager.h @@ -133,7 +133,7 @@ class SoundManager final : public ConfigListener void volumeOff() const; - void volumeRestore(); + void volumeRestore() const; std::string getCurrentMusicFile() const A_WARN_UNUSED { return mCurrentMusicFile; } -- cgit v1.2.3-60-g2f50