Very fast react with using Array!
Hi
Can we do something with array to make it work faster?
I have an array with 8 elements.
I can call each of these elements separately by key pressing.
I want to make this program react very fast when a key is pressed and the sound can be heard as soon as a key pressed. How can I do it?
I don’t want to write lots of arrays and separate the original array!
-
import krister.Ess.*;
-
AudioChannel myChannel;
TriangleWave myWave;
Envelope myEnvelope;
int numNotes = 200;
int noteDuration = 200;
float[] rawSequence = {
293.6648,//(a)
329.62756,//(s)
391.9955,//(d)
369.99445,//(f)
439.99997,//(z)
587.3294,//(x)
392.62756,//(c)
523.25116//(v)
}; -
int time = 0;
int current = 0;
void setup()
{
size(300,300);
Ess.start(this);
myChannel = new AudioChannel();
myChannel.initChannel(myChannel.frames(rawSequence.length * noteDuration));
//int current = 0;
myWave = new TriangleWave(480, 0.3);
EPoint[] myEnv = new EPoint[3];
myEnv[0] = new EPoint(0,0);
myEnv[1] = new EPoint(0.25,1);
myEnv[2] = new EPoint(2,0);
myEnvelope = new Envelope(myEnv);
// int time = 0;
}
void draw()
{
int begin = myChannel.frames(time);
int e = int(noteDuration*0.8);
int end = myChannel.frames(e);
myWave.generate(myChannel, begin, end);
myEnvelope.filter(myChannel, begin, end); -
if((keyPressed == true)&&(key =='a'))
{
myWave.frequency = rawSequence[0];
myChannel.play(); }
if((keyPressed == true)&&(key =='s'))
{
myWave.frequency = rawSequence[1];
myChannel.play();}
if((keyPressed == true)&&(key =='d'))
{
myWave.frequency = rawSequence[2];
myChannel.play();}
if((keyPressed == true)&&(key =='f'))
{
myWave.frequency = rawSequence[3];
myChannel.play();}
if((keyPressed == true)&&(key =='z'))
{
myWave.frequency = rawSequence[4];
myChannel.play();}
if((keyPressed == true)&&(key =='x'))
{
myWave.frequency = rawSequence[5];
myChannel.play();}
if((keyPressed == true)&&(key =='c'))
{
myWave.frequency = rawSequence[6];
myChannel.play();}
if((keyPressed == true)&&(key =='c'))
{
myWave.frequency = rawSequence[7];
myChannel.play();}
} -
public void stop()
{
Ess.stop();
super.stop();
}