help in increment!!
in
Contributed Library Questions
•
1 year ago
- import krister.Ess.*;
AudioChannel myChannel;
SineWave myWave;
int frequency = 5000;
int amplitude =50;
int duration=5000; // 5 secs
int timer =0;
void setup() {
size(500,250);
background(0);
frameRate(10);
// start up Ess
Ess.start(this);
// create a new AudioChannel
myChannel=new AudioChannel();
myChannel.sampleRate(44100);
// generate 3 seconds of a soft triangle wave
// play
//myChannel.play();
}
void draw() {
// set the size to 5 seconds
myChannel.initChannel(myChannel.frames(duration));
myWave=new SineWave(frequency,0.5);
myWave.generate(myChannel,0,myChannel.frames(3000));
myChannel.play();
stroke(255);
beginShape();
for(int j=0;j<myChannel.buffer.length;j++)
{
vertex((float)j/10,height/2+amplitude*myChannel.buffer[j]);
}
background(0);
endShape();
//print(amplitude);
if(frameCount%10==0)
{
timer++;
}
// timer++;
// println("time elapsed: "+timer+" ");
//println("duration: " +duration);
fill(0,200f,0);
text("duration: "+ duration,15,30);
text("frquency: "+ frequency,400,30);
fill(220,0,0);
text("elapsed time: "+ timer +" (s)",15,45);
text("amplitude: "+ amplitude,400,45);
if(timer*1000>= duration)
{
stop();
}
}
// we are done, clean up Ess
public void stop() {
Ess.stop();
super.stop();
}
void keyPressed()
{
if (key=='f')
{
if(mousePressed==true)
{
if (mouseButton==LEFT)
frequency+=1000;
else if(mouseButton==RIGHT)
frequency-=1000;
}
}
else if(key=='d')
{
if(mousePressed==true)
{
if (mouseButton==LEFT)
duration+=1000;
else if(mouseButton==RIGHT)
duration-=1000;
}
}
else if(key=='a')
{
if(mousePressed==true)
{
if (mouseButton==LEFT)
amplitude+=10;
else if(mouseButton==RIGHT)
amplitude-=10;
}
}
}
Note: Ess library is needed for the code to work!!
this is my code so far , the problem is when I click a certain key (a,d,f) followed by mousePress in order to increment (amplitude,duration, frequency) It doesn't get incremeted by the value I specify ... It either go triple the value or double the value. I think it's due to the frameRate but I don't know how to fix it.
thanks in advance !
1