在iOS上将立体声音频拆分为单声道流 [英] split stereo audio to mono streams on iOS

查看:309
本文介绍了在iOS上将立体声音频拆分为单声道流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对此表示歉意.我见过很多问题,但没有很好的答案.

Apologies if this has been answered. I've seen lots of questions but no good answers.

我正在尝试将iPod音乐从iPod库导出到两个mono caf文件.如何在iOS上执行此操作?我目前正在使用Objective C.

I'm trying to export stereo music from my iPod library to two mono caf files. How can I do this on iOS? I'm currently using Objective C.

谢谢!

更新:我已经设法从以下位置的Apple处获得示例代码:

Update: I've managed to get the sample code working from apple thats here: https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/05_Export.html

我的代码现在将导入媒体文件,并输出为可以正常播放的有效caf文件.我的问题是在写缓冲区之前我无法弄清楚如何修改缓冲区.这是我到目前为止的代码:

My code will now import a media file and output as a valid caf file which plays fine. My problem is I can't work out how to modify the buffer before writing it. Here is my code I have so far:

// Get the next audio sample buffer, and append it to the output file.
CMSampleBufferRef sampleBuffer = [self.assetReaderAudioOutput copyNextSampleBuffer];
if (sampleBuffer != NULL)
{
    /////////////////////////////////////////
    CMBlockBufferRef blockBuffer;
    AudioBufferList audioBufferList;
    NSMutableData *data= [NSMutableData data];

    CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(sampleBuffer, NULL, &audioBufferList, sizeof(AudioBufferList), NULL, NULL, kCMSampleBufferFlag_AudioBufferList_Assure16ByteAlignment, &blockBuffer);

    AudioBuffer audioBuffer = audioBufferList.mBuffers[0];

    for( int y=0; y< audioBufferList.mNumberBuffers; y=y+4 ){
        [data appendBytes:(audioBuffer.mData+y) length:2];
    }

    // how do I replace data in sampleBuffer with new data?

    CFRelease(blockBuffer);

    //////////////////////////////////////////

    BOOL success = [self.assetWriterAudioInput appendSampleBuffer:sampleBuffer];

    CFRelease(sampleBuffer);
    sampleBuffer = NULL;
    completedOrFailed = !success;
}
else
{
    completedOrFailed = YES;
}

推荐答案

我设法通过手动创建标头并写入文件来做到这一点.这篇文章给了我大部分我需要的东西: https://stackoverflow.com/a/8677726/313272

I've managed to do this by manually creating the header and writing to the file. This post gave me most of what I needed: https://stackoverflow.com/a/8677726/313272

这篇关于在iOS上将立体声音频拆分为单声道流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆