简体   繁体   English

使用NAUDIO播放Dialogic ADPCM音频文件

[英]Play Dialogic ADPCM audio file with NAUDIO

I am trying to play a Dialogic ADPCM file (no RIFF header) with the NAUDIO library. 我正在尝试使用NAUDIO库播放Dialogic ADPCM文件(无RIFF标头)。 I have tried a couple of different things but have been unsuccessful so far. 我尝试了几种不同的方法,但到目前为止都没有成功。 I tried a simple wav conversion: 我尝试了一个简单的WAV转换:

        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: 我尝试了一个更具体的转换,因为它看起来好像NAUDIO支持内置的Dialogic ADPCM:

        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 这在调用WaveOut.Init()时引发异常-异常为“ WaveBadFormat调用waveOutOpen”,我也尝试使用

AdpcmWaveFormat wf = new AdpcmWaveFormat(8000, 1);

for my WaveFormat object- I get the same exception. 对于我的WaveFormat对象,我得到了相同的异常。 The file is recorded at a sample rate of 8000 Hz and is only 1 channel. 该文件以8000 Hz的采样率记录,并且只有1个通道。 Any help getting this sorted out would be greatly appreciated. 任何帮助解决这个问题将不胜感激。 Thanks 谢谢

You need to convert to regular PCM before you can play it. 您需要先转换为常规PCM,然后才能播放它。 Use WaveFormatConversionStream.ConvertToPcm to do this. 使用WaveFormatConversionStream.ConvertToPcm来执行此操作。 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. 仅当计算机上安装了可以解压缩ADPCM的ACM编解码器时,它才起作用,并且您还需要传递完全正确的WaveFormat结构。

The NAudioDemo application can show you what ACM codecs are installed on your couputer and what input and output WaveFormats they support. NAudioDemo应用程序可以向您显示耦合器上安装了哪些ACM编解码器,以及它们支持哪些输入和输出WaveFormat。

To learn more about converting between formats with NAudio, you can read my article on CodeProject . 要了解有关使用NAudio在格式之间进行转换的更多信息,请阅读我在CodeProject上的文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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