Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Trying to figure out chn input/output problems.

  • Loading branch information...
commit a27f8aac9f1b53260a2d8329489382077f039b27 1 parent 55fb090
@jacobjoaquin authored
View
37 examples/protectedTable/protectedTable.pde
@@ -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();
View
101 src/csoundo/Csoundo.java
@@ -33,7 +33,7 @@
*/
-public class Csoundo{
+public class Csoundo extends Thread{
PApplet myParent;
public final static String VERSION = "##version##";
@@ -57,42 +57,35 @@
* @param theParent The PApplet. Usually pass 'this'
* @param f The Csound file to run. Requires full absolute path.
*/
- public Csoundo(PApplet theParent, String _csd) {
- myParent = theParent;
- welcome();
- myParent.registerDispose(this);
- myParent.registerPost(this);
+ public Csoundo(PApplet theParent, String _csd) {
+ myParent = theParent;
+ welcome();
+ myParent.registerDispose(this);
+ myParent.registerPost(this);
path = myParent.dataPath("");
- csd = myParent.dataPath(path + _csd);
- engine = new Engine(csd, path);
- }
+ csd = myParent.dataPath(path + _csd);
+ engine = new Engine(csd, path);
+
+ }
public void dispose() {
System.out.println("Csound dispose");
- // TODO: Not satisified that Csound is shutdown properly.
-
- perfThread.Stop(); // Calls csound.Cleanup() too
-
- System.out.println("perfThread waiting");
- while(perfThread.GetStatus() == 0) { };
- System.out.println("perfThread finished");
+ // NOTE:
-/*
- csound.Stop();
-
- System.out.println("csnd.csoundDestroy()");
- csnd.csoundDestroy(csound_p);
- while(csound != null) { }
- System.out.println("csound finished");
-*/
- System.out.println("Csound dispose complete");
+ perfThread.Stop();
+ System.out.println("perfThread waiting");
+ perfThread.Join();
+ System.out.println("perfThread finished");
+ csound.Cleanup();
+ csound.delete();
+ System.out.println("Csound dispose complete");
}
public void pre() { }
public void post() {
- mutex.cleanup(); // Closes any mutex locks left open from lock()
+// mutex.cleanup(); // Closes any mutex locks left open from lock()
}
private void welcome() {
@@ -114,12 +107,12 @@ public static String version() {
* @param s The score event. ie "i 1 0 1 0.707 440"
*/
public void event(String s) {
- if (!isRunning) return;
+// if (!isRunning) return;
// TODO: Is mutex needed if csoundPerformanceThread.InputMessage()
// is already thread safe? Does it use mutex?
- mutex.lock();
+// mutex.lock();
perfThread.InputMessage(s);
- mutex.unlock();
+// mutex.unlock();
}
/**
@@ -128,7 +121,7 @@ public void event(String s) {
* @return 0dbfs
*/
public float get0dBFS() {
- if (!isRunning) return 0;
+// if (!isRunning) return 0;
return csound.Get0dBFS();
}
@@ -138,10 +131,10 @@ public float get0dBFS() {
* @return chn bus value
*/
public float getChn(String chn) {
- if (!isRunning) return 0;
- mutex.lock();
+// if (!isRunning) return 0;
+// mutex.lock();
float value = csound.GetChannel(chn);
- mutex.unlock();
+// mutex.unlock();
return value;
}
@@ -164,7 +157,7 @@ public String getOptions() {
*/
public int getPerfStatus() {
// TODO: Make ENUMS, not magic numbers
- if (!isRunning) return -99999;
+// if (!isRunning) return -99999;
return perfThread.GetStatus();
}
@@ -174,7 +167,7 @@ public int getPerfStatus() {
* @return krate
*/
public float kr() {
- if (!isRunning) return 0;
+// if (!isRunning) return 0;
return csound.GetKr();
}
@@ -185,7 +178,7 @@ public float kr() {
*/
public float ksmps() {
// TODO: Throw exceptions, not magic numbers.
- if (!isRunning) return 0;
+// if (!isRunning) return 0;
return csound.GetKsmps();
}
@@ -202,7 +195,7 @@ public void lock() {
* @return number of output channels
*/
public float nchnls() {
- if (!isRunning) return 0;
+// if (!isRunning) return 0;
return csound.GetNchnls();
}
@@ -210,6 +203,8 @@ public float nchnls() {
* starts the Csound engine.
*/
public void run() {
+ super.run();
+ System.out.println(getName());
engine.start();
perfThread = engine.perfThread;
while(perfThread.GetStatus() != 0) {
@@ -224,10 +219,10 @@ public void run() {
* Sets the value of the specified chn bus.
*/
public void setChn(String chn, float value) {
- if (!isRunning) return;
- mutex.lock();
+// if (!isRunning) return;
+// mutex.lock();
csound.SetChannel(chn, value);
- mutex.unlock();
+// mutex.unlock();
}
/**
@@ -235,10 +230,10 @@ public void setChn(String chn, float value) {
*/
public void setChn(String chn, String sValue) {
// TODO: Untested. Need to figure out how to get a string.
- if (!isRunning) return;
- mutex.lock();
+// if (!isRunning) return;
+// mutex.lock();
csound.SetChannel(chn, sValue);
- mutex.unlock();
+// mutex.unlock();
}
/* TODO: Try to get this working, even if unnecessary.
@@ -275,7 +270,7 @@ public void setOptions(String s) {
* @return samplerate
*/
public float sr() {
- if (!isRunning) return 0;
+// if (!isRunning) return 0;
return csound.GetSr();
}
@@ -288,10 +283,10 @@ public float sr() {
*/
public float tableGet(int t, int i) {
// TODO: If sets are locked, do gets need to be?
- if (!isRunning) return 0;
- mutex.lock();
+// if (!isRunning) return 0;
+// mutex.lock();
float value = csound.TableGet(t, i);
- mutex.unlock();
+// mutex.unlock();
return value;
}
@@ -302,10 +297,10 @@ public float tableGet(int t, int i) {
* @return Csound table length
*/
public int tableLength(int t) {
- if (!isRunning) return 0;
- mutex.lock();
+// if (!isRunning) return 0;
+// mutex.lock();
int value = csound.TableLength(t);
- mutex.unlock();
+// mutex.unlock();
return value;
}
@@ -317,10 +312,10 @@ public int tableLength(int t) {
* @param v Value
*/
public void tableSet(int t, int i, float v) {
- if (!isRunning) return;
- mutex.lock();
+// if (!isRunning) return;
+// mutex.lock();
csound.TableSet(t, i, v);
- mutex.unlock();
+// mutex.unlock();
}
/**
View
2  src/csoundo/Engine.java
@@ -86,7 +86,7 @@ private void csoundPerf() {
isRunning = true;
perfThread = new CsoundPerformanceThread(csound_p);
perfThread.Play();
- mutex = new Mutex();
+ //mutex = new Mutex();
}
}
}
View
2  src/csoundo/Mutex.java
@@ -36,7 +36,7 @@
SWIGTYPE_p_void m; // Mutex
private int locks = 0; // Number of active locks
- private boolean useLocks = true; // Use locks?
+ private boolean useLocks = false; // Use locks?
public Mutex() {
m = csnd.csoundCreateMutex(1);
Please sign in to comment.
Something went wrong with that request. Please try again.