Author Topic: Best way to perform fast transitions between audios (playback)  (Read 8402 times)

DriMarq

  • Guest
Hi,

Please, could anyone say me what is the most efficient way to avoid a perceptible gap ('tic') when playing audio files in sequence?

I'm sure the audio files are nice because when I merge them (in one) I don't notice any gap.

For example, how could I optimize the following code?
Code: [Select]
DWORD s1 = BASS_StreamCreateFile(FALSE, fileName1,0,0,0);
DWORD s2 = BASS_StreamCreateFile(FALSE, fileName2,0,0,0);

BASS_ChannelPlay(s1,FALSE);

while (BASS_ChannelIsActive(s1) )
{
   // Here it is 'locked', but it is just an example.
}

BASS_ChannelPlay(s2,FALSE);

Thanks in advance

DriMarq

  • Guest
The audio transition from XMPlay is very very good (no gap is noticed). Please, does anyone know what BASS resource was used to implement the audio transition in XMPlay?

Ian @ un4seen

  • Administrator
  • Posts: 22167
The way to do perfect gapless playback is to use the same output stream to play all the tracks, ie. feed decoding channels into a custom stream. For simplicity, I'd suggest using BASSmix to do it, something like this...

Code: [Select]
mixer=BASS_Mixer_StreamCreate(44100, 2, BASS_MIXER_END); // create mixer
BASS_ChannelSetSync(mixer, BASS_SYNC_END|BASS_SYNC_MIXTIME, 0, EndSync, 0); // set sync for end

source=BASS_StreamCreateFile(...,BASS_STREAM_DECODE|BASS_SAMPLE_FLOAT); // open 1st source
BASS_Mixer_StreamAddChannel(mixer, source, BASS_STREAM_AUTOFREE); // plug it in (and auto-free it when it ends)

BASS_ChannelPlay(mixer, FALSE); // start playing

...

void CALLBACK EndSync(HSYNC handle, DWORD channel, DWORD data, DWORD user)
{
if (!more_sources) return;
source=BASS_StreamCreateFile(...,BASS_STREAM_DECODE|BASS_SAMPLE_FLOAT); // open next source
BASS_Mixer_StreamAddChannel(mixer, source, BASS_STREAM_AUTOFREE|BASS_MIXER_NORAMPIN); // plug it in
BASS_ChannelSetPosition(mixer, 0); // reset the mixer
}
« Last Edit: 20 Sep '06 - 15:45 by Ian @ un4seen »

DriMarq

  • Guest
Thanks Ian! Your code minimized the gap time... I just noticed a very small 'tic' now.  :)

Was XMPlay implemented with BASSmix? There I don't notice any gap. XMPlay is really fantastic.

Thanks again.

Ian @ un4seen

  • Administrator
  • Posts: 22167
Thanks Ian! Your code minimized the gap time... I just noticed a very small 'tic' now.  :)

Ah, that'll probably be due to the new tracks being ramped-in. That's intended to avoid possible clicks, but in this scenario (gap-less playback), it could actually cause one. I guess an option to disable that is required, so an update is now in the BASSmix download...

   www.un4seen.com/stuff/bassmix.zip

I've updated the example above. Btw, I forgot to make the source channels floating-point (for better performance), so I've added that (BASS_SAMPLE_FLOAT) now too.

Was XMPlay implemented with BASSmix? There I don't notice any gap. XMPlay is really fantastic.

No, XMPlay doesn't use BASSmix, but it does do the same basic thing that I described :)

DriMarq

  • Guest
 :D WOW... Thank you very much!!! :D