Getting CSound to work with Java is a tedious task since there is no clear documentation on the process in the wild. A quick search on Google and CSound blogs will summon numerous papers and articles that reference a Java interface for CSound but do not elaborate on the process of setting it up. Through hours of tedious searching and cross-referencing, I have finally figured out how to compile and manipulate CSound through Java. It's actually pretty simple, once you know what is required:
1. Download the latest linux version of CSound from the CSound sourceforge and untar. http://csound.sourceforge.net/#Downloads
2. Locate the csnd.jar file within the untarred folder. This should be in linux_d32/opc/frontends.
3. Add the csnd.jar file to your Java project's build path. In the Eclipse IDE, right-click your project and select the Java Build Path. Add the JAR by clicking "Add External JARs..."
4. Finished. You should now be able to compile and work with CSound using Java.
The CSound C API [PDF] will serve as a base reference, however, because the Java interface for CSound is generated automatically from C with SWIG, many methods will not work as originally intended. I have found Java Slider Demo extremely helpful in laying out the basic Java CSound code necessary in creating a working project.
Here is some code for getting started. The code takes a CSound.csd, compiles it, and performs it from an audio device. You may have to tweak the command switches for your OS. The following code assumes Mac OS X.
public static void main(String[] args) {
csound = new Csound();
cargs = new CsoundArgVList();
cargs.Append("csound");
//CSound compile options
cargs.Append("-d"); //supress displays
cargs.Append("-odac"); //realtime audio
cargs.Append("-M0"); //enable midi
//.csd file to be compiled
cargs.Append("miditest.csd");
//Compile
int result = csound.Compile(cargs.argc(), cargs.argv());
//if result returns 0, then success and perform. if result returns -1, fails.
if(result == 0) {
csound.Perform();
}
}
I am currently working on a modular synth using Java and CSound with success with MIDI and Swing GUI manipulation of CSound control rates. Most of the method calls I have used have come from the Java Slider Example, which is really all I need for my project. I'd be interested if anyone finds out more about any other working Java CSound methods.
Happy CSounding!



Java Examples
I would recommend looking at code from both my software blue (csounds.com/stevenyi/blue) as well as Jean-Pierre Lemoine's AVSynthesis (http://avsynthesis.blogspot.com/). I think both of our projects implemented our own Runnables or Threads to call Csound's performKsmps method as well as do additional processing between calls in the main performance loop.
Good luck!
steven