获取m4a文件的原始样本数据以绘制波形

时间:2011-09-09 10:44:29

标签: objective-c signal-processing audiotoolbox m4a

我正在使用AudioToolbox访问m4a音频文件,代码如下:

UInt32 packetsToRead = 1; //Does it makes difference?

void *buffer = malloc(maxPacketSize * packetsToRead);

for (UInt64 packetIndex = 0; packetIndex < packetCount; packetIndex++)
{
   ioNumberOfPackets = packetsToRead;
   ioNumberOfBytes = maxPacketSize * ioNumberOfPackets;

   AudioFileReadPacketData(audioFile, NO, &ioNumbersOfBytes, NULL, packetIndex, &ioNumberOFPackets, buffer);
    for (UInt32 batchPacketIndex = 0; batchPacketIndex < ioNumberOfPackets; batchPacketIndex++)
    {
    //What to do here to get amplitude value? How to get sample value?
    }
    packetIndex+=ioNumberOfPackets;
}

我的音频格式为: AppleM4A,8000 Hz,16位,每包4096帧

2 个答案:

答案 0 :(得分:1)

解决方案是使用扩展音频文件服务。您只需设置客户端格式和PCM之间的转换。正确的方法Audio Processing: Playing with volume level

答案 1 :(得分:0)

要获取波形数据,您可能首先需要将压缩的音频文件转换为原始PCM样本,例如在WAV文件中找到的或其他非压缩音频格式。尝试AVAssetReader,et.al。