class library: SynthDef - lazy implementation of removeUGen
[supercollider.git] / include / lang / PyrSignal.h
blobef2425657dbacfa1f307f51ad00676de3a52c6a0
1 /*
2 SuperCollider real time audio synthesis system
3 Copyright (c) 2002 James McCartney. All rights reserved.
4 http://www.audiosynth.com
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #pragma once // the value on here causes MSVC8 not to compile, is it needed elsewhere?
23 #include "PyrObject.h"
24 #include "GC.h"
26 #define UNROLL 1
28 enum {
29 kSignalRate = 0, // index of rate slot
30 kSignalNextNode
33 #define FSINESIZE 8192.
34 #define SINESIZE 8192
35 #define SINEMASK 8191
36 #define VERY_BIG_FLOAT (1.e10)
37 extern float *sineCycle;
38 extern float *invSineCycle;
39 extern float *pmSineCycle;
40 extern double phaseToSineIndex;
41 extern double sineIndexToPhase;
43 //#define FRACTABLESIZE 4096
44 //#define FRACMASK 0x3FFC
45 //extern float *gFracTable;
48 PyrObject* newPyrSignal(VMGlobals *g, long size);
50 #define UNROLL8_CODE(size,var,stmt) \
51 { int tempi, tempend; \
52 tempend = size>>3; \
53 for (tempi=0; tempi<tempend; ++tempi) { \
54 stmt;stmt;stmt;stmt; \
55 stmt;stmt;stmt;stmt; \
56 } \
57 tempend = size&7; \
58 for (tempi=0; tempi<tempend; ++tempi) { \
59 stmt; \
60 } \
63 #define UNROLL4_CODE(size,var,stmt) \
64 { int tempi, tempend; \
65 tempend = size>>2; \
66 for (tempi=0; tempi<tempend; ++tempi) { \
67 stmt;stmt;stmt;stmt; \
68 } \
69 tempend = size&3; \
70 for (tempi=0; tempi<tempend; ++tempi) { \
71 stmt; \
72 } \
75 #define FILTER_LOOP(size,var,stmt,stmt2) \
76 { int tempi, tempend; \
77 tempend = size>>2; \
78 for (tempi=0; tempi<tempend; ++tempi) { \
79 stmt;stmt;stmt;stmt; \
80 stmt2; \
81 } \
82 tempend = size&3; \
83 for (tempi=0; tempi<tempend; ++tempi) { \
84 stmt; \
85 } \
88 #define UNROLL1_CODE(size,var,stmt) \
89 { int tempi, tempend; \
90 tempend = size; \
91 for (tempi=0; tempi<tempend; ++tempi) { \
92 stmt; \
93 } \
97 #if UNROLL == 8
98 #define UNROLL_CODE UNROLL8_CODE
99 #elif UNROLL == 4
100 #define UNROLL_CODE UNROLL4_CODE
101 #else
102 #define UNROLL_CODE UNROLL1_CODE
103 #endif
105 #if 0
107 #define BINOP_LOOP1(OP)
108 #define BINOP_LOOP2(STMT1, STMT2, STMT3)
110 #else
112 #define BINOP_LOOP1(OP) \
113 float *a, *b, *c, *endptr; \
114 PyrObject *outc; \
115 long size; \
116 a = (float*)(ina->slots) - 1; \
117 b = (float*)(inb->slots) - 1; \
118 size = sc_min(ina->size, inb->size); \
119 outc = newPyrSignal(g, size); \
120 c = (float*)(outc->slots) - 1; \
121 endptr = c + size; \
122 switch (size & 3) { \
123 while (c < endptr) { \
124 *++c = *++a OP *++b; \
125 case 3 : *++c = *++a OP *++b; \
126 case 2 : *++c = *++a OP *++b; \
127 case 1 : *++c = *++a OP *++b; \
128 case 0 : ; \
131 return outc; \
134 #define BINOP_LOOP2(STMT1) \
135 float *a, *b, *c, *endptr; \
136 PyrObject *outc; \
137 long size; \
138 a = (float*)(ina->slots) - 1; \
139 b = (float*)(inb->slots) - 1; \
140 size = sc_min(ina->size, inb->size); \
141 outc = newPyrSignal(g, size); \
142 c = (float*)(outc->slots) - 1; \
143 endptr = c + size; \
144 switch (size & 3) { \
145 while (c < endptr) { \
146 STMT1; \
147 case 3 :STMT1; \
148 case 2 :STMT1; \
149 case 1 :STMT1; \
150 case 0 : ; \
153 return outc; \
155 #endif
158 compound formulas :
159 amclip out = B<=0 ? 0 : A*B; // two quadrant amplitude modulation
160 ring1 out = A*(B+1) = A*B + A; // amplitude modulation of a by b.
161 ring2 out = A*B + A + B; // ring modulation plus both original signals
162 ring3 out = A*A*B; // ring modulation variant
163 ring4 out = A*A*B - A*B*B; // ring modulation variant
164 difsqr out = A*A - B*B; // difference of squares
165 sumsqr out = A*A + B*B; // sum of squares
166 sqrdif out = (A - B)^2 // square of the difference = a^2 + b^2 - 2ab
167 sqrsum out = (A + B)^2 // square of the sum = a^2 + b^2 + 2ab
170 void signal_init_globs();
171 PyrObject* signal_fill(PyrObject *outSignal, float inValue);
172 PyrObject* signal_scale(PyrObject *outSignal, float inValue);
173 PyrObject* signal_offset(PyrObject *outSignal, float inValue);
174 PyrObject* signal_scale_offset(PyrObject *outSignal, float mul, float add);
175 PyrObject* signal_mix(PyrObject* ina, PyrObject* inb, float start, float end, float slopeFactor);
176 PyrObject* signal_add_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb);
177 PyrObject* signal_sub_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb);
178 PyrObject* signal_mul_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb);
179 PyrObject* signal_mul_ds_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb);
180 PyrObject* signal_add_ds_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb);
181 PyrObject* signal_sub_ds_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb);
182 PyrObject* signal_ring1_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb);
183 PyrObject* signal_ring2_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb);
184 PyrObject* signal_ring3_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb);
185 PyrObject* signal_ring4_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb);
186 PyrObject* signal_thresh_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb);
187 PyrObject* signal_amclip_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb);
188 PyrObject* signal_div_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb);
189 PyrObject* signal_difsqr_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb);
190 PyrObject* signal_sumsqr_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb);
191 PyrObject* signal_sqrsum_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb);
192 PyrObject* signal_sqrdif_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb);
193 PyrObject* signal_add_xf(VMGlobals *g, PyrObject* ina, float inb);
194 PyrObject* signal_sub_xf(VMGlobals *g, PyrObject* ina, float inb);
195 PyrObject* signal_mul_xf(VMGlobals *g, PyrObject* ina, float inb);
196 PyrObject* signal_ring1_xf(VMGlobals *g, PyrObject* ina, float inb);
197 PyrObject* signal_ring2_xf(VMGlobals *g, PyrObject* ina, float inb);
198 PyrObject* signal_ring3_xf(VMGlobals *g, PyrObject* ina, float inb);
199 PyrObject* signal_ring4_xf(VMGlobals *g, PyrObject* ina, float inb);
200 PyrObject* signal_thresh_xf(VMGlobals *g, PyrObject* ina, float inb);
201 PyrObject* signal_amclip_xf(VMGlobals *g, PyrObject* ina, float inb);
202 PyrObject* signal_div_xf(VMGlobals *g, PyrObject* ina, float inb);
203 PyrObject* signal_difsqr_xf(VMGlobals *g, PyrObject* ina, float inb);
204 PyrObject* signal_sumsqr_xf(VMGlobals *g, PyrObject* ina, float inb);
205 PyrObject* signal_sqrsum_xf(VMGlobals *g, PyrObject* ina, float inb);
206 PyrObject* signal_sqrdif_xf(VMGlobals *g, PyrObject* ina, float inb);
207 PyrObject* signal_ring1_fx(VMGlobals *g, float ina, PyrObject* inb);
208 PyrObject* signal_ring2_fx(VMGlobals *g, float ina, PyrObject* inb);
209 PyrObject* signal_ring3_fx(VMGlobals *g, float ina, PyrObject* inb);
210 PyrObject* signal_ring4_fx(VMGlobals *g, float ina, PyrObject* inb);
211 PyrObject* signal_thresh_fx(VMGlobals *g, float ina, PyrObject* inb);
212 PyrObject* signal_amclip_fx(VMGlobals *g, float ina, PyrObject* inb);
213 PyrObject* signal_sub_fx(VMGlobals *g, float ina, PyrObject* inb);
214 PyrObject* signal_div_fx(VMGlobals *g, float ina, PyrObject* inb);
215 PyrObject* signal_difsqr_fx(VMGlobals *g, float ina, PyrObject* inb);
216 PyrObject* signal_sumsqr_fx(VMGlobals *g, float ina, PyrObject* inb);
217 PyrObject* signal_sqrsum_fx(VMGlobals *g, float ina, PyrObject* inb);
218 PyrObject* signal_sqrdif_fx(VMGlobals *g, float ina, PyrObject* inb);
219 PyrObject* signal_min_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb);
220 PyrObject* signal_max_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb);
221 PyrObject* signal_min_xf(VMGlobals *g, PyrObject* ina, float inb);
222 PyrObject* signal_max_xf(VMGlobals *g, PyrObject* ina, float inb);
223 PyrObject* signal_invert(VMGlobals *g, PyrObject *inPyrSignal);
224 PyrObject* signal_recip(VMGlobals *g, PyrObject *inPyrSignal);
225 PyrObject* signal_squared(VMGlobals *g, PyrObject *inPyrSignal);
226 PyrObject* signal_cubed(VMGlobals *g, PyrObject *inPyrSignal);
227 PyrObject* signal_abs(VMGlobals *g, PyrObject *inPyrSignal);
228 PyrObject* signal_sign(VMGlobals *g, PyrObject *inPyrSignal);
229 PyrObject* signal_negative(VMGlobals *g, PyrObject *inPyrSignal);
230 PyrObject* signal_positive(VMGlobals *g, PyrObject *inPyrSignal);
231 PyrObject* signal_strictly_positive(VMGlobals *g, PyrObject *inPyrSignal);
232 PyrObject* signal_nyqring(VMGlobals *g, PyrObject *inPyrSignal);
233 PyrObject* signal_clip_f(VMGlobals *g, PyrObject *inPyrSignal, float lo, float hi);
234 PyrObject* signal_clip_f_ds(PyrObject *inPyrSignal, float lo, float hi);
235 PyrObject* signal_clip_x(VMGlobals *g, PyrObject *ina, PyrObject *inb, PyrObject *inc);
236 PyrObject* signal_wrap_f(VMGlobals *g, PyrObject *inPyrSignal, float lo, float hi);
237 PyrObject* signal_wrap_x(VMGlobals *g, PyrObject *ina, PyrObject *inb, PyrObject *inc);
238 PyrObject* signal_fold_f(VMGlobals *g, PyrObject *inPyrSignal, float lo, float hi);
239 PyrObject* signal_fold_x(VMGlobals *g, PyrObject *ina, PyrObject *inb, PyrObject *inc);
240 PyrObject* signal_log(VMGlobals *g, PyrObject *inPyrSignal);
241 PyrObject* signal_log2(VMGlobals *g, PyrObject *inPyrSignal);
242 PyrObject* signal_log10(VMGlobals *g, PyrObject *inPyrSignal);
243 PyrObject* signal_sin(VMGlobals *g, PyrObject *inPyrSignal);
244 PyrObject* signal_cos(VMGlobals *g, PyrObject *inPyrSignal);
245 PyrObject* signal_tan(VMGlobals *g, PyrObject *inPyrSignal);
246 PyrObject* signal_sinh(VMGlobals *g, PyrObject *inPyrSignal);
247 PyrObject* signal_cosh(VMGlobals *g, PyrObject *inPyrSignal);
248 PyrObject* signal_tanh(VMGlobals *g, PyrObject *inPyrSignal);
249 PyrObject* signal_asin(VMGlobals *g, PyrObject *inPyrSignal);
250 PyrObject* signal_acos(VMGlobals *g, PyrObject *inPyrSignal);
251 PyrObject* signal_atan(VMGlobals *g, PyrObject *inPyrSignal);
252 PyrObject* signal_exp(VMGlobals *g, PyrObject *inPyrSignal);
253 PyrObject* signal_sqrt(VMGlobals *g, PyrObject *inPyrSignal);
254 PyrObject* signal_distort(VMGlobals *g, PyrObject *inPyrSignal);
255 PyrObject* signal_distortneg(VMGlobals *g, PyrObject *inPyrSignal);
256 PyrObject* signal_softclip(VMGlobals *g, PyrObject *inPyrSignal);
257 PyrObject* signal_softclipneg(VMGlobals *g, PyrObject *inPyrSignal);
258 PyrObject* signal_fsin(VMGlobals *g, PyrObject *inPyrSignal);
259 PyrObject* signal_poly3(VMGlobals *g, PyrObject *inPyrSignal, float a, float b, float c);
260 PyrObject* signal_poly3r(VMGlobals *g, PyrObject *inPyrSignal,
261 float a1, float a2, float b1, float b2, float c1, float c2, float slopeFactor);
262 PyrObject* signal_integrate(VMGlobals *g, PyrObject *inPyrSignal, float *ioSum);
263 PyrObject* signal_leakdc(VMGlobals *g, PyrObject *inPyrSignal, float *ioDC, float leakFactor);
264 PyrObject* signal_ampflw1(VMGlobals *g, PyrObject *inPyrSignal, float *ioAmp, float leak1);
265 PyrObject* signal_ampflw2(VMGlobals *g, PyrObject *inPyrSignal, float *ioAmp, float leak1);
266 PyrObject* signal_differentiate(VMGlobals *g, PyrObject *inPyrSignal, float *ioPrev);
267 PyrObject* signal_rotate(VMGlobals *g, PyrObject* ina, int rot);
268 PyrObject* signal_reverse_ds(PyrObject* ina);
269 PyrObject* signal_cat(VMGlobals *g, PyrObject* ina, PyrObject* inb);
270 PyrObject* signal_insert(VMGlobals *g, PyrObject* ina, PyrObject* inb, long index);
271 PyrObject* signal_overdub(VMGlobals *g, PyrObject* ina, PyrObject* inb, long index);
272 PyrObject* signal_overwrite(VMGlobals *g, PyrObject* ina, PyrObject* inb, long index);
273 PyrObject* signal_cat3(VMGlobals *g, PyrObject* ina, PyrObject* inb, PyrObject* inc);
274 PyrObject* signal_linen(VMGlobals *g, PyrObject* ina, long atk, long dcy, float amp);
275 PyrObject* signal_linen2(VMGlobals *g, PyrObject* ina, long atk, long dcy, float amp, float midamp);
276 PyrObject* signal_writesplice(VMGlobals *g, PyrObject* outc, PyrObject* ina, PyrObject* inb,
277 long indexc, long indexa, long indexb, long fadelen, float midamp);
278 PyrObject* signal_splice(VMGlobals *g, PyrObject* ina, PyrObject* inb,
279 long indexa, long indexb, long fadelen, float midamp);
281 PyrObject* signal_invert_ds(PyrObject *inPyrSignal);
282 PyrObject* signal_recip_ds(PyrObject *inPyrSignal);
283 PyrObject* signal_squared_ds(PyrObject *inPyrSignal);
284 PyrObject* signal_cubed_ds(PyrObject *inPyrSignal);
285 PyrObject* signal_abs_ds(PyrObject *inPyrSignal);
286 PyrObject* signal_sign_ds(PyrObject *inPyrSignal);
287 PyrObject* signal_negative_ds(PyrObject *inPyrSignal);
288 PyrObject* signal_positive_ds(PyrObject *inPyrSignal);
289 PyrObject* signal_strictly_positive_ds(PyrObject *inPyrSignal);
290 PyrObject* signal_nyqring_ds(PyrObject *inPyrSignal);
292 PyrObject* signal_clipneg_ds(PyrObject *inPyrSignal);
293 PyrObject* signal_distort_ds(PyrObject *inPyrSignal);
294 PyrObject* signal_distortneg_ds(PyrObject *inPyrSignal);
295 PyrObject* signal_softclip_ds(PyrObject *inPyrSignal);
296 PyrObject* signal_softclipneg_ds(PyrObject *inPyrSignal);
297 PyrObject* signal_fsin_ds(PyrObject *inPyrSignal);
299 PyrObject* signal_log_ds(PyrObject *inPyrSignal);
300 PyrObject* signal_log2_ds(PyrObject *inPyrSignal);
301 PyrObject* signal_log10_ds(PyrObject *inPyrSignal);
302 PyrObject* signal_sin_ds(PyrObject *inPyrSignal);
303 PyrObject* signal_cos_ds(PyrObject *inPyrSignal);
304 PyrObject* signal_tan_ds(PyrObject *inPyrSignal);
305 PyrObject* signal_sinh_ds(PyrObject *inPyrSignal);
306 PyrObject* signal_cosh_ds(PyrObject *inPyrSignal);
307 PyrObject* signal_tanh_ds(PyrObject *inPyrSignal);
308 PyrObject* signal_asin_ds(PyrObject *inPyrSignal);
309 PyrObject* signal_acos_ds(PyrObject *inPyrSignal);
310 PyrObject* signal_atan_ds(PyrObject *inPyrSignal);
311 PyrObject* signal_exp_ds(PyrObject *inPyrSignal);
312 PyrObject* signal_sqrt_ds(PyrObject *inPyrSignal);
314 float signal_findpeak(PyrObject *inPyrSignal);
315 PyrObject* signal_normalize(PyrObject *inPyrSignal);
316 PyrObject* signal_normalize_transfer_fn(PyrObject *inPyrSignal);
317 float signal_integral(PyrObject *inPyrSignal);
318 PyrObject* signal_combself(VMGlobals *g, PyrObject* ina, long rot);
319 PyrObject* signal_bilinen(VMGlobals *g, PyrObject* ina, long atk, long dcy, float amp, float midamp);
320 PyrObject* signal_lace2(VMGlobals *g, PyrObject* ina, PyrObject* inb);
321 void signal_unlace2(VMGlobals *g, PyrObject* ina, PyrObject** outb, PyrObject** outc);
322 void signal_convolve(VMGlobals *g, PyrObject* ina, PyrObject* ir, PyrObject* previn, long *ppos);
323 PyrObject* signal_thumbnail(VMGlobals *g, PyrObject* ina, long startpos, long length, int binsize);
325 PyrObject* signal_scaleneg_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb);
326 PyrObject* signal_scaleneg_xf(VMGlobals *g, PyrObject* ina, float inb);
327 PyrObject* signal_scaleneg_fx(VMGlobals *g, float ina, PyrObject* inb);
329 PyrObject* signal_clip2_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb);
330 PyrObject* signal_clip2_xf(VMGlobals *g, PyrObject* ina, float inb);
331 PyrObject* signal_clip2_fx(VMGlobals *g, float ina, PyrObject* inb);
333 PyrObject* signal_fold2_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb);
334 PyrObject* signal_fold2_xf(VMGlobals *g, PyrObject* ina, float inb);
335 PyrObject* signal_fold2_fx(VMGlobals *g, float ina, PyrObject* inb);
337 PyrObject* signal_wrap2_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb);
338 PyrObject* signal_wrap2_xf(VMGlobals *g, PyrObject* ina, float inb);
339 PyrObject* signal_wrap2_fx(VMGlobals *g, float ina, PyrObject* inb);
341 PyrObject* signal_excess_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb);
342 PyrObject* signal_excess_xf(VMGlobals *g, PyrObject* ina, float inb);
343 PyrObject* signal_excess_fx(VMGlobals *g, float ina, PyrObject* inb);
345 PyrObject* signal_absdif_fx(VMGlobals *g, float ina, PyrObject* inb);
346 PyrObject* signal_absdif_xf(VMGlobals *g, PyrObject* ina, float inb);
347 PyrObject* signal_absdif_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb);
349 bool signal_equal_xf(VMGlobals *g, PyrObject* ina, float inb);
350 bool signal_equal_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb);
352 void signal_get_bounds(PyrObject* ina, float *ominval, float *omaxval);
354 void signal_smooth_ds(PyrObject* inPyrSignal);
355 void signal_hanning_ds(PyrObject* inPyrSignal);
356 void signal_welch_ds(PyrObject* inPyrSignal);
357 void signal_parzen_ds(PyrObject* inPyrSignal);
359 PyrObject* signal_normalize_range(PyrObject* ina, long start, long end);
360 PyrObject* signal_zero_range(PyrObject* ina, long start, long end);
361 PyrObject* signal_invert_range(PyrObject* ina, long start, long end);
362 PyrObject* signal_reverse_range(PyrObject* ina, long start, long end);
363 PyrObject* signal_fade_in(PyrObject* ina, long start, long end);
364 PyrObject* signal_fade_out(PyrObject* ina, long start, long end);
365 PyrObject* signal_abs_range(PyrObject* ina, long start, long end);
366 PyrObject* signal_squared_range(PyrObject* ina, long start, long end);
367 PyrObject* signal_cubed_range(PyrObject* ina, long start, long end);
368 PyrObject* signal_distort_range(PyrObject* ina, long start, long end);
370 PyrObject* signal_fade_range(PyrObject* ina, long start, long end, float lvl0, float lvl1);