重采样 WasapiLoopbackCapture [英] Resampling WasapiLoopbackCapture

查看:230
本文介绍了重采样 WasapiLoopbackCapture的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 WasapiLoopbackCapture 的输出从我的声卡 44100Hz, 16bit, 2 channel 波形重新采样为 16000Hz, 16bit, 1 channel 格式,以便以后在System.Net.Sockets.NetworkStream(我想将转换后的字节写入网络流)

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.

这是我目前得到的:

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.

推荐答案

NAudio 包括几种不同的重采样器 - 一种使用 ACM (WaveFormatConversionStream),一种使用 Media Foundation (MediaFoundationResamplercode>) 和一个完全用托管代码编写的 (WdlResamplingSampleProvider).我在这篇文章中讨论了每一个.

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.

对于您的情况,您想要进行输入驱动"重采样,您知道有多少输入样本,并且只想将它们传递到重采样器中.这可能比 NAudio 中的输出驱动重采样要棘手一些.我写了另一篇关于如何使用 AcmStream 进行输入驱动重采样的文章.类似的技术可以与 Media Foundation 重采样器转换或 WDL 重采样提供程序一起使用,但恐怕我还没有可用的代码示例.

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.

这篇关于重采样 WasapiLoopbackCapture的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆