Question

I have to Compress an Audio WAV with the best codec possible using NAudio. I use WaveFormatConversionStream, but I always get this error :
"AcmNotPossible calling acmStreamOpen" I had read a lot of answer about this error , but I don't find the solution.

Here's my code,Where Am I wrong ?

All help would be nice and welcome :)

private void InvokeOnNewAudioData(byte[] data, AudioFormat audioFormat)
{
    WaveFormat waveFormat = new WaveFormat(audioFormat.NumberSamplesPerSec, audioFormat.NumberBitsPerSample, audioFormat.NumberChannels);

    WaveFormat targetFormat = WaveFormat.CreateCustomFormat(WaveFormatEncoding.Vorbis1,
                                                            22000, //SampleRate
                                                            audioFormat.NumberChannels,     //Channels
                                                            48000,    //Average Bytes per Second
                                                            2,     //Block Align
                                                            16);    //Bits per Sample   


    using (MemoryStream dataStream = new MemoryStream(data))
    {
        using (WaveStream inputStream = new RawSourceWaveStream(dataStream, waveFormat))
        {
            try
            {
                using (WaveFormatConversionStream converter = new WaveFormatConversionStream(targetFormat, inputStream))
                {

                }
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
Was it helpful?

Solution

This means that there is no ACM codec on your system that can perform the requested conversion. You can use the NAudioDemo app that comes with NAudio to examine all the ACM codecs you have installed on your system and their supported input and output formats. Windows certainly doesn't come with a Vorbis ACM codec, which is probably why your code doesn't work. Even if you had installed a Vorbis ACM codec, you need to get the WaveFormat exactly right or you will get the ACM not possible error.

You'd probably be better off trying to use the the NAudio support that comes with NVorbis in any case.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top