OXYGENHUB
◆ main openmsx / src / sound / Mixer.hh
1.8 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#ifndef MIXER_HH
2
#define MIXER_HH
3
4
#include "BooleanSetting.hh"
5
#include "EnumSetting.hh"
6
#include "IntegerSetting.hh"
7
8
#include "Observer.hh"
9
10
#include <cstdint>
11
#include <memory>
12
#include <vector>
13
14
namespace openmsx {
15
16
class SoundDriver;
17
class Reactor;
18
class CommandController;
19
class MSXMixer;
20
21
struct StereoFloat {
22
	// Note: important to keep this uninitialized, we have large arrays of
23
	// these objects and needlessly initializing those is expensive
24
	float left;
25
	float right;
26
};
27
28
class Mixer final : private Observer<Setting>
29
{
30
public:
31
	enum class SoundDriverType : uint8_t { NONE, SDL };
32
33
	Mixer(Reactor& reactor, CommandController& commandController);
34
	~Mixer();
35
36
	/** Register per-machine mixer
37
	 */
38
	void registerMixer(MSXMixer& mixer);
39
40
	/** Unregister per-machine mixer
41
	 */
42
	void unregisterMixer(MSXMixer& mixer);
43
44
	/**
45
	 * This methods (un)mute the sound.
46
	 * These methods may be called multiple times, as long as
47
	 * you never call unmute() more than mute()
48
	 */
49
	void mute();
50
	void unmute();
51
52
	// Called by MSXMixer
53
54
	/** Upload new sample data
55
	 */
56
	void uploadBuffer(MSXMixer& msxMixer, std::span<const StereoFloat> buffer);
57
58
	[[nodiscard]] IntegerSetting& getMasterVolume() { return masterVolume; }
59
	[[nodiscard]] BooleanSetting& getMuteSetting() { return muteSetting; }
60
61
private:
62
	void reloadDriver();
63
	void muteHelper();
64
65
	// Observer<Setting>
66
	void update(const Setting& setting) noexcept override;
67
68
private:
69
	std::vector<MSXMixer*> msxMixers; // unordered
70
71
	std::unique_ptr<SoundDriver> driver;
72
	Reactor& reactor;
73
	CommandController& commandController;
74
75
	EnumSetting<SoundDriverType> soundDriverSetting;
76
	BooleanSetting muteSetting;
77
	IntegerSetting masterVolume;
78
	IntegerSetting frequencySetting;
79
	IntegerSetting samplesSetting;
80
81
	int muteCount = 0;
82
};
83
84
} // namespace openmsx
85
86
#endif