简体   繁体   中英

Play IMA ADPCM Audio with NAudio

I have a file with no header with IMA ADPCM raw data stored, I would like to play it using NAudio. In Audacity, using this config plays without problems:

Encoding: VOX ADPCM 
Byte order: No Endianness
Channels: 1 Channel (Mono)
Start offset: 0 bytes
Amount to import: 100%
Sample rate: 22050Hz

This is the code I'm using, but I always get a System.DivideByZeroException error.

internal void PlayIMAAudio(WaveOut AudioPlayer, byte[] IMAData, int Frequency, int Bits, int Channels)
{
    if (AudioPlayer.PlaybackState == PlaybackState.Stopped)
    {
        MemoryStream AudioSample = new MemoryStream(IMAData);
        ImaAdpcmWaveFormat FileFormat = new ImaAdpcmWaveFormat(Frequency, Channels, Bits);
        RawSourceWaveStream provider = new RawSourceWaveStream(AudioSample, FileFormat);
        AudioPlayer.Init(provider);
        AudioPlayer.Play();
    }
}

How could I fix it?

Thanks!

You can't usually play compressed formats directly. Pass the RawSourceWaveStream into WaveFormatConversionStream.CreatePcmStream to get to PCM. That should work if you have the right codec available on your PC and if you've correctly specified the source WaveFormat

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM