iphone - 获取 AVAssetReader 的示例数据

标签 iphone objective-c ios audio core-audio

我正在尝试从 MP3 获取 PCM 数据。我正在使用 AVAssetReaderOutput,它似乎可以很好地读取数据。

while(true)
{
    nextBuffer = [assetReaderOutput copyNextSampleBuffer];

    if(nextBuffer)
    {

       countsample = CMSampleBufferGetNumSamples(nextBuffer);
       NSLog(@"%i", countsample);
    }

}

我注意到,如果我将 countsample 加起来,它就等于歌曲中的秒数(假设采样率为 44100hz)。因此,我确信阅读处理得非常完美。然而,我想做的是对这些数据执行各种 DSP 过滤器,但我需要对样本信息本身执行此操作。我如何访问示例数据?另外,我注意到 CMSampleBufferGetNumSamples 总是返回 8192,除了歌曲结尾处。有没有办法提高/降低这个读取率? 谢谢

最佳答案

将数据附加到 NSMutableData 对象。

NSMutabelData *samples = [NSMutabelData data];
while(countsample)
{
    nextBuffer = [assetReaderOutput copyNextSampleBuffer];
    if(nextBuffer)
    {
       countsample = CMSampleBufferGetNumSamples(nextBuffer);
       [samples appendBytes:nextBuffer length:countsample];
    }
}

countsamplenextBuffer 假定已存在于您的代码中。

关于iphone - 获取 AVAssetReader 的示例数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7590851/

相关文章:

iphone - XCode 中的 header 搜索路径 - 是否可以设置宏或变量,以便它们与 SDK 版本相关?

iphone - 什么时候用 self 访问属性,什么时候不访问?

ios - Xcode 4.2或4.6的iOS 7部署

iOS:如何以最简单的方式测试互联网连接,而不卡住应用程序(没有可达性)?

ios - UITableViewCell 框架高度始终为 44px

iphone - 如何将字符串中的单个字符保存到 NSDictionary 对象中

iphone - iOS 导航 Controller 后退按钮导致故障

objective-c - 我如何真正用 NSNumbers 做数学? (在 obj-c 中实现 lisp)

objective-c - 我的类别的 +load 没有被调用,但只在存档构建中

iOS - 单击按钮时更改 CALayer 的大小然后返回到原始大小