Skip to content

Instantly share code, notes, and snippets.

@villares
Created November 28, 2018 22:55
Show Gist options
  • Save villares/09c06a3d5e778c9a9817c65eed82b19e to your computer and use it in GitHub Desktop.
Save villares/09c06a3d5e778c9a9817c65eed82b19e to your computer and use it in GitHub Desktop.
testing sound lib
import processing.sound.*;
SoundFile[] file;
// Define the number of samples
int numsounds = 5;
// Create an array of values which represent the octaves. 1.0 is playback at normal speed, 0.5 is half and
// therefore one octave down. 2.0 is double so one octave up.
float[] octave = {0.25, 0.5, 1.0, 2.0, 4.0};
// The playSound array is defining how many samples will be played at each trigger event
int[] playSound = {1, 1, 1, 1, 1};
// The trigger is an integer number in milliseconds so we can schedule new events in the draw loop
int trigger;
// This array holds the pixel positions of the rectangles which are drawn each event
int[] posx = {0, 128, 256, 384, 512};
boolean A, B, C, D, E;
void setup() {
size(640, 360);
background(255);
A = false;
B = false;
C = false;
D = false;
E = false;
// Create an array of empty soundfiles
file = new SoundFile[numsounds];
// Load 5 soundfiles from a folder in a for loop. By naming the files 1., 2., 3., n.aif it is easy to iterate
// through the folder and load all files in one line of code.
for (int i = 0; i < numsounds; i++) {
file[i] = new SoundFile(this, (i+1) + ".aif");
}
// Create a trigger which will be the basis for our random sequencer.
trigger = millis();
frameRate(10);
}
void draw() {
if (A) {
file[0].play(1, 1.0);
A = false;
}
if (B) {
file[1].play(1, 1.0);
B = false;
}
if (C) {
file[2].play(1, 1.0);
C = false;
}
if (D) {
file[3].play(1, 1.0);
D = false;
}
if (E) {
file[4].play(1, 1.0);
E = false;
}
}
void keyPressed() {
if (key == '1') A = true;
if (key == '2') B = true;
if (key == '3') C = true;
if (key == '4') D = true;
if (key == '5') E = true;
}
void keyReleased() {
if (key == '1') A = false;
if (key == '2') B = false;
if (key == '3') C = false;
if (key == '4') D = false;
if (key == '5') E = false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment