Search code examples
iosaudioavassetwriter

AVAssetWriter record settings not working like AVAudioRecorder


I have successfully used these recording settings to create audio formatted into the needed format. However these settings only seemed to work with AVAudioRecorder. When I try them with AVAssetWriter I get an error stating that the AVLinearPCMBitDepthKey needs AVLinearPCMBitFloatKey but when I add that it says its not allowed for 'ulaw'. My question is why does AVLinearPCMBitDepthKey work fine in one recorder but not the other?

[recordSettings setObject:[NSNumber numberWithInt: kAudioFormatULaw] forKey: AVFormatIDKey];        
        [recordSettings setObject:[NSNumber numberWithFloat:8000.0] forKey: AVSampleRateKey];//was 44100.0
        [recordSettings setObject:[NSNumber numberWithInt:1] forKey:AVNumberOfChannelsKey];
        [recordSettings setObject:[NSNumber numberWithInt:8000] forKey:AVEncoderBitRateKey];//was 64000
        [recordSettings setObject:[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
        [recordSettings setObject:[NSNumber numberWithInt: AVAudioQualityLow] forKey: AVEncoderAudioQualityKey];

Solution

  • Per Apple support: this is therefore the bug -- the file is created, a number of samples are written successfully then append starts failing for some unknown reason.

    The bug only seems to happen with these settings and AVAssetWriter

    AudioQueue is what should be used for ulaw audio