Csound Csound-dev Csound-tekno Search About

[Csnd-dev] Writing a new opcode

Date2015-12-10 16:22
FromPeter Burgess
Subject[Csnd-dev] Writing a new opcode
AttachmentsbitwiseOr.c  
Hi there, I am writing a new opcode for csound. I am using these two sources as a guide...

http://www.csounds.com/manual/html/csound5extending.html
http://booki.flossmanuals.net/csound/extending-csound/

When showing how to write an opcode with an audio rate output, neither tutorial initialises the output array to the size of ksmps before use. They both instead just reference ksmps to control the array processing loop. Is the array initialisation done automatically somewhere else in csound?

My opcode also uses two input audio rate arguments. Should I initialise the arrays for them to ksmps size before use?

Next, I am wondering if all the arrays that I initialise in the _perform function should actually be initialised in the _init function for speed.

I have attached my .h and .c files in one continuous file for reference. My opcode's purpose is to take two input audio signals and bitwise-or them to get the output audio signal (though I am guessing the results of bitwise operations on floats won't be as linear as on ints, but I'm ok with that for now :D ).

Date2015-12-10 16:35
Fromjpff
SubjectRe: [Csnd-dev] Writing a new opcode
Qick response.  There is no need to initialise te outout a-variale as it 
is written by the perf.  Take care to copy thhe early end/late start code 
which does include some zeroing of  the outout as it is necessary in this 
case

The a-variable are created  as ksp-long vectors by the engine

I a assuming  you eand array as in internal structure anfd nor csound 
arrays which are something else.

I am a little oushed fior time today but will look at your  code asap

==John ff

On Thu, 10 Dec 2015, Peter Burgess wrote:

> Hi there, I am writing a new opcode for csound. I am using these two sources
> as a guide...
> 
> http://www.csounds.com/manual/html/csound5extending.html
> http://booki.flossmanuals.net/csound/extending-csound/
> 
> When showing how to write an opcode with an audio rate output, neither
> tutorial initialises the output array to the size of ksmps before use. They
> both instead just reference ksmps to control the array processing loop. Is the
> array initialisation done automatically somewhere else in csound?
> 
> My opcode also uses two input audio rate arguments. Should I initialise the
> arrays for them to ksmps size before use?
> 
> Next, I am wondering if all the arrays that I initialise in the _perform
> function should actually be initialised in the _init function for speed.
> 
> I have attached my .h and .c files in one continuous file for reference. My
> opcode's purpose is to take two input audio signals and bitwise-or them to get
> the output audio signal (though I am guessing the results of bitwise
> operations on floats won't be as linear as on ints, but I'm ok with that for
> now :D ).
> 

Date2015-12-10 16:38
Fromjpff
SubjectRe: [Csnd-dev] Writing a new opcode
QUick look at the code -- this is corret except fot --saple-accurate use

\Releasenore 6.0 say....

The template for arate perf-pass opcodes is:

     int perf_myopcode(CSOUND *csound, MYOPCODE *p)
     {
         uint32_t offset = p->h.insdshead->ksmps_offset;
         uint32_t early  = p->h.insdshead->ksmps_no_end;
         uint32_t nsmps = CS_KSMPS;
         ...
         if (UNLIKELY(offset)) memset(p->res, '\0', offset*sizeof(MYFLT));
         if (UNLIKELY(early))  {
           nsmps -= early;
           memset(&p->res[nsmps], '\0', early*sizeof(MYFLT));
         }
         for (n=offset; nres[n] = ....
         }
         return OK;
     }



On Thu, 10 Dec 2015, Peter Burgess wrote:

> Hi there, I am writing a new opcode for csound. I am using these two sources
> as a guide...
> 
> http://www.csounds.com/manual/html/csound5extending.html
> http://booki.flossmanuals.net/csound/extending-csound/
> 
> When showing how to write an opcode with an audio rate output, neither
> tutorial initialises the output array to the size of ksmps before use. They
> both instead just reference ksmps to control the array processing loop. Is the
> array initialisation done automatically somewhere else in csound?
> 
> My opcode also uses two input audio rate arguments. Should I initialise the
> arrays for them to ksmps size before use?
> 
> Next, I am wondering if all the arrays that I initialise in the _perform
> function should actually be initialised in the _init function for speed.
> 
> I have attached my .h and .c files in one continuous file for reference. My
> opcode's purpose is to take two input audio signals and bitwise-or them to get
> the output audio signal (though I am guessing the results of bitwise
> operations on floats won't be as linear as on ints, but I'm ok with that for
> now :D ).
> 

Date2015-12-10 16:50
FromPeter Burgess
SubjectRe: [Csnd-dev] Writing a new opcode
Excellent! Cheers.

Yeah I hadn't added the sample accurate business yet, I'll add that in now. What are the UNLIKELY() functions for?

On Thu, Dec 10, 2015 at 4:38 PM, jpff <jpff@codemist.co.uk> wrote:
QUick look at the code -- this is corret except fot --saple-accurate use

\Releasenore 6.0 say....

The template for arate perf-pass opcodes is:

    int perf_myopcode(CSOUND *csound, MYOPCODE *p)
    {
        uint32_t offset = p->h.insdshead->ksmps_offset;
        uint32_t early  = p->h.insdshead->ksmps_no_end;
        uint32_t nsmps = CS_KSMPS;
        ...
        if (UNLIKELY(offset)) memset(p->res, '\0', offset*sizeof(MYFLT));
        if (UNLIKELY(early))  {
          nsmps -= early;
          memset(&p->res[nsmps], '\0', early*sizeof(MYFLT));
        }
        for (n=offset; n<nsmps; n++) {
            .....
            p->res[n] = ....
        }
        return OK;
    }



On Thu, 10 Dec 2015, Peter Burgess wrote:

Hi there, I am writing a new opcode for csound. I am using these two sources
as a guide...

http://www.csounds.com/manual/html/csound5extending.html
http://booki.flossmanuals.net/csound/extending-csound/

When showing how to write an opcode with an audio rate output, neither
tutorial initialises the output array to the size of ksmps before use. They
both instead just reference ksmps to control the array processing loop. Is the
array initialisation done automatically somewhere else in csound?

My opcode also uses two input audio rate arguments. Should I initialise the
arrays for them to ksmps size before use?

Next, I am wondering if all the arrays that I initialise in the _perform
function should actually be initialised in the _init function for speed.

I have attached my .h and .c files in one continuous file for reference. My
opcode's purpose is to take two input audio signals and bitwise-or them to get
the output audio signal (though I am guessing the results of bitwise
operations on floats won't be as linear as on ints, but I'm ok with that for
now :D ).




Date2015-12-10 17:35
Fromjpff
SubjectRe: [Csnd-dev] Writing a new opcode
LIKELY and UNLIKELY are just hints to te C compiler fot conditionals to 
indocate wich route is nost likely.  Can make a difference to speed. 
Ignore it until you understabd your code
==John

On Thu, 10 Dec 2015, Peter Burgess wrote:

> Excellent! Cheers.
> 
> Yeah I hadn't added the sample accurate business yet, I'll add that in now.
> What are the UNLIKELY() functions for?
> 
> On Thu, Dec 10, 2015 at 4:38 PM, jpff  wrote:
>       QUick look at the code -- this is corret except fot
>       --saple-accurate use
>
>       \Releasenore 6.0 say....
>
>       The template for arate perf-pass opcodes is:
>
>           int perf_myopcode(CSOUND *csound, MYOPCODE *p)
>           {
>               uint32_t offset = p->h.insdshead->ksmps_offset;
>               uint32_t early  = p->h.insdshead->ksmps_no_end;
>               uint32_t nsmps = CS_KSMPS;
>               ...
>               if (UNLIKELY(offset)) memset(p->res, '\0',
>       offset*sizeof(MYFLT));
>               if (UNLIKELY(early))  {
>                 nsmps -= early;
>                 memset(&p->res[nsmps], '\0', early*sizeof(MYFLT));
>               }
>               for (n=offset; n                   .....
>                   p->res[n] = ....
>               }
>               return OK;
>           }
> 
> 
>
>       On Thu, 10 Dec 2015, Peter Burgess wrote:
>
>             Hi there, I am writing a new opcode for csound. I am
>             using these two sources
>             as a guide...
>
>             http://www.csounds.com/manual/html/csound5extending.html
>             http://booki.flossmanuals.net/csound/extending-csound/
>
>             When showing how to write an opcode with an audio rate
>             output, neither
>             tutorial initialises the output array to the size of
>             ksmps before use. They
>             both instead just reference ksmps to control the array
>             processing loop. Is the
>             array initialisation done automatically somewhere else
>             in csound?
>
>             My opcode also uses two input audio rate arguments.
>             Should I initialise the
>             arrays for them to ksmps size before use?
>
>             Next, I am wondering if all the arrays that I
>             initialise in the _perform
>             function should actually be initialised in the _init
>             function for speed.
>
>             I have attached my .h and .c files in one continuous
>             file for reference. My
>             opcode's purpose is to take two input audio signals
>             and bitwise-or them to get
>             the output audio signal (though I am guessing the
>             results of bitwise
>             operations on floats won't be as linear as on ints,
>             but I'm ok with that for
>             now :D ).
> 
> 
> 
> 
>

Date2015-12-10 17:57
FromPeter Burgess
SubjectRe: [Csnd-dev] Writing a new opcode
Ok cool, cheers man!

On Thu, Dec 10, 2015 at 5:35 PM, jpff <jpff@codemist.co.uk> wrote:
LIKELY and UNLIKELY are just hints to te C compiler fot conditionals to indocate wich route is nost likely.  Can make a difference to speed. Ignore it until you understabd your code
==John


On Thu, 10 Dec 2015, Peter Burgess wrote:

Excellent! Cheers.

Yeah I hadn't added the sample accurate business yet, I'll add that in now.
What are the UNLIKELY() functions for?

On Thu, Dec 10, 2015 at 4:38 PM, jpff <jpff@codemist.co.uk> wrote:
      QUick look at the code -- this is corret except fot
      --saple-accurate use

      \Releasenore 6.0 say....

      The template for arate perf-pass opcodes is:

          int perf_myopcode(CSOUND *csound, MYOPCODE *p)
          {
              uint32_t offset = p->h.insdshead->ksmps_offset;
              uint32_t early  = p->h.insdshead->ksmps_no_end;
              uint32_t nsmps = CS_KSMPS;
              ...
              if (UNLIKELY(offset)) memset(p->res, '\0',
      offset*sizeof(MYFLT));
              if (UNLIKELY(early))  {
                nsmps -= early;
                memset(&p->res[nsmps], '\0', early*sizeof(MYFLT));
              }
              for (n=offset; n<nsmps; n++) {
                  .....
                  p->res[n] = ....
              }
              return OK;
          }



      On Thu, 10 Dec 2015, Peter Burgess wrote:

            Hi there, I am writing a new opcode for csound. I am
            using these two sources
            as a guide...

            http://www.csounds.com/manual/html/csound5extending.html
            http://booki.flossmanuals.net/csound/extending-csound/

            When showing how to write an opcode with an audio rate
            output, neither
            tutorial initialises the output array to the size of
            ksmps before use. They
            both instead just reference ksmps to control the array
            processing loop. Is the
            array initialisation done automatically somewhere else
            in csound?

            My opcode also uses two input audio rate arguments.
            Should I initialise the
            arrays for them to ksmps size before use?

            Next, I am wondering if all the arrays that I
            initialise in the _perform
            function should actually be initialised in the _init
            function for speed.

            I have attached my .h and .c files in one continuous
            file for reference. My
            opcode's purpose is to take two input audio signals
            and bitwise-or them to get
            the output audio signal (though I am guessing the
            results of bitwise
            operations on floats won't be as linear as on ints,
            but I'm ok with that for
            now :D ).






Date2015-12-10 18:56
FromPeter Burgess
SubjectRe: [Csnd-dev] Writing a new opcode
AttachmentsbitwiseOr.hc  
Ok, I have a further question...

Is it actually necessary to declare all internal variables in the header? Because the examples in the tutorials declare new internal variables within the functions body.

On Thu, Dec 10, 2015 at 5:57 PM, Peter Burgess <pete.soundtechnician@gmail.com> wrote:
Ok cool, cheers man!

On Thu, Dec 10, 2015 at 5:35 PM, jpff <jpff@codemist.co.uk> wrote:
LIKELY and UNLIKELY are just hints to te C compiler fot conditionals to indocate wich route is nost likely.  Can make a difference to speed. Ignore it until you understabd your code
==John


On Thu, 10 Dec 2015, Peter Burgess wrote:

Excellent! Cheers.

Yeah I hadn't added the sample accurate business yet, I'll add that in now.
What are the UNLIKELY() functions for?

On Thu, Dec 10, 2015 at 4:38 PM, jpff <jpff@codemist.co.uk> wrote:
      QUick look at the code -- this is corret except fot
      --saple-accurate use

      \Releasenore 6.0 say....

      The template for arate perf-pass opcodes is:

          int perf_myopcode(CSOUND *csound, MYOPCODE *p)
          {
              uint32_t offset = p->h.insdshead->ksmps_offset;
              uint32_t early  = p->h.insdshead->ksmps_no_end;
              uint32_t nsmps = CS_KSMPS;
              ...
              if (UNLIKELY(offset)) memset(p->res, '\0',
      offset*sizeof(MYFLT));
              if (UNLIKELY(early))  {
                nsmps -= early;
                memset(&p->res[nsmps], '\0', early*sizeof(MYFLT));
              }
              for (n=offset; n<nsmps; n++) {
                  .....
                  p->res[n] = ....
              }
              return OK;
          }



      On Thu, 10 Dec 2015, Peter Burgess wrote:

            Hi there, I am writing a new opcode for csound. I am
            using these two sources
            as a guide...

            http://www.csounds.com/manual/html/csound5extending.html
            http://booki.flossmanuals.net/csound/extending-csound/

            When showing how to write an opcode with an audio rate
            output, neither
            tutorial initialises the output array to the size of
            ksmps before use. They
            both instead just reference ksmps to control the array
            processing loop. Is the
            array initialisation done automatically somewhere else
            in csound?

            My opcode also uses two input audio rate arguments.
            Should I initialise the
            arrays for them to ksmps size before use?

            Next, I am wondering if all the arrays that I
            initialise in the _perform
            function should actually be initialised in the _init
            function for speed.

            I have attached my .h and .c files in one continuous
            file for reference. My
            opcode's purpose is to take two input audio signals
            and bitwise-or them to get
            the output audio signal (though I am guessing the
            results of bitwise
            operations on floats won't be as linear as on ints,
            but I'm ok with that for
            now :D ).







Date2015-12-11 11:51
Fromjpff
SubjectRe: [Csnd-dev] Writing a new opcode
If you want/eed the values to persist from kcycle to k-cycle they need to 
be in the structure.Oterwise they can be local.  It is lso common to copy 
struct fields to locals (look t the filters for this) bt that is fr 
ffciency.

I always told my studdents thta correcness was more important thn 
efficiency  well it is usually true!

==John

On Thu, 10 Dec 2015, Peter Burgess wrote:

> Ok, I have a further question...
> 
> Is it actually necessary to declare all internal variables in the header?
> Because the examples in the tutorials declare new internal variables within
> the functions body.
> 
> On Thu, Dec 10, 2015 at 5:57 PM, Peter Burgess
>  wrote:
>       Ok cool, cheers man!
> 
> On Thu, Dec 10, 2015 at 5:35 PM, jpff  wrote:
>       LIKELY and UNLIKELY are just hints to te C compiler fot
>       conditionals to indocate wich route is nost likely.  Can
>       make a difference to speed. Ignore it until you understabd
>       your code
>       ==John
>
>       On Thu, 10 Dec 2015, Peter Burgess wrote:
>
>             Excellent! Cheers.
>
>             Yeah I hadn't added the sample accurate
>             business yet, I'll add that in now.
>             What are the UNLIKELY() functions for?
>
>             On Thu, Dec 10, 2015 at 4:38 PM, jpff
>              wrote:
>                   QUick look at the code -- this is corret
>             except fot
>                   --saple-accurate use
>
>                   \Releasenore 6.0 say....
>
>                   The template for arate perf-pass opcodes
>             is:
>
>                       int perf_myopcode(CSOUND *csound,
>             MYOPCODE *p)
>                       {
>                           uint32_t offset =
>             p->h.insdshead->ksmps_offset;
>                           uint32_t early  =
>             p->h.insdshead->ksmps_no_end;
>                           uint32_t nsmps = CS_KSMPS;
>                           ...
>                           if (UNLIKELY(offset))
>             memset(p->res, '\0',
>                   offset*sizeof(MYFLT));
>                           if (UNLIKELY(early))  {
>                             nsmps -= early;
>                             memset(&p->res[nsmps], '\0',
>             early*sizeof(MYFLT));
>                           }
>                           for (n=offset; n                               .....
>                               p->res[n] = ....
>                           }
>                           return OK;
>                       }
> 
> 
>
>                   On Thu, 10 Dec 2015, Peter Burgess
>             wrote:
>
>                         Hi there, I am writing a new
>             opcode for csound. I am
>                         using these two sources
>                         as a guide...
>
>                        
>             http://www.csounds.com/manual/html/csound5extending.html
>                        
>             http://booki.flossmanuals.net/csound/extending-csound/
>
>                         When showing how to write an
>             opcode with an audio rate
>                         output, neither
>                         tutorial initialises the output
>             array to the size of
>                         ksmps before use. They
>                         both instead just reference ksmps
>             to control the array
>                         processing loop. Is the
>                         array initialisation done
>             automatically somewhere else
>                         in csound?
>
>                         My opcode also uses two input
>             audio rate arguments.
>                         Should I initialise the
>                         arrays for them to ksmps size
>             before use?
>
>                         Next, I am wondering if all the
>             arrays that I
>                         initialise in the _perform
>                         function should actually be
>             initialised in the _init
>                         function for speed.
>
>                         I have attached my .h and .c files
>             in one continuous
>                         file for reference. My
>                         opcode's purpose is to take two
>             input audio signals
>                         and bitwise-or them to get
>                         the output audio signal (though I
>             am guessing the
>                         results of bitwise
>                         operations on floats won't be as
>             linear as on ints,
>                         but I'm ok with that for
>                         now :D ).
> 
> 
> 
> 
> 
> 
> 
>

Date2015-12-11 17:27
FromPeter Burgess
SubjectRe: [Csnd-dev] Writing a new opcode
ok cool, cheers for the advice.

On Fri, Dec 11, 2015 at 11:51 AM, jpff <jpff@codemist.co.uk> wrote:
If you want/eed the values to persist from kcycle to k-cycle they need to be in the structure.Oterwise they can be local.  It is lso common to copy struct fields to locals (look t the filters for this) bt that is fr ffciency.

I always told my studdents thta correcness was more important thn efficiency  well it is usually true!


==John

On Thu, 10 Dec 2015, Peter Burgess wrote:

Ok, I have a further question...

Is it actually necessary to declare all internal variables in the header?
Because the examples in the tutorials declare new internal variables within
the functions body.

On Thu, Dec 10, 2015 at 5:57 PM, Peter Burgess
<pete.soundtechnician@gmail.com> wrote:
      Ok cool, cheers man!

On Thu, Dec 10, 2015 at 5:35 PM, jpff <jpff@codemist.co.uk> wrote:
      LIKELY and UNLIKELY are just hints to te C compiler fot
      conditionals to indocate wich route is nost likely.  Can
      make a difference to speed. Ignore it until you understabd
      your code
      ==John

      On Thu, 10 Dec 2015, Peter Burgess wrote:

            Excellent! Cheers.

            Yeah I hadn't added the sample accurate
            business yet, I'll add that in now.
            What are the UNLIKELY() functions for?

            On Thu, Dec 10, 2015 at 4:38 PM, jpff
            <jpff@codemist.co.uk> wrote:
                  QUick look at the code -- this is corret
            except fot
                  --saple-accurate use

                  \Releasenore 6.0 say....

                  The template for arate perf-pass opcodes
            is:

                      int perf_myopcode(CSOUND *csound,
            MYOPCODE *p)
                      {
                          uint32_t offset =
            p->h.insdshead->ksmps_offset;
                          uint32_t early  =
            p->h.insdshead->ksmps_no_end;
                          uint32_t nsmps = CS_KSMPS;
                          ...
                          if (UNLIKELY(offset))
            memset(p->res, '\0',
                  offset*sizeof(MYFLT));
                          if (UNLIKELY(early))  {
                            nsmps -= early;
                            memset(&p->res[nsmps], '\0',
            early*sizeof(MYFLT));
                          }
                          for (n=offset; n<nsmps; n++) {
                              .....
                              p->res[n] = ....
                          }
                          return OK;
                      }



                  On Thu, 10 Dec 2015, Peter Burgess
            wrote:

                        Hi there, I am writing a new
            opcode for csound. I am
                        using these two sources
                        as a guide...

                       
            http://www.csounds.com/manual/html/csound5extending.html
                       
            http://booki.flossmanuals.net/csound/extending-csound/

                        When showing how to write an
            opcode with an audio rate
                        output, neither
                        tutorial initialises the output
            array to the size of
                        ksmps before use. They
                        both instead just reference ksmps
            to control the array
                        processing loop. Is the
                        array initialisation done
            automatically somewhere else
                        in csound?

                        My opcode also uses two input
            audio rate arguments.
                        Should I initialise the
                        arrays for them to ksmps size
            before use?

                        Next, I am wondering if all the
            arrays that I
                        initialise in the _perform
                        function should actually be
            initialised in the _init
                        function for speed.

                        I have attached my .h and .c files
            in one continuous
                        file for reference. My
                        opcode's purpose is to take two
            input audio signals
                        and bitwise-or them to get
                        the output audio signal (though I
            am guessing the
                        results of bitwise
                        operations on floats won't be as
            linear as on ints,
                        but I'm ok with that for
                        now :D ).









Date2015-12-13 12:51
FromPeter Burgess
SubjectRe: [Csnd-dev] Writing a new opcode
I decided to make a copy of csound to add my opcode to, so I keep an original untouched version. But how do I get terminal and QT to point to the correct one? I assume there's just an envirenment variable stored on my system somewhere.

I've tried to work it out from this before:

http://www.csounds.com/manual/html/CommandEnvironment.html

but it says to use the PATH command in terminal to set it. This seems like a fairly ambiguous command to use without already being within a csound context though. I was hoping just typing csound --env:PATH="my/path" might do it, but it doesn't seem to.


On Fri, Dec 11, 2015 at 5:27 PM, Peter Burgess <pete.soundtechnician@gmail.com> wrote:
ok cool, cheers for the advice.

On Fri, Dec 11, 2015 at 11:51 AM, jpff <jpff@codemist.co.uk> wrote:
If you want/eed the values to persist from kcycle to k-cycle they need to be in the structure.Oterwise they can be local.  It is lso common to copy struct fields to locals (look t the filters for this) bt that is fr ffciency.

I always told my studdents thta correcness was more important thn efficiency  well it is usually true!


==John

On Thu, 10 Dec 2015, Peter Burgess wrote:

Ok, I have a further question...

Is it actually necessary to declare all internal variables in the header?
Because the examples in the tutorials declare new internal variables within
the functions body.

On Thu, Dec 10, 2015 at 5:57 PM, Peter Burgess
<pete.soundtechnician@gmail.com> wrote:
      Ok cool, cheers man!

On Thu, Dec 10, 2015 at 5:35 PM, jpff <jpff@codemist.co.uk> wrote:
      LIKELY and UNLIKELY are just hints to te C compiler fot
      conditionals to indocate wich route is nost likely.  Can
      make a difference to speed. Ignore it until you understabd
      your code
      ==John

      On Thu, 10 Dec 2015, Peter Burgess wrote:

            Excellent! Cheers.

            Yeah I hadn't added the sample accurate
            business yet, I'll add that in now.
            What are the UNLIKELY() functions for?

            On Thu, Dec 10, 2015 at 4:38 PM, jpff
            <jpff@codemist.co.uk> wrote:
                  QUick look at the code -- this is corret
            except fot
                  --saple-accurate use

                  \Releasenore 6.0 say....

                  The template for arate perf-pass opcodes
            is:

                      int perf_myopcode(CSOUND *csound,
            MYOPCODE *p)
                      {
                          uint32_t offset =
            p->h.insdshead->ksmps_offset;
                          uint32_t early  =
            p->h.insdshead->ksmps_no_end;
                          uint32_t nsmps = CS_KSMPS;
                          ...
                          if (UNLIKELY(offset))
            memset(p->res, '\0',
                  offset*sizeof(MYFLT));
                          if (UNLIKELY(early))  {
                            nsmps -= early;
                            memset(&p->res[nsmps], '\0',
            early*sizeof(MYFLT));
                          }
                          for (n=offset; n<nsmps; n++) {
                              .....
                              p->res[n] = ....
                          }
                          return OK;
                      }



                  On Thu, 10 Dec 2015, Peter Burgess
            wrote:

                        Hi there, I am writing a new
            opcode for csound. I am
                        using these two sources
                        as a guide...

                       
            http://www.csounds.com/manual/html/csound5extending.html
                       
            http://booki.flossmanuals.net/csound/extending-csound/

                        When showing how to write an
            opcode with an audio rate
                        output, neither
                        tutorial initialises the output
            array to the size of
                        ksmps before use. They
                        both instead just reference ksmps
            to control the array
                        processing loop. Is the
                        array initialisation done
            automatically somewhere else
                        in csound?

                        My opcode also uses two input
            audio rate arguments.
                        Should I initialise the
                        arrays for them to ksmps size
            before use?

                        Next, I am wondering if all the
            arrays that I
                        initialise in the _perform
                        function should actually be
            initialised in the _init
                        function for speed.

                        I have attached my .h and .c files
            in one continuous
                        file for reference. My
                        opcode's purpose is to take two
            input audio signals
                        and bitwise-or them to get
                        the output audio signal (though I
            am guessing the
                        results of bitwise
                        operations on floats won't be as
            linear as on ints,
                        but I'm ok with that for
                        now :D ).










Date2015-12-13 12:52
FromPeter Burgess
SubjectRe: [Csnd-dev] Writing a new opcode
Oh yeah, probably worth mentioning I'm on ubuntu 14.04

On Sun, Dec 13, 2015 at 12:51 PM, Peter Burgess <pete.soundtechnician@gmail.com> wrote:
I decided to make a copy of csound to add my opcode to, so I keep an original untouched version. But how do I get terminal and QT to point to the correct one? I assume there's just an envirenment variable stored on my system somewhere.

I've tried to work it out from this before:

http://www.csounds.com/manual/html/CommandEnvironment.html

but it says to use the PATH command in terminal to set it. This seems like a fairly ambiguous command to use without already being within a csound context though. I was hoping just typing csound --env:PATH="my/path" might do it, but it doesn't seem to.


On Fri, Dec 11, 2015 at 5:27 PM, Peter Burgess <pete.soundtechnician@gmail.com> wrote:
ok cool, cheers for the advice.

On Fri, Dec 11, 2015 at 11:51 AM, jpff <jpff@codemist.co.uk> wrote:
If you want/eed the values to persist from kcycle to k-cycle they need to be in the structure.Oterwise they can be local.  It is lso common to copy struct fields to locals (look t the filters for this) bt that is fr ffciency.

I always told my studdents thta correcness was more important thn efficiency  well it is usually true!


==John

On Thu, 10 Dec 2015, Peter Burgess wrote:

Ok, I have a further question...

Is it actually necessary to declare all internal variables in the header?
Because the examples in the tutorials declare new internal variables within
the functions body.

On Thu, Dec 10, 2015 at 5:57 PM, Peter Burgess
<pete.soundtechnician@gmail.com> wrote:
      Ok cool, cheers man!

On Thu, Dec 10, 2015 at 5:35 PM, jpff <jpff@codemist.co.uk> wrote:
      LIKELY and UNLIKELY are just hints to te C compiler fot
      conditionals to indocate wich route is nost likely.  Can
      make a difference to speed. Ignore it until you understabd
      your code
      ==John

      On Thu, 10 Dec 2015, Peter Burgess wrote:

            Excellent! Cheers.

            Yeah I hadn't added the sample accurate
            business yet, I'll add that in now.
            What are the UNLIKELY() functions for?

            On Thu, Dec 10, 2015 at 4:38 PM, jpff
            <jpff@codemist.co.uk> wrote:
                  QUick look at the code -- this is corret
            except fot
                  --saple-accurate use

                  \Releasenore 6.0 say....

                  The template for arate perf-pass opcodes
            is:

                      int perf_myopcode(CSOUND *csound,
            MYOPCODE *p)
                      {
                          uint32_t offset =
            p->h.insdshead->ksmps_offset;
                          uint32_t early  =
            p->h.insdshead->ksmps_no_end;
                          uint32_t nsmps = CS_KSMPS;
                          ...
                          if (UNLIKELY(offset))
            memset(p->res, '\0',
                  offset*sizeof(MYFLT));
                          if (UNLIKELY(early))  {
                            nsmps -= early;
                            memset(&p->res[nsmps], '\0',
            early*sizeof(MYFLT));
                          }
                          for (n=offset; n<nsmps; n++) {
                              .....
                              p->res[n] = ....
                          }
                          return OK;
                      }



                  On Thu, 10 Dec 2015, Peter Burgess
            wrote:

                        Hi there, I am writing a new
            opcode for csound. I am
                        using these two sources
                        as a guide...

                       
            http://www.csounds.com/manual/html/csound5extending.html
                       
            http://booki.flossmanuals.net/csound/extending-csound/

                        When showing how to write an
            opcode with an audio rate
                        output, neither
                        tutorial initialises the output
            array to the size of
                        ksmps before use. They
                        both instead just reference ksmps
            to control the array
                        processing loop. Is the
                        array initialisation done
            automatically somewhere else
                        in csound?

                        My opcode also uses two input
            audio rate arguments.
                        Should I initialise the
                        arrays for them to ksmps size
            before use?

                        Next, I am wondering if all the
            arrays that I
                        initialise in the _perform
                        function should actually be
            initialised in the _init
                        function for speed.

                        I have attached my .h and .c files
            in one continuous
                        file for reference. My
                        opcode's purpose is to take two
            input audio signals
                        and bitwise-or them to get
                        the output audio signal (though I
            am guessing the
                        results of bitwise
                        operations on floats won't be as
            linear as on ints,
                        but I'm ok with that for
                        now :D ).











Date2015-12-13 13:06
FromRory Walsh
SubjectRe: [Csnd-dev] Writing a new opcode
Why are you making a copy? 

On 13 December 2015 at 12:51, Peter Burgess <pete.soundtechnician@gmail.com> wrote:
I decided to make a copy of csound to add my opcode to, so I keep an original untouched version. But how do I get terminal and QT to point to the correct one? I assume there's just an envirenment variable stored on my system somewhere.

I've tried to work it out from this before:

http://www.csounds.com/manual/html/CommandEnvironment.html

but it says to use the PATH command in terminal to set it. This seems like a fairly ambiguous command to use without already being within a csound context though. I was hoping just typing csound --env:PATH="my/path" might do it, but it doesn't seem to.


On Fri, Dec 11, 2015 at 5:27 PM, Peter Burgess <pete.soundtechnician@gmail.com> wrote:
ok cool, cheers for the advice.

On Fri, Dec 11, 2015 at 11:51 AM, jpff <jpff@codemist.co.uk> wrote:
If you want/eed the values to persist from kcycle to k-cycle they need to be in the structure.Oterwise they can be local.  It is lso common to copy struct fields to locals (look t the filters for this) bt that is fr ffciency.

I always told my studdents thta correcness was more important thn efficiency  well it is usually true!


==John

On Thu, 10 Dec 2015, Peter Burgess wrote:

Ok, I have a further question...

Is it actually necessary to declare all internal variables in the header?
Because the examples in the tutorials declare new internal variables within
the functions body.

On Thu, Dec 10, 2015 at 5:57 PM, Peter Burgess
<pete.soundtechnician@gmail.com> wrote:
      Ok cool, cheers man!

On Thu, Dec 10, 2015 at 5:35 PM, jpff <jpff@codemist.co.uk> wrote:
      LIKELY and UNLIKELY are just hints to te C compiler fot
      conditionals to indocate wich route is nost likely.  Can
      make a difference to speed. Ignore it until you understabd
      your code
      ==John

      On Thu, 10 Dec 2015, Peter Burgess wrote:

            Excellent! Cheers.

            Yeah I hadn't added the sample accurate
            business yet, I'll add that in now.
            What are the UNLIKELY() functions for?

            On Thu, Dec 10, 2015 at 4:38 PM, jpff
            <jpff@codemist.co.uk> wrote:
                  QUick look at the code -- this is corret
            except fot
                  --saple-accurate use

                  \Releasenore 6.0 say....

                  The template for arate perf-pass opcodes
            is:

                      int perf_myopcode(CSOUND *csound,
            MYOPCODE *p)
                      {
                          uint32_t offset =
            p->h.insdshead->ksmps_offset;
                          uint32_t early  =
            p->h.insdshead->ksmps_no_end;
                          uint32_t nsmps = CS_KSMPS;
                          ...
                          if (UNLIKELY(offset))
            memset(p->res, '\0',
                  offset*sizeof(MYFLT));
                          if (UNLIKELY(early))  {
                            nsmps -= early;
                            memset(&p->res[nsmps], '\0',
            early*sizeof(MYFLT));
                          }
                          for (n=offset; n<nsmps; n++) {
                              .....
                              p->res[n] = ....
                          }
                          return OK;
                      }



                  On Thu, 10 Dec 2015, Peter Burgess
            wrote:

                        Hi there, I am writing a new
            opcode for csound. I am
                        using these two sources
                        as a guide...

                       
            http://www.csounds.com/manual/html/csound5extending.html
                       
            http://booki.flossmanuals.net/csound/extending-csound/

                        When showing how to write an
            opcode with an audio rate
                        output, neither
                        tutorial initialises the output
            array to the size of
                        ksmps before use. They
                        both instead just reference ksmps
            to control the array
                        processing loop. Is the
                        array initialisation done
            automatically somewhere else
                        in csound?

                        My opcode also uses two input
            audio rate arguments.
                        Should I initialise the
                        arrays for them to ksmps size
            before use?

                        Next, I am wondering if all the
            arrays that I
                        initialise in the _perform
                        function should actually be
            initialised in the _init
                        function for speed.

                        I have attached my .h and .c files
            in one continuous
                        file for reference. My
                        opcode's purpose is to take two
            input audio signals
                        and bitwise-or them to get
                        the output audio signal (though I
            am guessing the
                        results of bitwise
                        operations on floats won't be as
            linear as on ints,
                        but I'm ok with that for
                        now :D ).











Date2015-12-13 13:15
FromRory Walsh
SubjectRe: [Csnd-dev] Writing a new opcode
I mean there is absolutely no need to do this. If you are modifying any of Csound's files then you need to stop because that's not right. 

On 13 December 2015 at 13:06, Rory Walsh <rorywalsh@ear.ie> wrote:
Why are you making a copy? 

On 13 December 2015 at 12:51, Peter Burgess <pete.soundtechnician@gmail.com> wrote:
I decided to make a copy of csound to add my opcode to, so I keep an original untouched version. But how do I get terminal and QT to point to the correct one? I assume there's just an envirenment variable stored on my system somewhere.

I've tried to work it out from this before:

http://www.csounds.com/manual/html/CommandEnvironment.html

but it says to use the PATH command in terminal to set it. This seems like a fairly ambiguous command to use without already being within a csound context though. I was hoping just typing csound --env:PATH="my/path" might do it, but it doesn't seem to.


On Fri, Dec 11, 2015 at 5:27 PM, Peter Burgess <pete.soundtechnician@gmail.com> wrote:
ok cool, cheers for the advice.

On Fri, Dec 11, 2015 at 11:51 AM, jpff <jpff@codemist.co.uk> wrote:
If you want/eed the values to persist from kcycle to k-cycle they need to be in the structure.Oterwise they can be local.  It is lso common to copy struct fields to locals (look t the filters for this) bt that is fr ffciency.

I always told my studdents thta correcness was more important thn efficiency  well it is usually true!


==John

On Thu, 10 Dec 2015, Peter Burgess wrote:

Ok, I have a further question...

Is it actually necessary to declare all internal variables in the header?
Because the examples in the tutorials declare new internal variables within
the functions body.

On Thu, Dec 10, 2015 at 5:57 PM, Peter Burgess
<pete.soundtechnician@gmail.com> wrote:
      Ok cool, cheers man!

On Thu, Dec 10, 2015 at 5:35 PM, jpff <jpff@codemist.co.uk> wrote:
      LIKELY and UNLIKELY are just hints to te C compiler fot
      conditionals to indocate wich route is nost likely.  Can
      make a difference to speed. Ignore it until you understabd
      your code
      ==John

      On Thu, 10 Dec 2015, Peter Burgess wrote:

            Excellent! Cheers.

            Yeah I hadn't added the sample accurate
            business yet, I'll add that in now.
            What are the UNLIKELY() functions for?

            On Thu, Dec 10, 2015 at 4:38 PM, jpff
            <jpff@codemist.co.uk> wrote:
                  QUick look at the code -- this is corret
            except fot
                  --saple-accurate use

                  \Releasenore 6.0 say....

                  The template for arate perf-pass opcodes
            is:

                      int perf_myopcode(CSOUND *csound,
            MYOPCODE *p)
                      {
                          uint32_t offset =
            p->h.insdshead->ksmps_offset;
                          uint32_t early  =
            p->h.insdshead->ksmps_no_end;
                          uint32_t nsmps = CS_KSMPS;
                          ...
                          if (UNLIKELY(offset))
            memset(p->res, '\0',
                  offset*sizeof(MYFLT));
                          if (UNLIKELY(early))  {
                            nsmps -= early;
                            memset(&p->res[nsmps], '\0',
            early*sizeof(MYFLT));
                          }
                          for (n=offset; n<nsmps; n++) {
                              .....
                              p->res[n] = ....
                          }
                          return OK;
                      }



                  On Thu, 10 Dec 2015, Peter Burgess
            wrote:

                        Hi there, I am writing a new
            opcode for csound. I am
                        using these two sources
                        as a guide...

                       
            http://www.csounds.com/manual/html/csound5extending.html
                       
            http://booki.flossmanuals.net/csound/extending-csound/

                        When showing how to write an
            opcode with an audio rate
                        output, neither
                        tutorial initialises the output
            array to the size of
                        ksmps before use. They
                        both instead just reference ksmps
            to control the array
                        processing loop. Is the
                        array initialisation done
            automatically somewhere else
                        in csound?

                        My opcode also uses two input
            audio rate arguments.
                        Should I initialise the
                        arrays for them to ksmps size
            before use?

                        Next, I am wondering if all the
            arrays that I
                        initialise in the _perform
                        function should actually be
            initialised in the _init
                        function for speed.

                        I have attached my .h and .c files
            in one continuous
                        file for reference. My
                        opcode's purpose is to take two
            input audio signals
                        and bitwise-or them to get
                        the output audio signal (though I
            am guessing the
                        results of bitwise
                        operations on floats won't be as
            linear as on ints,
                        but I'm ok with that for
                        now :D ).












Date2015-12-13 13:18
FromPeter Burgess
SubjectRe: [Csnd-dev] Writing a new opcode
Just feels right to keep a clean copy before I tamper with it.

To add a new opcode though, I have to add it to entry1.c right?

On Sun, Dec 13, 2015 at 1:15 PM, Rory Walsh <rorywalsh@ear.ie> wrote:
I mean there is absolutely no need to do this. If you are modifying any of Csound's files then you need to stop because that's not right. 

On 13 December 2015 at 13:06, Rory Walsh <rorywalsh@ear.ie> wrote:
Why are you making a copy? 

On 13 December 2015 at 12:51, Peter Burgess <pete.soundtechnician@gmail.com> wrote:
I decided to make a copy of csound to add my opcode to, so I keep an original untouched version. But how do I get terminal and QT to point to the correct one? I assume there's just an envirenment variable stored on my system somewhere.

I've tried to work it out from this before:

http://www.csounds.com/manual/html/CommandEnvironment.html

but it says to use the PATH command in terminal to set it. This seems like a fairly ambiguous command to use without already being within a csound context though. I was hoping just typing csound --env:PATH="my/path" might do it, but it doesn't seem to.


On Fri, Dec 11, 2015 at 5:27 PM, Peter Burgess <pete.soundtechnician@gmail.com> wrote:
ok cool, cheers for the advice.

On Fri, Dec 11, 2015 at 11:51 AM, jpff <jpff@codemist.co.uk> wrote:
If you want/eed the values to persist from kcycle to k-cycle they need to be in the structure.Oterwise they can be local.  It is lso common to copy struct fields to locals (look t the filters for this) bt that is fr ffciency.

I always told my studdents thta correcness was more important thn efficiency  well it is usually true!


==John

On Thu, 10 Dec 2015, Peter Burgess wrote:

Ok, I have a further question...

Is it actually necessary to declare all internal variables in the header?
Because the examples in the tutorials declare new internal variables within
the functions body.

On Thu, Dec 10, 2015 at 5:57 PM, Peter Burgess
<pete.soundtechnician@gmail.com> wrote:
      Ok cool, cheers man!

On Thu, Dec 10, 2015 at 5:35 PM, jpff <jpff@codemist.co.uk> wrote:
      LIKELY and UNLIKELY are just hints to te C compiler fot
      conditionals to indocate wich route is nost likely.  Can
      make a difference to speed. Ignore it until you understabd
      your code
      ==John

      On Thu, 10 Dec 2015, Peter Burgess wrote:

            Excellent! Cheers.

            Yeah I hadn't added the sample accurate
            business yet, I'll add that in now.
            What are the UNLIKELY() functions for?

            On Thu, Dec 10, 2015 at 4:38 PM, jpff
            <jpff@codemist.co.uk> wrote:
                  QUick look at the code -- this is corret
            except fot
                  --saple-accurate use

                  \Releasenore 6.0 say....

                  The template for arate perf-pass opcodes
            is:

                      int perf_myopcode(CSOUND *csound,
            MYOPCODE *p)
                      {
                          uint32_t offset =
            p->h.insdshead->ksmps_offset;
                          uint32_t early  =
            p->h.insdshead->ksmps_no_end;
                          uint32_t nsmps = CS_KSMPS;
                          ...
                          if (UNLIKELY(offset))
            memset(p->res, '\0',
                  offset*sizeof(MYFLT));
                          if (UNLIKELY(early))  {
                            nsmps -= early;
                            memset(&p->res[nsmps], '\0',
            early*sizeof(MYFLT));
                          }
                          for (n=offset; n<nsmps; n++) {
                              .....
                              p->res[n] = ....
                          }
                          return OK;
                      }



                  On Thu, 10 Dec 2015, Peter Burgess
            wrote:

                        Hi there, I am writing a new
            opcode for csound. I am
                        using these two sources
                        as a guide...

                       
            http://www.csounds.com/manual/html/csound5extending.html
                       
            http://booki.flossmanuals.net/csound/extending-csound/

                        When showing how to write an
            opcode with an audio rate
                        output, neither
                        tutorial initialises the output
            array to the size of
                        ksmps before use. They
                        both instead just reference ksmps
            to control the array
                        processing loop. Is the
                        array initialisation done
            automatically somewhere else
                        in csound?

                        My opcode also uses two input
            audio rate arguments.
                        Should I initialise the
                        arrays for them to ksmps size
            before use?

                        Next, I am wondering if all the
            arrays that I
                        initialise in the _perform
                        function should actually be
            initialised in the _init
                        function for speed.

                        I have attached my .h and .c files
            in one continuous
                        file for reference. My
                        opcode's purpose is to take two
            input audio signals
                        and bitwise-or them to get
                        the output audio signal (though I
            am guessing the
                        results of bitwise
                        operations on floats won't be as
            linear as on ints,
                        but I'm ok with that for
                        now :D ).













Date2015-12-13 13:23
FromRory Walsh
SubjectRe: [Csnd-dev] Writing a new opcode
It's been a while since I've done this, but I don't think so? Others can confirm. What I usually do is simply add my source .cpp to the Opcodes dir. Then I add a call to make_plugin()  to Opcodes/CMakeLists.txt:

make_plugin(myplugin myplugin.cpp)

Then I just run make in the Csound build dir. This should take of everything. You shouldn't ever have to mess with any of Csound's code files. That was the original idea behind the development of plugin opcodes.  


On 13 December 2015 at 13:18, Peter Burgess <pete.soundtechnician@gmail.com> wrote:
Just feels right to keep a clean copy before I tamper with it.

To add a new opcode though, I have to add it to entry1.c right?

On Sun, Dec 13, 2015 at 1:15 PM, Rory Walsh <rorywalsh@ear.ie> wrote:
I mean there is absolutely no need to do this. If you are modifying any of Csound's files then you need to stop because that's not right. 

On 13 December 2015 at 13:06, Rory Walsh <rorywalsh@ear.ie> wrote:
Why are you making a copy? 

On 13 December 2015 at 12:51, Peter Burgess <pete.soundtechnician@gmail.com> wrote:
I decided to make a copy of csound to add my opcode to, so I keep an original untouched version. But how do I get terminal and QT to point to the correct one? I assume there's just an envirenment variable stored on my system somewhere.

I've tried to work it out from this before:

http://www.csounds.com/manual/html/CommandEnvironment.html

but it says to use the PATH command in terminal to set it. This seems like a fairly ambiguous command to use without already being within a csound context though. I was hoping just typing csound --env:PATH="my/path" might do it, but it doesn't seem to.


On Fri, Dec 11, 2015 at 5:27 PM, Peter Burgess <pete.soundtechnician@gmail.com> wrote:
ok cool, cheers for the advice.

On Fri, Dec 11, 2015 at 11:51 AM, jpff <jpff@codemist.co.uk> wrote:
If you want/eed the values to persist from kcycle to k-cycle they need to be in the structure.Oterwise they can be local.  It is lso common to copy struct fields to locals (look t the filters for this) bt that is fr ffciency.

I always told my studdents thta correcness was more important thn efficiency  well it is usually true!


==John

On Thu, 10 Dec 2015, Peter Burgess wrote:

Ok, I have a further question...

Is it actually necessary to declare all internal variables in the header?
Because the examples in the tutorials declare new internal variables within
the functions body.

On Thu, Dec 10, 2015 at 5:57 PM, Peter Burgess
<pete.soundtechnician@gmail.com> wrote:
      Ok cool, cheers man!

On Thu, Dec 10, 2015 at 5:35 PM, jpff <jpff@codemist.co.uk> wrote:
      LIKELY and UNLIKELY are just hints to te C compiler fot
      conditionals to indocate wich route is nost likely.  Can
      make a difference to speed. Ignore it until you understabd
      your code
      ==John

      On Thu, 10 Dec 2015, Peter Burgess wrote:

            Excellent! Cheers.

            Yeah I hadn't added the sample accurate
            business yet, I'll add that in now.
            What are the UNLIKELY() functions for?

            On Thu, Dec 10, 2015 at 4:38 PM, jpff
            <jpff@codemist.co.uk> wrote:
                  QUick look at the code -- this is corret
            except fot
                  --saple-accurate use

                  \Releasenore 6.0 say....

                  The template for arate perf-pass opcodes
            is:

                      int perf_myopcode(CSOUND *csound,
            MYOPCODE *p)
                      {
                          uint32_t offset =
            p->h.insdshead->ksmps_offset;
                          uint32_t early  =
            p->h.insdshead->ksmps_no_end;
                          uint32_t nsmps = CS_KSMPS;
                          ...
                          if (UNLIKELY(offset))
            memset(p->res, '\0',
                  offset*sizeof(MYFLT));
                          if (UNLIKELY(early))  {
                            nsmps -= early;
                            memset(&p->res[nsmps], '\0',
            early*sizeof(MYFLT));
                          }
                          for (n=offset; n<nsmps; n++) {
                              .....
                              p->res[n] = ....
                          }
                          return OK;
                      }



                  On Thu, 10 Dec 2015, Peter Burgess
            wrote:

                        Hi there, I am writing a new
            opcode for csound. I am
                        using these two sources
                        as a guide...

                       
            http://www.csounds.com/manual/html/csound5extending.html
                       
            http://booki.flossmanuals.net/csound/extending-csound/

                        When showing how to write an
            opcode with an audio rate
                        output, neither
                        tutorial initialises the output
            array to the size of
                        ksmps before use. They
                        both instead just reference ksmps
            to control the array
                        processing loop. Is the
                        array initialisation done
            automatically somewhere else
                        in csound?

                        My opcode also uses two input
            audio rate arguments.
                        Should I initialise the
                        arrays for them to ksmps size
            before use?

                        Next, I am wondering if all the
            arrays that I
                        initialise in the _perform
                        function should actually be
            initialised in the _init
                        function for speed.

                        I have attached my .h and .c files
            in one continuous
                        file for reference. My
                        opcode's purpose is to take two
            input audio signals
                        and bitwise-or them to get
                        the output audio signal (though I
            am guessing the
                        results of bitwise
                        operations on floats won't be as
            linear as on ints,
                        but I'm ok with that for
                        now :D ).














Date2015-12-13 13:32
FromPeter Burgess
SubjectRe: [Csnd-dev] Writing a new opcode
Ah right. I've just realised where I've gone wrong. I've added this to the entry1.c file:

static OENTRY localops[] = {
{ "newopc", sizeof(newopc), 0, 7, "s", "kki",(SUBR) newopc_init,
(SUBR) newopc_process_control, (SUBR) newopc_process_audio }
};

LINKAGE

But I think that was something I read in an older resource that required you to rebuild csound to add new opcodes. I've just read that this should actually go at the end of my c code.

I'll give your suggestion a try.

Cheers!


On Sun, Dec 13, 2015 at 1:23 PM, Rory Walsh <rorywalsh@ear.ie> wrote:
It's been a while since I've done this, but I don't think so? Others can confirm. What I usually do is simply add my source .cpp to the Opcodes dir. Then I add a call to make_plugin()  to Opcodes/CMakeLists.txt:

make_plugin(myplugin myplugin.cpp)

Then I just run make in the Csound build dir. This should take of everything. You shouldn't ever have to mess with any of Csound's code files. That was the original idea behind the development of plugin opcodes.  


On 13 December 2015 at 13:18, Peter Burgess <pete.soundtechnician@gmail.com> wrote:
Just feels right to keep a clean copy before I tamper with it.

To add a new opcode though, I have to add it to entry1.c right?

On Sun, Dec 13, 2015 at 1:15 PM, Rory Walsh <rorywalsh@ear.ie> wrote:
I mean there is absolutely no need to do this. If you are modifying any of Csound's files then you need to stop because that's not right. 

On 13 December 2015 at 13:06, Rory Walsh <rorywalsh@ear.ie> wrote:
Why are you making a copy? 

On 13 December 2015 at 12:51, Peter Burgess <pete.soundtechnician@gmail.com> wrote:
I decided to make a copy of csound to add my opcode to, so I keep an original untouched version. But how do I get terminal and QT to point to the correct one? I assume there's just an envirenment variable stored on my system somewhere.

I've tried to work it out from this before:

http://www.csounds.com/manual/html/CommandEnvironment.html

but it says to use the PATH command in terminal to set it. This seems like a fairly ambiguous command to use without already being within a csound context though. I was hoping just typing csound --env:PATH="my/path" might do it, but it doesn't seem to.


On Fri, Dec 11, 2015 at 5:27 PM, Peter Burgess <pete.soundtechnician@gmail.com> wrote:
ok cool, cheers for the advice.

On Fri, Dec 11, 2015 at 11:51 AM, jpff <jpff@codemist.co.uk> wrote:
If you want/eed the values to persist from kcycle to k-cycle they need to be in the structure.Oterwise they can be local.  It is lso common to copy struct fields to locals (look t the filters for this) bt that is fr ffciency.

I always told my studdents thta correcness was more important thn efficiency  well it is usually true!


==John

On Thu, 10 Dec 2015, Peter Burgess wrote:

Ok, I have a further question...

Is it actually necessary to declare all internal variables in the header?
Because the examples in the tutorials declare new internal variables within
the functions body.

On Thu, Dec 10, 2015 at 5:57 PM, Peter Burgess
<pete.soundtechnician@gmail.com> wrote:
      Ok cool, cheers man!

On Thu, Dec 10, 2015 at 5:35 PM, jpff <jpff@codemist.co.uk> wrote:
      LIKELY and UNLIKELY are just hints to te C compiler fot
      conditionals to indocate wich route is nost likely.  Can
      make a difference to speed. Ignore it until you understabd
      your code
      ==John

      On Thu, 10 Dec 2015, Peter Burgess wrote:

            Excellent! Cheers.

            Yeah I hadn't added the sample accurate
            business yet, I'll add that in now.
            What are the UNLIKELY() functions for?

            On Thu, Dec 10, 2015 at 4:38 PM, jpff
            <jpff@codemist.co.uk> wrote:
                  QUick look at the code -- this is corret
            except fot
                  --saple-accurate use

                  \Releasenore 6.0 say....

                  The template for arate perf-pass opcodes
            is:

                      int perf_myopcode(CSOUND *csound,
            MYOPCODE *p)
                      {
                          uint32_t offset =
            p->h.insdshead->ksmps_offset;
                          uint32_t early  =
            p->h.insdshead->ksmps_no_end;
                          uint32_t nsmps = CS_KSMPS;
                          ...
                          if (UNLIKELY(offset))
            memset(p->res, '\0',
                  offset*sizeof(MYFLT));
                          if (UNLIKELY(early))  {
                            nsmps -= early;
                            memset(&p->res[nsmps], '\0',
            early*sizeof(MYFLT));
                          }
                          for (n=offset; n<nsmps; n++) {
                              .....
                              p->res[n] = ....
                          }
                          return OK;
                      }



                  On Thu, 10 Dec 2015, Peter Burgess
            wrote:

                        Hi there, I am writing a new
            opcode for csound. I am
                        using these two sources
                        as a guide...

                       
            http://www.csounds.com/manual/html/csound5extending.html
                       
            http://booki.flossmanuals.net/csound/extending-csound/

                        When showing how to write an
            opcode with an audio rate
                        output, neither
                        tutorial initialises the output
            array to the size of
                        ksmps before use. They
                        both instead just reference ksmps
            to control the array
                        processing loop. Is the
                        array initialisation done
            automatically somewhere else
                        in csound?

                        My opcode also uses two input
            audio rate arguments.
                        Should I initialise the
                        arrays for them to ksmps size
            before use?

                        Next, I am wondering if all the
            arrays that I
                        initialise in the _perform
                        function should actually be
            initialised in the _init
                        function for speed.

                        I have attached my .h and .c files
            in one continuous
                        file for reference. My
                        opcode's purpose is to take two
            input audio signals
                        and bitwise-or them to get
                        the output audio signal (though I
            am guessing the
                        results of bitwise
                        operations on floats won't be as
            linear as on ints,
                        but I'm ok with that for
                        now :D ).















Date2015-12-13 13:35
FromPeter Burgess
SubjectRe: [Csnd-dev] Writing a new opcode
So with that said, where is the standard opcode directory on linux? Or how can I find out where OPCODEDIR is pointing? My computers a bit of a mess with csound copies, as I didn't know what I was doing when I started. I have a few different versions in my home folder, and one in my app's project folder, but I'm guessing the system points to a version in usr/local somewhere. I need to sort it out really.

On Sun, Dec 13, 2015 at 1:32 PM, Peter Burgess <pete.soundtechnician@gmail.com> wrote:
Ah right. I've just realised where I've gone wrong. I've added this to the entry1.c file:

static OENTRY localops[] = {
{ "newopc", sizeof(newopc), 0, 7, "s", "kki",(SUBR) newopc_init,
(SUBR) newopc_process_control, (SUBR) newopc_process_audio }
};

LINKAGE

But I think that was something I read in an older resource that required you to rebuild csound to add new opcodes. I've just read that this should actually go at the end of my c code.

I'll give your suggestion a try.

Cheers!


On Sun, Dec 13, 2015 at 1:23 PM, Rory Walsh <rorywalsh@ear.ie> wrote:
It's been a while since I've done this, but I don't think so? Others can confirm. What I usually do is simply add my source .cpp to the Opcodes dir. Then I add a call to make_plugin()  to Opcodes/CMakeLists.txt:

make_plugin(myplugin myplugin.cpp)

Then I just run make in the Csound build dir. This should take of everything. You shouldn't ever have to mess with any of Csound's code files. That was the original idea behind the development of plugin opcodes.  


On 13 December 2015 at 13:18, Peter Burgess <pete.soundtechnician@gmail.com> wrote:
Just feels right to keep a clean copy before I tamper with it.

To add a new opcode though, I have to add it to entry1.c right?

On Sun, Dec 13, 2015 at 1:15 PM, Rory Walsh <rorywalsh@ear.ie> wrote:
I mean there is absolutely no need to do this. If you are modifying any of Csound's files then you need to stop because that's not right. 

On 13 December 2015 at 13:06, Rory Walsh <rorywalsh@ear.ie> wrote:
Why are you making a copy? 

On 13 December 2015 at 12:51, Peter Burgess <pete.soundtechnician@gmail.com> wrote:
I decided to make a copy of csound to add my opcode to, so I keep an original untouched version. But how do I get terminal and QT to point to the correct one? I assume there's just an envirenment variable stored on my system somewhere.

I've tried to work it out from this before:

http://www.csounds.com/manual/html/CommandEnvironment.html

but it says to use the PATH command in terminal to set it. This seems like a fairly ambiguous command to use without already being within a csound context though. I was hoping just typing csound --env:PATH="my/path" might do it, but it doesn't seem to.


On Fri, Dec 11, 2015 at 5:27 PM, Peter Burgess <pete.soundtechnician@gmail.com> wrote:
ok cool, cheers for the advice.

On Fri, Dec 11, 2015 at 11:51 AM, jpff <jpff@codemist.co.uk> wrote:
If you want/eed the values to persist from kcycle to k-cycle they need to be in the structure.Oterwise they can be local.  It is lso common to copy struct fields to locals (look t the filters for this) bt that is fr ffciency.

I always told my studdents thta correcness was more important thn efficiency  well it is usually true!


==John

On Thu, 10 Dec 2015, Peter Burgess wrote:

Ok, I have a further question...

Is it actually necessary to declare all internal variables in the header?
Because the examples in the tutorials declare new internal variables within
the functions body.

On Thu, Dec 10, 2015 at 5:57 PM, Peter Burgess
<pete.soundtechnician@gmail.com> wrote:
      Ok cool, cheers man!

On Thu, Dec 10, 2015 at 5:35 PM, jpff <jpff@codemist.co.uk> wrote:
      LIKELY and UNLIKELY are just hints to te C compiler fot
      conditionals to indocate wich route is nost likely.  Can
      make a difference to speed. Ignore it until you understabd
      your code
      ==John

      On Thu, 10 Dec 2015, Peter Burgess wrote:

            Excellent! Cheers.

            Yeah I hadn't added the sample accurate
            business yet, I'll add that in now.
            What are the UNLIKELY() functions for?

            On Thu, Dec 10, 2015 at 4:38 PM, jpff
            <jpff@codemist.co.uk> wrote:
                  QUick look at the code -- this is corret
            except fot
                  --saple-accurate use

                  \Releasenore 6.0 say....

                  The template for arate perf-pass opcodes
            is:

                      int perf_myopcode(CSOUND *csound,
            MYOPCODE *p)
                      {
                          uint32_t offset =
            p->h.insdshead->ksmps_offset;
                          uint32_t early  =
            p->h.insdshead->ksmps_no_end;
                          uint32_t nsmps = CS_KSMPS;
                          ...
                          if (UNLIKELY(offset))
            memset(p->res, '\0',
                  offset*sizeof(MYFLT));
                          if (UNLIKELY(early))  {
                            nsmps -= early;
                            memset(&p->res[nsmps], '\0',
            early*sizeof(MYFLT));
                          }
                          for (n=offset; n<nsmps; n++) {
                              .....
                              p->res[n] = ....
                          }
                          return OK;
                      }



                  On Thu, 10 Dec 2015, Peter Burgess
            wrote:

                        Hi there, I am writing a new
            opcode for csound. I am
                        using these two sources
                        as a guide...

                       
            http://www.csounds.com/manual/html/csound5extending.html
                       
            http://booki.flossmanuals.net/csound/extending-csound/

                        When showing how to write an
            opcode with an audio rate
                        output, neither
                        tutorial initialises the output
            array to the size of
                        ksmps before use. They
                        both instead just reference ksmps
            to control the array
                        processing loop. Is the
                        array initialisation done
            automatically somewhere else
                        in csound?

                        My opcode also uses two input
            audio rate arguments.
                        Should I initialise the
                        arrays for them to ksmps size
            before use?

                        Next, I am wondering if all the
            arrays that I
                        initialise in the _perform
                        function should actually be
            initialised in the _init
                        function for speed.

                        I have attached my .h and .c files
            in one continuous
                        file for reference. My
                        opcode's purpose is to take two
            input audio signals
                        and bitwise-or them to get
                        the output audio signal (though I
            am guessing the
                        results of bitwise
                        operations on floats won't be as
            linear as on ints,
                        but I'm ok with that for
                        now :D ).
















Date2015-12-13 14:18
Fromjpff
SubjectRe: [Csnd-dev] Writing a new opcode
Look at one of the plugin opcodes -- say Opcode/linuxjoystick.c and make 
your code like  that and place in  Opcodes.  Then look for the string 
linuxjoystick in Opcodes/CMakeLists.txt and copy that.  Then call make as 
usual.  Will make a plugin library that you can use by moving it to the 
main system or you can use option --opcode-lib= to load

TW I do not understand the output "s" in your localops.  It is marked 
deprecated in the source.  What does it do?
==John

I though I had written all this somewhere.....


On Sun, 13 Dec 2015, Peter Burgess wrote:

> So with that said, where is the standard opcode directory on linux? Or how can
> I find out where OPCODEDIR is pointing? My computers a bit of a mess with
> csound copies, as I didn't know what I was doing when I started. I have a few
> different versions in my home folder, and one in my app's project folder, but
> I'm guessing the system points to a version in usr/local somewhere. I need to
> sort it out really.
> 
> On Sun, Dec 13, 2015 at 1:32 PM, Peter Burgess
>  wrote:
>       Ah right. I've just realised where I've gone wrong. I've added
>       this to the entry1.c file:
> 
> static OENTRY localops[] = {
> { "newopc", sizeof(newopc), 0, 7, "s", "kki",(SUBR) newopc_init,
> (SUBR) newopc_process_control, (SUBR) newopc_process_audio }
> };
>
>       LINKAGE
> 
> But I think that was something I read in an older resource that required
> you to rebuild csound to add new opcodes. I've just read that this
> should actually go at the end of my c code.
> 
> I'll give your suggestion a try.
> 
> Cheers!
> 
> 
> On Sun, Dec 13, 2015 at 1:23 PM, Rory Walsh  wrote:
>       It's been a while since I've done this, but I don't think
>       so? Others can confirm. What I usually do is simply add my
>       source .cpp to the Opcodes dir. Then I add a call to
>       make_plugin()  to Opcodes/CMakeLists.txt:
> make_plugin(myplugin myplugin.cpp)
> 
> Then I just run make in the Csound build dir. This should take of
> everything. You shouldn't ever have to mess with any of Csound's
> code files. That was the original idea behind the development of
> plugin opcodes.  
> 
> 
> On 13 December 2015 at 13:18, Peter Burgess
>  wrote:
>       Just feels right to keep a clean copy before I tamper
>       with it.
>
>       To add a new opcode though, I have to add it to
>       entry1.c right?
> 
> On Sun, Dec 13, 2015 at 1:15 PM, Rory Walsh
>  wrote:
>       I mean there is absolutely no need to do this.
>       If you are modifying any of Csound's files then
>       you need to stop because that's not right. 
> 
> On 13 December 2015 at 13:06, Rory Walsh
>  wrote:
>       Why are you making a copy? 
> 
> On 13 December 2015 at 12:51, Peter Burgess
>  wrote:
>       I decided to make a copy of csound
>       to add my opcode to, so I keep an
>       original untouched version. But how
>       do I get terminal and QT to point to
>       the correct one? I assume there's
>       just an envirenment variable stored
>       on my system somewhere.
> 
> I've tried to work it out from this
> before:
> 
> http://www.csounds.com/manual/html/CommandEnvironment.html
> 
> but it says to use the PATH command in
> terminal to set it. This seems like a
> fairly ambiguous command to use without
> already being within a csound context
> though. I was hoping just typing csound
> --env:PATH="my/path" might do it, but it
> doesn't seem to.
> 
> 
> On Fri, Dec 11, 2015 at 5:27 PM, Peter
> Burgess 
> wrote:
>       ok cool, cheers for the
>       advice.
> 
> On Fri, Dec 11, 2015 at 11:51 AM,
> jpff  wrote:
>       If you want/eed the
>       values to persist from
>       kcycle to k-cycle they
>       need to be in the
>       structure.Oterwise they
>       can be local.  It is lso
>       common to copy struct
>       fields to locals (look t
>       the filters for this) bt
>       that is fr ffciency.
>
>       I always told my
>       studdents thta
>       correcness was more
>       important thn
>       efficiency  well it is
>       usually true!
>
>       ==John
>
>       On Thu, 10 Dec 2015,
>       Peter Burgess wrote:
>
>             Ok, I have a
>             further
>             question...
>
>             Is it
>             actually
>             necessary to
>             declare all
>             internal
>             variables in
>             the header?
>             Because the
>             examples in
>             the
>             tutorials
>             declare new
>             internal
>             variables
>             within
>             the
>             functions
>             body.
>
>             On Thu, Dec
>             10, 2015 at
>             5:57 PM,
>             Peter
>             Burgess
>             
>             wrote:
>                   Ok
>             cool, cheers
>             man!
>
>             On Thu, Dec
>             10, 2015 at
>             5:35 PM,
>             jpff
>             
>             wrote:
>                   LIKELY
>             and UNLIKELY
>             are just
>             hints to te
>             C compiler
>             fot
>                  
>             conditionals
>             to indocate
>             wich route
>             is nost
>             likely.  Can
>                   make a
>             difference
>             to speed.
>             Ignore it
>             until you
>             understabd
>                   your
>             code
>                   ==John
>
>                   On
>             Thu, 10 Dec
>             2015, Peter
>             Burgess
>             wrote:
>
>                        
>             Excellent!
>             Cheers.
>
>                        
>             Yeah I
>             hadn't added
>             the sample
>             accurate
>                        
>             business
>             yet, I'll
>             add that in
>             now.
>                        
>             What are the
>             UNLIKELY()
>             functions
>             for?
>
>                        
>             On Thu, Dec
>             10, 2015 at
>             4:38 PM,
>             jpff
>                        
>             
>             wrote:
>                        
>                   QUick
>             look at the
>             code -- this
>             is corret
>                        
>             except fot
>                        
>                  
>             --saple-accurate
>             use
>
>                        
>                  
>             \Releasenore
>             6.0 say....
>
>                        
>                   The
>             template for
>             arate
>             perf-pass
>             opcodes
>                        
>             is:
>
>                        
>                      
>             int
>             perf_myopcode(CSOUND
>             *csound,
>                        
>             MYOPCODE *p)
>                        
>                       {
>                        
>                        
>               uint32_t
>             offset =
>                        
>             p->h.insdshead->ksmps_offset;
>                        
>                        
>               uint32_t
>             early  =
>                        
>             p->h.insdshead->ksmps_no_end;
>                        
>                        
>               uint32_t
>             nsmps =
>             CS_KSMPS;
>                        
>                        
>               ...
>                        
>                        
>               if
>             (UNLIKELY(offset))
>                        
>             memset(p->res,
>             '\0',
>                        
>                  
>             offset*sizeof(MYFLT));
>                        
>                        
>               if
>             (UNLIKELY(early)) 
>             {
>                        
>                        
>                 nsmps -=
>             early;
>                        
>                        
>                
>             memset(&p->res[nsmps],
>             '\0',
>                        
>             early*sizeof(MYFLT));
>                        
>                        
>               }
>                        
>                        
>               for
>             (n=offset;
>             n             n++) {
>                        
>                        
>                   .....
>                        
>                        
>                  
>             p->res[n] =
>             ....
>                        
>                        
>               }
>                        
>                        
>               return OK;
>                        
>                       }
> 
> 
>
>                        
>                   On
>             Thu, 10 Dec
>             2015, Peter
>             Burgess
>                        
>             wrote:
>
>                        
>                        
>             Hi there, I
>             am writing a
>             new
>                        
>             opcode for
>             csound. I am
>                        
>                        
>             using these
>             two sources
>                        
>                        
>             as a
>             guide...
>
>                        
>                        
>                        
>             http://www.csounds.com/manual/html/csound5extending.html
>                        
>                        
>                        
>             http://booki.flossmanuals.net/csound/extending-csound/
>
>                        
>                        
>             When showing
>             how to write
>             an
>                        
>             opcode with
>             an audio
>             rate
>                        
>                        
>             output,
>             neither
>                        
>                        
>             tutorial
>             initialises
>             the output
>                        
>             array to the
>             size of
>                        
>                        
>             ksmps before
>             use. They
>                        
>                        
>             both instead
>             just
>             reference
>             ksmps
>                        
>             to control
>             the array
>                        
>                        
>             processing
>             loop. Is the
>                        
>                        
>             array
>             initialisation
>             done
>                        
>             automatically
>             somewhere
>             else
>                        
>                        
>             in csound?
>
>                        
>                        
>             My opcode
>             also uses
>             two input
>                        
>             audio rate
>             arguments.
>                        
>                        
>             Should I
>             initialise
>             the
>                        
>                        
>             arrays for
>             them to
>             ksmps size
>                        
>             before use?
>
>                        
>                        
>             Next, I am
>             wondering if
>             all the
>                        
>             arrays that
>             I
>                        
>                        
>             initialise
>             in the
>             _perform
>                        
>                        
>             function
>             should
>             actually be
>                        
>             initialised
>             in the _init
>                        
>                        
>             function for
>             speed.
>
>                        
>                        
>             I have
>             attached my
>             .h and .c
>             files
>                        
>             in one
>             continuous
>                        
>                        
>             file for
>             reference.
>             My
>                        
>                        
>             opcode's
>             purpose is
>             to take two
>                        
>             input audio
>             signals
>                        
>                        
>             and
>             bitwise-or
>             them to get
>                        
>                        
>             the output
>             audio signal
>             (though I
>                        
>             am guessing
>             the
>                        
>                        
>             results of
>             bitwise
>                        
>                        
>             operations
>             on floats
>             won't be as
>                        
>             linear as on
>             ints,
>                        
>                        
>             but I'm ok
>             with that
>             for
>                        
>                        
>             now :D ).
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
>

Date2015-12-13 14:26
FromPeter Burgess
SubjectRe: [Csnd-dev] Writing a new opcode
Alright, I am hellishly confused. I'll start by setting the scene and saying that I've never directly used make or scons and I've so far never built csound myself.

So as I've said already, I have a few copies of csound in various places on my computer. This is obviosuly not helping my confusion. I am starting by trying to follow your instructions to make the pluggin in a copy of csound in my home folder. This isn't the version the system uses, but once I've figured it out, I'll try and tidy it all up and update the main copy.

Firstly I can't work out what I need to do with make. I've tried running 'make' and 'make CMakeLists.txt' from this csound directly in terminal. I've also tried both with cmake. My searches online for help have only told me to build csound in the usual way or to use sconstruct to build csound.

If I just type 'make' it says:

make: *** No targets specified and no makefile found. Stop.

If I type make CMakeLists.txt:

make: Nothing to be done for `CMakeLists.txt'.

cmake CMakeLists.txt result in this:

-- Configuring incomplete, errors occurred!
See also "/home/pete/Programming/csound/Csound6.06_MyOps/CMakeFiles/CMakeOutput.log".
See also "/home/pete/Programming/csound/Csound6.06_MyOps/CMakeFiles/CMakeError.log".

the first entry in hte CMakeError.log says:

Compiling the C compiler identification source file "CMakeCCompilerId.c" failed.
Compiler: CMAKE_C_COMPILER-NOTFOUND
Build flags:
Id flags:

The output was:
No such file or directory

I have changed the version of gcc recently, I think it's now called gcc4.9 or something, could that be what this error means?

@John: In the floss manual, it says 's' means either 'a' or 'k' output. It might be outdated. Here's the link.

http://floss.booktype.pro/csound/extending-csound/

On Sun, Dec 13, 2015 at 2:18 PM, jpff <jpff@codemist.co.uk> wrote:
Look at one of the plugin opcodes -- say Opcode/linuxjoystick.c and make your code like  that and place in  Opcodes.  Then look for the string linuxjoystick in Opcodes/CMakeLists.txt and copy that.  Then call make as usual.  Will make a plugin library that you can use by moving it to the main system or you can use option --opcode-lib= to load

TW I do not understand the output "s" in your localops.  It is marked deprecated in the source.  What does it do?
==John

I though I had written all this somewhere.....



On Sun, 13 Dec 2015, Peter Burgess wrote:

So with that said, where is the standard opcode directory on linux? Or how can
I find out where OPCODEDIR is pointing? My computers a bit of a mess with
csound copies, as I didn't know what I was doing when I started. I have a few
different versions in my home folder, and one in my app's project folder, but
I'm guessing the system points to a version in usr/local somewhere. I need to
sort it out really.

On Sun, Dec 13, 2015 at 1:32 PM, Peter Burgess
<pete.soundtechnician@gmail.com> wrote:
      Ah right. I've just realised where I've gone wrong. I've added
      this to the entry1.c file:

static OENTRY localops[] = {
{ "newopc", sizeof(newopc), 0, 7, "s", "kki",(SUBR) newopc_init,
(SUBR) newopc_process_control, (SUBR) newopc_process_audio }
};

      LINKAGE

But I think that was something I read in an older resource that required
you to rebuild csound to add new opcodes. I've just read that this
should actually go at the end of my c code.

I'll give your suggestion a try.

Cheers!


On Sun, Dec 13, 2015 at 1:23 PM, Rory Walsh <rorywalsh@ear.ie> wrote:
      It's been a while since I've done this, but I don't think
      so? Others can confirm. What I usually do is simply add my
      source .cpp to the Opcodes dir. Then I add a call to
      make_plugin()  to Opcodes/CMakeLists.txt:
make_plugin(myplugin myplugin.cpp)

Then I just run make in the Csound build dir. This should take of
everything. You shouldn't ever have to mess with any of Csound's
code files. That was the original idea behind the development of
plugin opcodes.  


On 13 December 2015 at 13:18, Peter Burgess
<pete.soundtechnician@gmail.com> wrote:
      Just feels right to keep a clean copy before I tamper
      with it.

      To add a new opcode though, I have to add it to
      entry1.c right?

On Sun, Dec 13, 2015 at 1:15 PM, Rory Walsh
<rorywalsh@ear.ie> wrote:
      I mean there is absolutely no need to do this.
      If you are modifying any of Csound's files then
      you need to stop because that's not right. 

On 13 December 2015 at 13:06, Rory Walsh
<rorywalsh@ear.ie> wrote:
      Why are you making a copy? 

On 13 December 2015 at 12:51, Peter Burgess
<pete.soundtechnician@gmail.com> wrote:
      I decided to make a copy of csound
      to add my opcode to, so I keep an
      original untouched version. But how
      do I get terminal and QT to point to
      the correct one? I assume there's
      just an envirenment variable stored
      on my system somewhere.

I've tried to work it out from this
before:

http://www.csounds.com/manual/html/CommandEnvironment.html

but it says to use the PATH command in
terminal to set it. This seems like a
fairly ambiguous command to use without
already being within a csound context
though. I was hoping just typing csound
--env:PATH="my/path" might do it, but it
doesn't seem to.


On Fri, Dec 11, 2015 at 5:27 PM, Peter
Burgess <pete.soundtechnician@gmail.com>
wrote:
      ok cool, cheers for the
      advice.

On Fri, Dec 11, 2015 at 11:51 AM,
jpff <jpff@codemist.co.uk> wrote:
      If you want/eed the
      values to persist from
      kcycle to k-cycle they
      need to be in the
      structure.Oterwise they
      can be local.  It is lso
      common to copy struct
      fields to locals (look t
      the filters for this) bt
      that is fr ffciency.

      I always told my
      studdents thta
      correcness was more
      important thn
      efficiency  well it is
      usually true!

      ==John

      On Thu, 10 Dec 2015,
      Peter Burgess wrote:

            Ok, I have a
            further
            question...

            Is it
            actually
            necessary to
            declare all
            internal
            variables in
            the header?
            Because the
            examples in
            the
            tutorials
            declare new
            internal
            variables
            within
            the
            functions
            body.

            On Thu, Dec
            10, 2015 at
            5:57 PM,
            Peter
            Burgess
            <pete.soundtechnician@gmail.com>
            wrote:
                  Ok
            cool, cheers
            man!

            On Thu, Dec
            10, 2015 at
            5:35 PM,
            jpff
            <jpff@codemist.co.uk>
            wrote:
                  LIKELY
            and UNLIKELY
            are just
            hints to te
            C compiler
            fot
                 
            conditionals
            to indocate
            wich route
            is nost
            likely.  Can
                  make a
            difference
            to speed.
            Ignore it
            until you
            understabd
                  your
            code
                  ==John

                  On
            Thu, 10 Dec
            2015, Peter
            Burgess
            wrote:

                       
            Excellent!
            Cheers.

                       
            Yeah I
            hadn't added
            the sample
            accurate
                       
            business
            yet, I'll
            add that in
            now.
                       
            What are the
            UNLIKELY()
            functions
            for?

                       
            On Thu, Dec
            10, 2015 at
            4:38 PM,
            jpff
                       
            <jpff@codemist.co.uk>
            wrote:
                       
                  QUick
            look at the
            code -- this
            is corret
                       
            except fot
                       
                 
            --saple-accurate
            use

                       
                 
            \Releasenore
            6.0 say....

                       
                  The
            template for
            arate
            perf-pass
            opcodes
                       
            is:

                       
                     
            int
            perf_myopcode(CSOUND
            *csound,
                       
            MYOPCODE *p)
                       
                      {
                       
                       
              uint32_t
            offset =
                       
            p->h.insdshead->ksmps_offset;
                       
                       
              uint32_t
            early  =
                       
            p->h.insdshead->ksmps_no_end;
                       
                       
              uint32_t
            nsmps =
            CS_KSMPS;
                       
                       
              ...
                       
                       
              if
            (UNLIKELY(offset))
                       
            memset(p->res,
            '\0',
                       
                 
            offset*sizeof(MYFLT));
                       
                       
              if
            (UNLIKELY(early)) 
            {
                       
                       
                nsmps -=
            early;
                       
                       
               
            memset(&p->res[nsmps],
            '\0',
                       
            early*sizeof(MYFLT));
                       
                       
              }
                       
                       
              for
            (n=offset;
            n<nsmps;
            n++) {
                       
                       
                  .....
                       
                       
                 
            p->res[n] =
            ....
                       
                       
              }
                       
                       
              return OK;
                       
                      }



                       
                  On
            Thu, 10 Dec
            2015, Peter
            Burgess
                       
            wrote:

                       
                       
            Hi there, I
            am writing a
            new
                       
            opcode for
            csound. I am
                       
                       
            using these
            two sources
                       
                       
            as a
            guide...

                       
                       
                       
            http://www.csounds.com/manual/html/csound5extending.html
                       
                       
                       
            http://booki.flossmanuals.net/csound/extending-csound/

                       
                       
            When showing
            how to write
            an
                       
            opcode with
            an audio
            rate
                       
                       
            output,
            neither
                       
                       
            tutorial
            initialises
            the output
                       
            array to the
            size of
                       
                       
            ksmps before
            use. They
                       
                       
            both instead
            just
            reference
            ksmps
                       
            to control
            the array
                       
                       
            processing
            loop. Is the
                       
                       
            array
            initialisation
            done
                       
            automatically
            somewhere
            else
                       
                       
            in csound?

                       
                       
            My opcode
            also uses
            two input
                       
            audio rate
            arguments.
                       
                       
            Should I
            initialise
            the
                       
                       
            arrays for
            them to
            ksmps size
                       
            before use?

                       
                       
            Next, I am
            wondering if
            all the
                       
            arrays that
            I
                       
                       
            initialise
            in the
            _perform
                       
                       
            function
            should
            actually be
                       
            initialised
            in the _init
                       
                       
            function for
            speed.

                       
                       
            I have
            attached my
            .h and .c
            files
                       
            in one
            continuous
                       
                       
            file for
            reference.
            My
                       
                       
            opcode's
            purpose is
            to take two
                       
            input audio
            signals
                       
                       
            and
            bitwise-or
            them to get
                       
                       
            the output
            audio signal
            (though I
                       
            am guessing
            the
                       
                       
            results of
            bitwise
                       
                       
            operations
            on floats
            won't be as
                       
            linear as on
            ints,
                       
                       
            but I'm ok
            with that
            for
                       
                       
            now :D ).


















Date2015-12-13 14:38
FromRory Walsh
SubjectRe: [Csnd-dev] Writing a new opcode
Hang on. I assumed that you were building Csound yourself all this time? Or did you install Csound using apt-get? 

On 13 December 2015 at 14:26, Peter Burgess <pete.soundtechnician@gmail.com> wrote:
Alright, I am hellishly confused. I'll start by setting the scene and saying that I've never directly used make or scons and I've so far never built csound myself.

So as I've said already, I have a few copies of csound in various places on my computer. This is obviosuly not helping my confusion. I am starting by trying to follow your instructions to make the pluggin in a copy of csound in my home folder. This isn't the version the system uses, but once I've figured it out, I'll try and tidy it all up and update the main copy.

Firstly I can't work out what I need to do with make. I've tried running 'make' and 'make CMakeLists.txt' from this csound directly in terminal. I've also tried both with cmake. My searches online for help have only told me to build csound in the usual way or to use sconstruct to build csound.

If I just type 'make' it says:

make: *** No targets specified and no makefile found. Stop.

If I type make CMakeLists.txt:

make: Nothing to be done for `CMakeLists.txt'.

cmake CMakeLists.txt result in this:

-- Configuring incomplete, errors occurred!
See also "/home/pete/Programming/csound/Csound6.06_MyOps/CMakeFiles/CMakeOutput.log".
See also "/home/pete/Programming/csound/Csound6.06_MyOps/CMakeFiles/CMakeError.log".

the first entry in hte CMakeError.log says:

Compiling the C compiler identification source file "CMakeCCompilerId.c" failed.
Compiler: CMAKE_C_COMPILER-NOTFOUND
Build flags:
Id flags:

The output was:
No such file or directory

I have changed the version of gcc recently, I think it's now called gcc4.9 or something, could that be what this error means?

@John: In the floss manual, it says 's' means either 'a' or 'k' output. It might be outdated. Here's the link.

http://floss.booktype.pro/csound/extending-csound/

On Sun, Dec 13, 2015 at 2:18 PM, jpff <jpff@codemist.co.uk> wrote:
Look at one of the plugin opcodes -- say Opcode/linuxjoystick.c and make your code like  that and place in  Opcodes.  Then look for the string linuxjoystick in Opcodes/CMakeLists.txt and copy that.  Then call make as usual.  Will make a plugin library that you can use by moving it to the main system or you can use option --opcode-lib= to load

TW I do not understand the output "s" in your localops.  It is marked deprecated in the source.  What does it do?
==John

I though I had written all this somewhere.....



On Sun, 13 Dec 2015, Peter Burgess wrote:

So with that said, where is the standard opcode directory on linux? Or how can
I find out where OPCODEDIR is pointing? My computers a bit of a mess with
csound copies, as I didn't know what I was doing when I started. I have a few
different versions in my home folder, and one in my app's project folder, but
I'm guessing the system points to a version in usr/local somewhere. I need to
sort it out really.

On Sun, Dec 13, 2015 at 1:32 PM, Peter Burgess
<pete.soundtechnician@gmail.com> wrote:
      Ah right. I've just realised where I've gone wrong. I've added
      this to the entry1.c file:

static OENTRY localops[] = {
{ "newopc", sizeof(newopc), 0, 7, "s", "kki",(SUBR) newopc_init,
(SUBR) newopc_process_control, (SUBR) newopc_process_audio }
};

      LINKAGE

But I think that was something I read in an older resource that required
you to rebuild csound to add new opcodes. I've just read that this
should actually go at the end of my c code.

I'll give your suggestion a try.

Cheers!


On Sun, Dec 13, 2015 at 1:23 PM, Rory Walsh <rorywalsh@ear.ie> wrote:
      It's been a while since I've done this, but I don't think
      so? Others can confirm. What I usually do is simply add my
      source .cpp to the Opcodes dir. Then I add a call to
      make_plugin()  to Opcodes/CMakeLists.txt:
make_plugin(myplugin myplugin.cpp)

Then I just run make in the Csound build dir. This should take of
everything. You shouldn't ever have to mess with any of Csound's
code files. That was the original idea behind the development of
plugin opcodes.  


On 13 December 2015 at 13:18, Peter Burgess
<pete.soundtechnician@gmail.com> wrote:
      Just feels right to keep a clean copy before I tamper
      with it.

      To add a new opcode though, I have to add it to
      entry1.c right?

On Sun, Dec 13, 2015 at 1:15 PM, Rory Walsh
<rorywalsh@ear.ie> wrote:
      I mean there is absolutely no need to do this.
      If you are modifying any of Csound's files then
      you need to stop because that's not right. 

On 13 December 2015 at 13:06, Rory Walsh
<rorywalsh@ear.ie> wrote:
      Why are you making a copy? 

On 13 December 2015 at 12:51, Peter Burgess
<pete.soundtechnician@gmail.com> wrote:
      I decided to make a copy of csound
      to add my opcode to, so I keep an
      original untouched version. But how
      do I get terminal and QT to point to
      the correct one? I assume there's
      just an envirenment variable stored
      on my system somewhere.

I've tried to work it out from this
before:

http://www.csounds.com/manual/html/CommandEnvironment.html

but it says to use the PATH command in
terminal to set it. This seems like a
fairly ambiguous command to use without
already being within a csound context
though. I was hoping just typing csound
--env:PATH="my/path" might do it, but it
doesn't seem to.


On Fri, Dec 11, 2015 at 5:27 PM, Peter
Burgess <pete.soundtechnician@gmail.com>
wrote:
      ok cool, cheers for the
      advice.

On Fri, Dec 11, 2015 at 11:51 AM,
jpff <jpff@codemist.co.uk> wrote:
      If you want/eed the
      values to persist from
      kcycle to k-cycle they
      need to be in the
      structure.Oterwise they
      can be local.  It is lso
      common to copy struct
      fields to locals (look t
      the filters for this) bt
      that is fr ffciency.

      I always told my
      studdents thta
      correcness was more
      important thn
      efficiency  well it is
      usually true!

      ==John

      On Thu, 10 Dec 2015,
      Peter Burgess wrote:

            Ok, I have a
            further
            question...

            Is it
            actually
            necessary to
            declare all
            internal
            variables in
            the header?
            Because the
            examples in
            the
            tutorials
            declare new
            internal
            variables
            within
            the
            functions
            body.

            On Thu, Dec
            10, 2015 at
            5:57 PM,
            Peter
            Burgess
            <pete.soundtechnician@gmail.com>
            wrote:
                  Ok
            cool, cheers
            man!

            On Thu, Dec
            10, 2015 at
            5:35 PM,
            jpff
            <jpff@codemist.co.uk>
            wrote:
                  LIKELY
            and UNLIKELY
            are just
            hints to te
            C compiler
            fot
                 
            conditionals
            to indocate
            wich route
            is nost
            likely.  Can
                  make a
            difference
            to speed.
            Ignore it
            until you
            understabd
                  your
            code
                  ==John

                  On
            Thu, 10 Dec
            2015, Peter
            Burgess
            wrote:

                       
            Excellent!
            Cheers.

                       
            Yeah I
            hadn't added
            the sample
            accurate
                       
            business
            yet, I'll
            add that in
            now.
                       
            What are the
            UNLIKELY()
            functions
            for?

                       
            On Thu, Dec
            10, 2015 at
            4:38 PM,
            jpff
                       
            <jpff@codemist.co.uk>
            wrote:
                       
                  QUick
            look at the
            code -- this
            is corret
                       
            except fot
                       
                 
            --saple-accurate
            use

                       
                 
            \Releasenore
            6.0 say....

                       
                  The
            template for
            arate
            perf-pass
            opcodes
                       
            is:

                       
                     
            int
            perf_myopcode(CSOUND
            *csound,
                       
            MYOPCODE *p)
                       
                      {
                       
                       
              uint32_t
            offset =
                       
            p->h.insdshead->ksmps_offset;
                       
                       
              uint32_t
            early  =
                       
            p->h.insdshead->ksmps_no_end;
                       
                       
              uint32_t
            nsmps =
            CS_KSMPS;
                       
                       
              ...
                       
                       
              if
            (UNLIKELY(offset))
                       
            memset(p->res,
            '\0',
                       
                 
            offset*sizeof(MYFLT));
                       
                       
              if
            (UNLIKELY(early)) 
            {
                       
                       
                nsmps -=
            early;
                       
                       
               
            memset(&p->res[nsmps],
            '\0',
                       
            early*sizeof(MYFLT));
                       
                       
              }
                       
                       
              for
            (n=offset;
            n<nsmps;
            n++) {
                       
                       
                  .....
                       
                       
                 
            p->res[n] =
            ....
                       
                       
              }
                       
                       
              return OK;
                       
                      }



                       
                  On
            Thu, 10 Dec
            2015, Peter
            Burgess
                       
            wrote:

                       
                       
            Hi there, I
            am writing a
            new
                       
            opcode for
            csound. I am
                       
                       
            using these
            two sources
                       
                       
            as a
            guide...

                       
                       
                       
            http://www.csounds.com/manual/html/csound5extending.html
                       
                       
                       
            http://booki.flossmanuals.net/csound/extending-csound/

                       
                       
            When showing
            how to write
            an
                       
            opcode with
            an audio
            rate
                       
                       
            output,
            neither
                       
                       
            tutorial
            initialises
            the output
                       
            array to the
            size of
                       
                       
            ksmps before
            use. They
                       
                       
            both instead
            just
            reference
            ksmps
                       
            to control
            the array
                       
                       
            processing
            loop. Is the
                       
                       
            array
            initialisation
            done
                       
            automatically
            somewhere
            else
                       
                       
            in csound?

                       
                       
            My opcode
            also uses
            two input
                       
            audio rate
            arguments.
                       
                       
            Should I
            initialise
            the
                       
                       
            arrays for
            them to
            ksmps size
                       
            before use?

                       
                       
            Next, I am
            wondering if
            all the
                       
            arrays that
            I
                       
                       
            initialise
            in the
            _perform
                       
                       
            function
            should
            actually be
                       
            initialised
            in the _init
                       
                       
            function for
            speed.

                       
                       
            I have
            attached my
            .h and .c
            files
                       
            in one
            continuous
                       
                       
            file for
            reference.
            My
                       
                       
            opcode's
            purpose is
            to take two
                       
            input audio
            signals
                       
                       
            and
            bitwise-or
            them to get
                       
                       
            the output
            audio signal
            (though I
                       
            am guessing
            the
                       
                       
            results of
            bitwise
                       
                       
            operations
            on floats
            won't be as
                       
            linear as on
            ints,
                       
                       
            but I'm ok
            with that
            for
                       
                       
            now :D ).



















Date2015-12-13 14:40
FromPeter Burgess
SubjectRe: [Csnd-dev] Writing a new opcode
apt-get. But I have copies that I've downloaded as well that I'm assuming are for the purpose of building

On Sun, Dec 13, 2015 at 2:38 PM, Rory Walsh <rorywalsh@ear.ie> wrote:
Hang on. I assumed that you were building Csound yourself all this time? Or did you install Csound using apt-get? 

On 13 December 2015 at 14:26, Peter Burgess <pete.soundtechnician@gmail.com> wrote:
Alright, I am hellishly confused. I'll start by setting the scene and saying that I've never directly used make or scons and I've so far never built csound myself.

So as I've said already, I have a few copies of csound in various places on my computer. This is obviosuly not helping my confusion. I am starting by trying to follow your instructions to make the pluggin in a copy of csound in my home folder. This isn't the version the system uses, but once I've figured it out, I'll try and tidy it all up and update the main copy.

Firstly I can't work out what I need to do with make. I've tried running 'make' and 'make CMakeLists.txt' from this csound directly in terminal. I've also tried both with cmake. My searches online for help have only told me to build csound in the usual way or to use sconstruct to build csound.

If I just type 'make' it says:

make: *** No targets specified and no makefile found. Stop.

If I type make CMakeLists.txt:

make: Nothing to be done for `CMakeLists.txt'.

cmake CMakeLists.txt result in this:

-- Configuring incomplete, errors occurred!
See also "/home/pete/Programming/csound/Csound6.06_MyOps/CMakeFiles/CMakeOutput.log".
See also "/home/pete/Programming/csound/Csound6.06_MyOps/CMakeFiles/CMakeError.log".

the first entry in hte CMakeError.log says:

Compiling the C compiler identification source file "CMakeCCompilerId.c" failed.
Compiler: CMAKE_C_COMPILER-NOTFOUND
Build flags:
Id flags:

The output was:
No such file or directory

I have changed the version of gcc recently, I think it's now called gcc4.9 or something, could that be what this error means?

@John: In the floss manual, it says 's' means either 'a' or 'k' output. It might be outdated. Here's the link.

http://floss.booktype.pro/csound/extending-csound/

On Sun, Dec 13, 2015 at 2:18 PM, jpff <jpff@codemist.co.uk> wrote:
Look at one of the plugin opcodes -- say Opcode/linuxjoystick.c and make your code like  that and place in  Opcodes.  Then look for the string linuxjoystick in Opcodes/CMakeLists.txt and copy that.  Then call make as usual.  Will make a plugin library that you can use by moving it to the main system or you can use option --opcode-lib= to load

TW I do not understand the output "s" in your localops.  It is marked deprecated in the source.  What does it do?
==John

I though I had written all this somewhere.....



On Sun, 13 Dec 2015, Peter Burgess wrote:

So with that said, where is the standard opcode directory on linux? Or how can
I find out where OPCODEDIR is pointing? My computers a bit of a mess with
csound copies, as I didn't know what I was doing when I started. I have a few
different versions in my home folder, and one in my app's project folder, but
I'm guessing the system points to a version in usr/local somewhere. I need to
sort it out really.

On Sun, Dec 13, 2015 at 1:32 PM, Peter Burgess
<pete.soundtechnician@gmail.com> wrote:
      Ah right. I've just realised where I've gone wrong. I've added
      this to the entry1.c file:

static OENTRY localops[] = {
{ "newopc", sizeof(newopc), 0, 7, "s", "kki",(SUBR) newopc_init,
(SUBR) newopc_process_control, (SUBR) newopc_process_audio }
};

      LINKAGE

But I think that was something I read in an older resource that required
you to rebuild csound to add new opcodes. I've just read that this
should actually go at the end of my c code.

I'll give your suggestion a try.

Cheers!


On Sun, Dec 13, 2015 at 1:23 PM, Rory Walsh <rorywalsh@ear.ie> wrote:
      It's been a while since I've done this, but I don't think
      so? Others can confirm. What I usually do is simply add my
      source .cpp to the Opcodes dir. Then I add a call to
      make_plugin()  to Opcodes/CMakeLists.txt:
make_plugin(myplugin myplugin.cpp)

Then I just run make in the Csound build dir. This should take of
everything. You shouldn't ever have to mess with any of Csound's
code files. That was the original idea behind the development of
plugin opcodes.  


On 13 December 2015 at 13:18, Peter Burgess
<pete.soundtechnician@gmail.com> wrote:
      Just feels right to keep a clean copy before I tamper
      with it.

      To add a new opcode though, I have to add it to
      entry1.c right?

On Sun, Dec 13, 2015 at 1:15 PM, Rory Walsh
<rorywalsh@ear.ie> wrote:
      I mean there is absolutely no need to do this.
      If you are modifying any of Csound's files then
      you need to stop because that's not right. 

On 13 December 2015 at 13:06, Rory Walsh
<rorywalsh@ear.ie> wrote:
      Why are you making a copy? 

On 13 December 2015 at 12:51, Peter Burgess
<pete.soundtechnician@gmail.com> wrote:
      I decided to make a copy of csound
      to add my opcode to, so I keep an
      original untouched version. But how
      do I get terminal and QT to point to
      the correct one? I assume there's
      just an envirenment variable stored
      on my system somewhere.

I've tried to work it out from this
before:

http://www.csounds.com/manual/html/CommandEnvironment.html

but it says to use the PATH command in
terminal to set it. This seems like a
fairly ambiguous command to use without
already being within a csound context
though. I was hoping just typing csound
--env:PATH="my/path" might do it, but it
doesn't seem to.


On Fri, Dec 11, 2015 at 5:27 PM, Peter
Burgess <pete.soundtechnician@gmail.com>
wrote:
      ok cool, cheers for the
      advice.

On Fri, Dec 11, 2015 at 11:51 AM,
jpff <jpff@codemist.co.uk> wrote:
      If you want/eed the
      values to persist from
      kcycle to k-cycle they
      need to be in the
      structure.Oterwise they
      can be local.  It is lso
      common to copy struct
      fields to locals (look t
      the filters for this) bt
      that is fr ffciency.

      I always told my
      studdents thta
      correcness was more
      important thn
      efficiency  well it is
      usually true!

      ==John

      On Thu, 10 Dec 2015,
      Peter Burgess wrote:

            Ok, I have a
            further
            question...

            Is it
            actually
            necessary to
            declare all
            internal
            variables in
            the header?
            Because the
            examples in
            the
            tutorials
            declare new
            internal
            variables
            within
            the
            functions
            body.

            On Thu, Dec
            10, 2015 at
            5:57 PM,
            Peter
            Burgess
            <pete.soundtechnician@gmail.com>
            wrote:
                  Ok
            cool, cheers
            man!

            On Thu, Dec
            10, 2015 at
            5:35 PM,
            jpff
            <jpff@codemist.co.uk>
            wrote:
                  LIKELY
            and UNLIKELY
            are just
            hints to te
            C compiler
            fot
                 
            conditionals
            to indocate
            wich route
            is nost
            likely.  Can
                  make a
            difference
            to speed.
            Ignore it
            until you
            understabd
                  your
            code
                  ==John

                  On
            Thu, 10 Dec
            2015, Peter
            Burgess
            wrote:

                       
            Excellent!
            Cheers.

                       
            Yeah I
            hadn't added
            the sample
            accurate
                       
            business
            yet, I'll
            add that in
            now.
                       
            What are the
            UNLIKELY()
            functions
            for?

                       
            On Thu, Dec
            10, 2015 at
            4:38 PM,
            jpff
                       
            <jpff@codemist.co.uk>
            wrote:
                       
                  QUick
            look at the
            code -- this
            is corret
                       
            except fot
                       
                 
            --saple-accurate
            use

                       
                 
            \Releasenore
            6.0 say....

                       
                  The
            template for
            arate
            perf-pass
            opcodes
                       
            is:

                       
                     
            int
            perf_myopcode(CSOUND
            *csound,
                       
            MYOPCODE *p)
                       
                      {
                       
                       
              uint32_t
            offset =
                       
            p->h.insdshead->ksmps_offset;
                       
                       
              uint32_t
            early  =
                       
            p->h.insdshead->ksmps_no_end;
                       
                       
              uint32_t
            nsmps =
            CS_KSMPS;
                       
                       
              ...
                       
                       
              if
            (UNLIKELY(offset))
                       
            memset(p->res,
            '\0',
                       
                 
            offset*sizeof(MYFLT));
                       
                       
              if
            (UNLIKELY(early)) 
            {
                       
                       
                nsmps -=
            early;
                       
                       
               
            memset(&p->res[nsmps],
            '\0',
                       
            early*sizeof(MYFLT));
                       
                       
              }
                       
                       
              for
            (n=offset;
            n<nsmps;
            n++) {
                       
                       
                  .....
                       
                       
                 
            p->res[n] =
            ....
                       
                       
              }
                       
                       
              return OK;
                       
                      }



                       
                  On
            Thu, 10 Dec
            2015, Peter
            Burgess
                       
            wrote:

                       
                       
            Hi there, I
            am writing a
            new
                       
            opcode for
            csound. I am
                       
                       
            using these
            two sources
                       
                       
            as a
            guide...

                       
                       
                       
            http://www.csounds.com/manual/html/csound5extending.html
                       
                       
                       
            http://booki.flossmanuals.net/csound/extending-csound/

                       
                       
            When showing
            how to write
            an
                       
            opcode with
            an audio
            rate
                       
                       
            output,
            neither
                       
                       
            tutorial
            initialises
            the output
                       
            array to the
            size of
                       
                       
            ksmps before
            use. They
                       
                       
            both instead
            just
            reference
            ksmps
                       
            to control
            the array
                       
                       
            processing
            loop. Is the
                       
                       
            array
            initialisation
            done
                       
            automatically
            somewhere
            else
                       
                       
            in csound?

                       
                       
            My opcode
            also uses
            two input
                       
            audio rate
            arguments.
                       
                       
            Should I
            initialise
            the
                       
                       
            arrays for
            them to
            ksmps size
                       
            before use?

                       
                       
            Next, I am
            wondering if
            all the
                       
            arrays that
            I
                       
                       
            initialise
            in the
            _perform
                       
                       
            function
            should
            actually be
                       
            initialised
            in the _init
                       
                       
            function for
            speed.

                       
                       
            I have
            attached my
            .h and .c
            files
                       
            in one
            continuous
                       
                       
            file for
            reference.
            My
                       
                       
            opcode's
            purpose is
            to take two
                       
            input audio
            signals
                       
                       
            and
            bitwise-or
            them to get
                       
                       
            the output
            audio signal
            (though I
                       
            am guessing
            the
                       
                       
            results of
            bitwise
                       
                       
            operations
            on floats
            won't be as
                       
            linear as on
            ints,
                       
                       
            but I'm ok
            with that
            for
                       
                       
            now :D ).




















Date2015-12-13 14:40
FromPeter Burgess
SubjectRe: [Csnd-dev] Writing a new opcode
the directory I've been working in with the new opcodes is one for building csound i think

On Sun, Dec 13, 2015 at 2:40 PM, Peter Burgess <pete.soundtechnician@gmail.com> wrote:
apt-get. But I have copies that I've downloaded as well that I'm assuming are for the purpose of building

On Sun, Dec 13, 2015 at 2:38 PM, Rory Walsh <rorywalsh@ear.ie> wrote:
Hang on. I assumed that you were building Csound yourself all this time? Or did you install Csound using apt-get? 

On 13 December 2015 at 14:26, Peter Burgess <pete.soundtechnician@gmail.com> wrote:
Alright, I am hellishly confused. I'll start by setting the scene and saying that I've never directly used make or scons and I've so far never built csound myself.

So as I've said already, I have a few copies of csound in various places on my computer. This is obviosuly not helping my confusion. I am starting by trying to follow your instructions to make the pluggin in a copy of csound in my home folder. This isn't the version the system uses, but once I've figured it out, I'll try and tidy it all up and update the main copy.

Firstly I can't work out what I need to do with make. I've tried running 'make' and 'make CMakeLists.txt' from this csound directly in terminal. I've also tried both with cmake. My searches online for help have only told me to build csound in the usual way or to use sconstruct to build csound.

If I just type 'make' it says:

make: *** No targets specified and no makefile found. Stop.

If I type make CMakeLists.txt:

make: Nothing to be done for `CMakeLists.txt'.

cmake CMakeLists.txt result in this:

-- Configuring incomplete, errors occurred!
See also "/home/pete/Programming/csound/Csound6.06_MyOps/CMakeFiles/CMakeOutput.log".
See also "/home/pete/Programming/csound/Csound6.06_MyOps/CMakeFiles/CMakeError.log".

the first entry in hte CMakeError.log says:

Compiling the C compiler identification source file "CMakeCCompilerId.c" failed.
Compiler: CMAKE_C_COMPILER-NOTFOUND
Build flags:
Id flags:

The output was:
No such file or directory

I have changed the version of gcc recently, I think it's now called gcc4.9 or something, could that be what this error means?

@John: In the floss manual, it says 's' means either 'a' or 'k' output. It might be outdated. Here's the link.

http://floss.booktype.pro/csound/extending-csound/

On Sun, Dec 13, 2015 at 2:18 PM, jpff <jpff@codemist.co.uk> wrote:
Look at one of the plugin opcodes -- say Opcode/linuxjoystick.c and make your code like  that and place in  Opcodes.  Then look for the string linuxjoystick in Opcodes/CMakeLists.txt and copy that.  Then call make as usual.  Will make a plugin library that you can use by moving it to the main system or you can use option --opcode-lib= to load

TW I do not understand the output "s" in your localops.  It is marked deprecated in the source.  What does it do?
==John

I though I had written all this somewhere.....



On Sun, 13 Dec 2015, Peter Burgess wrote:

So with that said, where is the standard opcode directory on linux? Or how can
I find out where OPCODEDIR is pointing? My computers a bit of a mess with
csound copies, as I didn't know what I was doing when I started. I have a few
different versions in my home folder, and one in my app's project folder, but
I'm guessing the system points to a version in usr/local somewhere. I need to
sort it out really.

On Sun, Dec 13, 2015 at 1:32 PM, Peter Burgess
<pete.soundtechnician@gmail.com> wrote:
      Ah right. I've just realised where I've gone wrong. I've added
      this to the entry1.c file:

static OENTRY localops[] = {
{ "newopc", sizeof(newopc), 0, 7, "s", "kki",(SUBR) newopc_init,
(SUBR) newopc_process_control, (SUBR) newopc_process_audio }
};

      LINKAGE

But I think that was something I read in an older resource that required
you to rebuild csound to add new opcodes. I've just read that this
should actually go at the end of my c code.

I'll give your suggestion a try.

Cheers!


On Sun, Dec 13, 2015 at 1:23 PM, Rory Walsh <rorywalsh@ear.ie> wrote:
      It's been a while since I've done this, but I don't think
      so? Others can confirm. What I usually do is simply add my
      source .cpp to the Opcodes dir. Then I add a call to
      make_plugin()  to Opcodes/CMakeLists.txt:
make_plugin(myplugin myplugin.cpp)

Then I just run make in the Csound build dir. This should take of
everything. You shouldn't ever have to mess with any of Csound's
code files. That was the original idea behind the development of
plugin opcodes.  


On 13 December 2015 at 13:18, Peter Burgess
<pete.soundtechnician@gmail.com> wrote:
      Just feels right to keep a clean copy before I tamper
      with it.

      To add a new opcode though, I have to add it to
      entry1.c right?

On Sun, Dec 13, 2015 at 1:15 PM, Rory Walsh
<rorywalsh@ear.ie> wrote:
      I mean there is absolutely no need to do this.
      If you are modifying any of Csound's files then
      you need to stop because that's not right. 

On 13 December 2015 at 13:06, Rory Walsh
<rorywalsh@ear.ie> wrote:
      Why are you making a copy? 

On 13 December 2015 at 12:51, Peter Burgess
<pete.soundtechnician@gmail.com> wrote:
      I decided to make a copy of csound
      to add my opcode to, so I keep an
      original untouched version. But how
      do I get terminal and QT to point to
      the correct one? I assume there's
      just an envirenment variable stored
      on my system somewhere.

I've tried to work it out from this
before:

http://www.csounds.com/manual/html/CommandEnvironment.html

but it says to use the PATH command in
terminal to set it. This seems like a
fairly ambiguous command to use without
already being within a csound context
though. I was hoping just typing csound
--env:PATH="my/path" might do it, but it
doesn't seem to.


On Fri, Dec 11, 2015 at 5:27 PM, Peter
Burgess <pete.soundtechnician@gmail.com>
wrote:
      ok cool, cheers for the
      advice.

On Fri, Dec 11, 2015 at 11:51 AM,
jpff <jpff@codemist.co.uk> wrote:
      If you want/eed the
      values to persist from
      kcycle to k-cycle they
      need to be in the
      structure.Oterwise they
      can be local.  It is lso
      common to copy struct
      fields to locals (look t
      the filters for this) bt
      that is fr ffciency.

      I always told my
      studdents thta
      correcness was more
      important thn
      efficiency  well it is
      usually true!

      ==John

      On Thu, 10 Dec 2015,
      Peter Burgess wrote:

            Ok, I have a
            further
            question...

            Is it
            actually
            necessary to
            declare all
            internal
            variables in
            the header?
            Because the
            examples in
            the
            tutorials
            declare new
            internal
            variables
            within
            the
            functions
            body.

            On Thu, Dec
            10, 2015 at
            5:57 PM,
            Peter
            Burgess
            <pete.soundtechnician@gmail.com>
            wrote:
                  Ok
            cool, cheers
            man!

            On Thu, Dec
            10, 2015 at
            5:35 PM,
            jpff
            <jpff@codemist.co.uk>
            wrote:
                  LIKELY
            and UNLIKELY
            are just
            hints to te
            C compiler
            fot
                 
            conditionals
            to indocate
            wich route
            is nost
            likely.  Can
                  make a
            difference
            to speed.
            Ignore it
            until you
            understabd
                  your
            code
                  ==John

                  On
            Thu, 10 Dec
            2015, Peter
            Burgess
            wrote:

                       
            Excellent!
            Cheers.

                       
            Yeah I
            hadn't added
            the sample
            accurate
                       
            business
            yet, I'll
            add that in
            now.
                       
            What are the
            UNLIKELY()
            functions
            for?

                       
            On Thu, Dec
            10, 2015 at
            4:38 PM,
            jpff
                       
            <jpff@codemist.co.uk>
            wrote:
                       
                  QUick
            look at the
            code -- this
            is corret
                       
            except fot
                       
                 
            --saple-accurate
            use

                       
                 
            \Releasenore
            6.0 say....

                       
                  The
            template for
            arate
            perf-pass
            opcodes
                       
            is:

                       
                     
            int
            perf_myopcode(CSOUND
            *csound,
                       
            MYOPCODE *p)
                       
                      {
                       
                       
              uint32_t
            offset =
                       
            p->h.insdshead->ksmps_offset;
                       
                       
              uint32_t
            early  =
                       
            p->h.insdshead->ksmps_no_end;
                       
                       
              uint32_t
            nsmps =
            CS_KSMPS;
                       
                       
              ...
                       
                       
              if
            (UNLIKELY(offset))
                       
            memset(p->res,
            '\0',
                       
                 
            offset*sizeof(MYFLT));
                       
                       
              if
            (UNLIKELY(early)) 
            {
                       
                       
                nsmps -=
            early;
                       
                       
               
            memset(&p->res[nsmps],
            '\0',
                       
            early*sizeof(MYFLT));
                       
                       
              }
                       
                       
              for
            (n=offset;
            n<nsmps;
            n++) {
                       
                       
                  .....
                       
                       
                 
            p->res[n] =
            ....
                       
                       
              }
                       
                       
              return OK;
                       
                      }



                       
                  On
            Thu, 10 Dec
            2015, Peter
            Burgess
                       
            wrote:

                       
                       
            Hi there, I
            am writing a
            new
                       
            opcode for
            csound. I am
                       
                       
            using these
            two sources
                       
                       
            as a
            guide...

                       
                       
                       
            http://www.csounds.com/manual/html/csound5extending.html
                       
                       
                       
            http://booki.flossmanuals.net/csound/extending-csound/

                       
                       
            When showing
            how to write
            an
                       
            opcode with
            an audio
            rate
                       
                       
            output,
            neither
                       
                       
            tutorial
            initialises
            the output
                       
            array to the
            size of
                       
                       
            ksmps before
            use. They
                       
                       
            both instead
            just
            reference
            ksmps
                       
            to control
            the array
                       
                       
            processing
            loop. Is the
                       
                       
            array
            initialisation
            done
                       
            automatically
            somewhere
            else
                       
                       
            in csound?

                       
                       
            My opcode
            also uses
            two input
                       
            audio rate
            arguments.
                       
                       
            Should I
            initialise
            the
                       
                       
            arrays for
            them to
            ksmps size
                       
            before use?

                       
                       
            Next, I am
            wondering if
            all the
                       
            arrays that
            I
                       
                       
            initialise
            in the
            _perform
                       
                       
            function
            should
            actually be
                       
            initialised
            in the _init
                       
                       
            function for
            speed.

                       
                       
            I have
            attached my
            .h and .c
            files
                       
            in one
            continuous
                       
                       
            file for
            reference.
            My
                       
                       
            opcode's
            purpose is
            to take two
                       
            input audio
            signals
                       
                       
            and
            bitwise-or
            them to get
                       
                       
            the output
            audio signal
            (though I
                       
            am guessing
            the
                       
                       
            results of
            bitwise
                       
                       
            operations
            on floats
            won't be as
                       
            linear as on
            ints,
                       
                       
            but I'm ok
            with that
            for
                       
                       
            now :D ).





















Date2015-12-13 14:48
FromRory Walsh
SubjectRe: [Csnd-dev] Writing a new opcode
I think in the long run you'd be as well off to simple start building Csound yourself. 


It will make things much easier as you can get cmake to automatically build your new opcodes for you and you don't need to work about build commands, or linker flags.  

On 13 December 2015 at 14:40, Peter Burgess <pete.soundtechnician@gmail.com> wrote:
the directory I've been working in with the new opcodes is one for building csound i think

On Sun, Dec 13, 2015 at 2:40 PM, Peter Burgess <pete.soundtechnician@gmail.com> wrote:
apt-get. But I have copies that I've downloaded as well that I'm assuming are for the purpose of building

On Sun, Dec 13, 2015 at 2:38 PM, Rory Walsh <rorywalsh@ear.ie> wrote:
Hang on. I assumed that you were building Csound yourself all this time? Or did you install Csound using apt-get? 

On 13 December 2015 at 14:26, Peter Burgess <pete.soundtechnician@gmail.com> wrote:
Alright, I am hellishly confused. I'll start by setting the scene and saying that I've never directly used make or scons and I've so far never built csound myself.

So as I've said already, I have a few copies of csound in various places on my computer. This is obviosuly not helping my confusion. I am starting by trying to follow your instructions to make the pluggin in a copy of csound in my home folder. This isn't the version the system uses, but once I've figured it out, I'll try and tidy it all up and update the main copy.

Firstly I can't work out what I need to do with make. I've tried running 'make' and 'make CMakeLists.txt' from this csound directly in terminal. I've also tried both with cmake. My searches online for help have only told me to build csound in the usual way or to use sconstruct to build csound.

If I just type 'make' it says:

make: *** No targets specified and no makefile found. Stop.

If I type make CMakeLists.txt:

make: Nothing to be done for `CMakeLists.txt'.

cmake CMakeLists.txt result in this:

-- Configuring incomplete, errors occurred!
See also "/home/pete/Programming/csound/Csound6.06_MyOps/CMakeFiles/CMakeOutput.log".
See also "/home/pete/Programming/csound/Csound6.06_MyOps/CMakeFiles/CMakeError.log".

the first entry in hte CMakeError.log says:

Compiling the C compiler identification source file "CMakeCCompilerId.c" failed.
Compiler: CMAKE_C_COMPILER-NOTFOUND
Build flags:
Id flags:

The output was:
No such file or directory

I have changed the version of gcc recently, I think it's now called gcc4.9 or something, could that be what this error means?

@John: In the floss manual, it says 's' means either 'a' or 'k' output. It might be outdated. Here's the link.

http://floss.booktype.pro/csound/extending-csound/

On Sun, Dec 13, 2015 at 2:18 PM, jpff <jpff@codemist.co.uk> wrote:
Look at one of the plugin opcodes -- say Opcode/linuxjoystick.c and make your code like  that and place in  Opcodes.  Then look for the string linuxjoystick in Opcodes/CMakeLists.txt and copy that.  Then call make as usual.  Will make a plugin library that you can use by moving it to the main system or you can use option --opcode-lib= to load

TW I do not understand the output "s" in your localops.  It is marked deprecated in the source.  What does it do?
==John

I though I had written all this somewhere.....



On Sun, 13 Dec 2015, Peter Burgess wrote:

So with that said, where is the standard opcode directory on linux? Or how can
I find out where OPCODEDIR is pointing? My computers a bit of a mess with
csound copies, as I didn't know what I was doing when I started. I have a few
different versions in my home folder, and one in my app's project folder, but
I'm guessing the system points to a version in usr/local somewhere. I need to
sort it out really.

On Sun, Dec 13, 2015 at 1:32 PM, Peter Burgess
<pete.soundtechnician@gmail.com> wrote:
      Ah right. I've just realised where I've gone wrong. I've added
      this to the entry1.c file:

static OENTRY localops[] = {
{ "newopc", sizeof(newopc), 0, 7, "s", "kki",(SUBR) newopc_init,
(SUBR) newopc_process_control, (SUBR) newopc_process_audio }
};

      LINKAGE

But I think that was something I read in an older resource that required
you to rebuild csound to add new opcodes. I've just read that this
should actually go at the end of my c code.

I'll give your suggestion a try.

Cheers!


On Sun, Dec 13, 2015 at 1:23 PM, Rory Walsh <rorywalsh@ear.ie> wrote:
      It's been a while since I've done this, but I don't think
      so? Others can confirm. What I usually do is simply add my
      source .cpp to the Opcodes dir. Then I add a call to
      make_plugin()  to Opcodes/CMakeLists.txt:
make_plugin(myplugin myplugin.cpp)

Then I just run make in the Csound build dir. This should take of
everything. You shouldn't ever have to mess with any of Csound's
code files. That was the original idea behind the development of
plugin opcodes.  


On 13 December 2015 at 13:18, Peter Burgess
<pete.soundtechnician@gmail.com> wrote:
      Just feels right to keep a clean copy before I tamper
      with it.

      To add a new opcode though, I have to add it to
      entry1.c right?

On Sun, Dec 13, 2015 at 1:15 PM, Rory Walsh
<rorywalsh@ear.ie> wrote:
      I mean there is absolutely no need to do this.
      If you are modifying any of Csound's files then
      you need to stop because that's not right. 

On 13 December 2015 at 13:06, Rory Walsh
<rorywalsh@ear.ie> wrote:
      Why are you making a copy? 

On 13 December 2015 at 12:51, Peter Burgess
<pete.soundtechnician@gmail.com> wrote:
      I decided to make a copy of csound
      to add my opcode to, so I keep an
      original untouched version. But how
      do I get terminal and QT to point to
      the correct one? I assume there's
      just an envirenment variable stored
      on my system somewhere.

I've tried to work it out from this
before:

http://www.csounds.com/manual/html/CommandEnvironment.html

but it says to use the PATH command in
terminal to set it. This seems like a
fairly ambiguous command to use without
already being within a csound context
though. I was hoping just typing csound
--env:PATH="my/path" might do it, but it
doesn't seem to.


On Fri, Dec 11, 2015 at 5:27 PM, Peter
Burgess <pete.soundtechnician@gmail.com>
wrote:
      ok cool, cheers for the
      advice.

On Fri, Dec 11, 2015 at 11:51 AM,
jpff <jpff@codemist.co.uk> wrote:
      If you want/eed the
      values to persist from
      kcycle to k-cycle they
      need to be in the
      structure.Oterwise they
      can be local.  It is lso
      common to copy struct
      fields to locals (look t
      the filters for this) bt
      that is fr ffciency.

      I always told my
      studdents thta
      correcness was more
      important thn
      efficiency  well it is
      usually true!

      ==John

      On Thu, 10 Dec 2015,
      Peter Burgess wrote:

            Ok, I have a
            further
            question...

            Is it
            actually
            necessary to
            declare all
            internal
            variables in
            the header?
            Because the
            examples in
            the
            tutorials
            declare new
            internal
            variables
            within
            the
            functions
            body.

            On Thu, Dec
            10, 2015 at
            5:57 PM,
            Peter
            Burgess
            <pete.soundtechnician@gmail.com>
            wrote:
                  Ok
            cool, cheers
            man!

            On Thu, Dec
            10, 2015 at
            5:35 PM,
            jpff
            <jpff@codemist.co.uk>
            wrote:
                  LIKELY
            and UNLIKELY
            are just
            hints to te
            C compiler
            fot
                 
            conditionals
            to indocate
            wich route
            is nost
            likely.  Can
                  make a
            difference
            to speed.
            Ignore it
            until you
            understabd
                  your
            code
                  ==John

                  On
            Thu, 10 Dec
            2015, Peter
            Burgess
            wrote:

                       
            Excellent!
            Cheers.

                       
            Yeah I
            hadn't added
            the sample
            accurate
                       
            business
            yet, I'll
            add that in
            now.
                       
            What are the
            UNLIKELY()
            functions
            for?

                       
            On Thu, Dec
            10, 2015 at
            4:38 PM,
            jpff
                       
            <jpff@codemist.co.uk>
            wrote:
                       
                  QUick
            look at the
            code -- this
            is corret
                       
            except fot
                       
                 
            --saple-accurate
            use

                       
                 
            \Releasenore
            6.0 say....

                       
                  The
            template for
            arate
            perf-pass
            opcodes
                       
            is:

                       
                     
            int
            perf_myopcode(CSOUND
            *csound,
                       
            MYOPCODE *p)
                       
                      {
                       
                       
              uint32_t
            offset =
                       
            p->h.insdshead->ksmps_offset;
                       
                       
              uint32_t
            early  =
                       
            p->h.insdshead->ksmps_no_end;
                       
                       
              uint32_t
            nsmps =
            CS_KSMPS;
                       
                       
              ...
                       
                       
              if
            (UNLIKELY(offset))
                       
            memset(p->res,
            '\0',
                       
                 
            offset*sizeof(MYFLT));
                       
                       
              if
            (UNLIKELY(early)) 
            {
                       
                       
                nsmps -=
            early;
                       
                       
               
            memset(&p->res[nsmps],
            '\0',
                       
            early*sizeof(MYFLT));
                       
                       
              }
                       
                       
              for
            (n=offset;
            n<nsmps;
            n++) {
                       
                       
                  .....
                       
                       
                 
            p->res[n] =
            ....
                       
                       
              }
                       
                       
              return OK;
                       
                      }



                       
                  On
            Thu, 10 Dec
            2015, Peter
            Burgess
                       
            wrote:

                       
                       
            Hi there, I
            am writing a
            new
                       
            opcode for
            csound. I am
                       
                       
            using these
            two sources
                       
                       
            as a
            guide...

                       
                       
                       
            http://www.csounds.com/manual/html/csound5extending.html
                       
                       
                       
            http://booki.flossmanuals.net/csound/extending-csound/

                       
                       
            When showing
            how to write
            an
                       
            opcode with
            an audio
            rate
                       
                       
            output,
            neither
                       
                       
            tutorial
            initialises
            the output
                       
            array to the
            size of
                       
                       
            ksmps before
            use. They
                       
                       
            both instead
            just
            reference
            ksmps
                       
            to control
            the array
                       
                       
            processing
            loop. Is the
                       
                       
            array
            initialisation
            done
                       
            automatically
            somewhere
            else
                       
                       
            in csound?

                       
                       
            My opcode
            also uses
            two input
                       
            audio rate
            arguments.
                       
                       
            Should I
            initialise
            the
                       
                       
            arrays for
            them to
            ksmps size
                       
            before use?

                       
                       
            Next, I am
            wondering if
            all the
                       
            arrays that
            I
                       
                       
            initialise
            in the
            _perform
                       
                       
            function
            should
            actually be
                       
            initialised
            in the _init
                       
                       
            function for
            speed.

                       
                       
            I have
            attached my
            .h and .c
            files
                       
            in one
            continuous
                       
                       
            file for
            reference.
            My
                       
                       
            opcode's
            purpose is
            to take two
                       
            input audio
            signals
                       
                       
            and
            bitwise-or
            them to get
                       
                       
            the output
            audio signal
            (though I
                       
            am guessing
            the
                       
                       
            results of
            bitwise
                       
                       
            operations
            on floats
            won't be as
                       
            linear as on
            ints,
                       
                       
            but I'm ok
            with that
            for
                       
                       
            now :D ).






















Date2015-12-13 14:52
FromPeter Burgess
SubjectRe: [Csnd-dev] Writing a new opcode
Maybe you're right. It's about time I manned up and had a go really.

Just to clarify something though, I thought the point of the pluggin opcodes was so you didn't have to rebuild csound to add a new opcode. So why do we need to go through the 'make' process?

On Sun, Dec 13, 2015 at 2:48 PM, Rory Walsh <rorywalsh@ear.ie> wrote:
I think in the long run you'd be as well off to simple start building Csound yourself. 


It will make things much easier as you can get cmake to automatically build your new opcodes for you and you don't need to work about build commands, or linker flags.  

On 13 December 2015 at 14:40, Peter Burgess <pete.soundtechnician@gmail.com> wrote:
the directory I've been working in with the new opcodes is one for building csound i think

On Sun, Dec 13, 2015 at 2:40 PM, Peter Burgess <pete.soundtechnician@gmail.com> wrote:
apt-get. But I have copies that I've downloaded as well that I'm assuming are for the purpose of building

On Sun, Dec 13, 2015 at 2:38 PM, Rory Walsh <rorywalsh@ear.ie> wrote:
Hang on. I assumed that you were building Csound yourself all this time? Or did you install Csound using apt-get? 

On 13 December 2015 at 14:26, Peter Burgess <pete.soundtechnician@gmail.com> wrote:
Alright, I am hellishly confused. I'll start by setting the scene and saying that I've never directly used make or scons and I've so far never built csound myself.

So as I've said already, I have a few copies of csound in various places on my computer. This is obviosuly not helping my confusion. I am starting by trying to follow your instructions to make the pluggin in a copy of csound in my home folder. This isn't the version the system uses, but once I've figured it out, I'll try and tidy it all up and update the main copy.

Firstly I can't work out what I need to do with make. I've tried running 'make' and 'make CMakeLists.txt' from this csound directly in terminal. I've also tried both with cmake. My searches online for help have only told me to build csound in the usual way or to use sconstruct to build csound.

If I just type 'make' it says:

make: *** No targets specified and no makefile found. Stop.

If I type make CMakeLists.txt:

make: Nothing to be done for `CMakeLists.txt'.

cmake CMakeLists.txt result in this:

-- Configuring incomplete, errors occurred!
See also "/home/pete/Programming/csound/Csound6.06_MyOps/CMakeFiles/CMakeOutput.log".
See also "/home/pete/Programming/csound/Csound6.06_MyOps/CMakeFiles/CMakeError.log".

the first entry in hte CMakeError.log says:

Compiling the C compiler identification source file "CMakeCCompilerId.c" failed.
Compiler: CMAKE_C_COMPILER-NOTFOUND
Build flags:
Id flags:

The output was:
No such file or directory

I have changed the version of gcc recently, I think it's now called gcc4.9 or something, could that be what this error means?

@John: In the floss manual, it says 's' means either 'a' or 'k' output. It might be outdated. Here's the link.

http://floss.booktype.pro/csound/extending-csound/

On Sun, Dec 13, 2015 at 2:18 PM, jpff <jpff@codemist.co.uk> wrote:
Look at one of the plugin opcodes -- say Opcode/linuxjoystick.c and make your code like  that and place in  Opcodes.  Then look for the string linuxjoystick in Opcodes/CMakeLists.txt and copy that.  Then call make as usual.  Will make a plugin library that you can use by moving it to the main system or you can use option --opcode-lib= to load

TW I do not understand the output "s" in your localops.  It is marked deprecated in the source.  What does it do?
==John

I though I had written all this somewhere.....



On Sun, 13 Dec 2015, Peter Burgess wrote:

So with that said, where is the standard opcode directory on linux? Or how can
I find out where OPCODEDIR is pointing? My computers a bit of a mess with
csound copies, as I didn't know what I was doing when I started. I have a few
different versions in my home folder, and one in my app's project folder, but
I'm guessing the system points to a version in usr/local somewhere. I need to
sort it out really.

On Sun, Dec 13, 2015 at 1:32 PM, Peter Burgess
<pete.soundtechnician@gmail.com> wrote:
      Ah right. I've just realised where I've gone wrong. I've added
      this to the entry1.c file:

static OENTRY localops[] = {
{ "newopc", sizeof(newopc), 0, 7, "s", "kki",(SUBR) newopc_init,
(SUBR) newopc_process_control, (SUBR) newopc_process_audio }
};

      LINKAGE

But I think that was something I read in an older resource that required
you to rebuild csound to add new opcodes. I've just read that this
should actually go at the end of my c code.

I'll give your suggestion a try.

Cheers!


On Sun, Dec 13, 2015 at 1:23 PM, Rory Walsh <rorywalsh@ear.ie> wrote:
      It's been a while since I've done this, but I don't think
      so? Others can confirm. What I usually do is simply add my
      source .cpp to the Opcodes dir. Then I add a call to
      make_plugin()  to Opcodes/CMakeLists.txt:
make_plugin(myplugin myplugin.cpp)

Then I just run make in the Csound build dir. This should take of
everything. You shouldn't ever have to mess with any of Csound's
code files. That was the original idea behind the development of
plugin opcodes.  


On 13 December 2015 at 13:18, Peter Burgess
<pete.soundtechnician@gmail.com> wrote:
      Just feels right to keep a clean copy before I tamper
      with it.

      To add a new opcode though, I have to add it to
      entry1.c right?

On Sun, Dec 13, 2015 at 1:15 PM, Rory Walsh
<rorywalsh@ear.ie> wrote:
      I mean there is absolutely no need to do this.
      If you are modifying any of Csound's files then
      you need to stop because that's not right. 

On 13 December 2015 at 13:06, Rory Walsh
<rorywalsh@ear.ie> wrote:
      Why are you making a copy? 

On 13 December 2015 at 12:51, Peter Burgess
<pete.soundtechnician@gmail.com> wrote:
      I decided to make a copy of csound
      to add my opcode to, so I keep an
      original untouched version. But how
      do I get terminal and QT to point to
      the correct one? I assume there's
      just an envirenment variable stored
      on my system somewhere.

I've tried to work it out from this
before:

http://www.csounds.com/manual/html/CommandEnvironment.html

but it says to use the PATH command in
terminal to set it. This seems like a
fairly ambiguous command to use without
already being within a csound context
though. I was hoping just typing csound
--env:PATH="my/path" might do it, but it
doesn't seem to.


On Fri, Dec 11, 2015 at 5:27 PM, Peter
Burgess <pete.soundtechnician@gmail.com>
wrote:
      ok cool, cheers for the
      advice.

On Fri, Dec 11, 2015 at 11:51 AM,
jpff <jpff@codemist.co.uk> wrote:
      If you want/eed the
      values to persist from
      kcycle to k-cycle they
      need to be in the
      structure.Oterwise they
      can be local.  It is lso
      common to copy struct
      fields to locals (look t
      the filters for this) bt
      that is fr ffciency.

      I always told my
      studdents thta
      correcness was more
      important thn
      efficiency  well it is
      usually true!

      ==John

      On Thu, 10 Dec 2015,
      Peter Burgess wrote:

            Ok, I have a
            further
            question...

            Is it
            actually
            necessary to
            declare all
            internal
            variables in
            the header?
            Because the
            examples in
            the
            tutorials
            declare new
            internal
            variables
            within
            the
            functions
            body.

            On Thu, Dec
            10, 2015 at
            5:57 PM,
            Peter
            Burgess
            <pete.soundtechnician@gmail.com>
            wrote:
                  Ok
            cool, cheers
            man!

            On Thu, Dec
            10, 2015 at
            5:35 PM,
            jpff
            <jpff@codemist.co.uk>
            wrote:
                  LIKELY
            and UNLIKELY
            are just
            hints to te
            C compiler
            fot
                 
            conditionals
            to indocate
            wich route
            is nost
            likely.  Can
                  make a
            difference
            to speed.
            Ignore it
            until you
            understabd
                  your
            code
                  ==John

                  On
            Thu, 10 Dec
            2015, Peter
            Burgess
            wrote:

                       
            Excellent!
            Cheers.

                       
            Yeah I
            hadn't added
            the sample
            accurate
                       
            business
            yet, I'll
            add that in
            now.
                       
            What are the
            UNLIKELY()
            functions
            for?

                       
            On Thu, Dec
            10, 2015 at
            4:38 PM,
            jpff
                       
            <jpff@codemist.co.uk>
            wrote:
                       
                  QUick
            look at the
            code -- this
            is corret
                       
            except fot
                       
                 
            --saple-accurate
            use

                       
                 
            \Releasenore
            6.0 say....

                       
                  The
            template for
            arate
            perf-pass
            opcodes
                       
            is:

                       
                     
            int
            perf_myopcode(CSOUND
            *csound,
                       
            MYOPCODE *p)
                       
                      {
                       
                       
              uint32_t
            offset =
                       
            p->h.insdshead->ksmps_offset;
                       
                       
              uint32_t
            early  =
                       
            p->h.insdshead->ksmps_no_end;
                       
                       
              uint32_t
            nsmps =
            CS_KSMPS;
                       
                       
              ...
                       
                       
              if
            (UNLIKELY(offset))
                       
            memset(p->res,
            '\0',
                       
                 
            offset*sizeof(MYFLT));
                       
                       
              if
            (UNLIKELY(early)) 
            {
                       
                       
                nsmps -=
            early;
                       
                       
               
            memset(&p->res[nsmps],
            '\0',
                       
            early*sizeof(MYFLT));
                       
                       
              }
                       
                       
              for
            (n=offset;
            n<nsmps;
            n++) {
                       
                       
                  .....
                       
                       
                 
            p->res[n] =
            ....
                       
                       
              }
                       
                       
              return OK;
                       
                      }



                       
                  On
            Thu, 10 Dec
            2015, Peter
            Burgess
                       
            wrote:

                       
                       
            Hi there, I
            am writing a
            new
                       
            opcode for
            csound. I am
                       
                       
            using these
            two sources
                       
                       
            as a
            guide...

                       
                       
                       
            http://www.csounds.com/manual/html/csound5extending.html
                       
                       
                       
            http://booki.flossmanuals.net/csound/extending-csound/

                       
                       
            When showing
            how to write
            an
                       
            opcode with
            an audio
            rate
                       
                       
            output,
            neither
                       
                       
            tutorial
            initialises
            the output
                       
            array to the
            size of
                       
                       
            ksmps before
            use. They
                       
                       
            both instead
            just
            reference
            ksmps
                       
            to control
            the array
                       
                       
            processing
            loop. Is the
                       
                       
            array
            initialisation
            done
                       
            automatically
            somewhere
            else
                       
                       
            in csound?

                       
                       
            My opcode
            also uses
            two input
                       
            audio rate
            arguments.
                       
                       
            Should I
            initialise
            the
                       
                       
            arrays for
            them to
            ksmps size
                       
            before use?

                       
                       
            Next, I am
            wondering if
            all the
                       
            arrays that
            I
                       
                       
            initialise
            in the
            _perform
                       
                       
            function
            should
            actually be
                       
            initialised
            in the _init
                       
                       
            function for
            speed.

                       
                       
            I have
            attached my
            .h and .c
            files
                       
            in one
            continuous
                       
                       
            file for
            reference.
            My
                       
                       
            opcode's
            purpose is
            to take two
                       
            input audio
            signals
                       
                       
            and
            bitwise-or
            them to get
                       
                       
            the output
            audio signal
            (though I
                       
            am guessing
            the
                       
                       
            results of
            bitwise
                       
                       
            operations
            on floats
            won't be as
                       
            linear as on
            ints,
                       
                       
            but I'm ok
            with that
            for
                       
                       
            now :D ).























Date2015-12-13 14:52
Fromjpff
SubjectRe: [Csnd-dev] Writing a new opcode
Rory is right.  Easier for you and easier for us to help

Date2015-12-13 15:04
FromRory Walsh
SubjectRe: [Csnd-dev] Writing a new opcode
That is correct. You don't need to build Csound. You can simple run gcc and provide the correct linker flags. And I would usually recommend that approach on Windows for example. But because Csound is so easy to build on Linux, it's probably more convenient to use its cmake system for building opcodes. 

On 13 December 2015 at 14:52, jpff <jpff@codemist.co.uk> wrote:
Rory is right.  Easier for you and easier for us to help
==Jon


Date2015-12-13 15:08
FromPeter Burgess
SubjectRe: [Csnd-dev] Writing a new opcode
Ok cool, thanks for clearing that up! Well then, I'll have a quick go using the linker flags just to test my opcodes, then I'll have a go at building csound.

If I happen to come up with any useful/interesting opcodes, should I post them up here?

On Sun, Dec 13, 2015 at 3:04 PM, Rory Walsh <rorywalsh@ear.ie> wrote:
That is correct. You don't need to build Csound. You can simple run gcc and provide the correct linker flags. And I would usually recommend that approach on Windows for example. But because Csound is so easy to build on Linux, it's probably more convenient to use its cmake system for building opcodes. 

On 13 December 2015 at 14:52, jpff <jpff@codemist.co.uk> wrote:
Rory is right.  Easier for you and easier for us to help
==Jon



Date2015-12-13 15:17
FromRory Walsh
SubjectRe: [Csnd-dev] Writing a new opcode
Sure. You can also post them to the main user list. As far as I know all you need to do to build a plugin opcode is:

gcc mysource.c -o myplugin.so -lcsound64 -lsndfile  -I/path_to_csound_includes

On 13 December 2015 at 15:08, Peter Burgess <pete.soundtechnician@gmail.com> wrote:
Ok cool, thanks for clearing that up! Well then, I'll have a quick go using the linker flags just to test my opcodes, then I'll have a go at building csound.

If I happen to come up with any useful/interesting opcodes, should I post them up here?

On Sun, Dec 13, 2015 at 3:04 PM, Rory Walsh <rorywalsh@ear.ie> wrote:
That is correct. You don't need to build Csound. You can simple run gcc and provide the correct linker flags. And I would usually recommend that approach on Windows for example. But because Csound is so easy to build on Linux, it's probably more convenient to use its cmake system for building opcodes. 

On 13 December 2015 at 14:52, jpff <jpff@codemist.co.uk> wrote:
Rory is right.  Easier for you and easier for us to help
==Jon




Date2015-12-13 15:19
Fromjpff
SubjectRe: [Csnd-dev] Writing a new opcode
> If I happen to come up with any useful/interesting opcodes, should I post them
> up here?
>

Yes.  If enough people want it, it adds functionality and you are willing 
to licence under LGPL then it can be incorporated and maintained by the 
developers.   Anyway we are generally interested in what people do with 
csound.

Date2015-12-13 15:28
FromPeter Burgess
SubjectRe: [Csnd-dev] Writing a new opcode
Cool! I certainly will be willing to licence under LGPL.

So, is this not the main users list? Have I been posting to the wrong list all this time? Lol

On Sun, Dec 13, 2015 at 3:19 PM, jpff <jpff@codemist.co.uk> wrote:
If I happen to come up with any useful/interesting opcodes, should I post them
up here?


Yes.  If enough people want it, it adds functionality and you are willing to licence under LGPL then it can be incorporated and maintained by the developers.   Anyway we are generally interested in what people do with csound.
==John


Date2015-12-13 15:36
Fromjpff
SubjectRe: [Csnd-dev] Writing a new opcode
There are two lists.  This one is for developer stuff, concentrating on 
the code and technical design.  The other one, csound@listserv.heanet.ie is 
for more user-orieted stuff; how to use opcodes, oddiities and bugs.  The 
intent is not to frighten users with technobable.

I think you are using the right list for now.  If/when it works it might 

Date2015-12-13 16:35
FromPeter Burgess
SubjectRe: [Csnd-dev] Writing a new opcode
ok cool. So this is still the right forum for questions about building csound and using the API's and stuff like that is it?

On Sun, Dec 13, 2015 at 3:36 PM, jpff <jpff@codemist.co.uk> wrote:
There are two lists.  This one is for developer stuff, concentrating on the code and technical design.  The other one, csound@listserv.heanet.ie is for more user-orieted stuff; how to use opcodes, oddiities and bugs.  The intent is not to frighten users with technobable.

I think you are using the right list for now.  If/when it works it might be appropriate to transfer discussion to the users.