0

I have a problem with MP2 audio files and JAVA. Audio seems to be a pain in JAVA anyway. I tried using JavaLayer and Xuggler to decode and transcode the MP2 file to WAV. Both of which failed. And development of those seems to be not active. Although many are still using these. JMF or FMJ I haven't tried yet. I was wishing for more native approach.

I ended up forking JavaLayer to my project. And with a small code change I managed to seemingly get it to read all the frames from the MP2. But trying to convert it to WAV resulted in a file playable only in VLC and well, it was recognizable but distorted.

Anyway, a broad question, I apologize. I guess I'm asking that is there any JAVA + JavaLayer + MP2 gurus out there who can help me?

Original MP2: https://dl.dropboxusercontent.com/u/90134918/horng014.mp2 Failed WAV conversion: https://dl.dropboxusercontent.com/u/90134918/horng014_fail.wav

I have a public GitHub account for this project, but I haven't posted this broken code there yet.

tonihele
  • 49
  • 1
  • 6

3 Answers3

0

After stepping through jlayer1.01 in debugger, I conclude there are only two possibilities:

Either jlayer decodes the header word wrong, or jlayers tables and code are correct and the file's parameters deviate from what the standard defines. I lack the knowledge and time to find out wich of the two is the case.

Just because jlayer hasn't been updated for a few years does not necessarily mean its abandoned; it generally works very well with the average MP3. Why should there be an update if there aren't any known bugs left?

MP2 isn't exactly common these days; actually it hasn't even been that common 15 years ago, so it might well be the case there is a still unknown bug. Try filing a bug report and give it some time.

Durandal
  • 19,919
  • 4
  • 36
  • 70
  • The file converts to WAV with many converters without any problems. And all the headers were just fine (as far as I can tell). I also used and HEX editor to check it. I commented out the following from javazoom.jl.decoder.Header (185): `if (stream.isSyncCurrentPosition(syncmode)) {` Because it just seemed to advance the cursor from the heading where it was already at. And already parsed it correctly. And with this it recognized and decoded all the frames. Thank you for the reply, I will try to submit a bug, although all seems to be not answered there on the SourceForge. – tonihele Sep 05 '14 at 07:57
  • Hm, I did something else. In Header.calculate_framesize() I commented out " if (h_version == MPEG2_LSF || h_version == MPEG25_LSF) framesize >>= 1;". I suspect the decoder itself is fine, but that particular combination of header bits is mishandled. I wouldn't write off the bug report that quickly; open source staff does this on the side and they will probably first take a look at the problem before making any statements. Only if there's no reaction after 5-10 days I would assume the project is dead. – Durandal Sep 05 '14 at 12:34
  • Oh yeah you were correct. It was the header size (http://www.codeproject.com/Articles/8295/MPEG-Audio-Frame-Header). The code I unplugged checks that it is either EOF or next header after the frame (after the last frame, there is some clutter)? With this I could get out a WAV that sounded a bit better, but still unplayable by other than VLC. I'm unsure if it is the rest of MP2 encoding still faulty or just the WAV encoding that is messed up. Thank you. – tonihele Sep 06 '14 at 07:30
  • I forgot to close the stream... That is why my WAV was unplayable... But it is still not very listenable. So it must be the MP2 decoding, and that is beyond my capabilities to fix :( – tonihele Sep 06 '14 at 18:23
0

The MP2 file is is correct and MP2 is common these days, the MP2 Encoder twolame is up to date with enhanced VBR encoding. You can play the file with common players. There are two different bugs in JLayer: 1. The frame size calculation is wrong and 2. A Bit allocation table for MP2 Low Sampling Frequency (Mpeg2-Layer2) is buggy.

  • Thanks. I also figured that out. The solution for me was that I found a simpler C-library that I converted to JAVA. It had specifically fixes for the low sampling frequency things. It was easier than to figure out how to fix the JLayer (even when I knew where the problem was)... The library: http://keyj.emphy.de/kjmp2/ – tonihele Jan 07 '15 at 06:36
0

Meanwhile theres's a new Java Media Framework here:

https://sourceforge.net/projects/doppio/

with a high level API for players and a low level API for using only decoders.

This player here https://sourceforge.net/projects/xamp2/ based on this media framework and can play mentioned file. Also the stuff is open source.