openMSX
SamplePlayer.hh
Go to the documentation of this file.
1 #ifndef SAMPLEPLAYER_HH
2 #define SAMPLEPLAYER_HH
3 
5 #include "WavData.hh"
6 #include <vector>
7 
8 namespace openmsx {
9 
10 class SamplePlayer final : public ResampledSoundDevice
11 {
12 public:
13  SamplePlayer(const std::string& name, const std::string& desc,
14  const DeviceConfig& config,
15  const std::string& samplesBaseName, unsigned numSamples,
16  const std::string& alternativeName = {});
17  ~SamplePlayer();
18 
19  void reset();
20 
23  void play(unsigned sampleNum);
24 
32  void repeat(unsigned sampleNum);
33 
39  void stopRepeat() { nextSampleNum = unsigned(-1); }
40 
42  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  // SoundDevice
52  void generateChannels(float** bufs, unsigned num) override;
53 
54  std::vector<WavData> samples;
55 
56  unsigned index;
57  unsigned bufferSize;
58  unsigned currentSampleNum;
59  unsigned nextSampleNum;
60 };
61 
62 } // namespace openmsx
63 
64 #endif
openmsx::ResampledSoundDevice
Definition: ResampledSoundDevice.hh:17
openmsx::DeviceConfig
Definition: DeviceConfig.hh:20
openmsx::SamplePlayer::repeat
void repeat(unsigned sampleNum)
Keep on repeating the given sample data.
Definition: SamplePlayer.cc:91
WavData.hh
openmsx::SamplePlayer::play
void play(unsigned sampleNum)
Start playing a (new) sample.
Definition: SamplePlayer.cc:63
openmsx::SamplePlayer::reset
void reset()
Definition: SamplePlayer.cc:57
openmsx::SamplePlayer::serialize
void serialize(Archive &ar, unsigned version)
Definition: SamplePlayer.cc:132
openmsx::SamplePlayer::isPlaying
bool isPlaying() const
Is there currently playing a sample.
Definition: SamplePlayer.hh:42
openmsx::SamplePlayer::SamplePlayer
SamplePlayer(const std::string &name, const std::string &desc, const DeviceConfig &config, const std::string &samplesBaseName, unsigned numSamples, const std::string &alternativeName={})
Definition: SamplePlayer.cc:13
openmsx::SamplePlayer::stopRepeat
void stopRepeat()
Stop repeat mode.
Definition: SamplePlayer.hh:39
openmsx::SamplePlayer
Definition: SamplePlayer.hh:11
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5
openmsx::SamplePlayer::~SamplePlayer
~SamplePlayer()
Definition: SamplePlayer.cc:52
ResampledSoundDevice.hh