0

I am trying to change the format of a wav file in .Net from a 32 bit, 44100 samplerate, stereo wav file to a 16 bit, 44100 samplerate, stereo wav file.

The code Ive already tried with Naudio:

public static byte[] ChangeWavQuality(Stream filePath, int sampleRate, int bitDepth, int numOfChannels = 2)
    {
        WaveFormat w = new WaveFormat(sampleRate, bitDepth, numOfChannels);
        WaveStream stream = new WaveFileReader(filePath);
        WaveFormatConversionStream str = new WaveFormatConversionStream(w, stream);
        byte[] buffer = new byte[str.Length];
        str.Write(buffer, 0, buffer.Length);
        return buffer;
    }

But the error Im getting with this piece of code ive tried is that everytime I try to use this code I get an error returning:


An unhandled exception of type 'NAudio.MmException' occurred in NAudio.dll

Additional information: AcmNotPossible calling acmStreamOpen


Any others ways of changing the format of a wav file or a fix to the above problem in the code snippet?

  • You're missing the `WaveFileWriter` (`WaveFileWriter.CreateWaveFile()`), which takes the `WaveFormatConversionStream` as input stream. You could also use the `WaveFileWriter` constructor that take a Stream (and a `WaveFormat`), then `.Write()` a buffer to a `MemoryStream`, if you don't want to create a file. – Jimi Oct 20 '19 at 22:46
  • Still getting that same exception as written above, this exception is created when every i try to initialize a WaveFormatConversionStream – Kozmak242 Oct 21 '19 at 01:15

0 Answers0