GameKit  0.0.1a
C++ gamedev tools
Sound.hpp
Go to the documentation of this file.
1 /*
2  * =====================================================================================
3  *
4  * Filename: Sound.hpp
5  *
6  * Description:
7  *
8  * Created: 15/09/2014 23:03:24
9  *
10  * Author: Quentin Bazin, <quent42340@gmail.com>
11  *
12  * =====================================================================================
13  */
14 #ifndef GK_SOUND_HPP_
15 #define GK_SOUND_HPP_
16 
17 #include <memory>
18 #include <string>
19 
20 #include "gk/core/SDLHeaders.hpp"
21 #include "gk/core/Timer.hpp"
22 
23 namespace gk {
24 
25 class Sound {
26  public:
27  Sound() = default;
28  Sound(const std::string &filename);
29 
30  void openFromFile(const std::string &filename);
31 
32  void play();
33 
34  void repeat(u16 delay);
35 
36  void setChannel(int channel) { m_channel = channel; }
37  void setVolume(int volume) { m_volume = volume; }
38 
39  private:
40  static int s_lastUsedChannel;
41 
42  using Mix_ChunkPtr = std::unique_ptr<Mix_Chunk, decltype(&Mix_FreeChunk)>;
43 
44  Mix_ChunkPtr m_sfx{nullptr, Mix_FreeChunk};
45 
47 
48  int m_channel = -1;
49  int m_volume = MIX_MAX_VOLUME;
50 };
51 
52 } // namespace gk
53 
54 #endif // GK_SOUND_HPP_
void setChannel(int channel)
Definition: Sound.hpp:36
void openFromFile(const std::string &filename)
Definition: Sound.cpp:25
Mix_ChunkPtr m_sfx
Definition: Sound.hpp:44
unsigned short u16
Definition: IntTypes.hpp:22
int m_volume
Definition: Sound.hpp:49
void setVolume(int volume)
Definition: Sound.hpp:37
int m_channel
Definition: Sound.hpp:48
Sound()=default
void play()
Definition: Sound.cpp:36
gk::Timer m_timer
Definition: Sound.hpp:46
void repeat(u16 delay)
Definition: Sound.cpp:41
static int s_lastUsedChannel
Definition: Sound.hpp:40
Very basic timer.
Definition: Timer.hpp:25
std::unique_ptr< Mix_Chunk, decltype(&Mix_FreeChunk)> Mix_ChunkPtr
Definition: Sound.hpp:42