Q:

Parameter required to convert .caf to .wav format?

I want ti convert sound recorded .caf file into .wav file. I m trying to use 
OSStatus AudioFileCreateWithURL( CFURLRef   inFileRef, AudioFileTypeID   inFileType,const AudioStreamBasicDescription *inFormat, UInt32   inFlags,AudioFileID  *outAudioFile);

on above method i stuck on setting two parameter, i mean which parameter i have to set in
const AudioStreamBasicDescription *inFormat and in  UInt32   inFlags,AudioFileID  *outAudioFile.
And in the placement i m trying used following method
- (id)initWithURL:(NSURL *)url settings:(NSDictionary *)settings error:(NSError **)outError

Again i stuck on settings:(NSDictionary *)settings, i mean which parameter i have to be set or used for conversion from .caf to .wav file.
Give me please if any other solution exist in iphone ???

A:

//Here send your file path where you stored .caf file
-(BOOL)exportAssetAsWaveFormat:(NSString*)filePath                  
{
    NSError *error = nil ;

    NSDictionary *audioSetting = [NSDictionary dictionaryWithObjectsAndKeys:
                                  [ NSNumber numberWithFloat:44100.0], AVSampleRateKey,
                                  [ NSNumber numberWithInt:2], AVNumberOfChannelsKey,
                                  [ NSNumber numberWithInt:16], AVLinearPCMBitDepthKey,
                                  [ NSNumber numberWithInt:kAudioFormatLinearPCM], AVFormatIDKey,
                                  [ NSNumber numberWithBool:NO], AVLinearPCMIsFloatKey, 
                                  [ NSNumber numberWithBool:0], AVLinearPCMIsBigEndianKey,
                                  [ NSNumber numberWithBool:NO], AVLinearPCMIsNonInterleaved,
                                  [ NSData data], AVChannelLayoutKey, nil ];

    NSString *audioFilePath = filePath;
    AVURLAsset * URLAsset = [[AVURLAsset alloc]  initWithURL:[NSURL fileURLWithPath:audioFilePath] options:nil];

    if (!URLAsset) return NO ;

    AVAssetReader *assetReader = [AVAssetReader assetReaderWithAsset:URLAsset error:&error];
    if (error) return NO;

    NSArray *tracks = [URLAsset tracksWithMediaType:AVMediaTypeAudio];
    if (![tracks count]) return NO;

    AVAssetReaderAudioMixOutput *audioMixOutput = [AVAssetReaderAudioMixOutput
                                                   assetReaderAudioMixOutputWithAudioTracks:tracks
                                                   audioSettings :audioSetting];

    if (![assetReader canAddOutput:audioMixOutput]) return NO ;

    [assetReader addOutput :audioMixOutput];

    if (![assetReader startReading]) return NO;

    NSString *title = @"WavConverted";
    NSArray *docDirs = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *docDir = [docDirs objectAtIndex: 0];
    NSString *outPath = [[docDir stringByAppendingPathComponent :title]
                         stringByAppendingPathExtension:@"wav" ];

    NSURL *outURL = [NSURL fileURLWithPath:outPath];
    AVAssetWriter *assetWriter = [AVAssetWriter assetWriterWithURL:outURL
                                                          fileType:AVFileTypeWAVE
                                                             error:&error];
    if (error) return NO;

    AVAssetWriterInput *assetWriterInput = [ AVAssetWriterInput assetWriterInputWithMediaType :AVMediaTypeAudio
                                                                                outputSettings:audioSetting];
    assetWriterInput. expectsMediaDataInRealTime = NO;

    if (![assetWriter canAddInput:assetWriterInput]) return NO ;

    [assetWriter addInput :assetWriterInput];

    if (![assetWriter startWriting]) return NO;

    [assetReader retain];
    [assetWriter retain];

    [assetWriter startSessionAtSourceTime:kCMTimeZero ];

    dispatch_queue_t queue = dispatch_queue_create( "assetWriterQueue", NULL );

    [assetWriterInput requestMediaDataWhenReadyOnQueue:queue usingBlock:^{

        NSLog(@"start");

        while (1)
        {
            if ([assetWriterInput isReadyForMoreMediaData]) {

                CMSampleBufferRef sampleBuffer = [audioMixOutput copyNextSampleBuffer];

                if (sampleBuffer) {
                    [assetWriterInput appendSampleBuffer :sampleBuffer];
                    CFRelease(sampleBuffer);
                } else {
                    [assetWriterInput markAsFinished];
                    break;
                }
            }
        }

        [assetWriter finishWriting];
        [assetReader release ];
        [assetWriter release ];

        NSLog(@"finish");
    }];

    dispatch_release(queue);
}

