From e6124335d153965dfa3357867f221e567054a6b5 Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Thu, 13 Jan 2022 23:02:01 -0800 Subject: [PATCH] Cog Audio: Change output callback to always retry reading for sample data until the requested buffer is filled, or until the playback either ends or is torn down. This prevents gaps when the preceding ring buffer wraps around. --- Audio/Output/OutputCoreAudio.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Audio/Output/OutputCoreAudio.m b/Audio/Output/OutputCoreAudio.m index 834b69f20..24b73ae53 100644 --- a/Audio/Output/OutputCoreAudio.m +++ b/Audio/Output/OutputCoreAudio.m @@ -361,7 +361,9 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const amountRead = [outputController readData:(readPointer) amount:amountToRead]; - if ((amountRead < amountToRead) && [outputController endOfStream] == NO) //Try one more time! for track changes! + // Try repeatedly! Buffer wraps can cause a slight data shortage, as can + // unexpected track changes. + while ((amountRead < amountToRead) && [outputController endOfStream] == NO && [outputController shouldContinue] == YES) { int amountRead2; //Use this since return type of readdata isnt known...may want to fix then can do a simple += to readdata amountRead2 = [outputController readData:(readPointer+amountRead) amount:amountToRead-amountRead];