SDL Breakout Engine  0.1.0
An implementation of a Breakout game using sdl, implemented with efficient resource management.
SoundManager.hpp
Go to the documentation of this file.
1 #ifndef SOUND_MANAGER_HPP
2 #define SOUND_MANAGER_HPP
3 
4 #include <SDL2/SDL.h>
5 #include <SDL2/SDL_mixer.h>
6 #include <ResourceManager.hpp>
7 
11 class SoundManager : public ResourceManager<SoundManager, Mix_Chunk>
12 {
13 public:
18  {
19  static SoundManager *instance = new SoundManager();
20  return *instance;
21  }
22 
26  int shutDown()
27  {
29  Mix_CloseAudio();
30  return 1;
31  }
32 
43  int startUp(int frequency, Uint16 format, int channels, int chunksize)
44  {
45  Mix_OpenAudio(frequency, format, channels, chunksize);
46  fileMap.emplace("GameOver", "./Assets/sound/GameOver_SFX.mp3");
47  fileMap.emplace("BrickHit", "./Assets/sound/BrickHit_SFX.mp3");
48  fileMap.emplace("PaddleHit", "./Assets/sound/PaddleBorderHit_SFX.mp3");
49  fileMap.emplace("Music", "./Assets/sound/MusicTrack.mp3");
50  return 1;
51  }
52 
58  std::shared_ptr<Mix_Chunk> Load(const std::string &path)
59  {
60  std::shared_ptr<Mix_Chunk> sound = std::shared_ptr<Mix_Chunk>(Mix_LoadWAV(path.c_str()));
61  if (!sound)
62  {
63  SDL_LogError(SDL_LOG_CATEGORY_AUDIO, "Mix_LoadWAV: %s", Mix_GetError());
64  return NULL;
65  }
66  else
67  {
68  SDL_Log("Allocated memory for: %s", path.c_str());
69  return sound;
70  }
71  }
72 };
73 
74 #endif
std::shared_ptr< Mix_Chunk > Load(const std::string &path)
Definition: SoundManager.hpp:58
std::map< std::string, std::string > fileMap
stores location of resources
Definition: ResourceManager.hpp:156
int startUp(int frequency, Uint16 format, int channels, int chunksize)
Definition: SoundManager.hpp:43
int shutDown()
Definition: ResourceManager.hpp:69
int shutDown()
Definition: SoundManager.hpp:26
static SoundManager & instance()
Definition: SoundManager.hpp:17
Definition: ResourceManager.hpp:62
Definition: SoundManager.hpp:11