macos 在 Cocoa 中从 Mac 捕获音频并保存到文件的代码示例?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/871819/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 06:10:05  来源:igfitidea点击:

Code sample for capturing audio from a Mac in Cocoa and saving to file?

objective-cmacoscocoaaudio

提问by Demi

I'm due to work on a small application that captures audio from the Mac's Audio Queue and needs to save it to disk in some reasonable audio format.

我要开发一个小应用程序,该应用程序从 Mac 的音频队列中捕获音频,并需要以某种合理的音频格式将其保存到磁盘。

Does anyone have a some decent sample code (Cocoa / Objective-C) that they can share?

有没有人可以分享一些不错的示例代码(Cocoa / Objective-C)?

I specifically need to capture the audio that is being passed to the Built-in Output device in order to record it. Any insights? The answers so far have been helpful, but have not helped me understand how the data going to the output can be captured, agnostic of the input source.

我特别需要捕获传递到内置输出设备的音频以进行记录。任何见解?到目前为止的答案很有帮助,但并没有帮助我理解如何捕获进入输出的数据,与输入源无关。

采纳答案by Wesley

Working with audio in Mac OS X involves interfacing with Core Audio. For a quick overview, take a look at the Core Audio Overview.

在 Mac OS X 中处理音频涉及与 Core Audio 交互。如需快速概览,请查看Core Audio 概览

You will need to interface with the AUHAL to perform input and output; a technical noteexists detailing the steps required to do so. This code seems to usually be written in C++, as that is the procedure taken in the SimplePlayThru demo.

您将需要与 AUHAL 交互以执行输入和输出;有一份技术说明详细说明了这样做所需的步骤。这段代码似乎通常是用 C++ 编写的,因为这是SimplePlayThru 演示中采用的过程。

This doesn't cover the actual steps required to capture that audio input. However, these links should provide you with enough sample code to begin interfacing with your input device. I'll post more links in this answer if I happen across them.

这不包括捕获该音频输入所需的实际步骤。但是,这些链接应该为您提供足够的示例代码来开始与您的输入设备交互。如果我遇到它们,我会在这个答案中发布更多链接。



Take a look at /Developer/Example/CoreAudio/Services/AudioFileTools. Specifically, look at afrecord.cpp. Admittedly, this is not Cocoa per se; Cocoa itself doesn't seem to have any specific capabilities for recording. If you'll want to interface with the C++ file there, you'll likely need to write some Objective C++ like in SimplePlayThru.

看看/Developer/Example/CoreAudio/Services/AudioFileTools。具体看afrecord.cpp。不可否认,这不是 Cocoa本身;Cocoa 本身似乎没有任何特定的录音功能。如果您想在那里与 C++ 文件交互,您可能需要像 SimplePlayThru 一样编写一些 Objective C++。

回答by Thomas Zoechling

There is a good example code at Ulli Kusterers website
Cocoadev also has an articleabout that topic. The source code at the bottom of the page uses QuickTimes Sequence Grabber API. I would go with Core Audio.

Ulli Kusterers网站上有一个很好的示例代码
Cocoadev 也有一篇关于该主题的文章。页面底部的源代码使用 QuickTimes Sequence Grabber API。我会选择 Core Audio。