MacOS自定义音频驱动程序不处理我们的硬件音频流。

huangapple go评论48阅读模式
英文:

MacOS custom Audio Driver doesn't process our hardware audio stream

问题

我们正在为USB麦克风开发自定义音频驱动程序,以便对输入音频流进行简单处理(例如均衡器),类似于Windows的APO。我们的代码基于苹果的SimpleAudioDriver示例,最终成功地用我们自己的驱动程序覆盖了原始驱动程序(再次感谢)。但I/O缓冲区未从/到我们的硬件设备流传输。在SimpleAudioDevice.cpp文件中,我们尝试调试“input_buffer”(来自默认示例):

auto input_buffer = reinterpret_cast<int16_t*>(ivars->m_input_memory_map->GetAddress() + ivars->m_input_memory_map->GetOffset());

我们猜测,由于我们的设备现在与我们的驱动程序分配在一起,这个缓冲区应该被填充为来自我们麦克风的音频数据,但实际上没有。我们对output_buffer的行为也相同,我们用默认正弦波发生器填充它,但在我们的驱动程序分配给的音频设备上没有任何音频输出。

文档表示:

AudioDriverKit将这些流的内存映射到Core Audio HAL。在实际的硬件驱动程序中,这个内存需要与系统用于DMA到硬件的I/O内存相同。

但随后没有提供更多细节。如何访问这个“I/O内存”并将其用于处理我们的硬件输入/输出流?

如果您有任何提示,请回复给我们。

谢谢。

英文:

We are developing a custom audio driver for a USB microphone in order to do simple processing (EQs) on the input audio stream (comparable to an APO for Windows). Our code is based on the SimpleAudioDriver example from Apple and we finally managed to override the original driver with ours (thanks again). But the I/O buffers are not streamed from/to our hardware device. In the SimpleAudioDevice.cpp file, we tried to debug the "input_buffer" (from the default example) :

auto input_buffer = reinterpret_cast&lt;int16_t*&gt;(ivars-&gt;m_input_memory_map-&gt;GetAddress() + ivars-&gt;m_input_memory_map-&gt;GetOffset());

And our guess is that as our device is now assign with our driver, this buffer should be filled with the audio data from our microphone but it's not. And we have the same behaviour with the output_buffer, we filled it with the default sine generator and we don't get any audio outputted on the audio device our driver is assigned to.

The documentation says that the

> AudioDriverKit maps the memory of these streams to the Core Audio HAL. In an actual hardware driver, this memory needs to be the same I/O memory the system uses for DMA to hardware.

But then no more details are given. How to access this "I/O memory" and use it to process our hardware input/output stream ?

If you have any hints, please get back to us.

Thanks.

答案1

得分: 1

我在思考你是否对AudioDriverKit的工作原理有错误的心智模型:从你的问题中并不完全清楚,但似乎你期望这个框架已经为你处理了(USB音频类兼容的?)设备I/O?如果是这样,你在错误的层面上。AudioDriverKit用于实现低级音频驱动程序,并不假设这是什么类型的设备 - PCI/Thunderbolt、USB、类兼容或其他等等。这意味着你需要编写所有设备I/O代码,从你的代码中发出单独的USB数据传输请求。

如果你想继续使用操作系统附带的类兼容驱动程序,但只想在音频样本上执行预处理/后处理,有许多不错的选择:

  1. 一个AppleUSBAudioPlugin内核扩展。理论上,这正是你想要的,但在现代macOS上,内核扩展不是一个吸引人的选择。
  2. 一个音频服务器插件,提供通过从真实原始麦克风回送获取样本的虚拟麦克风。这里的缺点是你需要一个应用程序来录制来自真实麦克风的声音,原始和后处理的麦克风设备都会出现在系统中。
  3. 继续你已经开始的路线,实现足够的USB音频类功能在一个AudioDriverKit驱动程序中,以使你的麦克风工作,然后在将样本交给声音系统之前进行后处理。这意味着要执行理论上已经在苹果自己的USB音频驱动程序中实现的所有低级USB操作。
  4. 一种种类特殊的音频插件,位于USB音频驱动程序和核心音频之间。我不确定这是否可能,或者它是否比选项2和3更容易。
英文:

I'm wondering if you might have an incorrect mental model for how AudioDriverKit works: it's not 100% clear from your question, but it sounds like you're expecting the framework to already be taking care of the (USB Audio Class compliant?) device I/O for you? If so, you're at the wrong layer. AudioDriverKit is for implementing low-level audio drivers and makes no assumption about what kind of device this is - PCI/Thunderbolt, USB, class-compliant or not, etc. That means you're writing all the device I/O code, issuing individual USB data transfer requests from your code.

If you want to keep using the class compliant driver that ships with the OS but merely want to perform pre-/post-processing on audio samples, there are a bunch of different options, but they're not great:

  1. An AppleUSBAudioPlugin kext. This is theoretically exactly what you're after, but on modern macOS, kexts are not an attractive choice.
  2. An Audio Server Plugin which provides a virtual microphone which gets its samples via a loop back from the real raw microphone. The downside here is that you'd need an app running to record from the real microphone, and both the raw and post-processed mic devices will show up in the system.
  3. Continue down the route you've started on and implement enough of the USB audio class in an AudioDriverKit driver to make your microphone work, then post-processing the samples before handing them over to the sound system. This means doing all the low-level USB stuff that's theoretically already implemented in Apple's own USB audio driver.
  4. Some kind of long shot hail-Mary audio plugin that sits between the USB Audio driver and Core Audio. I'm not sure how possible this is, or if it's any less effort than options 2+3.

huangapple
  • 本文由 发表于 2023年3月7日 23:41:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/75664110.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定