USB Audio on Jetson TX2

Hello,

We have a Java app that simply opens the microphone and speaker, records microphone input and plays it out on the speaker. We’re using a USB audio device. This runs fine on Ubuntu 16.04 except it does not run on a Jetson board. On Jetson, it cannot open the microphone line and fails.

Any suggestions would be greatly appreciated.

See code below:

import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.TargetDataLine;

public class TestMic {

public static void main(String[] args) {
	AudioFormat format = new AudioFormat(44100, 16, 2, true, true);

	DataLine.Info targetInfo = new DataLine.Info(TargetDataLine.class, format);
	DataLine.Info sourceInfo = new DataLine.Info(SourceDataLine.class, format);

	try {
		TargetDataLine targetLine = (TargetDataLine) AudioSystem.getLine(targetInfo);
		targetLine.open(format);
		targetLine.start();

		SourceDataLine sourceLine = (SourceDataLine) AudioSystem.getLine(sourceInfo);
		sourceLine.open(format);
		sourceLine.start();

		int numBytesRead;
		byte[] targetData = new byte[targetLine.getBufferSize() / 5];

		while (true) {
			numBytesRead = targetLine.read(targetData, 0, targetData.length);

			if (numBytesRead == -1)	break;

			sourceLine.write(targetData, 0, numBytesRead);
		}
	}
	catch (Exception e) {
		System.err.println(e);
	}
}

}

Hello!

Can you tell me what l4t release you are using?

Can you check if USB audio support is enabled in your kernel …

$ zcat /proc/config.gz | grep SND_USB
CONFIG_SND_USB=y
CONFIG_SND_USB_AUDIO=y

I assume that you have checked that the device is seen from the output of ‘lsusb’.

Regards,
Jon

Hi Jon,

When running head /etc/nv_tegra_release I see the release is R27, Revision 0.1

When running zcat /proc/config.gz | grep SND_USB
CONFIG_SND_USB=y
CONFIG_SND_USB_AUDIO=m

Not sure the difference between your “y” and my “m”

When running lsusb it doesn’t seem to see the USB audio. When I run this with the USB audio unplugged I get the same response showing realtek and Intel Corp.

Thanks Jon for your help on this.

Best,
Dean

Hi Dean,

Any reason why you are using rel27 and not rel28.2 (which is the latest for TX2)?

The ‘m’ means that the USB_AUDIO driver is built as a module and not into the kernel. You can check if the module it getting loaded by looking at the output from ‘lsmod’. However, given that your USB audio device is not detected you may find that it is not loaded.

Yes so if ‘lsusb’ is not detecting the device then this is the first problem that needs to be resolved. However, you mentioned that ‘lsusb’ shows an Intel and Realtek device, that does not sound like you are running the command on Tegra but maybe your host? Sorry, if I was not clear, but I meant that you should run ‘lsusb’ on Tegra if you were not doing this.

You can also check the output from ‘dmesg’ on Tegra after connecting the USB device to see if anything was detected.

$ dmesg

I assume that you are connecting the USB device to the USB-A connector (J19) on TX2.

Thanks
Jon

Thanks Jon,

No particular reason for running rel27 vs rel28, it’s just what came on the TX2 board and I haven’t updated it.

I’m using this for a voice recognition application and at the moment not using the AI libraries in JetPack, just standard Ubuntu OS services (file read, write, microphone and speaker).

When running dmesg I do see several USB devices, including HUB, HID, PnP Sound so it seems to be detected.

$ lsmod shows snd_usbmidi_lib (1 snd_usb_audio)

Not sure if that means the USB audio driver is loaded or not. How can I make sure the USB audio driver is loaded into the kernel load?

Thanks again.

Best,
Dean

Hi Dean,

Yes it should be loaded, however, it should also be listed as well …

$ lsmod | grep snd_usb
snd_usb_audio 184320 0
snd_usbmidi_lib 32768 1 snd_usb_audio

Regards,
Jon

Hi Dean,

If the USB device is detected and the sound drivers are loaded, then dump the following and see if the USB sound card is listed …

$ cat /proc/asound/cards

Regards,
Jon

Hi Jon, here’s the output from those commands:

$ lsmod | grep snd_usb

snd_usb_audio 182328 1
snd_usbmidi_lib 26149 1 snd_usb_audio

$ cat /proc/asound/cards

0 [tegrahda ]: tegra-hda

1 [tegrasndt186ref]: tegra-snd-t186r

2 [Device ]: USB-Audio - USB PnP Sound Device

Hi Dean,

Great. If you run ‘aplay -l’ you should see a list of the audio playback devices. For example, I have …

$ aplay -l
**** List of PLAYBACK Hardware Devices ****

card 2: MicroII [Audio Advantage MicroII], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0

Where card 2 is my USB speaker. Assuming that it has one device like mine, you can test playing an WAV file to card 2, device 0, by …

$ aplay -D hw:2,0

Or recording by …

$ arecord -D hw:2,0 -r 44100 -f S16_LE -c 2

Regards,
Jon