[英]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.我有一个没有 header 的文件,其中存储了 IMA ADPCM 原始数据,我想使用 NAudio 播放它。 In Audacity, using this config plays without problems:在 Audacity 中,使用这个配置没有问题:
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.这是我正在使用的代码,但我总是收到System.DivideByZeroException错误。
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.将RawSourceWaveStream
传递到WaveFormatConversionStream.CreatePcmStream
以获取 PCM。 That should work if you have the right codec available on your PC and if you've correctly specified the source WaveFormat如果您的 PC 上有正确的编解码器并且正确指定了源 WaveFormat,这应该可以工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.