Csound Csound-dev Csound-tekno Search About

[Csnd] csnd.csoundGetChannelPtr is returning a invalid memory access error

Date2010-08-17 19:42
FromJacob Joaquin
Subject[Csnd] csnd.csoundGetChannelPtr is returning a invalid memory access error
Hello everyone,

Ever since I starting using CppSound, I've been having issues
accessing the chn busses. For example, I get a "Invalid memory access
of location 0x0 eip=0x4215ba53" when calling Csoundo.setChn().

public void setChn(String chn, float value) {
    if (isRunning) {
        CsoundMYFLTArray myflt = new CsoundMYFLTArray();
        int check = csnd.csoundGetChannelPtr(csound_p, myflt.GetPtr(), chn,
                                             csnd.CSOUND_CONTROL_CHANNEL |
                                             csnd.CSOUND_INPUT_CHANNEL);

        if (check == 0) {
            myflt.SetValue(0, value);
        }
    }
}

This breaks when calling csnd.csoundGetChannelPtr(), as commenting out
myflt.SetValue() still leads to the same problem. I've also tried
csound.GetChannelPtr and csound.SetChannel() without any luck. Could
anyone look over this to see if there is anything obviously wrong with
my methodology?

The full code can be found here.
http://github.com/jacobjoaquin/Csoundo/tree/master/src/csoundo/

Thanks!
Jake

Date2010-08-17 19:54
FromVictor Lazzarini
Subject[Csnd] Re: csnd.csoundGetChannelPtr is returning a invalid memory access error
And what instance of Csound exactly is 'csound' in your call  
csoundGetChannelPtr()? Has it been compiled?
Is there any reason not to use Csound.GetChannel() or  
Csound.SetChannel(), as they are way simpler in terms of syntax for  
Java?

On 17 Aug 2010, at 19:42, Jacob Joaquin wrote:

>        int check = csnd.csoundGetChannelPtr(csound_p,  
> myflt.GetPtr(), chn,
>                                              
> csnd.CSOUND_CONTROL_CHANNEL |
>                                              
> csnd.CSOUND_INPUT_CHANNEL);



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-17 20:15
FromJacob Joaquin
Subject[Csnd] Re: Re: csnd.csoundGetChannelPtr is returning a invalid memory access error
> And what instance of Csound exactly is 'csound' in your call
> csoundGetChannelPtr()? Has it been compiled?
> Is there any reason not to use Csound.GetChannel() or Csound.SetChannel(),
> as they are way simpler in terms of syntax for Java?

csound is an instance of CppSound. It has been compiled, and runs with
audio. Originally I was using Csound.GetChannel() and
Csound.SetChannel(), but they stopped working when I implemented this
new code to get Csound up and running.


private void cppSoundPerf() {
    // TODO: Make sure csound isn't already running
    if (true) {
        csnd.csoundInitialize(null, null,
                csnd.CSOUNDINIT_NO_SIGNAL_HANDLER);

        csound = new CppSound();
        csound_p = csound.getCsound();

        csoundFile = csound.getCsoundFile();
        csoundFile.setCSD(fileToString(csd));

        // TODO: csd should get unique names, in case of multiple
        //       instances.
        String tempCSD = "temp.csd";
        csoundFile.setCommand("-d -odac " + path + tempCSD);

        csoundFile.exportForPerformance();
        int compile = csound.compile();
        System.out.println("compile status: " + compile);

        if (compile == 0) {
            isRunning = true;
            perfThread = new CsoundPerformanceThread(csound_p);
            perfThread.Play();
            mutex = csnd.csoundCreateMutex(1);
        }
    }
}



In the version previous to this, I used class Csound instead of
CppSound. With that, I could pass my instance of csound to the
CsoundPerformanceThread like this:

            perfThread = new CsoundPerformanceThread(csound);

Though this didn't work with CppSound and/or my new code. It would
crash and give me a similar invalid memory address error as the one
I'm having now. So I switched to passing the java equivalent of CSOUND
* to CsoundPerformanceThread. That allowed the engine to run, but I
had to go through and change many methods to use
csnd.someFunction(CSOUND *, ...) instead of cCsound.someFunction(...),
as those would also create the invalid memory address.  Specifically
tableLength(), tableSet() and tableGet().  However, converting to use
the pointer version does not seem to work with the Channel methods as
they did with the table methods.

Thanks,
Jake


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-17 20:40
FromVictor Lazzarini
Subject[Csnd] Re: Re: Re: csnd.csoundGetChannelPtr is returning a invalid memory access error
I think the problem with CppSound is its C++ version

class PUBLIC CppSound : public Csound, public CsoundFile

is derived from two classes, and Java does not like that (there is a  
warning when the
Java wrapper is built). This might be a problem. In C++ what you are  
trying to do would be perfectly possible.

However, if csound_p is holding a correct instance of csound_p, then  
you should be able to use it.
I think you are not creating the MYFLT variable properly. Try

CsoundMYFLTArray(1);

to create a variable. If there is no argument, no memory is allocated:

/**
  * CsoundMYFLTArray()
  *
  * Creates a pointer for use with csoundGetChannelPtr(),
  * csoundGetOutputBuffer(), or other functions that return a
  * pointer to an array of floating point values.
  *
  * CsoundMYFLTArray(int cnt)
  *
  * Allocates an array of 'cnt' floating point values, for use
  * with Csound API functions that take a MYFLT* pointer.
  */

Victor


On 17 Aug 2010, at 20:15, Jacob Joaquin wrote:

>> And what instance of Csound exactly is 'csound' in your call
>> csoundGetChannelPtr()? Has it been compiled?
>> Is there any reason not to use Csound.GetChannel() or  
>> Csound.SetChannel(),
>> as they are way simpler in terms of syntax for Java?
>
> csound is an instance of CppSound. It has been compiled, and runs with
> audio. Originally I was using Csound.GetChannel() and
> Csound.SetChannel(), but they stopped working when I implemented this
> new code to get Csound up and running.
>
>
> private void cppSoundPerf() {
>    // TODO: Make sure csound isn't already running
>    if (true) {
>        csnd.csoundInitialize(null, null,
>                csnd.CSOUNDINIT_NO_SIGNAL_HANDLER);
>
>        csound = new CppSound();
>        csound_p = csound.getCsound();
>
>        csoundFile = csound.getCsoundFile();
>        csoundFile.setCSD(fileToString(csd));
>
>        // TODO: csd should get unique names, in case of multiple
>        //       instances.
>        String tempCSD = "temp.csd";
>        csoundFile.setCommand("-d -odac " + path + tempCSD);
>
>        csoundFile.exportForPerformance();
>        int compile = csound.compile();
>        System.out.println("compile status: " + compile);
>
>        if (compile == 0) {
>            isRunning = true;
>            perfThread = new CsoundPerformanceThread(csound_p);
>            perfThread.Play();
>            mutex = csnd.csoundCreateMutex(1);
>        }
>    }
> }
>
>
>
> In the version previous to this, I used class Csound instead of
> CppSound. With that, I could pass my instance of csound to the
> CsoundPerformanceThread like this:
>
>            perfThread = new CsoundPerformanceThread(csound);
>
> Though this didn't work with CppSound and/or my new code. It would
> crash and give me a similar invalid memory address error as the one
> I'm having now. So I switched to passing the java equivalent of CSOUND
> * to CsoundPerformanceThread. That allowed the engine to run, but I
> had to go through and change many methods to use
> csnd.someFunction(CSOUND *, ...) instead of cCsound.someFunction(...),
> as those would also create the invalid memory address.  Specifically
> tableLength(), tableSet() and tableGet().  However, converting to use
> the pointer version does not seem to work with the Channel methods as
> they did with the table methods.
>
> Thanks,
> Jake
>
>
> 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-17 21:01
FromJacob Joaquin
Subject[Csnd] Re: Re: Re: Re: csnd.csoundGetChannelPtr is returning a invalid memory access error
Thanks Victor. I'm going to move back to using class Csound for now.
CsoundMYFLTArray(1) didn't work, but even if it had, it probably isn't
a good idea to continue using CppSound anyways based on everything
you've said.

Best,
Jake


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"