19 Jun '13 - 17:14 *
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: Mix incoming Icecast stream and own broadcast to new broadcast  (Read 2058 times)
eltimmie
Posts: 6


« on: 22 Jul '08 - 07:46 »
Reply with quoteQuote

Hi all Wink

What I would like to do is the following:

- Listen to an Icecast stream
- mix this stream with an own recording from microphone
- send mixed stream to Icecast server as a new broadcast

Is this possible ? I suppose so but can't quite figure out how to set this up. I already have been succesful in both setting up a stream to a icecast server and listening to one but im not sure how to mix the channels(using bassmix i suppose)

Any help or quick examples (i'm using bass.net C#) would be much appreciated. Thanks
Logged
radio42
Posts: 4030


« Reply #1 on: 22 Jul '08 - 11:19 »
Reply with quoteQuote

Yes, with the BASSmix add-on you can do so:
a) you need to create a mixer stream (which you then use to stream TO Icecast)
b) you need to setup a recording (without a RECPROC, so that it is decoding only)
c) you need to setup a decoding stream to 'listen' to your Icecast stream
- then add b) and c) as sources to the mixer
Logged
eltimmie
Posts: 6


« Reply #2 on: 22 Jul '08 - 14:21 »
Reply with quoteQuote

Thanks for your reply.. I currently have it setup as follows:

       public Boolean startBroadcast(string name_mountpoint, string broadcaster_fullname)
        {
         //initialise recording:
         _recProc = new RECORDPROC(RecordingHandler);
         //Start recording op 44,1kHz stereo:
         if (_recHandle != 0) Bass.BASS_ChannelStop(_recHandle);     
         //_recHandle = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_DEFAULT, _recProc, IntPtr.Zero);
         _recHandle = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_DEFAULT, null, IntPtr.Zero);
         if (_recHandle == Bass.FALSE)
         {
             MessageBox.Show("Unfortunatly there was an error initialising the voice recording functionality: "+Bass.BASS_ErrorGetCode()+".\n\nPlease restart and try again.");
             return (false);
         }

         //create main mixing channel/stream:
         _mixerStream = BassMix.BASS_Mixer_StreamCreate(44100, 2, BASSFlag.BASS_DEFAULT);
         BassMix.BASS_Mixer_StreamAddChannel(_mixerStream, _recHandle, BASSFlag.BASS_STREAM_AUTOFREE | BASSFlag.BASS_MIXER_DOWNMIX);

         IBaseEncoder encoder = null;
         IStreamingServer IceCastServer = null;

         //EncoderLAME lame = new EncoderLAME(_recHandle);
         EncoderLAME lame = new EncoderLAME(_mixerStream);
         lame.InputFile = null;
         lame.OutputFile = null;
         lame.LAME_Bitrate = 128;
         lame.LAME_Mode = EncoderLAME.LAMEMode.Default;
         lame.LAME_TargetSampleRate = (int)EncoderLAME.SAMPLERATE.Hz_44100;
         lame.LAME_Quality = EncoderLAME.LAMEQuality.Speed;
         lame.EncoderDirectory = Application.StartupPath;
         if (lame.EncoderExists) encoder = lame;
         else
         {
             MessageBox.Show("The file LAME.EXE can not be found, the installation might be corrupt !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return (false);
         }

         //de stream naar Icecast instellen:
         ICEcast icecast = new ICEcast(encoder, true);              //True: bass.dll handelt alles af
         icecast.ServerAddress = _serverAdress;
         icecast.ServerPort = _serverPort;
        ...
        ...

The code is followed by an Autoconnect() ofcourse. However the stream is setup but it is completely silent since I changed _RecProc to NULL(disabled callback). Im a supposed to do something else now the callback is gone, or am I missing something else ?
(the example is just settings up a broadcast to Icecast via a mixing channel. not adding a second listening channel as of yet)
Logged
radio42
Posts: 4030


« Reply #3 on: 22 Jul '08 - 14:35 »
Reply with quoteQuote

So farr all good.
But you would also need to play the "_mixerStream"  after it was created ;-)
So just add "Bass.BASS_ChannelPlay(_mixerStream);" after the mixer creation.
Logged
eltimmie
Posts: 6


« Reply #4 on: 23 Jul '08 - 10:30 »
Reply with quoteQuote

So farr all good.
But you would also need to play the "_mixerStream"  after it was created ;-)
So just add "Bass.BASS_ChannelPlay(_mixerStream);" after the mixer creation.

Thanks for the help ! It looks like everything's working fine now Wink

1 question remains: since I use Bass.BASS_ChannelPlay to start the (new) mixed channel the stream is also outputted to the speakers. Because the machine is recording too I get horrible loopback squeeks Wink local output to speakers was silent when I used the callback way. Is there any way to play the _mixerstream without outputting to the speakers ?

Again, thanks for the help
Logged
radio42
Posts: 4030


« Reply #5 on: 23 Jul '08 - 11:29 »
Reply with quoteQuote

You could e.g. 'mute' the output of the mixerStream (see BASS_ChannelSetAttribute and set the VOL to 0).

Or you could also use a decoding mixerStream, but then you would have to call BASS_ChannelGetData frequently enough by yourself (manually) to get the sources and all DSPs (like the encoders) processed.
So I guess the first is easier ;-)
Logged
eltimmie
Posts: 6


« Reply #6 on: 24 Jul '08 - 12:49 »
Reply with quoteQuote

OK. Im getting there, although it is piece by piece, bit by bit  Grin

Creating a mixing channel and adding the recording now works fine.. But I got some trouble adding the decoding stream(step C in your reply) to the mixer. I suppose that has to be a decoding channel too ?

        public void startListen(string mountpoint, Boolean interviewmode)
        {
         if (listening) return;

         string url = "http://"+_serverAdress + ":"+_serverPort+@"/" + mountpoint;
         Bass.BASS_StreamFree(_Stream);
         // create the stream
         //user callback init:
         myStreamCreateURL = new DOWNLOADPROC(StreamReceiveHandler);
         _Stream = Bass.BASS_StreamCreateURL(url, 0, BASSFlag.BASS_STREAM_STATUS & BASSFlag.BASS_STREAM_AUTOFREE, myStreamCreateURL, IntPtr.Zero);
         //kunnen we niet connecten? eruit.
         if (_Stream == 0) return;

         //_tagInfo = new TAG_INFO(url);

         // set a sync to detect when the stream ends..
         mySync = new SYNCPROC(MetaSync);
         Bass.BASS_ChannelSetSync(_Stream, BASSSync.BASS_SYNC_END, 0, mySync, IntPtr.Zero);
         
         // play the stream
         Bass.BASS_ChannelPlay(_Stream, false);

         if (interviewmode) BassMix.BASS_Mixer_StreamAddChannel(_mixerStream, _Stream, BASSFlag.BASS_STREAM_AUTOFREE | BASSFlag.BASS_MIXER_DOWNMIX);

         listening = true;
        }

This is the code I currently use. However, I suppose I need to remove the downloadproc and call Channelgetdata() in a loop to process ?
Logged
radio42
Posts: 4030


« Reply #7 on: 24 Jul '08 - 13:35 »
Reply with quoteQuote

No - not so complex ;-)

1. a DOWNLOADPROC is not really need and can be removed
2. in your code the DECODE flag in missing in the BASS_StreamCreateURL call
3. no need to play the url stream, instead add it to your mixer!
   (the mixer will take care of the BASS_ChanellGetData calls, so you don't need to do that ;-)

Something like this should do the job:
streamUrl = Bass.BASS_StreamCreateURL(filename, 0, BASSFlag.BASS_STREAM_DECODE, null, IntPtr.Zero);
BassMix.BASS_Mixer_StreamAddChannel(_mixerStream, streamUrl, BASSFlag.BASS_MIXER_DOWNMIX);
Logged
eltimmie
Posts: 6


« Reply #8 on: 24 Jul '08 - 13:40 »
Reply with quoteQuote

Maybe I was too quick in posting my last question. I figured it out by myself 5 minuts ago  Cheesy

Ah well, at least I now really get my hands around the whole process. Bass is great  Tongue

Everything is working now like I wanted it to be. You've really been of great help.. thanks !!

For topic completeness, i'ver added my code to get get step C working:

        public void startListen_interviewedclient(string mountpoint)
        {
         if (listening) return;

         string url = "http://" + _serverAdress + ":" + _serverPort + @"/" + mountpoint;
         Bass.BASS_StreamFree(_Stream);

         // create the stream
         _Stream = Bass.BASS_StreamCreateURL(url, 0, BASSFlag.BASS_STREAM_DECODE, null, IntPtr.Zero);

         //kunnen we niet connecten? eruit.
         if (_Stream == 0)
         {
             MessageBox.Show("Warning: \nFailed to connect to the voice-stream.\n\nError: " + Bass.BASS_ErrorGetCode(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }

         //add the stream we just connected to to our local mixer. To mix with own broadcast:
         if (!BassMix.BASS_Mixer_StreamAddChannel(_mixerStream, _Stream, BASSFlag.BASS_STREAM_AUTOFREE | BASSFlag.BASS_MIXER_DOWNMIX))
         {
             MessageBox.Show("There was an error while trying to add the client.\n\nError: " + Bass.BASS_ErrorGetCode());
         }


         listening = true;
        }

Logged
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.18 | SMF © 2013, Simple Machines