Csound Csound-dev Csound-tekno Search About

[Csnd] Csound audio output in Java [Was: Csound bus opcodes]

Date2009-11-27 21:42
FromMichael 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

Date2009-11-27 22:27
FromVictor 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 // Average N-channel output to my monophonic native buffer.
> // Note that v collects only one sample if nchnls = 1.
>  float v = 0;
>  // I.e., k is the CHANNEL index (and ksmps is the channel "stride"  
> in spout).
>  for(int k=j; k   v += spout.GetValue(k);
>  }
>  cumulativeBuffer[j] = v/scale;
> }
> // Write my native audio buffer to my backend.
> ringBuffer.write(cumulativeBuffer, 0, ksmps);
> }
> }
>
> For N-channel final output, instead of
>
> v+= spout.GetValue(k)
>
> you should have
>
> frame[channel] = spout.getValue(k)
>
> In spite of the fact that this works, I will add to the API more
> direct, samplewise access to spout and spin. The above would be more
> efficient for ksmps above a certain size, but I'm not sure what that
> size would be; I expect for low latency (ksmps of 20 or so) samplewise
> access should be about as fast.
>
> I imagine the reason SWIG takes this circuitous route is that, in some
> languages, you can directly index a pointer as though it is an array,
> whereas in other languages pointers do not directly appear. The array
> wrapper makes both kinds of languages act the same way.
>
> Hope this helps,
> Mike
>
>
>
> -- 
> Michael Gogins
> Irreducible Productions
> http://www.michael-gogins.com
> Michael dot Gogins at gmail dot com
>
>
> Send bugs reports to this list.
> To unsubscribe, send email sympa@lists.bath.ac.uk with body  
> "unsubscribe csound"



Send bugs reports to this list.
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"

Date2009-11-28 00:08
FromMichael 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  wrote:
> 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> // Average N-channel output to my monophonic native buffer.
>> // Note that v collects only one sample if nchnls = 1.
>>  float v = 0;
>>  // I.e., k is the CHANNEL index (and ksmps is the channel "stride"
>> in spout).
>>  for(int k=j; k>   v += spout.GetValue(k);
>>  }
>>  cumulativeBuffer[j] = v/scale;
>> }
>> // Write my native audio buffer to my backend.
>> ringBuffer.write(cumulativeBuffer, 0, ksmps);
>> }
>> }
>>
>> For N-channel final output, instead of
>>
>> v+= spout.GetValue(k)
>>
>> you should have
>>
>> frame[channel] = spout.getValue(k)
>>
>> In spite of the fact that this works, I will add to the API more
>> direct, samplewise access to spout and spin. The above would be more
>> efficient for ksmps above a certain size, but I'm not sure what that
>> size would be; I expect for low latency (ksmps of 20 or so) samplewise
>> access should be about as fast.
>>
>> I imagine the reason SWIG takes this circuitous route is that, in some
>> languages, you can directly index a pointer as though it is an array,
>> whereas in other languages pointers do not directly appear. The array
>> wrapper makes both kinds of languages act the same way.
>>
>> Hope this helps,
>> Mike
>>
>>
>>
>> --
>> Michael Gogins
>> Irreducible Productions
>> http://www.michael-gogins.com
>> Michael dot Gogins at gmail dot com
>>
>>
>> Send bugs reports to this list.
>> To unsubscribe, send email sympa@lists.bath.ac.uk with body
>> "unsubscribe csound"
>
>
>
> Send bugs reports to this list.
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe
> csound"
>

Date2009-11-28 08:22
FromVictor 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  wrote:
>> 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>> // Average N-channel output to my monophonic native buffer.
>>> // Note that v collects only one sample if nchnls = 1.
>>> float v = 0;
>>> // I.e., k is the CHANNEL index (and ksmps is the channel "stride"
>>> in spout).
>>> for(int k=j; k>>  v += spout.GetValue(k);
>>> }
>>> cumulativeBuffer[j] = v/scale;
>>> }
>>> // Write my native audio buffer to my backend.
>>> ringBuffer.write(cumulativeBuffer, 0, ksmps);
>>> }
>>> }
>>>
>>> For N-channel final output, instead of
>>>
>>> v+= spout.GetValue(k)
>>>
>>> you should have
>>>
>>> frame[channel] = spout.getValue(k)
>>>
>>> In spite of the fact that this works, I will add to the API more
>>> direct, samplewise access to spout and spin. The above would be more
>>> efficient for ksmps above a certain size, but I'm not sure what that
>>> size would be; I expect for low latency (ksmps of 20 or so)  
>>> samplewise
>>> access should be about as fast.
>>>
>>> I imagine the reason SWIG takes this circuitous route is that, in  
>>> some
>>> languages, you can directly index a pointer as though it is an  
>>> array,
>>> whereas in other languages pointers do not directly appear. The  
>>> array
>>> wrapper makes both kinds of languages act the same way.
>>>
>>> Hope this helps,
>>> Mike
>>>
>>>
>>>
>>> --
>>> Michael Gogins
>>> Irreducible Productions
>>> http://www.michael-gogins.com
>>> Michael dot Gogins at gmail dot com
>>>
>>>
>>> Send bugs reports to this list.
>>> To unsubscribe, send email sympa@lists.bath.ac.uk with body
>>> "unsubscribe csound"
>>
>>
>>
>> Send bugs reports to this list.
>> To unsubscribe, send email sympa@lists.bath.ac.uk with body  
>> "unsubscribe
>> csound"
>>
>
>
> -- 
> Michael Gogins
> Irreducible Productions
> http://www.michael-gogins.com
> Michael dot Gogins at gmail dot com
>
>
> Send bugs reports to this list.
> To unsubscribe, send email sympa@lists.bath.ac.uk with body  
> "unsubscribe csound"



Send bugs reports to this list.
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"

Date2009-11-30 18:05
Fromjhearon
SubjectRe: [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

Date2009-11-30 18:18
FromMichael Gogins
SubjectRe: [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  wrote:
>
>
>
> 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
> 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

Date2009-12-01 22:29
Fromjhearon
SubjectRe: [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

Date2009-12-02 03:27
FromMichael Gogins
SubjectRe: [Cs-dev] Csound audio output in Java [Was: Csound bus opcodes]
AttachmentsNone  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:



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.sourcef...


Date2009-12-02 21:40
Fromjhearon
SubjectRe: [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

Date2009-12-02 21:49
FromVictor Lazzarini
SubjectRe: [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

Date2009-12-03 19:53
Fromjhearon
SubjectRe: [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



csound -s -d -+rtaudio=ALSA -odac:hw:0,0 -b1024 -B16384 




sr=44100
 ksmps=64
 nchnls=2

 instr 1
 ;asig,asig1 diskin "clar.wav", 1, 0, 1 ;can't find
 asig,asig1 diskin "beats2.wav", 1, 0, 1 ;I made a stereo vers of the manual
ex. file
 outs asig, asig1
 endin

 
 
 i1 0 12
 e
 
 
-------------------
//receiver.csd




csound -s -d -+rtaudio=ALSA -odac:hw:0,0 -b1024 -B16384 





sr=44100
 ksmps=64
 nchnls=2

 instr 1
;aout in;I'm using stereo, below
aoutL, aoutR ins
 outs aoutL, aoutR
 endin

 
 
 i1 0 12
 e
 
 

-- 
View this message in context: http://old.nabble.com/Csound-audio-output-in-Java--Was%3A-Csound-bus-opcodes--tp26548109p26632084.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

Date2009-12-03 21:01
FromVictor Lazzarini
SubjectRe: [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                                   psend_array[j]=
> (float)myspout.GetValue(j);
>                                   myspin.SetValue(j,  psend_array[j]);
> 			}
>                        receiver.PerformKsmps();
>                        if (sender_res != 0) sender.PerformKsmps();
>                }
>     }
>        sender.Reset();
>        receiver.Reset();
>        java.lang.System.exit(1);
> }
> }
> ---------------
> //sender.csd
> 
>
> 
>
> csound -s -d -+rtaudio=ALSA -odac:hw:0,0 -b1024 -B16384
>
> 
>
> 
> sr=44100
> ksmps=64
> nchnls=2
>
> instr 1
> ;asig,asig1 diskin "clar.wav", 1, 0, 1 ;can't find
> asig,asig1 diskin "beats2.wav", 1, 0, 1 ;I made a stereo vers of the  
> manual
> ex. file
> outs asig, asig1
> endin
>
> 
> 
> i1 0 12
> e
> 
> 
> -------------------
> //receiver.csd
> 
>
> 
>
> csound -s -d -+rtaudio=ALSA -odac:hw:0,0 -b1024 -B16384
>
> 
>
> 
>
> sr=44100
> ksmps=64
> nchnls=2
>
> instr 1
> ;aout in;I'm using stereo, below
> aoutL, aoutR ins
> outs aoutL, aoutR
> endin
>
> 
> 
> i1 0 12
> e
> 
> 
>
> -- 
> View this message in context: http://old.nabble.com/Csound-audio-output-in-Java--Was%3A-Csound-bus-opcodes--tp26548109p26632084.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

Date2009-12-03 21:07
FromMichael Gogins
SubjectRe: [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  wrote:
> 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>                                   psend_array[j]=
>> (float)myspout.GetValue(j);
>>                                   myspin.SetValue(j,  psend_array[j]);
>> 			}
>>                        receiver.PerformKsmps();
>>                        if (sender_res != 0) sender.PerformKsmps();
>>                }
>>     }
>>        sender.Reset();
>>        receiver.Reset();
>>        java.lang.System.exit(1);
>> }
>> }
>> ---------------
>> //sender.csd
>> 
>>
>> 
>>
>> csound -s -d -+rtaudio=ALSA -odac:hw:0,0 -b1024 -B16384
>>
>> 
>>
>> 
>> sr=44100
>> ksmps=64
>> nchnls=2
>>
>> instr 1
>> ;asig,asig1 diskin "clar.wav", 1, 0, 1 ;can't find
>> asig,asig1 diskin "beats2.wav", 1, 0, 1 ;I made a stereo vers of the
>> manual
>> ex. file
>> outs asig, asig1
>> endin
>>
>> 
>> 
>> i1 0 12
>> e
>> 
>> 
>> -------------------
>> //receiver.csd
>> 
>>
>> 
>>
>> csound -s -d -+rtaudio=ALSA -odac:hw:0,0 -b1024 -B16384
>>
>> 
>>
>> 
>>
>> sr=44100
>> ksmps=64
>> nchnls=2
>>
>> instr 1
>> ;aout in;I'm using stereo, below
>> aoutL, aoutR ins
>> outs aoutL, aoutR
>> endin
>>
>> 
>> 
>> i1 0 12
>> e
>> 
>> 
>>
>> --
>> View this message in context:
>> http://old.nabble.com/Csound-audio-output-in-Java--Was%3A-Csound-bus-opcodes--tp26548109p26632084.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
> https://lists.sourceforge.net/lists/listinfo/csound-devel
>


-- 
Michael Gogins
Irreducible Productions
http://www.michael-gogins.com
Michael dot Gogins at gmail dot 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