获取 AVAssetReader 的示例数据

发布于 2024-12-07 06:12:15 字数 555 浏览 0 评论 0原文

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

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

    if(nextBuffer)
    {

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

}

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

I'm trying to get the PCM data from an MP3. I'm using AVAssetReaderOutput and it seems to reading the data fine.

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

    if(nextBuffer)
    {

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

}

I noticed that if I add up countsample, it equates to the number of seconds in the song (assuming 44100hz sample rate). For this reason, I'm sure the reading is being handled perfectly. What I'd like to do, however, is perform various DSP filters on this data but I need to do it on the sample information itself. How can I access the sample data? Also, I noticed that the CMSampleBufferGetNumSamples always returned 8192 except at the end of the song. Is there a way to increase/decrease this read rate?
Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心碎无痕… 2024-12-14 06:12:15

将数据附加到 NSMutableData 对象。

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

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

Append the data to a NSMutableData object.

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

countsample and nextBuffer are assumed to already exist in your code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文