From 3d24168ba75fe62d928a2886cbf08706a4e22250 Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Fri, 14 Jul 2023 05:15:14 -0700 Subject: [PATCH] Fix clipped sample rate changing between files When the clipped sample rate changes, the resampler needs to be restarted. This was previously failing because the target sample rate wasn't changing. Signed-off-by: Christopher Snowhill --- Audio/Output/OutputAVFoundation.h | 2 ++ Audio/Output/OutputAVFoundation.m | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Audio/Output/OutputAVFoundation.h b/Audio/Output/OutputAVFoundation.h index 98f107a19..67d8f9b8b 100644 --- a/Audio/Output/OutputAVFoundation.h +++ b/Audio/Output/OutputAVFoundation.h @@ -42,6 +42,8 @@ using std::atomic_long; BOOL rsDone; void *rsstate, *rsold; + + double lastClippedSampleRate; void *rsvis; double lastVisRate; diff --git a/Audio/Output/OutputAVFoundation.m b/Audio/Output/OutputAVFoundation.m index 2dcd866e8..4e63c29ca 100644 --- a/Audio/Output/OutputAVFoundation.m +++ b/Audio/Output/OutputAVFoundation.m @@ -85,6 +85,10 @@ - (int)renderInput:(int)amountToRead toBuffer:(float *)buffer { format.mSampleRate = maxSampleRate; dstRate = maxSampleRate; formatClipped = YES; + if(srcRate != lastClippedSampleRate) { + lastClippedSampleRate = srcRate; + streamFormatStarted = NO; + } } if(!streamFormatStarted || config != realStreamChannelConfig || memcmp(&newFormat, &format, sizeof(format)) != 0) { [currentPtsLock lock]; @@ -817,7 +821,7 @@ - (int)makeBlockBuffer:(CMBlockBufferRef *)blockBufferOut { rsDone = NO; realStreamFormat = newFormat; realStreamChannelConfig = newChannelConfig; - streamFormatChanged = YES; + [self updateStreamFormat]; } } @@ -962,6 +966,8 @@ - (BOOL)setup { rsDone = NO; rsstate = NULL; rsold = NULL; + + lastClippedSampleRate = 0.0; rsvis = NULL; lastVisRate = 44100.0;