ExtAudioFile 3+ Channels Fails?
ExtAudioFile 3+ Channels Fails?
- Subject: ExtAudioFile 3+ Channels Fails?
- From: Seth Willits <email@hidden>
- Date: Sun, 17 Feb 2013 16:12:20 -0800
I'm taking audio from an AudioOutput unit and passing it off to ExtAudioFile to convert and write it as AAC.
I have created an aggregate audio device in Audio MIDI Setup to test with. The device has one stereo and one mono device as part of it, so it's a 3 channel device. According to AudioUnitGetProperty(…, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, …) the device format is:
deviceFormat.mFormatID = kAudioFormatLinearPCM;
deviceFormat.mFormatFlags = kAudioFormatFlagIsFloat | kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked | kAudioFormatFlagIsNonInterleaved;
deviceFormat.mSampleRate = 48000;
deviceFormat.mFramesPerPacket = 1;
deviceFormat.mChannelsPerFrame = 3;
deviceFormat.mBitsPerChannel = 32;
deviceFormat.mBytesPerFrame = 4;
deviceFormat.mBytesPerPacket = 4;
I then create the audio file to use the same sample rate and number of channels as the device, like so:
fileType = kAudioFileM4AType;
fileFormat.mFormatID = kAudioFormatMPEG4AAC;
fileFormat.mFormatFlags = 0;
fileFormat.mSampleRate = deviceFormat.mSampleRate;
fileFormat.mChannelsPerFrame = deviceFormat.mChannelsPerFrame;
fileFormat.mBytesPerPacket = 0; // Everything
fileFormat.mFramesPerPacket = 0; // else is
fileFormat.mBytesPerFrame = 0; // up to
fileFormat.mBitsPerChannel = 0; // the aac
fileFormat.mReserved = 0; // codec
ExtAudioFileCreateWithURL(…, fileFormat, …) // no error
Finally I set the AudioOutput unit's output stream format and the ExtAudioFile's client data format to be LPCM matching the channels and sample rate of the device. (Since I'll be taking the render results from the unit and passing them to ExtAudioFileWrite, they should be the same format.)
outputFormat.mFormatID = kAudioFormatLinearPCM;
outputFormat.mFormatFlags = kAudioFormatFlagIsFloat | kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked | kAudioFormatFlagIsNonInterleaved;
outputFormat.mSampleRate = deviceFormat.mSampleRate;
outputFormat.mFramesPerPacket = 1;
outputFormat.mChannelsPerFrame = deviceFormat.mChannelsPerFrame;
outputFormat.mBitsPerChannel = sizeof(Float32) * 8;
outputFormat.mBytesPerFrame = outputFormat.mBitsPerChannel / 8;
outputFormat.mBytesPerPacket = outputFormat.mBytesPerFrame;
AudioUnitSetProperty(…, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &outputFormat, …); // no error
ExtAudioFileSetProperty(…, kExtAudioFileProperty_ClientDataFormat, …, &outputFormat); // 'fmt?' error
I can't figure out why I'm getting a format error when setting the file's client data format. The same code works for a mono and stereo device, but if it has three channels it throws a format error. Any idea why?
--
Seth Willits
_______________________________________________
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