How can JLayer library extract audio data from one mp3 file to another? Here is what I tried to do:

public Cutter(FileInputStream input, int start, int end) throws IOException, DecoderException, BitstreamException { Decoder dcr = new Decoder(); Bitstream bStream = new Bitstream(input); Header hdr = bStream.readFrame(); FileOutputStream output = new FileOutputStream("tmp.mp3"); while(start != bStream.header_pos()) { Obuffer buf = dcr.decodeFrame(hdr, bStream); SampleBuffer buffer = new SampleBuffer(dcr.getOutputFrequency(), dcr.getOutputChannels()); dcr.setOutputBuffer(buffer); try { for (int i = 0; i < buffer.getBufferLength(); i++) output.write(buffer.getBuffer()[i]); } catch (IOException e) { } } 
  • This is very inefficient, but in theory it will write to the file a decoded WAVE stream without a header - cy6erGn0m
  • I am writing an audio editor that should cut and glue mp3. In the mp3 file frames are composed of 2 parts: the header and data. Here's how to extract the data and how to find out the time of the current piece, I do not know. - Justinserg

1 answer 1

In general, I worked with JLayer a year and a half ago. Here I laid out the code for decoding MP3: MP3Decoder

  • I have a question about the code: what does the getBuffer () method return? - Justinserg