<!--
{
  "availability" : [
    "iOS: 2.0.0 - 8.0.0",
    "iPadOS: 2.0.0 - 8.0.0",
    "macCatalyst: 13.1.0 - 13.1.0",
    "macOS: 10.2.0 - 10.10.0",
    "visionOS: 1.0.0 - 1.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "AudioToolbox",
  "identifier" : "/documentation/AudioToolbox/AudioFileReadPackets(_:_:_:_:_:_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Audio Toolbox"
    ],
    "preciseIdentifier" : "c:@F@AudioFileReadPackets"
  },
  "title" : "AudioFileReadPackets(_:_:_:_:_:_:_:)"
}
-->

# AudioFileReadPackets(_:_:_:_:_:_:_:)

Reads a fixed duration of audio data from an audio file.

```
func AudioFileReadPackets(_ inAudioFile: AudioFileID, _ inUseCache: Bool, _ outNumBytes: UnsafeMutablePointer<UInt32>, _ outPacketDescriptions: UnsafeMutablePointer<AudioStreamPacketDescription>?, _ inStartingPacket: Int64, _ ioNumPackets: UnsafeMutablePointer<UInt32>, _ outBuffer: UnsafeMutableRawPointer?) -> OSStatus
```

## Parameters

`inAudioFile`

The audio file whose audio packets you want to read.

`inUseCache`

Set to `true` to cache the data. Otherwise, set to `false`.

`outNumBytes`

On output, the number of bytes actually read.

`outPacketDescriptions`

On output, an array of packet descriptions for the packets that were read. The array that you pass must be large enough to accommodate descriptions for the number of packets requested in the `ioNumPackets` parameter.

    This parameter applies only to variable bit-rate data. If the file being read contains constant bit-rate (CBR) data, such as linear PCM, this parameter does not get filled. Pass     `NULL`     if the file’s data format is CBR.

`inStartingPacket`

The packet index of the first packet you want to read.

`ioNumPackets`

On input, the number of packets to read. On output, the number of packets actually read.

    You will see a difference in the input and output values when this function has reached the end of the file you are reading. In this case, the output value for this parameter is smaller than its input value.

`outBuffer`

Memory that you allocate to hold the read packets. Determine an appropriate size by multiplying the number of packets requested (in the `ioNumPackets` parameter) by the maximum (or upper bound for) packet size of the audio file. For uncompressed audio formats, a packet is equal to a frame.

## Return Value

A result code. See Result Codes.

## Discussion

If you do not need to read a fixed duration of audio data, but rather want to use your memory buffer most efficiently, use [`AudioFileReadPacketData(_:_:_:_:_:_:_:)`](/documentation/AudioToolbox/AudioFileReadPacketData(_:_:_:_:_:_:_:)) instead of this function.

When reading variable bit-rate (VBR) audio data, using this function requires that you allocate more memory than you would for the [`AudioFileReadPacketData(_:_:_:_:_:_:_:)`](/documentation/AudioToolbox/AudioFileReadPacketData(_:_:_:_:_:_:_:)) function. See the descriptions for the `outBuffer` parameter in each of these two functions.

In addition, this function is less efficient than [`AudioFileReadPacketData(_:_:_:_:_:_:_:)`](/documentation/AudioToolbox/AudioFileReadPacketData(_:_:_:_:_:_:_:)) when reading compressed file formats that do not have packet tables, such as MP3 or ADTS. Use this function only when you need to read a fixed duration of audio data, or when you are reading only uncompressed audio.

Audio File Services reads one 32-bit chunk of a file at a time.

## See Also

[`AudioFileWritePackets(_:_:_:_:_:_:_:)`](/documentation/AudioToolbox/AudioFileWritePackets(_:_:_:_:_:_:_:))

Writes packets of audio data to an audio data file.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)