views:

64

answers:

0

Hi,

I am trying to record some audio and convert them to other sound formats. I am using AVAudioRecorder class to record and these are the recording settings I used..

 NSDictionary *recordSetting = [[NSMutableDictionary alloc] init];
 [recordSetting setValue:[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey];//kAudioFormatMicrosoftGSM,kAudioFormatLinearPCM
 [recordSetting setValue:[NSNumber numberWithFloat:8000] forKey:AVSampleRateKey]; 
 [recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
 [recordSetting setValue :[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
 [recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
 [recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];

Recording is working beautifully. Now I want to convert this sound file to mp3 format. Can I do this with AudioToolBox framework. I tried this

 AudioStreamBasicDescription sourceFormat,destinationFormat;
 //Setting up source Format setting..here wav
 sourceFormat.mSampleRate   = 8000.0;
 sourceFormat.mFormatID    = kAudioFormatLinearPCM;
 sourceFormat.mFormatFlags   = kAudioFormatFlagIsSignedInteger ;
 sourceFormat.mBytesPerPacket  = 4;
 sourceFormat.mFramesPerPacket  = 1;
 sourceFormat.mBytesPerFrame   = 4;
 sourceFormat.mChannelsPerFrame  = 2;
 sourceFormat.mBitsPerChannel  = 16;

 destinationFormat.mSampleRate  = 8000.0;
 destinationFormat.mFormatID   = kAudioFormatMPEGLayer3;
 destinationFormat.mFormatFlags  = 0;
 destinationFormat.mBytesPerPacket = 4;
 destinationFormat.mFramesPerPacket = 1;
 destinationFormat.mBytesPerFrame = 4;
 destinationFormat.mChannelsPerFrame = 2;
 destinationFormat.mBitsPerChannel = 16;

 OSStatus returnCode     =     AudioConverterNew(&sourceFormat,&destinationFormat,&converter);
 if (returnCode) {
    NSLog(@"error getting converter : %d",returnCode);
    return;
 }

The function AudioConverterNew() is giving me error kAudioConverterErr_FormatNotSupported ('fmt'). I tried with different mFormatID and mFormatFlag combinations. But whenever one of the operant (source or destination) is mp3 I am getting this error. Now please help me with these questions.

  1. Can we use AudioToolbox framework and functions to convert sounds between compressed and non compressed format (At present I want to convert between .wav and .mp3). In the AudioConverterNew documentation they are saying "Encoding and decoding between linear PCM and compressed formats is supported". But they are not specifically saying which compressed formats.

  2. If the answer to question 1 is 'no' then which framework do I need to use to convert the sound between above mentioned formats?

  3. Not related to above 2, but can anybody give me a link to any websites where information about different sound formats (wav,mp3,aac etc ) and their digital representations (cpm,lpcm etc) so that I can understand which uses what.