I had never done audio programming before I started my iPhone programming. After starting iPhone programming, I started to learn CoreAudio Framework, Audio Unit for Mac OS X system and iPhone System, and largest problem is which audio format should I choose for best practice?
After iPhone OS 3.0 beta was released, Apple finally introducedAVAudioRecorder class to AVFoundation framework. With which, we can play and record audio more efficiently! For me, I can cut the original playback code down from 400+ lines to 20 lines. And for recording, cut down from 300+ lines to 30 lines.
When testing AVAudioRecorder, the file format will significantly effect the file size. I had tried all the available data format when packed with .CAF file. Here is the result:
[Updated@2009-05-25] YES, we can record with this format on simulator, but we CANNOT record this on the device! Remember this. While another one we can refer to is Apple’s official QA1615
[Updated@2009-06-15] Please do not use AAC if you want to play a system sound.
[Updated@2009-09-30] iPhone 3GS support AAC recording since iPhone OS 3.1 was released on Sept 9th. You can use hardware assisted encoding to record the AAC formatted audio file. But let me remind you, you can notuse AVAudioRecord to record AAC audio file yet. The only option is using the RemoteIO Unit.
- kAudioFormatLinearPCM = ‘lpcm’, OK 20.2M .CAF
- kAudioFormatAppleIMA4 = ‘ima4′, OK 2.7M .CAF[Best Choice]
- kAudioFormatMPEG4AAC = ‘aac ‘, OK 968K .CAF[Updated 2009-05-25], [Updated 2009-09-30] Best Choice for iPhone 3GS
- kAudioFormatMACE3 = ‘MAC3′, NG .CAF
- kAudioFormatMACE6 = ‘MAC6′, NG .CAF
- kAudioFormatULaw = ‘ulaw’, OK 5.1M .CAF
- kAudioFormatALaw = ‘alaw’, OK 5.1M .CAF
- kAudioFormatQDesign = ‘QDMC’, NG .CAF
- kAudioFormatQDesign2 = ‘QDM2′, NG .CAF
- kAudioFormatQUALCOMM = ‘Qclp’, NG .CAF
- kAudioFormatMPEGLayer1 = ‘.mp1′, NG .CAF
- kAudioFormatMPEGLayer2 = ‘.mp2′, NG .CAF
- kAudioFormatMPEGLayer3 = ‘.mp3′, NG .CAF
- kAudioFormatAppleLossless = ‘alac’ OK 4M .CAF
- kAudioFormatMPEG4AAC_LD = ‘aacl’, NG .CAF
- kAudioFormatAMR = ‘samr’, NG .CAF
- kAudioFormatiLBC = ‘ilbc’, NG Wierd .CAF
The list here has omitted all the other data format that are not supported by CAF file extension. You can use the console application afconvert to verify each supported file format and data format via typing this:
afconvert -h
All the tests were recorded in 60 seconds, with sample rate@44100, 2 channels, 96kbps. The RecordSetting Dictionary object is used as below:
recordSetting = [[NSMutableDictionary alloc] init];
//General Audio Format Settings (Necessary for all audio format.)
[recordSetting setValue:[NSNumber numberWithInt:kAudioFormatMPEG4AACkAudioFormatAppleIMA4] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
//Linear PCM Format Settings (only necessary when you want to record Liner PCM format)
[recordSetting setValue:[NSNumber numberWithInt: 32] forKey:AVLinearPCMBitDepthKey];
[recordSetting setValue:[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
[recordSetting setValue:[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];
//Encoder Settings (Only necessary if you want to change it.)
[recordSetting setValue:[NSNumber numberWithInt:AVAudioQualityMin] forKey:AVEncoderAudioQualityKey];
[recordSetting setValue:[NSNumber numberWithInt:96] forKey:AVEncoderBitRateKey];
[recordSetting setValue:[NSNumber numberWithInt:16] forKey:AVEncoderBitDepthHintKey];
//Sample Rate Conversion Settings (Only necessary when you want to change the sample rate to a value different to the hardware sample rate, AVAudioQualityHigh means no conversion, usually, 44.1KHz)
[recordSetting setValue:[NSNumber numberWithInt:AVAudioQualityHigh] forKey:AVSampleRateConverterAudioQualityKey];
[Updated 2009-09-30], The record settings listed above was for example only, if you want to record IMA4 or other compressed audio format, you are no need to put the Liner PCM part. Other parts are commented for their purpose.
You can see, the MPEG4AAC has the minimum file size and same quality when compare to other file formats. About the AAC format, please refer to [Wikipedia – AAC"]
Apple, you could just give us a best practice guide! So I won’t need to test it one by one myself. OK, I know, you are working out of people, hire me, I would love to do these works.
相关推荐
Getting Started with C++ Audio Programming for Game Developers is a quick and practical introduction to the most important audio programming topics that any game developer is expected to know....
Best Practices for Programming Eclipse and OSGi.pdf Best Practices for Programming Eclipse and OSGi.pdf
It's a great time to go for Cocoa, because it's not only Apple's preferred framework for developing software, it's also the best way for you to create software for Mac OS X and iPhone. This book gives...
How to select the best digital audio data codec and format for your digital audio content application How to go about data footprint optimization, to ascertain which audio formats give the best ...
Welcome to ASP Programming for the Absolute Beginner. By developing an interest in Active Server Pages (ASP), you stand at the threshold of a very exciting programming adventure. When first introduced...
3D Game Programming for Kids: Create Interactive Worlds with JavaScript, 2nd Edition by Chris Strom epub电子书 English | 2018 | ISBN: 1680502701 | 374 Pages | EPUB | 14 MB You know what’s even ...
NHTSA_Cybersecurity Best Practices for Modern Vehicles
《Prolog Programming for Artificial Intelligence》附书源码
CHM <br>Overview The best-selling introduction to Cocoa, once again updated to cover the latest Mac programming technologies, and still enthusiastically recommended by experienced Mac OS X ...
Prolog Programming for Artificial Intelligence 第四版(2011) 作者 Ivan Bratko ISBN-13: 978-0321417466 ISBN-10: 0321417461 This best-selling guide to Prolog and Artificial Intelligence, which has ...
3D Game Programming for Kids: Create Interactive Worlds with JavaScript by Chris Strom English | 2013 | 308 Pages | True PDF, EPUB | 18 MB You know what's even better than playing games? Creating ...
Python is the high-level language of choice for hackers and software security analysts because it makes it easy to write powerful and effective security tools. A follow-up to the perennial best-seller...
Incredible iPhone Apps For Dummies,英文版本,PDF 格式,大小 13 Mb,作者 Bob LeVitus,2010 年 2 月出版。 A full-color directory of must-have iPhone and iPod touch apps! The App Store allows you to ...
windows 程序开发人员必备的参考书。这本书可以帮助您理解windows的精髓和核心构成。这应该是同类书中最权威,讲解最透彻的一本书。-A excellent windows ... It is the best book of the same category you can find.
Chapter 9: Best Practices for Function-Based Views Chapter 10: Best Practices for Class-Based Views Chapter 11: Form Fundamentals Chapter 12: Common Patterns for Forms Chapter 13: Templates: Best ...
Filled with insights from game industry pros, this volume provides faster, better tools and techniques for making the best games possible. These techniques have been used in today's most successful ...
The "iOS Application Programming Guide" is a comprehensive resource designed to help developers create applications for Apple's iOS platform, including the iPhone, iPad, and iPod touch. It covers a ...