[Csnd] linseg drift after several values

hello everybody,

been using linseg with some pretty long val/dur pairs and I have noticed that the timing starts to drift after awhile. not sure if the number of val/dur pairs or the general length of the line segment has to do with this, but looking for some remedy...

apologies in advance for this long file, but no need to listen to the whole thing. after you specify a file path, just listen to the beginning and end of the file and you will hear that the filter on/off has fallen behind the notes' on/off.

thanks again everybody,

walker

hi walker -

i think you should look for another method to do what you want to do. as far as i understand your code, you calleach instance of instr 1 either with or without the filter. why not pass then an additional parameter to each instrument call? the score lines would be:
  i 1 0 1 7.00 0 ;no filter
  i 1 + 1 7.02 1; filer

and the instrument:

instr 1
     ifilter_onoff = p4
     kenv adsr .0001, 1, .01, .001
     kcps = cpspch(p4)

     asig vco2 kenv * 0.8, kcps

     if ifilter_onoff == 1 then
         asig butterlp asig, 500
     endif

     ga_record += asig
endin

best -
  joachim

hey joachim,

thanks for the quick response. that file/code that I posted above is more to test/debug what i am hearing. although passing the filter on/off as p4 is more logical, I am really trying to investigate the difference between event times and linseg times(in this file all durations are 1s)… in this file, i have made all p3’s 1 second, and have made the linseg portions 1 second as well.

I have a few theories as to what is going on, but my knowledge here is pretty surface level. I have updated the file to hopefully rule out any other issues. In this new file, I have:

  • separated the two different notes into unique instruments/channels

  • processed the filter effect prior to the if/then statement(was thinking that turning on the buttercup opcode might cause some lag/drift; this does not seem to be the case)

  • converted the event times from the ‘+’ operator to hard coded integers

These changes have made the drift even a little more apparent, you can hear the filter ‘click’ at the beginning of the second upper note and gradually move further into that note. (Very similar to different trains(cool, but not what I am trying to achieve here)).

It is also worth noting that with this linseg, the durations alternate between 1 second, and 0 seconds. Perhaps this 0 second duration is not truly 0? This might cause the gradual drift away from the event on times? If a 0 duration is not in fact 0, do we know how many milliseconds it might be?

I will leave the updated code snippet below. You can listen via -odac, or again bounce the file and listen to different points.

Thanks again Joachim and everybody,

walker

; -odac

sr = 44100

ksmps = 441

nchnls = 2

0dbfs = 1

ga_synth1 init 0

ga_synth2 init 0

ga_record init 0

instr 100

fout “OUTPU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, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0

afilt butterlp ga_synth2, 500

if gkfil_onoff == 1 then

aout = afilt

else

aout = ga_synth2

endif

ga_record += aout + ga_synth1

clear ga_synth1

clear ga_synth2

endin

instr 1

kenv adsr .0001, 1, .01, .001

kcps = cpspch(p4)

asig vco2 kenv * 0.8, kcps

ga_synth1 += asig

endin

instr 2

kenv adsr .0001, 1, .01, .001

kcps = cpspch(p4)

asig vco2 kenv * 0.8, kcps

ga_synth2 += asig

endin

i100 0 100

i10 0 100

i 1 0 1 7.00

i 2 1 1 7.02

i 1 2 1 7.00

i 2 3 1 7.02

i 1 4 1 7.00

i 2 5 1 7.02

i 1 6 1 7.00

i 2 7 1 7.02

i 1 8 1 7.00

i 2 9 1 7.02

i 1 10 1 7.00

i 2 11 1 7.02

i 1 12 1 7.00

i 2 13 1 7.02

i 1 14 1 7.00

i 2 15 1 7.02

i 1 16 1 7.00

i 2 17 1 7.02

i 1 18 1 7.00

i 2 19 1 7.02

i 1 20 1 7.00

i 2 21 1 7.02

i 1 22 1 7.00

i 2 23 1 7.02

i 1 24 1 7.00

i 2 25 1 7.02

i 1 26 1 7.00

i 2 27 1 7.02

i 1 28 1 7.00

i 2 29 1 7.02

i 1 30 1 7.00

i 2 31 1 7.02

i 1 32 1 7.00

i 2 33 1 7.02

i 1 34 1 7.00

i 2 35 1 7.02

i 1 36 1 7.00

i 2 37 1 7.02

i 1 38 1 7.00

i 2 39 1 7.02

i 1 40 1 7.00

i 2 41 1 7.02

i 1 42 1 7.00

i 2 43 1 7.02

i 1 44 1 7.00

i 2 45 1 7.02

i 1 46 1 7.00

i 2 47 1 7.02

i 1 48 1 7.00

i 2 49 1 7.02

i 1 50 1 7.00

i 2 51 1 7.02

i 1 52 1 7.00

i 2 53 1 7.02

i 1 54 1 7.00

i 2 55 1 7.02

i 1 56 1 7.00

i 2 57 1 7.02

i 1 58 1 7.00

i 2 59 1 7.02

i 1 60 1 7.00

i 2 61 1 7.02

i 1 62 1 7.00

i 2 63 1 7.02

i 1 64 1 7.00

i 2 65 1 7.02

i 1 66 1 7.00

i 2 67 1 7.02

i 1 68 1 7.00

i 2 69 1 7.02

i 1 70 1 7.00

i 2 71 1 7.02

i 1 72 1 7.00

i 2 73 1 7.02

i 1 74 1 7.00

i 2 75 1 7.02

i 1 76 1 7.00

i 2 77 1 7.02

i 1 78 1 7.00

i 2 79 1 7.02

i 1 80 1 7.00

i 2 81 1 7.02

i 1 82 1 7.00

i 2 83 1 7.02

i 1 84 1 7.00

i 2 85 1 7.02

i 1 86 1 7.00

i 2 87 1 7.02

i 1 88 1 7.00

i 2 89 1 7.02

i 1 90 1 7.00

i 2 91 1 7.02

i 1 92 1 7.00

i 2 93 1 7.02

i 1 94 1 7.00

i 2 95 1 7.02

i 1 96 1 7.00

i 2 97 1 7.02

i 1 98 1 7.00

i 2 99 1 7.02

i 1 100 1 7.00

i 2 101 1 7.02

i 1 102 1 7.00

i 2 103 1 7.02

i 1 104 1 7.00

i 2 105 1 7.02

i 1 106 1 7.00

i 2 107 1 7.02

i 1 108 1 7.00

i 2 109 1 7.02

i 1 110 1 7.00

i 2 111 1 7.02

i 1 112 1 7.00

i 2 113 1 7.02

i 1 114 1 7.00

i 2 115 1 7.02

i 1 116 1 7.00

i 2 117 1 7.02

i 1 118 1 7.00

i 2 119 1 7.02

i 1 120 1 7.00

i 2 121 1 7.02

i 1 122 1 7.00

i 2 123 1 7.02

i 1 124 1 7.00

i 2 125 1 7.02

i 1 126 1 7.00

i 2 127 1 7.02

i 1 128 1 7.00

i 2 129 1 7.02

i 1 130 1 7.00

i 2 131 1 7.02

i 1 132 1 7.00

i 2 133 1 7.02

i 1 134 1 7.00

i 2 135 1 7.02

i 1 136 1 7.00

i 2 137 1 7.02

i 1 138 1 7.00

i 2 139 1 7.02

i 1 140 1 7.00

i 2 141 1 7.02

i 1 142 1 7.00

i 2 143 1 7.02

i 1 144 1 7.00

i 2 145 1 7.02

i 1 146 1 7.00

i 2 147 1 7.02

i 1 148 1 7.00

i 2 149 1 7.02

i 1 150 1 7.00

i 2 151 1 7.02

i 1 152 1 7.00

i 2 153 1 7.02

i 1 154 1 7.00

i 2 155 1 7.02

i 1 156 1 7.00

i 2 157 1 7.02

i 1 158 1 7.00

i 2 159 1 7.02

i 1 160 1 7.00

i 2 161 1 7.02

i 1 162 1 7.00

i 2 163 1 7.02

i 1 164 1 7.00

i 2 165 1 7.02

i 1 166 1 7.00

i 2 167 1 7.02

i 1 168 1 7.00

i 2 169 1 7.02

i 1 170 1 7.00

i 2 171 1 7.02

i 1 172 1 7.00

i 2 173 1 7.02

i 1 174 1 7.00

i 2 175 1 7.02

i 1 176 1 7.00

i 2 177 1 7.02

i 1 178 1 7.00

i 2 179 1 7.02

i 1 180 1 7.00

i 2 181 1 7.02

i 1 182 1 7.00

i 2 183 1 7.02

i 1 184 1 7.00

i 2 185 1 7.02

i 1 186 1 7.00

i 2 187 1 7.02

i 1 188 1 7.00

i 2 189 1 7.02

i 1 190 1 7.00

i 2 191 1 7.02

i 1 192 1 7.00

i 2 193 1 7.02

i 1 194 1 7.00

i 2 195 1 7.02

i 1 196 1 7.00

i 2 197 1 7.02

i 1 198 1 7.00

i 2 199 1 7.02

i 1 200 1 7.00

i 2 201 1 7.02

i 1 202 1 7.00

i 2 203 1 7.02

i 1 204 1 7.00

i 2 205 1 7.02

i 1 206 1 7.00

i 2 207 1 7.02

i 1 208 1 7.00

i 2 209 1 7.02

i 1 201 1 7.00

i 2 202 1 7.02

i 1 203 1 7.00

i 2 204 1 7.02

i 1 205 1 7.00

i 2 206 1 7.02

i 1 207 1 7.00

i 2 208 1 7.02

i 1 209 1 7.00

i 2 210 1 7.02

e

hi again -

i have no doubt about the drift you mention. i think it has to do mostly with the ksmps size. perhaps it is worth to try ksmps=1 --- i'd expect that it will be less drift then.

what i meant, and still mean: if you want a real sync, you have to look or anoher solution (architecture) than the one you chose. depending on your real case, there might be several ones. if you like, let's continue this thread in figuring out what might work.

regards -
  joachim

Joachim,

Thanks for helping me on this. Setting ksmps=1 helped, but the drift did still occur after several val/dur pairs and the write time increased significantly. I am messing around with triggering the filter on/off via score events, so far this is working better (will post soon). It seems like it would be advantageous to have a linseg equivalent that operated on total time rather than summing durations… again, surface dweller here, so not sure if that is difficult or impossible to implement (or relevant enough for the user base).

Thanks again,

walker

Looking at the source, the code is ill conceived and will always drift if kr is not an integer (in fact it seems that these concerns have already surfaced before and the code has a naive hack to try to fix this rounding problem). I would suggest implementing it again: for reference, here is an opcode which does the same as linseg but works as expected:

If you replace your line with

 gkfil_onoff linenv 1, 0, 0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0, 1,  0, 0,  1, 1,  1, 0,  0

Csound mailing list Send bugs reports to Discussions of bugs and features can be posted here

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