From cf024cb71fc0dc534ab5440429898cb481f7a5a4 Mon Sep 17 00:00:00 2001 From: David Reid Date: Sat, 1 Jan 2022 07:42:42 +1000 Subject: [PATCH] Fix an error in the simple_mixing example. Public issue https://github.com/mackron/miniaudio/issues/388 --- examples/simple_mixing.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/examples/simple_mixing.c b/examples/simple_mixing.c index 5d846048..e4c81b05 100644 --- a/examples/simple_mixing.c +++ b/examples/simple_mixing.c @@ -48,21 +48,22 @@ ma_uint32 read_and_mix_pcm_frames_f32(ma_decoder* pDecoder, float* pOutputF32, m contents of the output buffer by simply adding the samples together. You could also clip the samples to -1..+1, but I'm not doing that in this example. */ + ma_result result; float temp[4096]; ma_uint32 tempCapInFrames = ma_countof(temp) / CHANNEL_COUNT; ma_uint32 totalFramesRead = 0; while (totalFramesRead < frameCount) { - ma_uint32 iSample; - ma_uint32 framesReadThisIteration; + ma_uint64 iSample; + ma_uint64 framesReadThisIteration; ma_uint32 totalFramesRemaining = frameCount - totalFramesRead; ma_uint32 framesToReadThisIteration = tempCapInFrames; if (framesToReadThisIteration > totalFramesRemaining) { framesToReadThisIteration = totalFramesRemaining; } - framesReadThisIteration = (ma_uint32)ma_decoder_read_pcm_frames(pDecoder, temp, framesToReadThisIteration, NULL); - if (framesReadThisIteration == 0) { + result = ma_decoder_read_pcm_frames(pDecoder, temp, framesToReadThisIteration, &framesReadThisIteration); + if (result != MA_SUCCESS || framesReadThisIteration == 0) { break; } @@ -71,9 +72,9 @@ ma_uint32 read_and_mix_pcm_frames_f32(ma_decoder* pDecoder, float* pOutputF32, m pOutputF32[totalFramesRead*CHANNEL_COUNT + iSample] += temp[iSample]; } - totalFramesRead += framesReadThisIteration; + totalFramesRead += (ma_uint32)framesReadThisIteration; - if (framesReadThisIteration < framesToReadThisIteration) { + if (framesReadThisIteration < (ma_uint32)framesToReadThisIteration) { break; /* Reached EOF. */ } }