Solution - Beads Audio Library error : java.lang.IllegalArgumentException: Line unsupported

In Linux I was getting this error when using the Beads audio library:

Exception in thread "Thread-1" java.lang.IllegalArgumentException: Line unsupported: interface SourceDataLine supporting format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, big-endian
	at java.desktop/com.sun.media.sound.PortMixer.getLine(PortMixer.java:131)
	at beads.JavaSoundAudioIO.create(Unknown Source)
	at beads.JavaSoundAudioIO$1.run(Unknown Source)
	at java.base/java.lang.Thread.run(Thread.java:844)

Since I didn’t find any help online about this but I made it work I thought I would share here how I did it.

The problem is that by default it chooses the wrong audio mixer. I fixed it with two steps.

  1. Call JavaSoundAudioIO.printMixerInfo(); to list the available mixers on the console.
  2. Look at the console and choose a mixer that it’s not the default one (0). Then I replace this line:
ac = new AudioContext();

with these three, in which I choose mixer 3 (my internal sound card):

JavaSoundAudioIO jsaIO = new JavaSoundAudioIO();
jsaIO.selectMixer(3);
ac = new AudioContext(jsaIO);

Then it works fine.

1 Like

@hamoid thanks for sharing :slight_smile: feel free to offer more Solutions in the future.

It’d be gr8 if the forum had a separate category for sharing tips & snippets. :angel:

1 Like

I feel this can simply go in Library questions, because it answers a Library question.

Gallery is “share and discuss your work” – this is a great contribution, but isn’t really “hamoid’s work”, even though it is a trick that hamoid got working.

@hamoid what exactly do you mean by “wrong mixer” though? Is this with the Oracle JDK in Processing or with OpenJDK? Because OpenJDK ships with a PulseAudio mixer provider that should come first in the mixer list by default. If with the bundled JDK, you could also look at the sound.properties file inside java/lib which should allow you to customize this for your system so default usage works. But no PulseAudio mixer because of Oracle’s license!

Of course you could always use JACK with Beads and get better audio performance. Beads also has a very old version of the JAudioLibs JavaSound backend from PraxisLIVE in there, but not the default, and for some reason Ollie broke it so it only works properly on macOS! :confused:

Thank you @neilcsmith :slight_smile: I’m in the process of making old projects work for a talk. The server side (which takes care of sound) was crashing by default. I’m not sure what I mean with “wrong mixer”, but I assumed it’s a mixer since the problem is solved by calling selectMixer() :slight_smile:

I’m using OpenJDK. I don’t know why the default audio setup doesn’t work. Probably related to the audio config in my ArchLinux. But I haven’t had issues with any other software… I can run Jack, SuperCollider and any common sound-generating program.

Thanks for the sound.properties tip. In my system it’s located in

/etc/java10-openjdk/sound.properties
/etc/java-8-openjdk/sound.properties

I should find online what to put in those files and see if it fixes the issue for all Java programs, not only for this specific project.

Thanks for this. This problem popped up when I switched from Java 8 to 11. Maybe something changed after Java 9.

Just a reminder for anyone:
The JavaSoundAudioIO.printMixerInfo() method prints a 1-based list;
While jsaIO.selectMixer(i) accepts a 0-based index.

Indeed, a breaking change happened in Java 9 → Java Modules: :coffee:
Docs.Oracle.com/javase/9/docs/api/overview-summary.html