通过 Java SoundSystem 使用 ALSA pcm 输出

发布于 2025-01-07 17:20:24 字数 1649 浏览 5 评论 0原文

我有一个具有多个输出的声卡,并使用 ALSA 将它们映射到 2 个独立的立体声通道。配置工作正常,并允许我使用扬声器测试来在它们上播放音频。

我现在想使用 AudioSystem API 在 Java 程序中使用这 2 个立体声输出。但是,使用 MixerInfo 不会显示立体声 1 和立体声 2。

我不太明白 Java 如何决定使用 AudioSystem API 公开哪些“设备”。我目前正在 Ubuntu 11.10 系统上对此进行测试。

这是使用的 asound.conf:

#/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 ]
        }
}

这是我用来显示可用输入和输出的代码:

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.");
        }
    }
}

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.");
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花之痕靓丽 2025-01-14 17:20:24

答案是:不。 Java 无法列出用户定义的 ALSA pcm,因为它仅公开硬件设备和“默认”设备。

从 ALSA 开发人员处获取信息:http://www.spinics。净/linux/fedora/alsa-user/msg10796.html

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文