Record “Apple lossless” audio on the iPhone
-
22-08-2019 - |
Question
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
OTHER TIPS
Take a look at the SpeakHere example on the Apple iPhone Dev center.
I use iTalk Recorder Premium for .aiff (uncompressed), then export to laptop and use flac to compress it - it by default keep time stamps.
flac --best *.aiff