<!--
{
  "availability" : [
    "iOS: 4.0.0 -",
    "iPadOS: 4.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.7.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreMedia",
  "identifier" : "/documentation/CoreMedia/CMAudioSampleBufferCreateWithPacketDescriptions(allocator:dataBuffer:dataReady:makeDataReadyCallback:refcon:formatDescription:sampleCount:presentationTimeStamp:packetDescriptions:sampleBufferOut:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Core Media"
    ],
    "preciseIdentifier" : "c:@F@CMAudioSampleBufferCreateWithPacketDescriptions"
  },
  "title" : "CMAudioSampleBufferCreateWithPacketDescriptions(allocator:dataBuffer:dataReady:makeDataReadyCallback:refcon:formatDescription:sampleCount:presentationTimeStamp:packetDescriptions:sampleBufferOut:)"
}
-->

# CMAudioSampleBufferCreateWithPacketDescriptions(allocator:dataBuffer:dataReady:makeDataReadyCallback:refcon:formatDescription:sampleCount:presentationTimeStamp:packetDescriptions:sampleBufferOut:)

Creates a sample buffer with packet descriptions and a callback to make the data ready for use.

```
func CMAudioSampleBufferCreateWithPacketDescriptions(allocator: CFAllocator?, dataBuffer: CMBlockBuffer?, dataReady: Bool, makeDataReadyCallback: CMSampleBufferMakeDataReadyCallback?, refcon makeDataReadyRefcon: UnsafeMutableRawPointer?, formatDescription: CMFormatDescription, sampleCount numSamples: CMItemCount, presentationTimeStamp: CMTime, packetDescriptions: UnsafePointer<AudioStreamPacketDescription>?, sampleBufferOut: UnsafeMutablePointer<CMSampleBuffer?>) -> OSStatus
```

## Parameters

`allocator`

The allocator to use for allocating the `CMSampleBuffer` object. Pass `kCFAllocatorDefault` to use the default allocator.

`dataBuffer`

`CMBlockBuffer` for the media data. This can be `NULL`, a `CMBlockBuffer` with no backing memory, a `CMBlockBuffer` with backing memory but no data yet, or a `CMBlockBuffer` that already contains the media data. If `CMBlockBuffer` contains the media data, `dataReady` should be `true`.

`dataReady`

Indicates whether or not the `BlockBuffer` already contains the media data.

`makeDataReadyCallback`

Callback that `CMSampleBufferMakeDataReady` should call to make the data ready. Can be `NULL`.

`makeDataReadyRefcon`

The reference constant, [`CMSampleBufferMakeDataReady(_:)`](/documentation/CoreMedia/CMSampleBufferMakeDataReady(_:)), that this function should pass to the callback.

`formatDescription`

A description of the media data’s format. Can’t be `NULL`.

`numSamples`

Number of samples in the `CMSampleBuffer`. Must not be 0.

`presentationTimeStamp`

Timestamp of the first sample in the buffer. Must be a numeric `CMTime`.

`packetDescriptions`

Array of `packetDescriptions`, one for each of `numSamples`. May be `NULL` if the samples are known to have a constant number of frames per packet and a constant size.

`sampleBufferOut`

On output, points to the newly created `CMSampleBuffer`.

## Return Value

A result code. See [Sample Buffer Error Codes](/documentation/CoreMedia/sample-buffer-errors).

## Discussion

Provides an optimization over `CMSampleBufferCreate`() when the caller already has `packetDescriptions` for the audio data. This routine uses the packetDescriptions to create the sizing and timing arrays required to make the sample buffer if necessary.

## Topics

### Callbacks

[`CMSampleBufferMakeDataReadyCallback`](/documentation/CoreMedia/CMSampleBufferMakeDataReadyCallback)

Client callback called by [`CMSampleBufferMakeDataReady(_:)`](/documentation/CoreMedia/CMSampleBufferMakeDataReady(_:)).



---

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)