gpt4 book ai didi

iphone - 通过 AVAssetReader 读取音频样本

转载 作者:太空狗 更新时间:2023-10-30 03:16:15 27 4
gpt4 key购买 nike

如何通过 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com