multiple streams

Started by j.schleipen,

j.schleipen

:-[
Hi !  Can anybody help out here ?
I'm writing a simple MP3 player application using Delphi 6.
I succeeded in loading and play a MP3 file. No problem.
BUT: if I want to start a new MP3 file from my playlist, I want to fade-out the previous one and during this fade-out, gradually fade-in fade-in the new MP3 file, with some timing overlap. How can I succeed in doing this ? Is there a standard procedure incorporated in BASS ?
Thanx !
Jean Schleipen.

bigjim

When you make a stream and get the handle of it into a dword- ie. stream_handle1 all you do is create another one and put the handle into ie. stream_handle2.

Check out the Bass_ChannelSlideAttributes in the bass help file and if you put a timer on your form you can continually load and play between the two files by examining their position and Bass_IsChannelSliding.

If it is still not clear I can post a code example for you?

Jean

Hi,

Thankx for your quick reply.  I think it is clear, but I'm not sure yet. I will give it a try.

If it's not too much effort for you, I'd appreciate if you could send me some sample program/code, via e-mail, or through the BASS forum ...

Cheers,
Jean

==============================================
Jean Schleipen
e-mail: j.j.h.b.schleipen@hccnet.nl
==============================================

bigjim

Ok..

New form and add:
a button (button1)
2 timers (timer1, timer2) set their interval to about 50 and enabled to false then...

in the var at the top of your project add

 
  songs : array[0..4] of string; // array of files
  handles : array[0..1] of DWORD; // two handles
  finish : array[0..1] of float; // two finish times
  cross_f_l : integer; // length of cross fade
  curfile, curhandle, nofiles : integer; // misc ints
  done_it : boolean; // done the fade yet

Under the button put

handles[0] := Bass_StreamCreateFile(FALSE, pChar(songs[0]), 0, 0, 0); // Open the first file
finish[0] := Bass_ChannelBytes2Seconds(handles[0], Bass_StreamGetLength(handles[0]))-cross_f_l; // get the finish time
Bass_StreamPlay(handles[0], FALSE, 0); // Play the file
timer1.Enabled := true; // start checking the files position

under form create put

songs[0] := 'mp31.mp3';/// Get a set of songs
songs[1] := 'mp32.mp3';
songs[2] := 'mp33.mp3';
songs[3] := 'mp34.mp3';
songs[4] := 'mp35.mp3';
nofiles := 5; // no of songs
////////////
done_it := false; // hasnt faded yet
///////////
cross_f_l := 5; // cross fade length is 5 seconds
curfile := 0; // on file 1
curhandle := 0; // on handle 0
///////////
Bass_Init(-1, 44100, 0, form1.handle); // init bass on default device
Bass_Start; // Start bass

under timer 1 put

if (Bass_ChannelBytes2Seconds(handles[curhandle], Bass_ChannelGetPosition(handles[curhandle])) >= finish[curhandle]) and (done_it = false) then
begin
  done_it := true; // started the fade
  Bass_ChannelSlideAttributes(handles[curhandle], -1, -2, -101, cross_f_l*1000); // slide the playing files volume down
  curhandle := curhandle + 1; // use the next available handle
  if curhandle = 2 then curhandle := 0;
  curfile := curfile + 1; // open the next file
  if curfile = nofiles then curfile := 0;
  handles[curhandle] := Bass_StreamCreateFile(FALSE, pChar(songs[curfile]), 0, 0, 0); // open the new file
  finish[curhandle] := Bass_ChannelBytes2Seconds(handles[curhandle], Bass_StreamGetLength(handles[curhandle]))-cross_f_l; // get the new finish length
  Bass_ChannelSetAttributes(handles[curhandle], -1, 0, -101); // Set the new files volume to 0
  Bass_StreamPlay(handles[curhandle], FALSE, 0); // Play the new file
  Bass_ChannelSlideAttributes(handles[curhandle], -1, 100, -101, cross_f_l*1000); // Slide the new files volume up to 100
  timer2.enabled := true; // Start checking for the original file to finish
end;

under timer2 put

var
  hand_to_check : integer; // handle to check
begin
hand_to_check := curhandle - 1; // check the previous handle
if hand_to_check = -1 then hand_to_check := 1;
if Bass_ChannelIsActive(handles[hand_to_check]) = 0 then // if the files finished
begin
  done_it := false; // hasnt slided the new file yet
  timer2.enabled := false; // stop checking for previous file to finish
end;
end;

This code will play through the files in the songs array and then back to the begininning and loop, so on.
have fun.

bdinnocenzo (Guest)

I just found bass.dll in the past two days and have begun looking at it closley.  I see where you can have two streams, but is it possible to have more?

My appplication -- which currently uses MS Media Player Control -- is has two players (A & B) to play tunes and allows fading to and from but also uses 6 other players which stay preloaded with sound effects/sweepers, jingles whatever.  The problem with the MS control is that it is slow and sloppy to work with.  When it loops on a file it has a pause between the stop and the next start.

Ideally I would like to find an OCX control that's a player -- no visible portion needed, just access to the usual suff (load, play, pause, stop, vol up/down, position, etc.).  I've looked around and I guess for $200 or $400 I can buy one, but my app is freeware mostly for me and a few others.

So, can I have up to a dozen streams playing (or at least cued) with bass.dll?  Does anyone know of an OCX control that already does this that won't break my bank account?!?!?!

Thanks,

-Bill

P.S. App is called DeeJay and can be found at //www.laidbackradio.net

Chris

Yes of cource you can have more streams....
I think you mean  2 Streams for the players and 6 streams for the SamplePlayer (JinglePlayer).
Directx has the no Limitation....
Greets Chris


Chris


bdinnocenzo (Guest)

Thanks!  You must be using DirectX to reply -- that's why I got two!   :laugh:

-Bill