| Peter Brinkmann is using the Csound Java API for audio in his JReality
mathematics visualizer. I worked with him a bit on this. Peter's main
problem was getting Java access to Csound's audio input and output
buffers. it is not intuitive, but it does work.
You can download JReality sources from here:
http://www3.math.tu-berlin.de/jreality/index.php?article_id=4
The CsoundNode.java file contains the code that accesses the spout
buffer. I think similar code woud work for channels. I append the
entire file. This code may not be quite up to date, but I think you
will get the basic idea. SWIG encapsulates MYFLT * in a
SWIGTYPE_p_double from which data can be copied into a
CsoundMYFLTArray, which provides samplewise access to the data.
Regards,
Mike
package de.jreality.audio.csound;
import java.io.IOException;
import csnd.CppSound;
import csnd.Csound;
import csnd.CsoundFile;
import csnd.CsoundMYFLTArray;
import csnd.SWIGTYPE_p_double;
import de.jreality.audio.RingBuffer;
import de.jreality.audio.RingBufferSource;
import de.jreality.util.Input;
/**
* Audio source that uses Csound as its synthesis engine.
*
* @author brinkman
*
*/
public class CsoundNode extends RingBufferSource {
private CppSound csnd = new CppSound();
private CsoundFile csf = csnd.getCsoundFile();
private CsoundMYFLTArray auxBuffer;
private SWIGTYPE_p_double csOutBuffer;
private float cumulativeBuffer[];
private int ksmps;
private int nchnls;
private int bufSize;
private float scale;
public CsoundNode(String name, Input csd) throws IOException {
super(name);
csf.setCSD(csd.getContentAsString());
initFields();
}
public CsoundNode(String name, Input orc, Input score) throws IOException {
super(name);
csf.setOrchestra(orc.getContentAsString());
csf.setScore(score.getContentAsString());
initFields();
}
private void initFields() {
csf.setCommand("-n -d foo.orc foo.sco");
csf.exportForPerformance();
csnd.compile();
ksmps = csnd.GetKsmps();
nchnls = csnd.GetNchnls();
bufSize = ksmps*nchnls;
sampleRate = (int) csnd.GetSr();
scale = (float) csnd.Get0dBFS();
ringBuffer = new RingBuffer(sampleRate);
cumulativeBuffer = new float[ksmps];
csOutBuffer = csnd.GetSpout();
auxBuffer = new CsoundMYFLTArray(bufSize); // too many buffers...
}
public Csound getCsound() {
return csnd;
}
@Override
protected void reset() {
csnd.RewindScore();
}
@Override
protected void writeSamples(int n) {
for(int i=0; i wrote:
> There does not seem to be any documentation at all!
>
> 1: How do I use the external equivalent of
> setchn aout, "audio"
> ie my orchestra does that line but how do I get the audio vector
> into Java? I tried a few things but they did not work
>
> 2: My other orchestra wants to say
> aout chani p4
> but how to I put data into the channel in Java? I tried
> csound.ChanOAGet(audio,1);
> but that complains about the type of the first argument. I had a
> vector of floats; possiby I need a SWIGTYPE_p_double arg0 whatever
> that is.
>
> I am suspecting that no one has really used the API
>
> ==John ffitch
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus
> on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now. http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel
>
--
Michael Gogins
Irreducible Productions
http://www.michael-gogins.com
Michael dot Gogins at gmail dot com
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net |