0

I am recording two sounds and then mixing them using AVMutableComposition and AVAudioMix. I am able to achieve this using the code given

-(void)saveRecording
{
    AVMutableComposition *composition = [AVMutableComposition composition];
    audioMixParams = [[NSMutableArray alloc] initWithObjects:nil];

    //IMPLEMENT FOLLOWING CODE WHEN WANT TO MERGE ANOTHER AUDIO FILE
    //Add Audio Tracks to Composition
    NSString *docsDir;
    NSArray *dirPaths;
    dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    docsDir = [dirPaths objectAtIndex:0];

    NSString *URLPath1 = [docsDir
                          stringByAppendingPathComponent:@"sound1.caf"];
    NSString *URLPath2 = [docsDir
                          stringByAppendingPathComponent:@"sound2.caf"];
    NSURL *assetURL1 = [NSURL fileURLWithPath:URLPath1];
    [self setUpAndAddAudioAtPath:assetURL1   toComposition:composition];

    NSURL *assetURL2 = [NSURL fileURLWithPath:URLPath2];
    [self setUpAndAddAudioAtPath:assetURL2   toComposition:composition];

    AVMutableAudioMix *audioMix = [AVMutableAudioMix audioMix];
    audioMix.inputParameters = [NSArray arrayWithArray:audioMixParams];

    //If you need to query what formats you can export to, here's a way to find out
    NSLog (@"compatible presets for songAsset: %@",
           [AVAssetExportSession exportPresetsCompatibleWithAsset:composition]);

    AVAssetExportSession *exporter = [[AVAssetExportSession alloc]
                                      initWithAsset: composition
                                      presetName:AVAssetExportPresetAppleM4A];
    //  NSFileManager *fileManager=[NSFileManager defaultManager];

    /*Get the Path  to Application Documents Directory*/
    NSArray *docDir=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

    /*append the neccessary file extension */

    NSString *exportFile=[NSString stringWithFormat:@"/%@/mixed.mp4",docDir];
    NSLog(@"document directory path %@",exportFile);
    exporter.audioMix = audioMix;
    exporter.outputFileType = @"com.apple.m4a-audio";
    NSURL *exportURL = [NSURL fileURLWithPath:exportFile];
    exporter.outputURL = exportURL;

    // do the export
    [exporter exportAsynchronouslyWithCompletionHandler:^{
        int exportStatus = exporter.status;
        NSError *exportError = exporter.error;

        switch (exportStatus) {
            case AVAssetExportSessionStatusFailed:
                NSLog (@"%@",exportError.description);
                break;

            case AVAssetExportSessionStatusCompleted:{
                mixingStatusl=YES;
                NSLog (@"AVAssetExportSessionStatusCompleted");
            }
                break;
            case AVAssetExportSessionStatusUnknown: NSLog (@"AVAssetExportSessionStatusUnknown"); break;
            case AVAssetExportSessionStatusExporting: NSLog (@"AVAssetExportSessionStatusExporting"); break;
            case AVAssetExportSessionStatusCancelled: NSLog (@"AVAssetExportSessionStatusCancelled"); break;
            case AVAssetExportSessionStatusWaiting: NSLog (@"AVAssetExportSessionStatusWaiting"); break;
            default:  NSLog (@"didn't get export status"); break;
        }

        if(mixingStatusl)
        {
            NSArray *docDir=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

            /*append the neccessary file extension */

            NSString *exportFile=[NSString stringWithFormat:@"/%@/mixed.mp4",docDir];
            NSURL *url = [NSURL fileURLWithPath:exportFile];

            NSError *error;
            audioPlayer1 = [[AVAudioPlayer alloc]
                            initWithContentsOfURL:url
                            error:&error];
            if (error)
            {
                NSLog(@"Error in audioPlayer: %@",
                      [error localizedDescription]);
            } else {
                audioPlayer1.delegate = self;
                [audioPlayer1 prepareToPlay];
            }
            [audioPlayer1 play];


        }
    }];
}

Now I need to split the final sound ( mixed.mp4 ) into the separate sounds mixed earlier.Please suggest how to proceed for splitting the mixed.mp4

1 Answers1

0

In general, mixed audio can not be un-mixed, split or separated, unless in completely non-overlapping and known frequency bands, time slots, or channels.

hotpaw2
  • 70,107
  • 14
  • 90
  • 153
  • I am recording both the sounds and mixing them, so is it possible to split mixed file using channels of those sounds that I have recorded. If possible please suggest how to achieve that. – Sumit Kumar Nov 15 '13 at 06:23
  • I'm not sure about your answer, because iMovie doing it – Ofir Malachi Aug 07 '17 at 10:19