00001 /* 00002 ugrw1.h: 00003 00004 Copyright (C) 1997 Robin Whittle 00005 00006 This file is part of Csound. 00007 00008 The Csound Library is free software; you can redistribute it 00009 and/or modify it under the terms of the GNU Lesser General Public 00010 License as published by the Free Software Foundation; either 00011 version 2.1 of the License, or (at your option) any later version. 00012 00013 Csound is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU Lesser General Public License for more details. 00017 00018 You should have received a copy of the GNU Lesser General Public 00019 License along with Csound; if not, write to the Free Software 00020 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 00021 02111-1307 USA 00022 */ 00023 00024 /* UGRW1.H */ 00025 /* These files are based on Robin Whittle's 00026 * ugrw1.c of 27 August 1996 00027 * and ugrw1.h of 7 January 1995 00028 * 00029 * In February 1997, John Fitch reformatted the comments and 00030 * cleaned up some code in printksset() - which was working fine 00031 * but was inelegantly coded. 00032 * 00033 * 00034 * Copyright notice - Robin Whittle 25 February 1997 00035 * 00036 * Documentation files, and the original .c and .h files, with more 00037 * spaced out comments, are available from http://www.firstpr.com.au 00038 * 00039 * The code in both ugrw1 and ugrw2 is copyright Robin Whittle. 00040 * Permission is granted to use this in whole or in part for any 00041 * purpose, provided this copyright notice remains intact and 00042 * any alterations to the source code, including comments, are 00043 * clearly indicated as such. 00044 */ 00045 00046 #include "csoundCore.h" 00047 00048 /* 00049 * Unit generators by Robin Whittle 6 January 1996 00050 * Header file containing data structures for UGRW1.C. 00051 */ 00052 00053 /* TABLEW data structure used by all the tablew subroutines. */ 00054 00055 typedef struct { 00056 OPDS h; 00057 MYFLT *xsig; /* Input value to write to table. */ 00058 MYFLT *xndx; /* Index into the table where want to write */ 00059 MYFLT *xfn; /* Number of table we are writing to. */ 00060 MYFLT *ixmode; /* Index mode (optional parm). 00061 * 0 --> Use raw xfn and ixoff. 00062 * 1 --> Use these with a range of 0 to 1 for 00063 * the entire range of the table. */ 00064 MYFLT *ixoff; /* Offset (opt). Fixed value to add to ndx*/ 00065 MYFLT *iwgmode; /* Wrap and guard point mode (optional) 00066 * 0 --> Limit indx to between 0 table len 00067 * 1 --> Index wraps around modulo len 00068 * 2 --> Write with 0.5 step offset, and 00069 * write both 0 and guard with the 00070 * same data. */ 00071 00072 /* Internal variable for previous state of xfn. */ 00073 long pfn; /* Internal variable for what to multiply 00074 * the ndx and ixoff by. Set to 1 or table 00075 * length by tblwset() depending on ixmode. 00076 */ 00077 long xbmul; /* Internal variable for iwrap and igmode. */ 00078 int iwgm; /* Internal variable for offset. */ 00079 MYFLT offset; /* Pointer to data structure used to access 00080 * function table. tblwset() writes this, based 00081 * on the value of xfn. 00082 */ 00083 FUNC *ftp; 00084 } TABLEW; 00085 00086 /* TABLENG data structure used by function tableng to return the 00087 * length of the table. */ 00088 00089 typedef struct { 00090 OPDS h; 00091 MYFLT *kout; /* Output pointer */ 00092 MYFLT *xfn; /* Points to the number of the table. */ 00093 } TABLENG; 00094 00095 /* TABLEGPW data structure used by function tablegpw to write the 00096 * guard point of a specified table. (No output arguments) */ 00097 00098 typedef struct { 00099 OPDS h; 00100 MYFLT *xfn; /* Points to number of table. */ 00101 } TABLEGPW; 00102 00103 /* TABLEMIX data structure used by function tablemix. */ 00104 00105 typedef struct { 00106 OPDS h; 00107 MYFLT *dft, *doff, *len, *s1ft, *s1off, *s1g, *s2ft, *s2off, *s2g; 00108 00109 /* Storage to remember what the table numbers were from a previous k 00110 cycle, and to store pointers to their FUNC data structures. */ 00111 int pdft; /* Previous destination */ 00112 int ps1ft, ps2ft; /* source function table numbers. */ 00113 FUNC *funcd, *funcs1, *funcs2; 00114 } TABLEMIX; 00115 00116 /* TABLECOPY data structure used by function tablecopy. */ 00117 00118 typedef struct { 00119 OPDS h; 00120 MYFLT *dft; /* Destination function table number. */ 00121 MYFLT *sft; /* Source function table number */ 00122 00123 /* Storage to remember what the table numbers were from a previous k 00124 cycle, and to store pointers to their FUNC data structures. */ 00125 int pdft; /* Previous destination */ 00126 int psft; /* source function table numbers. */ 00127 FUNC *funcd, *funcs; 00128 } TABLECOPY; 00129 00130 /* TABLERA data structure used by tablera subroutine. */ 00131 00132 typedef struct { 00133 OPDS h; 00134 MYFLT *adest; /* A rate destination */ 00135 MYFLT *kfn; /* Number of table read */ 00136 MYFLT *kstart; /* Index mode within table */ 00137 MYFLT *koff; /* Offset to add to table index */ 00138 00139 /* Internal variable for previous state of xfn. */ 00140 long pfn; /* Pointer to function table data structure */ 00141 FUNC *ftp; 00142 } TABLERA; 00143 00144 /* TABLEWA data structure used by tablewa subroutine. */ 00145 00146 typedef struct { 00147 OPDS h; 00148 MYFLT *kstart; /* Index mode within table we start reading. 00149 * Note this is also an input argument. First 00150 * we read it to determine where we should start 00151 * writing the a rate samples. When we have 00152 * finished we write to it the number of the 00153 * next location which should be written. */ 00154 MYFLT *kfn; /* Number of table we are reading from. */ 00155 MYFLT *asig; /* a rate input signal. */ 00156 MYFLT *koff; /* Offset to add to table index. */ 00157 00158 long pfn; /* Pointer to function table. */ 00159 FUNC *ftp; 00160 } TABLEWA; 00161 00162 /*****************************************************************************/ 00163 00164 /* Data structures for the zak family of ugens for patching data at i, 00165 * k or a rates. 00166 * See also four global variables declared in the C code. */ 00167 00168 /* ZAKINIT data structure for zakinit(). */ 00169 typedef struct { 00170 OPDS h; 00171 MYFLT *isizea; /* Number of a locations, each an array of 00172 * ksmps long, to to reserve for a rate 00173 * patching */ 00174 MYFLT *isizek; /* Number of locations for i or k rate 00175 * variables */ 00176 } ZAKINIT; 00177 00178 /* ZKR data structure for zir() and zkr(). */ 00179 typedef struct { 00180 OPDS h; 00181 MYFLT *rslt; /* Where to write the value read from zk */ 00182 MYFLT *ndx; /* Location in zk space to read */ 00183 } ZKR; 00184 00185 /* ZKW data structure for ziw() and zkw(). */ 00186 typedef struct { 00187 OPDS h; 00188 MYFLT *sig; /* Value to write */ 00189 MYFLT *ndx; /* Locations to read */ 00190 } ZKW; 00191 00192 /* ZKWM data structure for ziwm() and zkwm(). */ 00193 typedef struct { 00194 OPDS h; 00195 MYFLT *sig; /* Value to write */ 00196 MYFLT *ndx; /* Locations to read */ 00197 MYFLT *mix; /* 0 for write directly; !0 for mix - add in */ 00198 00199 } ZKWM; 00200 00201 /* ZKMOD data structure for zkmod(). */ 00202 typedef struct { 00203 OPDS h; 00204 MYFLT *rslt; /* Points to where to write output */ 00205 MYFLT *sig; /* Value to modulate */ 00206 MYFLT *zkmod; /* Which zk variable to use to modulate sig */ 00207 00208 } ZKMOD; 00209 00210 /* ZKCL data structure for zkcl(). */ 00211 typedef struct { 00212 OPDS h; 00213 MYFLT *first; /* First variable to clear */ 00214 MYFLT *last; /* Final variable to clear */ 00215 00216 } ZKCL; 00217 00218 /* ZAR data structure for zar(). */ 00219 typedef struct { 00220 OPDS h; 00221 MYFLT *rslt; /* Where to write the value */ 00222 MYFLT *ndx; /* Location in za space to read */ 00223 00224 } ZAR; 00225 00226 /* ZARG data structure for zarg(). */ 00227 typedef struct { 00228 OPDS h; 00229 MYFLT *rslt; /* Where to write the zk location */ 00230 MYFLT *ndx; /* Location in za space to read */ 00231 MYFLT *kgain; /* Gain to be given to signal read */ 00232 } ZARG; 00233 00234 /* ZAW data structure for zaw(). */ 00235 typedef struct { 00236 OPDS h; 00237 MYFLT *sig, *ndx; 00238 } ZAW; 00239 00240 /* ZAWM data structure for zawm(). */ 00241 typedef struct { 00242 OPDS h; 00243 MYFLT *sig; 00244 MYFLT *ndx, *mix; /* Locations to read; 0 for write directly, or addd in */ 00245 } ZAWM; 00246 00247 /* ZAWOD data structure for zamod(). */ 00248 typedef struct { 00249 OPDS h; 00250 MYFLT *rslt; 00251 MYFLT *sig, *zamod; /* Value to modulate; Which za variable to use */ 00252 } ZAMOD; 00253 00254 /* ZACL data structure for zacl(). */ 00255 typedef struct { 00256 OPDS h; 00257 MYFLT *first, *last; 00258 } ZACL; 00259 00260 /*****************************************************************************/ 00261 00262 /* RDTIME data structure for timek(), times(), instimset(), instimek() 00263 and instimes(). */ 00264 00265 typedef struct { 00266 OPDS h; 00267 MYFLT *rslt; 00268 long instartk; 00269 } RDTIME; 00270 00271 /*****************************************************************************/ 00272 00273 /* PRINTK data structure for printk() and printkset(). */ 00274 typedef struct { 00275 OPDS h; 00276 MYFLT *ptime; /* How much time to leave between each print*/ 00277 MYFLT *val; /* Value to print */ 00278 MYFLT *space; /* Spaces to insert before printing */ 00279 MYFLT initime, ctime; /* Time when initialised; initialised */ 00280 long pspace; /* How many spaces to print */ 00281 long cysofar; /* Number of print cycles so far */ 00282 } PRINTK; 00283 00284 /* PRINTKS data structure for printks() and printksset() */ 00285 typedef struct { 00286 OPDS h; 00287 MYFLT *ifilcod; /* File name */ 00288 MYFLT *ptime; /* How much time to leave between each print */ 00289 MYFLT *kvals[VARGMAX];/* values to print */ 00290 MYFLT initime, ctime; /* Time when initialised; Cycle time */ 00291 long cysofar; /* Number of print cycles so far from 0 */ 00292 char txtstring[8192]; /* Place to store the string printed */ 00293 } PRINTKS; 00294 00295 /* an i-rate-only prints */ 00296 typedef struct { 00297 OPDS h; 00298 MYFLT *ifilcod; /* File name */ 00299 MYFLT *kvals[VARGMAX];/* values to print */ 00300 } PRINTS; 00301 /*****************************************************************************/ 00302 00303 /* PEAK data structure for peakk() and peaka(). */ 00304 typedef struct { 00305 OPDS h; 00306 MYFLT *kpeakout; /* Pointer to k or a rate input variable. */ 00307 MYFLT *xsigin; /* Pointer to k rate input variable which, 00308 * if set to no zero, causes the ugen to 00309 * clear the accumulator. */ 00310 } PEAK; 00311 00312 typedef struct { 00313 OPDS h; 00314 MYFLT *val, *space; 00315 MYFLT oldvalue; 00316 int pspace; 00317 } PRINTK2; 00318 00319 typedef struct { 00320 OPDS h; 00321 MYFLT *ndx; 00322 } IOZ; 00323 00324 int instimek(CSOUND*,RDTIME *p); 00325 int instimes(CSOUND*,RDTIME *p); 00326 int instimset(CSOUND*,RDTIME *p); 00327 int inz(CSOUND*,IOZ *p); 00328 int itablecopy(CSOUND*,TABLECOPY *p); 00329 int itablegpw(CSOUND*,TABLEGPW *p); 00330 int itablemix(CSOUND*,TABLEMIX *p); 00331 int itableng(CSOUND*,TABLENG *p); 00332 int itablew(CSOUND*,TABLEW *p); 00333 int ktablew(CSOUND*,TABLEW *p); 00334 int ktablewkt(CSOUND*,TABLEW *p); 00335 int outz(CSOUND*,IOZ *p); 00336 int peaka(CSOUND*,PEAK *p); 00337 int peakk(CSOUND*,PEAK *p); 00338 int printk(CSOUND*,PRINTK *p); 00339 int printk2(CSOUND*,PRINTK2 *p); 00340 int printk2set(CSOUND*,PRINTK2 *p); 00341 int printks(CSOUND*,PRINTKS *p); 00342 int printkset(CSOUND*,PRINTK *p); 00343 int printksset(CSOUND*,PRINTKS *p); 00344 int printsset(CSOUND*,PRINTS *p); 00345 int tablecopy(CSOUND*,TABLECOPY *p); 00346 int tablecopyset(CSOUND*,TABLECOPY *p); 00347 int tablegpw(CSOUND*,TABLEGPW *p); 00348 int tablemix(CSOUND*,TABLEMIX *p); 00349 int tablemixset(CSOUND*,TABLEMIX *p); 00350 int tableng(CSOUND*,TABLENG *p); 00351 int tablera(CSOUND*,TABLERA *p); 00352 int tableraset(CSOUND*,TABLERA *p); 00353 int tablew(CSOUND*,TABLEW *p); 00354 int tablewa(CSOUND*,TABLEWA *p); 00355 int tablewaset(CSOUND*,TABLEWA *p); 00356 int tablewkt(CSOUND*,TABLEW *p); 00357 int tblsetw(CSOUND*,TABLEW *p); 00358 int tblsetwkt(CSOUND*,TABLEW *p); 00359 int timek(CSOUND*,RDTIME *p); 00360 int timesr(CSOUND*,RDTIME *p); 00361 int zacl(CSOUND*,ZACL *p); 00362 int zakinit(CSOUND*,ZAKINIT *p); 00363 int zamod(CSOUND*,ZAMOD *p); 00364 int zar(CSOUND*,ZAR *p); 00365 int zarg(CSOUND*,ZARG *p); 00366 int zaset(CSOUND*,ZAR *p); 00367 int zaw(CSOUND*,ZAW *p); 00368 int zawm(CSOUND*,ZAWM *p); 00369 int zir(CSOUND*,ZKR *p); 00370 int ziw(CSOUND*,ZKW *p); 00371 int ziwm(CSOUND*,ZKWM *p); 00372 int zkcl(CSOUND*,ZKCL *p); 00373 int zkmod(CSOUND*,ZKMOD *p); 00374 int zkr(CSOUND*,ZKR *p); 00375 int zkset(CSOUND*,ZKR *p); 00376 int zkw(CSOUND*,ZKW *p); 00377 int zkwm(CSOUND*,ZKWM *p); 00378 void sprints(char *outstring, char *fmt, MYFLT **kvals, long numVals); 00379