3
3
import java .util .logging .Level ;
4
4
import java .util .logging .Logger ;
5
5
6
+ import javax .sound .sampled .LineUnavailableException ;
7
+
6
8
import com .jsyn .JSyn ;
7
9
import com .jsyn .Synthesizer ;
8
10
import com .jsyn .devices .AudioDeviceFactory ;
9
11
import com .jsyn .devices .AudioDeviceManager ;
12
+ import com .jsyn .devices .AudioDeviceOutputStream ;
13
+ import com .jsyn .devices .jportaudio .JPortAudioDevice ;
10
14
import com .jsyn .unitgen .ChannelOut ;
11
15
import com .jsyn .unitgen .Multiply ;
12
16
import com .jsyn .unitgen .UnitGenerator ;
@@ -91,6 +95,40 @@ private Engine() {
91
95
Logger logger = Logger .getLogger (com .jsyn .engine .SynthesisEngine .class .getName ());
92
96
logger .setLevel (Level .WARNING );
93
97
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
+ // }
94
132
// create and start the synthesizer, and set this object as the singleton.
95
133
this .synth = JSyn .createSynthesizer (Engine .getAudioDeviceManager ());
96
134
@@ -116,8 +154,6 @@ private Engine() {
116
154
Engine .printWarning ("could not find any sound devices with input channels, you won't be able to use the AudioIn class" );
117
155
}
118
156
this .startSynth ();
119
-
120
- Engine .singleton = this ;
121
157
}
122
158
123
159
protected void startSynth () {
0 commit comments