-
-
Notifications
You must be signed in to change notification settings - Fork 50
/
MultiChannelOutput.pde
74 lines (60 loc) · 2.15 KB
/
MultiChannelOutput.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import processing.sound.*;
SinOsc sines[];
int initialised;
float frequency;
void setup() {
size(640, 360);
background(255);
// some multi-channel USB audio interfaces don't show the correct number of
// output channels using the default audio drivers on Windows. If this is the
// case, try loading PortAudio support at the very top of your sketch with the
// following command (see the LowLevelEngine example for details):
// MultiChannel.usePortAudio();
boolean foundMultiChannel = false;
String[] deviceNames = Sound.list();
for (int i = 0; i < deviceNames.length; i++) {
if (MultiChannel.availableChannels(i) > 2) {
println("Found a multi-channel device: " + deviceNames[i]);
Sound.outputDevice(i);
foundMultiChannel = true;
break;
}
}
if (!foundMultiChannel) {
println("Did not find any output devices with more than 2 channels!");
}
println("Playing back different sine waves on the " + MultiChannel.availableChannels() + " different channels");
sines = new SinOsc[MultiChannel.availableChannels()];
initialised = 0;
frequency = 100;
textSize(128);
fill(0);
textAlign(CENTER);
}
void draw() {
// loop through all channels and start one sine wave on each
if (initialised < sines.length) {
// add a nice theatrical break
delay(1000);
background(255);
text((initialised + 1) + " of " + sines.length, width/2, height/2);
MultiChannel.activeChannel(initialised);
// create and start the sine oscillator.
sines[initialised] = new SinOsc(this);
sines[initialised].freq(frequency);
sines[initialised].play();
// increase frequency on the next channel by one semitone
frequency = frequency * 1.05946;
initialised = initialised + 1;
return;
}
// as long as the oscillators are not stopped they will 'stick'
// to the channel that they were originally added to, and we can
// change their parameters freely
frequency = map(mouseX, 0, width, 80.0, 1000.0);
for (SinOsc sin : sines) {
sin.freq(frequency);
// increase frequency on the next channel by one semitone (a factor of 2^(1/12))
frequency = frequency * 1.05946;
}
}