2015-04-21 24 views
1

我正在使用音頻設備錄製一些PCM音頻。在回調中,當我有30秒的音頻時,我想要以12kb/s比特率寫入8000Hz AAC編碼文件的磁盤。如何在Coreaudio中爲AudioStreamBasicDescription指定比特率?

這是我使用的AudioStreamBasicDescription,但我的輸出結果是40 kb/s。我的問題是,我可以改變一些參數來降低比特率,如果是這樣,我修改哪些參數?

// specify the M4A 
    AudioStreamBasicDescription outputFormat = {0}; 

    outputFormat.mSampleRate   = 8000.0; 
    outputFormat.mFormatID   = kAudioFormatMPEG4AAC; 
    outputFormat.mFormatFlags  = kMPEG4Object_AAC_Main; 
    outputFormat.mChannelsPerFrame = 1; 

回答

1

請參閱AudioStreamBasicDescription中的字段mBitsPerChannel

一個音頻採樣的位數。例如,對於使用kAudioFormatFlagsCanonical格式標誌線性PCM音頻,計算值該字段如下:

mBitsPerChannel = 8 * sizeof (AudioSampleType); 

將此字段設置爲0的壓縮格式。

https://developer.apple.com/library/ios/documentation/MusicAudio/Reference/CoreAudioDataTypesRef/#//apple_ref/c/tdef/AudioStreamBasicDescription

+0

謝謝,這就是我一直在尋找的東西。 – blueether

+1

這設置位深度,但不是位速率,是否正確?比特深度是16比特或24比特,而比特率是128kbps – user1021430

+0

@ user1021430,我同意你的意見。你知道設置比特率的正確方法嗎? – mbaros

0

比特率等於sampleRate * bitDepth * numberOfChannel,這就是方式,您可以通過選擇這3個變量的權值設置你的比特率。 對於44100kHz,每個採樣和立體聲16bit的波形,您將擁有: 16 * 44100 * 2 = 1 411 200 bit/sec