SDL SPOOKY PLATFORMER ENGINE  0.2.0
An implementation of a platformer using sdl, implemented using an entity component system and efficient collision 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("ThreeTone", "./Assets/sound/ThreeTone_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  fileMap.emplace("SpookyMusic", "./Assets/sound/Reflex_Nightmare_Trimmed.mp3");
51  return 1;
52  }
53 
59  std::shared_ptr<Mix_Chunk> Load(const std::string &path)
60  {
61  std::shared_ptr<Mix_Chunk> sound = std::shared_ptr<Mix_Chunk>(Mix_LoadWAV(path.c_str()));
62  if (!sound)
63  {
64  SDL_LogError(SDL_LOG_CATEGORY_AUDIO, "Mix_LoadWAV: %s", Mix_GetError());
65  return NULL;
66  }
67  else
68  {
69  SDL_Log("Allocated memory for: %s", path.c_str());
70  return sound;
71  }
72  }
73 };
74 
75 #endif
std::shared_ptr< Mix_Chunk > Load(const std::string &path)
Definition: SoundManager.hpp:59
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