Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

removed csoundCompile() from perf and put it in class contructor, add…

…ed performKsmps() method
  • Loading branch information...
commit 4c790b78ccfc9b1a14ec32312cdfa4981c00c249 1 parent 049eaec
@rorywalsh rorywalsh authored
View
17 csoundo/examples/DrawWaveform/AndroidManifest.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package=""
+ android:versionCode="1"
+ android:versionName="1.0">
+ <uses-sdk android:minSdkVersion="10" />
+ <application android:label=""
+ android:icon="@drawable/icon"
+ android:debuggable="true">
+ <activity android:name="">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+</manifest>
View
87 csoundo/examples/DrawWaveform/DrawWaveform.pde
@@ -0,0 +1,87 @@
+/**
+ * Continuous Lines.
+ *
+ * Click and drag the mouse to draw a line.
+ */
+import csoundo.*;
+
+Csoundo cs;
+
+float[] points;
+float prevY = height/2;
+float prevX = 0;
+int tableNumber = 1;
+int tableLength = 1024;
+
+
+void setup() {
+ //Android Mode (comment out either)
+ cs = new Csoundo(this, super.getApplicationContext());
+ //Java Mode
+ //cs = new Csoundo(this, "DrawWaveform.csd");
+ cs.run();
+ points = new float[1024];
+ for(int i=0;i<1024;i++)
+ points[i]=0;
+ size(640, 360);
+ background(255);
+ fillPointsArray();
+ drawPoints();
+ noLoop();
+
+}
+
+void draw() {
+ background(255);
+ fill(255);
+ rect(0, 0, width, height);
+ drawPoints();
+}
+
+void mouseDragged(){
+ float index = (float(mouseX)/float(width))*tableLength;
+ float amp = (float(mouseY)/float(height)*-2)+1;
+ if(index>5 && index<(tableLength-5)){
+ points[int(index)-1] = amp;
+ cs.tableSet(1, int(index)-1, amp);
+ points[int(index)-2] = amp;
+ cs.tableSet(1, int(index)-2, amp);
+ points[int(index)-3] = amp;
+ cs.tableSet(1, int(index)-3, amp);
+ points[int(index)-4] = amp;
+ cs.tableSet(1, int(index)-4, amp);
+ points[int(index)] = amp;
+ cs.tableSet(1, int(index), amp);
+ points[int(index)+1] = amp;
+ cs.tableSet(1, int(index)+1, amp);
+ points[int(index)+2] = amp;
+ cs.tableSet(1, int(index)+2, amp);
+ points[int(index)+3] = amp;
+ cs.tableSet(1, int(index)+3, amp);
+ points[int(index)+4] = amp;
+ cs.tableSet(1, int(index)+4, amp);
+ }
+ redraw();
+}
+
+void fillPointsArray() {
+ for(int i=0;i<tableLength;i++)
+ points[i] = cs.tableGet(tableNumber, i);
+}
+
+void drawPoints(){
+ strokeWeight(1);
+ //fill(255, 0, 0);
+ float amp;
+ float index;
+ for(int i = 0; i < tableLength; i++)
+ {
+ amp = height-(((points[i]+1)/2)*height);
+ index = (float(i)/float(tableLength))*width;
+ line(prevX, prevY, index, amp);
+ prevX = index;
+ prevY = amp;
+ }
+}
+
+
View
23 csoundo/examples/DrawWaveform/data/DrawWaveform.csd
@@ -0,0 +1,23 @@
+<CsoundSynthesizer>
+<CsOptions>
+-o dac -d -+msg_color=0 -m0 -b512
+</CsOptions>
+<CsInstruments>
+sr = 44100
+kr = 4410
+ksmps = 10
+nchnls = 2
+0dbfs = 1
+
+instr 1
+a1 oscil .5, 400, 1
+outs a1, a1
+endin
+
+</CsInstruments>
+<CsScore>
+f1 0 1024 10 1
+
+i 1 0 [60 * 60] ; Turn on for 1 hour
+</CsScore>
+</CsoundSynthesizer>
View
2  csoundo/examples/DrawWaveform/sketch.properties
@@ -0,0 +1,2 @@
+mode.id=processing.mode.java.JavaMode
+mode=Java
View
BIN  csoundo/library/Csoundo.jar
Binary file not shown
View
12 csoundo/src/csoundo/CallbackWrapper.java
@@ -1,5 +1,7 @@
package csoundo;
+import processing.core.*;
+
import csnd.*;
import java.io.*;
import java.util.*;
@@ -8,26 +10,30 @@
public class CallbackWrapper extends CsoundCallbackWrapper{
public Csound csound;
public MessageQueue messageQueue;
+
public CallbackWrapper(Csound csnd){
super(csnd);
+ //System.out.print(this.getClass().getSuperclass().getName()+"\n");
csound = csnd;
messageQueue = new MessageQueue();
}
+
public int YieldCallback()
{
- //update channels
+ //update Csound channels
for(int i=0;i<messageQueue.getNumberOfMessagesInChannelQueue();i++)
csound.SetChannel(messageQueue.getMessageFromChannelQueue(i).channelName,
messageQueue.getMessageFromChannelQueue(i).channelData);
- //update table values
+ //update Csound table values
for(int i=0;i<messageQueue.getNumberOfMessagesInTableQueue();i++)
csound.TableSet(messageQueue.getMessageFromTableQueue(i).tableNumber,
messageQueue.getMessageFromTableQueue(i).xVal,
messageQueue.getMessageFromTableQueue(i).yVal);
+ csound.TableGet(1, 1);
//flush messages from queues
messageQueue.flushMessagesFromTableQueue();
@@ -36,4 +42,6 @@ public int YieldCallback()
}
+
+
}
View
87 csoundo/src/csoundo/Csoundo.java
@@ -71,6 +71,8 @@
//Android Mode Constructor
public Csoundo(PApplet theParent, Context context) {
+ csnd.csoundInitialize(null, null,
+ csnd.CSOUNDINIT_NO_SIGNAL_HANDLER);
myParent = theParent;
welcome();
csound = new AndroidCsound();
@@ -79,10 +81,25 @@ public Csoundo(PApplet theParent, Context context) {
csd = createTempFile(getResourceFileAsString(0x7f040000, context), context).getAbsolutePath().toLowerCase();
androidMode=true;
messageQueue = new MessageQueue();
+
+ csoundFile = new CsoundFile();
+ csoundFile.setCSD(fileToString(csd));
+ csoundFile.exportForPerformance();
+ csound.PreCompile();
+ csoundFile.setCommand(options + "\\" +csd);
+ if(csound.Compile(csd)==0)
+ compiledOK = true;
+ else
+ compiledOK = false;
+
+ checkCompileStatus(compiledOK);
+
}
//Java Mode Constructor
public Csoundo(PApplet theParent, String _csd) {
+ csnd.csoundInitialize(null, null,
+ csnd.CSOUNDINIT_NO_SIGNAL_HANDLER);
myParent = theParent;
welcome();
messageQueue = new MessageQueue();
@@ -91,8 +108,18 @@ public Csoundo(PApplet theParent, String _csd) {
csound = new Csound();
callbackWrapper = new CallbackWrapper(csound);
callbackWrapper.SetYieldCallback();
+
+ csoundFile = new CsoundFile();
+ csoundFile.setCSD(fileToString(csd));
+ csoundFile.exportForPerformance();
+ if(csound.Compile(csd)==0)
+ compiledOK = true;
+ else
+ compiledOK = false;
+
+ checkCompileStatus(compiledOK);
}
-
+
//Method for Android, locates .csd file in .apk and returns it as a string.
protected String getResourceFileAsString(int resId, Context context) {
StringBuilder str = new StringBuilder();
@@ -128,7 +155,15 @@ protected File createTempFile(String csd, Context context) {
return f;
}
-
+
+ public int performKsmps(){
+ return csound.PerformKsmps();
+ }
+
+ public void stopPerformKsmps(){
+ csound.Stop();
+ }
+
public void dispose() {
System.out.println("Csound dispose");
// NOTE:
@@ -142,39 +177,6 @@ public void dispose() {
}
private void csoundPerf() {
- csnd.csoundInitialize(null, null,
- csnd.CSOUNDINIT_NO_SIGNAL_HANDLER);
- csoundFile = new CsoundFile();
- csoundFile.setCSD(fileToString(csd));
-
- if(androidMode){
-
- csoundFile.exportForPerformance();
- csound.PreCompile();
- csoundFile.setCommand(options + "\\" +csd);
- if(csound.Compile(csd)==0){
- compiledOK = true;
- callbackWrapper = new CallbackWrapper(csound);
- }
- else
- compiledOK = false;
- }
- else{
- csoundFile.exportForPerformance();
- if(csound.Compile(csd)==0){
- compiledOK = true;
- callbackWrapper = new CallbackWrapper(csound);
- }
- else
- compiledOK = false;
-
- }
- if(compiledOK)
- System.out.println("Csound compiled your file without error");
- else
- System.out.println("Csound failed to compile your file");
-
-
if (compiledOK) {
isRunning = true;
perfThread = new CsoundPerformanceThread(csound.GetCsound());
@@ -384,10 +386,13 @@ public float sr() {
* @return Csound table value
*/
+ //this should only be called when performKsmps is finished a cycle
public float tableGet(int t, int i) {
if (!compiledOK) return 0;
return (float) csound.TableGet(t, i);
}
+
+
/**
* Return the length of a Csound table.
@@ -395,21 +400,29 @@ public float tableGet(int t, int i) {
* @param t Table number
* @return Csound table length
*/
+ //as above
public int tableLength(int t) {
if(!compiledOK) return -99999;
return csound.TableLength(t);
}
/**
- * Sets the value of a Csound table at a specif index.
+ * Writes table changes to a queue, they will be sent to Csound at a safe time.
*
* @param t Table number
* @param i Index
* @param v Value
*/
- public void tableSet(int t, int i, float v) {
+ public void tableSet(int t, int i, float v){
if(compiledOK)
callbackWrapper.messageQueue.addMessageToTableQueue(t, i, v);
}
+
+ private void checkCompileStatus(boolean status){
+ if(status)
+ System.out.println("Csound compiled your file without error");
+ else
+ System.out.println("Csound failed to compile your file");
+ }
}
View
9 csoundo/src/csoundo/MessageQueue.java
@@ -35,13 +35,14 @@
*/
public class MessageQueue {
private String csd;
+ int numberOfTablesToRetreive;
private Vector<ChannelMessage> channelMessageQueue;
private Vector<TableMessage> tableMessageQueue;
public MessageQueue(){
- channelMessageQueue = new Vector<ChannelMessage>();
- tableMessageQueue = new Vector<TableMessage>();
+ channelMessageQueue = new Vector<ChannelMessage>();
+ tableMessageQueue = new Vector<TableMessage>();
}
public void addMessageToChannelQueue(String _chan, double _val){
@@ -52,6 +53,10 @@ public void addMessageToTableQueue(int _tableNumber, int _index, double _amp){
tableMessageQueue.addElement(new TableMessage(_tableNumber, _index, _amp));
}
+ public void fillArrayWithTablePoints(int table, float[] array){
+
+ }
+
public ChannelMessage getMessageFromChannelQueue(int index){
return channelMessageQueue.get(index);
}
Please sign in to comment.
Something went wrong with that request. Please try again.