代码示例,用于从Mac中捕获音频并保存到文件中?

时间:2021-08-05 02:45:19

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.

我特别需要捕获传递到内置输出设备的音频,以便记录它。见解吗?到目前为止,这些答案都很有帮助,但并没有帮助我理解如何捕获输入源的数据。

2 个解决方案

#1


9  

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中使用音频需要与核心音频进行交互。为了快速概述,请查看核心音频概述。

You will need to interface with the AUHAL to perform input and output; a technical note exists 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.

查看/开发人员/示例/CoreAudio/Services/AudioFileTools。具体地说,看看afrecord.cpp。诚然,这不是可可本身;Cocoa本身似乎没有任何特定的记录功能。如果您希望与那里的c++文件进行接口,您可能需要编写一些目标c++,比如SimplePlayThru。

#2


3  

There is a good example code at Ulli Kusterers website
Cocoadev also has an article about 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序列Grabber API。我会选择Core Audio。

#1


9  

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中使用音频需要与核心音频进行交互。为了快速概述,请查看核心音频概述。

You will need to interface with the AUHAL to perform input and output; a technical note exists 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.

查看/开发人员/示例/CoreAudio/Services/AudioFileTools。具体地说,看看afrecord.cpp。诚然,这不是可可本身;Cocoa本身似乎没有任何特定的记录功能。如果您希望与那里的c++文件进行接口,您可能需要编写一些目标c++,比如SimplePlayThru。

#2


3  

There is a good example code at Ulli Kusterers website
Cocoadev also has an article about 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序列Grabber API。我会选择Core Audio。