From 99fea233e81d7388d4fdb6936d831f6ff239173b Mon Sep 17 00:00:00 2001 From: David Reid Date: Sun, 7 Jun 2020 11:51:59 +1000 Subject: [PATCH] Fix a bug when mixing a data source using mmap mode. This was causing mmaped data sources to not loop if they coincidentally reached the end at the same time as the final output frame was written. --- research/ma_mixing.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/research/ma_mixing.h b/research/ma_mixing.h index 257c88e5..45def344 100644 --- a/research/ma_mixing.h +++ b/research/ma_mixing.h @@ -2557,10 +2557,14 @@ static ma_result ma_mixer_mix_data_source_mmap(ma_mixer* pMixer, ma_data_source* result = ma_data_source_unmap(pDataSource, framesMapped); /* Do this last because the result code is used below to determine whether or not we need to loop. */ } + totalFramesProcessed += framesToProcess; + pRunningAccumulationBuffer = ma_offset_ptr(pRunningAccumulationBuffer, framesToProcess * ma_get_accumulation_bytes_per_frame(pMixer->format, pMixer->channels)); + if (result != MA_SUCCESS) { if (result == MA_AT_END) { if (loop) { ma_data_source_seek_to_pcm_frame(pDataSource, 0); + result = MA_SUCCESS; /* Make sure we don't return MA_AT_END which will happen if we conicidentally hit the end of the data source at the same time as we finish outputting. */ } else { break; /* We've reached the end and we're not looping. */ } @@ -2568,9 +2572,6 @@ static ma_result ma_mixer_mix_data_source_mmap(ma_mixer* pMixer, ma_data_source* return result; /* An error occurred. */ } } - - totalFramesProcessed += framesToProcess; - pRunningAccumulationBuffer = ma_offset_ptr(pRunningAccumulationBuffer, framesToProcess * ma_get_accumulation_bytes_per_frame(pMixer->format, pMixer->channels)); } return result;