Tiaga is part V of the web audio api minimal synths series.
You can play with the synth here. Since it uses the web audio api, it currently requires the chrome browser.
/**
tiaga.pde
kawandeep virdee
**/
int width=600;
int height=600;
int t=0;
float yval=300;
boolean saveFrames=false;
void setup() {
smooth();
frameRate(15);
colorMode(HSB, 360, 100, 100, 100);
size(width, height);
}
void draw() {
yval =450+50*sin(radians(5*t));
if (mouseY!=0) {
yval=mouseY;
}
float y = max(height-(yval), 100);
float res = height/(y/10);
float sat=50;
float val = map(height-yval, 0, height, 10, 20);
background(234, 5, 100);
for (int i=0; i<height; i+=res) {
noStroke();
fill(100, 50, val, 2+res);
rect(0, y+i, width, 1*i*res);
}
if (saveFrames) {
save("images/"+str(t)+".gif");
}
t++;
}
void keyPressed() {
if (key == CODED) {
if (keyCode == UP) {
println("Start saving frames");
saveFrames=true;
}
else if (keyCode == DOWN) {
println("Stop saving frames");
saveFrames=false;
}
}
}
/**
synth.js
kawandeep virdee
**/
var synths = [];
var gainVal = 0.03;
var qval = 25;
function openNotes(){
synths.push(setupSynth(150));
synths.push(setupSynth(100));
synths.push(setupSynth(200));
synths.push(setupSynth(250));
synths.push(setupSynth(300));
}
function closeNotes(){
for(var i=0; i<synths.length; i++){
synths[i].source.noteOff(0);
}
}
function updateNotes(pitch, variance){
for(var i=0; i<synths.length; i++){
synths[i].filter.frequency.value = pitch + variance*Math.random();
}
}
function onNotes(){
for(var i=0; i<synths.length; i++){
synths[i].volume.gain.value=gainVal;
}
}
function offNotes(){
for(var i=0; i<synths.length; i++){
synths[i].volume.gain.value=0;
}
}
function setupSynth(f){
var nodes={};
nodes.source = context.createOscillator();
nodes.source.type=1;
nodes.source.frequency.value = f;
nodes.filter = context.createBiquadFilter();
nodes.filter.Q.value =qval;
nodes.volume = context.createGainNode();
nodes.filter.type=0; //0 is a low pass filter
nodes.volume.gain.value = gainVal;
nodes.source.connect(nodes.filter);
nodes.filter.connect(nodes.volume);
//frequency val
nodes.filter.frequency.value=400;
//reverb
nodes.reverb = context.createConvolver();
nodes.volume.connect(nodes.reverb);
nodes.reverb.connect(context.destination);
nodes.volume.gain.value=0;
nodes.source.noteOn(0);
nodes.volume.gain.value=0;
setReverbImpulseResponse('http://thelab.thingsinjars.com/web-audio-tutorial/Church-Schellingwoude.mp3', nodes.reverb, function() {
nodes.source.noteOn(0);
});
return nodes;
}
function setReverbImpulseResponse(url, convolver, callback) {
var request = new XMLHttpRequest();
request.open("GET", url, true);
request.responseType = "arraybuffer";
request.onload = function () {
convolver.buffer = context.createBuffer(request.response, false);
callback();
}
request.send();
}