0

I'm trying to encode audio stream into IMA ADPCM, here is my code.

public Byte[] EncodeDVI(Byte[] source)
        {
            var resampleStream = new AcmStream(new WaveFormat(11025, 16, 1), new ImaAdpcmWaveFormat(11025, 16, 1));
            Buffer.BlockCopy(source, 0, resampleStream.SourceBuffer, 0, source.Length);

            int sourceBytesConverted = 0;
            var convertedBytes = resampleStream.Convert(source.Length, out sourceBytesConverted);
            if (sourceBytesConverted != source.Length)
            {
                Console.WriteLine("We didn't convert everything {0} bytes in, {1} bytes converted");
            }

            var converted = new byte[convertedBytes];
            Buffer.BlockCopy(resampleStream.DestBuffer, 0, converted, 0, convertedBytes);

            return converted;
        }

Each time i run the code i got this error "NAudio.MmException: 'AcmNotPossible calling acmStreamOpen'"

Samy Massoud
  • 4,295
  • 2
  • 35
  • 48

1 Answers1

0

ACM codecs only have a limited number of conversions they are able to perform. You can use the NAudio demo application to explore in more detail what ACM codecs are installed on your system and what they can convert between.

I suspect in this case it might be your sample rate that is not supported. I've written a more detailed guide on format conversion here, which explains how you sometimes need to make your conversion in a few stages.

Mark Heath
  • 48,273
  • 29
  • 137
  • 194
  • I have tried NAudio demo project to encode IMA Adpcm, and the only available option is 11025 Khz,4bit Mono. and my file is 11025,16 bit Mono. So,this is not what i need, and i can't find wdlResample example that works the same way like the one i mentioned here, can you please point me to one? – Samy Massoud Sep 24 '17 at 18:29