[Csnd] Question re: tab vs tab_i

If I have a table, for example:
iFrq ftgen 1, 0, -5, -2, 100, 200, 300, 400, 500

then

iFrq1 = tab_i(0, 1)

works fine, but

kFrq1 = tab(0, 1)

gives an error message "tab off end". I'm curious as to why, as the index isn't changing.

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

Hi Scott,
I copied your code into an instrument as is. Using either statement
worked fine, as did using both.

I wouldn't know why this happens. Perhaps you could post the complete
code of your instrument?

As an aside: it makes for better reading if you write:
iFreq1 = tab_i(0, iFreq)

Best wishes,

Jeanette

Apr 25 2023, Scott Daughtrey has written:

Hi Jeanette, thanks for taking the time to test & reply.

The instr is getting big so just posting an example. It’s a formant/vowel type thing, so ultimately probably using a morph opcode anyways & the issue will be moot; that’s also why I didn’t use iFreq = tab_i(0, iFrq) as I was testing different vowel freq tables using p4 to select the table. But your point was well taken =)

Nonetheless when I come across these issues I like to follow up for future reference or in case I need to report a bug.

So here’s a short example:

-o dac

sr = 48000
ksmps = 32
nchnls = 1
0dbfs = 1

iFrq ftgen 1, 0, -4, -2, 100, 200, 300, 400, 500

instr 1
iFrq1 = tab_i(2, 1)
kNdx = 0
kFrq1 = tab(0, 1)
aSig = oscil(.8, iFrq1)
out aSig
endin

i1 0 3

This gives the error:
PERF ERROR in instr 1 (opcode tab) line 17: tab off end 2147483647 from file string (1) #a1 tab 0 1 0

If I comment out kFrq1 = tab(0, 1) it runs fine. Where it gets even weirder is if I instead use kFrq1 = tab(kNdx, 1), then still an error but instead it’s:
PERF ERROR in instr 1 (opcode tab) line 17: tab off end 100 from file string (1) #a1 tab kNdx 1 0

In that case it’s reporting the right value for index 0 (tab off end 100) as opposed to tab off end 2147483647. As to why I haven’t got a clue. Likewise if I use kNdx = 1, then “tab off end 200” etc. But always an error & code won’t run.

So not sure if I’m doing something wrong or whether this is a Csound for Android specific problem

Best & thanks again,

Scott

ST Music
https://soundcloud.com/st-csound
https://soundcloud.com/stoons-1

https://youtube.com/channel/UCGhwmkS1uWmX6mhTIQ0IDsg

Apr 25 2023, ST Music has written:
...
Hm, the error output citing #a1 tab ... makes me think. Have you tried:
kFrq1 = tab:k(0, 1)
tab can return both an a-rate or k-rate signal. It should not happen, I
think, but this error suggests that it might have used the a-rate
version, which might cause issues.

HTH.

Best wishes,

Jeanette

Hi Scott,
FYI, Your example below runs without error on my system (v6.14 on Haiku OS).

  -- Pete --

Thanks Pete, appeciate the feedback. Appears it may be specific to either the Csound for Android app or library version 6.16 which I think it uses.

Jeanette, good catch, you were right (no surprise there =) ). Although it’s fairly rare that type annotations are required in this type of situation I occasionally come across them. I can see why with function(al) syntax in Csound it might be useful to always use type annotations as a general practice but seems like a pain, guess I’m lazy.

So turns out either:
kFrq1 = tab:k(kNdx, 1)

or old school

kFrq1 tab kNdx, 1

will work in this specific case.

Scott

ST Music
https://soundcloud.com/st-csound
https://soundcloud.com/stoons-1

https://youtube.com/channel/UCGhwmkS1uWmX6mhTIQ0IDsg