OXYGENHUB
◆ main openmsx / src / sound / ResampledSoundDevice.hh
1.6 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#ifndef RESAMPLEDSOUNDDEVICE_HH
2
#define RESAMPLEDSOUNDDEVICE_HH
3
4
#include "SoundDevice.hh"
5
6
#include "DynamicClock.hh"
7
#include "EnumSetting.hh"
8
9
#include "Observer.hh"
10
11
#include <cstdint>
12
#include <memory>
13
14
namespace openmsx {
15
16
class MSXMotherBoard;
17
class ResampleAlgo;
18
class Setting;
19
20
class ResampledSoundDevice : public SoundDevice, protected Observer<Setting>
21
{
22
public:
23
	enum class ResampleType : uint8_t { HQ, BLIP };
24
25
	/** Note: To enable various optimizations (like SSE), this method is
26
	  * allowed to generate up to 3 extra sample.
27
	  * @see SoundDevice::updateBuffer()
28
	  */
29
	bool generateInput(float* buffer, size_t num);
30
31
	[[nodiscard]] DynamicClock& getEmuClock() { return emuClock; }
32
33
	// setBalance() might switch between mono/stereo
34
	void postSetBalance() override {
35
		createResampler();
36
		SoundDevice::postSetBalance();
37
	}
38
39
protected:
40
	ResampledSoundDevice(MSXMotherBoard& motherBoard, std::string_view name,
41
	                     static_string_view description, unsigned channels,
42
	                     unsigned inputSampleRate, bool stereo);
43
	~ResampledSoundDevice();
44
45
	// SoundDevice
46
	void setOutputRate(unsigned hostSampleRate, double speed) override;
47
	bool updateBuffer(size_t length, float* buffer,
48
	                  EmuTime time) override;
49
50
	// Observer<Setting>
51
	void update(const Setting& setting) noexcept override;
52
53
	void createResampler();
54
55
private:
56
	EnumSetting<ResampleType>& resampleSetting;
57
	std::unique_ptr<ResampleAlgo> algo;
58
	DynamicClock emuClock{EmuTime::zero()}; // time of the last produced emu-sample,
59
	                                        //    ticks once per emu-sample
60
};
61
62
} // namespace openmsx
63
64
#endif