I am able to read the amplitude of a wav file using the following code
AudioInputStream in = AudioSystem.getAudioInputStream(file);
AudioFormat baseFormat = in.getFormat();
AudioFormat decodedFormat = new AudioFormat(Encoding.PCM_FLOAT, 44100, 32, 1, 4, 44100, false);
AudioInputStream din = AudioSystem.getAudioInputStream(decodedFormat, in);
byte[] array = new byte[4];
int read = din.read(array);
while (read != -1) {
ByteBuffer bb = ByteBuffer.wrap(array);
bb.order(ByteOrder.LITTLE_ENDIAN);
float amplitude = bb.asFloatBuffer().get();
System.out.println(amplitude);
read = din.read(array);
}
How do I read the same date for the equivalent mp3 file. I tried including the MP3 SPI library
However, the amplitudes I receive are just bogus numbers that fluctuate randomly without any natural smoothness of correct amplitude array.
Is there anything I can do to read mp3 file amplitude?