raylib-cpp
C++ object-oriented wrapper library for raylib.
Wave.hpp
1 #ifndef RAYLIB_CPP_INCLUDE_WAVE_HPP_
2 #define RAYLIB_CPP_INCLUDE_WAVE_HPP_
3 
4 #include <string>
5 
6 #include "./raylib.hpp"
7 #include "./raylib-cpp-utils.hpp"
8 
9 namespace raylib {
13 class Wave : public ::Wave {
14  public:
15  Wave(const ::Wave& wave) {
16  set(wave);
17  }
18 
19  Wave(
20  unsigned int SampleCount = 0,
21  unsigned int SampleRate = 0,
22  unsigned int SampleSize = 0,
23  unsigned int Channels = 0) {
24  sampleCount = SampleCount;
25  sampleRate = SampleRate;
26  sampleSize = SampleSize;
27  channels = Channels;
28  }
29 
33  Wave(const std::string& fileName) {
34  set(::LoadWave(fileName.c_str()));
35  }
36 
40  Wave(const std::string& fileType, const unsigned char *fileData, int dataSize) {
41  set(::LoadWaveFromMemory(fileType.c_str(), fileData, dataSize));
42  }
43 
47  ~Wave() {
48  Unload();
49  }
50 
51  GETTERSETTER(unsigned int, SampleCount, sampleCount)
52  GETTERSETTER(unsigned int, SampleRate, sampleRate)
53  GETTERSETTER(unsigned int, SampleSize, sampleSize)
54  GETTERSETTER(unsigned int, Channels, channels)
55  GETTERSETTER(void *, Data, data)
56 
57  Wave& operator=(const ::Wave& wave) {
58  set(wave);
59  return *this;
60  }
61 
65  inline Wave& Format(int SampleRate, int SampleSize, int Channels = 2) {
66  ::WaveFormat(this, SampleRate, SampleSize, Channels);
67  return *this;
68  }
69 
73  inline ::Wave Copy() {
74  return ::WaveCopy(*this);
75  }
76 
80  inline Wave& Crop(int initSample, int finalSample) {
81  ::WaveCrop(this, initSample, finalSample);
82  return *this;
83  }
84 
88  inline float* LoadSamples() {
89  return ::LoadWaveSamples(*this);
90  }
91 
95  inline void UnloadSamples(float *samples) {
96  ::UnloadWaveSamples(samples);
97  }
98 
102  inline bool Export(const std::string& fileName) {
103  // TODO(RobLoach): Throw exception on error.
104  return ::ExportWave(*this, fileName.c_str());
105  }
106 
110  inline bool ExportAsCode(const std::string& fileName) {
111  // TODO(RobLoach): Throw exception on error.
112  return ::ExportWaveAsCode(*this, fileName.c_str());
113  }
114 
118  void Unload() {
119  if (data != NULL) {
120  ::UnloadWave(*this);
121  data = NULL;
122  }
123  }
124 
128  inline ::Sound LoadSound() {
129  return ::LoadSoundFromWave(*this);
130  }
131 
135  inline operator ::Sound() {
136  return LoadSound();
137  }
138 
142  inline operator Sound() {
143  return LoadSound();
144  }
145 
146  private:
147  inline void set(const ::Wave& wave) {
148  sampleCount = wave.sampleCount;
149  sampleRate = wave.sampleRate;
150  sampleSize = wave.sampleSize;
151  channels = wave.channels;
152  data = wave.data;
153  }
154 };
155 } // namespace raylib
156 
157 #endif // RAYLIB_CPP_INCLUDE_WAVE_HPP_
raylib::Wave::Copy
inline ::Wave Copy()
Copy a wave to a new wave.
Definition: Wave.hpp:73
raylib
All raylib-cpp classes and functions appear in the raylib namespace.
Definition: AudioDevice.hpp:7
raylib::Wave
Wave type, defines audio wave data.
Definition: Wave.hpp:13
raylib::Wave::Crop
Wave & Crop(int initSample, int finalSample)
Crop a wave to defined samples range.
Definition: Wave.hpp:80
raylib::Wave::Unload
void Unload()
Unload wave data.
Definition: Wave.hpp:118
raylib::Wave::LoadSamples
float * LoadSamples()
Load samples data from wave as a floats array.
Definition: Wave.hpp:88
raylib::Sound
Wave/Sound management functions.
Definition: Sound.hpp:18
raylib::Wave::Export
bool Export(const std::string &fileName)
Export wave data to file, returns true on success.
Definition: Wave.hpp:102
raylib::Wave::~Wave
~Wave()
Unload wave data.
Definition: Wave.hpp:47
raylib::Wave::Wave
Wave(const std::string &fileType, const unsigned char *fileData, int dataSize)
Load wave from memory buffer, fileType refers to extension: i.e.
Definition: Wave.hpp:40
raylib::Wave::Wave
Wave(const std::string &fileName)
Load wave data from file.
Definition: Wave.hpp:33
raylib::Wave::ExportAsCode
bool ExportAsCode(const std::string &fileName)
Export wave sample data to code (.h), returns true on success.
Definition: Wave.hpp:110
raylib::Wave::UnloadSamples
void UnloadSamples(float *samples)
Unload samples data loaded with LoadWaveSamples()
Definition: Wave.hpp:95
raylib::Wave::Format
Wave & Format(int SampleRate, int SampleSize, int Channels=2)
Convert wave data to desired format.
Definition: Wave.hpp:65
raylib::Wave::LoadSound
inline ::Sound LoadSound()
Load sound from wave data.
Definition: Wave.hpp:128