mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-22 00:06:59 +02:00
Fix a bug with the audio ring buffer data source.
This commit is contained in:
+23
-1
@@ -63597,7 +63597,29 @@ MA_API ma_uint32 ma_ring_buffer_capacity(const ma_ring_buffer* pRingBuffer)
|
||||
|
||||
static ma_result ma_audio_ring_buffer__data_source_on_read(ma_data_source* pDataSource, void* pFrames, ma_uint64 frameCount, ma_uint64* pFramesRead)
|
||||
{
|
||||
return ma_audio_ring_buffer_read_pcm_frames((ma_audio_ring_buffer*)pDataSource, pFrames, frameCount, pFramesRead);
|
||||
ma_audio_ring_buffer* pRingBuffer = (ma_audio_ring_buffer*)pDataSource;
|
||||
ma_result result;
|
||||
ma_uint64 framesRead;
|
||||
|
||||
|
||||
result = ma_audio_ring_buffer_read_pcm_frames(pRingBuffer, pFrames, frameCount, &framesRead);
|
||||
if (result != MA_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
There is no notion of an "end" in a ring buffer. If we didn't have enough data to fill the requested frame
|
||||
count we'll need to pad with silence. If we don't do this, framesRead might equal 0 which will result in
|
||||
the data source layer at a higher level translating this to MA_AT_END which is incorrect for a ring buffer.
|
||||
*/
|
||||
if (framesRead < frameCount) {
|
||||
ma_silence_pcm_frames(ma_offset_pcm_frames_ptr(pFrames, framesRead, pRingBuffer->format, pRingBuffer->channels), (frameCount - framesRead), pRingBuffer->format, pRingBuffer->channels);
|
||||
framesRead = frameCount;
|
||||
}
|
||||
|
||||
*pFramesRead = framesRead;
|
||||
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
static ma_result ma_audio_ring_buffer__data_source_on_get_data_format(ma_data_source* pDataSource, ma_format* pFormat, ma_uint32* pChannels, ma_uint32* pSampleRate, ma_channel* pChannelMap, size_t channelMapCap)
|
||||
|
||||
Reference in New Issue
Block a user