diff options
Diffstat (limited to 'src/mixer.cpp')
| -rw-r--r-- | src/mixer.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
| diff --git a/src/mixer.cpp b/src/mixer.cpp index 74a870a..6071fca 100644 --- a/src/mixer.cpp +++ b/src/mixer.cpp | |||
| @@ -4,9 +4,12 @@ | |||
| 4 | void Mixer::playSound(std::string_view filename) { | 4 | void Mixer::playSound(std::string_view filename) { |
| 5 | Mix_Chunk* chunk = getChunkByFilename(std::string(filename)); | 5 | Mix_Chunk* chunk = getChunkByFilename(std::string(filename)); |
| 6 | 6 | ||
| 7 | if (Mix_PlayChannel(-1, chunk, 0) == -1) { | 7 | int ret = Mix_PlayChannel(-1, chunk, 0); |
| 8 | if (ret == -1) { | ||
| 8 | throw mix_error(); | 9 | throw mix_error(); |
| 9 | } | 10 | } |
| 11 | |||
| 12 | Mix_Volume(ret, soundVolume_); | ||
| 10 | } | 13 | } |
| 11 | 14 | ||
| 12 | int Mixer::loopSound(std::string_view filename) { | 15 | int Mixer::loopSound(std::string_view filename) { |
| @@ -17,6 +20,8 @@ int Mixer::loopSound(std::string_view filename) { | |||
| 17 | throw mix_error(); | 20 | throw mix_error(); |
| 18 | } | 21 | } |
| 19 | 22 | ||
| 23 | Mix_Volume(ret, soundVolume_); | ||
| 24 | |||
| 20 | return ret; | 25 | return ret; |
| 21 | } | 26 | } |
| 22 | 27 | ||
| @@ -32,6 +37,11 @@ void Mixer::unpauseSounds() { | |||
| 32 | Mix_Resume(-1); | 37 | Mix_Resume(-1); |
| 33 | } | 38 | } |
| 34 | 39 | ||
| 40 | void Mixer::setSoundVolume(int vol) { | ||
| 41 | soundVolume_ = MIX_MAX_VOLUME / 10.0 * vol; | ||
| 42 | Mix_Volume(-1, soundVolume_); | ||
| 43 | } | ||
| 44 | |||
| 35 | void Mixer::playMusic(std::string_view name, int ms) { | 45 | void Mixer::playMusic(std::string_view name, int ms) { |
| 36 | Mix_Music* song = getMusicByName(name); | 46 | Mix_Music* song = getMusicByName(name); |
| 37 | int ret; | 47 | int ret; |
