From 02c991e5ea1ec93c8245157a3f174b547774a7e3 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 13 Mar 2021 14:58:50 -0500 Subject: Sound volume is controllable from settings menu #7 --- src/mixer.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/mixer.cpp') 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 @@ void Mixer::playSound(std::string_view filename) { Mix_Chunk* chunk = getChunkByFilename(std::string(filename)); - if (Mix_PlayChannel(-1, chunk, 0) == -1) { + int ret = Mix_PlayChannel(-1, chunk, 0); + if (ret == -1) { throw mix_error(); } + + Mix_Volume(ret, soundVolume_); } int Mixer::loopSound(std::string_view filename) { @@ -17,6 +20,8 @@ int Mixer::loopSound(std::string_view filename) { throw mix_error(); } + Mix_Volume(ret, soundVolume_); + return ret; } @@ -32,6 +37,11 @@ void Mixer::unpauseSounds() { Mix_Resume(-1); } +void Mixer::setSoundVolume(int vol) { + soundVolume_ = MIX_MAX_VOLUME / 10.0 * vol; + Mix_Volume(-1, soundVolume_); +} + void Mixer::playMusic(std::string_view name, int ms) { Mix_Music* song = getMusicByName(name); int ret; -- cgit 1.4.1