1#ifndef RAYLIB_CPP_INCLUDE_WAVE_HPP_
2#define RAYLIB_CPP_INCLUDE_WAVE_HPP_
8#include "./RaylibException.hpp"
9#include "./raylib-cpp-utils.hpp"
10#include "./raylib.hpp"
16class Wave :
public ::Wave {
18 Wave(const ::Wave& wave) : ::Wave(wave) { }
21 unsigned int frameCount = 0,
22 unsigned int sampleRate = 0,
23 unsigned int sampleSize = 0,
24 unsigned int channels = 0,
26 : ::Wave{frameCount, sampleRate, sampleSize, channels, data} {
35 Wave(
const std::string_view fileName) {
44 Wave(
const std::string_view fileType,
const unsigned char *fileData,
int dataSize) {
45 Load(fileType, fileData, dataSize);
53 Wave(
const std::string_view fileType, std::span<const unsigned char> fileData) {
54 Load(fileType, fileData);
61 Wave(Wave&& other)
noexcept {
76 GETTER(
unsigned int, FrameCount, frameCount)
77 GETTER(
unsigned int, SampleRate, sampleRate)
78 GETTER(
unsigned int, SampleSize, sampleSize)
79 GETTER(
unsigned int, Channels, channels)
80 GETTER(
void*, Data, data)
82 Wave& operator=(const ::
Wave& wave) {
98 Wave& operator=(Wave&& other)
noexcept {
106 other.frameCount = 0;
107 other.sampleRate = 0;
108 other.sampleSize = 0;
110 other.data =
nullptr;
118 [[nodiscard]] ::Wave
Copy()
const { return ::WaveCopy(*
this); }
124 ::WaveCrop(
this, initSample, finalSample);
131 Wave&
Format(
int SampleRate,
int SampleSize,
int Channels = 2) {
132 ::WaveFormat(
this, SampleRate, SampleSize, Channels);
149 bool Export(
const std::string_view fileName) {
151 return ::ExportWave(*
this, fileName.data());
159 return ::ExportWaveAsCode(*
this, fileName.data());
167 if (data !=
nullptr) {
188 void Load(
const std::string_view fileName) {
189 set(::LoadWave(fileName.data()));
191 throw RaylibException(
"Failed to load Wave from file: " + std::string(fileName));
200 void Load(
const std::string_view fileType,
const unsigned char *fileData,
int dataSize) {
201 set(::LoadWaveFromMemory(fileType.data(), fileData, dataSize));
203 throw RaylibException(
"Failed to load Wave from file data of type: " + std::string(fileType));
212 void Load(
const std::string_view fileType, std::span<const unsigned char> fileData) {
213 set(::LoadWaveFromMemory(fileType.data(), fileData.data(),
static_cast<int>(fileData.size())));
215 throw RaylibException(
"Failed to load Wave from file data of type: " + std::string(fileType));
224 [[nodiscard]]
bool IsValid()
const { return ::IsWaveValid(*
this); }
226 void set(const ::Wave& wave) {
227 frameCount = wave.frameCount;
228 sampleRate = wave.sampleRate;
229 sampleSize = wave.sampleSize;
230 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 IsValid() 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.
All raylib-cpp classes and functions appear in the raylib namespace.