# jacobjoaquin/Csoundo

Trying to figure out chn input/output problems.

1 parent 55fb090 commit a27f8aac9f1b53260a2d8329489382077f039b27 committed Aug 27, 2010
Showing with 78 additions and 64 deletions.
1. +28 −9 examples/protectedTable/protectedTable.pde
2. +48 −53 src/csoundo/Csoundo.java
3. +1 −1 src/csoundo/Engine.java
4. +1 −1 src/csoundo/Mutex.java
 @@ -15,6 +15,7 @@ import csoundo.*; Csoundo cs; +int bugs = 0; void setup() { size(740, 480); @@ -31,22 +32,40 @@ void draw() { noStroke(); fill(0, 8); rect(0, 0, width, height); - + + // Create empty table float size = pow(2, 12); cs.event("f 20 0 " + size + " 10 0"); int length = cs.tableLength(20); - float phase = (float) (frameCount % 60) / 60 * TWO_PI; - + + // Increment phase of sine table input + int inc = 60; + float phase = (float) (frameCount % inc) / inc * TWO_PI; + + // Create, write, read and draw sine waveform stroke(255, 255); beginShape(); - for (int i = 0; i < length; i++) { - // Intentionally read backwards - cs.tableSet(20, length - i - 1, sin(2 * PI * (float) i * - (random(0.0001) + 2.0) / (float) length + phase)); + for (int i = length - 1; i >= 0; i--) { + + // Generate sine data point and input into table + float input = sin(TWO_PI * (float) i / (float) length + phase); + cs.tableSet(20, length, input); + + // Read the from the table at the same index + float output = cs.tableGet(20, length); + + // Print message if input != output + if (output != input) { + println(output + " != " + input + " @index " + i); + bugs++; + println("fail rate = " + ((float) bugs / (float) frameCount)); + } - float v = cs.tableGet(20, length - i - 1); - vertex((float) i / (float) length * (float) width, height / 2.0 + height / 2.0 * v); + // Draw wave form + vertex((float) i / (float) (length - 1) * (float) width, + height / 2.0 + height / 2.0 * output); + } endShape();