diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2021-02-03 17:11:46 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2021-02-03 17:11:46 -0500 |
commit | dab96b810691c26e29fef92d88c828a311be3e9d (patch) | |
tree | e906b10f8dbca817e2b65bd14469226c2717a05a /src/mixer.cpp | |
parent | c54dd4fd583f1d00d424590a9f192b2a35ede26b (diff) | |
download | tanetane-dab96b810691c26e29fef92d88c828a311be3e9d.tar.gz tanetane-dab96b810691c26e29fef92d88c828a311be3e9d.tar.bz2 tanetane-dab96b810691c26e29fef92d88c828a311be3e9d.zip |
Added running sounds
Diffstat (limited to 'src/mixer.cpp')
-rw-r--r-- | src/mixer.cpp | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/src/mixer.cpp b/src/mixer.cpp index bfbedcd..bdcb7ce 100644 --- a/src/mixer.cpp +++ b/src/mixer.cpp | |||
@@ -1,6 +1,29 @@ | |||
1 | #include "mixer.h" | 1 | #include "mixer.h" |
2 | 2 | ||
3 | void Mixer::playSound(std::string filename) { | 3 | void Mixer::playSound(std::string_view filename) { |
4 | Mix_Chunk* chunk = getChunkByFilename(std::string(filename)); | ||
5 | |||
6 | if (Mix_PlayChannel(-1, chunk, 0) == -1) { | ||
7 | throw mix_error(); | ||
8 | } | ||
9 | } | ||
10 | |||
11 | int Mixer::loopSound(std::string_view filename) { | ||
12 | Mix_Chunk* chunk = getChunkByFilename(std::string(filename)); | ||
13 | |||
14 | int ret = Mix_PlayChannel(-1, chunk, -1); | ||
15 | if (ret == -1) { | ||
16 | throw mix_error(); | ||
17 | } | ||
18 | |||
19 | return ret; | ||
20 | } | ||
21 | |||
22 | void Mixer::stopChannel(int channel) { | ||
23 | Mix_HaltChannel(channel); | ||
24 | } | ||
25 | |||
26 | Mix_Chunk* Mixer::getChunkByFilename(std::string filename) { | ||
4 | if (!sounds_.count(filename)) { | 27 | if (!sounds_.count(filename)) { |
5 | Mix_Chunk* sample = Mix_LoadWAV(filename.c_str()); | 28 | Mix_Chunk* sample = Mix_LoadWAV(filename.c_str()); |
6 | if (!sample) { | 29 | if (!sample) { |
@@ -10,7 +33,5 @@ void Mixer::playSound(std::string filename) { | |||
10 | sounds_[filename] = chunk_ptr(sample); | 33 | sounds_[filename] = chunk_ptr(sample); |
11 | } | 34 | } |
12 | 35 | ||
13 | if (Mix_PlayChannel(-1, sounds_[filename].get(), 0) == -1) { | 36 | return sounds_[filename].get(); |
14 | throw mix_error(); | ||
15 | } | ||
16 | } | 37 | } |