| 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 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
bool generateInput(float* buffer, size_t num); |
| 30 |
|
| 31 |
[[nodiscard]] DynamicClock& getEmuClock() { return emuClock; } |
| 32 |
|
| 33 |
|
| 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 |
|
| 46 |
void setOutputRate(unsigned hostSampleRate, double speed) override; |
| 47 |
bool updateBuffer(size_t length, float* buffer, |
| 48 |
EmuTime time) override; |
| 49 |
|
| 50 |
|
| 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()}; |
| 59 |
|
| 60 |
}; |
| 61 |
|
| 62 |
} |
| 63 |
|
| 64 |
#endif |