0

I want to decode mp3 file to pcm or wav data.(Android Application: API 20)

I use this approach for decoding data from mp3, but on native platform with C++.

After decoding i know from decoder filled output buffered data is in "sound/raw" format. This buffered data stored in uint8_t*, so it`s uint8_t(byte) array (values from 0 - 255).

How can i convert this arrays into pcm or wav format, if it is possible?

Maksym
  • 41
  • 7

1 Answers1

1

The audio decoders currently all return 16 bit PCM audio, so just cast your uint8_t* to int16_t*, which allows you to read out the PCM samples. If you have size bytes of data, you can read size/2 samples from the int16_t* pointer. You also might want to check AMEDIAFORMAT_KEY_CHANNEL_COUNT from the output format - if you have size/2 samples in total you'll have size/(2*channels) tuples of samples for each channel.

mstorsjo
  • 12,983
  • 2
  • 39
  • 62
  • 1
    maybe for casting better use "byte shift" like this " int16 intValue = (byte[1] << 8) | byte[0] "? – Maksym Oct 14 '14 at 13:23