INNER CODE UNIT · Kotlin
ADTS_SIZE
pedroSG94/RootEncoder · common/src/main/java/com/pedro/common/AudioUtils.kt:6
const val ADTS_SIZE = 7 //Never use crc (with crc the size is 9)
fun createAdtsHeader(type: Int, length: Int, sampleRate: Int, channels: Int): ByteBuffer {
val header = ByteArray(ADTS_SIZE)
header[0] = 0xFF.toByte()
header[1] = 0xF1.toByte()
header[2] = (((type - 1) shl 6) or (getFrequency(sampleRate) shl 2) or (channels shr 2)).toByte()
header[3] = (((channels and 3) shl 6) or (length shr 11)).toByte()
header[4] = ((length and 0x7FF) shr 3).toByte()
header[5] = (((length and 7) shl 5).toByte()).plus(0x1F).toByte()
header[6] = 0xFC.toByte()
return ByteBuffer.wrap(header)
}
fun getFrequency(sampleRate: Int): Int {
var frequency = AUDIO_SAMPLING_RATES.indexOf(sampleRate)
//sane check, if sample rate not found using default 44100