/**
*
Tuned Wind
*by Benito
*Filtered noise = fun. Hit keys to start a wind sequence with a bluesy pentatonic-plus-flat-third scale.
*- Different keys will change at different rates (though it will always change randomly.
*- Also, different keys will be tuned slightly differently, though you might not notice.
*- The mouse X-axis controls how much the frequency glides.
*- The mouse Y-axis controls the tone quality of the sequence.
*/
import net.beadsproject.beads.core.*;
import net.beadsproject.beads.ugens.*;
import net.beadsproject.beads.data.*;
import net.beadsproject.beads.events.*;
AudioContext ac;
Gain mg;
Compressor comp;
Noise n;
float[] pent = {0, 1.98, 3.02, 3.95, 7.02, 8.98};
void setup() {
size(400, 400);
ac = new AudioContext();
n = new Noise(ac);
ac.out.addDependent(n);
mg = new Gain(ac, 1, .4);
comp = new Compressor(ac);
mg.addInput(comp);
ac.out.addInput(mg);
ac.start();
}
void draw() {
background(0);
}
void keyTyped() {
int newkey = key % 40;
float shortlen = (float)(key % 17) * 600 + 2000;
float longlen = (float)(key % 37 + 1) * 600 + shortlen;
RandomPWM pwm = new RandomPWM(ac, RandomPWM.NOISE, shortlen, longlen, 1);
Function f = new Function(pwm) {
float inval = -2;
float outval = 0;
float base = 55 * ((float)(key % 3) + 2) / ((key % 3) + 1);
public float calculate() {
if(x[0] != inval) {
inval = x[0];
int i = (int)((inval + 1) * 26);
outval = 55 * pow(2, i / pent.length + pent[i % pent.length] / 12 + (float)(i % 17) / 500);
}
return outval;
}
};
float glide = (float)mouseX / width;
glide = glide * glide * 10;
OnePoleFilter opf = new OnePoleFilter(ac, glide);
opf.addInput(f);
BiquadFilter bf = new BiquadFilter(ac, 1, BiquadFilter.BP_PEAK);
float q = (float)mouseY / height;
q = q * 200 + 1;
bf.setQ(q).setFrequency(opf);
bf.addInput(n);
OnePoleFilter opf2 = new OnePoleFilter(ac, 1200);
opf2.addInput(bf);
Envelope env = new Envelope(ac, 0);
Gain g = new Gain(ac, 1, env);
g.addInput(opf2);
comp.addInput(g);
env.addSegment(10, 400);
env.addSegment(10, 1000);
env.addSegment(0, 4000);
env.addSegment(0, 100, new KillTrigger(g));
}
void keyPressed() {
// trap escape
if(key == ESC) {
key = 0;
}
}