summary refs log tree commit diff stats
path: root/src/mixer.h
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2021-02-02 20:18:41 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2021-02-02 20:18:41 -0500
commitc772a3e5d8d9507b898813cdfb597c14b07cdc61 (patch)
treed2b79410a30f55b2c8d10b6b4b564cdb40467a95 /src/mixer.h
parent93b3e4004387047c25b2f5a190aced01c9091934 (diff)
downloadtanetane-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.h67
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
10class mix_error : public std::logic_error {
11public:
12
13 mix_error() : std::logic_error(Mix_GetError())
14 {
15 }
16};
17
18class mix_wrapper {
19public:
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
45class chunk_deleter {
46public:
47
48 void operator()(Mix_Chunk* chunk) {
49 Mix_FreeChunk(chunk);
50 }
51};
52
53using chunk_ptr = std::unique_ptr<Mix_Chunk, chunk_deleter>;
54
55// MUST create the Renderer first!
56class Mixer {
57public:
58
59 void playSound(std::string filename);
60
61private:
62
63 mix_wrapper mix_;
64 std::map<std::string, chunk_ptr> sounds_;
65};
66
67#endif /* end of include guard: MIXER_H_6DF82000 */