[Csnd] Interpolated table access and its challenges

Hey hey,
I'm simply trying to read/calculate an interpolated value. I want to "rescale" a 0-1 input to a succession of 1/25, 1/12.5 and 1. So I created a table:
iValueTab = ftgenonce(0, 0, 4, 2, .04, .08, 1, 1)
No I can scan through that with an index between 0 and .5. This is all rather unintuitive:
kIndex = line:k(0, p3, .5)
kValue = tablei:k(kIndex, iValueTab, 1)
I thought an index of at least 0-.75 would do the trick, but after index values of .5 the output is 1.

Is there a more intuitive/numerically meaningful way to solve this issue?

Best wishes and thanks,

Jeanette

yeah interesting --- i tried it and i see your point.
i found two possible solutions.
the first avoids to reach 1, in normalized reading.
the second
- adds one value to the table, and
- multiplies the normalized index by the last raw index (here 2)
for me this second solution looks better.
but perhaps best is to put the three values in an array and write a UDO for linear interpolation?
best -
  j

instr 1 //normalized
   iVals = ftgen(0,0,3,-2,1/25,2/25,1)
   kIndx = linseg:k(0,1,0.999999)
   kValue = tablei:k(kIndx,iVals,1)
   printk(.1,kValue)
endin
schedule(1,0,1.1)

instr 2 //raw indices
   iVals = ftgen(0,0,4,-2,1/25,2/25,1)
   kIndx = linseg:k(0,1,1)
   kIndx *= 2
   kValue = tablei:k(kIndx,iVals)
   printk(.1,kValue)
endin
schedule(2,2,1.1)

Hi Joachim,
thanks for your solutions. I think I'd prefer the first solution, but it's good to have the choice. Many thanks for investigating and chiming in!

Best wishes,

Jeanette

Mar 6 2024, joachim heintz has written:


kidx = linseg:k(0, p3, 1)
kval = bpf:k(kidx, 0, 1/25, 0.5, 2/25, 1, 1)
printks "kidx: %f, kval: %f\n", 0.01, kidx, kval

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

Wouldn't a table like this do the job with your original code?

f1 0 1025 7 0.04 512 0.08 256 1 256 1

Prof. Victor Lazzarini
Maynooth University
Ireland

Hi Eduardo!
Mar 7 2024, Eduardo Moguillansky has written:

kidx = linseg:k0, p3, 1

kval = bpf:kkidx, 0, 1/25, 0\.5, 2/25, 1, 1

...
Many thanks. This is a great solution! Simple and straightforward.

Best wishes,

Jeanette