4
votes

Hi I've been trying to create a wav audio file from the below code, but keep getting the error Creating file ('fmt?'). Can anyone help me out here ? Thanks.

My log : *2012-11-01 13:33:14.183 Novocaine iOS Example[7456:c07] URL: file://localhost/Users/pier/Library/Application%20Support/iPhone%20Simulator/6.0/Applications/01EBF2C0-2C3A-490D-835E-9C39A3E88E0B/Documents/testrecording.wav

Error: Creating file ('fmt?')*

- (id)initWithAudioFileURL:(NSURL *)urlToAudioFile samplingRate:(float)thisSamplingRate numChannels:(UInt32)thisNumChannels
{
self = [super init];
if (self)
{

    // Zero-out our timer, so we know we're not using our callback yet
    self.callbackTimer = nil;


    // Open a reference to the audio file
    self.audioFileURL = urlToAudioFile;
    CFURLRef audioFileRef = (CFURLRef)self.audioFileURL;

    AudioStreamBasicDescription outputFileDesc; 

    // Set a few defaults and presets
    self.samplingRate = thisSamplingRate;
    self.numChannels = thisNumChannels;
    self.currentTime = 0.0;
    self.latency = .011609977; // 512 samples / ( 44100 samples / sec ) default

    outputFileDesc.mSampleRate = self.samplingRate;
    outputFileDesc.mFormatID = kAudioFormatLinearPCM;
    outputFileDesc.mFormatFlags = kAudioFormatFlagIsFloat;
    outputFileDesc.mBytesPerPacket = 4*self.numChannels;
    outputFileDesc.mFramesPerPacket = 1;
    outputFileDesc.mBytesPerFrame = 4*self.numChannels;
    outputFileDesc.mChannelsPerFrame = self.numChannels;
    outputFileDesc.mBitsPerChannel = 32;

    CheckError(ExtAudioFileCreateWithURL(audioFileRef, kAudioFileWAVEType, &outputFileDesc, NULL, kAudioFileFlags_EraseFile, &_outputFile), "Creating file");

. . .

2

2 Answers

1
votes

I have no idea why, but I made the following changes and it worked. One would think wav file would have type kAudioFileWAVType, no?
Anyone care to shine a light on this?

outputFileDesc.mFormatFlags = kAudioFormatFlagIsBigEndian | kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked; //changed


CheckError(ExtAudioFileCreateWithURL(audioFileRef, kAudioFileCAFType, &outputFileDesc, NULL, kAudioFileFlags_EraseFile, &_outputFile), "Creating file"); //changed
0
votes

Unusually, it appears that ExtAudioFileCreateWithURL's WAV file implementation requires that the kAudioFormatFlagIsPacked flag be explicitly set.

This is unusual because the kAudioFormatFlagIsPacked documentation claims that the flag is implied in the OP's case:

even if this flag is clear, it is implied that this flag is set if the AudioStreamBasicDescription is filled out such that the fields have the following relationship: ((mBitsPerSample / 8) * mChannelsPerFrame) == mBytesPerFrame

It's also unusual because other formats, like CAF, just don't care.

TL;DR setting the format flags like this will fix the kAudioFileUnsupportedDataFormatError = 'fmt?' error:

outputFileDesc.mFormatFlags = kAudioFormatFlagIsFloat | kAudioFormatFlagIsPacked;