Author Topic: Clearing buffer when paused?  (Read 5031 times)

smoodilo

  • Guest
Clearing buffer when paused?
« on: 23 Mar '12 - 10:20 »
Situation:

- I pause a track and move the position within' a track with SetPosition
- If I press play now, I sometimes hear 'garbage' for a split second at the beginning.

I think that what I hear are some 'leftovers' in the buffer from the position where I previously was.

Is there a way to pause the track, and clear the buffer?

Or even better: Refresh the buffer after SetPosition?




Ian @ un4seen

  • Administrator
  • Posts: 20437
Re: Clearing buffer when paused?
« Reply #1 on: 23 Mar '12 - 17:57 »
Are you playing the track via a mixer, eg. BASS_Mixer_StreamAddChannel? If so, you can clear the mixer's output buffer by calling BASS_ChannelPlay (with restart=TRUE) or BASS_ChannelSetPosition (with pos=0) on it.

If it's just normal playback (eg. using BASS_ChannelPlay), please state what OS you are using.

SoundMike

  • Posts: 331
Re: Clearing buffer when paused?
« Reply #2 on: 24 Mar '12 - 01:19 »
I've had a similar issue and so use BASS_ChannelPlay with restart=TRUE to overcome it. However, since that resets the position back to the start of the file I then have to immediately follow this with BASS_ChannelSetPosition. I get reports of this causing a glitch in playback, which I think is due to (a) a brief break in playback because I cannot do the reposition until AFTER issuing the 'play' command, and/or (b) a brief burst of sound from the start of the file that occurs between 'play' and 'set position'.

Something I am going to try in this scenario is to issue BASS_ChannelStop instead of BASS_ChannelPause as I understand this will clear the buffer. I can then follow this with a BASS_ChannelSetPosition followed by BASS_ChannelPlay (restart=FALSE). Is this a sensible solution?

smoodilo

  • Guest
Re: Clearing buffer when paused?
« Reply #3 on: 24 Mar '12 - 07:18 »
@ Ian
No I don't you use a mixer channel. I'm developing under XP to make sure that everything is backward compatible with .NET framework 2.
I really do think that after a SetPosition the buffer should be cleared/ recreated.
If I use the above method on a silent part of the track I don't hear any garbled sound when I press play again. This rules out that it's the soundcard clicking (which is another issue by the way).

@SoundMike:
What you can do to check this, is take a track with a slow fade-in beginning. If you press ChannelStop in a loud part, and then ChannelPlay again (meaning the track starts from the beginning) everything should be without clicks if the buffers are freed.

If I do this with ChannelPause, ChanelSetPosition(handle,0) and ChannelPlay, I hear the garbling.


stevenmmm

  • Posts: 114
Re: Clearing buffer when paused?
« Reply #4 on: 24 Mar '12 - 07:23 »
Something I am going to try in this scenario is to issue BASS_ChannelStop instead of BASS_ChannelPause as I understand this will clear the buffer. I can then follow this with a BASS_ChannelSetPosition followed by BASS_ChannelPlay (restart=FALSE). Is this a sensible solution?
this is the approach i ended up adopting to work around this issue and it works fine

smoodilo

  • Guest
Re: Clearing buffer when paused?
« Reply #5 on: 24 Mar '12 - 14:47 »
I don't get this?
Calling Bass_channelStop unloads the stream and I have to do StreamCreate again??

What am I missing?






smoodilo

  • Guest
Re: Clearing buffer when paused?
« Reply #6 on: 24 Mar '12 - 15:20 »
Normally I would do:
Bass_Channelpause, followed by Bass.ChannelSetPosition

To clean the buffer like you suggested I tried:
Bass_channelStop, Followed by Bass.ChannelSetPosition, followed by Bass_Channelpause

...Which should give me the same result.

But I don't think I can call Bass_channelPause straight away. I would first have to call ChannelPlay. And this would garble the buffer again. So can you please explain a little more how you did this?








SoundMike

  • Posts: 331
Re: Clearing buffer when paused?
« Reply #7 on: 24 Mar '12 - 21:53 »
smoodilo, the suggested solution is this:

For "pause a track and move the position within a track with SetPosition", use BASS_ChannelStop followed by BASS_ChannelSetPosition. This will effectively 'pause playback and clear buffer', and then reposition at the required new position.

Then, for "press play now", just use BASS_ChannelPlay.

Thanks, stevenmmm. I'll try this in my app over the next few days.