From 18ee6071d48263e266f34c960f72d3e1e6566608 Mon Sep 17 00:00:00 2001 From: David Reid Date: Fri, 20 Feb 2026 09:26:23 +1000 Subject: [PATCH] Audio: Correct usage of miniaudio's dynamic rate adjustment. This affects pitch shifting. The output rate is being modified with ma_data_converter_set_rate(), but then that value is being used in the computation of the output rate the next time SetAudioBufferPitch() which results in a cascade. The correct way to do this is to use an anchored output rate as the basis for the calculation after pitch shifting. In this case, it's the device's sample rate that acts as the anchor. --- src/raudio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/raudio.c b/src/raudio.c index 2de8a4858..0d5bb09c0 100644 --- a/src/raudio.c +++ b/src/raudio.c @@ -723,7 +723,7 @@ void SetAudioBufferPitch(AudioBuffer *buffer, float pitch) // Note that this changes the duration of the sound: // - higher pitches will make the sound faster // - lower pitches make it slower - ma_uint32 outputSampleRate = (ma_uint32)((float)buffer->converter.sampleRateOut/pitch); + ma_uint32 outputSampleRate = (ma_uint32)((float)AUDIO.System.device.sampleRate/pitch); ma_data_converter_set_rate(&buffer->converter, buffer->converter.sampleRateIn, outputSampleRate); buffer->pitch = pitch;