简体   繁体   English

C ++中的实时音频处理

[英]real time audio processing in C++

I want to produce software that reads raw audio from an external audio interface (Focusrite Scarlett 2i2) and processes it in C++ before returning it to the interface for playback. 我想生产一种软件,该软件可以从外部音频接口(Focusrite Scarlett 2i2)读取原始音频,并在返回到接口进行播放之前用C ++处理它。 I currently run Windows 8 and was wondering how to do this with minimum latency? 我目前正在运行Windows 8,并且想知道如何以最小的延迟做到这一点?

I've spent a while looking into (boost) ASIO but the documentation seems fairly poor. 我花了一段时间研究(增强)ASIO,但是文档似乎相当差。 I've also been considering OpenCL but I've been told it would most likely have higher latency. 我也一直在考虑OpenCL,但有人告诉我OpenCL很可能具有更高的延迟。 Ideally I'd like to be able to just access the Focusrite driver directly. 理想情况下,我希望能够直接访问Focusrite驱动程序。

I'm sorry that this is such an open question but I've been having some trouble finding educational materiel on Audio Programming, other than just manipulating the audio when provided by a third party plug in design suite such as RackAFX. 很抱歉,这是一个悬而未决的问题,但是我一直在寻找有关音频编程的教学材料时遇到一些麻烦,而不仅仅是在第三方插件设计套件(例如RackAFX)提供音频时操纵音频。 I'd also be grateful if anyone could recommend some reading on low level stuff like this. 如果有人能推荐这样的低水平内容阅读,我也将不胜感激。

You can get very low latency by communicating directly with the Focuswrite ASIO driver (this is totally different than boost ASIO). 通过直接与Focuswrite ASIO驱动程序进行通信,您可以获得非常低的延迟(这与boost ASIO完全不同)。 To work with this you'll need to register and download the ASIO SDK from Steinberg. 要使用此工具,您需要从Steinberg注册并下载ASIO SDK。 Within the API download there is a Visual C++ sample project called hostsample which is a good starting point and there is pretty good documentation about the buffering process that is used by ASIO. 在API下载中,有一个名为hostsample的Visual C ++示例项目,这是一个很好的起点,并且有很多关于ASIO使用的缓冲过程的很好的文档。

ASIO uses double buffering. ASIO使用双重缓冲。 Your application is able to choose a buffer size within the limits of the driver. 您的应用程序可以在驱动程序的限制范围内选择缓冲区大小。 For each input channel and each output channel, 2 buffers of that size are created. 对于每个输入通道和每个输出通道,将创建2个相同大小的缓冲区。 While the driver is playing from and recording to one set of buffers your program is reading from and writing to the other set. 当驱动程序从一组缓冲区播放并向其中记录时,您的程序正在从另一组缓冲区读取和写入。 If your program was performing a simple loopback then it would have access to the input 1 buffer period after it was recorded, would write directly to the output buffer which would be played out on the next period so there would be 2 buffer periods of latency. 如果您的程序正在执行简单的环回,那么它将在记录后有权访问输入的1个缓冲时间段,将直接写入输出缓冲区,该缓冲区将在下一个周期播放,因此会有2个缓冲时间段的延迟。 You'll need to experiment to find the smallest buffer size you can tolerate without glitches and this will give you the lowest latency. 您将需要进行实验,以找到可以容忍的最小缓冲区大小,而不会出现毛刺,这将使您的延迟最小。 And of course the signal processing code will need to be optimized well enough to keep up. 当然,信号处理代码也需要进行充分优化以跟上潮流。 A 64 sample (1.3 ms @ 48kHz) is not unheard of. 并非闻所未闻的是64个样本(1.3 ms @ 48kHz)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM