From 09aa0d96e1bde89ae882be1ee639b47192a4e95b Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Fri, 14 Jul 2023 05:16:12 -0700 Subject: [PATCH] Work around rounding error with resampler flush Resampler flush may indefinitely produce 1 sample if there is a rounding error with the buffering calculations. Work around this. Signed-off-by: Christopher Snowhill --- Audio/Output/OutputAVFoundation.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Audio/Output/OutputAVFoundation.m b/Audio/Output/OutputAVFoundation.m index 4e63c29ca..2063ba9eb 100644 --- a/Audio/Output/OutputAVFoundation.m +++ b/Audio/Output/OutputAVFoundation.m @@ -169,7 +169,7 @@ - (int)renderInput:(int)amountToRead toBuffer:(float *)buffer { [currentPtsLock lock]; samplesFlushed = (int)rsstate_flush(rsvis, &visTemp[0], 8192); [currentPtsLock unlock]; - if(samplesFlushed) { + if(samplesFlushed > 1) { [visController postVisPCM:visTemp amount:samplesFlushed]; } else { break; @@ -207,7 +207,7 @@ - (int)renderInput:(int)amountToRead toBuffer:(float *)buffer { [currentPtsLock lock]; samplesFlushed = (int)rsstate_flush(rsvis, &visTemp[0], 8192); [currentPtsLock unlock]; - if(samplesFlushed) { + if(samplesFlushed > 1) { [visController postVisPCM:visTemp amount:samplesFlushed]; } else { break; @@ -806,7 +806,7 @@ - (int)makeBlockBuffer:(CMBlockBufferRef *)blockBufferOut { [currentPtsLock lock]; samplesRendered = rsstate_flush(rsold, &rsTempBuffer[0], 4096); [currentPtsLock unlock]; - if(!samplesRendered) { + if(samplesRendered < 4096) { rsstate_delete(rsold); rsold = NULL; rsDone = YES;