這個類提供了對於音頻文件的描述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 audi... ...
這個類提供了對於音頻文件的描述
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是聲道數目