Search code examples
iphoneaudiocore-audiomp4

Record "Apple lossless" audio on the iPhone


could you point me to docs/snippets/blogs, which explain how to record Apple lossless audio files on the iPhone, please?

I've inspected the audio recorder example from the Apple Dev Center, but couldn't figure out, which setting I have use for lossless audio.

Regards,

Stefan


Solution

  • The iPhone OS supports recording a .caf file using a number of different compressed audio encoding formats:

    Apple Lossless - kAudioFormatAppleLossless

    iLBC (Internet Low Bitrate Codec) - kAudioFormatiLBC

    IMA/ADPCM (aka IMA4) - kAudioFormatAppleIMA4

    µLaw - kAudioFormatULaw

    aLaw - kAudioFormatALaw

    - (id) initWithURL: fileURL {
        NSLog (@"initializing a recorder object.");
        self = [super init];
    
        if (self != nil) {
    
            // define the audio stream basic description for the file to record into
    
            // record audio at the current hardware sample rate
            // make sure the audio session is active before asking for properties
            UInt32 propertySize = sizeof(audioFormat.mSampleRate);
            AudioSessionGetProperty(kAudioSessionProperty_CurrentHardwareSampleRate,
                                    &propertySize,
                                    &audioFormat.mSampleRate);
    
            audioFormat.mFormatID           = kAudioFormatAppleIMA4; // record using IMA4 codec
            audioFormat.mChannelsPerFrame   = 1;
    
            AudioQueueNewInput(&audioFormat, ... );
    
            ...
    
        }
    
        return self;
    }
    

    You'll definitely want to read the Audio Queue Services Programming Guide