The work of the previous time, and the audio related to iOS, need a function: Convert audio from WAV format to MP3 format. This demand is not very strong, but it is not very good to achieve.
So I wrote an open source library for audio format conversion, which contains all the audio formats supported by Ios/os X, and also supports the MP3 format (implemented with lame). It is modeled on the parameters of the command on OS X afconvert and will be more widely used in the future than Afconvert.
Open Source Library named Extaudioconverter, based on extaudiofile implementation. Link here: Https://github.com/lixing123/ExtAudioConverter
How to use:
- Add "Audiotoolbox.framework" to the project;
- Add "ExtAudioConverter.h" and "EXTAUDIOCONVERTER.M" to the project;
- Test:
ExtAudioConverter* converter = [[ExtAudioConverter alloc] init]; converter.inputFile = @"/your/input/file"; converter.outputFile = @"/your/output/file"; [converter convert];
The code is tested on iOS and OS X.
Some optional parameters:
1. Sample Rate
converter.outputSampleRate = 44100;
- Number of channels
converter.outputNumberChannels = 2;
- Bit depth
converter.outputBitDepth = BitDepth_16;
- Set file format
converter.outputFileType = kAudioFileWAVEType;
- Set data format
converter.outputFormatID = kAudioFormatLinearPCM;
Documentation on file format and data format, here: https://developer.apple.com/library/ios/documentation/MusicAudio/Conceptual/ Coreaudiooverview/supportedaudioformatsmacosx/supportedaudioformatsmacosx.html
In short, a file format corresponds to one or more data formats, such as MP3 file formats that correspond to MP3 data FORMAT,CAF (Core Audio format) for almost all data format. Therefore, the default output file format of the ToolPak is the CAF format.
There is no setup interface for bit rate at this time. The following will be added as needed.
If you need a classmate, you can download it. If you have questions and suggestions, please
1. Contact me for comments under this article;
2. Send issues to the project below;
3. e-mail to my email:[email protected]
With a GitHub account, a star/follow can encourage me to continue to contribute to the open source community, thank you!
iOS Audio Format Conversion Tool Gallery: Extaudioconverter