Author Topic: How can I cast/encode a record channel for streaming and playing a file?  (Read 451 times)

Chris Oakley

  • Posts: 96
Hi, I've written an app in VB.NET using BASS.NET and all is working great. It's a streaming application which broadcasts to Icecast or Shoutcast servers. Pretty normal stuff. However I've got silence detection in the app too and what I'd like to do is play a local audio file through the same stream. You wouldn't need to hear this file, it would just be pushed through the recording channel.

I've got to the point where I assume I have to set up a mixer and attach the stream and file to this and then cast the mixer. This is fine, all is okay with this. The casting of the record channel works, the file loads fine, no errors - but I just can't figure out how to play the file / stream the file is on.

Bass is initialised with no sound, as strictly speaking it doesn't play audio, and streams are DECODE.

Sorry if this hasn't explained the situation very well but hopefully it has. Any input or thoughts / suggestions would be brilliant :)

Ian @ un4seen

  • Administrator
  • Posts: 21368
Yes, that sounds like a mixer is what you want. You would create a mixer with the wanted sample format (presumably the same as you are currently using for the recording), set the encoder/caster on it, and then plug both the recording and file decoder into it. Note that in order to plug a recording into a mixer, you will need to not use a RECORDPROC in the BASS_RecordStart call. The mixer and recording setup could look something like this:

Code: [Select]
mixer=BASS_Mixer_StreamCreate(freq, chans, BASS_STREAM_DECODE); // create a mixer
// set encoder/caster on mixer here
recording=BASS_RecordStart(freq, chans, 0, NULL, NULL); // start recording without a RECORDPROC
BASS_Mixer_StreamAddChannel(mixer, recording, BASS_MIXER_LIMIT); // plug the recording into the mixer

You can then repeatedly call BASS_ChannelGetData on the mixer in a worker thread or timer, to process the mix and cast it. The BASS_MIXER_LIMIT flag will mean that the processing is limited to the rate of the recording, ie. real-time speed. So it doesn't matter if you try to process it faster, and you can set the BASS_ENCODE_CAST_NOLIMIT flag on the encoder/caster.

Call BASS_Mixer_StreamAddChannel again for the file when you want to play that:

Code: [Select]
decoder=BASS_StreamCreateFile(false, filename, 0, 0, BASS_STREAM_DECODE|BASS_SAMPLE_FLOAT); // create a decoder for the file
BASS_Mixer_StreamAddChannel(mixer, decoder, 0); // plug it into the mixer (might use BASS_STREAM_AUTOFREE here)

Please see the documentation for details on the mentioned functions.

Chris Oakley

  • Posts: 96
That's brilliant Ian. I've done all this, thanks so much.