title: get pcm data from mp3 file in android
body: <p>My question is simple. How do I get PCM data from the mp3 file?</p>
  
  <p>Now I found only ne way to get PCM bytes from the song, I loaded and played mp3 by <code>MediaPlayer</code> and tried listen to the change of waves by <code>Visualizer.OnDataCaptureListener</code> . This interface's method passes a <code>byte[] bytes</code> parameter. I tried to save all these bytes into the one byte array and then I passed this array to <code>AudioTrack.write</code> method and played it by <code>AudioTrack.play</code> method. Something like this:</p>
  
  <pre><code>    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);
       }
  </code></pre>
  
  <p>and then </p>
  
  <pre><code>AudioTrack tr = new AudioTrack(AudioManager.STREAM_MUSIC, 22050, 
                                AudioFormat.CHANNEL_OUT_STEREO,   
                                AudioFormat.ENCODING_PCM_16BIT,
                                allBytes.length, AudioTrack.MODE_STREAM);
  tr.play();
  tr.write(barr, 0, allBytes.length);
  </code></pre>
  
  <p>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.</p>
  
  <p>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?</p>