S
S
Sergey Kravchenko2014-09-17 23:21:25
Java
Sergey Kravchenko, 2014-09-17 23:21:25

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();    
    }
  }
  
}

For each frame, a value of the form " [[email protected] " is returned.
Please tell me how to parse it into pulse code modulation?
Or maybe you know another library with such functionality and know how to implement decoding with its help?
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
S
Sergey, 2014-09-18
Protko @Fesor

Can you please tell me how to parse it into pulse code modulation?

As far as I understand this is what it is, try this:
System.out.println(Short.valueOf(next));

S
Sergey Kravchenko, 2014-09-18
@Paladin1032

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 7f8cc3ca670a499a90633e1a21a05c7a.jpeg
. 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 question

Ask a Question

731 491 924 answers to any question