I am writing a class that opens an AudioQueue and analyzes its characteristics, and then, under certain conditions, can start or end recording a file from this AudioQueue that has already been created. This is my code (entirely based on SpeakHere) that opens AudioQueue without writing anything to 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 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");
}
}
But I don’t understand a bit how to write a function that tells this queue "from now on to the stop signal, start writing this queue to tmp as a file." I understand how to tell AudioQueue to record as a file at the time it was created, how to set the file format, etc., but not how to tell it to start and stop the middle of the stream. Thanks so much for any pointers, thanks.