24 May '13 - 14:17 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Reply  |  Print  
Author Topic: Best way to perform fast transitions between audios (playback)  (Read 5039 times)
DriMarq
Guest
« on: 19 Sep '06 - 01:18 »
Reply with quoteQuote

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?
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
Logged
DriMarq
Guest
« Reply #1 on: 19 Sep '06 - 02:16 »
Reply with quoteQuote

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?
Logged
Ian @ un4seen
Administrator
Posts: 15270


« Reply #2 on: 19 Sep '06 - 15:57 »
Reply with quoteQuote

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...

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 » Logged
DriMarq
Guest
« Reply #3 on: 19 Sep '06 - 16:27 »
Reply with quoteQuote

Thanks Ian! Your code minimized the gap time... I just noticed a very small 'tic' now.  Smiley

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

Thanks again.
Logged
Ian @ un4seen
Administrator
Posts: 15270


« Reply #4 on: 20 Sep '06 - 15:47 »
Reply with quoteQuote

Thanks Ian! Your code minimized the gap time... I just noticed a very small 'tic' now.  Smiley

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 Smiley
Logged
DriMarq
Guest
« Reply #5 on: 22 Sep '06 - 02:04 »
Reply with quoteQuote

 Cheesy WOW... Thank you very much!!! Cheesy
Logged
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.18 | SMF © 2013, Simple Machines