This project has moved. For the latest updates, please go here.

Using lame.exe on WaveIn

Sep 30, 2015 at 6:02 PM
I can't figure out why this wont work. I get an mp3 that is static. What am I missing? Thanks.
    public partial class MainWindow : Window
        private WaveIn waveIn;
        Process p = new Process();

        public MainWindow()
            waveIn = new WaveIn();
            waveIn.WaveFormat = new WaveFormat();
            waveIn.DataAvailable += waveIn_DataAvailable;

        void waveIn_DataAvailable(object sender, WaveInEventArgs e)
            p.StandardInput.BaseStream.Write(e.Buffer, 0, e.BytesRecorded); 

        private void Button_Click(object sender, RoutedEventArgs e)
            p.StartInfo.FileName = @"c:\lame.exe";
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.Arguments = "-r - testing2.mp3";
            p.StartInfo.CreateNoWindow = true;

        private void Button_Click_1(object sender, RoutedEventArgs e)
Oct 1, 2015 at 12:21 PM
By static I mean the whole mp3 sounds kind of like white noise. Just thought I would clear that up. Any help would be appreciated.
Oct 1, 2015 at 9:04 PM
make sure you are passing the right command line arguments for the WaveFormat you are passing in.
I'd also perhaps write to a WAV file at the same time to check the audio you are receiving is correct.
Oct 2, 2015 at 2:33 AM
Thanks for your reply Mark. I set up a wave file writer and the wav file sounds perfect. It sounds like the stdin might be clipping. I have an open mic and the room sound in the mp3 sounds fine but as soon as I say something it sounds like distortion/static. I copied the below from my output window. It is the waveformat being sent and the output from lame.exe. It all seems to be in order. Is it possible for a default wavein to be too hot for stdin?

Assuming raw pcm input file
LAME version 3.96.1 (
CPU features: MMX (ASM used), SSE, SSE2
Using polyphase lowpass filter, transition band: 17249 Hz - 17782 Hz
Encoding <stdin> to testing2.mp3
Encoding as 44.1 kHz 128 kbps j-stereo MPEG-1 Layer III (11x) qval=3
Oct 12, 2015 at 8:37 PM
try recording to WAV and then passing that into LAME, see if that gives the same results.
Oct 12, 2015 at 8:56 PM
Do you mean in two steps?
1) record wave to disk and close
2) send the the finished wave file to lame

I have done that and it works fine.
Oct 12, 2015 at 9:01 PM
then something is wrong with the lame command line parameters.
Oct 12, 2015 at 9:23 PM
Okay I'll play around with them. I started this using your EncodeToMp3UsingStdIn method from your pluralsight course with the same results. I think I'll back up to there and try again. Thanks