Resampling WasapiLoopbackCapture

非 Y 不嫁゛ 提交于 2021-01-28 19:27:22

问题


I'm trying to resample the WasapiLoopbackCapture's output from my soundcards 44100Hz, 16bit, 2 channel waveformat to a 16000Hz, 16bit, 1 channel format for later use in a System.Net.Sockets.NetworkStream (I want to write the converted bytes to the network stream)

But I have no idea how to start even! I'm really new to signal processing and I've tried searching for tutorials but I just can't wrap my head around how to do this.

Here's what I got so far:

void StartRecording()
{
   capture = new WasapiLoopbackCapture(device); //  device is an audiodevice picked from the user. speaker, headphones etc
   capture.ShareMode = NAudio.CoreAudioApi.AudioClientShareMode.Shared;
   capture.DataAvailable += capture_DataAvailable;
   capture.RecordingStopped += capture_RecordingStopped;
   capture.StartRecording();
}

void capture_DataAvailable(object sender, WaveInEventArgs e)
{
   outputStream.Write(e.Buffer, 0, e.BytesRecorded); // here I want to output audio to the NetworkStream.
   // But I have to resample it first, which brings me to my question.
}

What I basically want to know is how I can get a byte-array which has been resampled and ready to be shipped off to the other side of the networkstream! Any suggestions are really appreciated! Thank you in advance.


回答1:


NAudio includes several different resamplers - one that uses ACM (WaveFormatConversionStream), one that uses Media Foundation (MediaFoundationResampler) and one written entirely in managed code (WdlResamplingSampleProvider). I discuss each of these in this post.

For your case, you want to do "input driven" resampling, where you know how many input samples you have and just want to pass them into the resampler. This can be a bit trickier than output driven resampling in NAudio. I've written another post about how to do input driven resampling using AcmStream. A similar technique can be used with the Media Foundation resampler transform or the WDL Resampling Provider but I'm afraid I don't have a code sample of that available yet.



来源:https://stackoverflow.com/questions/28438025/resampling-wasapiloopbackcapture

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