I'm working on an interactive sound installation that runs using Processing and Minim, among other things. This project requires more than just a simple left/right output (5 speakers, to be specific), which from what I've read means the Java Sound api is my primary option with my setup. I'm fairly new to Processing and totally new to lower level Java.
I'm running this all on a 2011 Macbook Pro with this external USB sound card: http://amzn.com/B004Y0ERRO, which seems to detect as a single USB audio interface just fine on the Mac. When using the Java Sound api, theoretically I should be able to get a list of Lines from a Mixer which would correspond to the 3 stereo output jacks I need access to, but I can't seem to figure out how and where to find them after spending much time in the Java Audio api docs and related tutorial sites.
EDIT: Turns out most surround sound soundcards are only stereo compatible on Macs, which explains much of my trouble. I will be retrying this with 3 stereo soundcards instead.
Here is a bare-bones version of a demo I'm working with in Processing:
import javax.sound.sampled.*;
Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo();
Mixer mixer = AudioSystem.getMixer(mixerInfo[8]);
void setup()
{
size(200, 200);
printArray(mixerInfo);
for(Line.Info lineInfo : mixer.getTargetLineInfo()){
Line thisLine = mixer.getLine(lineInfo);
thisLine.open();
println(thisLine);
}
}
The printArray returns this:
[0] Default Audio Device, version Unknown Version
[1] Built-in Microphone, version Unknown Version
[2] Built-in Input, version Unknown Version
[3] Built-in Output, version Unknown Version
[4] USB Sound Device , version Unknown Version
[5] Port Built-in Microphone, version Unknown Version
[6] Port Built-in Input, version Unknown Version
[7] Port Built-in Output, version Unknown Version
[8] Port USB Sound Device , version Unknown Version
Presumably I would want the last device (8) or maybe 4. I can't quite tell because I can't see what lines/ports belong to each device. When I try using:
mixer.getTargetLineInfo()
I get only one result:
SPEAKER target port
The for loop at the end should loop through all the lines in the mixer and open them (up until this point you have to comment out this section to not throw an error) but instead I get this error:
Unhandled exception type LineUnavailableException
I feel like I must be digging into the wrong place, how could a surround sound USB card have only a single, closed SPEAKER target port when there are 10 jacks on the device? No matter how closely I read the documentation I can't figure out where I'm going wrong. Thanks for reading and I greatly appreciate any insight you can provide!
EDIT:
Version of above sketch with basic minim playback included:
import ddf.minim.Minim;
import ddf.minim.ugens.Oscil;
import ddf.minim.AudioOutput;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Mixer;
import javax.sound.sampled.Line;
Minim minim;
AudioOutput out;
Oscil wave;
Mixer.Info[] mixerInfo;
javax.sound.sampled.Line.Info lineInfo;
javax.sound.sampled.Line Line;
void setup()
{
size(200, 200);
minim = new Minim(this);
mixerInfo = AudioSystem.getMixerInfo();
Mixer mixer = AudioSystem.getMixer(mixerInfo[8]);
try {
for (Line.Info lineInfo : mixer.getTargetLineInfo()) {
Line thisLine = mixer.getLine(lineInfo);
thisLine.open();
println(lineInfo);
}
}
catch(LineUnavailableException e) {
e.printStackTrace();
}
minim.setOutputMixer(mixer);
out = minim.getLineOut(Minim.STEREO);
wave = new Oscil( 440, 0.5f, Waves.SINE );
wave.patch( out );
}