Author Topic: Best way to stream to icecast and record source audio  (Read 267 times)


  • Posts: 7

I’m wondering what’s the best way to stream a soundcard input to icecast as mp3 and record the encoded audio to disk as that mp3 stream at the same time. My thought is can you just encode the audio to mp3 once, send the mp3 encoded audio to icecast and to disk at the same time, without running two lame encoder instances (theory use less resource, and why do things twice if not needed)? Or do I need to use another separate record instance or separate encoderlame instance ?

Currently I’ve added a recording callback, which then uses wavewriter to write a wav file of the audio to be encoded and this is fine, but I’d rather record as the mp3 encoded audio (as I don’t need wav quality, and save space).

I’m using the code as (modified to icecast) as shown here from the example.

Any thoughts and comments would be great.

Thank you


Private _recHandle As Integer
Private _broadCast As BroadCast
_recHandle = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_DEFAULT, Nothing, 0)
' create an encoder instance (e.g. for MP3 use EncoderLAME):
Dim lame As New EncoderLAME(_recHandle)
lame.InputFile = Nothing 'STDIN
lame.OutputFile = Nothing 'STDOUT
lame.LAME_Bitrate = CInt(EncoderLAME.BITRATE.kbps_56)
lame.LAME_Mode = EncoderLAME.LAMEMode.Mono
lame.LAME_TargetSampleRate = CInt(EncoderLAME.SAMPLERATE.Hz_22050)
lame.LAME_Quality = EncoderLAME.LAMEQuality.Quality

' create a StreamingServer instance (e.g. SHOUTcast) using the encoder:
Dim shoutcast As New SHOUTcast(lame)
shoutcast.ServerAddress = "localhost"
shoutcast.ServerPort = 8000
shoutcast.Password = "changeme"
shoutcast.PublicFlag = True

Ian @ un4seen

  • Administrator
  • Posts: 25612
You can indeed send an MP3 encoder's output to a file and an Icecast server at the same time. It looks like you're using BASS.Net's helper classes in the code above. It should be possible with that too, but I'm not familiar enough with it to say how exactly. When using BASSenc directly instead, you could do something like this:

Code: [Select]
encoder = BASS_Encode_MP3_StartFile(rechandle, options, BASS_ENCODE_QUEUE, mp3filename);
BASS_Encode_CastInit(encoder, "localhost:8000", "changeme", BASS_ENCODE_TYPE_MP3, NULL, NULL, NULL, NULL, NULL, 0, BASS_ENCODE_CAST_PUBLIC);

Note that's using the BASSenc_MP3 add-on (which is based on LAME) instead of LAME.EXE for MP3 encoding. BASS_Encode_MP3_StartFile can be replaced with BASS_Encode_Start if you would prefer the latter. Please see the BASS_Encode_MP3_StartFile (or BASS_Encode_Start) and BASS_Encode_CastInit documentation for details.


  • Posts: 7
That’s great thank you Ian, I appreciate your help, all working. Keep up the good work.