## iOS音频开发之AudioStreamBasicDescription

• 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.

PCM时采样频率叫做sample rate。

mSampleRate，就是采用频率
mBitsPerChannel，就是每个采样数据的位数
mChannelsPerFrame,可以理解为声道数，也就是一个采样时刻产生几个采样数据。
mFramesPerPacket，就是每个packet的中frame的个数，等于这个packet中经历了几次采样间隔。
mBytesPerPacket，每个packet中数据的字节数。
mBytesPerFrame，每个frame中数据的字节数

## 计算公式

1. 计算每个packet的持续时间

duration = (1 / mSampleRate) * mFramesPerPacket

2. 计算mBitsPerChannel
对于kAudioFormatFlagsCanonical的PCM数据，有以下公式。大概每个采样数据的字节数用AudioSampleType描述。

mBitsPerChannel = 8 * sizeof (AudioSampleType);

3. 计算mBytesPerFrame

mBytesPerFrame = n * sizeof (AudioSampleType);


其中n是声道数目

posted on 2016-09-21 23:44  花老🐯  阅读(1479)  评论(0编辑  收藏