24 May '13 - 15:26 *
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: combining multiple channels/shoutcast  (Read 1407 times)
PhilWX
Posts: 2


« on: 5 Dec '04 - 22:12 »
Reply with quoteQuote

Hey gang -

I have having a problem with a Delphi application I'm writing which uses multiple independent BASS channels (multiple threads, one channel per thread).  

I'd like to be able to create a "combined" stream in order to send it to a shoutcast server.  Currently, the program spawns a copy of winamp with the shoutcast plugin, which uses the line input to stream the data and a convoluted method of updating the title (updating the ID3 on a dummy MP3 and telling winamp to play it - hey it works, but only in winamp 2.x).  

Two problems.
1.  The user must interact with the plugin for things like connecting the stream and making changes to the title/genre, etc.
2.  The user must use one soundcard output for all audio to be streamed, and have another for a cue-channel.  

So, I'd like to handle it all internally, and thus I have two questions.

First, the easier one (I hope).  
How can I combine multiple channels into one for purposes of creating a single stream?  
(I've got some code with things I've tried below, perhaps I'm on the right track?).

I think once I get that done, I'm thinking I can use some routines from BASSENC to convert it to mp3 which shoutcast will need.  Which brings me to point 2.  

I've got my program connecting and making the initial handshake with the shoutcast server, but then comes the hard part.  Do I just send a straight mp3 stream to the server?  (I haven't been able to figure it out because I haven't gotten past problem #1 yet).  

Any help would be GREATLY appreciated.

Here's what I've been trying so far, based in part on some sample code posted here for something else I believe (not 100% sure).


TWaveData = array[0..2048] of dWord;

// The following code is contained within the individual thread for a single device:

procedure TAudioDevice.getBuffer( out waveData : TWaveData; out bytesRead : integer );
;
   begin
   if ( channel = 0 ) or ( BASS_ChannelIsActive( channel ) <> BASS_ACTIVE_PLAYING ) then bytesRead := 0
   else
      bytesRead := BASS_ChannelGetData( channel, @waveData, 2048 );
   end;

//  In the common "audio manager" which spawns the devices is the following code:

var
      data        : array of TWaveData;
      values      : array of dWord;
      bytesRead   : array of integer;
      dn          : byte;
      bytes       : integer;
      maxBytes    : integer;
      waveData    : TWaveData;

         for dn := 0 to length( player ) - 1 do
            begin
            player[dn].getBuffer( data[dn], bytesRead[dn] );
            maxBytes := max( maxBytes, bytesRead[dn] );
            end;
         for bytes := 0 to maxBytes div 4 - 1 do
            begin
            for dn := 0 to length( data ) - 1 do
               begin
               if bytes < bytesRead[dn] then values[dn] := data[dn][bytes] else values[dn] := 0;
               end;
            waveData[bytes] := waveSum( values ); // where the combining happens
            end;

But now, I've got chunks of data, and nothing to really do with them ...  

Thanks in advance for any help you can offer - even if it's just to steer me in the right direction.
Logged
Ian @ un4seen
Administrator
Posts: 15270


« Reply #1 on: 7 Dec '04 - 17:31 »
Reply with quoteQuote

First, the easier one (I hope).  
How can I combine multiple channels into one for purposes of creating a single stream?

If the channels are all of the same format (eg. same sample rate), you can simply sum the samples from all the decoding channels (and clip the result). Depending on the number of channels you're mixing, you may want to reduce the level of the mix, so that it's not all clipped/distorted. Here's some example code...

http://www.un4seen.com/forum/?board=1;action=display;threadid=610;start=msg3194#msg3194

I think once I get that done, I'm thinking I can use some routines from BASSENC to convert it to mp3 which shoutcast will need.

That should work, I guess, but you'll probably need to use the BASS_ENCODE_NOHEAD flag and pass the format details via the encoder command-line...

http://www.un4seen.com/forum/?board=1;action=display;threadid=2476

If possible, it may be better to use the LAME_ENC.DLL though.

I've got my program connecting and making the initial handshake with the shoutcast server, but then comes the hard part.  Do I just send a straight mp3 stream to the server?

Dunno, I've never tried Smiley
Logged
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.18 | SMF © 2013, Simple Machines