Tutorial: Multichannel Audio with beads + JJack

1,512 views
Skip to first unread message

Martin Leopold

unread,
Nov 8, 2011, 11:16:14 AM11/8/11
to beadsproject
I think reliable, low-latency multichannel audio is an important
application for beads, unfortunately it's not exactly easy to set up.
I got valuable help from this community lately, so I thought I might
also contribute a little bit.
So here are my experiences with setting up 8 channel output using
Processing/Beads/Jack on OSX 10.6. using a M-Audio Profire 610 audio
interface. Though I was only dealing with outputs, you should be able
to get multiple inputs to work in a similar fashion, same applies to
other operating systems.

Software versions used:
OSX 10.6.8
jack v0.88 64/32bit
jjack 0.3
Processing 2.01a
beads compiled from SVN on 9/29/2011 (beads 20100418 should also work)


1. install jack
http://jackaudio.org/download
I used jack v0.88 64/32bit for OS X.
You need to setup jack to use your audio device of choice, preferrably
a multichannel one. On OS X you do that with the included JackPilot
application. Once this is done, make sure jack is running. For minimum
maintenace you can find the handy Jack OS X autostart here:
http://www.jackosx.com/download.html


2. install jjack
http://jjack.berlios.de/download.html
I used jjack-0.3.tar.gz

For java people: add lib/jjack.jar to your classpath and make the
"libjjack" native library for your OS available to java (e.g. using
the runtime option -Djava.library.path=./jjack/lib/macos/
libbjack.jnilib)

For processing people: Add lib/jjack.jar and the native library for
your OS (e.g. for mac: lib/macos/libjjack.jnilib) to your sketches
code folder (Create a folder named "code" inside your sketch folder).

Any beads Sketch should be jack enabled now. Watch for the following
messages on the console:
natively registering jack client ...
JavaSoundAudioIO: Chosen mixer is JJack.
As soon as the sketch is run, a device named "JJack" should show up in
Jack's Routing section. This is your Sketch. Route your JJack ins and
outs to "system" to connect your application to your soundcard.


3. More Channels
By default JJack provides only 2 ins and 2 outs. To adjust these
numbers you need to do two things:

3.1 Add runtime options:
Some of these are named incorrectly in the JJack manual, here are the
correct ones:
-Djjack.ports=n Number of input and output ports to be used.
Default: 2 (stereo)
-Djjack.ports.in=n Number of input ports to be used, if different
from output ports.
-Djjack.ports.out=n Number of output ports to be used, if
different from input ports.
-Djjack.ports.autoconnect=true|false Sets whether to connect both
input and output ports to physical JACK ports.
-Djjack.ports.in.autoconnect=true|false Sets whether to connect the
input ports to physical JACK ports.
-Djjack.ports.out.autoconnect=true|false Sets whether to connect the
output ports to physical JACK ports.
-Djjack.client.name=name Name of native JACK client to register.
-Djjack.verbose=true

Here's an example which I used to get my app to show up as
"Processing" in Jack, with 8 outputs that automatically connect to the
8 outs of my Profire 610:
* In java use these runtime options to your VM invocation: -
Djjack.client.name=Processing -Djjack.ports.out=8 -Djjack.ports.in=0 -
Djjack.ports.out.autoconnect=true
* In Processing set these runtime options in your preferences.txt (Go
to Processing/Preferences..., then clicking the line with
"preference.txt" should open an editor. Make sure you quit processing
before editing this file, otherwise your changes will be reverted/not
saved):
run.options=-Djjack.client.name=Processing -Djjack.ports.out=8 -
Djjack.ports.in=0 -Djjack.ports.out.autoconnect=true

3.2 Use a multichannel AudioFormat in beads.
By default the beads AudioContext provides only 2in/2outs.
For 8ins/8outs use:
AudioContext ac = new
AudioContext(AudioContext.defaultAudioFormat(8));

The latest beads as (as of this writing 20100418) only allows for the
same number of inputs & outputs.
For creating an AudioContext with a different number of ins and outs,
I used the development version of beads from SVN (compiled with ./
ant).
This allowed me to create an AudioContext with 8 outs and no ins like
this:
AudioContext ac = new AudioContext(AudioContext.defaultAudioFormat(0,
8));
Note: Using only inputs (i.e. 0 outs) didn't work for me
(ArrayIndexOutOfBoundsException), so use at least 1 output.


4. Optionally confirm your number of inputs /outputs:
println("no. of inputs: " + ac.getAudioInput().getOuts());
println("no of outputs: " + ac.out.getIns());
Note: You might get an ArrayIndexOutOfBoundsException on these if your
number of ins/or outs is 0, so don't use them in this case.

Now you should be all set up to add audio chains to your inputs and
outputs!

Evan Merz

unread,
Nov 8, 2011, 4:04:09 PM11/8/11
to beadsp...@googlegroups.com
Martin,

Thank you so much! This is excellent! I think this will be valuable to a lot of users (myself included).

Maybe we need to post this on the beads website?

-Evan


From: Martin Leopold <martin...@gmail.com>
To: beadsproject <beadsp...@googlegroups.com>
Sent: Tuesday, November 8, 2011 8:16 AM
Subject: [beadsproject] Tutorial: Multichannel Audio with beads + JJack
--
You received this message because you are subscribed to the Google Groups "beadsproject" group.
To post to this group, send email to beadsp...@googlegroups.com.
To unsubscribe from this group, send email to beadsproject+unsub...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/beadsproject?hl=en.



Oliver Bown

unread,
Nov 8, 2011, 5:49:39 PM11/8/11
to beadsp...@googlegroups.com
Will do, thanks for this valuable input Martin. I will also release that new version. It reworks some of the AudioContext constructors and is still not exactly what I want. Plus as I said I want to incorporate Neil's JNA-based approach, which is an important simplification because it relieves the need to link to native libraries, except the Jack libraries themselves.

Ollie

To unsubscribe from this group, send email to beadsproject...@googlegroups.com.

Neil C Smith

unread,
Nov 9, 2011, 4:56:12 AM11/9/11
to beadsp...@googlegroups.com
On 8 November 2011 22:49, Oliver Bown <ol...@icarus.nu> wrote:
> Will do, thanks for this valuable input Martin. I will also release that new
> version. It reworks some of the AudioContext constructors and is still not
> exactly what I want. Plus as I said I want to incorporate Neil's JNA-based
> approach, which is an important simplification because it relieves the need
> to link to native libraries, except the Jack libraries themselves.
> Ollie

The other simplification will be removing the need for all those
system properties, as it will set itself up from the Beads context.

Incidentally, are you planning on moving to the AudioServer API or
using JNAJack directly? There are plans to add more AudioServer
implementations - I've had some discussion with someone about a
PortAudio implementation. An Android implementation would also be
gratefully received(!), though it's not one I have an interest in
personally. It's all here by the way for anyone who's wondering -
http://code.google.com/p/java-audio-utils/

Ollie - might be worth opening a thread on here if you want some help
with integration. There's a few ideas that cropped up while hacking
together the AudioIO I sent you - mainly about whether it was possible
to reverse the construction of the AudioContext somehow - ie. have it
retrieved from the AudioIO?

Best wishes,

Neil

PS. Per discussion in another thread - JNAJack should hopefully now
be fixed on Windows (done some testing) - a new release will be up as
soon as I find the time to package it.


--
Neil C Smith
Artist : Technologist : Adviser
http://neilcsmith.net

Jaime Pericás

unread,
Aug 25, 2012, 12:06:55 PM8/25/12
to beadsp...@googlegroups.com
Hi, i'm trying to hook up a DAW emiting audio into processing by using the method stated above. The problem I have is that i really need a low latency stream into the processing program, but I can't find the way to archieve this. Im in OSX Mountain Lion, is it some problem with beads or with my JACK setup?

Thanks!

Oliver Bown

unread,
Aug 26, 2012, 4:42:37 AM8/26/12
to beadsp...@googlegroups.com
Hi Jamie,

can you say what latency you're aiming for, and what you've tried to do and what doesn't work?

On 26 Aug 2012, at 02:06, Jaime Pericás wrote:

> Hi, i'm trying to hook up a DAW emiting audio into processing by using the method stated above. The problem I have is that i really need a low latency stream into the processing program, but I can't find the way to archieve this. Im in OSX Mountain Lion, is it some problem with beads or with my JACK setup?
>
> Thanks!
>
> --
> You received this message because you are subscribed to the Google Groups "beadsproject" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/beadsproject/-/8jZV_xTFcSQJ.

Neil C Smith

unread,
Aug 29, 2012, 2:27:59 PM8/29/12
to beadsp...@googlegroups.com
Hi Jaime,

Out of interest are you using the Beads version with JJack (as at the
beginning of this thread) or the one with JNAJack (of which more here
- https://groups.google.com/d/topic/beadsproject/oWEVUNHSztE/discussion)?
Be interesting to know whether switching either way makes performance
any better.

Ollie - are you still intending to make the JAudioLibs version of
Beads the official one? Few changes in the pipeline over the next
month or two, some of which should hopefully be useful. I've also
been doing some more testing on Windows recently. Maybe a
conversation for another thread or off-list?

Best wishes,

Neil

--
Neil C Smith
Artist : Technologist : Adviser
http://neilcsmith.net

Praxis - open-source intermedia system for live creative play -
http://code.google.com/p/praxis

OpenEye - specialist web solutions for the cultural, education,
charitable and local government sectors - http://openeye.info




On 25 August 2012 17:06, Jaime Pericás <byk...@gmail.com> wrote:
> Hi, i'm trying to hook up a DAW emiting audio into processing by using the method stated above. The problem I have is that i really need a low latency stream into the processing program, but I can't find the way to archieve this. Im in OSX Mountain Lion, is it some problem with beads or with my JACK setup?
>
> Thanks!
>

Jaime Pericás

unread,
Aug 30, 2012, 4:02:14 PM8/30/12
to beadsp...@googlegroups.com
Hi,
I got no luck trying to set up the JNAJack option (im using the one with JJack, posted above). The processing log prints this when executing, with the JackServer turned on and with the defauld coreaudio values. In qjackctl I see no Input from the Processing sketch running.

Starting Jack implementation of AudioServerIO
30-ago-2012 22:01:06 org.jaudiolibs.jnajack.Jack initCallbackMethods
ADVERTENCIA: You seem to be using a version of JNA below 3.4.0 - performance may suffer
Unexpected audio configuration

I tried updating JNAJack and AudioServers with the same output. Any help? 

Neil C Smith

unread,
Aug 30, 2012, 6:42:43 PM8/30/12
to beadsp...@googlegroups.com

Hi,

Dealing with those messages in reverse order (but in order of importance), the "Unexpected audio configuration" message is called because you need to set the samplerate and buffersize of the AudioContext in Beads to the same as Jack.

The other error about JNA won't stop the audio working but might not let you get as low a latency. Assuming that the Beads archive has the right version of JNA (can't check right now) this might be because new versions of Processing use JNA for video and I think it's an older version. You should be able to swap in the updated JAR into Processing core without issue.

For best results, you should also have -Xincgc set on whatever command line starts Java.

Hope that helps.

Best wishes,

Neil

Neil C Smith
Artist : Technologist : Adviser
http://neilcsmith.net

To view this discussion on the web visit https://groups.google.com/d/msg/beadsproject/-/s6gQaNjG8SEJ.

Oliver Bown

unread,
Sep 6, 2012, 1:36:28 AM9/6/12
to beadsp...@googlegroups.com
Hi Neil,

sorry again for late response. The Jaudiolibs version remains the experimental option and not default yet. I'm still keen but still want to get to the bottom of a few usability issues. As you know I've been deeply frustrated finding the time to go through them and even check exactly what the design requirements are - and none of these are criticisms of your library, more finalising design decisions at my end. I'd love for you and I should fix a 3 hour slot where we can skype and hack through the design. The issues from memory are:

performance at low buffer sizes - seems to be poorer on OS X than my version, depending on certain factors
need for Jack and Beads to have the same buffer size = unnecessary cause of potential errors
making some of the additional features in your JNAJack (or native Jack) library available in Beads where appropriate
multiple Beads Jack clients should "just work" without user having to explicitly name them
finally I want to properly bundle everything into the Beads jar in my build

To be continued offlist?

Also dunno if you're on the JSyn list but Phil Burke is working on a JNI-based portaudio solution with bells and whistles. Might be worth touching base with that effort too… although I must say the JNA Jack approach is gloriously elegant and portable.

Ollie

Neil C Smith

unread,
Sep 6, 2012, 4:56:29 AM9/6/12
to beadsp...@googlegroups.com
Hi,

On 6 September 2012 06:36, Oliver Bown <ol...@icarus.nu> wrote:
> performance at low buffer sizes - seems to be poorer on OS X than my
> version, depending on certain factors
> need for Jack and Beads to have the same buffer size = unnecessary cause of
> potential errors
> making some of the additional features in your JNAJack (or native Jack)
> library available in Beads where appropriate
> multiple Beads Jack clients should "just work" without user having to
> explicitly name them
> finally I want to properly bundle everything into the Beads jar in my build
>
> To be continued offlist?
>

Good idea, and can reply here when the issues are resolved. Will email you.

> Also dunno if you're on the JSyn list but Phil Burke is working on a
> JNI-based portaudio solution with bells and whistles. Might be worth
> touching base with that effort too… although I must say the JNA Jack
> approach is gloriously elegant and portable.
>

That sounded great, and is on the main PortAudio site, until I read
this page http://www.portaudio.com/docs/v19-doxydocs/classcom_1_1portaudio_1_1PortAudio.html

"This Java binding does not support audio callbacks because an audio
callback should never block. Calling into a Java virtual machine might
block for garbage collection or synchronization. So only the blocking
read/write mode is supported."

WTF? That's a terrible argument for not implementing callbacks, and
will lead to higher latencies. A PortAudio binding is still on my
radar, and I've done a load of research in that direction. I was
planning on leaving out blocking mode!

I should have another look at it - it went on hold because I wasn't
sure about the best way to deliver (or even get hold of) all the
various native builds. Unlike JACK, it's not really something that
the user installs, though that's not an insurmountable problem.

Euh Bin

unread,
Jan 24, 2013, 12:33:56 PM1/24/13
to beadsp...@googlegroups.com
Hi everyone,
thanks for this great tutorial.
I've managed to have the JJack solution for multichannel working fine, with 8 ins/outs I get all the connections in the Jack routing utility.
My problem is that i'm totally new to Beads.
Could someone post a sample code that explains how to use only one specific input or output?
Coming from Supercollider I would do something like:

   ac = new AudioContext(AudioContext.defaultAudioFormat(8));

  Noise n = new Noise(ac);

  Gain g = new Gain(ac, 1, 0.1);

  g.addInput(n);

  ac.out[0,4,3].addInput(g);  <-- here i would specify an array with the ports I want to feed (here outputs 1,5,4)

But of course it doesn't work, I think i'm missing something crucial with AudioContext, I don't even understand how to feed only left or right in a simple stereo setup.

Cheers!
Olivier

Oliver Bown

unread,
Jan 25, 2013, 4:06:09 AM1/25/13
to beadsp...@googlegroups.com
You can do ac.out.addInput(x, g, y);

x is the target input index, i.e., the channel that you'll be connecting TO.
y is the source output index, i.e., the channel that you'll be connecting FROM.

There is no array mechanism for handling this. Beads is written in the Java language and there is no such syntax in Java.

(I'm curious about playing with Beads from Scala, where you can do operator overloading, but I still don't think you'd be able to create that language form).

Ollie

--
You received this message because you are subscribed to the Google Groups "beadsproject" group.
To post to this group, send email to beadsp...@googlegroups.com.
To unsubscribe from this group, send email to beadsproject...@googlegroups.com.

Euh Bin

unread,
Jan 25, 2013, 4:41:51 AM1/25/13
to beadsp...@googlegroups.com
Thanks Ollie !

mubase

unread,
Jan 13, 2014, 9:02:56 AM1/13/14
to beadsp...@googlegroups.com
hi - i've just seen your post about the tutorial to get multichannel audio using jjacks for audio I/O for Beads (in Processing) and connecting it to the jack server. the audio using the normal java sound is really clicking and unstable, so i launched into trying to follow the tutorial for multichannel audio installing jacks and jjacks, i've got the jack server up and running on my mac osx (mountain lion), but cant work out how to install jjacks on my mac osx mountain lion so i can put the files into my Processing sketch folder in a code folder and get the jjacks as the default mixer and be recognized in the jack server connection manager.  Ive tried putting the native library (libjjack.jnilibin) in usr/library/java but am not sure exactly where i need to put it in relation to the other java folders in my system library, i tried following the path in the top o fhte error message that came up in my processing console (with jjacks.jar //jjacks-clients.jar in the code folder). i have attached the error message (as i thought that might be where it is looking for it) but no joy.

i've even tried using the new experimental version of beads - but then couldnt get java sound to work that'll own jacks.

Is there anywere i can go for a step-by-step guide in how to install jjacks for use with Beads in Processing? or do you know how i might do it with no real experience with Java at all and limited experience with Processing

i realize this message was a while ago, but i cant find any other places where this is addressed. If there is another easier way of sorting out multichannel inputs with Beads i'd really appreciate it

many thanks

hannah - mubase
forum_console_error.txt

mubase

unread,
Jan 13, 2014, 9:14:32 AM1/13/14
to beadsp...@googlegroups.com
Hi - i have tried following the tutorial below, can jjacks be installed on osx mountain lion? i've installed jacks but can't
get jjacks as the default mixer in my processing sketch to be recognizable in jack connections manager as i'm not sure how to install it in my system.

Are there any other more recent solutions for multichannel inputs and outputs with beads in processing?

I was really excited when i found this as i thought it would resolve my clicking/unstable inputs. I am doing my final
year project and have loads of work to do with  the 'controllers' side of my project, using arduino. I'm using beads in processing
so hoped the audio itself wouldn't be problematic
(i need to split an input, so one is processed in a normal ugen chain and the other granulated and processed in another ugen chain
so i can granulate and mix the original ungranulated signal in real time, controlled by an augmented violin bow.)

Any help or advice would be enormously welcome, in terms of jjacks or any other option so that my processing sketch can be
recognized in the jack router. I've spent 24 hours trying to get this to work, i've just  tried using
the beads version from the repository, but then java sound wouldnt start and i'm not experienced enough to try and resolve these issues
as i have no java experience, just starting out with processing, first time using mic inputs


many thanks

hannah - mubase

Reply all
Reply to author
Forward
0 new messages