Csound Csound-dev Csound-tekno Search About

[Csnd] Csound API Question

Date2010-08-07 00:10
FromJacob Joaquin
Subject[Csnd] Csound API Question
Hi Everybody!

I'm using the Csound Java API as a separate thread in processing, and
I came across an issue that I knew I'd run into eventually. Now that
I'm facing it, I really have no idea on how to tackle it. Ponder the
following two lines of code:

csound.InputMessage("f 1 0 8192 10 1")
csound.TableGet(1, 400);

In my test, csound.TableGet() is executed before the table is created.
Is there a way to make certain that Csound receives the input message
and creates a sine table before the second line tries to read a value?
As a bonus question, can anyone recommend any good documentation or
examples I should be studying? I have only bits and pieces of
information about the API, and I would seriously benefit if I had more
material to grok.

Best,
Jake

Date2010-08-07 00:29
FromVictor Lazzarini
Subject[Csnd] Re: Csound API Question
How is your processing thread created? Are you setting it or using  
CsoundPerformanceThread()?

If you are setting up your own thread, make sure that any calls to  
event-handling functions like InputMessage() are thread-safe (ie.  
PerformKsmps() and these calls should not happen at the same time).

If you are using CsoundPerformanceThread(), which is recommended, use  
the InputMessage() method of that class, because it's thread-safe. The  
one in the Csound class is not.

This might not answer your question, but it's important to note.

Victor

On 7 Aug 2010, at 00:10, Jacob Joaquin wrote:

> Hi Everybody!
>
> I'm using the Csound Java API as a separate thread in processing, and
> I came across an issue that I knew I'd run into eventually. Now that
> I'm facing it, I really have no idea on how to tackle it. Ponder the
> following two lines of code:
>
> csound.InputMessage("f 1 0 8192 10 1")
> csound.TableGet(1, 400);
>
> In my test, csound.TableGet() is executed before the table is created.
> Is there a way to make certain that Csound receives the input message
> and creates a sine table before the second line tries to read a value?
> As a bonus question, can anyone recommend any good documentation or
> examples I should be studying? I have only bits and pieces of
> information about the API, and I would seriously benefit if I had more
> material to grok.
>
> Best,
> Jake
> -- 
> The Csound Blog - http://csound.noisepages.com/
> Slipmat - http://slipmat.noisepages.com/
>
>
> Send bugs reports to the Sourceforge bug tracker
>            https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body  
> "unsubscribe csound"
>



Send bugs reports to the Sourceforge bug tracker
            https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"

Date2010-08-07 00:38
FromSteven Yi
Subject[Csnd] Re: Csound API Question
Hi Jake,

I think csound won't run the input messages until the end of the
current kperf, so you may need to wait one kperf before doing
TableGet.

For examples, you can look at blue's APIRunner class:

http://bluemusic.hg.sourceforge.net/hgweb/bluemusic/blue/file/ad67d4d5a2cb/blue-ui-core/src/blue/ui/core/render/APIRunner.java

The static APIRunnerThread class near the bottom is probably the code
of interest. blue does not use a great deal of the API, so it may not
be that useful for you.

The only other Java program I can think of at the top of my head is
Jean-Pierre Lemoine's AVSynthesis. I'm not sure if the source is
available, but you could contact Jean-Pierre to see if he could send
code over to you to look at. For non-Java uses of the API, you may
also want to look at QuteCsound.

steven



On Fri, Aug 6, 2010 at 7:10 PM, Jacob Joaquin  wrote:
> Hi Everybody!
>
> I'm using the Csound Java API as a separate thread in processing, and
> I came across an issue that I knew I'd run into eventually. Now that
> I'm facing it, I really have no idea on how to tackle it. Ponder the
> following two lines of code:
>
> csound.InputMessage("f 1 0 8192 10 1")
> csound.TableGet(1, 400);
>
> In my test, csound.TableGet() is executed before the table is created.
> Is there a way to make certain that Csound receives the input message
> and creates a sine table before the second line tries to read a value?
> As a bonus question, can anyone recommend any good documentation or
> examples I should be studying? I have only bits and pieces of
> information about the API, and I would seriously benefit if I had more
> material to grok.
>
> Best,
> Jake
> --
> The Csound Blog - http://csound.noisepages.com/
> Slipmat - http://slipmat.noisepages.com/
>
>
> Send bugs reports to the Sourceforge bug tracker
>            https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>
>


Send bugs reports to the Sourceforge bug tracker
            https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"


Date2010-08-07 00:39
FromJacob Joaquin
Subject[Csnd] Re: Re: Csound API Question
It's created as such:

public class MyCsound extends Thread {
    ...
    public void run() {
        if (csound == null) {
            csnd.csoundInitialize(null, null,
                                  csnd.CSOUNDINIT_NO_SIGNAL_HANDLER);
            csound = new Csound();
            int compile = csound.Compile(csd);

            if (compile == 0) {
                while(csound.PerformKsmps() == 0) { }
            }
        }
    }
    ...
}


Originally, I was using CsoundPerformanceThread(). However, it seems
to shutdown mid-performance fairly reliably. Thus the reason I
switched to csound.PerformKsmps().

I'm going to put up my project at github soon, so the code should be
available online soon. The only thing that's holding me up is that I
haven't come up with a name for the project.

Does anyone have a preferences for "Csoundo" or "Csoundito" or
"Csoundita?"  It's a Processing library.

Best,
Jake

Date2010-08-07 01:10
FromVictor Lazzarini
Subject[Csnd] Re: Re: Re: Csound API Question
Then your code is not thread-safe, you'll need to put some locks to  
protect it or using queues to process events. Calls to InputMessage()  
might cause crashes if they happen to access the same resources as  
PerformKsmps().

I would suggest trying CsoundPerformanceThread() again, it's pretty  
solid, if you use it correctly. Then you'll avoid all the hassle.

Victor
On 7 Aug 2010, at 00:39, Jacob Joaquin wrote:

> It's created as such:
>
> public class MyCsound extends Thread {
>    ...
>    public void run() {
>        if (csound == null) {
>            csnd.csoundInitialize(null, null,
>                                  csnd.CSOUNDINIT_NO_SIGNAL_HANDLER);
>            csound = new Csound();
>            int compile = csound.Compile(csd);
>
>            if (compile == 0) {
>                while(csound.PerformKsmps() == 0) { }
>            }
>        }
>    }
>    ...
> }
>
>
> Originally, I was using CsoundPerformanceThread(). However, it seems
> to shutdown mid-performance fairly reliably. Thus the reason I
> switched to csound.PerformKsmps().
>
> I'm going to put up my project at github soon, so the code should be
> available online soon. The only thing that's holding me up is that I
> haven't come up with a name for the project.
>
> Does anyone have a preferences for "Csoundo" or "Csoundito" or
> "Csoundita?"  It's a Processing library.
>
> Best,
> Jake
> -- 
> The Csound Blog - http://csound.noisepages.com/
> Slipmat - http://slipmat.noisepages.com/
>
>
> On Fri, Aug 6, 2010 at 4:29 PM, Victor Lazzarini
>  wrote:
>> How is your processing thread created? Are you setting it or using
>> CsoundPerformanceThread()?
>>
>> If you are setting up your own thread, make sure that any calls to
>> event-handling functions like InputMessage() are thread-safe (ie.
>> PerformKsmps() and these calls should not happen at the same time).
>>
>> If you are using CsoundPerformanceThread(), which is recommended,  
>> use the
>> InputMessage() method of that class, because it's thread-safe. The  
>> one in
>> the Csound class is not.
>>
>> This might not answer your question, but it's important to note.
>>
>> Victor
>
>
> Send bugs reports to the Sourceforge bug tracker
>            https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body  
> "unsubscribe csound"
>



Send bugs reports to the Sourceforge bug tracker
            https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"

Date2010-08-07 08:19
FromAndres Cabrera
Subject[Csnd] Re: Csound API Question
Ah, yes, the beauties of concurrent programming.

There's actually no direct way of knowing since things are running on
a separate thread, so you have to make some kind of mechanism which
shares data to synchronize the instances.

All I've learned about this, has been from doing QuteCsound, and I'm
not sure my ideas are good advice. If anyone can correct me, I'd be
grateful.

You could create a "trigger" variable. It would have to be of a simple
type like int or bool, so that it is atomic, i.e. it is read and
written to in a single instruction (BTW way would that be valid for
Java as well?), so that without having to do locking in the csound
thread, you can change it, so you would do:

trigger = 1
InputMessage("f 1 0 8192 10 1")
while (trigger == 1) {
wait java sometime...
}
csound.TableGet(1, 400);

and in the Csound perf callback, you should set trigger to 0 when all
is done. Like Victor said, you should use the Csound PerfThread class,
otherwise you will need to handle all the locking and protecting of
Csound yourself, and i don't think you want to do that.

This idea works for simple cases (for example it won't work for many
tables at the same time), but if you need something more generic or
complex, you would need to think of something else.

Cheers,
Andrés

On Sat, Aug 7, 2010 at 12:10 AM, Jacob Joaquin  wrote:
> Hi Everybody!
>
> I'm using the Csound Java API as a separate thread in processing, and
> I came across an issue that I knew I'd run into eventually. Now that
> I'm facing it, I really have no idea on how to tackle it. Ponder the
> following two lines of code:
>
> csound.InputMessage("f 1 0 8192 10 1")
> csound.TableGet(1, 400);
>
> In my test, csound.TableGet() is executed before the table is created.
> Is there a way to make certain that Csound receives the input message
> and creates a sine table before the second line tries to read a value?
> As a bonus question, can anyone recommend any good documentation or
> examples I should be studying? I have only bits and pieces of
> information about the API, and I would seriously benefit if I had more
> material to grok.
>
> Best,
> Jake
> --
> The Csound Blog - http://csound.noisepages.com/
> Slipmat - http://slipmat.noisepages.com/
>
>
> Send bugs reports to the Sourceforge bug tracker
>            https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>
>



-- 


Andrés


Send bugs reports to the Sourceforge bug tracker
            https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"


Date2010-08-08 19:47
FromJacob Joaquin
Subject[Csnd] Re: Re: Csound API Question
Thanks everyone for the advice. I'll be asking a lots of questions in
the future. To make it all worthwhile, maybe I'll but together a small
compendium of "how-to" and "why is that?" together for future API use.

I think I may have found out my CsoundPerformanceThread was unstable
in my Processing projects. I still have to run more tests, but I
believe my problem was that I should have created a
CsoundPerformanceThread as class member, as opposed to creating it
locally in a method like this:

private void startCsound() {
    ...
    CsoundPerformanceThread cpThread = new CsoundPerformanceThread(csound);
    cpThread.Play();
    ...
}

The project will be up at a repository within the next 24 hours.

Best,
Jake

Date2010-08-08 21:58
FromJacob Joaquin
Subject[Csnd] Re: Re: Csound API Question
On Fri, Aug 6, 2010 at 4:29 PM, Victor Lazzarini
 wrote:
> If you are using CsoundPerformanceThread(), which is recommended, use the
> InputMessage() method of that class, because it's thread-safe. The one in
> the Csound class is not.

CsoundPerformanceThread().InputMessage() is thread-safe.  What about
Csound.TableGet() and Csound.TableSet()?  For example:

    cs.cpThread.InputMessage("f 1 0 512 10 1");
    cs.csound.TableSet(1, 400, -2);

Best,
Jake

Date2010-08-08 22:00
FromAndres Cabrera
SubjectRe: [Cs-dev] [Csnd] Re: Re: Csound API Question
The functions are thread safe, since they will pass the pointer to the
data. Reading or writing the data may not be thread safe, but I'm not
entirely sure.

BTW, I've moved this to -dev

Cheers,
Andrés

On Sun, Aug 8, 2010 at 9:58 PM, Jacob Joaquin  wrote:
> On Fri, Aug 6, 2010 at 4:29 PM, Victor Lazzarini
>  wrote:
>> If you are using CsoundPerformanceThread(), which is recommended, use the
>> InputMessage() method of that class, because it's thread-safe. The one in
>> the Csound class is not.
>
> CsoundPerformanceThread().InputMessage() is thread-safe.  What about
> Csound.TableGet() and Csound.TableSet()?  For example:
>
>    cs.cpThread.InputMessage("f 1 0 512 10 1");
>    cs.csound.TableSet(1, 400, -2);
>
> Best,
> Jake
> --
> The Csound Blog - http://csound.noisepages.com/
> Slipmat - http://slipmat.noisepages.com/
>
>
> Send bugs reports to the Sourceforge bug tracker
>            https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>
>



-- 


Andrés

------------------------------------------------------------------------------
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net
https://lists.sourcefo

Date2010-08-08 22:11
FromVictor Lazzarini
SubjectRe: [Cs-dev] [Csnd] Re: Re: Csound API Question
I don't think using pointer is thread-safe. You'll need to protect it.

Victor
On 8 Aug 2010, at 22:00, Andres Cabrera wrote:

> The functions are thread safe, since they will pass the pointer to the
> data. Reading or writing the data may not be thread safe, but I'm not
> entirely sure.
>
> BTW, I've moved this to -dev
>
> Cheers,
> Andrés
>
> On Sun, Aug 8, 2010 at 9:58 PM, Jacob Joaquin  
>  wrote:
>> On Fri, Aug 6, 2010 at 4:29 PM, Victor Lazzarini
>>  wrote:
>>> If you are using CsoundPerformanceThread(), which is recommended,  
>>> use the
>>> InputMessage() method of that class, because it's thread-safe. The  
>>> one in
>>> the Csound class is not.
>>
>> CsoundPerformanceThread().InputMessage() is thread-safe.  What about
>> Csound.TableGet() and Csound.TableSet()?  For example:
>>
>>    cs.cpThread.InputMessage("f 1 0 512 10 1");
>>    cs.csound.TableSet(1, 400, -2);
>>
>> Best,
>> Jake
>> --
>> The Csound Blog - http://csound.noisepages.com/
>> Slipmat - http://slipmat.noisepages.com/
>>
>>
>> Send bugs reports to the Sourceforge bug tracker
>>            https://sourceforge.net/tracker/? 
>> group_id=81968&atid=564599
>> Discussions of bugs and features can be posted here
>> To unsubscribe, send email sympa@lists.bath.ac.uk with body  
>> "unsubscribe csound"
>>
>>
>
>
>
> -- 
>
>
> Andrés
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by
>
> Make an app they can't live without
> Enter the BlackBerry Developer Challenge
> http://p.sf.net/sfu/RIM-dev2dev
> _______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel


------------------------------------------------------------------------------
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2010-08-08 22:13
FromVictor Lazzarini
SubjectRe: [Cs-dev] [Csnd] Re: Re: Csound API Question
By which I mean accessing the data it points to.
On 8 Aug 2010, at 22:11, Victor Lazzarini wrote:

> I don't think using pointer is thread-safe. You'll need to protect it.
>
> Victor
> On 8 Aug 2010, at 22:00, Andres Cabrera wrote:
>
>> The functions are thread safe, since they will pass the pointer to  
>> the
>> data. Reading or writing the data may not be thread safe, but I'm not
>> entirely sure.
>>
>> BTW, I've moved this to -dev
>>
>> Cheers,
>> Andrés
>>
>> On Sun, Aug 8, 2010 at 9:58 PM, Jacob Joaquin
>>  wrote:
>>> On Fri, Aug 6, 2010 at 4:29 PM, Victor Lazzarini
>>>  wrote:
>>>> If you are using CsoundPerformanceThread(), which is recommended,
>>>> use the
>>>> InputMessage() method of that class, because it's thread-safe. The
>>>> one in
>>>> the Csound class is not.
>>>
>>> CsoundPerformanceThread().InputMessage() is thread-safe.  What about
>>> Csound.TableGet() and Csound.TableSet()?  For example:
>>>
>>>   cs.cpThread.InputMessage("f 1 0 512 10 1");
>>>   cs.csound.TableSet(1, 400, -2);
>>>
>>> Best,
>>> Jake
>>> --
>>> The Csound Blog - http://csound.noisepages.com/
>>> Slipmat - http://slipmat.noisepages.com/
>>>
>>>
>>> Send bugs reports to the Sourceforge bug tracker
>>>           https://sourceforge.net/tracker/?
>>> group_id=81968&atid=564599
>>> Discussions of bugs and features can be posted here
>>> To unsubscribe, send email sympa@lists.bath.ac.uk with body
>>> "unsubscribe csound"
>>>
>>>
>>
>>
>>
>> -- 
>>
>>
>> Andrés
>>
>> ------------------------------------------------------------------------------
>> This SF.net email is sponsored by
>>
>> Make an app they can't live without
>> Enter the BlackBerry Developer Challenge
>> http://p.sf.net/sfu/RIM-dev2dev
>> _______________________________________________
>> Csound-devel mailing list
>> Csound-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/csound-devel
>
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by
>
> Make an app they can't live without
> Enter the BlackBerry Developer Challenge
> http://p.sf.net/sfu/RIM-dev2dev
> _______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel


------------------------------------------------------------------------------
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2010-08-08 23:47
FromJacob Joaquin
SubjectRe: [Cs-dev] [Csnd] Re: Re: Csound API Question
On Sun, Aug 8, 2010 at 2:13 PM, Victor Lazzarini
 wrote:
> By which I mean accessing the data it points to.
> On 8 Aug 2010, at 22:11, Victor Lazzarini wrote:
>
>> I don't think using pointer is thread-safe. You'll need to protect it.

I do believe I'm officially lost.

Best,
Jake
-- 
The Csound Blog - http://csound.noisepages.com/
Slipmat - http://slipmat.noisepages.com/

------------------------------------------------------------------------------
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net