Skip to content

Commit 781b0e7

Browse files
committed
Improve the MultiChannelOutput and LowLevelEngine examples
1 parent 5a796d0 commit 781b0e7

File tree

3 files changed

+41
-20
lines changed

3 files changed

+41
-20
lines changed

build.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
<include name="LICENSE" />
116116
<include name="README.md" />
117117
<include name="examples/**" />
118-
<include name="${lib}/.properties" />
118+
<include name="library.properties" />
119119
<include name="${lib}/*.jar" />
120120
<!-- all files inside per-architecture native library directories -->
121121
<include name="${lib}/*-*/*" />
Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,34 @@
11
import processing.sound.*;
22

3-
import com.jsyn.devices.*;
43
import com.jsyn.Synthesizer;
5-
import com.jsyn.devices.jportaudio.JPortAudioDevice;
64

75
void setup() {
86

9-
// get hardware device information
7+
// print audio device information to the console
108
Sound.list();
119

12-
AudioDeviceManager m = Sound.getAudioDeviceManager();
13-
println("Audio device manager: " + m);
14-
if (m instanceof JPortAudioDevice) {
15-
println("Using the PortAudio device for 24 bit support on Windows");
16-
}
17-
18-
19-
// get synthesis runtime information
20-
Synthesizer s = Sound.getSynthesizer();
21-
// a lot of this information can be gleaned with one look by calling Sound.status();
22-
println("Current CPU usage: " + s.getUsage());
10+
// to improve support for USB audio interfaces on Windows, it is possible to
11+
// use the PortAudio library, which is however not enabled by default. The
12+
// listing above might therefore not have given accurate input/output channel
13+
// numbers. The library automatically loads PortAudio drivers when
14+
// Sound.outputDevice() is called on a device that it is unable to use
15+
// correctly with the default drivers, OR you can always load them explicitly
16+
// using MultiChannel.usePortAudio().
17+
if (MultiChannel.usePortAudio()) {
18+
// if PortAudio was loaded successfully, the ids and names of the sound
19+
// devices (and possibly their number of input/output channels) will have
20+
// changed!
21+
Sound.list();
22+
}
23+
24+
// the Sound.status() method prints some general information about the current
25+
// memory and CPU usage of the library to the console
26+
Sound.status();
27+
28+
// to get programmatic access to the same information (and more), you can get
29+
// and inspect the JSyn Synthesizer class yourself:
30+
Synthesizer s = Sound.getSynthesizer();
31+
println("Current CPU usage: " + s.getUsage());
2332

2433
}
2534

examples/IO/MultiChannelOutput/MultiChannelOutput.pde

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@ SinOsc sines[];
55
void setup() {
66
size(640, 360);
77
background(255);
8-
9-
8+
9+
// some multi-channel USB audio interfaces don't show the correct number of
10+
// output channels on Windows. If this is the case, try loading PortAudio
11+
// support at the very top of your sketch with the following command (see the
12+
// LowLevelEngine example for details):
13+
//MultiChannel.usePortAudio();
14+
1015
boolean foundMultiChannel = false;
11-
for (int i = 0; i < Sound.list(true).length; i++) {
16+
String[] deviceNames = Sound.list();
17+
for (int i = 0; i < deviceNames.length; i++) {
1218
if (MultiChannel.availableChannels(i) > 2) {
13-
println("Found a multi-channel device: " + Sound.list(true)[i]);
19+
println("Found a multi-channel device: " + deviceNames[i]);
1420
Sound.outputDevice(i);
1521
foundMultiChannel = true;
1622
break;
@@ -21,16 +27,22 @@ void setup() {
2127
}
2228

2329
println("Playing back different sine waves on the " + MultiChannel.availableChannels() + " different channels");
24-
float freq = 100;
2530

2631
sines = new SinOsc[MultiChannel.availableChannels()];
2732

2833
// loop through all channels and start one sine wave on each
34+
float frequency = 100;
2935
for (int i = 0; i < sines.length; i++) {
3036
MultiChannel.activeChannel(i);
3137
// create and start the sine oscillator.
3238
sines[i] = new SinOsc(this);
39+
sinces[i].freq(frequency);
3340
sines[i].play();
41+
// add a nice theatrical break
42+
delay(500);
43+
44+
// increase frequency on the next channel by one semitone
45+
frequency = frequency * 1.05946;
3446
}
3547
}
3648

0 commit comments

Comments
 (0)