2011-09-09 116 views
2

我使用AudioToolbox訪問與下面的代碼M4A等音頻文件:獲取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赫茲,16位,4096幀每個數據包

回答

0

要獲得波形數據,您可能首先需要將壓縮音頻文件轉換爲原始PCM樣本,如在WAV文件內或其他非壓縮音頻格式中找到。嘗試AVAssetReader,et.al.

+0

AVAssetReader對於實時分析來說太慢了。這是我第一次解決這個問題。 –