gpt4 book ai didi

objective-c - 如何从 AudioBufferList 中读取样本?

转载 作者:可可西里 更新时间:2023-11-01 04:22:58 25 4
gpt4 key购买 nike

如果我使用以下客户端数据格式打开具有扩展音频文件服务的音频文件...

AudioStreamBasicDescription audioFormat;
memset(&audioFormat, 0, sizeof(audioFormat));
audioFormat.mSampleRate = 44100.0;
audioFormat.mFormatID = kAudioFormatLinearPCM;
audioFormat.mFormatFlags = kAudioFormatFlagIsBigEndian |
kAudioFormatFlagIsSignedInteger |
kAudioFormatFlagIsPacked;
audioFormat.mBytesPerPacket = 4;
audioFormat.mFramesPerPacket = 1;
audioFormat.mChannelsPerFrame = 2;
audioFormat.mBytesPerFrame = 4;
audioFormat.mBitsPerChannel = 16;

然后像这样配置一个 AudioBufferList....

AudioBufferList bufferList;
bufferList.mNumberBuffers = 1;
bufferList.mBuffers[0].mDataByteSize = bufferSize;
bufferList.mBuffers[0].mNumberChannels = audioFormat.mChannelsPerFrame;
bufferList.mBuffers[0].mData = buffer; //malloc(sizeof(UInt8) * 1024 * audioFormat.mBytesPerPacket)

那么mData中的数据是如何排列的呢?如果我像这样遍历数据

for (int i = 0; i < frameCount; i++) {
UInt8 somePieceOfAudioData = buffer[i];
}

那么什么是 somePieceOfAudioData。

是样本还是帧(左右声道一起)?如果它是一个样本,那么它是哪个 channel 的样本?例如,如果它是来自右声道的样本,那么 buffer[i + 1] 会是左声道的样本吗?

任何想法,链接?谢谢!

最佳答案

除非设置了 kAudioFormatFlagIsNonInterleaved,否则音频数据应该是交错的。我发现对于 Core Audio 问题,最好的文档来源通常是标题。 CoreAudioTypes.h 包含以下注释:

Typically, when an ASBD is being used, the fields describe the complete layout of the sample data in the buffers that are represented by this description - where typically those buffers are represented by an AudioBuffer that is contained in an AudioBufferList.

However, when an ASBD has the kAudioFormatFlagIsNonInterleaved flag, the AudioBufferList has a different structure and semantic. In this case, the ASBD fields will describe the format of ONE of the AudioBuffers that are contained in the list, AND each AudioBuffer in the list is determined to have a single (mono) channel of audio data. Then, the ASBD's mChannelsPerFrame will indicate the total number of AudioBuffers that are contained within the AudioBufferList - where each buffer contains one channel. This is used primarily with the AudioUnit (and AudioConverter) representation of this list - and won't be found in the AudioHardware usage of this structure.

在您的特定情况下,缓冲区将由从左声道开始的交错短裤组成。

关于objective-c - 如何从 AudioBufferList 中读取样本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8857145/

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