The small3d framework
Sound.hpp
Go to the documentation of this file.
1 
10 #pragma once
11 
12 #include <unordered_map>
13 #include <portaudio.h>
14 #include <vector>
15 #include <string>
16 
17 namespace small3d {
18 
24  class Sound {
25  private:
26 
27  struct SoundData {
28  int channels;
29  int rate;
30  long samples;
31  long size;
32  double duration;
33  double startTime;
34  bool repeat;
35  unsigned long currentFrame;
36  std::vector<char> data;
37  };
38 
39  SoundData soundData;
40  PaStream *stream;
41 
42  static bool noOutputDevice;
43  static PaDeviceIndex defaultOutput;
44  static unsigned int numInstances;
45 
46  static int audioCallback(const void *inputBuffer, void *outputBuffer,
47  unsigned long framesPerBuffer,
48  const PaStreamCallbackTimeInfo *timeInfo,
49  PaStreamCallbackFlags statusFlags,
50  void *userData);
51  void load(const std::string soundFilePath);
52  void openStream();
53 
54  public:
58  Sound();
59 
64  Sound(const std::string soundFilePath);
65 
69  ~Sound();
70 
75  void play(const bool repeat=false);
76 
80  void stop();
81 
85  Sound(const Sound& other);
86 
90  Sound(const Sound&& other);
91 
95  Sound& operator=(const Sound& other);
96 
100  Sound& operator=(const Sound&& other);
101 
102  };
103 
104 }
Sound()
Default constructor.
Definition: Sound.cpp:76
Sound & operator=(const Sound &other)
Copy assignment.
Definition: Sound.cpp:257
void play(const bool repeat=false)
Play the sound.
Definition: Sound.cpp:208
~Sound()
Destructor.
Definition: Sound.cpp:104
void stop()
Stop playing the sound.
Definition: Sound.cpp:235
Class that loads and plays a sound from an ogg file.
Definition: Sound.hpp:24