我正在编写一个打开 AudioQueue 并分析其特征的类,然后在某些条件下可以开始或结束从该 AudioQueue 中写出已经实例化的文件。这是我的代码(完全基于 SpeakHere)打开 AudioQueue 而不向 tmp 写入任何内容:
void AQRecorder::StartListen() {
int i, bufferByteSize;
UInt32 size;
try {
SetupAudioFormat(kAudioFormatLinearPCM);
XThrowIfError(AudioQueueNewInput(&mRecordFormat,
MyInputBufferHandler,
this,
NULL, NULL,
0, &mQueue), "AudioQueueNewInput failed");
mRecordPacket = 0;
size = sizeof(mRecordFormat);
XThrowIfError(AudioQueueGetProperty(mQueue, kAudioQueueProperty_StreamDescription,
&mRecordFormat, &size), "couldn't get queue's format");
bufferByteSize = ComputeRecordBufferSize(&mRecordFormat, kBufferDurationSeconds);
for (i = 0; i < kNumberRecordBuffers; ++i) {
XThrowIfError(AudioQueueAllocateBuffer(mQueue, bufferByteSize, &mBuffers[i]),
"AudioQueueAllocateBuffer failed");
XThrowIfError(AudioQueueEnqueueBuffer(mQueue, mBuffers[i], 0, NULL),
"AudioQueueEnqueueBuffer failed");
}
mIsRunning = true;
XThrowIfError(AudioQueueStart(mQueue, NULL), "AudioQueueStart failed");
}
catch (CAXException &e) {
char buf[256];
fprintf(stderr, "Error: %s (%s)\n", e.mOperation, e.FormatError(buf));
}
catch (...) {
fprintf(stderr, "An unknown error occurred\n");
}
}
但我有点不清楚如何编写一个函数来告诉这个队列“从现在到停止信号,开始将此队列作为文件写入 tmp”。我了解如何告诉 AudioQueue 在创建时作为文件写出,如何设置文件格式等,但不知道如何告诉它在中途开始和停止。非常感谢任何指针,谢谢。