title: wav file conversion PCM 48kHz/16 bit rate to u-law 8kHz/8 bit rate using NAudio
body: <p>I have a wav file that I need to convert into a format that can be read by one of our applications. The file I want to convert is in the format:</p>
  
  <ul>
  <li>Encoding: PCM</li>
  <li>Sample Rate: 48kHz</li>
  <li>Bit Rate: 16 bits</li>
  <li>Channels: 1</li>
  </ul>
  
  <p>The readable file format I want to convert to is:</p>
  
  <ul>
  <li>Encoding: u-Law</li>
  <li>Sample Rate: 8kHz</li>
  <li>Bit Rate: 8 bits</li>
  <li>Channels: 1</li>
  </ul>
  
  <p>To accomplish this, I'm using the <a href="https://github.com/naudio/NAudio/tree/master/NAudio/Wave" rel="nofollow noreferrer">NAudio</a> library. The code I'm using for the conversion is something along the lines of:</p>
  
  <pre><code>using (WaveFileReader reader = new WaveFileReader(inputWavFilePath))
  {
      WaveFormat newFormat = WaveFormat.CreateMuLawFormat(8000, 1);
      using (var conversionStream = new WaveFormatConversionStream(newFormat, reader))
      {
          WaveFileWriter.CreateWaveFile(outputWavFilePath, conversionStream);
      }
  }
  </code></pre>
  
  <p>The above conversion throws the error</p>
  
  <blockquote>
    <p>AcmNotPossible calling acmStreamOpen </p>
  </blockquote>
  
  <p>I've seen a few links for converting from u-law to PCM, but am having trouble with the reverse. </p>
  
  <p>What I'm struggling to understand is why when I convert <code>PCM/48kHz/16bit</code> <code>-&gt;</code> <code>uLaw/48kHz/8bit</code> the exception <strong>is not thrown</strong>. But, when I then try to convert the resulting file to <code>uLaw/8kHz/8bit</code> the exception <strong>is thrown</strong>.</p>
  
  <p>I'm new to working with audio files and different formats, so my apologies if I'm missing something simple.</p>
  
  <p>Could someone please explain why the conversion is only throwing the exception at the sample rate conversion and not at the other two conversions (encoding <code>PCM -&gt; uLaw</code> &amp;&amp; <code>16bit -&gt; 8bit</code>)?</p>