Structure

AudioStreamBasicDescription

An audio data format specification for a stream of audio.

Declaration

struct AudioStreamBasicDescription

Overview

You can configure an audio stream basic description (ASBD) to specify a linear PCM format or a constant bit rate (CBR) format that has channels of equal size. For variable bit rate (VBR) audio, and for CBR audio where the channels have unequal sizes, each packet must additionally be described by an AudioStreamPacketDescription structure.

A field value of 0 indicates that the value is either unknown or not applicable to the format.

Always initialize the fields of a new audio stream basic description structure to zero, as shown here:

AudioStreamBasicDescription myAudioDataFormat = {0};

To determine the duration represented by one packet, use the mSampleRate field with the mFramesPerPacket field, as follows:

duration = (1 / mSampleRate) * mFramesPerPacket

In Core Audio, the following definitions apply:

  • An audio stream is a continuous series of data that represents a sound, such as a song.

  • A channel is a discrete track of monophonic audio. A monophonic stream has one channel; a stereo stream has two channels.

  • A sample is single numerical value for a single audio channel in an audio stream.

  • A frame is a collection of time-coincident samples. For instance, a linear PCM stereo sound file has two samples per frame, one for the left channel and one for the right channel.

  • A packet is a collection of one or more contiguous frames. A packet defines the smallest meaningful set of frames for a given audio data format, and is the smallest data unit for which time can be measured. In linear PCM audio, a packet holds a single frame. In compressed formats, it typically holds more; in some formats, the number of frames per packet varies.

  • The sample rate for a stream is the number of frames per second of uncompressed (or, for compressed formats, the equivalent in decompressed) audio.

Topics

Instance Properties

var mBitsPerChannel: UInt32

The number of bits for one audio sample.

var mBytesPerFrame: UInt32

The number of bytes from the start of one frame to the start of the next frame in an audio buffer. Set this field to 0 for compressed formats.

var mBytesPerPacket: UInt32

The number of bytes in a packet of audio data. To indicate variable packet size, set this field to 0. For a format that uses variable packet size, specify the size of each packet using an AudioStreamPacketDescription structure.

var mChannelsPerFrame: UInt32

The number of channels in each frame of audio data. This value must be nonzero.

var mFormatFlags: AudioFormatFlags

Format-specific flags to specify details of the format. Set to 0 to indicate no format flags. See Audio Data Format Identifiers for the flags that apply to each format.

var mFormatID: AudioFormatID

An identifier specifying the general audio data format in the stream. See Audio Data Format Identifiers. This value must be nonzero.

var mFramesPerPacket: UInt32

The number of frames in a packet of audio data. For uncompressed audio, the value is 1. For variable bit-rate formats, the value is a larger fixed number, such as 1024 for AAC. For formats with a variable number of frames per packet, such as Ogg Vorbis, set this field to 0.

var mReserved: UInt32

Pads the structure out to force an even 8-byte alignment. Must be set to 0.

var mSampleRate: Float64

The number of frames per second of the data in the stream, when the stream is played at normal speed. For compressed formats, this field indicates the number of frames per second of equivalent decompressed data.