Author Topic: 'Seeking' with BassMix  (Read 2210 times)

jasona

  • Posts: 35
'Seeking' with BassMix
« on: 13 Apr '09 - 04:47 »
Hi there,

I realise from the docs that seeking is not possible with BassMix - what are the reasons for this? Do I have any alternative methods to simulate seeking. I currently have a mixer with several channels plugged into it for gapless playback. I would like to seek to hear what the segues sound like without have to listen to the whole thing.

I would really appreciate anyone's help on this.

Happy Easter,
Jason.

Ian @ un4seen

  • Administrator
  • Posts: 20401
Re: 'Seeking' with BassMix
« Reply #1 on: 13 Apr '09 - 15:07 »
To implement seeking, you would need to remove all sources, prepare them (eg. set them to the positions that they should be at that point in the mix), and then re-add them (taking account of the seek position if they have a delayed start). For example, if you have sources A & B, and A starts immediately and B starts after 5 seconds, and you want to seek 2 seconds in, you would set A's position to 2 seconds and B's start position would be 3 seconds...

Code: [Select]
BASS_ChannelSetPosition(sourceA, BASS_ChannelSeconds2Bytes(sourceA, 2), BASS_POS_BYTE); // set A's position to 2 seconds
BASS_Mixer_StreamAddChannel(mixer, sourceA, 0); // start it immediately
BASS_ChannelSetPosition(sourceB, 0, BASS_POS_BYTE); // set B's position to 0
BASS_Mixer_StreamAddChannelEx(mixer, sourceB, 0, BASS_ChannelSeconds2Bytes(mixer, 3), 0); // start it after 3 seconds

More generically, you could do something like this for each source...

Code: [Select]
BASS_Mixer_ChannelRemove(source); // remove the source from the mix
double d=sourcestart-seekpos; // difference between source start and seek positions (in seconds)
if (d<=0) { // source has already started
if (BASS_ChannelSetPosition(source, BASS_ChannelSeconds2Bytes(source, -d), BASS_POS_BYTE) // set the source position to where it should be
BASS_Mixer_StreamAddChannel(mixer, source, 0); // succeeded (eg. not beyond end) so add it to the mix
} else { // haven't reached source yet
BASS_ChannelSetPosition(source, 0, BASS_POS_BYTE); // rewind the source
BASS_Mixer_StreamAddChannelEx(mixer, source, 0, BASS_ChannelSeconds2Bytes(mixer, d), 0); // add it to the mix (with appropriate delay)
}

jasona

  • Posts: 35
Re: 'Seeking' with BassMix
« Reply #2 on: 13 Apr '09 - 16:54 »
Hi Ian,

Thank you for your help. I will try this out and let you know how I get on.

Cheers,
Jason.