If I understand the code I wrote correctly ::), the line is rejected if it either does not match the format or is unavailable. Could that be the cause for the “missing” options?
Code for selecting a Mixer on the JTheremin:
private void createMenuBars(){
JMenuBar menuBar = new JMenuBar();
menuBar.setBounds(0, 0, 60, 20);
JMenu optionMenu = new JMenu("Options");
JMenuItem pickMixers = new JMenuItem("Select a Playback Path");
optionMenu.add(pickMixers);
optionMenu.addSeparator();
ButtonGroup mixerSelections = new ButtonGroup();
addMixerOption("default sound system", mixerSelections,
optionMenu, true);
AudioFormat audioFmt = new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED,
44100, 16, 2, 4, 44100, false);
Mixer.Info[] mixers = AudioSystem.getMixerInfo();
for (Mixer.Info info : mixers)
{
Mixer mixer = AudioSystem.getMixer(info);
try
{
// System.out.println(info);
Info sdlLineInfo = new DataLine.Info(SourceDataLine.class,
audioFmt);
@SuppressWarnings("unused")
SourceDataLine sdl = (SourceDataLine) mixer.getLine(sdlLineInfo);
// if successful, add to list
addMixerOption(info.getName() + " <> " + info.getDescription(),
mixerSelections, optionMenu, false);
}
catch (LineUnavailableException e)
{
//e.printStackTrace();
// System.out.println("Mixer rejected, Line Unavailable: " + info);
}
catch (IllegalArgumentException e)
{
//e.printStackTrace();
// System.out.println("Mixer rejected, Illegal Argument: " + info);
}
}
menuBar.add(optionMenu);
add (menuBar,0);
}
private void addMixerOption(String optionName, ButtonGroup bg,
JMenu menu, boolean isSelected)
{
JRadioButtonMenuItem newOption = new JRadioButtonMenuItem(optionName);
bg.add(newOption);
newOption.setSelected(isSelected);
menu.add(newOption);
newOption.addActionListener(new OptionListener());
newOption.setActionCommand(optionName);
}
I am quite taken by surprise if there are cards that don’t support 44100 or try to use 48kHz in place of 44100. I was putting off implementing the suggestions for additional options due to not running into concrete examples of problems caused. This is a concrete example, though!
I’d be really tempted to limit input to the mixer to 44100 Hz and say to folks use Audacity to convert your sound resources. That is simple enough to do, or to explain how to do. But I am at a bit of a loss as to how to play back 44100 Hz data on a 48k line. There could well be pre-built converters in Java but it is annoying to have to add another level of processing. (Reality is a bitch, yeah.)
By the way, as I said “for grins,” I tried running a version of the audio mixer that omits the last step of sending the filled buffer to the SourceDataLine, and it takes about 6 milliseconds of processing per audio second.
I still have to write the “buffered input” version, and to create tests with more audio tracks. However, this preliminary test suggests that the loss of performance by working on a per-sample basis from the inputs may not be of killing significance. For example if the buffer inputs were twice as performant, that saves only 3 milliseconds. Either way, the cpu would still have 99% of its capacity free for other tasks. (I don’t know what the % free would drop to yet, when adding more tracks.)