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  [[nodiscard]] DynamicClock& getEmuClock() { return emuClock; }
28 
29 protected:
30  ResampledSoundDevice(MSXMotherBoard& motherBoard, std::string_view name,
31  static_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) noexcept 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
Represents a clock with a variable frequency.
Definition: DynamicClock.hh:17
Generic Gang-of-Four Observer class, templatized edition.
Definition: Observer.hh:10
bool updateBuffer(unsigned length, float *buffer, EmuTime::param time) override
Generate sample data.
void setOutputRate(unsigned sampleRate) override
When a SoundDevice registers itself with the Mixer, the Mixer sets the required sampleRate through th...
ResampledSoundDevice(MSXMotherBoard &motherBoard, std::string_view name, static_string_view description, unsigned channels, unsigned inputSampleRate, bool stereo)
void update(const Setting &setting) noexcept override
bool generateInput(float *buffer, unsigned num)
Note: To enable various optimizations (like SSE), this method is allowed to generate up to 3 extra sa...
static_string_view
T length(const vecN< N, T > &x)
Definition: gl_vec.hh:343
This file implemented 3 utility functions:
Definition: Autofire.cc:9