get pcm data from mp3 file in android

My question is simple. How do I get PCM data from the mp3 file?

Now I found only ne way to get PCM bytes from the song, I loaded and played mp3 by MediaPlayer and tried listen to the change of waves by Visualizer.OnDataCaptureListener . This interface's method passes a byte[] bytes parameter. I tried to save all these bytes into the one byte array and then I passed this array to AudioTrack.write method and played it by method. Something like this:

    mVisualizer.setDataCaptureListener(new Visualizer.OnDataCaptureListener() {
                public void onWaveFormDataCapture(Visualizer visualizer, byte[] bytes,
                        int samplingRate) {
                       // allBytes += bytes
        public void onFftDataCapture(Visualizer visualizer, byte[] bytes, int samplingRate) {
, Visualizer.getMaxCaptureRate() / 2, true, false);

and then

AudioTrack tr = new AudioTrack(AudioManager.STREAM_MUSIC, 22050, 
                              allBytes.length, AudioTrack.MODE_STREAM);;
tr.write(barr, 0, allBytes.length);

But unfortunately I didn't get expected results. The sound is playing but there are a lot of noise in the sound, quality is so bad, you can't actually identify what is singing there.

But it was some kinda of "hack method" to get PCM data. Can you say if there is a normal method to get PCM data from my mp3?


I am using the mpg123 native library for decoding my MP3. It decoded into PCM data in shorts not bytes. I am sure you can do the conversions. The decoder is very fast since it uses the NDK.


I am not sure how big your files are but I would stream the bytes into the AudioTrack instead of putting the whole song in one big array.

Need Your Help

Where am I going wrong with Sentinel or break in this Python code


Okay this program is almost done but it keeps running. Need to figure out where the sentinel or break needs to go. This is what I have so far in Python. The program is suppose to read all the Pres ...

Netezza SQL For Loop

sql loops for-loop netezza

I have the following query Which I will call query1: