Realtime audio in Java

Programming applications for making music on Linux.

Moderators: MattKingUSA, khz

Post Reply
User avatar
raboof
Established Member
Posts: 1865
Joined: Tue Apr 08, 2008 11:58 am
Location: Deventer, NL
Has thanked: 52 times
Been thanked: 80 times
Contact:

Realtime audio in Java

Post by raboof »

Anyone doing realtime audio stuff in Java?

I've been looking into JJack, which seems like a nice (albeit rather inactive) foundation.

However, I wonder if/how you can prevent the JVM from `getting in the way' by scheduling threads or even garbage collecting in the `realtime critical path' of your application.
User avatar
Capoeira
Established Member
Posts: 1321
Joined: Tue May 12, 2009 1:01 pm
Location: Brazil
Has thanked: 3 times
Been thanked: 2 times

Re: Realtime audio in Java

Post by Capoeira »

raboof wrote:Anyone doing realtime audio stuff in Java?

I've been looking into JJack, which seems like a nice (albeit rather inactive) foundation.

However, I wonder if/how you can prevent the JVM from `getting in the way' by scheduling threads or even garbage collecting in the `realtime critical path' of your application.
man, can you give me a hand?
I don't understand how yo use JJack.

what I want to do is making Room EQ Wizard "http://www.hometheatershack.com/roomeq/" run with Jack.
I copied libjack.so from JJack to the the lib-path. How do I call the java-program with JJack?
User avatar
Capoeira
Established Member
Posts: 1321
Joined: Tue May 12, 2009 1:01 pm
Location: Brazil
Has thanked: 3 times
Been thanked: 2 times

Re: Realtime audio in Java

Post by Capoeira »

found this:
I compiled and tested JJack on both machines here at Studio Dave, using only the first method. I installed jjack.jar and jjack-clients.jar in $JAVA_HOME/jre/lib/ext and copied libjjack.so to /usr/lib. According to the package instructions JJack would be recognized and started automatically
Jjack creates ports when starting the REW but than I get this:
GRAVE: Exception trying to open replay device
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljavax.sound.sampled.Line$Info;
User avatar
raboof
Established Member
Posts: 1865
Joined: Tue Apr 08, 2008 11:58 am
Location: Deventer, NL
Has thanked: 52 times
Been thanked: 80 times
Contact:

Re: Realtime audio in Java

Post by raboof »

Capoeira wrote:java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljavax.sound.sampled.Line$Info;
Hmm, no stacktrace anywhere?
User avatar
Capoeira
Established Member
Posts: 1321
Joined: Tue May 12, 2009 1:01 pm
Location: Brazil
Has thanked: 3 times
Been thanked: 2 times

Re: Realtime audio in Java

Post by Capoeira »

raboof wrote:
Capoeira wrote:java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljavax.sound.sampled.Line$Info;
Hmm, no stacktrace anywhere?
stacktrace wrote:Output device error


Message:
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljavax.sound.sampled.Line$Info;
Level:
SEVERE
Stack Trace:
[Ljava.lang.Object; cannot be cast to [Ljavax.sound.sampled.Line$Info;
com.petersalomonsen.jjack.javasound.JJackMixer.getSourceLineInfo(JJackMixer.java:190)
javax.sound.sampled.AudioSystem.getSourceLineInfo(AudioSystem.java:269)
roomeqwizard.JB.A(Unknown Source)
roomeqwizard.JB.D(Unknown Source)
roomeqwizard.P.actionPerformed(Unknown Source)
javax.swing.JComboBox.fireActionEvent(JComboBox.java:1240)
javax.swing.JComboBox.setSelectedItem(JComboBox.java:567)
javax.swing.JComboBox.setSelectedIndex(JComboBox.java:603)
roomeqwizard.JB.A(Unknown Source)
roomeqwizard.JB.C(Unknown Source)
roomeqwizard.JB$1.actionPerformed(Unknown Source)
javax.swing.Timer.fireActionPerformed(Timer.java:271)
javax.swing.Timer$DoPostEvent.run(Timer.java:201)
java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:178)
java.awt.Dialog$1.run(Dialog.java:1046)
java.awt.Dialog$3.run(Dialog.java:1098)
java.security.AccessController.doPrivileged(Native Method)
java.awt.Dialog.show(Dialog.java:1096)
java.awt.Component.show(Component.java:1563)
java.awt.Component.setVisible(Component.java:1515)
java.awt.Window.setVisible(Window.java:842)
java.awt.Dialog.setVisible(Dialog.java:986)
org.jdesktop.swingx.JXErrorPane$1.run(Unknown Source)
java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)
java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
java.awt.EventDispatchThread.run(EventDispatchThread.java:122)


Input device error


Message:
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljavax.sound.sampled.Line$Info;
Level:
SEVERE
Stack Trace:
[Ljava.lang.Object; cannot be cast to [Ljavax.sound.sampled.Line$Info;
com.petersalomonsen.jjack.javasound.JJackMixer.getTargetLineInfo(JJackMixer.java:214)
javax.sound.sampled.AudioSystem.getTargetLineInfo(AudioSystem.java:309)
roomeqwizard.JB.B(Unknown Source)
roomeqwizard.JB.I(Unknown Source)
roomeqwizard.P.actionPerformed(Unknown Source)
javax.swing.JComboBox.fireActionEvent(JComboBox.java:1240)
javax.swing.JComboBox.setSelectedItem(JComboBox.java:567)
javax.swing.JComboBox.setSelectedIndex(JComboBox.java:603)
roomeqwizard.JB.A(Unknown Source)
roomeqwizard.JB.C(Unknown Source)
roomeqwizard.JB.A(Unknown Source)
roomeqwizard.P.actionPerformed(Unknown Source)
javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
javax.swing.JToggleButton$ToggleButtonModel.setPressed(JToggleButton.java:291)
javax.swing.AbstractButton.doClick(AbstractButton.java:357)
javax.swing.AbstractButton.doClick(AbstractButton.java:337)
roomeqwizard.P.A(Unknown Source)
roomeqwizard.yA.I(Unknown Source)
roomeqwizard.RoomEQ_Wizard.main(Unknown Source)
User avatar
raboof
Established Member
Posts: 1865
Joined: Tue Apr 08, 2008 11:58 am
Location: Deventer, NL
Has thanked: 52 times
Been thanked: 80 times
Contact:

Re: Realtime audio in Java

Post by raboof »

Capoeira wrote:
stacktrace wrote: java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljavax.sound.sampled.Line$Info;
Level:
SEVERE
Stack Trace:
[Ljava.lang.Object; cannot be cast to [Ljavax.sound.sampled.Line$Info;
com.petersalomonsen.jjack.javasound.JJackMixer.getSourceLineInfo(JJackMixer.java:190)
javax.sound.sampled.AudioSystem.getSourceLineInfo(AudioSystem.java:269)
That would seem like a problem in JJack... what JDK are you using? Sun's or OpenJDK? And which version of JJack?
User avatar
Capoeira
Established Member
Posts: 1321
Joined: Tue May 12, 2009 1:01 pm
Location: Brazil
Has thanked: 3 times
Been thanked: 2 times

Re: Realtime audio in Java

Post by Capoeira »

raboof wrote:
Capoeira wrote:
stacktrace wrote: java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljavax.sound.sampled.Line$Info;
Level:
SEVERE
Stack Trace:
[Ljava.lang.Object; cannot be cast to [Ljavax.sound.sampled.Line$Info;
com.petersalomonsen.jjack.javasound.JJackMixer.getSourceLineInfo(JJackMixer.java:190)
javax.sound.sampled.AudioSystem.getSourceLineInfo(AudioSystem.java:269)
That would seem like a problem in JJack... what JDK are you using? Sun's or OpenJDK? And which version of JJack?
jdk I don't have installed, only this:
jre 6u21-1 [installed] Sun/Oracle's Java Runtime Environment
JJack 0.3

did you or anyone else try it? This software REW is verry usefull for audio visualation and provides funtions wich no pure-linux soft does. I think it could be interesting for other users here too, and therefore it should be nice to make it run with jack
thorgal
Established Member
Posts: 739
Joined: Mon Apr 07, 2008 6:04 pm

Re: Realtime audio in Java

Post by thorgal »

I tried jjack some time ago when I had time to fool around ;)
A pain to set up, but it worked ... i.e. it connected to jack and java apps could be heard through jack. But performance-wise, it sucked ... but my testing was not at all thorough and I quickly gave up on using this.

Instead, the snd-aloop hack could work out if java can output to ALSA. Not tried it yet, I have moved my home-studio to another room and it is not completely up and running. But forget about performance and / or low latency if you use this method.
StudioDave
Established Member
Posts: 753
Joined: Sat Nov 01, 2008 1:12 pm

Re: Realtime audio in Java

Post by StudioDave »

Thought I sent this earlier, sorry if it's a repeat.

I wrote a series of articles on music & sound software for Java, you might find some interesting tid-bits there.

http://www.linuxjournal.com/content/jav ... nux-part-1

http://www.linuxjournal.com/content/jav ... nux-part-2

http://www.linuxjournal.com/content/jav ... nux-part-3

I think someone needs to put a boot up Javasound's ass. The last time I looked, the API designers had a completely wrong notion of JACK (they lump it together with ESD, NAS, and other such network audio servers), and their own work was hopelessly tied to the ancient OSS/Free API. Alas, I couldn't get JJack to work as I wanted, but I think it deserves some love. Java has some great music & sound applications (see the articles), but without JACK their utility is limited in my system.
User avatar
Capoeira
Established Member
Posts: 1321
Joined: Tue May 12, 2009 1:01 pm
Location: Brazil
Has thanked: 3 times
Been thanked: 2 times

Re: Realtime audio in Java

Post by Capoeira »

thorgal wrote: Instead, the snd-aloop hack could work out if java can output to ALSA. .
yea, the snd-aloop hack I was always fleeing for ;-)
could work if it shows up as an alsa-device in the java-software
I need to make it run anyways, as I need now a static alsa-jack bridge for my convolver, will try it out
thorgal
Established Member
Posts: 739
Joined: Mon Apr 07, 2008 6:04 pm

Re: Realtime audio in Java

Post by thorgal »

just found the time to test the loopback hack with java apps on my laptop: it works :)

I just used some simple audio file players. Some did not even show a "preference" menu where you could choose your device (I have the loopback device defined in .asoundrc set up as the default device while jack is running on the real hardware). Ah yeah, actually I tried the Room EQ Wizard as well, no problem either.

Every time I disconnected the alsa2jack bridge from the connection window in qjackctl, sound would not be heard. When I stopped jack, the app continued playing unaffected. When I restarted jack (and bridge automatically started), sound was back just as expected.

I also tried very low latency for fun ... yeah, not really usable ... but my laptop is kinda weak.
User avatar
Capoeira
Established Member
Posts: 1321
Joined: Tue May 12, 2009 1:01 pm
Location: Brazil
Has thanked: 3 times
Been thanked: 2 times

Re: Realtime audio in Java

Post by Capoeira »

thorgal wrote:Ah yeah, actually I tried the Room EQ Wizard as well, no problem either.
unluckily I get output but no input (input in skype works)
also I don't get any sound if alsa is ocupied by other app
Post Reply