2

I'm using AudioToolbox to access m4a audio files with following code:

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;
}

My audio format is: AppleM4A, 8000 Hz, 16 Bit, 4096 frames per packet

Denis Mikhaylov
  • 2,035
  • 21
  • 24

2 Answers2

1

The solution was to use extended audio file services. You just have to set up transition between client format and PCM. Got the right way overthere Audio Processing: Playing with volume level.

Community
  • 1
  • 1
Denis Mikhaylov
  • 2,035
  • 21
  • 24
0

To get waveform data, you may first need to convert your compressed audio file into raw PCM samples, such as found inside a WAV file, or other non-compressed audio format. Try AVAssetReader, et.al.

hotpaw2
  • 70,107
  • 14
  • 90
  • 153