Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Mutex seems to be stable now.

  • Loading branch information...
commit 49f31d592e8a090835a012254d72f672a6969527 1 parent 7c0ff2b
@jacobjoaquin authored
Showing with 17 additions and 20 deletions.
  1. +5 −3 examples/devScratchPad/devScratchPad.pde
  2. +12 −17 src/csoundo/Csoundo.java
View
8 examples/devScratchPad/devScratchPad.pde
@@ -6,7 +6,7 @@ void setup() {
size(740, 480);
frameRate(30);
smooth();
- noLoop();
+// noLoop();
cs = new Csoundo(this, sketchPath("data/synth.csd"));
cs.run();
@@ -21,16 +21,18 @@ void draw() {
fill(255, 180);
println("before");
- float size = pow(2, 10);
+ float size = pow(2, 16);
println(size);
cs.event("f 20 0 " + size + " 10 0");
println("after");
int length = cs.tableLength(20);
for (int i = 0; i < length; i++) {
- cs.tableSet(20, length - i - 1, sin(2 * PI * (float) i * 8.0 / (float) length));
+ cs.tableSet(20, length - i - 1, sin(2 * PI * (float) i * (random(0.3) + 3.0) / (float) length));
float v = cs.tableGet(20, length - i - 1);
ellipse((float) i / (float) length * (float) width,
height / 2.0 + height / 2.0 * v, 1, 1);
}
+// float v = cs.tableGet(20, (length - 1));
+// print("done " + v);
}
View
29 src/csoundo/Csoundo.java
@@ -48,6 +48,8 @@
public CsoundPerformanceThread perfThread;
public SWIGTYPE_p_CSOUND_ csound_p;
+ SWIGTYPE_p_void mutex;
+
/**
* The Csoundo onstructor, usually called in the setup() method in your
* sketch to initialize and start the library.
@@ -128,6 +130,7 @@ private void cppSoundPerf() {
isRunning = true;
perfThread = new CsoundPerformanceThread(csound_p);
perfThread.Play();
+ mutex = csnd.csoundCreateMutex(1);
}
}
}
@@ -164,12 +167,10 @@ public void event(String s) {
if (isRunning) {
if (useThreads) {
- SWIGTYPE_p_void thread = csnd.csoundCreateMutex(1);
- csnd.csoundLockMutex(thread);
+ csnd.csoundLockMutex(mutex);
perfThread.InputMessage(s);
- perfThread.FlushMessageQueue();
- csnd.csoundUnlockMutex(thread);
- csnd.csoundDestroyMutex(thread);
+// perfThread.FlushMessageQueue();
+ csnd.csoundUnlockMutex(mutex);
} else {
perfThread.InputMessage(s);
}
@@ -268,11 +269,9 @@ public float sr() {
public float tableGet(int t, int i) {
if (isRunning) {
if (useThreads) {
- SWIGTYPE_p_void thread = csnd.csoundCreateMutex(1);
- csnd.csoundLockMutex(thread);
+ csnd.csoundLockMutex(mutex);
float value = csnd.csoundTableGet(csound_p, t, i);
- csnd.csoundUnlockMutex(thread);
- csnd.csoundDestroyMutex(thread);
+ csnd.csoundUnlockMutex(mutex);
return value;
} else {
return csnd.csoundTableGet(csound_p, t, i);
@@ -291,11 +290,9 @@ public float tableGet(int t, int i) {
public int tableLength(int t) {
if (isRunning) {
if (useThreads) {
- SWIGTYPE_p_void thread = csnd.csoundCreateMutex(1);
- csnd.csoundLockMutex(thread);
+ csnd.csoundLockMutex(mutex);
int value = csnd.csoundTableLength(csound_p, t);
- csnd.csoundUnlockMutex(thread);
- csnd.csoundDestroyMutex(thread);
+ csnd.csoundUnlockMutex(mutex);
return value;
} else {
return csnd.csoundTableLength(csound_p, t);
@@ -315,11 +312,9 @@ public int tableLength(int t) {
public void tableSet(int t, int i, float v) {
if (isRunning) {
if (useThreads) {
- SWIGTYPE_p_void thread = csnd.csoundCreateMutex(1);
- csnd.csoundLockMutex(thread);
+ csnd.csoundLockMutex(mutex);
csnd.csoundTableSet(csound_p, t, i, v);
- csnd.csoundUnlockMutex(thread);
- csnd.csoundDestroyMutex(thread);
+ csnd.csoundUnlockMutex(mutex);
} else {
csnd.csoundTableSet(csound_p, t, i, v);
}
Please sign in to comment.
Something went wrong with that request. Please try again.