質問
私は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の間のボリュームレベルを表すダブルの配列に変換する必要があります。誰かが私を助けてくれるなら、それは素晴らしいことです。
解決
戻ってきたバッファには、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;
}
}
所属していません StackOverflow