From c772a3e5d8d9507b898813cdfb597c14b07cdc61 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Tue, 2 Feb 2021 20:18:41 -0500 Subject: Added "bumping into something while running" sfx --- src/mixer.h | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/mixer.h (limited to 'src/mixer.h') 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 @@ +#ifndef MIXER_H_6DF82000 +#define MIXER_H_6DF82000 + +#include +#include +#include +#include +#include + +class mix_error : public std::logic_error { +public: + + mix_error() : std::logic_error(Mix_GetError()) + { + } +}; + +class mix_wrapper { +public: + + mix_wrapper() + { + if (Mix_Init(0) != 0) { + mix_error ex; + Mix_Quit(); + + throw ex; + } + + if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024) != 0) { + mix_error ex; + Mix_Quit(); + + throw ex; + } + } + + ~mix_wrapper() + { + Mix_CloseAudio(); + Mix_Quit(); + } +}; + +class chunk_deleter { +public: + + void operator()(Mix_Chunk* chunk) { + Mix_FreeChunk(chunk); + } +}; + +using chunk_ptr = std::unique_ptr; + +// MUST create the Renderer first! +class Mixer { +public: + + void playSound(std::string filename); + +private: + + mix_wrapper mix_; + std::map sounds_; +}; + +#endif /* end of include guard: MIXER_H_6DF82000 */ -- cgit 1.4.1