这个类提供了对于音频文件的描述
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以后的数字信号->压缩、编码以后的音频文件。
PCM时采样频率叫做sample rate。
每一次采样可以得到若干采样数据,对应多个channel。
每一个采样点得到的若干采样数据组合起来,叫做一个frame。
若干frame组合起来叫做一个packet。
mSampleRate
,就是采用频率
mBitsPerChannel
,就是每个采样数据的位数
mChannelsPerFrame
,可以理解为声道数,也就是一个采样时刻产生几个采样数据。
mFramesPerPacket
,就是每个packet的中frame的个数,等于这个packet中经历了几次采样间隔。
mBytesPerPacket
,每个packet中数据的字节数。
mBytesPerFrame
,每个frame中数据的字节数
计算每个packet的持续时间
duration = (1 / mSampleRate) * mFramesPerPacket
计算mBitsPerChannel
对于kAudioFormatFlagsCanonical
的PCM数据,有以下公式。大概每个采样数据的字节数用AudioSampleType
描述。
mBitsPerChannel = 8 * sizeof (AudioSampleType);
计算mBytesPerFrame
mBytesPerFrame = n * sizeof (AudioSampleType);
其中n是声道数目