title: InvalidParameter calling waveOutOpen
body: <p>I am attempting to implement Mp3 streaming using NAudio's BufferedWaveProvider following Mark Heath's blog <a href="http://mark-dot-net.blogspot.com/2011/05/how-to-play-back-streaming-mp3-using.html" rel="nofollow noreferrer">here</a>.</p>
  
  <p>I have all of my streaming implemented, but I'm getting an MmException with the message "InvalidParameter calling waveOutOpen."</p>
  
  <p>I saw this related question: <a href="https://stackoverflow.com/questions/22126148/invalidparameter-calling-waveoutopen-mmexception">InvalidParameter calling waveOutOpen MmException</a>, so I took a look at the WaveFormat I was getting using the following code snippet:</p>
  
  <pre><code>private WaveFormat CreateWaveFormat(Mp3Frame frame)
  {
      var numberOfChannels = frame.ChannelMode == ChannelMode.Mono ? 1 : 2;
      return new Mp3WaveFormat(frame.SampleRate, numberOfChannels, frame.FrameLength, frame.BitRate);
  }
  </code></pre>
  
  <p>Here is the WaveFormat I get, taken from my debugger:</p>
  
  <pre><code>-       sampleProvider.WaveFormat   {MpegLayer3}    NAudio.Wave.WaveFormat {NAudio.Wave.Mp3WaveFormat}
      AverageBytesPerSecond   32000   int
      BitsPerSample   0   int
      BlockAlign  1   int
      Channels    2   int
      Encoding    MpegLayer3  NAudio.Wave.WaveFormatEncoding
      ExtraSize   12  int
      SampleRate  48000   int
      averageBytesPerSecond   32000   int
      bitsPerSample   0   short
      blockAlign  1   short
      blockSize   768 ushort
      channels    2   short
      codecDelay  0   ushort
      extraSize   12  short
      flags   PaddingIso  NAudio.Wave.Mp3WaveFormatFlags
      framesPerBlock  1   ushort
      id  Mpeg    NAudio.Wave.Mp3WaveFormatId
      sampleRate  48000   int
      waveFormatTag   MpegLayer3  NAudio.Wave.WaveFormatEncoding
  +       Static members  
  </code></pre>
  
  <p>To test all this, I'm loading a test Mp3 file into a FileStream. I decided to see what the WaveFormat looked like when I used Mp3FileReader to read the whole stream, and interestingly I got a completely different WaveFormat:</p>
  
  <pre><code>-       format  {16 bit PCM: 48kHz 2 channels}  NAudio.Wave.WaveFormat
      AverageBytesPerSecond   192000  int
      BitsPerSample   16  int
      BlockAlign  4   int
      Channels    2   int
      Encoding    Pcm NAudio.Wave.WaveFormatEncoding
      ExtraSize   0   int
      SampleRate  48000   int
      averageBytesPerSecond   192000  int
      bitsPerSample   16  short
      blockAlign  4   short
      channels    2   short
      extraSize   0   short
      sampleRate  48000   int
      waveFormatTag   Pcm NAudio.Wave.WaveFormatEncoding
  </code></pre>
  
  <p>I took a look at the first 16 bytes of the stream in both cases, and they were identical. Any ideas where I'm going wrong? Or are the differing WaveFormats a red herring? Could something else be the problem?</p>
  
  <p>Thanks for your time!</p>