如何设置AAC文件的比特率?

时间:2019-01-28 15:03:52

标签: android arrays audio kotlin aac

我正在尝试在Android上生成AAC文件。我成功做到了。但是我有一点不愉快的事情。当我在VLC中打开文件时,它会使用以下参数检测文件:

  • sampleSize = 32(但以16位帧大小记录)
  • sampleRate = 16(但以8 kHz记录)
  • channelsCount = 2(但记录了1个频道)

我应该在哪里指定样本数量?我只能指定采样率。

这是我的生成ADTS标头的代码

val id = 0
val layer = 0
val protectionAbsent = 1
val profile = 2
val frequencyIndex = 11
val privateBit = 0
val channelConfig = 1
val originalCopy = 0
val home = 0
val copyritingIdBit = 0
val copyritingIdStart = 0
val frameLength = 775

val arr = ByteArray(7)
arr[0] = 0xff.toByte()
arr[1] = (0xf0 or ((id shl 3) and 0b1000) or ((layer shl 1) and 0b110) or (protectionAbsent and 0b1)).toByte()
arr[2] = ((((profile - 1) shl 6) and 0b11000000) or ((frequencyIndex shl 2) and 0b111100) or ((privateBit shl 1) and 0b00000010) or ((channelConfig shr 2) and 0b1)).toByte()
arr[3] = (((channelConfig shl 6) and 0b11000000) or ((originalCopy shl 5) and 0x100000) or ((home shl 4) and 0b10000) or ((copyritingIdBit shl 3) and 0b00001000) or ((copyritingIdStart shl 2) and 0b00000100) or ((frameLength shr 11) and 0b11)).toByte()
arr[4] = ((frameLength shr 3) and 0xff).toByte() 
arr[5] = (((frameLength shl 5) and 0b11100000) or 0x1f).toByte()
arr[6] = 0xfc.toByte()

当我将频率更改为16kHz时,它被检测为32 kHz。 MacOs可以正确检测频率。

所有玩家都正确播放记录。

0 个答案:

没有答案