I am trying to implement some code with Ess, that should layer different triangle waves in a sequence. It works fine when I use myTriangle.generate(myChannel, start, duration), but that does not allow for polyphony.
When I use myTriangle.generate(myChannel, Ess.ADD, start, duration), it stops working, unless I drastically increase the duration, at which point it the starting position seems to be + 50 % of the total length over. ie, if I wanted it to start 25% of the way through, it would now start 75% of the way, whereas with Ess.REPLACE it worked fine.
So, am I doing something wrong while generating these waves? Or is there another way to do this that works? I have tried many different things; Ess.SUBTRACT does the same thing as Ess.ADD. Why would it be different with these? I cannot find this mentioned anywhere in the Ess documentation.
If anyone can help, it would be much appreciated.
Relevant parts of the sound code:
Code:
void setup() {
...
Ess.start(this);
myChannel = new AudioChannel();
myChannel.initChannel(myChannel.frames(2560));
mySilence = new Silence();
myChannel.softClip = true;
myTriangle = new TriangleWave[POLYPHONY];
myChannel.play(Ess.FOREVER);
}
void killSound() {
myAmplify=new Amplify(0);
myAmplify.filter(myChannel, 0, myChannel.frames(2560));
}
void processSound()
{
killSound();
Blob b;
for (int n=0; n<theBlobDetection.getBlobNb(); n++) {
b = theBlobDetection.getBlob(n);
if (b!=null) {
freq = (int) (((b.yMin + b.h / 2) * height) + 10) * 2;
start = (int) (b.xMin * 640 * MULTIPLE);
end = (int) ((b.xMin * 640 * MULTIPLE) + (b.w * 640 * MULTIPLE));
if ( (end - start) > 30) {
println("Adding wave: " + freq + "hz, from " + start + " ms to " + end + " ms.");
println("Actual vals: " + freq + "hz, from " + myChannel.frames(start) + " frame " + myChannel.frames(end) + " frame");
myTriangle[n] = new TriangleWave(freq, .5);
myTriangle[n].generate(myChannel, Ess.ADD, myChannel.frames(start), myChannel.frames(end - start) );
}
}
}
}
void audioChannelLoop(AudioChannel ch) {
println("Current frame: " + myChannel.cue);
println("Current ms: " + myChannel.ms(myChannel.cue));
processSound();
}