Class

AVAudioFormat

A class that represents a buffer of audio data with a format.

Declaration

class AVAudioFormat : NSObject

Overview

Instances of this class are immutable.

This class wraps a Core Audio AudioStreamBasicDescription structure, with convenience initializers and accessors for common formats, including Core Audio’s standard deinterleaved, 32-bit floating-point format.

Topics

Creating a New Audio Format Representation

init(standardFormatWithSampleRate: Double, channelLayout: AVAudioChannelLayout)

Initializes a newly allocated audio format instance as a deinterleaved float with the specified sample rate and channel layout.

init?(standardFormatWithSampleRate: Double, channels: AVAudioChannelCount)

Initializes a newly allocated audio format instance with the specified sample rate and channel count.

init(commonFormat: AVAudioCommonFormat, sampleRate: Double, interleaved: Bool, channelLayout: AVAudioChannelLayout)

Initializes a newly allocated audio format instance with the specified auto format, sample rate, interleaved format and channel layout.

init?(settings: [String : Any])

Initializes a newly allocated audio format instance using a settings dictionary.

init?(streamDescription: UnsafePointer<AudioStreamBasicDescription>)

Initializes a newly allocated audio format instance from a stream description.

init?(streamDescription: UnsafePointer<AudioStreamBasicDescription>, channelLayout: AVAudioChannelLayout?)

Initializes a newly allocated audio format instance from a stream description and channel layout.

init(cmAudioFormatDescription: CMAudioFormatDescription)

Initializes a newly allocated audio format instance from a Core Media audio format description.

Getting the Audio Stream Description

Comparing Instances

func isEqual(Any) -> Bool

Returns a Boolean value that indicates whether the audio format instance and a given object have identical format settings.

Getting Audio Format Values

var channelCount: AVAudioChannelCount

The number of channels of audio data.

var channelLayout: AVAudioChannelLayout?

The underlying audio channel layout.

var sampleRate: Double

The audio format sampling rate in hertz.

var formatDescription: CMAudioFormatDescription

The audio format description as a CMAudioFormatDescription, for use with Core Media APIs.

Determining the Audio Format

var isStandard: Bool

A Boolean value that indicates whether the format is deinterleaved native-endian float.

var isInterleaved: Bool

A Boolean value that describes whether the samples are interleaved.

var commonFormat: AVAudioCommonFormat

The common format identifier.

var settings: [String : Any]

The format represented as a dictionary with keys from AVAudioSettings.

var magicCookie: Data?

An object that contains metadata required by encoders and decoders.

Constants

enum AVAudioCommonFormat

These constants describe the common audio formats.

Relationships

Inherits From

See Also

Formats

class AVAudioChannelLayout

The roles of a set of audio channels.

let AVChannelLayoutKey: String

The corresponding value is an NSData object containing an AudioChannelLayout structure.

Linear PCM Format Settings

Apply audio settings to linear PCM audio formats.

General Audio Format Settings

Audio settings that apply to all audio formats handled by the AVAudioPlayer and AVAudioRecorder classes.