From db33254cebf9a385a125d11177445bc2d44b1235 Mon Sep 17 00:00:00 2001 From: David Reid Date: Sat, 17 Nov 2018 13:24:56 +1000 Subject: [PATCH] Core Audio: Send silence to the client in unsupported cases. --- mini_al.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/mini_al.h b/mini_al.h index 2706d938..c085c5d9 100644 --- a/mini_al.h +++ b/mini_al.h @@ -15011,7 +15011,19 @@ OSStatus mal_on_input__coreaudio(void* pUserData, AudioUnitRenderActionFlags* pA // This case is where the number of channels in the output buffer do not match our internal channels. It could mean that it's // not interleaved, in which case we can't handle right now since mini_al does not yet support non-interleaved streams. - // TODO: Call mal_device__send_frames_to_client() with silence. + mal_uint8 silentBuffer[4096]; + mal_zero_memory(silentBuffer, sizeof(silentBuffer)); + + mal_uint32 framesRemaining = frameCount; + while (framesRemaining > 0) { + mal_uint32 framesToSend = sizeof(silentBuffer) / mal_get_bytes_per_frame(pDevice->internalFormat, pDevice->internalChannels); + if (framesToSend > framesRemaining) { + framesToSend = framesRemaining; + } + + mal_device__send_frames_to_client(pDevice, framesToSend, silentBuffer); + framesRemaining -= framesToSend; + } #if defined(MAL_DEBUG_OUTPUT) printf(" WARNING: Outputting silence. frameCount=%d, mNumberChannels=%d, mDataByteSize=%d\n", frameCount, pRenderBufferList->mBuffers[iBuffer].mNumberChannels, pRenderBufferList->mBuffers[iBuffer].mDataByteSize);