PCM -> AAC (Encoder) -> PCM(Decoder) in real-time with correct optimization

前端 未结 6 702
野趣味
野趣味 2020-11-29 17:37

I\'m trying to implement

AudioRecord (MIC) ->

PCM -> AAC Encoder
AAC -> PCM Decode

-> AudioTrack??  (SPEAKER)

with Me

6条回答
  •  星月不相逢
    2020-11-29 18:16

    I have tried the above code and it didn't work properly.I was getting lot of silence injected to the decoded output. Issue was not setting proper "csd" value to the decoder.

    So if you see "silence" in log or Decoder throwing error make sure you have added the following to your media decoder format

    int profile = 2;  //AAC LC
    int freqIdx = 11;  //8KHz
    int chanCfg = 1;  //Mono
    
    ByteBuffer csd = ByteBuffer.allocate(2);
    csd.put(0, (byte) (profile << 3 | freqIdx >> 1));
    csd.put(1, (byte)((freqIdx & 0x01) << 7 | chanCfg << 3));
    mediaFormat.setByteBuffer("csd-0", csd);
    

提交回复
热议问题