简体   繁体   中英

Play Dialogic ADPCM audio file with NAUDIO

I am trying to play a Dialogic ADPCM file (no RIFF header) with the NAUDIO library. I have tried a couple of different things but have been unsuccessful so far. I tried a simple wav conversion:

        FileStream fs = new FileStream(@"C:\TestFile.vox", FileMode.Open, FileAccess.Read);
        WaveFormat wf = new WaveFormat(8000, 1);
        WaveOut wo = new WaveOut();
        RawSourceWaveStream rawSource = new RawSourceWaveStream(fs, wf);
        wo.Init(rawSource);
        wo.Play();

This actually loads the file and starts to playback but its very noisy and distorted (actually not listenable) almost like the wrong codec was chosen to convert the file. I tried a more specific conversion because it appears as though NAUDIO has support for Dialogic ADPCM built in:

        FileStream fs = new FileStream(@"C:\TestFile.vox", FileMode.Open, FileAccess.Read);
        WaveFormat wf = WaveFormat.CreateCustomFormat(WaveFormatEncoding.DialogicOkiAdpcm, 8000, 1, 3000, 1, 4);
        WaveOut wo = new WaveOut();
        RawSourceWaveStream rawSource = new RawSourceWaveStream(fs, wf);
        wo.Init(rawSource);
        wo.Play();

This raises an exception when calling WaveOut.Init() - The exception is "WaveBadFormat calling waveOutOpen" I also tried using

AdpcmWaveFormat wf = new AdpcmWaveFormat(8000, 1);

for my WaveFormat object- I get the same exception. The file is recorded at a sample rate of 8000 Hz and is only 1 channel. Any help getting this sorted out would be greatly appreciated. Thanks

You need to convert to regular PCM before you can play it. Use WaveFormatConversionStream.ConvertToPcm to do this. It will only work if there is an ACM codec installed on your computer that can decompress the ADPCM, and you also need to pass in exactly the right WaveFormat structure.

The NAudioDemo application can show you what ACM codecs are installed on your couputer and what input and output WaveFormats they support.

To learn more about converting between formats with NAudio, you can read my article on CodeProject .

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