Possible Bug in AudioTransportSource Read-ahead Buffer


I’m not sure what to call the symptom, maybe “phantom playback”? It should be clearer from the scenario: I’ve got an instance of AudioSourcePlayer whose source is AudioTransportSource whose source in turn is an instance of Kraken’s PositionableMixerAudioSource. Instances of AudioFormatReaderSource are loaded into the mixer to playback audio. First note that if the AudioTransportSource’s read-ahead buffer is zero, there is no problem except that you lose the smoothing of the read-ahead buffer.

Load an instance of AudioFormatReaderSource into the PositionableMixerAudioSource attached to a file with audio at the very beginning. Play it back and notice a silence whose length corresponds to the size of the read-ahead buffer before the audio starts to play. Play it again and notice that audio starts at the very beginning as expected. Now mute or remove the audio and play it back a third time. This time you’ll hear the same audio as the second time for a length of time corresponding to the size of the read-ahead buffer before playing silence as it should. Note this only happens the first time after something is changed in what’s being played back. Playback without change works correctly.

Clearly there is audio not being flushed equal to the size of the read-ahead buffer. To be sure it is in the AudioTransportSource class, I’d have to isolate it a little better, perhaps skipping the mixer and playing back a single AudioFormatReaderSource. But before taking that detour, I wanted to check if anyone has encountered this problem. I’m using a version of AudioTransportSource from a few days ago, but the rest of the code is from around build 652.

Since I can’t see an easy way to flush the read-ahead buffer, it seems one solution is to pre-roll playback by muting playback for a time equal to the size of the read-ahead buffer. Thus if the buffer size were, say, 16K, there would be 16K of silence before playback of anything would start. To make this work, I’d probably have to still fetch from the AudioTransportSource during the pre-roll, just not output, then rewind and fetch from the beginning again.

The above seems a real hack, so any advice or insight into the problem would be greatly appreciated.


When u say “setSource” to an “AudioTransportSource” with readAheadBufferSize the preapareToPlay of the AudioSource is getting called. This intern will call the prepareToPlay method of BufferingAudioSource. Here the BufferingAudioSource will try to read the input source and fill the initial buffer.

So if u call the setSource method before adding any input source BuffreingAudioSource will fill empty buffer for the first time as there is no sources added at the beginning.

Add the sources using addInputSource to the MixerAudioSource first and then use the MixerAudiosource abject to the setSource method.

This Should work fine else there is bug in the Kraken’s PositionableMixerAudioSource class.

I have not gone through Kraken’s PositionableMixerAudioSource class (in fact not downloaded the code ) . I wrote my own class which is derived from PositionableAudiosource which has the MixerAudioSource as the member. It worked fine for me.