1 #ifndef RAYLIB_CPP_INCLUDE_WAVE_HPP_
2 #define RAYLIB_CPP_INCLUDE_WAVE_HPP_
6 #include "./raylib.hpp"
7 #include "./raylib-cpp-utils.hpp"
8 #include "./RaylibException.hpp"
16 Wave(const ::Wave& wave) {
21 unsigned int frameCount = 0,
22 unsigned int sampleRate = 0,
23 unsigned int sampleSize = 0,
24 unsigned int channels = 0,
25 void *data =
nullptr) :
::Wave{frameCount, sampleRate, sampleSize, channels, data} {
34 Wave(
const std::string& fileName) {
43 Wave(
const std::string& fileType,
const unsigned char *fileData,
int dataSize) {
44 Load(fileType, fileData, dataSize);
68 GETTERSETTER(
unsigned int, FrameCount, frameCount)
69 GETTERSETTER(
unsigned int, SampleRate, sampleRate)
70 GETTERSETTER(
unsigned int, SampleSize, sampleSize)
71 GETTERSETTER(
unsigned int, Channels, channels)
72 GETTERSETTER(
void *, Data, data)
74 Wave& operator=(const ::
Wave& wave) {
90 Wave& operator=(Wave&& other) noexcept {
100 other.sampleSize = 0;
102 other.data =
nullptr;
111 return ::WaveCopy(*
this);
117 inline Wave&
Crop(
int initSample,
int finalSample) {
118 ::WaveCrop(
this, initSample, finalSample);
125 inline Wave&
Format(
int SampleRate,
int SampleSize,
int Channels = 2) {
126 ::WaveFormat(
this, SampleRate, SampleSize, Channels);
134 return ::LoadWaveSamples(*
this);
141 ::UnloadWaveSamples(samples);
147 inline bool Export(
const std::string& fileName) {
149 return ::ExportWave(*
this, fileName.c_str());
157 return ::ExportWaveAsCode(*
this, fileName.c_str());
164 if (data !=
nullptr) {
174 return ::LoadSoundFromWave(*
this);
180 inline operator ::Sound() {
189 void Load(
const std::string& fileName) {
190 set(::LoadWave(fileName.c_str()));
201 void Load(
const std::string& fileType,
const unsigned char *fileData,
int dataSize) {
202 set(::LoadWaveFromMemory(fileType.c_str(), fileData, dataSize));
204 throw RaylibException(
"Failed to load Wave from file data of type: " + fileType);
214 return data !=
nullptr;
218 void set(const ::Wave& wave) {
219 frameCount = wave.frameCount;
220 sampleRate = wave.sampleRate;
221 sampleSize = wave.sampleSize;
222 channels = wave.channels;
Exception used for most raylib-related exceptions.
Wave type, defines audio wave data.
Wave & Crop(int initSample, int finalSample)
Crop a wave to defined samples range.
inline ::Wave Copy() const
Copy a wave to a new wave.
void Load(const std::string &fileType, const unsigned char *fileData, int dataSize)
Load wave from memory buffer, fileType refers to extension: i.e.
Wave(const std::string &fileType, const unsigned char *fileData, int dataSize)
Load wave from memory buffer, fileType refers to extension: i.e.
bool ExportAsCode(const std::string &fileName)
Export wave sample data to code (.h), returns true on success.
Wave & Format(int SampleRate, int SampleSize, int Channels=2)
Convert wave data to desired format.
void Unload()
Unload wave data.
inline ::Sound LoadSound()
Load sound from wave data.
bool IsReady() const
Retrieve whether or not the Wave data has been loaded.
bool Export(const std::string &fileName)
Export wave data to file, returns true on success.
float * LoadSamples()
Load samples data from wave as a floats array.
static void UnloadSamples(float *samples)
Unload samples data loaded with LoadWaveSamples()
Wave(const std::string &fileName)
Load wave data from file.
void Load(const std::string &fileName)
Load wave data from file.
All raylib-cpp classes and functions appear in the raylib namespace.