openMSX
ResampledSoundDevice.hh
Go to the documentation of this file.
1 #ifndef RESAMPLEDSOUNDDEVICE_HH
2 #define RESAMPLEDSOUNDDEVICE_HH
3 
4 #include "SoundDevice.hh"
5 #include "DynamicClock.hh"
6 #include "Observer.hh"
7 #include <memory>
8 
9 namespace openmsx {
10 
11 class MSXMotherBoard;
12 class ResampleAlgo;
13 class Setting;
14 template<typename T> class EnumSetting;
15 
16 class ResampledSoundDevice : public SoundDevice, protected Observer<Setting>
17 {
18 public:
20 
25  bool generateInput(float* buffer, unsigned num);
26 
27  DynamicClock& getEmuClock() { return emuClock; }
28 
29 protected:
30  ResampledSoundDevice(MSXMotherBoard& motherBoard, std::string_view name,
31  std::string_view description, unsigned channels,
32  unsigned inputSampleRate, bool stereo);
34 
35  // SoundDevice
36  void setOutputRate(unsigned sampleRate) override;
37  bool updateBuffer(unsigned length, float* buffer,
38  EmuTime::param time) override;
39 
40  // Observer<Setting>
41  void update(const Setting& setting) override;
42 
43  void createResampler();
44 
45 private:
46  EnumSetting<ResampleType>& resampleSetting;
47  std::unique_ptr<ResampleAlgo> algo;
48  DynamicClock emuClock; // time of the last produced emu-sample,
49  // ticks once per emu-sample
50 };
51 
52 } // namespace openmsx
53 
54 #endif
openmsx::EnumSetting< ResampleType >
openmsx::ResampledSoundDevice::RESAMPLE_HQ
@ RESAMPLE_HQ
Definition: ResampledSoundDevice.hh:19
openmsx::ResampledSoundDevice::ResampleType
ResampleType
Definition: ResampledSoundDevice.hh:19
openmsx::ResampledSoundDevice
Definition: ResampledSoundDevice.hh:17
openmsx::ResampledSoundDevice::setOutputRate
void setOutputRate(unsigned sampleRate) override
When a SoundDevice registers itself with the Mixer, the Mixer sets the required sampleRate through th...
Definition: ResampledSoundDevice.cc:34
openmsx::ResampledSoundDevice::RESAMPLE_LQ
@ RESAMPLE_LQ
Definition: ResampledSoundDevice.hh:19
openmsx::ResampledSoundDevice::~ResampledSoundDevice
~ResampledSoundDevice()
Definition: ResampledSoundDevice.cc:28
openmsx::ResampledSoundDevice::generateInput
bool generateInput(float *buffer, unsigned num)
Note: To enable various optimizations (like SSE), this method is allowed to generate up to 3 extra sa...
Definition: ResampledSoundDevice.cc:45
gl::length
T length(const vecN< N, T > &x)
Definition: gl_vec.hh:348
openmsx::ResampledSoundDevice::updateBuffer
bool updateBuffer(unsigned length, float *buffer, EmuTime::param time) override
Generate sample data.
Definition: ResampledSoundDevice.cc:39
openmsx::Setting
Definition: Setting.hh:120
openmsx::DynamicClock
Represents a clock with a variable frequency.
Definition: DynamicClock.hh:17
openmsx::ResampledSoundDevice::ResampledSoundDevice
ResampledSoundDevice(MSXMotherBoard &motherBoard, std::string_view name, std::string_view description, unsigned channels, unsigned inputSampleRate, bool stereo)
Definition: ResampledSoundDevice.cc:16
Observer.hh
openmsx::SoundDevice
Definition: SoundDevice.hh:17
openmsx::MSXMotherBoard
Definition: MSXMotherBoard.hh:60
SoundDevice.hh
openmsx::ResampledSoundDevice::getEmuClock
DynamicClock & getEmuClock()
Definition: ResampledSoundDevice.hh:27
openmsx::ResampledSoundDevice::RESAMPLE_BLIP
@ RESAMPLE_BLIP
Definition: ResampledSoundDevice.hh:19
openmsx::ResampledSoundDevice::update
void update(const Setting &setting) override
Definition: ResampledSoundDevice.cc:51
DynamicClock.hh
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5
openmsx::Observer
Generic Gang-of-Four Observer class, templatized edition.
Definition: Observer.hh:10
openmsx::ResampledSoundDevice::createResampler
void createResampler()
Definition: ResampledSoundDevice.cc:58