| i have written now a new section in
http://write.flossmanuals.net/csound/e-arrays/ called "More on Array
Rates". i put it here below and appreciate any corrections.
while writing, i was wondering whether i(kArr[i]) should perhaps better
yield an error, instead of always returning zero, for instance:
kArray[] fillarray 1, 2, 3
iFirst = i(kArray[0])
print iFirst
returns iFirst as zero which is obviously nonsense from the user's point
of view, but can be hidden as a wrong result because it passes silently.
what do you think?
joachim
#################################
More on Array Rates
Usually the first character of a variable name in Csound shows whether
it is i-rate or k-rate or a-rate. But for arrays, we have actually two
signifiers: the array variable name, and the index type. If both
coincide, it is easy:
* i_array[i_index] reads and writes at i-time
* k_array[k_index] reads and writes at k-time
* a_array[a_index] reads and writes at a-time
But what to do if array type and index type do not coincide? In general,
the index type will then determine whether the array is read or written
only once (at init-time) or at each k-cycle. This is valid in particular
for S_arrays (containing strings) and f_arrays (containing f-data).
Other cases are:
* i_array[k_index] reads at k-time; writing is not possible (yields
a runtime error)
* k_array[i_index] reads and writes at k-rate
* a_array[i_index] reads and writes at a-rate
For usual k-variables, you can get the value at init-time via the
expression i(kVar), for instance:
instr 1
gkLine linseg 1, 1, 2
schedule 2, .5, 0
endin
instr 2
iLine = i(gkLine)
print iLine
endin
will print: iLine = 1.499.
This expression cannot be used for arrays:
kArray[] fillarray 1, 2, 3
iFirst = i(kArray[0])
print iFirst
will print: iFirst = 0.000, which is obviously not what could be
expected. For this purpose, the i() expression can be used to pass the
index as second argument:
kArray[] fillarray 1, 2, 3
iFirst = i(kArray, 0)
print iFirst
will print: iFirst = 1.000.
############################
On 04/11/16 21:34, Victor Lazzarini wrote:
> Outputs -- means you can read it at k-time,
> but not write to it.
>
> Victor Lazzarini
> Dean of Arts, Celtic Studies, and Philosophy
> Maynooth University
> Ireland
>
>> On 4 Nov 2016, at 20:25, joachim heintz wrote:
>>
>> in the wiki which i quoted is written:
>> "isig[k] - outputs k-val"
>>
>> if there are reasons not to allow this, ok. otherwise i'd think it would be useful and would fit to the usage of tables.
>>
>>
>>> On 04/11/16 19:52, Victor Lazzarini wrote:
>>> According to what we discussed, i-rate arrays cannot be set at perf-time.
>>>
>>> Victor Lazzarini
>>> Dean of Arts, Celtic Studies, and Philosophy
>>> Maynooth University
>>> Ireland
>>>
>>>> On 4 Nov 2016, at 17:51, joachim heintz wrote:
>>>>
>>>> i did some more tests on array semantics; in particular i compared i-arrays and tables. as the usage of tables is so old in csound, it might be like a model for array usage.
>>>>
>>>> all good so far, but what did not work is to set an i-array at k-time. the line
>>>> giArray[kIndx] = -2
>>>> leads to the error message:
>>>> Cant set i-array at k-rate
>>>> ##array_set.e giArray #i0 kIndx
>>>>
>>>> according to http://github.com/csound/csound/wiki/Array-Semantics i think it should work. and it would be good to see it working — if nothing is against — because in function tables we do it regularily.
>>>>
>>>> the complete example / comparison is pasted below.
>>>>
>>>> joachim
>>>>
>>>>
>>>>
>>>>
>>>> -n -m0
>>>>
>>>>
>>>>
>>>> sr = 44100
>>>> ksmps = 32
>>>> nchnls = 2
>>>> 0dbfs = 1
>>>>
>>>> giTable ftgen 0, 0, 7, -2, 1, 2, 3, 4, 5, 6, 7
>>>> giArray[] fillarray 1, 2, 3, 4, 5, 6, 7
>>>>
>>>>
>>>> instr Read_i ;get i-val from i-table or i-array
>>>> iIndx = 2
>>>> iTabEl table iIndx, giTable
>>>> iArrEl = giArray[iIndx]
>>>> print iTabEl, iArrEl
>>>> endin
>>>>
>>>> instr Read_k ;get k-val from i-table or i-array
>>>> kIndx init 2
>>>> kTabEl table kIndx, giTable
>>>> kArrEl = giArray[kIndx]
>>>> printks "kTable = %.3f kArrEl = %.3f\n", 0, kTabEl, kArrEl
>>>> turnoff
>>>> endin
>>>>
>>>> instr Write_i ;change table at i and call Read-i/k
>>>> iIndx = 2
>>>> tablew -2, iIndx, giTable
>>>> giArray[iIndx] = -2
>>>> schedule "Read_i", 0, 1
>>>> schedule "Read_k", 0, 1
>>>> endin
>>>>
>>>> instr Write_k ;change table at k and call Read-i/k
>>>> kIndx init 2
>>>> tablew -2, kIndx, giTable
>>>> giArray[kIndx] = -2
>>>> schedule "Read_i", 0.1, 1
>>>> schedule "Read_k", 0.1, 1
>>>> turnoff
>>>> endin
>>>>
>>>>
>>>>
>>>> i "Read_i" 0 1
>>>> i "Read_k" 1 1
>>>> i "Write_i" 2 1
>>>> i "Write_k" 3 1
>>>>
>>>>
>>> |