Answer the question
In order to leave comments, you need to log in
How to decode mp3 to PCM?
The task is to decode mp3 into pulse-code modulation.
In the open spaces of the network I found the JLayer
library I
threw a class:
public class test {
public static void main(String[] args) throws DecoderException, BitstreamException, IOException{
Bitstream bitStream = new Bitstream(new FileInputStream("Work/sin.mp3"));
boolean done = false;
SampleBuffer output = null;
int i = 0;
int k = 0;
while(! done){
Header frameHeader = bitStream.readFrame();
i++;
if (frameHeader == null) {
done = true;
}
else {
Decoder decoder = new Decoder();
output = (SampleBuffer) decoder.decodeFrame(frameHeader, bitStream); //возвращает следующие 2304 сэмпла
// int freq = output.getSampleFrequency(); //частота дискретизации
// int channel = output.getChannelCount(); //количество каналов
short[] next = output.getBuffer();
System.out.println(next);
}
bitStream.closeFrame();
}
}
}
Answer the question
In order to leave comments, you need to log in
Can you please tell me how to parse it into pulse code modulation?
System.out.println(Short.valueOf(next));
Fesor , thank you very much!
But now if we take several frames from the audio file and separate one channel, you can see such a picture
. 3 frames are clearly visible, and each of them takes the value 0 at the beginning for some time.
I'm having doubts, is the audio data really recorded in mp3 like this, or is it a decoding flaw?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question