TurtleBrains  0.3.5
High quality, portable, C++ framework for rapid 2D game development.
tb_audio_manager.hpp
1 
10 #ifndef TurtleBrains_AudioManager_hpp
11 #define TurtleBrains_AudioManager_hpp
12 
13 #include <turtle_brains/core/tb_configuration.hpp>
14 #if defined(tb_with_audio)
15 
16 #include <turtle_brains/core/tb_noncopyable.hpp>
17 #include <turtle_brains/core/tb_string.hpp>
18 #include <turtle_brains/core/tb_types.hpp>
19 #include <turtle_brains/audio/tb_audio_controller.hpp>
20 
21 #include <memory>
22 
23 namespace tbImplementation { class AudioManagerCreator; struct AudioManagerData; }
24 
25 namespace TurtleBrains
26 {
27  namespace Audio
28  {
34  class AudioManager : public tbCore::Noncopyable
35  {
36  public:
48 
49  //
50  // example_event_table.json
51  //
52  //{ "audio_events":[
53  // "version":2,
54  // "root_path":"data/../audio",
55  // { "name":"simple", "source":"data/sound.wav" },
56  // { "name":"loop", "source":"data/sound.wav", "looping":true },
57  // { "name":"music", "source":"data/music.ogg", "looping":true, "music":true },
58  // { "name":"music_streaming", "source":"data/music.ogg", "looping":true, "music":true, "streaming":true },
59  // { "name":"music_loop_points", "source":"data/music.ogg", "looping":true, "music":true, "streaming":true, "start_loop":50000, "end_loop":403032 },
60  // { "name":"music_jingle", "source":"data/jingle.wav", "music":true },
61  // { "name":"extra", "source":"data/sound.wav", "pitch":1.0, "volume":1.0 },
62  // { "name":"multi_file", "source":[
63  // "data/sound1.wav",
64  // "data/sound2.wav" ]
65  // },
66  // { "name":"multi_custom", "source":[
67  // { "file":"data/sound1.wav", "pitch":1.0, "volume":1.0 },
68  // { "file":"data/sound2.wav", "min_pitch":0.8, "max_pitch":1.2, "min_volume":0.5, "max_volume":0.6 } ]
69  // },
70  // { "name":"multi_mixed", "source":[
71  // "data/sound1.wav",
72  // "data/sound2.wav",
73  // { "file":"data/sound3.wav", "pitch":1.0, "volume":1.0 },
74  // { "file":"data/sound4.wav", "min_pitch":0.8, "max_pitch":1.2, "min_volume":0.5, "max_volume":0.6 } ]
75  // }
76  // ]
77  // }
78  //
79  // The json data does not need to contain the optional parameters shown below with their default values.
80  // looping(false), pitch(1.0), volume(1.0), min_pitch(1.0), max_pitch(1.0), min_volume(1.0), max_volume(1.0)
81  //
82  bool LoadEventTable(const tbCore::tbString& eventTableName, const tbCore::tbString& eventTableFile);
83 
92  void UnloadEventTable(const tbCore::tbString& eventTableName);
93 
107  AudioHandle CreateSoundFromFile(const tbCore::tbString& filename, const bool isStreaming = false);
108 
117  void DestroySound(const AudioHandle& audioHandle);
118 
126  bool HasEvent(const tbCore::tbString& eventTableName, const tbCore::tbString& eventName);
127 
142  AudioController PlayEvent(const tbCore::tbString& eventTableName, const tbCore::tbString& eventName);
143 
161  AudioController PlaySound(const AudioHandle& audioHandle, const bool isLooping = false, const bool isMusic = false);
162 
166  float GetGlobalMusicVolume(void) const;
167 
178  void SetGlobalMusicVolume(const float musicVolume);
179 
183  float GetGlobalEffectVolume(void) const;
184 
195  void SetGlobalEffectVolume(const float effectVolume);
196 
204  void PauseAllAudio(void);
205 
209  void ResumeAllAudio(void);
210 
215  tbCore::uint64 ComputeMemoryUsage(void) const;
216 
217  private:
218  friend class tbImplementation::AudioManagerCreator;
219 
224  AudioManager(void);
225 
230  ~AudioManager(void);
231 
232  std::unique_ptr<tbImplementation::AudioManagerData> mData;
233  };
234 
239  extern AudioManager& theAudioManager;
240 
249  void OpenAudioDevice(void);
250 
258  void CloseAudioDevice(void);
259 
268  void UpdateAudioDevice(void);
269 
270  }; /* namespace Audio */
271 }; /* namespace TurtleBrains */
272 
273 namespace tbAudio = TurtleBrains::Audio;
274 
275 #endif /* tb_with_audio */
276 #endif /* TurtleBrains_AudioManager_hpp */
Definition: tb_noncopyable.hpp:22
Here is some information about the primary namespace.
Definition: tb_application_dialog.hpp:21
uint64_t uint64
Unsigned integer with a size of 64 bits, Supports values from 0 to (2^64 - 1).
Definition: tb_types.hpp:30
Bring some sound into the games created with TurtleBrains using a very simple fire and forget AudioMa...
std::string tbString
Definition: tb_string.hpp:335
Definition: tb_application_dialog.hpp:19