Problem decode ADPCM wav file

Jan 5, 2011 at 1:44 AM

I´m trying to decode a wav file encoded with NAudio ADPCM codec (WaveFormatConversionStream) to PCM, but when the file has more than 30 seconds, it shows me this exception "AcmNotPossible calling acmStreamSize"

my "decoder" code:

WaveStream waveStream = new WaveFileReader("OUTPUT_ADPCM.WAV");

NAudio.Wave.WaveFormat targetFormat = default(NAudio.Wave.WaveFormat);

targetFormat = NAudio.Wave.WaveFormat.CreateCustomFormat(WaveFormatEncoding.Pcm, 8000, 1, 8000, 1, 8);

using (WaveStream convertedStream = new WaveFormatConversionStream(targetFormat, waveStream))
     WaveFileWriter.CreateWaveFile("OUTPUT_PCM.wav", convertedStream);

What's the meaning of this exception? Where is the error?


Jan 5, 2011 at 9:34 AM

it is the ACM codec reporting that it can't convert a whole block. look at the NAudio source code for the CreateWaveFile function, and experiment with different block sizes (or ignore errors on the final block)


if you work with the latest code, the Mp3FileReader is much more accurate at reporting length, and offers the additional benefit of not requiring you to perform the format conversion (Read returns PCM). This will hopefully be released in the not too distant future as NAudio 1.4


Jan 5, 2011 at 2:51 PM


I look at CreateWaveFile function, and I try to change the block sizes with no sucess.

I try to change the size of the buffer at this point in CreateWaveFile

byte[] buffer = new byte[stream.WaveFormat.SampleRate * stream.WaveFormat.Channels * 16];

I use this:

byte[] buffer = new byte[stream.Length];

And it works!!!


Is there any incompatibility with buffer size and WaveFormatConversionStream.Read?

Thanks again.

Jan 5, 2011 at 3:09 PM

you need to be careful not to end up passing in too much to the ACM codec, or you'll end up with other buffers not being big enough. Apart from that you should be ok