AcmNotPossible calling acmStreamOpen

Nov 28, 2012 at 8:14 PM

Hi,

I'm trying to convert a wav file to alaw.

The Input file is 44kHz, 1 Channel, 16 bit PCM.

The output should be 8kHz, 1 Channel 16 bit alaw. But no matter what output format I choose I always get an Exception (AcmNotPossible calling acmStreamOpen) when creating the WaveFormatConversionStream.

 

                WaveFileReader reader = new NAudio.Wave.WaveFileReader("a.wav");
                WaveStream pcmStream = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(reader);
                BlockAlignReductionStream blockAlignReductionStream = new BlockAlignReductionStream(pcmStream);

                WaveFormat outputFormat = WaveFormat.CreateCustomFormat(WaveFormatEncoding.ALaw, blockAlignReductionStream.WaveFormat.SampleRate, blockAlignReductionStream.WaveFormat.Channels, blockAlignReductionStream.WaveFormat.AverageBytesPerSecond, blockAlignReductionStream.WaveFormat.BlockAlign, 8);
                WaveFormatConversionStream converter = new WaveFormatConversionStream(outputFormat, blockAlignReductionStream);


Any help appreciated! Thanks a lot.

Coordinator
Nov 28, 2012 at 9:32 PM

you can't do that conversion in one step. You need two WaveFormatConversionStreams - one to go from 44.1kHz to 8kHz PCM, and then another to go to a-law. Don't bother with BlockAlignReductionStream if you are just doing file conversion.

Nov 28, 2012 at 9:43 PM
                WaveFileReader reader = new NAudio.Wave.WaveFileReader("a.wav");
                WaveStream pcmStream = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(reader);
                WaveFormat outputFormat = WaveFormat.CreateCustomFormat(WaveFormatEncoding.Pcm, 8000, pcmStream.WaveFormat.Channels, pcmStream.WaveFormat.AverageBytesPerSecond, pcmStream.WaveFormat.BlockAlign, pcmStream.WaveFormat.BitsPerSample);
                WaveFormatConversionStream converter = new WaveFormatConversionStream(outputFormat, pcmStream);


Fails at the last line too although it should only convert 44kHz to 8kHz :-(

 

Coordinator
Nov 28, 2012 at 9:49 PM

Your code should look something like this:

var
reader = new WaveFileReader("a.wav"); var downsampledStream = new WaveFormatConversionStream(
new
WaveFormat(8000, reader.WaveFormat.BitsPerSample, reader.WaveFormat.Channels), reader); var alawStream = new WaveFormatConversionStream(WaveFormat.CreateALawFormat(8000, reader.WaveFormat.Channels), downsampledStream);

Nov 28, 2012 at 10:02 PM

WaveStream alawStream = new WaveFormatConversionStream(WaveFormat.CreateALawFormat(8000, reader.WaveFormat.Channels), downsampledStream);

 

throws MmException AcmNotPossible calling acmStreamOpen :-( going crazy. seems I can do whatever I want. It's always the same exception. Already checked if g.711 is installed at all. It is.

Coordinator
Nov 28, 2012 at 10:07 PM

reader waveformat should be  44.1kHz, 1 Channel, 16 bit PCM.

downsampled waveformat should be 8kHz, 1 channel, 16 bit PCM

then that should convert just fine to 8kHz, 1 channel, a-law

check the first two are correct. What OS are you on, and what version of NAudio are you using?

Nov 29, 2012 at 4:41 PM

Here is a more detailed description:

OS: Windows 7 Professional 64-bit

NAudio: 1.6.0

Current Code:

                WaveFileReader reader = new NAudio.Wave.WaveFileReader("a.wav");
                WaveStream downsampledStream = new WaveFormatConversionStream(new WaveFormat(8000, reader.WaveFormat.BitsPerSample, reader.WaveFormat.Channels), reader);
                WaveStream alawStream = new WaveFormatConversionStream(WaveFormat.CreateALawFormat(downsampledStream.WaveFormat.SampleRate, downsampledStream.WaveFormat.Channels), downsampledStream);

 

Fails with exception at the last line (alawStream).

After the last test failed I changed the input file.

VLC says: PCM U8 (araw), Mono, 22050 Hz, Bits per Sample: 8

 

When I debug step by step the three object reader, downsampledStream and alawStream contain the following information:

reader: WaveFormat    {8 bit PCM: 22kHz 1 channels}    NAudio.Wave.WaveFormat {NAudio.Wave.WaveFormatExtraData}

downsampledStream:  WaveFormat    {8 bit PCM: 8kHz 1 channels} , TotalTime    {00:00:07.9250000}, CurrentTime    {00:00:00}

alawStream: Exception NAudio.MmResult.AcmNotPossible {"AcmNotPossible calling acmStreamOpen"}

   bei NAudio.MmException.Try(MmResult result, String function)
   bei NAudio.Wave.Compression.AcmStream..ctor(WaveFormat sourceFormat, WaveFormat destFormat)
   bei NAudio.Wave.WaveFormatConversionStream..ctor(WaveFormat targetFormat, WaveStream sourceStream)
   bei RTPtest.Form1.Form1_Load(Object sender, EventArgs e) in C:\Users\joka\documents\visual studio 2010\Projects\RTPtest\RTPtest\Form1.cs:Zeile 50.

Coordinator
Nov 29, 2012 at 4:43 PM

you should be starting with 16 bit audio, not 8 bit. The a-law encoder converts from 16 bit to 8 bit.

Nov 29, 2012 at 5:21 PM

Thanks a lot. That works.

Is there any overview which conversions are supported? I think it depends on the codec!?

Coordinator
Nov 29, 2012 at 5:24 PM

Every codec has a list of supported input and output formats. You can look at these using the ACM demo in the NAudio Demo project.