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 
21  /** Start playing a (new) sample.
22  */
23  void play(unsigned sampleNum);
24 
25  /** Keep on repeating the given sample data.
26  * If there is already a sample playing, that sample is still
27  * finished. If there was no sample playing, the given sample
28  * immediatly starts playing.
29  * Parameters are the same as for the play() method.
30  * @see stopRepeat()
31  */
32  void repeat(unsigned sampleNum);
33 
34  /** Stop repeat mode.
35  * The currently playing sample will still be finished, but won't
36  * be started.
37  * @see repeat()
38  */
39  void stopRepeat() { nextSampleNum = unsigned(-1); }
40 
41  /** Is there currently playing a sample. */
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
bool getEnum() const noexcept
Definition: EnumSetting.hh:96
void repeat(unsigned sampleNum)
Keep on repeating the given sample data.
Definition: SamplePlayer.cc:91
void play(unsigned sampleNum)
Start playing a (new) sample.
Definition: SamplePlayer.cc:63
bool isPlaying() const
Is there currently playing a sample.
Definition: SamplePlayer.hh:42
void stopRepeat()
Stop repeat mode.
Definition: SamplePlayer.hh:39
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
void serialize(Archive &ar, unsigned version)