0

2 つのサウンドを録音し、AVMutableComposition と AVAudioMix を使用してそれらをミキシングしています。指定されたコードを使用してこれを達成できます

-(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];


        }
    }];
}

ここで、最終的なサウンド ( mixed.mp4 ) を以前にミックスされた個別のサウンドに分割する必要があります。mixed.mp4 を分割する方法を提案してください。

4

1 に答える 1

0

一般に、混合オーディオは、完全に重複しておらず、既知の周波数帯域、タイムスロット、またはチャネルでない限り、混合解除、分割、または分離することはできません。

于 2013-11-13T17:14:19.523 に答える