Hi,
In my iPhone app I am writing the product of my rendercallback in an offline render to an external file. All works fine exporting to a mono AudioSampleType (SInt16) file to both WAV and AAC. I have recently added stereo ability and want to be able to export stereo files also. I have made all the necessary updates and when writing the AAC file, stereo works fine. However when attempting to write to a WAV file (using a stereo AudioUnitSampleType fixed 8.24 format ASBD) I get an error (1718449215 / kAudioFileUnsupportedDataFormatError) when trying to create the container for the output file before the render takes place. The relevant code is as follows:
fileTypeID = kAudioFileWAVEType;
if (enableStereo) { // If setup for Stereo:
size_t bytesPerSample = sizeof (AudioUnitSampleType);
destFormat.mFormatID = kAudioFormatLinearPCM; destFormat.mFormatFlags = kAudioFormatFlagsAudioUnitCanonical; destFormat.mBytesPerPacket = bytesPerSample; destFormat.mFramesPerPacket = 1;
destFormat.mBytesPerFrame = bytesPerSample; destFormat.mChannelsPerFrame = 2; // 2 indicates stereo destFormat.mBitsPerChannel = 8 * bytesPerSample; destFormat.mSampleRate = graphSampleRate;
}
else { // If configured for mono, do this (works just fine)
fileTypeID = kAudioFileWAVEType;
destFormat = int16StreamFormat;
/* for clarities sake, this is defined as:
int16StreamFormat.mSampleRate = graphSampleRate;
int16StreamFormat.mFormatID = kAudioFormatLinearPCM;
int16StreamFormat.mFormatFlags = kAudioFormatFlagsCanonical ;
int16StreamFormat.mFramesPerPacket = 1;
int16StreamFormat.mChannelsPerFrame = 1;
int16StreamFormat.mBitsPerChannel = 16;
int16StreamFormat.mBytesPerPacket = 2;
int16StreamFormat.mBytesPerFrame = 2;
*/
}
//Then attempts to create the file, status = 1718449215 or kAudioFileUnsupportedDataFormatError is returned when trying to set the stereo format
status = ExtAudioFileCreateWithURL(destinationURL, fileTypeID, &destFormat, NULL, kAudioFileFlags_EraseFile, &exportFileRef);
if (status) NSLog(@"1. Error creating file with URL: %ld", status);
The error would suggest that a fixed point 8.24 cannot be stored in a wav file? Is this really the case? I have also tried setting the fileTypeID to AudioFileCAFType but get the same error.
Can anyone point me in the right direction? What is the right combination of fileTypeId and ASBD to write a LPCM 8.24 fixed point stereo file ?
Thanks for any insight you guys can provide.
Cheers,
Dave