Url:http://blog.csdn.net/ysy441088327/article/details/7392842#reply
To achieve audio interoperability for IPhone and Android. Then the MP3 format of the audio file is no better.
As for being able to convert to AMR is the best, 10 seconds for an amr file with only 5 K size. Ideal for data transfer on mobile devices
The main use of the lame, a very good Mp3 Audio encoder.
What about before the conversion? You need to record the audio file first, before using Avaudiorecorder for audio recording, the following parameters are set:
NSString *recordtemporarypathstring = [NSString stringwithformat:@ "%@/temporary", self.audiotemporarysavepath];// LINEARPCM is a lossless encoding format for iOS, but bulky//recording settings nsmutabledictionary *recordsettings = [[Nsmutabledictionary alloc] init];// The recording format cannot be used [recordsettings setValue: [nsnumber NUMBERWITHINT:KAUDIOFORMATLINEARPCM] forkey:avformatidkey];//sample rate [ Recordsettings setValue: [NSNumber numberwithfloat:11025.0] forkey:avsampleratekey];//44100.0//channel number [recordSettings SetValue: [NSNumber numberwithint:2] forkey:avnumberofchannelskey];//Linear sample number of bits//[recordsettings setValue: [NSNumber NUMBERWITHINT:16] forkey:avlinearpcmbitdepthkey];//audio quality, sample quality [Recordsettings setvalue:[nsnumber numberWithInt: Avaudioqualitymin] Forkey:avencoderaudioqualitykey];
The audio file recorded by the above parameters is very large, but do not worry, this is only the first step, as long as the successful conversion to MP3, you can ensure that the file volume per second around 4K. ^^
Another point, unless you have more time, then there is no need to try to set other kinds of parameters for conversion, because the author I tried a lot, but only the above parameters to ensure that the sound quality is complete and smooth.
The following is an introduction to the lame static library use process mainly has two core files, the use is very simple:
Need to join Lame.h
#include "lame.h"
transcoding to mp3-(void) Audio_pcmtomp3: (NSString *) Caffilepath Andmp3filepath: (NSString *) mp3filepath{nsfilemanager* Filemanager=[nsfilemanager Defaultmanager]; if ([FileManager removeitematpath:mp3filepath Error:nil]) {NSLog (@ "delete"); } @try {int read, write; FILE *PCM = fopen ([Caffilepath cstringusingencoding:1], "RB"); Source converted audio File location if (PCM = = NULL) {NSLog (@ "File not Found"); } else {fseek (PCM, 4*1024, seek_cur); Skip file header File *mp3 = fopen ([Mp3filepath cstringusingencoding:1], "WB"); MP3 file location generated by output outputs const int pcm_size = 8192; const int mp3_size = 8192; short int pcm_buffer[pcm_size*2]; unsigned char mp3_buffer[mp3_size]; lame_t lame = Lame_init (); Lame_set_in_samplerate (Lame, 11025.0); LAME_SET_VBR (Lame, vbr_default); Lame_init_paRams (LAME); do {read = Fread (pcm_buffer, 2 * sizeof (short int), pcm_size, PCM); if (read = = 0) write = Lame_encode_flush (lame, mp3_buffer, mp3_size); else Write = lame_encode_buffer_interleaved (lame, pcm_buffer, read, Mp3_buffer, mp3_size); Fwrite (Mp3_buffer, Write, 1, mp3); } while (read! = 0); Lame_close (lame); Fclose (mp3); Fclose (PCM); }} @catch (NSException *exception) {NSLog (@ "%@", [exception description]); } @finally {NSLog (@ "MP3 generated successfully"); }}
Lamp Download Area Password: 3gy2
iOS CAF audio converted to MP3