QUICK-REF - CsoundManual - Top of this section - Previous - Contents - Index - Next 

tablera, tablewa

   ar       tablera     kfn, kstart, koff
   kstart   tablewa     kfn, asig, koff

DESCRIPTION

These ugens read and write tables in sequential locations to and from an a rate variable. Some thought is required before using them. They have at least two major, and quite different, applications which are discussed below.

INITIALIZATION

ar - a rate destination for reading ksmps values from a table.

kfn - i or k rate number of the table to read or write.

kstart - Where in table to read or write.

asig - a rate signal to read from when writing to the table.

koff - i or k rate offset into table. Range unlimited - see explanation at end of this section.

PERFORMANCE

In one application, these are intended to be used in pairs, or with several tablera ugens before a tablewa - all sharing the same kstart variable.

These read from and write to sequential locations in a table at audio rates, with ksmps floats being written and read each cycle.

tablera starts reading from location kstart. tablewa starts writing to location kstart, and then writes to kstart with the number of the location one more than the one it last wrote. (Note that for tablewa, kstart is both an input and output variable.) If the writing index reaches the end of the table, then no further writing occurs and zero is written to kstart.

For instance, if the table's length was 16 (locations 0 to 15), and ksmps was 5. Then the following steps would occur with repetitive runs of the tablewa ugen, assuming that kstart started at 0.

Run no. Initial  Final    locations written
        kstart   kstart

1       0        5        0 1 2 3 4
2       5        10       5 6 7 8 9
3       10       15       10 11 12 13 14
4       15       0        15
This is to facilitate processing table data using standard a rate orchestra code between the tablera and tablewa ugens:

Notes on tablera and tablewa :

These are a fudge, but they allow all Csounds k rate operators to be used (with caution) on a rate variables - something that would only be possible otherwise by ksmps = 1, downsamp and upsamp.

Several cautions:

EXAMPLES:

                                  
 kstart   =       0      ; Read 5 values from table into an 
                         ; a rate variable.
 lab1:
   atemp  tablera ktabsource, kstart, 0 
                         ; Process the values using a rate code.
   atemp  =       log(atemp)    ; Write it back to the table
   kstart tablewa ktabdest, atemp, 0 
         ; Loop until all table locations have been processed.
 if ktemp > 0 goto lab1
The above example shows a processing loop, which runs every k cycle, reading each location in the table ktabsource, and writing the log of those values into the same locations of table ktabdest.

This enables whole tables, parts of tables (with offsets and different control loops) and data from several tables at once to be manipulated with a rate code and written back to another (or to the same) table. This is a bit of a fudge, but it is faster than doing it with k rate table read and write code.

Another application is:

   kzero = 0                    
   kloop = 0                    
                                 
   kzero tablewa 23, asignal, 0 ; ksmps a rate samples written
                                ; into locations 0 to (ksmps -1) of table 23.
                                
   lab1: ktemp table kloop, 23  ; Start a loop which runs ksmps times, 
                                ; in which each cycle processes one of 
    [ Some code to manipulate ] ; table 23's values with k rate orchestra
    [ the value of ktemp. ]     ; code.
                                 
    tablew ktemp, kloop, 23     ; Write the processed value to the table.
                                ;
   kloop = kloop + 1            ; Increment the kloop, which is both the
                                ; pointer into the table and the loop 
   if kloop < ksmps goto lab1   ; counter. Keep looping until all values
                                ; in the table have been processed.
                                
   asignal   tablera 23, 0, 0   ; Copy the table contents back
                                ; to an a rate variable.
koff - This is an offset which is added to the sum of kstart and the internal index variable which steps through the table. The result is then ANDed with the lengthmask (000 0111 for a table of length 8 - or 9 with guardpoint) and that final index is used to read or write to the table. koff can be any value. It is converted into a long using the ANSI floor() function so that -4.3 becomes -5. This is what we would want when using offsets which range above and below zero.

Ideally this would be an optional variable, defaulting to 0, however with the existing Csount orchestra read code, such default parameters must be init time only. We want k rate here, so we cannot have a default.


QUICK-REF - CsoundManual - Top of this section - Previous - Contents - Index - Next 
HTML Csound Manual - © Jean Piché & Peter J. Nix, 1994-97