From bb9bd73f435892b6f6f17d7068a7fe56dfca235d Mon Sep 17 00:00:00 2001 From: listeria <56203103+ListeriaM@users.noreply.github.com> Date: Tue, 21 May 2024 03:13:46 -0300 Subject: [PATCH] fix WaveCrop() and use frames instead of samples (#3994) Co-authored-by: Listeria monocytogenes --- src/raudio.c | 12 ++++++------ src/raylib.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/raudio.c b/src/raudio.c index 8f4bf7a5..e74f8590 100644 --- a/src/raudio.c +++ b/src/raudio.c @@ -1274,17 +1274,17 @@ Wave WaveCopy(Wave wave) return newWave; } -// Crop a wave to defined samples range +// Crop a wave to defined frames range // NOTE: Security check in case of out-of-range -void WaveCrop(Wave *wave, int initSample, int finalSample) +void WaveCrop(Wave *wave, int initFrame, int finalFrame) { - if ((initSample >= 0) && (initSample < finalSample) && ((unsigned int)finalSample < (wave->frameCount*wave->channels))) + if ((initFrame >= 0) && (initFrame < finalFrame) && ((unsigned int)finalFrame < wave->frameCount)) { - int sampleCount = finalSample - initSample; + int frameCount = finalFrame - initFrame; - void *data = RL_MALLOC(sampleCount*wave->sampleSize/8); + void *data = RL_MALLOC(frameCount*wave->channels*wave->sampleSize/8); - memcpy(data, (unsigned char *)wave->data + (initSample*wave->channels*wave->sampleSize/8), sampleCount*wave->sampleSize/8); + memcpy(data, (unsigned char *)wave->data + (initFrame*wave->channels*wave->sampleSize/8), frameCount*wave->channels*wave->sampleSize/8); RL_FREE(wave->data); wave->data = data; diff --git a/src/raylib.h b/src/raylib.h index 035f6f2b..c53ea555 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1624,7 +1624,7 @@ RLAPI void SetSoundVolume(Sound sound, float volume); // Set vol RLAPI void SetSoundPitch(Sound sound, float pitch); // Set pitch for a sound (1.0 is base level) RLAPI void SetSoundPan(Sound sound, float pan); // Set pan for a sound (0.5 is center) RLAPI Wave WaveCopy(Wave wave); // Copy a wave to a new wave -RLAPI void WaveCrop(Wave *wave, int initSample, int finalSample); // Crop a wave to defined samples range +RLAPI void WaveCrop(Wave *wave, int initFrame, int finalFrame); // Crop a wave to defined frames range RLAPI void WaveFormat(Wave *wave, int sampleRate, int sampleSize, int channels); // Convert wave data to desired format RLAPI float *LoadWaveSamples(Wave wave); // Load samples data from wave as a 32bit float data array RLAPI void UnloadWaveSamples(float *samples); // Unload samples data loaded with LoadWaveSamples()