我对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之间的双精度数组。如果有人可以帮助我,那就太好了。
发布于 2010-10-14 21:46:30
您得到的缓冲区将包含16位短值。您可以使用NAudio中的WaveBuffer类,这样可以很容易地将样本值作为短值读出。除以32768可以得到双精度/浮点样本值。
void waveIn_DataAvailable(object sender, WaveInEventArgs e)
{
byte[] buffer = e.Buffer;
for (int index = 0; index < e.BytesRecorded; index += 2)
{
short sample = (short)((buffer[index + 1] << 8) |
buffer[index]);
float sample32 = sample / 32768f;
}
}https://stackoverflow.com/questions/3929389
复制相似问题