NAudio 将输入字节数组转换为双精度数组
我对 NAudio 非常陌生,我需要将输入样本的缓冲区从输入设备转换为范围从 -1 到 1 的双精度数组。
我按如下方式创建输入设备:
WaveIn inputDevice = new WaveIn();
//change the input device to the one i want to receive audio from
inputDevice.DeviceNumber = 1;
//change the wave format to what i want it to be.
inputDevice.WaveFormat = new WaveFormat(24000, 16, 2);
//set up the event handlers
inputDevice.DataAvailable +=
new EventHandler<WaveInEventArgs>(inputDevice_DataAvailable);
inputDevice.RecordingStopped +=
new EventHandler(inputDevice_RecordingStopped);
//start the device recording
inputDevice.StartRecording();
现在,当调用“inputDevice_DataAvailable”回调时我得到了音频数据的缓冲区。我需要将这些数据转换为代表 -1 和 1 之间音量级别的双精度数组。如果有人可以帮助我,那就太好了。
I am very new to NAudio and I need to convert the buffer of input samples from an input device to an array of doubles that range from -1 to 1.
I create the input device as follows:
WaveIn inputDevice = new WaveIn();
//change the input device to the one i want to receive audio from
inputDevice.DeviceNumber = 1;
//change the wave format to what i want it to be.
inputDevice.WaveFormat = new WaveFormat(24000, 16, 2);
//set up the event handlers
inputDevice.DataAvailable +=
new EventHandler<WaveInEventArgs>(inputDevice_DataAvailable);
inputDevice.RecordingStopped +=
new EventHandler(inputDevice_RecordingStopped);
//start the device recording
inputDevice.StartRecording();
Now when the 'inputDevice_DataAvailable' callback gets called I get a buffer of audio data. I need to convert this data to and array of doubles that represent volume levels between -1 and 1. If anyone can help me out that would be great.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您返回的缓冲区将包含 16 位短值。您可以使用 NAudio 中的 WaveBuffer 类,这将可以轻松地将示例值读取为 Shorts。除以 32768 即可得到双精度/浮点样本值。
the buffer you get back will contain 16 bit short values. You can use the WaveBuffer class from NAudio which will make it easy to read the sample values out as shorts. Divide by 32768 to get your double/float sample value.