summary refs log tree commit diff stats
path: root/src/mixer.cpp
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2021-03-13 14:58:50 -0500
committerStar Rauchenberger <fefferburbia@gmail.com>2021-03-13 15:34:50 -0500
commit02c991e5ea1ec93c8245157a3f174b547774a7e3 (patch)
treea975df9e5bfa51a7910a4e6e3cccaadd991a0ec1 /src/mixer.cpp
parent255bb9ce381eeb0989a5b8efb3d41c88a0f2c642 (diff)
downloadtanetane-02c991e5ea1ec93c8245157a3f174b547774a7e3.tar.gz
tanetane-02c991e5ea1ec93c8245157a3f174b547774a7e3.tar.bz2
tanetane-02c991e5ea1ec93c8245157a3f174b547774a7e3.zip
Sound volume is controllable from settings menu
#7
Diffstat (limited to 'src/mixer.cpp')
-rw-r--r--src/mixer.cpp12
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 @@
4void Mixer::playSound(std::string_view filename) { 4void 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
12int Mixer::loopSound(std::string_view filename) { 15int 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
40void Mixer::setSoundVolume(int vol) {
41 soundVolume_ = MIX_MAX_VOLUME / 10.0 * vol;
42 Mix_Volume(-1, soundVolume_);
43}
44
35void Mixer::playMusic(std::string_view name, int ms) { 45void 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;