Reputation:
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.
Upvotes: 2
Views: 831
Reputation: 329
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.
Upvotes: 3