recording 4 channels from an audioqueue
recording 4 channels from an audioqueue
- Subject: recording 4 channels from an audioqueue
- From: Rob Clark <email@hidden>
- Date: Thu, 22 Sep 2011 16:35:46 +0100
I'm having difficulty recording more than 2 channels with an audio
queue on OS X 10.6 and 10.7.
I only ever get data values in the first 2 channels.
I'm using modified AQRecorder code (AudioSession stuff removed, and
generally cleaned up to work with URLs for files):
CABasicStreamdescription is set as follows with bitDepth=24,
channels=4, sampleRate=96000
mRecordFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger |
kLinearPCMFormatFlagIsPacked;
mRecordFormat.mBitsPerChannel = bitDepth;
mRecordFormat.mChannelsPerFrame = channels;
mRecordFormat.mBytesPerPacket = mRecordFormat.mBytesPerFrame =
(mRecordFormat.mBitsPerChannel / 8) * mRecordFormat.mChannelsPerFrame;
mRecordFormat.mFramesPerPacket = 1;
mRecordFormat.mSampleRate = sampleRate;
This structure is used both by the queue and for metering, the correct
number of meters are created from this structure, but both meter
values obtained from the queue and data written to a file from the
queue are null for all but the first two channels.
Callback is (I think unchanged):
int AQRecorder::ComputeRecordBufferSize(const
AudioStreamBasicDescription *format, float seconds)
{
int packets, frames, bytes = 0;
try {
frames = (int)ceil(seconds * format->mSampleRate);
if (format->mBytesPerFrame > 0)
bytes = frames * format->mBytesPerFrame;
else {
UInt32 maxPacketSize;
if (format->mBytesPerPacket > 0)
maxPacketSize = format->mBytesPerPacket; // constant packet size
else {
UInt32 propertySize = sizeof(maxPacketSize);
XThrowIfError(AudioQueueGetProperty(mQueue,
kAudioQueueProperty_MaximumOutputPacketSize, &maxPacketSize,
&propertySize), "couldn't get queue's maximum output packet size");
}
if (format->mFramesPerPacket > 0)
packets = frames / format->mFramesPerPacket;
else
packets = frames; // worst-case scenario: 1 frame in a packet
if (packets == 0) // sanity check
packets = 1;
bytes = packets * maxPacketSize;
}
} catch (CAXException e) {
char buf[256];
fprintf(stderr, "Error: %s (%s)\n", e.mOperation, e.FormatError(buf));
return 0;
}
return bytes;
}
The stream description is passed to the queue for further completion,
and then used to create an audio file (which has the correct number of
channels, but only the first 2 are non-empty).
requesting kAudioQueueDeviceProperty_NumberChannels from the queue
returns 12 which is correct for the device.
requesting kAudioQueueProperty_ChannelLayout from the queue returns an
error, setting a ChannelLayout with 4 channels defined, such as
kAudioChannelLayoutTag_Quadraphonic makes no difference to the
behaviour.
I was previously getting this problem with an aggregate device (and
assumed it was related to the device being an aggregate device) but it
seems to also be the case for a single device with more than 2
channels.
Any suggestions welcome. Particularly is this a inherent limitation
with an audioqueue (and I need to be using audio units) or am I likely
to be doing something stupid.
Regards,
Rob Clark.
--
Rob Clark
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden