/** *

Shimmertone

*

by Benito

*

A "shimmering" effect created by alternating between a pure tone and one ring modulated with random frequencies.

*

Move the mouse to shange the shimmer: X-axis controls rate of alternation, Y-axis controls spread of random ring frequencies.

*

Clicking changes the base tone.

*/ import net.beadsproject.beads.core.*; import net.beadsproject.beads.ugens.*; import net.beadsproject.beads.data.*; AudioContext ac; Envelope rate; Envelope tonefreq, softsquare; WavePlayer ringtone; float randomed = 0; void setup() { size(400, 400); ac = new AudioContext(); rate = new Envelope(ac, 6); tonefreq = new Envelope(ac, 220); softsquare = new Envelope(ac, 1); WavePlayer square = new WavePlayer(ac, rate, Buffer.SQUARE); WavePlayer tone = new WavePlayer(ac, tonefreq, Buffer.SINE); ringtone = new WavePlayer(ac, 220, Buffer.SINE); Function ring = new Function(square, ringtone, softsquare) { boolean one = true; public float calculate() { if(x[0] > 0) { if(!one) { one = true; float tf = tonefreq.getValue(); ringtone.setFrequency(random(tf * (1 - randomed), tf * (1 + randomed))); softsquare.clear(); softsquare.addSegment(1, 5); } } else { if(one) { one = false; softsquare.clear(); softsquare.addSegment(0, 5); } } return x[2] + (1 - x[2]) * x[1]; } }; Gain ringer = new Gain(ac, 1, ring); ringer.addInput(tone); Gain mg = new Gain(ac, 1, .2); mg.addInput(ringer); ac.out.addInput(mg); ac.start(); } void draw() { background(0); } void mouseMoved() { rate.clear(); rate.addSegment((float)mouseX / width * 80 + 3, 100); randomed = (float)mouseY / height; } void mouseClicked() { tonefreq.clear(); float freq = pow(2, 8 * (1 - (float)mouseY / height)) * 55; tonefreq.addSegment(freq, 500); }