[Csnd] Re: Re: csnd.jar and Processing-1.0.1
Date | 2009-01-03 10:37 |
From | victor |
Subject | [Csnd] Re: Re: csnd.jar and Processing-1.0.1 |
Jean-Pierre,
that would do a fine article for the Csound
Journal!
Thanks for the example
Victor
|
Date | 2009-01-03 20:14 |
From | jhearon |
Subject | [Csnd] Re: csnd.jar and Processing-1.0.1 |
Yes, thanks. That's an interesting thread class, and I agree a Journal article would be a good idea. The technology has changed since the last Jp article, so it would good to learn more about new integration ideas with Csound, Java, Processing, Jogl, Eclipse, NetBeans, etc. I hacked a bit and got the first example you posted to compile in pure Processing (no static etc.), but can get no sound yet. The compiler stops at "SECTION 1:" or just before p-fields are rendered. I know my .csd is working for Processing. compiler output: ... Csound version 5.10 beta (double samples) Dec 30 2008 displays suppressed 0dBFS level = 32768.0 orch now loaded audio buffered in 1024 sample-frame blocks ALSA output: total buffer size: 16384, period size: 1024 writing 4096-byte blks of shorts to dac:hw:0,1 SECTION 1: [stops here] ------ I tried adding the String or path to my .csd in cs.Perform in the run method below, but that did not seem to allow the compiler to finish the performance. public void run() { if ( cs != null ) { try { cleanFinished = false; cs.Perform(aCSDFile); Will look at the second example posted, and see if I can figure out how to make sound. regards, ============ //Processing sketchbook file import csnd.*; Csound csoundInstance = new Csound(); void setup () { size(200, 200); if ( csoundInstance == null ) { csnd.csoundInitialize(null, null, csnd.CSOUNDINIT_NO_SIGNAL_HANDLER); csoundInstance = new Csound(); } int rc = csoundInstance.Compile("/home/JCH/sketchbook/CsndTest/Sine.csd"); if ( rc == 0 ) { CsoundThread csoundPerformanceThread = new CsoundThread(); csoundPerformanceThread.startCsound(); // -> at this point a Java thread is launched and the // Processing draw is continuing } } void draw() { background(0); } class CsoundThread extends Thread { private CsoundThread singleton; private Csound cs; private boolean running = false; private boolean cleanFinished = false; String aCSDFile = "/home/JCH/sketchbook/CsndTest/Sine.csd"; public CsoundThread create( Csound aCs ) { if ( singleton != null ) { if ( singleton.isRunning() == true ) { stopCsound(); } } singleton = new CsoundThread(); singleton.init( aCs ); return singleton; } /* * ------------------------------------------------------------------ */ private void init( Csound aCs ) { cs = aCs; } public int compile( String aCSDFile ) { if ( cs == null ) { return -1; } else { cs.Reset(); return cs.Compile(aCSDFile); } } public void stopCsound() { if ( cs != null ) { cs.Stop(); double timeOut = System.currentTimeMillis(); while( singleton.isCleanFinished() == false ) { timeOut = System.currentTimeMillis() - timeOut; if ( timeOut >= 5000 ) { break; } Thread.yield(); } } } public void startCsound() { running = true; start(); } public void run() { if ( cs != null ) { try { cleanFinished = false; cs.Perform(); running = false; cs.Cleanup(); cs.Reset(); cleanFinished = true; } catch( Exception ex ) { ex.printStackTrace(); } } } /** * @return Returns the running. */ public synchronized boolean isRunning() { return running; } /** * @param running The running to set. */ public synchronized void setRunning( boolean running ) { this.running = running; } public Csound getCsound() { return cs; } public boolean isCleanFinished() { return cleanFinished; } } -- View this message in context: http://www.nabble.com/csnd.jar-and-Processing-1.0.1-tp21256228p21268846.html Sent from the Csound - General mailing list archive at Nabble.com. |
Date | 2009-01-03 21:30 |
From | jhearon |
Subject | [Csnd] Re: csnd.jar and Processing-1.0.1 |
...sorry. Answering my own reply. Problem seems to be in run method of thread class where 'cs' is null, and thus cs.Perform does not happen. Not sure where cs becomes null, since it seems to make it thru the compile method of CsoundThread class o.k. ... public void run() { //if ( cs == null ) { //java.lang.System.out.println( "cs is NULL" ); //} if ( cs != null ) { try { cleanFinished = false; cs.Perform(); running = false; cs.Cleanup(); cs.Reset(); cleanFinished = true; } catch( Exception ex ) { ex.printStackTrace(); } } } -- View this message in context: http://www.nabble.com/csnd.jar-and-Processing-1.0.1-tp21256228p21269649.html Sent from the Csound - General mailing list archive at Nabble.com. |