Proper way to play audio in reverse


What exactly is the best way to play audio smoothly going back and forth between forward and reverse (think shuttle/jog wheel)?

I tried creating a buffering audio source that would do a setNextReadPosition to the previous block and then reverse the samples in getNextAudioBlock for going in reverse, but that didn’t even come close to working right. After digging around in the JUCE source trying to figure out exactly how it pulls an audio stream in, I came to the conclusion that all of the audio code is specifically written to play forward and doesn’t really work all that well for going backwards.

Am I just going to have to bite the bullet and build all my own AudioSource classes for smoothly handling forward/reverse, or am I missing something completely obvious?

  • kbj


Well you could write a special AudioFileReader object that wraps another AudioFileReader but pulls the samples out backwards - that way all the existing read-ahead code in the AudioSources would still work…


I did a crude approximation of this by prebuffering an entire file in memory, making a copy of this buffer, reversing the data, created a mixer source going into a resampler source, then I switched between the two buffers with setNextReadPosition at inverse locations. It sort of worked. Sort of.

There’s a problem with changing smoothly when samplesPerBlockExpected is the audio card buffer size. I can get a fairly reasonable jog/shuttle effect, but the stream has to play out until the next block and is rather clicky. If I set it to half the buffer size and have a small audio card buffer size (128 bytes or less), things become pretty smooth. Is there any drawbacks to setting the samplesPerBlockExpected buffer much smaller than the audio card buffer size?

  • kbj