[Csnd] Csound audio output in Java [Was: Csound bus opcodes]
Date | 2009-11-27 21:42 |
From | Michael Gogins |
Subject | [Csnd] Csound audio output in Java [Was: Csound bus opcodes] |
I tried responding to this a day or so ago and didn't see it go through to the list, perhaps because of the attachment, which I now omit. If you want to see Peter Brinkmann's code you can look at it in jReality subversion. My previous text follows. II have mentioned before that Peter Brinkmann's jReality package, written in Java, for mathematics visualization and sonification can use Csound to attach sounds to visual objects. Here is Peter's source code, which I helped him to write, from jReality SVN for sending audio output from Csound to the audio backend of jReality. I have heard this code run. I imagine similar code would work in Lua, and I may verify that if I have time. The key lines are as follows, with my comments added: // SWIG-generated wrapper for an array of MYFLT. spout = new CsoundMYFLTArray(); // Set the SWIG wrapper for Csound's spout buffer pointer to the MYFLT array wrapper. The "Ptr" is a SWIG wrapper for a C MYFLT * pointer. // In other words, in SWIG-generated code you never see a truly raw pointer. // THIS IS PROBABLY YOUR MISSING STEP, GENTLEMEN. spout.SetPtr(csnd.GetSpout()); // Create a native host language buffer for sending monophonic audio to the backend. cumulativeBuffer = new float[ksmps]; // Call on Csound to synthesize ksmps worth of audio. // ANOTHER POSSIBLE "GOTCHA": MUST USE csoundPerformKsmps NOT csoundPerformBuffer. csnd.PerformKsmps(); // Transfer audio, framewise, from the SWIG wrapper for spout to my native buffer. // I.e., j is the SAMPLE FRAME index. for(int j=0; j |
Date | 2009-11-27 22:27 |
From | Victor Lazzarini |
Subject | [Csnd] Re: Csound audio output in Java [Was: Csound bus opcodes] |
Michael, I think a problem mentioned here was to access audio channels in the bus, rather than spout; I can see that a similar code could be used, but the stumbling block was how to obtain the pointer to the channel bus audio signal (via csoundGetChannelPtr() ). Could you provide a similar example to do this? Victor On 27 Nov 2009, at 21:42, Michael Gogins wrote: > I tried responding to this a day or so ago and didn't see it go > through to the list, perhaps because of the attachment, which I now > omit. If you want to see Peter Brinkmann's code you can look at it in > jReality subversion. My previous text follows. > > II have mentioned before that Peter Brinkmann's jReality package, > written in Java, for mathematics visualization and sonification can > use Csound to attach sounds to visual objects. Here is Peter's source > code, which I helped him to write, from jReality SVN for sending audio > output from Csound to the audio backend of jReality. I have heard this > code run. I imagine similar code would work in Lua, and I may verify > that if I have time. > > The key lines are as follows, with my comments added: > > // SWIG-generated wrapper for an array of MYFLT. > spout = new CsoundMYFLTArray(); > // Set the SWIG wrapper for Csound's spout buffer pointer to the MYFLT > array wrapper. The "Ptr" is a SWIG wrapper for a C MYFLT * pointer. > // In other words, in SWIG-generated code you never see a truly raw > pointer. > // THIS IS PROBABLY YOUR MISSING STEP, GENTLEMEN. > spout.SetPtr(csnd.GetSpout()); > // Create a native host language buffer for sending monophonic audio > to the backend. > cumulativeBuffer = new float[ksmps]; > > // Call on Csound to synthesize ksmps worth of audio. > // ANOTHER POSSIBLE "GOTCHA": MUST USE csoundPerformKsmps NOT > csoundPerformBuffer. > csnd.PerformKsmps(); > // Transfer audio, framewise, from the SWIG wrapper for spout to my > native buffer. > // I.e., j is the SAMPLE FRAME index. > for(int j=0; j |
Date | 2009-11-28 00:08 |
From | Michael Gogins |
Subject | [Csnd] Re: Re: Csound audio output in Java [Was: Csound bus opcodes] |
I can't run Java with Csound on my computer up here on the farm, but I have examined the Csound API and the Java interface and I don't see how to do it for the busses. It would not be hard to fix. The problem is that csoundGetChannelPtr takes a pointer to a pointer in the argument, and returns the channel pointer in that. We need to either (a) provide a function that returns the channel pointer directly, just like getSpout, or (b) write a typemap or convenience function for the Java interface that will dereference the pointer to the pointer and return a SWIGTYPE_p_double instead of a SWIGTYPE_p_p_double; SWIGTYPE_p_double could be used in exactly the same way as the return value from getSpout. Hope this helps, Mike On 11/27/09, Victor Lazzarini |
Date | 2009-11-28 08:22 |
From | Victor Lazzarini |
Subject | [Csnd] Re: Re: Re: Csound audio output in Java [Was: Csound bus opcodes] |
I guess that was the problem. There's some extra code needed. Victor On 28 Nov 2009, at 00:08, Michael Gogins wrote: > I can't run Java with Csound on my computer up here on the farm, but I > have examined the Csound API and the Java interface and I don't see > how to do it for the busses. > > It would not be hard to fix. The problem is that csoundGetChannelPtr > takes a pointer to a pointer in the argument, and returns the channel > pointer in that. We need to either (a) provide a function that returns > the channel pointer directly, just like getSpout, or (b) write a > typemap or convenience function for the Java interface that will > dereference the pointer to the pointer and return a SWIGTYPE_p_double > instead of a SWIGTYPE_p_p_double; SWIGTYPE_p_double could be used in > exactly the same way as the return value from getSpout. > > Hope this helps, > Mike > > On 11/27/09, Victor Lazzarini |
Date | 2009-11-30 18:05 |
From | jhearon |
Subject | Re: [Cs-dev] Csound audio output in Java [Was: Csound bus opcodes] |
Michael Gogins-2 wrote: > > ... > // Set the SWIG wrapper for Csound's spout buffer pointer to the MYFLT > array wrapper. The "Ptr" is a SWIG wrapper for a C MYFLT * pointer. > // In other words, in SWIG-generated code you never see a truly raw > pointer. > // THIS IS PROBABLY YOUR MISSING STEP, GENTLEMEN. > spout.SetPtr(csnd.GetSpout()); > ... > Hi Mike, I took a look at the JReality code and looks interesting. I'm confused about CsoundMYFLTArray.java methods SetPtr and GePtr which I can't find in Csound C code src. Could you possibly offer a brief explanation of when to use each? For ex. it seems like SetPtr would be used with spin, and GetPtr with spout, but seems that's not the case. Also am confused about int ndx param on GetPtr. What is the indx for when using GetPtr? spout.SetPtr(csnd.GetSpout()); SWIGTYPE_p_double myspout = spout.GetPtr(0); ---from CsoundMYFLTArray.java--- public SWIGTYPE_p_double GetPtr(int ndx) { long cPtr = csndJNI.CsoundMYFLTArray_GetPtr__SWIG_1(swigCPtr, this, ndx); return (cPtr == 0) ? null : new SWIGTYPE_p_double(cPtr, false); } public void SetPtr(SWIGTYPE_p_double ptr) { csndJNI.CsoundMYFLTArray_SetPtr(swigCPtr, this, SWIGTYPE_p_double.getCPtr(ptr)); } -- View this message in context: http://old.nabble.com/Csound-audio-output-in-Java--Was%3A-Csound-bus-opcodes--tp26548109p26579157.html Sent from the Csound - Dev mailing list archive at Nabble.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 |
Date | 2009-11-30 18:18 |
From | Michael Gogins |
Subject | Re: [Cs-dev] Csound audio output in Java [Was: Csound bus opcodes] |
GetPtr and SetPtr are generated by SWIG and do not appear in our sources. You use SetPtr to set a C pointer into an object, and GetPtr to get a C pointer from an object. The CsoundMYFLTArray object begins with no pointer. getSpout returns a pointer that we set into the CsoundMYFLTArray object, which enables to access the elements of the array pointed at by the pointer from Java instead if needing to to it in C. Hope this helps, Mike On 11/30/09, jhearon |
Date | 2009-12-01 22:29 |
From | jhearon |
Subject | Re: [Cs-dev] Csound audio output in Java [Was: Csound bus opcodes] |
Hi, I'm not sure if this is helpful, but I cannot seem to get Java to run past a line which has GetValue(int ndx). I've tried seeing what's happening in a Debugger but it just jumps to the end with "User Program Finished", with no crash or anything. It just won't excude the code and steps out to the end of the program. CsoundMYFLTArray myspout = new CsoundMYFLTArray(); double test = myspout.GetValue(0); I've tried a few other methods from CsoundMYFLTArray.java such as SetValue and GetString and they work, but for some reason GetValue is not working for me on csound5.11. I tried using the code you suggested from JReality with the vector etc. and it jumps out of the loop and skips to the end of the program. If I place GetValue before PreCompile() or Compile() csound returns a segfault. If I place it after Compile(), the .csd will compile but the rest of the java code is skipped. A bit odd. -- View this message in context: http://old.nabble.com/Csound-audio-output-in-Java--Was%3A-Csound-bus-opcodes--tp26548109p26600180.html Sent from the Csound - Dev mailing list archive at Nabble.com. ------------------------------------------------------------------------------ Join us December 9, 2009 for the Red Hat Virtual Experience, a free event focused on virtualization and cloud computing. Attend in-depth sessions from your desk. Your couch. Anywhere. http://p.sf.net/sfu/redhat-sfdev2dev _______________________________________________ Csound-devel mailing list Csound-devel@lists.sourceforge.net |
Date | 2009-12-02 03:27 |
From | Michael Gogins |
Subject | Re: [Cs-dev] Csound audio output in Java [Was: Csound bus opcodes] |
Attachments | None None |
Post your complete code. I don't see where you set the spout pointer into your buffer. Without that your code might throw an exception. This could cause the skip in the debugger. MKG from cell phone On Dec 1, 2009 5:30 PM, "jhearon" <j_hearon@hotmail.com> wrote: |
Date | 2009-12-02 21:40 |
From | jhearon |
Subject | Re: [Cs-dev] Csound audio output in Java [Was: Csound bus opcodes] |
Michael Gogins-2 wrote: > > Post your complete code. I don't see where you set the spout pointer into > your buffer. > > Hi, I figured out the problem which was the spout pointer needs to be set after the call to Compile or GetValue with step out to the end of the code. I'll keep working on this. I haven't used spout much because for me there hasn't been much I needed to do with a buffer full of audio data. I mean that's normally why I would use Csound, to play the audio since it has all the plumbing to libsndfile and the audio card; but I believe it was Victor who posted a neat Spout/Spin example in cpp a while back where you use two .csd files--one to play and one to listen to show that spout and spin are working, and I'm trying to get that one working in Java. regards, -- View this message in context: http://old.nabble.com/Csound-audio-output-in-Java--Was%3A-Csound-bus-opcodes--tp26548109p26616953.html Sent from the Csound - Dev mailing list archive at Nabble.com. ------------------------------------------------------------------------------ Join us December 9, 2009 for the Red Hat Virtual Experience, a free event focused on virtualization and cloud computing. Attend in-depth sessions from your desk. Your couch. Anywhere. http://p.sf.net/sfu/redhat-sfdev2dev _______________________________________________ Csound-devel mailing list Csound-devel@lists.sourceforge.net |
Date | 2009-12-02 21:49 |
From | Victor Lazzarini |
Subject | Re: [Cs-dev] Csound audio output in Java [Was: Csound bus opcodes] |
spout can be used to feed a display (for instance an oscilloscope), if you need. Victor On 2 Dec 2009, at 21:40, jhearon wrote: > > > > Michael Gogins-2 wrote: >> >> Post your complete code. I don't see where you set the spout >> pointer into >> your buffer. >> >> > > Hi, > I figured out the problem which was the spout pointer needs to be > set after > the call to Compile or GetValue with step out to the end of the code. > > I'll keep working on this. I haven't used spout much because for me > there > hasn't been much I needed to do with a buffer full of audio data. I > mean > that's normally why I would use Csound, to play the audio since it > has all > the plumbing to libsndfile and the audio card; but I believe it was > Victor > who posted a neat Spout/Spin example in cpp a while back where you > use two > .csd files--one to play and one to listen to show that spout and > spin are > working, and I'm trying to get that one working in Java. > > regards, > -- > View this message in context: http://old.nabble.com/Csound-audio-output-in-Java--Was%3A-Csound-bus-opcodes--tp26548109p26616953.html > Sent from the Csound - Dev mailing list archive at Nabble.com. > > > ------------------------------------------------------------------------------ > Join us December 9, 2009 for the Red Hat Virtual Experience, > a free event focused on virtualization and cloud computing. > Attend in-depth sessions from your desk. Your couch. Anywhere. > http://p.sf.net/sfu/redhat-sfdev2dev > _______________________________________________ > Csound-devel mailing list > Csound-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/csound-devel ------------------------------------------------------------------------------ Join us December 9, 2009 for the Red Hat Virtual Experience, a free event focused on virtualization and cloud computing. Attend in-depth sessions from your desk. Your couch. Anywhere. http://p.sf.net/sfu/redhat-sfdev2dev _______________________________________________ Csound-devel mailing list Csound-devel@lists.sourceforge.net |
Date | 2009-12-03 19:53 |
From | jhearon |
Subject | Re: [Cs-dev] Csound audio output in Java [Was: Csound bus opcodes] |
Victor Lazzarini wrote: > > spout can be used to feed a display (for instance an oscilloscope), if > you need. > Good idea! Brings up a host (no pun) of DSP applications such as analysis etc. ------ I think I have the spin/spout example working now in Java. I cannot remember exactly if it was Victor's original .cpp example; but he might willing to share the .cpp which is alot easier done than Java. Key to proof is "nosound" on sender.csd output which reads the .wav via diskin. Receiver.csd is the one which plays the audio. import csnd.*; public class Main { public static void main(String[] args) { Csound sender = new Csound(); Csound receiver = new Csound(); CsoundMYFLTArray myspout = new CsoundMYFLTArray(); CsoundMYFLTArray myspin = new CsoundMYFLTArray(); int ksmps = sender.GetKsmps(); float psend_array[] = new float[ksmps]; int nchnls = sender.GetNchnls(); String nosound = "-n"; // compile sender & retrieve kr & sr sender.PreCompile(); int sender_res = sender.Compile("sender.csd", nosound); myspout.SetPtr(sender.GetSpout()); ;**Michael's help** String sar = "--sample-rate= " + Double.toString(sender.GetSr()); String kar = "--control-rate= " + Double.toString(sender.GetKr()); // compile receiver & force kr & sr receiver.PreCompile(); int receiver_res = receiver.Compile("receiver.csd", kar, sar); myspin.SetPtr(receiver.GetSpin()); if (sender_res == 0) { while (sender.PerformKsmps() == 0) { for(int j=0; j |
Date | 2009-12-03 21:01 |
From | Victor Lazzarini |
Subject | Re: [Cs-dev] Csound audio output in Java [Was: Csound bus opcodes] |
I'd share if I knew where it was... but your example seems to do the job. More importantly, we need to find a way to use audio channels in Java. Does Michael have an idea of a solution? We could add an extra wrapper method in the Java interface. Victor On 3 Dec 2009, at 19:53, jhearon wrote: > > > > Victor Lazzarini wrote: >> >> spout can be used to feed a display (for instance an oscilloscope), >> if >> you need. >> > > Good idea! Brings up a host (no pun) of DSP applications such as > analysis > etc. > ------ > I think I have the spin/spout example working now in Java. I cannot > remember exactly if it was Victor's original .cpp example; but he > might > willing to share the .cpp which is alot easier done than Java. Key > to proof > is "nosound" on sender.csd output which reads the .wav via diskin. > Receiver.csd is the one which plays the audio. > > import csnd.*; > > public class Main { > public static void main(String[] args) { > > Csound sender = new Csound(); > Csound receiver = new Csound(); > CsoundMYFLTArray myspout = new CsoundMYFLTArray(); > CsoundMYFLTArray myspin = new CsoundMYFLTArray(); > int ksmps = sender.GetKsmps(); > float psend_array[] = new float[ksmps]; > int nchnls = sender.GetNchnls(); > > String nosound = "-n"; > // compile sender & retrieve kr & sr > sender.PreCompile(); > int sender_res = sender.Compile("sender.csd", nosound); > myspout.SetPtr(sender.GetSpout()); ;**Michael's help** > > String sar = "--sample-rate= " + Double.toString(sender.GetSr()); > String kar = "--control-rate= " + Double.toString(sender.GetKr()); > > // compile receiver & force kr & sr > receiver.PreCompile(); > int receiver_res = receiver.Compile("receiver.csd", kar, sar); > myspin.SetPtr(receiver.GetSpin()); > > if (sender_res == 0) { > while (sender.PerformKsmps() == 0) { > for(int j=0; j |
Date | 2009-12-03 21:07 |
From | Michael Gogins |
Subject | Re: [Cs-dev] Csound audio output in Java [Was: Csound bus opcodes] |
I am planning to add extra methods in the API for all languages. These will provide samplewise access to spout and spin, e.g. csoundGetOutputSample(csound, frame, channel) csoundPutInputSample(csound, frame, channel, sample) Regards, Mike On 12/3/09, Victor Lazzarini |