iphone - 通过 AVAssetReader 读取音频样本

标签 iphone objective-c cocoa-touch avfoundation

如何通过 AVAssetReader 读取音频样本?我找到了使用 AVAssetReader 进行复制或混合的示例,但这些循环始终由 AVAssetWriter 循环控制。是否可以只创建一个 AVAssetReader 并读取它,获取每个样本并将每个音频样本的 int32 放入数组中?

谢谢。

最佳答案

要扩展@amrox 的答案,您可以从 CMBlockBufferRef 获取 AudioBufferList,例如

CMItemCount numSamplesInBuffer = CMSampleBufferGetNumSamples(buffer);

AudioBufferList audioBufferList;

CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(
      buffer,
      NULL,
      &audioBufferList,
      sizeof(audioBufferList),
      NULL,
      NULL,
      kCMSampleBufferFlag_AudioBufferList_Assure16ByteAlignment,
      &buffer
    );

for (int bufferCount=0; bufferCount < audioBufferList.mNumberBuffers; bufferCount++) {
  SInt16* samples = (SInt16 *)audioBufferList.mBuffers[bufferCount].mData;
  for (int i=0; i < numSamplesInBuffer; i++) {
    // amplitude for the sample is samples[i], assuming you have linear pcm to start with
  }
}

//Release the buffer when done with the samples 
//(retained by CMSampleBufferGetAudioBufferListWithRetainedblockBuffer)
CFRelease(buffer); 

关于iphone - 通过 AVAssetReader 读取音频样本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4972677/

相关文章:

iphone - 在提交的应用中删除功能

iphone - 突出显示单个烛条的核心图

iphone - 使用 iPhone 测量房间

objective-c - 检查磁盘上文件是否存在?

iphone - 是否检测到iPhone应用程序的价格变化?

objective-c - 用于呈现多个模态的 NSNotificationCenter?

iphone - 如何在 iPhone 上访问 safari、facebook 等应用程序的远程连接请求

iOS Objective-C 浮点范围

objective-c - iOS 应用程序 - 如何制作和调用运行时库/应用程序

ios - 每次应用重新启动时我都应该调用 setMinimumBackgroundFetchInterval 吗?