ST_engine  0.3-ALPHA
audio_manager.hpp
1 /* This file is part of the "ST" project.
2  * You may use, distribute or modify this code under the terms
3  * of the GNU General Public License version 2.
4  * See LICENCE.txt in the root directory of the project.
5  *
6  * Author: Maxim Atanasov
7  * E-mail: maxim.atanasov@protonmail.com
8  */
9 
10 #ifndef AUDIO_MNGR_DEF
11 #define AUDIO_MNGR_DEF
12 
13 #include <SDL.h>
14 #include <SDL_mixer.h>
15 #include <message_bus.hpp>
16 #include <task_manager.hpp>
17 
20  friend class audio_manager_test;
21 
22 private:
23 
24  uint8_t chunk_volume = MIX_MAX_VOLUME;
25  uint8_t music_volume = MIX_MAX_VOLUME;
26  bool muted = false;
27  //ratio: MIX_MAX_VOLUME/volume
28  float chunk_playback_volume_ratio = 1;
29  float music_playback_volume_ratio = 1;
30 
32  subscriber msg_sub{};
33 
35  ska::bytell_hash_map<uint16_t, Mix_Chunk *> *chunks_ptr{};
36  ska::bytell_hash_map<uint16_t, Mix_Music *> *music_ptr{};//-Delivered as a message
37  message_bus &gMessage_bus; //-Delivered in constructor
38  task_manager &gTask_manager; //-Delivered in constructor
39 
41  void handle_messages();
42 
43 
45  void play_music(uint16_t arg, uint8_t volume, int8_t loops) const;
46 
47  void play_sound(uint16_t arg, uint8_t volume, int8_t loops) const;
48 
49  void mute();
50 
51  void unmute();
52 
53  static void stop_music();
54 
55  static void pause_music();
56 
57  static void stop_channels();
58 
59  void set_chunk_volume(uint8_t arg);
60 
61  void set_music_volume(uint8_t arg);
62 
63  static void update_task(void *arg);
64 
65 public:
66  audio_manager(task_manager &tsk_mngr, message_bus &gMessageBus);
67 
69 
70  void update();
71 };
72 
73 
74 #endif
Tests fixture for the audio_manager.
This object is responsible for playing sounds and music.
audio_manager(task_manager &tsk_mngr, message_bus &gMessageBus)
The central messaging system of the engine. All subsystem make extensive use of it.
Definition: message_bus.hpp:29
This class handles a small queue for messages.
Definition: subscriber.hpp:20
The Task Manager handles all things multi-threaded in the engine.