Use ALSA pcm outputs via the Java SoundSystem
Asked Answered
D

1

6

I have a sound card with multiple outputs and use ALSA to map them to 2 separate stereo channels. The configuration works fine and allows me, for example with speaker-test to play audio on them.

I now want to use those 2 stereo outputs in a Java program, using the AudioSystem API. However, the stereo1 and stereo2 dont' show up using MixerInfo.

I do not really understand how Java decides which "devices" to expose using the AudioSystem API. I'm currently testing this on an Ubuntu 11.10 system.

This is the asound.conf used:

#/etc/asound.conf
pcm_slave.fourchannels {
        pcm "hw:0,0"          
        channels 4
}
pcm.stereo1 {
        type plug
        slave.pcm {
                type dshare
                ipc_key 87882222
                slave fourchannels
                bindings [ 0 1 ]
        }
}
pcm.stereo2 {
        type plug
        slave.pcm {
                type dshare
                ipc_key 87882222
                slave fourchannels
                bindings [ 2 3 ]
        }
}

This is the code I'm using to show the available inputs and outputs:

Mixer.Info[] mixers = AudioSystem.getMixerInfo();
for (Mixer.Info mixerInfo : mixers) {
    System.out.println("Found Mixer: " + mixerInfo);
    Mixer m = AudioSystem.getMixer(mixerInfo);

    Line.Info[] sourceLines = m.getSourceLineInfo();
    for (Line.Info li : sourceLines) {
        System.out.println("    Found source line: " + li);
        try {
            m.open();
        } catch (LineUnavailableException e) {
            System.out.println("        Line unavailable.");
        }
    }

    Line.Info[] targetLines = m.getTargetLineInfo();
    for (Line.Info li : targetLines) {
        System.out.println("    Found source line: " + li);
        try {
            m.open();
        } catch (LineUnavailableException e) {
            System.out.println("        Line unavailable.");
        }
    }
}
Desiraedesire answered 21/2, 2012 at 17:13 Comment(2)
Could we see the code you are using to display your mixers?Triplett
Looks good to me. Hmmm. How about the output of this code? I confess I don't know much about *nix system sound and probably won't be of much help. But others maybe will be able to use this info. I recall a thread that had to do with one of the apps monopolizing audio lines, not letting Java reach them. But I wasn't able to follow (understand) the entire exchange. If you want to look at that thread, it is at JGO: java-gaming.org/topics/javasound-on-linux/24686/view.html There are several references to ALSA.Triplett
D
2

The answer is: no. Java is not able to list the user-defined ALSA pcms, as it exposes only the hardware devices and the "default" device.

Got the info from an ALSA dev here: http://www.spinics.net/linux/fedora/alsa-user/msg10796.html

Desiraedesire answered 1/3, 2012 at 9:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.