2

I'm testing

Mic

-> AudioRecord (raw PCM)

-> MediaCodec Encoder (to raw AAC)

-> UDP

-> MediaCodec Decoder (to raw PCM)

-> Speaker

Currently, the decoder process is successfully done, at least with no error.

However, the Byte[] size of rawPCM as the output of every decoding cycle is approximately as double as the input of encoding cycle.

D/AudioRecoder﹕ 4096 bytes read

D/AudioEncoder﹕ 360 bytes encoded

D/UDP Receiver﹕ received !! from ///127.0.0.1:39000

D/UDP Receiver﹕ 360 bytes received

D/AudioDecoder﹕ 8192 bytes decoded

Obviously, I expected the rawPCM size is matched to the original one, and feel something wrong.

This question is related to my previous questions, and the code is also there.

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

So far, I have not done this decoded byte to play with speaker.

Any thought? Thanks.


UPDATE:

I tried to play with speaker, and actually, it slightly worked, so the decoding process works at least.

slightly means, the latency is about 10 seconds, and sound quality is horrible. I test this on Genymotion emulator, and don't know how this kind of emulator affect this.

Community
  • 1
  • 1

1 Answers1

3

This sounds like you're capturing mono, encoding it, and then the decoder outputs it as a stereo stream with the mono channel duplicated across the left and right channels.

Make sure that when MediaCodec.dequeueOutputBuffer() returns MediaCodec.INFO_OUTPUT_FORMAT_CHANGED, you call MediaCodec.getOutputFormat() to get the current format.

fadden
  • 51,356
  • 5
  • 116
  • 166
marcone
  • 321
  • 1
  • 5
  • I'm trying to solve the very same issue, and yes, when I call `MediaCodec.getOutputFormat()`, on the decoder's `MediaCodec.INFO_OUTPUT_FORMAT_CHANGED`, there are 2 channels instead of 1 in the original input. – Gensoukyou1337 Aug 18 '16 at 10:46