1#ifndef RAYLIB_CPP_INCLUDE_WAVE_HPP_
2#define RAYLIB_CPP_INCLUDE_WAVE_HPP_
9#include "./raylib-cpp-utils.hpp"
10#include "./RaylibException.hpp"
16class Wave :
public ::Wave {
18 Wave(const ::Wave& wave) {
23 unsigned int frameCount = 0,
24 unsigned int sampleRate = 0,
25 unsigned int sampleSize = 0,
26 unsigned int channels = 0,
27 void *data =
nullptr) : ::Wave{frameCount, sampleRate, sampleSize, channels, data} {
36 Wave(
const std::string_view fileName) {
45 Wave(
const std::string_view fileType,
const unsigned char *fileData,
int dataSize) {
46 Load(fileType, fileData, dataSize);
54 Wave(
const std::string_view fileType, std::span<const unsigned char> fileData) {
55 Load(fileType, fileData);
79 GETTER(
unsigned int, FrameCount, frameCount)
80 GETTER(
unsigned int, SampleRate, sampleRate)
81 GETTER(
unsigned int, SampleSize, sampleSize)
82 GETTER(
unsigned int, Channels, channels)
83 GETTER(
void *, Data, data)
85 Wave& operator=(const ::
Wave& wave) {
101 Wave& operator=(Wave&& other)
noexcept {
102 if (
this != &other) {
109 other.frameCount = 0;
110 other.sampleRate = 0;
111 other.sampleSize = 0;
113 other.data =
nullptr;
122 return ::WaveCopy(*
this);
129 ::WaveCrop(
this, initSample, finalSample);
136 Wave&
Format(
int SampleRate,
int SampleSize,
int Channels = 2) {
137 ::WaveFormat(
this, SampleRate, SampleSize, Channels);
145 return ::LoadWaveSamples(*
this);
152 ::UnloadWaveSamples(samples);
158 bool Export(
const std::string_view fileName) {
160 return ::ExportWave(*
this, fileName.data());
168 return ::ExportWaveAsCode(*
this, fileName.data());
176 if (data !=
nullptr) {
186 return ::LoadSoundFromWave(*
this);
201 void Load(
const std::string_view fileName) {
202 set(::LoadWave(fileName.data()));
204 throw RaylibException(
"Failed to load Wave from file: " + std::string(fileName));
213 void Load(
const std::string_view fileType,
const unsigned char *fileData,
int dataSize) {
214 set(::LoadWaveFromMemory(fileType.data(), fileData, dataSize));
216 throw RaylibException(
"Failed to load Wave from file data of type: " + std::string(fileType));
225 void Load(
const std::string_view fileType, std::span<const unsigned char> fileData) {
226 set(::LoadWaveFromMemory(fileType.data(), fileData.data(),
static_cast<int>(fileData.size())));
228 throw RaylibException(
"Failed to load Wave from file data of type: " + std::string(fileType));
238 return ::IsWaveReady(*
this);
242 void set(const ::Wave& wave) {
243 frameCount = wave.frameCount;
244 sampleRate = wave.sampleRate;
245 sampleSize = wave.sampleSize;
246 channels = wave.channels;
Exception used for most raylib-related exceptions.
Wave type, defines audio wave data.
float * LoadSamples()
Load samples data from wave as a floats array.
void Load(const std::string_view fileType, const unsigned char *fileData, int dataSize)
Load wave from memory buffer, fileType refers to extension: i.e.
bool Export(const std::string_view fileName)
Export wave data to file, returns true on success.
::Wave Copy() const
Copy a wave to a new wave.
bool ExportAsCode(const std::string_view fileName)
Export wave sample data to code (.h), returns true on success.
::Sound LoadSound()
Load sound from wave data.
Wave & Crop(int initSample, int finalSample)
Crop a wave to defined samples range.
Wave(const std::string_view fileType, const unsigned char *fileData, int dataSize)
Load wave from memory buffer, fileType refers to extension: i.e.
void Unload()
Unload wave data.
Wave & Format(int SampleRate, int SampleSize, int Channels=2)
Convert wave data to desired format.
void Load(const std::string_view fileName)
Load wave data from file.
operator::Sound()
Load sound from wave data.
Wave(const std::string_view fileType, std::span< const unsigned char > fileData)
Load wave from memory buffer, fileType refers to extension: i.e.
Wave(const std::string_view fileName)
Load wave data from file.
bool IsReady() const
Retrieve whether or not the Wave data has been loaded.
static void UnloadSamples(float *samples)
Unload samples data loaded with LoadWaveSamples()
void Load(const std::string_view fileType, std::span< const unsigned char > fileData)
Load wave from memory buffer, fileType refers to extension: i.e.