Skip to content

Commit

Permalink
Improve the MultiChannelOutput and LowLevelEngine examples
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinstadler committed Sep 20, 2023
1 parent 5a796d0 commit 781b0e7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 20 deletions.
2 changes: 1 addition & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
<include name="LICENSE" />
<include name="README.md" />
<include name="examples/**" />
<include name="${lib}/.properties" />
<include name="library.properties" />
<include name="${lib}/*.jar" />
<!-- all files inside per-architecture native library directories -->
<include name="${lib}/*-*/*" />
Expand Down
37 changes: 23 additions & 14 deletions examples/IO/LowLevelEngine/LowLevelEngine.pde
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
import processing.sound.*;

import com.jsyn.devices.*;
import com.jsyn.Synthesizer;
import com.jsyn.devices.jportaudio.JPortAudioDevice;

void setup() {

// get hardware device information
// print audio device information to the console
Sound.list();

AudioDeviceManager m = Sound.getAudioDeviceManager();
println("Audio device manager: " + m);
if (m instanceof JPortAudioDevice) {
println("Using the PortAudio device for 24 bit support on Windows");
}


// get synthesis runtime information
Synthesizer s = Sound.getSynthesizer();
// a lot of this information can be gleaned with one look by calling Sound.status();
println("Current CPU usage: " + s.getUsage());
// to improve support for USB audio interfaces on Windows, it is possible to
// use the PortAudio library, which is however not enabled by default. The
// listing above might therefore not have given accurate input/output channel
// numbers. The library automatically loads PortAudio drivers when
// Sound.outputDevice() is called on a device that it is unable to use
// correctly with the default drivers, OR you can always load them explicitly
// using MultiChannel.usePortAudio().
if (MultiChannel.usePortAudio()) {
// if PortAudio was loaded successfully, the ids and names of the sound
// devices (and possibly their number of input/output channels) will have
// changed!
Sound.list();
}

// the Sound.status() method prints some general information about the current
// memory and CPU usage of the library to the console
Sound.status();

// to get programmatic access to the same information (and more), you can get
// and inspect the JSyn Synthesizer class yourself:
Synthesizer s = Sound.getSynthesizer();
println("Current CPU usage: " + s.getUsage());

}

22 changes: 17 additions & 5 deletions examples/IO/MultiChannelOutput/MultiChannelOutput.pde
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ SinOsc sines[];
void setup() {
size(640, 360);
background(255);



// some multi-channel USB audio interfaces don't show the correct number of
// output channels 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;
for (int i = 0; i < Sound.list(true).length; i++) {
String[] deviceNames = Sound.list();
for (int i = 0; i < deviceNames.length; i++) {
if (MultiChannel.availableChannels(i) > 2) {
println("Found a multi-channel device: " + Sound.list(true)[i]);
println("Found a multi-channel device: " + deviceNames[i]);
Sound.outputDevice(i);
foundMultiChannel = true;
break;
Expand All @@ -21,16 +27,22 @@ void setup() {
}

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

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

// loop through all channels and start one sine wave on each
float frequency = 100;
for (int i = 0; i < sines.length; i++) {
MultiChannel.activeChannel(i);
// create and start the sine oscillator.
sines[i] = new SinOsc(this);
sinces[i].freq(frequency);
sines[i].play();
// add a nice theatrical break
delay(500);

// increase frequency on the next channel by one semitone
frequency = frequency * 1.05946;
}
}

Expand Down

0 comments on commit 781b0e7

Please sign in to comment.