File: tablera.html

package info (click to toggle)
csound-doc 3.47b2-2
  • links: PTS
  • area: non-free
  • in suites: woody
  • size: 1,492 kB
  • ctags: 272
  • sloc: makefile: 36
file content (183 lines) | stat: -rw-r--r-- 11,158 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<HTML>
<TITLE>TABLERA</TITLE>
<CENTER><A NAME="tablera"></A>
<HR><B><A HREF="../REFER.html">QUICK-REF</A></B> - <B><A HREF="../TITLE.html"><FONT SIZE=+1>C</FONT>soundManual</A>
- <A HREF="./SIG_GENS.html#">Top of this section</A></B> - <A HREF="./tablegpw.html">Previous</A>
- <A HREF="../CONTENTS.html">Contents</A> - <A HREF="../INDEX.html">Index</A>
- <A HREF="./loscil.html">Next</A>&nbsp;
<HR></CENTER>

<H2>
tablera, tablewa</H2>

<PRE>&nbsp;&nbsp; ar&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <B>tablera</B>&nbsp;&nbsp;&nbsp;&nbsp; kfn, kstart, koff
&nbsp;&nbsp; kstart&nbsp;&nbsp; <B>tablewa</B>&nbsp;&nbsp;&nbsp;&nbsp; kfn, asig, koff</PRE>

<HR>
<H4>
<U>DESCRIPTION</U></H4>
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.
<H4>
<U>INITIALIZATION</U></H4>
<I>ar</I> - a rate destination for reading ksmps values from a table.

<P><I>kfn</I> - i or k rate number of the table to read or write.

<P><I>kstart</I> - Where in table to read or write.

<P><I>asig</I> - a rate signal to read from when writing to the table.

<P><I>koff</I> - i or k rate offset into table. Range unlimited - see explanation
at end of this section.
<H4>
<U>PERFORMANCE</U></H4>
In one application, these are intended to be used in pairs, or with several
<B>tablera</B> ugens before a <B>tablewa</B> - all sharing the same <I>kstart</I>
variable.

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

<P><B>tablera</B> starts reading from location <I>kstart</I>. <B>tablewa</B>
starts writing to location <I>kstart</I>, and then writes to <I>kstart</I>
with the number of the location one more than the one it last wrote. (Note
that for <B>tablewa</B>, <I>kstart</I> 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 <I>kstart</I>.

<P>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 <B>tablewa</B> ugen, assuming that <I>kstart</I> started at 0.
<PRE>Run no. Initial&nbsp; Final&nbsp;&nbsp;&nbsp; locations written&nbsp;
<I>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; kstart</I>&nbsp;&nbsp; <I>kstart</I></PRE>

<PRE>1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 1 2 3 4</PRE>

<PRE>2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 10&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5 6 7 8 9</PRE>

<PRE>3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 10&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 15&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 10 11 12 13 14</PRE>

<PRE>4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 15&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 15</PRE>
This is to facilitate processing table data using standard a rate orchestra
code between the <B>tablera</B> and <B>tablewa</B> ugens:

<P><U>Notes on tablera and tablewa :</U>

<P>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.

<P>Several cautions:
<UL>
<LI>
The k rate code in the processing loop is really running at a rate, so
time dependant functions like port and oscil work faster than normal -
their code is expecting to be running at k rate.</LI>

<LI>
This system will produce undesirable results unless the ksmps fits within
the table length. For instance a table of length 16 will accomodate 1 to
16 samples, so this example will work with ksmps = 1 to 16.</LI>


<P>Both these ugens generate an error and deactivate the instrument if
a table with length &lt; ksmps is selected. Likewise an error occurs if
<I>kstart</I> is below 0 or greater than the highest entry in the table
- if <I>kstart</I> >= table length.
<LI>
<I>kstart</I> is intended to contain integer values between 0 and (table
length - 1). Fractional values above this should not affect operation but
do not achieve anything useful.</LI>

<LI>
These ugens do not do interpolation and the <I>kstart</I> and <I>koff</I>
parameters always have a range of 0 to (table length - 1) - not 0 to 1
as is available in other table read/write ugens. <I>koff</I> can be outside
this range but it is wrapped around by the final AND operation.</LI>

<LI>
These ugens are permanently in wrap mode. When <I>koff</I> is 0, no wrapping
needs to occur, since the <I>kstart</I>++ index will always be within the
table's normal range. <I>koff</I> != 0 can lead to wrapping.</LI>

<LI>
The offset does not affect the number of read/write cycles performed, or
the value written to <I>kstart</I> by tablewa.</LI>

<LI>
These ugens cannot read or write the guardpoint. Use tablegpw to write
the guardpoint after manipulations have been done with tablewa.</LI>
</UL>

<H4>
<U>EXAMPLES:</U></H4>

<PRE>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;kstart&nbsp;&nbsp; =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; Read 5 values from table into an&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; a rate variable.
&nbsp;lab1:
&nbsp;&nbsp; atemp&nbsp; <B>tablera</B> ktabsource, kstart, 0&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; Process the values using a rate code.
&nbsp;&nbsp; atemp&nbsp; =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; log(atemp)&nbsp;&nbsp;&nbsp; ; Write it back to the table
&nbsp;&nbsp; kstart <B>tablewa</B> ktabdest, atemp, 0&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; Loop until all table locations have been processed.
&nbsp;if ktemp > 0 goto lab1</PRE>
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.

<P>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.

<P>Another application is:
<PRE>&nbsp;&nbsp; kzero = 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp; kloop = 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp; kzero <B>tablewa</B> 23, asignal, 0 ; ksmps a rate samples written
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; into locations 0 to (ksmps -1) of table 23.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp; lab1: ktemp <B>table</B> kloop, 23&nbsp; ; Start a loop which runs ksmps times,&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; in which each cycle processes one of&nbsp;
&nbsp;&nbsp;&nbsp; [ Some code to manipulate ] ; table 23's values with k rate orchestra
&nbsp;&nbsp;&nbsp; [ the value of ktemp. ]&nbsp;&nbsp;&nbsp;&nbsp; ; code.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; <B>tablew</B> ktemp, kloop, 23&nbsp;&nbsp;&nbsp;&nbsp; ; Write the processed value to the table.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;
&nbsp;&nbsp; kloop = kloop + 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; Increment the kloop, which is both the
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; pointer into the table and the loop&nbsp;
&nbsp;&nbsp; if kloop &lt; ksmps goto lab1&nbsp;&nbsp; ; counter. Keep looping until all values
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; in the table have been processed.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp; asignal&nbsp;&nbsp; <B>tablera</B> 23, 0, 0&nbsp;&nbsp; ; Copy the table contents back
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; to an a rate variable.</PRE>
<I>koff</I> - 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.

<P>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.
<CENTER><P>
<HR><B><A HREF="../REFER.html">QUICK-REF</A></B> - <B><A HREF="../TITLE.html"><FONT SIZE=+1>C</FONT>soundManual</A>
- <A HREF="./SIG_GENS.html#">Top of this section</A></B> - <A HREF="./tablegpw.html">Previous</A>
- <A HREF="../CONTENTS.html">Contents</A> - <A HREF="../INDEX.html">Index</A>
- <A HREF="./loscil.html">Next</A>&nbsp;
<HR></CENTER>


<P><CENTER>
<B><I><FONT COLOR="#006600">HTML Csound Manual - <FONT SIZE=-1>&copy;
Jean Pich&eacute; &amp; Peter J. Nix, 1994-97</FONT></FONT></I></B>&nbsp;
</CENTER>
</HTML>