tags:

views:

443

answers:

1

I have a working program written in Java with the Java Sound API that is able to play multiple mp3 audio files at the same time to different USB Sound Cards in the same computer. It works fine in Linux. In Mac OS X, however, it does not.

The listing of my sound Mixer Infos is:

[0] Java Sound Audio Engine
[1] Built-in Input
[2] USB Advanced Audio Device

If I choose mixer [0] to play the file it does so successfully with the built-in sound card. If I choose mixer [2] to play the file, I get the following exception:

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, little-endian
at com.sun.media.sound.SimpleInputDevice.getLine(SimpleInputDevice.java:142)
at javax.sound.sampled.AudioSystem.getSourceDataLine(AudioSystem.java:633)
at pt.mobbit.sensorsloader.actuators.multiaudio.AudioPlayer$AudioPlayerThread.run(AudioPlayer.java:135)
at java.lang.Thread.run(Thread.java:613)

However, if I change the Output Device in OS X's System Preferences to be the USB Sound Card, and then in my java application I choose the mixer [0], the sound comes out through the USB Sound card. This leads me to believe that the USB Sound Card can play the mp3 files in OS X as well, just not when it isn't the main output device.

Does anyone know how I can output sound to my usb sound card in OS X without it having to be the system's main output device?

+2  A: 

Can you play back on the USB card with other sample rates/sample formats when it is not the default device?

My is that OS X does software mixing + sample rate + sample format conversion on the default sound card (otherwise multiple programs would not be able to simultaneously play sounds unless they all agreed on one single sample rate + sample format which would be very unpractical), but it does not do that for other sound cards. So OS X converts the output of your program to the one the USB sound card hardware needs when the USB sound card is selected as default, but there is no conversion when it is not the default, so you get an unsupported format error.

Look into the documentation of the card to see the sample rate and sample format it supports - most probably it will be like 48000 Hz, 16 bit signed little endian, and 2 or 6 or 8 channels.

Bandi-T
Thank you for your answer. I have tried other files including .wav files with the format the Sound Card expects (Asus Xonar U1 - basically it's the one you described) but still no luck. I've also tried to manually set the AudioFormat but still nothing.I still get stuff like: java.lang.IllegalArgumentException: Line unsupported: interface SourceDataLine supporting format PCM_SIGNED 48000.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endianDo you have any other suggestion? Thanks.
Tiago Alves
Hmm, maybe try 6 channels and 8 channels.Alternatively, look in the documentation of the card to find out what formats it does natively support. Lacking documentation, try to find a detailed enough USB sound card driver (e.g. the one in Linux does) that lists the formats the card supports.
Bandi-T