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

前端 未结 6 703
野趣味
野趣味 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:23

    Your networking code is combining data. You got 369 bytes of compressed data, but on the receiving end you ended up with 1024 bytes. Those 1024 bytes consist of two whole and one partial frame. The two whole frames each decode to 4096 bytes again, for the total of 8192 bytes that you saw. The remaining partial frame will probably be decoded once you send sufficiently more data to the decoder, but you should generally send only whole frames to the decoder.

    In addition, MediaCodec.dequeueOutputBuffer() does not only return (positive) buffer indices, but also (negative) status codes. One of the possible codes is MediaCodec.INFO_OUTPUT_FORMAT_CHANGED, which indicates that you need to call MediaCodec.getOutputFormat() to get the format of the audio data. You might see the codec output stereo even if the input was mono. The code you posted simply breaks out of the loop when it receives one of these status codes.

提交回复
热议问题