Author Topic: Bass routine seems not to clear buffer  (Read 543 times)

murspieg

  • Posts: 20
Bass routine seems not to clear buffer
« on: 8 Oct '23 - 04:04 »
Our project uses the Bass 2.4 routines, with adjustments using Bass_Fx.

After setting up the stream data, ChannelPlay, ChannelPause, ChannelStop play our mp3s just fine.  However, when calling Play after Pause, a few samples are often heard (as a chirp) before the beginning of the file.  It appears the buffer is not getting cleared out.  This happens even when we call ChannelStop prior the ChannelPlay (my understanding is ChanelStop explicitly clears the buffer).  The left over samples are heard on two different machines, with different OS's.

The same calls with the bass 2.3 versions did not do this.

Is there a call to absolutely clear the buffer? Has this problem been seen (and solved) before?
Tnx


Ian @ un4seen

  • Administrator
  • Posts: 25614
Re: Bass routine seems not to clear buffer
« Reply #1 on: 9 Oct '23 - 12:26 »
Please confirm what type of stream you're playing (eg. how you created it), and on what platform(s) you're having the problem. Also, to perhaps narrow it down, does it still happen if you remove BASS_FX?

murspieg

  • Posts: 20
Re: Bass routine seems not to clear buffer
« Reply #2 on: 14 Oct '23 - 20:13 »
0) Platforms showing problem: Windows 7, Windows 10.

1) We were unsuccessful cutting out only BASS_FX calls; what remained wasn't functional, didn't play mp3s

2) Via experimentation, we discovered
- calling STOP prior to PLAY did not clear the buffer: PAUSE then PLAY still yields a chirp.
- but setting Vol to 0 prior to PLAY did prevent the chirp. 

So we have an interim solution, a hack.  If you wish to inspect our calls below to suggest a decent solution, we welcome that.

3) Our calls / how we create the stream

Note: in upgrading from BASS 2.3 to 2.4, we discovered setting Vol before Play (which I think is what we before) caused problems; so we swapped the order.  (Making #2, our hack, even more interesting.)

dance_name = PATH+FILENAME
dance_duration
play
dance_volume
pause

Code in dance_name:
  Call BASS_StreamFree(chan)
  Call BASS_MusicFree(chan)
  chan = BASS_StreamCreateFile(BASSFALSE, StrPtr(passed_in_data), 0, 0, BASS_STREAM_DECODE)
  Call UpdateFX ( [separate calls for bass, mid, treble bands] )
  Call BASS_ChannelGetInfo(chan, info)
  Call BASS_ChannelBytes2Seconds(chan, BASS_ChannelGetLength(chan, BASS_POS_BYTE))
  chan = BASS_FX_TempoCreate(chan, BASS_FX_FREESOURCE) ' create a new decoded & resampled stream [taken from bass_fx demo]
  Call SetDSP_EQ( [various params] )
  Call BASS_ChannelSetAttribute(chan, BASS_ATTRIB_VOL, vol [scaled from 0 to 100])

Code in dance_duration:
  dance_duration = BASS_ChannelBytes2Seconds(chan, BASS_ChannelGetLength(chan, BASS_POS_BYTE))

Code in play:
  Call BASS_ChannelPlay(chan, BASSFALSE)

Code in stop:
  Call BASS_ChannelStop(chan)

Code in pause:
  Call BASS_ChannelPause(chan)






murspieg

  • Posts: 20
Re: Bass routine seems not to clear buffer
« Reply #3 on: 14 Oct '23 - 20:22 »
Noticed a similar post from a looong time ago: https://www.un4seen.com/forum/?topic=6686.msg45069
And see the same suggestion of setting Vol to 0 before play.

would like to know if our calls should be changed so we actually clear the audio buffer.
Tnx

Ian @ un4seen

  • Administrator
  • Posts: 25614
Re: Bass routine seems not to clear buffer
« Reply #4 on: 16 Oct '23 - 12:32 »
At the time of that old thread (in 2007), DirectSound mixing was still being used, and using the BASS_SAMPLE_SOFTWARE flag to disable hardware mixing could sometimes help to overcome driver-related issues, as it apparently did in that case. That doesn't apply these days, eg. there is no hardware DirectSound mixing on Windows 7 or 10, and BASS handles the mixing itself.

To narrow down where the problem lies in your case, please see if you can reproduce it with the pre-compiled BASSTEST.EXE example included in the BASS package (C\BIN folder), ie. "Add" a file and then use the "Play" and "Stop" buttons. If that sounds fine then you can try cutting out BASS_FX from your code for comparison by removing the BASS_FX_TempoCreate call and removing the BASS_STREAM_DECODE flag from your BASS_StreamCreateFile call.

murspieg

  • Posts: 20
Re: Bass routine seems not to clear buffer
« Reply #5 on: 16 Oct '23 - 20:06 »
test.exe works fine.  Will try extracting the bassfx calls again.  Will post again later.  Thanks

murspieg

  • Posts: 20
Re: Bass routine seems not to clear buffer
« Reply #6 on: 20 Oct '23 - 03:47 »
Removed items you indicated, so that BASS_FX is not called.   Even using basic BASS routines, we still get the chirp going from pause to play.

Clearly, something is different in how we're using the routines compared to test.exe, but it might be impossible to figure out.  Our program is 74k lines of code.  Of course, only a small number call BASS routines, but paring the program just to test what's going astray could be too time consuming.

The calls are precisely as specified in my post above.  If nothing seems wrong, then we'll just set Vol to 0 prior to ChannelPlay (coming out of ChannelPause), which avoids our problem.  It's a puzzle, but thanks for looking this over.

Ian @ un4seen

  • Administrator
  • Posts: 25614
Re: Bass routine seems not to clear buffer
« Reply #7 on: 20 Oct '23 - 11:56 »
Please use BASS_GetVersion to confirm what BASS.DLL version is being loaded (perhaps it's an old version that's still using DirectSound mixing). That will return &H02041100 if it's the latest release (2.4.17.0).

murspieg

  • Posts: 20
Re: Bass routine seems not to clear buffer
« Reply #8 on: 20 Oct '23 - 22:27 »
Precisely what I got: 2041100.