Author Topic: Possible to write out stream to .mp3 using BASS on C#?  (Read 346 times)


  • Posts: 48
Hi there. It's been a long time since I've been here.

A few years ago I used Bass (and this great forum) to replace what I was doing with SOX and ended up much nicer and robust. I'm using BASS with C#.

In essence, I take multi-channel ogg files with custom metadata for channel volume and other information, and make it playable back like a typical stereo file. Back then I was able to also write it out into stereo WAV or OGG files. Back then I distinctly remember writing to MP3 not being an option... I'm back with a new idea and need to take the same files, and write to stereo files like I was, but definitely want a way to do MP3, FLAC and WMA besides the two I can already do. I just grabbed the FLAC and WMA add-ons, but didn't see one for MP3.

Is it possible to write out a stream to a properly formatted MP3 file? If so, can you point me at the class or add-on or third party library I could use alongside BASS? I'd really love to keep it all within BASS and not have to juggle two different tools.

« Last Edit: 31 Jul '17 - 04:40 by trojannemo »


  • Posts: 4625
YOu can use the BASSenc add-on together with lame.exe to encode any stream to MP3.
When using BASS.NET there is a "Un4seen.Bass.Misc" namespace hosting various helper function for it.
Here is an example:

Code: [Select]
int stream = Bass.BASS_StreamCreateFile("test.wav", 0, 0, BASSFlag.BASS_STREAM_DECODE);
EncoderLAME l = new EncoderLAME(stream);
l.InputFile = null;    //STDIN
l.OutputFile = "test.mp3";
l.LAME_Bitrate = (int)EncoderLAME.BITRATE.kbps_64;
l.LAME_Mode = EncoderLAME.LAMEMode.Default;
l.LAME_Quality = EncoderLAME.LAMEQuality.Quality;
l.Start(null, IntPtr.Zero, false);
// decode the stream (if not using a decoding channel, simply call "Bass.BASS_ChannelPlay" here)
byte[] encBuffer = new byte[65536]; // our dummy encoder buffer
while (Bass.BASS_ChannelIsActive(stream) == BASSActive.BASS_ACTIVE_PLAYING)
    // getting sample data will automatically feed the encoder
    int len = Bass.BASS_ChannelGetData(_stream, encBuffer, encBuffer.Length);
l.Stop();  // finish


  • Posts: 48
Thanks. That's exactly what I needed. This new idea might just work out  :)