【发布时间】:2020-04-08 16:34:55
【问题描述】:
我正在学习 Learning Core Audio 书籍教程,在第 4 章中有一个练习,其中包括创建缓冲区队列、收听默认输入麦克风并将缓冲区保存在 @ 987654321@ 文件。 我多次尝试执行代码,作者也提供了一个版本。但我得到的所有时间都是一个 30kb 的 caf 文件,其中包含前导和尾随魔术 cookie,中间全为零。
xxd output.caf 摘录:
00006fb0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00006fc0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00006fd0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00006fe0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
我多次尝试重置麦克风隐私首选项,允许在 XCode 和终端的设置中使用麦克风,在调试和发布模式以及不同文件夹中执行 CLI 应用程序,但没有任何改变。我得到的只是一个 30kb caf 文件,无论持续时间长短。
我认为报告所有代码并没有多大用处,因为它似乎对其他人有用。但这里是回调实现:
// Audio Queue callback function, called when an input buffer has been filled.
static void MyAQInputCallback(void *inUserData, AudioQueueRef inQueue,
AudioQueueBufferRef inBuffer,
const AudioTimeStamp *inStartTime,
UInt32 inNumPackets,
const AudioStreamPacketDescription *inPacketDesc)
{
MyRecorder *recorder = (MyRecorder *)inUserData;
// if inNumPackets is greater then zero, our buffer contains audio data
// in the format we specified (AAC)
if (inNumPackets > 0)
{
// write packets to file
CheckError(AudioFileWritePackets(recorder->recordFile, FALSE, inBuffer->mAudioDataByteSize,
inPacketDesc, recorder->recordPacket, &inNumPackets,
inBuffer->mAudioData), "AudioFileWritePackets failed");
// increment packet index
recorder->recordPacket += inNumPackets;
}
// if we're not stopping, re-enqueue the buffer so that it gets filled again
if (recorder->running)
CheckError(AudioQueueEnqueueBuffer(inQueue, inBuffer,
0, NULL), "AudioQueueEnqueueBuffer failed");
}
我尝试打印一些变量,感觉一切都很好。告诉我你是否想要某个变量或其他代码的输出。
我知道你很难用这么少的信息提供帮助,但我真的需要这个功能,我希望你至少可以做出一些假设或指导我完成调试。
谢谢
【问题讨论】:
标签: objective-c xcode core-audio audio-recording