在iOS上将立体声音频拆分为单声道流

编程入门 行业动态 更新时间:2024-10-11 23:16:23
本文介绍了在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处获得示例代码: developer.apple/library/ios/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/05_Export.html

Update: I've managed to get the sample code working from apple thats here: developer.apple/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; }

推荐答案

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

更多推荐

在iOS上将立体声音频拆分为单声道流

本文发布于:2023-06-03 07:05:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/471240.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:上将   立体声   单声道   音频   iOS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!