Skip to content

Commit

Permalink
Work around rounding error with resampler flush
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
kode54 committed Jul 14, 2023
1 parent 3d24168 commit 09aa0d9
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Audio/Output/OutputAVFoundation.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 09aa0d9

Please sign in to comment.