Usando la librería sound de Processing.
import processing.sound.*;
TriOsc triOsc;
Env env;
float attackTime = 0.001;
float sustainTime = 0.004;
float sustainLevel = 0.2;
float releaseTime = 0.2;
int[] midiSequence = {61,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75};
int duration = 300;
int trigger = 0;
int note = 0;
int a;
float x,y,r,g,b;
void setup(){
size(640,360);
background(255);
triOsc = new TriOsc(this);
env = new Env(this);
}
void draw(){
println(millis());
if((millis()>trigger) && (note<midiSequence.length)){
//triOsc.play(midiToFreq(midiSequence[note]),0.8);
triOsc.play(midiToFreq((int)random(50,85)),0.8);
env.play(triOsc, attackTime, sustainTime, sustainLevel, releaseTime);
trigger = millis() + duration;
note++;
duration = (int)random(100,200);
x = (float)random(0,640);
y = (float)random(0,360);
r = (float)random(0,255);
g = (float)random(0,255);
b = (float)random(0,255);
a = (int)random(0,100);
fill(r,g,b,a);
noStroke();
ellipse(x,y,(float)random(20,100),(float)random(20,100));
//if(duration == 100){ duration = 300;}
if(note == 15){
note = 0;
}
}
}
float midiToFreq(int note){
return(pow(2,((note-69)/12.0)))*440;
}
No hay comentarios:
Publicar un comentario