views:

546

answers:

2

I would like to get your recommendation on what settings to use for audio recording using AVAudioRecorder. Below is the settings I am using currently. Also, what file extension should I save it as so users on Mac or Windows can play it without difficulties? Right now I am saving the file out as .caf

    [settings setValue:[NSNumber numberWithInt: kAudioFormatAppleLossless] forKey:AVFormatIDKey];
    [settings setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
    [settings setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];

    //Linear PCM Format Settings
    [settings setValue:[NSNumber numberWithInt: 32] forKey:AVLinearPCMBitDepthKey];
    [settings setValue:[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
    [settings setValue:[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];

    //Encoder Settings
    [settings setValue:[NSNumber numberWithInt:AVAudioQualityMin] forKey:AVEncoderAudioQualityKey];
    [settings setValue:[NSNumber numberWithInt:96] forKey:AVEncoderBitRateKey];
    [settings setValue:[NSNumber numberWithInt:16] forKey:AVEncoderBitDepthHintKey];
A: 

CAF is a very flexible format, but not widely supported outside of Core Audio-dom.

Since you're recording big-endian PCM, you probably need to use AIFF. If you're keen on being more Windows-friendly, you can use WAV, but you'll have to go little-endian.

invalidname
Actually, IsBigEndian=NO, so it's little endian, so WAV instead of AIFF (There's an undocumented "sowt" AIFF-C which is little-endian; I believe this exists solely so the Audio CD "filesystem" can pass CD audio blocks without byte-swapping. "sowt" is "twos" backwards.)
tc.
A: 

What are you recording audio for? Local playback? Uploading to a server? Streaming over the internet?

A few notes:

  • Use the sampling rate of the audio hardware (is it 32, 44.1, or 48?). Downsampling is a pain. Upsampling just makes your data bigger. Make sure it's actually supported (you can check by looking at the FFT in Audacity or similar; upsampled audio will tend to have a repeated or flat spectrum above some frequency). For example, a Nokia E90 appears to record from the mic at 8 kHz but will upsample to 48 kHz for you.
  • I'm not aware of any hardware that does 32-bit audio. The iPhone probably doesn't even do 24-bit audio. You certainly don't need to; use 16.
  • Apple Lossless isn't supported apart from with QuickTime and accompanying apple products.
  • AVAudioQualityMin might mean "compress quickly" rather than "make it small", i.e. it might sound crap without actually being small.
  • I'm not sure encoder settings matter much for Apple Lossless (the bit rate is probably ignored; the quality might be a size/speed tradeoff).
tc.