Skip to content

Commit

Permalink
Fix clipped sample rate changing between files
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
kode54 committed Jul 14, 2023
1 parent 323a554 commit 3d24168
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Audio/Output/OutputAVFoundation.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ using std::atomic_long;

BOOL rsDone;
void *rsstate, *rsold;

double lastClippedSampleRate;

void *rsvis;
double lastVisRate;
Expand Down
8 changes: 7 additions & 1 deletion Audio/Output/OutputAVFoundation.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -817,7 +821,7 @@ - (int)makeBlockBuffer:(CMBlockBufferRef *)blockBufferOut {
rsDone = NO;
realStreamFormat = newFormat;
realStreamChannelConfig = newChannelConfig;
streamFormatChanged = YES;
[self updateStreamFormat];
}
}

Expand Down Expand Up @@ -962,6 +966,8 @@ - (BOOL)setup {
rsDone = NO;
rsstate = NULL;
rsold = NULL;

lastClippedSampleRate = 0.0;

rsvis = NULL;
lastVisRate = 44100.0;
Expand Down

0 comments on commit 3d24168

Please sign in to comment.