Author Topic: Duplicate stream in multiple outputs  (Read 5595 times)

hukka

  • Posts: 77
Duplicate stream in multiple outputs
« on: 18 Aug '03 - 20:21 »
Let's say I have a non-decoding stream with some effects. Which would be the best way to output this stream to two separate outputs of the same sound card?
I want the same audio to both but I want the volumes adjustable separately for each output. It seems like a waste of CPU time to just create multiple streams and have them play at the same time with different speaker assignments, as the effects and everything would then be calculated multiple times.
Isn't there a more efficient way?

(Background: I'm making a DJ'ing software, with separate Master and Monitor outputs. If I have two songs playing, with one effect each, my poor P2-350 would need to decode both songs and effects twice, and it really doesn't like to do that. Also, keeping the outputs in perfect sync is problematic.)

Ian @ un4seen

  • Administrator
  • Posts: 20424
Re: Duplicate stream in multiple outputs
« Reply #1 on: 18 Aug '03 - 22:05 »
I'd suggest using a decoding channel and 2 custom streams.

That way the decoding (and any DSP/FX you set on the channel) is performed only once. You'll have to do some buffering of the decoded sample data though - when the 1st stream gets some decoded data, it should be buffered so that it's also available for the 2nd stream (you can discard the buffered data when both streams have used it).

hukka

  • Posts: 77
Re: Duplicate stream in multiple outputs
« Reply #2 on: 19 Aug '03 - 13:34 »
Thanks, that works nicely. But I am still having problems with the speaker assignments not working - or only working randomly. I init BASS with the BASS_DEVICE_SPEAKERS flag, then create the streams:

Code: [Select]

chan1 := BASS_StreamCreate(44100, BASS_SPEAKER_FRONT, @StreamProc, 1);
chan2 := BASS_StreamCreate(44100, BASS_SPEAKER_REAR,  @StreamProc, 2);


It occasionally does work as it should, but most of the time it plays the first stream on both front and rear outputs, and the second stream is only barely audible on the right channel of the rear output. I think you or someone suggested that my soundcard (SB Live) is broken, but the audio test in Creative's mixer works just fine. I do have the number of speakers set to 4.
Anyway, if nobody else is having this kind of problem, and you're certain it's not a bug in BASS, I'll gladly buy a new sound card. Just wanted to make sure. I know you're probably quite busy and I apologize for bugging you if it indeed is a fault in my hardware.

Ian @ un4seen

  • Administrator
  • Posts: 20424
Re: Duplicate stream in multiple outputs
« Reply #3 on: 19 Aug '03 - 15:19 »
Can you reproduce the problem at all in the precompiled SPEAKERS example?

Also, do you have to use the BASS_DEVICE_SPEAKERS flag - does BASS not detect that there are possibly multiple speakers available without it?

I don't recall suggesting that your card was broken (but maybe it is :D), but you could check for updated drivers and/or try reinstalling your current drivers. You could even try moving the card to another slot and/or irq.

hukka

  • Posts: 77
Re: Duplicate stream in multiple outputs
« Reply #4 on: 19 Aug '03 - 19:10 »
Thanks Ian! The precompiled SPEAKERS example works perfectly. So I went and removed the BASS_DEVICE_SPEAKERS flag from Bass initialization and voila, it worked. (But I recall adding the flag in there because I couldn't get it to work properly otherwise). So I still really dunno what was wrong with it. Now I'm just hoping it won't break again :oP

One more thing; a question about buffering in case someone can help me. As Ian suggested, I made a decoding channel and two custom streams. I think there's something wrong in my buffering as the second stream crackles, while the first stream plays fine. Here's my STREAMPROC (Delphi 6):

Code: [Select]

function StreamProc(handle:HSTREAM; buffer:Pointer; length:DWORD; user:DWORD): DWORD; stdcall;
var
 buf: ^byte;
 aa: Integer;
begin
 if user = 1 then // for first stream, fill buffer with audio data
 begin
   if length >= decodemaxlength then
   begin
     decodemaxlength := length;
     SetLength(decoded, decodemaxlength);
   end;
   BASS_ChannelGetData(decode, decoded, length);
 end;
 buf := buffer;
 for aa := 0 to length-1 do
 begin    // feed buffer with audio data to stream
   buf^ := decoded[aa];
   Inc(buf);
 end;
 Result := length;
end;

hukka

  • Posts: 77
Re: Duplicate stream in multiple outputs
« Reply #5 on: 20 Aug '03 - 17:12 »
OK, I got it working now by adapting some code from the 4speaker.c example. Works perfectly :o)