Resample loopback capture

梦想与她 提交于 2019-12-10 19:03:22

问题


I successfully captured sound from Wasapi using the following code:

IWaveIn waveIn = new WasapiLoopbackCapture();
waveIn.DataAvailable += OnDataReceivedFromWaveOut;

What I need to do now, is to resample the in-memory data to pcm with a sample rate of 8000 and 16 bits per sample mono.

I can't use ACMStream to resample the example, because the recorded audio is 32 bits per second.

I have tried this code to convert bytes from 32 to 16 bits, but all I get every time is just blank audio.

byte[] newArray16Bit = new byte[e.BytesRecorded / 2];
short two;
float value;
for (int i = 0, j = 0; i < e.BytesRecorded; i += 4, j += 2)
{
    value = (BitConverter.ToSingle(e.Buffer, i));
    two = (short)(value * short.MaxValue);

    newArray16Bit[j] = (byte)(two & 0xFF);
    newArray16Bit[j + 1] = (byte)((two >> 8) & 0xFF);
}

source = newArray16Bit;

来源:https://stackoverflow.com/questions/31788741/resample-loopback-capture

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!