简体   繁体   English

Java Sound API - 区分多个相同的USB声卡

[英]Java Sound API - Distinguish multiple equal USB sound cards

I'm using 4 USB sound cards (ASUS Xonar U1). 我正在使用4个USB声卡(华硕Xonar U1)。 I want to send to each one of them a different sound (the same text narrated in different languages). 我想向他们每个人发送一个不同的声音(同一个文本用不同的语言叙述)。 For now, what I do to get the sound mixers that I'm interested in, is something like this: 现在,我为了得到我感兴趣的混音器而做的是这样的:

Info[] mixerInfo = AudioSystem.getMixerInfo();
int count = 0;
for (Info i : mixerInfo) {
    System.out.println("["+(count++)+"]" + i.getName() + " - " + i.getDescription()+" - "+i.getVendor());
}

This gives me something like the following: 这给了我类似以下内容:

[5] Device [plughw:1,0] - Direct Audio Device: USB Advanced Audio Device, USB Audio, USB Audio - ALSA (http://www.alsa-project.org)
[6] Device_1 [plughw:2,0] - Direct Audio Device: USB Advanced Audio Device, USB Audio, USB Audio - ALSA (http://www.alsa-project.org)
[7] Device_2 [plughw:3,0] - Direct Audio Device: USB Advanced Audio Device, USB Audio, USB Audio - ALSA (http://www.alsa-project.org)

For now, in my configuration file, I'm associating the sound cards to the Info[] index (the "count" variable). 现在,在我的配置文件中,我将声卡与Info []索引(“count”变量)相关联。

The problem is if I change the USB port to which a sound card is connected. 问题是我是否更改了声卡所连接的USB端口。 Then the Info[] array has a whole new order and I don't know anymore which sound card should play the language en_US and which pt_PT for instance. 然后Info []数组有一个全新的顺序,我不知道哪个声卡应该播放语言en_US和哪个pt_PT

Also, the "plughw:1,0" string changes without any noticeable pattern. 此外,“plughw:1,0”字符串更改没有任何明显的模式。 If I have just one sound card it will always be "plughw:1,0" no matter to which port I connect it to. 如果我只有一个声卡,无论我连接到哪个端口,它总是“plughw:1,0”。

If the computer is restarted the mixer Info[] also gets reordered sometimes. 如果重新启动计算机,混音器Info []有时会重新排序。

I've also given a look at jUSB but the Device information for the sound cards is exactly the same for all of them and I wouldn't know how to map the USB information it gives me with the Java Sound API mixer Info. 我还看了一下jUSB,但声卡的设备信息对于所有这些都完全相同,我不知道如何映射它给我带来的Java Sound API混音器信息的USB信息。

So, does anyone know how to uniquely identify equal sound cards with the Java Sound API? 那么,有没有人知道如何使用Java Sound API唯一识别相同的声卡?

Alternatively, does anyone have another suggestion about which language/library I could use to write an application that outputs different audio files to 4 different USB sound cards in the same machine? 或者,有没有人有另外的建议,我可以使用哪种语言/库来编写一个应用程序,在同一台机器上输出不同的音频文件到4个不同的USB声卡?

Give a look at the BASS Audio Library, which is written in C. There's a JNI library, NativeBass , that's a bridge to use this natively in Java. 看一下用C语言编写的BASS音频库。有一个JNI库NativeBass ,它是在Java中本地使用它的桥梁。 You lose some cross-platform abilities, but the library is notably better performing, works very well with multiple outs, and I believe has better identification on each audio device. 你失去了一些跨平台的能力,但是图书馆表现更好,多次出局效果很好,我相信每个音频设备都有更好的识别能力。

(Installing NativeBass, you also need to download BASS itself, and merge the two /lib directories, which isn't completely documented.) (安装NativeBass,您还需要下载BASS本身,并合并两个/ lib目录,这些目录尚未完整记录。)

If I were going to stick with the solution you're using, I'd get an inexpensive USB hub, connect the audio USB to the hub, and connect the hub to the computer. 如果我要坚持使用您正在使用的解决方案,我会得到一个便宜的USB集线器,将音频USB连接到集线器,并将集线器连接到计算机。 That should initialize the audio in the same order each time, at least giving you a consistent ordering to work with in JavaSound. 这应该每次都以相同的顺序初始化音频,至少给你一个在JavaSound中使用的一致顺序。

Since we needed this to work in Linux, we ended up using this solution: http://alsa.opensrc.org/Udev 由于我们需要在Linux中使用它,我们最终使用了这个解决方案: http//alsa.opensrc.org/Udev

It assigns audio devices the same hwplug:x,y each time they're plugged in. More specifically, it assigns a fixed hwplug:x,y per USB port. 每次插入时,它都会为音频设备分配相同的hwplug:x,y。更具体地说,它为每个USB端口分配一个固定的hwplug:x,y。 Thus, we always know to which USB port a specific sound will be sent. 因此,我们始终知道将向哪个USB端口发送特定声音。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM