[Csnd] sample-accurate mechanism

Hello everyone!

I try to get my head around some plugin development and i have some questions regarding the sample-accurate mechanism.

In the floss manual we have the example at the end of the mail and my questions are:

- how often are the offset and early variables updated? every k-cycle?
- is only one of these (offset and early) > 0 ?
- what is the `early` variable representing?
- are there multiple k-cycle running out of sync at the same time?

Because when i got it right, the mechanism is working like this:
- a main csound k-cycle is running
- when the accurate flag is given, a new instrument is not starting in sync with the main k-cycle, but to the nearest sample in time; so there are two k-cycles now running which are not in sync
- Csound gives the information at which point in the main-csound-k-cycle (?) the instrument is started and represents this in the offset and early variables
- so when the the new instrument is started at the 5th sample of the main-k-cycle the offset is 5
- but what is now happening with the early variable?

- Philipp

    int newopc_process_audio(CSOUND *csound, newopc *p){
      int i, n = CS_KSMPS;
      MYFLT *aout = p->out;  /* output signal */
      MYFLT cnt = p->var1 + *(p->in2);
      uint32_t offset = p->h.insdshead->ksmps_offset;
      uint32_t early  = p->h.insdshead->ksmps_no_end;

      /* sample-accurate mode mechanism */
      if(offset)
        memset(aout, '', offset*sizeof(MYFLT));
      if(early) {
        n -= early;
        memset(&aout[n], '', early*sizeof(MYFLT));
      }

      if(cnt > p->var2)
        cnt = (MYFLT) 0; /* check bounds */

      /* processing loop    */
      for(i=offset; i < n; i++)
        aout[i] = *(p->in1) + cnt;

      p->var1 = cnt; /* keep the value of cnt */
      return OK;
    }

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        Issues · csound/csound · GitHub
Discussions of bugs and features can be posted here

Offset may be nonzero at the start of the event and early may be nonzero at the end of the event.

There is boilerplate code in the opcode_sdk repository for dealing with this in the mult.c example.

Prof. Victor Lazzarini
Maynooth University
Ireland

ah, now i guess i got it:

offset is only important, when a event is starting.
so it creates a offset, just for the first k-cycle and only for this k-cycle it may be nonzero.

early is only important, when a event is stopped.
so it’s making the buffer writing process stop at the time, the instrument is stopped, and the remaining samples of the k-cycle are set to zero.

Thanks!