| 1 |
#ifndef SAMPLEPLAYER_HH |
| 2 |
#define SAMPLEPLAYER_HH |
| 3 |
|
| 4 |
#include "ResampledSoundDevice.hh" |
| 5 |
#include "WavData.hh" |
| 6 |
#include "dynarray.hh" |
| 7 |
|
| 8 |
namespace openmsx { |
| 9 |
|
| 10 |
class SamplePlayer final : public ResampledSoundDevice |
| 11 |
{ |
| 12 |
public: |
| 13 |
SamplePlayer(const std::string& name, static_string_view desc, |
| 14 |
const DeviceConfig& config, |
| 15 |
std::string_view samplesBaseName, unsigned numSamples, |
| 16 |
std::string_view alternativeName = {}); |
| 17 |
~SamplePlayer(); |
| 18 |
|
| 19 |
void reset(); |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
void play(unsigned sampleNum); |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
void repeat(unsigned sampleNum); |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
void stopRepeat() { nextSampleNum = unsigned(-1); } |
| 40 |
|
| 41 |
|
| 42 |
[[nodiscard]] bool isPlaying() const { return currentSampleNum != unsigned(-1); } |
| 43 |
|
| 44 |
template<typename Archive> |
| 45 |
void serialize(Archive& ar, unsigned version); |
| 46 |
|
| 47 |
private: |
| 48 |
void setWavParams(); |
| 49 |
void doRepeat(); |
| 50 |
|
| 51 |
|
| 52 |
void generateChannels(std::span<float*> bufs, unsigned num) override; |
| 53 |
|
| 54 |
private: |
| 55 |
const dynarray<WavData> samples; |
| 56 |
|
| 57 |
unsigned index = 0; |
| 58 |
unsigned bufferSize; |
| 59 |
unsigned currentSampleNum; |
| 60 |
unsigned nextSampleNum; |
| 61 |
}; |
| 62 |
|
| 63 |
} |
| 64 |
|
| 65 |
#endif |