如何在coreaudio中为AudioStreamBasicDescription指定比特率?

时间:2015-04-21 18:33:30

标签: ios core-audio

我正在使用音频单元录制一些PCM音频。在回调中,当我有30秒的音频时,我想用磁盘写入一个速率为12kb / s的8000Hz AAC编码文件。

这是我使用的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;

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

比特率等于sampleRate * bitDepth * numberOfChannel,您可以通过为这3个变量选择正确的值来设置比特率。 对于44100kHz的波形,每个样本和立体声16bit,您将拥有: 16 * 44100 * 2 = 1 411 200 bit/sec