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

# AudioCodecInitialize(_:_:_:_:_:)

Sets up the specified codec to perform a data format translation.

```
func AudioCodecInitialize(_ inCodec: AudioCodec, _ inInputFormat: UnsafePointer<AudioStreamBasicDescription>?, _ inOutputFormat: UnsafePointer<AudioStreamBasicDescription>?, _ inMagicCookie: UnsafeRawPointer?, _ inMagicCookieByteSize: UInt32) -> OSStatus
```

## Parameters

`inCodec`

An audio codec object. Because an audio codec object is a Component Manager component instance, you can use the Component Manager (for example, the functions <doc://com.apple.documentation/documentation/coreservices/1516552-findnextcomponent> and OpenAComponent) to obtain an audio codec object.

`inInputFormat`

A structure that describes the format of the input data. See <doc://com.apple.documentation/documentation/CoreAudio/core-audio-data-types> for a description of this structure and the values of constants that can be used in this structure. If the input data has a variable number of frames per packet, this structure is supplemented with the `AudioStreamPacketDescription` structure passed in the `inPacketDescription` parameter of the [`AudioCodecAppendInputData(_:_:_:_:_:)`](/documentation/AudioToolbox/AudioCodecAppendInputData(_:_:_:_:_:)) function.

`inOutputFormat`

A structure that describes the format desired for the output data.

`inMagicCookie`

Magic cookie data, if required for the input format.

`inMagicCookieByteSize`

Size in bytes of the magic cookie data, if any.

## Return Value

Returns `NoErr` if successful. Returns `kAudioCodecUnsupportedFormatError` if the codec cannot handle the specified data translation.  See `Result Codes` for other possible values.

## Discussion

This function allocates any buffers needed, sets the input and output formats, and puts the codec into the initialized state. The codec has to be in the initialized state for the  [`AudioCodecAppendInputData(_:_:_:_:_:)`](/documentation/AudioToolbox/AudioCodecAppendInputData(_:_:_:_:_:)) and [`AudioCodecProduceOutputPackets(_:_:_:_:_:_:)`](/documentation/AudioToolbox/AudioCodecProduceOutputPackets(_:_:_:_:_:_:)) functions to work. While in this state, the format information for the translation cannot be changed; you must call the [`AudioCodecUninitialize(_:)`](/documentation/AudioToolbox/AudioCodecUninitialize(_:)) function before making any changes.
A codec’s properties provide information about allowable types of input and output, magic cookies, and so forth. Use the [`AudioCodecGetProperty(_:_:_:_:)`](/documentation/AudioToolbox/AudioCodecGetProperty(_:_:_:_:)) function to read a codec’s properties. The properties are described in [Global Codec Properties](/documentation/AudioToolbox/1494121-global-codec-properties) and [Instance Codec Properties](/documentation/AudioToolbox/1494111-instance-codec-properties).

If any argument is `NULL`, any values previously set for that argument are used. For example, if you are using the same codec repeatedly with the same input and output formats, you only need to enter the formats the first time you initialize the codec. After that, you can uninitialize, change property values as necessary, and then call this function again with `NULL` in the `inInputFormat` and `inOutputFormat` parameters before processing the next set of data.

## See Also

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

Retrieves output data from a codec.

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

Appends audio data to the codec’s input buffer.

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

Retrieves the value of a codec property.



---

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)