Realtime audio in Java
Moderators: MattKingUSA, khz
- 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
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.
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.
- 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
man, can you give me a hand?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.
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?
- 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
found this:
Jjack creates ports when starting the REW but than I get 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
GRAVE: Exception trying to open replay device
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljavax.sound.sampled.Line$Info;
- 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
Hmm, no stacktrace anywhere?Capoeira wrote:java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljavax.sound.sampled.Line$Info;
- 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
raboof wrote:Hmm, no stacktrace anywhere?Capoeira wrote:java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljavax.sound.sampled.Line$Info;
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)
- 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
That would seem like a problem in JJack... what JDK are you using? Sun's or OpenJDK? And which version of JJack?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)
- 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
jdk I don't have installed, only this:raboof wrote:That would seem like a problem in JJack... what JDK are you using? Sun's or OpenJDK? And which version of JJack?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)
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
Re: Realtime audio in Java
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.
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
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.
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.
- 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
yea, the snd-aloop hack I was always fleeing forthorgal wrote: Instead, the snd-aloop hack could work out if java can output to ALSA. .
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
Re: Realtime audio in Java
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.
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.
- 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
unluckily I get output but no input (input in skype works)thorgal wrote:Ah yeah, actually I tried the Room EQ Wizard as well, no problem either.
also I don't get any sound if alsa is ocupied by other app