diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2021-02-02 20:18:41 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2021-02-02 20:18:41 -0500 |
commit | c772a3e5d8d9507b898813cdfb597c14b07cdc61 (patch) | |
tree | d2b79410a30f55b2c8d10b6b4b564cdb40467a95 /src/mixer.h | |
parent | 93b3e4004387047c25b2f5a190aced01c9091934 (diff) | |
download | tanetane-c772a3e5d8d9507b898813cdfb597c14b07cdc61.tar.gz tanetane-c772a3e5d8d9507b898813cdfb597c14b07cdc61.tar.bz2 tanetane-c772a3e5d8d9507b898813cdfb597c14b07cdc61.zip |
Added "bumping into something while running" sfx
Diffstat (limited to 'src/mixer.h')
-rw-r--r-- | src/mixer.h | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/mixer.h b/src/mixer.h new file mode 100644 index 0000000..010bb09 --- /dev/null +++ b/src/mixer.h | |||
@@ -0,0 +1,67 @@ | |||
1 | #ifndef MIXER_H_6DF82000 | ||
2 | #define MIXER_H_6DF82000 | ||
3 | |||
4 | #include <SDL_mixer.h> | ||
5 | #include <memory> | ||
6 | #include <stdexcept> | ||
7 | #include <map> | ||
8 | #include <string> | ||
9 | |||
10 | class mix_error : public std::logic_error { | ||
11 | public: | ||
12 | |||
13 | mix_error() : std::logic_error(Mix_GetError()) | ||
14 | { | ||
15 | } | ||
16 | }; | ||
17 | |||
18 | class mix_wrapper { | ||
19 | public: | ||
20 | |||
21 | mix_wrapper() | ||
22 | { | ||
23 | if (Mix_Init(0) != 0) { | ||
24 | mix_error ex; | ||
25 | Mix_Quit(); | ||
26 | |||
27 | throw ex; | ||
28 | } | ||
29 | |||
30 | if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024) != 0) { | ||
31 | mix_error ex; | ||
32 | Mix_Quit(); | ||
33 | |||
34 | throw ex; | ||
35 | } | ||
36 | } | ||
37 | |||
38 | ~mix_wrapper() | ||
39 | { | ||
40 | Mix_CloseAudio(); | ||
41 | Mix_Quit(); | ||
42 | } | ||
43 | }; | ||
44 | |||
45 | class chunk_deleter { | ||
46 | public: | ||
47 | |||
48 | void operator()(Mix_Chunk* chunk) { | ||
49 | Mix_FreeChunk(chunk); | ||
50 | } | ||
51 | }; | ||
52 | |||
53 | using chunk_ptr = std::unique_ptr<Mix_Chunk, chunk_deleter>; | ||
54 | |||
55 | // MUST create the Renderer first! | ||
56 | class Mixer { | ||
57 | public: | ||
58 | |||
59 | void playSound(std::string filename); | ||
60 | |||
61 | private: | ||
62 | |||
63 | mix_wrapper mix_; | ||
64 | std::map<std::string, chunk_ptr> sounds_; | ||
65 | }; | ||
66 | |||
67 | #endif /* end of include guard: MIXER_H_6DF82000 */ | ||