title: NAudio is not reading MemoryStream containing wav data
body: <p>I'm trying to use NAudio to record 8 seconds of streaming audio, store it in <code>System.IO.MemoryStream</code>, and then play it back right after. To do this, I'm running the following code:</p>
  
  <pre><code>using System.IO;
  using NAudio.Wave;
  
  public class AudioCapture{
  
      static WaveFileWriter wri;
      static bool stopped = false;
  
      public AudioCapture(){
          //record from loopback
          IWaveIn waveIn = new WasapiLoopbackCapture();
          waveIn.DataAvailable += waveIn_DataAvailable;
          waveIn.RecordingStopped += waveIn_RecordingStopped;
  
          //write loopback capture to MemoryStream
          Stream sos = new MemoryStream();
          wri = new WaveFileWriter(sos, waveIn.WaveFormat);
  
          //record 8 seconds of streaming audio
          waveIn.StartRecording();
          System.Threading.Thread.Sleep(8000);
          waveIn.StopRecording();
  
          //flush and dispose objects
          wri.Flush();
          waveIn.Dispose();
          wri.Dispose();
  
          //play back recorded audio
          WaveOut waveOut = new WaveOut();
          WaveFileReader waveFileReader = new WaveFileReader(sos);
          waveOut.Init(waveFileReader);
          waveOut.Play();
  
      }
  
      static void waveIn_RecordingStopped(object sender, StoppedEventArgs e){
          stopped = true;
      }
  
      static void waveIn_DataAvailable(object sender, WaveInEventArgs e){
          if (wri != null) wri.Write(e.Buffer, 0, e.BytesRecorded);
      }
  
  }
  </code></pre>
  
  <p>I get the following exception telling me that the stream could not be read:</p>
  
  <pre><code>Activated   Event   Time    Duration    Thread
      Exception: Exception thrown: 'System.ArgumentException' in NAudio.dll 
  ("Stream was not readable."). Exception thrown: 'System.ArgumentException' in 
  NAudio.dll ("Stream was not readable.") 17.86s      [17404] &lt;No Name&gt; 
  </code></pre>
  
  <p>I'm not quite sure what the issue is as WaveFileWriter clearly accepts <code>MemoryStream</code> according to the documentation. Is there some conversion that I'm missing? Any help would be appreciated. Thanks!</p>
  
  <p>For clarification: The error seems to be at this line:</p>
  
  <pre><code>WaveFileReader waveFileReader = new WaveFileReader(sos);
  </code></pre>