Commit bb4078cc authored by David Reid's avatar David Reid

Fix a bug when reading from a looped data source with a range.

parent efa95d99
...@@ -52269,7 +52269,16 @@ static ma_result ma_data_source_read_pcm_frames_within_range(ma_data_source* pDa ...@@ -52269,7 +52269,16 @@ static ma_result ma_data_source_read_pcm_frames_within_range(ma_data_source* pDa
frameCount = (rangeEnd - cursor); frameCount = (rangeEnd - cursor);
} }
/*
If the cursor is sitting on the end of the range the frame count will be set to 0 which can
result in MA_INVALID_ARGS. In this case, we don't want to try reading, but instead return
MA_AT_END so the higher level function can know about it.
*/
if (frameCount > 0) {
result = pDataSourceBase->vtable->onRead(pDataSourceBase, pFramesOut, frameCount, &framesRead); result = pDataSourceBase->vtable->onRead(pDataSourceBase, pFramesOut, frameCount, &framesRead);
} else {
result = MA_AT_END; /* The cursor is sitting on the end of the range which means we're at the end. */
}
} }
} }
...@@ -52356,8 +52365,8 @@ MA_API ma_result ma_data_source_read_pcm_frames(ma_data_source* pDataSource, voi ...@@ -52356,8 +52365,8 @@ MA_API ma_result ma_data_source_read_pcm_frames(ma_data_source* pDataSource, voi
} }
/* /*
We can determine if we've reached the end by checking the return value of the onRead() We can determine if we've reached the end by checking if ma_data_source_read_pcm_frames_within_range() returned
callback. To loop back to the start, all we need to do is seek back to the first frame. MA_AT_END. To loop back to the start, all we need to do is seek back to the first frame.
*/ */
if (result == MA_AT_END) { if (result == MA_AT_END) {
/* /*
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment