diff --git a/src/processing/sound/Engine.java b/src/processing/sound/Engine.java index a3c8cbd..c5745d1 100644 --- a/src/processing/sound/Engine.java +++ b/src/processing/sound/Engine.java @@ -138,7 +138,13 @@ private void createSynth(AudioDeviceManager deviceManager) { if (this.synth != null) { this.stopSynth(true); } - this.inputDevice = deviceManager.getDefaultInputDeviceID(); + // this might be -1 if there is no device with inputs. handled below. + System.out.println(deviceManager.USE_DEFAULT_DEVICE); + try { + this.inputDevice = deviceManager.getDefaultInputDeviceID(); + } catch (RuntimeException e) { + // JPortAudioDevice throws an exception if no devices with inputs + } this.outputDevice = deviceManager.getDefaultOutputDeviceID(); this.synth = JSyn.createSynthesizer(deviceManager); } @@ -191,8 +197,11 @@ private void startSynth() { } this.setVolume(1.0f); + // prevent IndexOutOfBoundsException on input-less devices + int inputChannels = this.inputDevice >= 0 ? + this.synth.getAudioDeviceManager().getMaxInputChannels(this.inputDevice) : 0; this.synth.start(this.sampleRate, - this.inputDevice, this.synth.getAudioDeviceManager().getMaxInputChannels(this.inputDevice), + this.inputDevice, inputChannels, this.outputDevice, this.synth.getAudioDeviceManager().getMaxOutputChannels(this.outputDevice)); }