Skip to content

Commit

Permalink
Minor Bug Fix: Handle Rubber Band buffer latency
Browse files Browse the repository at this point in the history
We implement this function to return the current latency buffered,
regardless of how often this function may be called. In practice, it is
only called on track completion, to time the reporting of the next track
display. We also avoid using Rubber Band's latency function, as in most
cases, this function will be called from other threads, and also, it
currently only gets called after Rubber Band has been emptied out, so it
would otherwise calculate zero samples buffered. And thirdly, Rubber
Band's latency function doesn't account for the buffered samples already
removed from it and waiting to be fed out.

Signed-off-by: Christopher Snowhill <[email protected]>
  • Loading branch information
kode54 committed Feb 16, 2025
1 parent f251c91 commit 44b8aa0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Audio/Chain/DSP/DSPRubberbandNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
- (void)process;
- (AudioChunk * _Nullable)convert;

- (double)secondsBuffered;

@end

#endif /* DSPRubberbandNode_h */
16 changes: 16 additions & 0 deletions Audio/Chain/DSP/DSPRubberbandNode.m
Original file line number Diff line number Diff line change
Expand Up @@ -513,4 +513,20 @@ - (AudioChunk *)convert {
return outputChunk;
}

- (double)secondsBuffered {
double rbBuffered = 0.0;
if(ts) {
// We don't use Rubber Band's latency function, because at least in Cog's case,
// by the time we call this function, and also, because it doesn't account for
// how much audio will be lopped off at the end of the process.
//
// Tested once, this tends to be close to zero when actually called.
rbBuffered = stretchIn - stretchOut;
if(rbBuffered < 0.0) {
rbBuffered = 0.0;
}
}
return [buffer listDuration] + rbBuffered;
}

@end

0 comments on commit 44b8aa0

Please sign in to comment.