8

I have a Java-based MP3 player based on the JLayer / BasicPlayer framework which I'd like to get running on the Pi. I have installed the OpenJDK on the most current Raspbian. The BasicPlayer opens the line correctly, but only get stuttering noise when playing back a file.

Playing back sound using the mpg123 command line tool works fine.

Is there something wrong with the Java Sound implementation of the ARM OpenJDK?

I'm thankful for any hints in the right direction.

This is the code:

BasicPlayer pl = new BasicPlayer();
try {
    String path = "/home/pi/Music/testmp3.mp3";
    File file = new File(path);
    pl.open(file);
    pl.play();
} catch (Exception e) {
    CubeLog.logException(e);
}

Thanks.

nanoman
  • 181
  • 1
  • 5

4 Answers4

5

I do not have enough score to make comments. So I'll post here:

1-"Not enough CPU"- I used to do mp3 decoding by software in a Sparc Station with a 35MHz CPU. So unless that decoder is seriously flawed it should work.

Can you do the full decode to a file? If yes measure the time it takes. If it is less that the total runtime of the song you are in business. Afterwards copy the undecode file to another machine and see if the wav is ok.

[EDIT]:

I did some tests with JLayer1.0.1 on my RPI and it is slow:

time java -cacao -classpath jl1.0.1.jar javazoom.jl.converter.jlc file.mp3 -p out.wav

Takes 3 times more to decode than the runtime of the song.

[EDIT 2]:

Managed to decode a mp3 in less time than the runtime using Java SE Embedded 6 http://www.oracle.com/technetwork/java/embedded/downloads/javase/index.html :

pi@raspbmc:~/java/JLayer1.0.1$ rm out.wav; time ../ejre1.7.0_04/bin/java -classpath jl1.0.1.jar javazoom.jl.converter.jlc Gill\ Scott-Heron-\ The\ Revolution\ Will\ Not\ Be\ Televised.mp3 -p out.wav FileName = Gill Scott-Heron- The Revolution Will Not Be Televised.mp3

real 0m57.624s user 0m49.900s sys 0m2.320s

On a 3 minutes wav.

Problem is that it does not work on raspbian:

http://www.raspberrypi.org/phpBB3/viewtopic.php?f=66&t=11671

gfelisberto
  • 260
  • 1
  • 6
4

Here's your problem:

by MartenR » Thu Jul 05, 2012 11:09 am

Sound is always done on the cpu for codecs other than the free codecs, no licenses bought for sound decoding for mpeg audio or ac3.

The Raspberry Pi is simply not powerful enough to decode the mp3 in real time in software when running on the JVM.

You can try a few things to make it work:

  • Increase the memory available to the CPU

  • Try running a player that is not restricted by the JVM (though I have no idea if this will yield any improvement...)

     Runtime.getRuntime().exec("omxplayer [filename]");
    
Jivings
  • 22,208
  • 11
  • 88
  • 138
2

If any application can play sound smoothly using the CPU, then all applications should be able to play it smoothly.

OpenJDK 6 has problems with ALSA (doesn't play to the "default" device for example), so use OpenJDK 7 instead. Also, both OpenJDK versions use the Zero interpreter, which is very slow. You should use a JVM that JITs, such as CACAO on a soft-float distribution, or Avian JVM on a hard-float distribution (such as Raspbian).

0

Great news - I have it running!

I installed the new softfloat Debian wheezy image, then installed the just-released JDK 7 Update 6 on it, and it runs flawlessly. Just make sure you're installing this JDK on a softfloat-based distribution.

CPU consumption while playing back an MP3 is constantly at about 45%.

nanoman
  • 181
  • 1
  • 5