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 AudioTrack.play 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,
AudioFormat.CHANNEL_OUT_STEREO,
AudioFormat.ENCODING_PCM_16BIT,
allBytes.length, AudioTrack.MODE_STREAM);
tr.play();
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?