| Ave Csound coders,
This is to announce my intention to design an opcode which can
generate subtle performance errors in most other opcodes
used in the orchestra.
"How?" you ask - "Csound is pretty stable isitnot?"
Easy!
As some of you may know, the Csound orchestra parser will,
when it finds an (i-type, or k-rate) opcode argument which
is set with a constant value (ie a direct number), store this
value in a pool, and let the opcode parameter point to this value.
If two opcodes use the same constant value, they will thus
point to the same value in the pool.
k-rate variables which use a named orchestra variable are
however given individual storage space.
You can now figure out the new opcode: It will traverse this pool
of constants at k-rate and swap around values, or insert new
random values. (I think I'll call it "leatoric", so as not to
pollute namespace.)
And if this opcode is not included in the canonical sources,
there are actually a few who already have the feature built-in.
To be specific, any opcode which assigns values to any of its own
(k-rate or i-time) input arguments, may sometimes corrupt some
value in the const pool. This will then ruin the performance of
other opcodes which happened to be inited with the same value
constant.
Here are the ones I've found and confirmed so far:
cross2 will correct the iovlp value without warning to make sure
it is a power of two. (Lines 362-364 in Cross.c)
grain forces kgdur to be same length as imgdur. (Line 78 in Grain.c)
nlfilt will similarly correct the kL input value to stay in the
range 1.0 - 1024.0. (Lines 50, 53 in Nlfilt.c)
pitch sets irolloff to 0.6 if it was negative. (Line 150 in pitch.c)
repluck corrects argument iplk to be in range 0.0 - 1.0.
(Line 39 in Repluck.c)
xyin, will, if a min value is larger than the corresponding max,
swap around its argument values.
(Several places in lines 16-33 in Windin.c)
Except for xyin, which got me on the track, these were all
detected by greping sources for "*p->\w+ = " (where "\w+" means
"one or more alphanumerics") and looking at those not called
*p->ar, *p->out etc. I have probably missed some.
The problem can of course be repaired locally for these few cases,
the (temporary?) fix being to make them cause initerrors or perferrors,
thus making Csound slightly more picky.
But programmers should be warned, as this is nowhere documented.
Perhaps there should also be some change to the parser, but
I haven't dug deeply enough to have any advise here - this is
for the maintainer(s) to decide. (I could continue digging, but
if anybody has some idea about this, that's probably quicker
and better.)
Regards,
re
------------- Bugdemo -------------
instr 1 ; Demo of bugs in some opcodes
; This causes invalid ftable no 0.3 in victim
; kx, ky xyin .03, 1, .3, 0, 1, .5, 440
; cross2 paraphernalia
anysig rand 30000
ar1 pluck 20000, 300, 250, 0, 1
ar2 oscil ar1, 440, 1
kbias line 0, p3, 1
; This causes invalid ftable no 2 in victim
; ar cross2 ar1, ar2, 512, 1, 8, kbias
; This causes amp of victim to be 1.0 instead of 0.1
; ar nlfilt anysig, 2, 3, 4, 5, 0.1
; This causes invalid ftable no 0.0 in victim
; ar repluck 1, 10000, 220, .7, .5, anysig
; This causes cps of victim to be .2 instead of 440
; ar grain 25000, 2, 3, 4, 5, 440, 1, 8, .2
; Change victim ftable to -1, then this will cause it to be 0.6
; kpitch, kamp pitch anysig, .2, 7.0, 8.0, 1, 12, 10, 7.5, 6, 10, 4, -1
endin
instr 2
; The victim
ar oscil .1, 440, 1
out ar*300000
endin
f1 0 8192 10 1 ; Sine
f8 0 1024 20 4 ; Blackman
i1 0 1
i2 0 5
e
|