[Csnd] SetChannel value not received by CSound?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[Csnd] SetChannel value not received by CSound?

Jarrad Hope
I'm using the c++ api and embedding CSound into a software application. I have been attempting to pass a control parameter to Csound under a channel named "param1", but it is returning 0. However reading the string channel is fine, with the oscillator it also returns expected values over time.

Furthermore if I read csound->GetChannel("param1"), I see the value I set.

It's unclear to me what I am doing wrong?

// csound->SetControlChannel("param1", (MYFLT)0.5);
csound->SetChannel("param1", (MYFLT)0.5);
csound->PerformKsmps();
char tmp_string[4096] = { 0 };
csound->GetStringChannel("stringChannel", tmp_string);

my csd file is something like the following

<CsoundSynthesizer>
  <CsOptions> </CsOptions>
  <CsInstruments>
      sr = 44100 ; samplerate
      ksmps = 512 ; number of samples per control period
      nchnls = 2 ; number of I/O channels
   
      instr 1
        kParam chnget "param1"

      ; kParam oscil 1000, 1
      SText sprintfk "param1(\"%d\")", kParam
      chnset SText, "stringChannel"

      endin
  </CsInstruments>
  <CsScore>
      i1 0 10000 ; switch on instrument 1 for 10000 seconds
      ; f0 z ; run for 7000 years?
      e
  </CsScore>
</CsoundSynthesizer>

Csound mailing list [hidden email] https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Reply | Threaded
Open this post in threaded view
|

Re: [Csnd] SetChannel value not received by CSound?

moguillansky
Why do you use %d to receive 0.5?

On Sun, Nov 29, 2020, 07:51 Jarrad Hope <[hidden email]> wrote:
I'm using the c++ api and embedding CSound into a software application. I have been attempting to pass a control parameter to Csound under a channel named "param1", but it is returning 0. However reading the string channel is fine, with the oscillator it also returns expected values over time.

Furthermore if I read csound->GetChannel("param1"), I see the value I set.

It's unclear to me what I am doing wrong?

// csound->SetControlChannel("param1", (MYFLT)0.5);
csound->SetChannel("param1", (MYFLT)0.5);
csound->PerformKsmps();
char tmp_string[4096] = { 0 };
csound->GetStringChannel("stringChannel", tmp_string);

my csd file is something like the following

<CsoundSynthesizer>
  <CsOptions> </CsOptions>
  <CsInstruments>
      sr = 44100 ; samplerate
      ksmps = 512 ; number of samples per control period
      nchnls = 2 ; number of I/O channels
   
      instr 1
        kParam chnget "param1"

      ; kParam oscil 1000, 1
      SText sprintfk "param1(\"%d\")", kParam
      chnset SText, "stringChannel"

      endin
  </CsInstruments>
  <CsScore>
      i1 0 10000 ; switch on instrument 1 for 10000 seconds
      ; f0 z ; run for 7000 years?
      e
  </CsScore>
</CsoundSynthesizer>

Csound mailing list [hidden email] https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Csound mailing list [hidden email] https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Reply | Threaded
Open this post in threaded view
|

Re: [Csnd] SetChannel value not received by CSound?

Jarrad Hope
In reply to this post by Jarrad Hope
Ah, lack of awareness :)

Unfortunately, changing to "param1(\"%f\")" results in param1("0.000000")

The only other calls I am making before this are:

csound = new Csound();
csound->CompileCsd(csdFilePtr);
csound->Start();

Should I be declaring the channels somewhere prior?

I also noticed the Software Bus and chnexport, which might be an alternative for me to look at ?

Csound mailing list
[hidden email]
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Reply | Threaded
Open this post in threaded view
|

Re: [Csnd] SetChannel value not received by CSound?

Jarrad Hope
In reply to this post by Jarrad Hope
I solved this by the using the channel pointer

MYFLT *chan_param1;
csound->GetChannelPtr(chan_param1, "param1", CSOUND_CONTROL_CHANNEL | CSOUND_INPUT_CHANNEL);
*chan_param1 = (MYFLT)0.5;

Csound mailing list
[hidden email]
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Reply | Threaded
Open this post in threaded view
|

Re: [Csnd] SetChannel value not received by CSound?

rorywalsh
Can you post your full C++ code? The SetChannel() method just wraps the GetChannelPtr() function, so if it works, so should the other. 

On Sun, 29 Nov 2020 at 14:32, Jarrad Hope <[hidden email]> wrote:
I solved this by the using the channel pointer

MYFLT *chan_param1;
csound->GetChannelPtr(chan_param1, "param1", CSOUND_CONTROL_CHANNEL | CSOUND_INPUT_CHANNEL);
*chan_param1 = (MYFLT)0.5;

Csound mailing list
[hidden email]
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Csound mailing list [hidden email] https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here