Author Topic: iOS - how to flush audio playback buffer after time seek  (Read 87 times)

Rich

  • Posts: 51
Hi

I've been using BASS in my app for years very successfully, and I'm sure that the problem I have is down to my lack of understanding!

I'm playing back audio using a channel inside a mixer.  The channel is using the flag BASS_STREAM_DECODE.

I've had a long standing non-critical bug in the app - when a user is playing audio, pauses, seeks/scrubs to a new position (say the start) then restarts, it plays a short burst from where they were then starts playing at the new position.  I assume this is buffered decoded audio.

I've tried using the following code to clear the buffered audio (which I found after trawling through the forums) before seeking

Code: [Select]
    QWORD currentPos = BASS_ChannelGetPosition(self.channel, BASS_POS_BYTE);
    BASS_ChannelSetPosition(self.channel, currentPos, BASS_POS_BYTE);

I assume that this code seeks the channel to the very end of it's data, effectively flushing it, but this has no effect.

I also tried flushing the mixer with

Code: [Select]
    BASS_ChannelSetPosition(_mixerStream, 0, BASS_POS_BYTE | BASS_POS_MIXER_RESET);

Still no effect (although this makes seeking very responsive).

I assume that as the channel is a decode only channel that the buffer is in the mixer - but it could also be a buffer of decoded data in the channel itself?

Any help or pointers would be much appreciated.

Thanks
Rich





Ian @ un4seen

  • Administrator
  • Posts: 23288
If you're playing through a mixer then flushing the mixer's buffer (using BASS_ChannelSetPosition like you wrote) should ensure that no old data is heard when you resume after seeking. Do you happen to be using BASS_Pause rather than BASS_ChannelPause (on the mixer) to pause? If so, please try the latter, as the old data is probably in the device output's buffer rather than the mixer's.

Rich

  • Posts: 51
Thanks Ian.  I was using BASS_Pause.  I've changed to use BASS_ChannelPause on the mixer and the amount of buffered audio is hugely reduced but it still plays a tiny bit of audio when I restart with

Code: [Select]
BASS_ChannelPlay(_mixerStream, NO);
Changing the restart parameter to YES has no effect.

I also tried with and without the decode channel flushing code too. 

Any other possibilities?

Thanks
Rich

Ian @ un4seen

  • Administrator
  • Posts: 23288
Ah, I notice above that you're using BASS_ChannelSetPosition to set the source's position. You should use BASS_Mixer_ChannelSetPosition instead, as that will also clear the source's resampling buffer in the mixer (which is probably where the remaining tiny burst is coming from).

Rich

  • Posts: 51
Hi Ian,

thanks for the advice, it's now working.  This is the code that I'm using to flush the audio buffer:

Code: [Select]
QWORD currentPos=BASS_Mixer_ChannelGetPosition(self.currentChannelInMixer.channel, BASS_POS_BYTE);
BASS_Mixer_ChannelSetPosition(self.currentChannelInMixer.channel, currentPos, BASS_POS_BYTE);
BASS_ChannelSetPosition(_mixerStream, 0, BASS_POS_BYTE | BASS_POS_MIXER_RESET);

Cheers
Rich