Skip to content

Commit 5b05615

Browse files
committed
Load PortAudio when LineUnsupportedException occurs (refs #85)
1 parent 25d56a4 commit 5b05615

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

.classpath

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
<classpathentry kind="src" path="test"/>
77
<classpathentry kind="lib" path="library/javamp3-1.0.4.jar"/>
88
<classpathentry kind="lib" path="library/jsyn-17.1.0.jar"/>
9-
<classpathentry kind="lib" path="lib/junit-4.12.jar"/>
10-
<classpathentry kind="lib" path="lib/android.jar"/>
9+
<classpathentry kind="lib" path="library/junit-4.12.jar"/>
10+
<classpathentry kind="lib" path="library/android.jar"/>
11+
<classpathentry kind="lib" path="library/jportaudio.jar"/>
1112
<classpathentry kind="lib" path="test/**/*.class"/>
1213
<classpathentry kind="output" path="bin"/>
1314
</classpath>

src/processing/sound/Engine.java

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
import java.util.logging.Level;
44
import java.util.logging.Logger;
55

6+
import javax.sound.sampled.LineUnavailableException;
7+
68
import com.jsyn.JSyn;
79
import com.jsyn.Synthesizer;
810
import com.jsyn.devices.AudioDeviceFactory;
911
import com.jsyn.devices.AudioDeviceManager;
12+
import com.jsyn.devices.AudioDeviceOutputStream;
13+
import com.jsyn.devices.jportaudio.JPortAudioDevice;
1014
import com.jsyn.unitgen.ChannelOut;
1115
import com.jsyn.unitgen.Multiply;
1216
import com.jsyn.unitgen.UnitGenerator;
@@ -91,6 +95,40 @@ private Engine() {
9195
Logger logger = Logger.getLogger(com.jsyn.engine.SynthesisEngine.class.getName());
9296
logger.setLevel(Level.WARNING);
9397

98+
this.createSynthesizer();
99+
100+
Engine.singleton = this;
101+
}
102+
103+
private boolean triedPortAudio = false;
104+
105+
protected boolean usePortAudio() {
106+
// TODO check if we're actually on Windows?
107+
if (!this.triedPortAudio) {
108+
Engine.printMessage("Loading PortAudio");
109+
this.triedPortAudio = true;
110+
System.loadLibrary("portaudio_x64");
111+
AudioDeviceManager newManager = AudioDeviceFactory.createAudioDeviceManager();
112+
if (newManager instanceof JPortAudioDevice) {
113+
Engine.printMessage("Using PortAudio");
114+
Engine.audioManager = newManager;
115+
this.createSynthesizer();
116+
// TODO might need to reconnect old entities if possible?
117+
}
118+
}
119+
return Engine.audioManager instanceof JPortAudioDevice;
120+
}
121+
122+
private void createSynthesizer() {
123+
// try {
124+
AudioDeviceOutputStream o = Engine.audioManager.createOutputStream(AudioDeviceManager.USE_DEFAULT_DEVICE, this.sampleRate, 2);
125+
o.start();
126+
o.stop();
127+
// } catch (LineUnavailableException e) {
128+
// System.out.println(e);
129+
// this.usePortAudio();
130+
// return;
131+
// }
94132
// create and start the synthesizer, and set this object as the singleton.
95133
this.synth = JSyn.createSynthesizer(Engine.getAudioDeviceManager());
96134

@@ -116,8 +154,6 @@ private Engine() {
116154
Engine.printWarning("could not find any sound devices with input channels, you won't be able to use the AudioIn class");
117155
}
118156
this.startSynth();
119-
120-
Engine.singleton = this;
121157
}
122158

123159
protected void startSynth() {

0 commit comments

Comments
 (0)