sound_manager.hpp 1.4 KB
Newer Older
Florian Oetke's avatar
Florian Oetke committed
1
2
3
4
5
6
7
8
9
10
#pragma once

#include "../util/random_vector.hpp"

#include <mirrage/asset/asset_manager.hpp>
#include <mirrage/utils/messagebus.hpp>
#include <mirrage/utils/str_id.hpp>
#include <mirrage/utils/units.hpp>

#include <audio.hpp>
Florian Oetke's avatar
Florian Oetke committed
11
#include <sources/opus.hpp>
Florian Oetke's avatar
Florian Oetke committed
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

#include <memory>
#include <random>
#include <string>
#include <unordered_map>


namespace phase_shifter::audio {

	using Sound_effect_id = mirrage::util::Str_id;

	class Sound_manager {
	  public:
		Sound_manager(eam::audio& audio, mirrage::util::Message_bus&, mirrage::asset::Asset_manager&);

		void load_effects_file(const mirrage::asset::AID& aid);

		void effect_volume(float);
		auto effect_volume() const -> float { return _effect_volume; }

		void pause();
		void resume();

		void update(mirrage::util::Time dt);

		void register_effect(Sound_effect_id id, const mirrage::asset::AID& aid);
		void unregister_effect(Sound_effect_id id);

		void play_effect(Sound_effect_id id);

	  private:
		using Sound_effect     = std::shared_ptr<eam::opus>;
		using Sound_effect_set = utils::Random_vector<Sound_effect>;

		eam::audio&                       _audio;
		mirrage::util::Mailbox_collection _mailbox;
		mirrage::asset::Asset_manager&    _assets;
		float                             _effect_volume = 1.f;
		std::mt19937_64                   _random_gen;

		std::unordered_map<Sound_effect_id, Sound_effect_set> _sound_effects;
	};

} // namespace phase_shifter::audio