*** empty log message ***
[chuck-blob.git] / v2 / ugen_filter.cpp
blob410f8838eeb15a57622512924d18802c75bc7618
1 /*----------------------------------------------------------------------------
2 ChucK Concurrent, On-the-fly Audio Programming Language
3 Compiler and Virtual Machine
5 Copyright (c) 2004 Ge Wang and Perry R. Cook. All rights reserved.
6 http://chuck.cs.princeton.edu/
7 http://soundlab.cs.princeton.edu/
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 U.S.A.
23 -----------------------------------------------------------------------------*/
25 //-----------------------------------------------------------------------------
26 // file: ugen_filter.cpp
27 // desc: ...
29 // author: Ge Wang (gewang@cs.princeton.edu)
30 // Perry R. Cook (prc@cs.princeton.edu)
31 // date: Spring 2004
32 //-----------------------------------------------------------------------------
33 #include "ugen_filter.h"
34 #include "chuck_type.h"
35 #include <math.h>
36 #include <stdlib.h>
39 static t_CKUINT g_srate = 0;
40 static t_CKFLOAT g_radians_per_sample = 0;
41 // filter member data offset
42 static t_CKUINT FilterBasic_offset_data = 0;
43 static t_CKUINT Teabox_offset_data = 0;
44 static t_CKUINT biquad_offset_data = 0;
47 //-----------------------------------------------------------------------------
48 // name: filter_query()
49 // desc: ...
50 //-----------------------------------------------------------------------------
51 DLL_QUERY filter_query( Chuck_DL_Query * QUERY )
53 // set srate
54 g_srate = QUERY->srate;
55 // set radians per sample
56 g_radians_per_sample = TWO_PI / (t_CKFLOAT)g_srate;
58 Chuck_Env * env = Chuck_Env::instance();
60 Chuck_DL_Func * func = NULL;
62 // deprecate
63 type_engine_register_deprecate( env, "filter", "Filter" );
64 type_engine_register_deprecate( env, "biquad", "BiQuad" );
65 type_engine_register_deprecate( env, "onepole", "OnePole" );
66 type_engine_register_deprecate( env, "onezero", "OneZero" );
67 type_engine_register_deprecate( env, "twopole", "TwoPole" );
68 type_engine_register_deprecate( env, "twozero", "TwoZero" );
69 type_engine_register_deprecate( env, "delay", "Delay" );
70 type_engine_register_deprecate( env, "delayl", "DelayL" );
71 type_engine_register_deprecate( env, "delaya", "DelayA" );
73 //---------------------------------------------------------------------
74 // init as base class: FilterBasic
75 //---------------------------------------------------------------------
76 if( !type_engine_import_ugen_begin( env, "FilterBasic", "UGen", env->global(),
77 FilterBasic_ctor, FilterBasic_dtor,
78 FilterBasic_tick, FilterBasic_pmsg ) )
79 return FALSE;
81 // member variable
82 FilterBasic_offset_data = type_engine_import_mvar( env, "int", "@FilterBasic_data", FALSE );
83 if( FilterBasic_offset_data == CK_INVALID_OFFSET ) goto error;
85 // freq
86 func = make_new_mfun( "float", "freq", FilterBasic_ctrl_freq );
87 func->add_arg( "float", "val" );
88 if( !type_engine_import_mfun( env, func ) ) goto error;
89 func = make_new_mfun( "float", "freq", FilterBasic_cget_freq );
90 if( !type_engine_import_mfun( env, func ) ) goto error;
92 // Q
93 func = make_new_mfun( "float", "Q", FilterBasic_ctrl_Q );
94 func->add_arg( "float", "val" );
95 if( !type_engine_import_mfun( env, func ) ) goto error;
96 func = make_new_mfun( "float", "Q", FilterBasic_cget_Q );
97 if( !type_engine_import_mfun( env, func ) ) goto error;
99 // set
100 func = make_new_mfun( "void", "set", FilterBasic_ctrl_set );
101 func->add_arg( "float", "freq" );
102 func->add_arg( "float", "Q" );
103 if( !type_engine_import_mfun( env, func ) ) goto error;
105 // end the class import
106 type_engine_import_class_end( env );
110 //---------------------------------------------------------------------
111 // init class: LPF
112 //---------------------------------------------------------------------
113 if( !type_engine_import_ugen_begin( env, "LPF", "FilterBasic", env->global(),
114 LPF_ctor, LPF_tick, LPF_pmsg ) )
115 return FALSE;
117 // freq
118 func = make_new_mfun( "float", "freq", LPF_ctrl_freq );
119 func->add_arg( "float", "val" );
120 if( !type_engine_import_mfun( env, func ) ) goto error;
121 func = make_new_mfun( "float", "freq", LPF_cget_freq );
122 if( !type_engine_import_mfun( env, func ) ) goto error;
124 // end the class import
125 type_engine_import_class_end( env );
128 //---------------------------------------------------------------------
129 // init class: HPF
130 //---------------------------------------------------------------------
131 if( !type_engine_import_ugen_begin( env, "HPF", "FilterBasic", env->global(),
132 HPF_ctor, HPF_tick, HPF_pmsg ) )
133 return FALSE;
135 // freq
136 func = make_new_mfun( "float", "freq", HPF_ctrl_freq );
137 func->add_arg( "float", "val" );
138 if( !type_engine_import_mfun( env, func ) ) goto error;
139 func = make_new_mfun( "float", "freq", HPF_cget_freq );
140 if( !type_engine_import_mfun( env, func ) ) goto error;
142 // end the class import
143 type_engine_import_class_end( env );
147 //---------------------------------------------------------------------
148 // init class: BPF
149 //---------------------------------------------------------------------
150 if( !type_engine_import_ugen_begin( env, "BPF", "FilterBasic", env->global(),
151 BPF_ctor, NULL, BPF_tick, BPF_pmsg ) )
152 return FALSE;
154 // freq
155 func = make_new_mfun( "float", "freq", BPF_ctrl_freq );
156 func->add_arg( "float", "val" );
157 if( !type_engine_import_mfun( env, func ) ) goto error;
158 func = make_new_mfun( "float", "freq", BPF_cget_freq );
159 if( !type_engine_import_mfun( env, func ) ) goto error;
161 // Q
162 func = make_new_mfun( "float", "Q", BPF_ctrl_Q );
163 func->add_arg( "float", "val" );
164 if( !type_engine_import_mfun( env, func ) ) goto error;
165 func = make_new_mfun( "float", "Q", BPF_cget_Q );
166 if( !type_engine_import_mfun( env, func ) ) goto error;
168 // set
169 func = make_new_mfun( "void", "set", BPF_ctrl_set );
170 func->add_arg( "float", "freq" );
171 func->add_arg( "float", "Q" );
172 if( !type_engine_import_mfun( env, func ) ) goto error;
174 // end the class import
175 type_engine_import_class_end( env );
178 //---------------------------------------------------------------------
179 // init class: BRF
180 //---------------------------------------------------------------------
181 if( !type_engine_import_ugen_begin( env, "BRF", "FilterBasic", env->global(),
182 BRF_ctor, NULL, BRF_tick, BRF_pmsg ) )
183 return FALSE;
185 // freq
186 func = make_new_mfun( "float", "freq", BRF_ctrl_freq );
187 func->add_arg( "float", "val" );
188 if( !type_engine_import_mfun( env, func ) ) goto error;
189 func = make_new_mfun( "float", "freq", BRF_cget_freq );
190 if( !type_engine_import_mfun( env, func ) ) goto error;
192 // Q
193 func = make_new_mfun( "float", "Q", BRF_ctrl_Q );
194 func->add_arg( "float", "val" );
195 if( !type_engine_import_mfun( env, func ) ) goto error;
196 func = make_new_mfun( "float", "Q", BRF_cget_Q );
197 if( !type_engine_import_mfun( env, func ) ) goto error;
199 // set
200 func = make_new_mfun( "void", "set", BRF_ctrl_set );
201 func->add_arg( "float", "freq" );
202 func->add_arg( "float", "Q" );
203 if( !type_engine_import_mfun( env, func ) ) goto error;
205 // end the class import
206 type_engine_import_class_end( env );
209 //---------------------------------------------------------------------
210 // init class: RLPF
211 //---------------------------------------------------------------------
212 if( !type_engine_import_ugen_begin( env, "LPF", "FilterBasic", env->global(),
213 RLPF_ctor, NULL, RLPF_tick, RLPF_pmsg ) )
214 return FALSE;
216 // freq
217 func = make_new_mfun( "float", "freq", RLPF_ctrl_freq );
218 func->add_arg( "float", "val" );
219 if( !type_engine_import_mfun( env, func ) ) goto error;
220 func = make_new_mfun( "float", "freq", RLPF_cget_freq );
221 if( !type_engine_import_mfun( env, func ) ) goto error;
223 // Q
224 func = make_new_mfun( "float", "Q", RLPF_ctrl_Q );
225 func->add_arg( "float", "val" );
226 if( !type_engine_import_mfun( env, func ) ) goto error;
227 func = make_new_mfun( "float", "Q", RLPF_cget_Q );
228 if( !type_engine_import_mfun( env, func ) ) goto error;
230 // set
231 func = make_new_mfun( "void", "set", RLPF_ctrl_set );
232 func->add_arg( "float", "freq" );
233 func->add_arg( "float", "Q" );
234 if( !type_engine_import_mfun( env, func ) ) goto error;
236 // end the class import
237 type_engine_import_class_end( env );
240 //---------------------------------------------------------------------
241 // init class: RHPF
242 //---------------------------------------------------------------------
243 if( !type_engine_import_ugen_begin( env, "HPF", "FilterBasic", env->global(),
244 RHPF_ctor, NULL, RHPF_tick, RHPF_pmsg ) )
245 return FALSE;
247 // freq
248 func = make_new_mfun( "float", "freq", RHPF_ctrl_freq );
249 func->add_arg( "float", "val" );
250 if( !type_engine_import_mfun( env, func ) ) goto error;
251 func = make_new_mfun( "float", "freq", RHPF_cget_freq );
252 if( !type_engine_import_mfun( env, func ) ) goto error;
254 // Q
255 func = make_new_mfun( "float", "Q", RHPF_ctrl_Q );
256 func->add_arg( "float", "val" );
257 if( !type_engine_import_mfun( env, func ) ) goto error;
258 func = make_new_mfun( "float", "Q", RHPF_cget_Q );
259 if( !type_engine_import_mfun( env, func ) ) goto error;
261 // set
262 func = make_new_mfun( "void", "set", RHPF_ctrl_set );
263 func->add_arg( "float", "freq" );
264 func->add_arg( "float", "Q" );
265 if( !type_engine_import_mfun( env, func ) ) goto error;
267 // end the class import
268 type_engine_import_class_end( env );
271 //---------------------------------------------------------------------
272 // init class: ResonZ
273 //---------------------------------------------------------------------
274 if( !type_engine_import_ugen_begin( env, "ResonZ", "FilterBasic", env->global(),
275 ResonZ_ctor, NULL, ResonZ_tick, ResonZ_pmsg ) )
276 return FALSE;
278 // freq
279 func = make_new_mfun( "float", "freq", ResonZ_ctrl_freq );
280 func->add_arg( "float", "val" );
281 if( !type_engine_import_mfun( env, func ) ) goto error;
282 func = make_new_mfun( "float", "freq", ResonZ_cget_freq );
283 if( !type_engine_import_mfun( env, func ) ) goto error;
285 // reson
286 func = make_new_mfun( "float", "Q", ResonZ_ctrl_Q );
287 func->add_arg( "float", "val" );
288 if( !type_engine_import_mfun( env, func ) ) goto error;
289 func = make_new_mfun( "float", "Q", ResonZ_cget_Q );
290 if( !type_engine_import_mfun( env, func ) ) goto error;
292 // set
293 func = make_new_mfun( "void", "set", ResonZ_ctrl_set );
294 func->add_arg( "float", "freq" );
295 func->add_arg( "float", "Q" );
296 if( !type_engine_import_mfun( env, func ) ) goto error;
298 // end the class import
299 type_engine_import_class_end( env );
302 //---------------------------------------------------------------------
303 // init as base class: BiQuad
304 //---------------------------------------------------------------------
305 if( !type_engine_import_ugen_begin( env, "BiQuad", "UGen", env->global(),
306 biquad_ctor, biquad_dtor, biquad_tick, NULL ) )
307 return FALSE;
309 // member variable
310 biquad_offset_data = type_engine_import_mvar ( env, "int", "@biquad_data", FALSE );
311 if ( biquad_offset_data == CK_INVALID_OFFSET ) goto error;
313 // pfreq
314 func = make_new_mfun ( "float", "pfreq", biquad_ctrl_pfreq );
315 func->add_arg ( "float", "freq" );
316 if( !type_engine_import_mfun( env, func ) ) goto error;
317 func = make_new_mfun ( "float", "pfreq", biquad_cget_pfreq );
318 if( !type_engine_import_mfun( env, func ) ) goto error;
320 // prad
321 func = make_new_mfun ( "float", "prad", biquad_ctrl_prad );
322 func->add_arg ( "float", "value" );
323 if( !type_engine_import_mfun( env, func ) ) goto error;
324 func = make_new_mfun ( "float", "prad", biquad_cget_prad );
325 if( !type_engine_import_mfun( env, func ) ) goto error;
327 // zfreq
328 func = make_new_mfun ( "float", "zfreq", biquad_ctrl_zfreq );
329 func->add_arg ( "float", "freq" );
330 if( !type_engine_import_mfun( env, func ) ) goto error;
331 func = make_new_mfun ( "float", "zfreq", biquad_cget_zfreq );
332 if( !type_engine_import_mfun( env, func ) ) goto error;
334 // zrad
335 func = make_new_mfun ( "float", "zrad", biquad_ctrl_zrad );
336 func->add_arg ( "float", "value" );
337 if( !type_engine_import_mfun( env, func ) ) goto error;
338 func = make_new_mfun ( "float", "zrad", biquad_cget_zrad );
339 if( !type_engine_import_mfun( env, func ) ) goto error;
341 // norm
342 func = make_new_mfun ( "int", "norm", biquad_ctrl_norm );
343 func->add_arg ( "int", "value" );
344 if( !type_engine_import_mfun( env, func ) ) goto error;
345 func = make_new_mfun ( "int", "norm", biquad_cget_norm );
346 if( !type_engine_import_mfun( env, func ) ) goto error;
348 // pregain
349 func = make_new_mfun ( "float", "pregain", biquad_ctrl_pregain );
350 func->add_arg ( "float", "level" );
351 if( !type_engine_import_mfun( env, func ) ) goto error;
352 func = make_new_mfun ( "float", "pregain", biquad_cget_pregain );
353 if( !type_engine_import_mfun( env, func ) ) goto error;
355 // eqzs
356 func = make_new_mfun ( "int", "eqzs", biquad_ctrl_eqzs );
357 func->add_arg ( "int", "value" );
358 if( !type_engine_import_mfun( env, func ) ) goto error;
360 // b0
361 func = make_new_mfun ( "float", "b0", biquad_ctrl_b0 );
362 func->add_arg ( "float", "value" );
363 if( !type_engine_import_mfun( env, func ) ) goto error;
364 func = make_new_mfun ( "float", "b0", biquad_cget_b0 );
365 if( !type_engine_import_mfun( env, func ) ) goto error;
367 // b1
368 func = make_new_mfun ( "float", "b1", biquad_ctrl_b1 );
369 func->add_arg ( "float", "value" );
370 if( !type_engine_import_mfun( env, func ) ) goto error;
371 func = make_new_mfun ( "float", "b1", biquad_cget_b1 );
372 if( !type_engine_import_mfun( env, func ) ) goto error;
374 // b2
375 func = make_new_mfun ( "float", "b2", biquad_ctrl_b2 );
376 func->add_arg ( "float", "value" );
377 if( !type_engine_import_mfun( env, func ) ) goto error;
378 func = make_new_mfun ( "float", "b2", biquad_cget_b2 );
379 if( !type_engine_import_mfun( env, func ) ) goto error;
381 // a0
382 func = make_new_mfun ( "float", "a0", biquad_ctrl_a0 );
383 func->add_arg ( "float", "value" );
384 if( !type_engine_import_mfun( env, func ) ) goto error;
385 func = make_new_mfun ( "float", "a0", biquad_cget_a0 );
386 if( !type_engine_import_mfun( env, func ) ) goto error;
388 // a1
389 func = make_new_mfun ( "float", "a1", biquad_ctrl_a1 );
390 func->add_arg ( "float", "value" );
391 if( !type_engine_import_mfun( env, func ) ) goto error;
392 func = make_new_mfun ( "float", "a1", biquad_cget_a1 );
393 if( !type_engine_import_mfun( env, func ) ) goto error;
395 // a2
396 func = make_new_mfun ( "float", "a2", biquad_ctrl_a2 );
397 func->add_arg ( "float", "value" );
398 if( !type_engine_import_mfun( env, func ) ) goto error;
399 func = make_new_mfun ( "float", "a2", biquad_cget_a2 );
400 if( !type_engine_import_mfun( env, func ) ) goto error;
402 // end the class import
403 type_engine_import_class_end( env );
405 //---------------------------------------------------------------------
406 // init class: Teabox
407 //---------------------------------------------------------------------
408 if( !type_engine_import_ugen_begin( env, "Teabox", "FilterBasic", env->global(),
409 teabox_ctor, NULL, teabox_tick, teabox_pmsg ) )
410 return FALSE;
412 // analog
413 func = make_new_mfun( "float", "analog", teabox_cget_analog );
414 func->add_arg( "int", "which" );
415 if( !type_engine_import_mfun( env, func ) ) goto error;
417 // digital
418 func = make_new_mfun( "float", "digital", teabox_cget_digital );
419 func->add_arg( "int", "which" );
420 if( !type_engine_import_mfun( env, func ) ) goto error;
422 // end the class import
423 type_engine_import_class_end( env );
426 //----------------------------------
427 // begin onepole ugen
428 //----------------------------------
429 if ( !type_engine_import_ugen_begin( env, "OnePole", "biquad", env->global(),
430 NULL, onepole_tick, NULL ) ) return FALSE;
431 // ctrl func
432 func = make_new_mfun ( "float", "pole", onepole_ctrl_pole );
433 func->add_arg ( "float", "value" );
434 if( !type_engine_import_mfun( env, func ) ) goto error;
436 // end the class import
437 type_engine_import_class_end( env );
440 //----------------------------------
441 // begin onezero ugen
442 //----------------------------------
443 if ( !type_engine_import_ugen_begin( env, "onezero", "biquad", env->global(),
444 NULL, onezero_tick, NULL ) ) return FALSE;
445 // ctrl func
446 func = make_new_mfun ( "float", "zero", onezero_ctrl_zero );
447 func->add_arg ( "float", "value" );
448 if( !type_engine_import_mfun( env, func ) ) goto error;
451 // end the class import
452 type_engine_import_class_end( env );
455 //----------------------------------
456 // begin twopole ugen
457 //----------------------------------
458 if ( !type_engine_import_ugen_begin( env, "twopole", "biquad", env->global(),
459 NULL, twopole_tick, NULL ) ) return FALSE;
460 // ctrl func
461 func = make_new_mfun ( "float", "freq", twopole_ctrl_freq );
462 func->add_arg ( "float", "value" );
463 if( !type_engine_import_mfun( env, func ) ) goto error;
465 func = make_new_mfun ( "float", "rad", twopole_ctrl_rad );
466 func->add_arg ( "float", "value" );
467 if( !type_engine_import_mfun( env, func ) ) goto error;
469 func = make_new_mfun ( "int", "norm", twopole_ctrl_norm );
470 func->add_arg ( "int", "value" );
471 if( !type_engine_import_mfun( env, func ) ) goto error;
473 // end the class import
474 type_engine_import_class_end( env );
477 //----------------------------------
478 // begin twozero ugen
479 //----------------------------------
480 if ( !type_engine_import_ugen_begin( env, "twozero", "biquad", env->global(),
481 NULL, twozero_tick, NULL ) ) return FALSE;
482 // ctrl func
483 func = make_new_mfun ( "float", "freq", twozero_ctrl_freq );
484 func->add_arg ( "float", "value" );
485 if( !type_engine_import_mfun( env, func ) ) goto error;
487 func = make_new_mfun ( "float", "rad", twozero_ctrl_rad );
488 func->add_arg ( "float", "value" );
489 if( !type_engine_import_mfun( env, func ) ) goto error;
491 // end the class import
492 type_engine_import_class_end( env );
495 //----------------------------------
496 // begin delay ugen
497 //----------------------------------
498 if ( !type_engine_import_ugen_begin( env, "delay", "UGen", env->global(),
499 delay_ctor, delay_tick, NULL ) ) return FALSE;
501 // ctrl func
502 func = make_new_mfun ( "float", "delay", delay_ctrl_delay );
503 func->add_arg ( "float", "value" );
504 if( !type_engine_import_mfun( env, func ) ) goto error;
506 func = make_new_mfun ( "float", "max", delay_ctrl_max );
507 func->add_arg ( "float", "value" );
508 if( !type_engine_import_mfun( env, func ) ) goto error;
511 // QUERY->ugen_ctrl( QUERY, delay_ctrl_energy, NULL,"int", "energy" );
512 // QUERY->ugen_ctrl( QUERY, delay_ctrl_tap, NULL, "int", "tap" );
513 // QUERY->ugen_ctrl( QUERY, delay_ctrl_ftap, NULL, "float", "ftap" );
515 // end the class import
516 type_engine_import_class_end( env );
519 //----------------------------------
520 // begin delayA ugen
521 //----------------------------------
522 if ( !type_engine_import_ugen_begin( env, "delayA", "UGen", env->global(),
523 delayA_ctor, delayA_tick, NULL ) ) return FALSE;
525 // ctrl func
526 func = make_new_mfun ( "float", "delay", delayA_ctrl_delay );
527 func->add_arg ( "float", "length" );
528 if( !type_engine_import_mfun( env, func ) ) goto error;
530 func = make_new_mfun ( "float", "max", delayA_ctrl_max );
531 func->add_arg ( "float", "max" );
532 if( !type_engine_import_mfun( env, func ) ) goto error;
535 // end the class import
536 type_engine_import_class_end( env );
539 //----------------------------------
540 // begin one ugen
541 //----------------------------------
542 if ( !type_engine_import_ugen_begin( env, "delayL", "UGen", env->global(),
543 delayL_ctor, delayL_tick, NULL ) ) return FALSE;
544 // ctrl func
545 func = make_new_mfun ( "float", "delay", delayL_ctrl_delay );
546 func->add_arg ( "float", "length" );
547 if( !type_engine_import_mfun( env, func ) ) goto error;
549 func = make_new_mfun ( "float", "max", delayL_ctrl_max );
550 func->add_arg ( "float", "max" );
551 if( !type_engine_import_mfun( env, func ) ) goto error;
553 // end the class import
554 type_engine_import_class_end( env );
557 return TRUE;
559 error:
561 // end the class import
562 type_engine_import_class_end( env );
564 return FALSE;
570 //-----------------------------------------------------------------------------
571 // name: Filter_data
572 // desc: ...
573 //-----------------------------------------------------------------------------
574 struct Filter_data
576 t_CKUINT nB;
577 t_CKUINT nA;
578 SAMPLE * b;
579 SAMPLE * a;
580 SAMPLE * input;
581 SAMPLE * output;
583 Filter_data()
585 a = b = NULL;
586 alloc( 1, 1 );
587 a[0] = b[0] = 1.0f;
590 void alloc( t_CKUINT _b, t_CKUINT _a )
592 nB = _b; nA = _a;
593 if( b ) delete b;
594 if( a ) delete a;
595 if( input ) delete input;
596 if( output ) delete output;
597 b = new SAMPLE[nB];
598 a = new SAMPLE[nA];
599 input = new SAMPLE[nB];
600 output = new SAMPLE[nA];
603 inline SAMPLE tick( SAMPLE in )
605 t_CKUINT i;
607 output[0] = 0.0;
608 input[0] = in;
609 for( i = nB-1; i > 0; i-- )
611 output[0] += b[i] * input[i];
612 input[i] = input[i-1];
614 output[0] += b[0] * input[0];
616 for ( i = nA-1; i>0; i--)
618 output[0] += -a[i] * output[i];
619 output[i] = output[i-1];
622 return output[0];
629 //-----------------------------------------------------------------------------
630 // name: FilterBasic_data
631 // desc: ...
632 //-----------------------------------------------------------------------------
633 struct FilterBasic_data
635 // much of this implementation is adapted or copied outright from SC3
636 SAMPLE m_y1;
637 SAMPLE m_y2;
638 SAMPLE m_a0;
639 SAMPLE m_b1;
640 SAMPLE m_b2;
641 t_CKFLOAT m_freq;
642 t_CKFLOAT m_Q;
643 t_CKFLOAT m_db;
645 // tick_lpf
646 inline SAMPLE tick_lpf( SAMPLE in )
648 SAMPLE y0, result;
650 // go: adapted from SC3's LPF
651 y0 = in + m_b1 * m_y1 + m_b2 * m_y2;
652 result = m_a0 * (y0 + 2 * m_y1 + m_y2);
653 m_y2 = m_y1;
654 m_y1 = y0;
656 // be normal
657 CK_DDN(m_y1);
658 CK_DDN(m_y2);
660 return result;
663 // tick_hpf
664 inline SAMPLE tick_hpf( SAMPLE in )
666 SAMPLE y0, result;
668 // go: adapted from SC3's HPF
669 y0 = in + m_b1 * m_y1 + m_b2 * m_y2;
670 result = m_a0 * (y0 - 2 * m_y1 + m_y2);
671 m_y2 = m_y1;
672 m_y1 = y0;
674 // be normal
675 CK_DDN(m_y1);
676 CK_DDN(m_y2);
678 return result;
681 // set_bpf
682 inline void set_bpf( t_CKFLOAT freq, t_CKFLOAT Q )
684 t_CKFLOAT pfreq = freq * g_radians_per_sample;
685 t_CKFLOAT pbw = 1.0 / Q * pfreq * .5;
687 t_CKFLOAT C = 1.0 / ::tan(pbw);
688 t_CKFLOAT D = 2.0 * ::cos(pfreq);
689 t_CKFLOAT next_a0 = 1.0 / (1.0 + C);
690 t_CKFLOAT next_b1 = C * D * next_a0 ;
691 t_CKFLOAT next_b2 = (1.0 - C) * next_a0;
693 m_freq = freq;
694 m_Q = Q;
695 m_a0 = (SAMPLE)next_a0;
696 m_b1 = (SAMPLE)next_b1;
697 m_b2 = (SAMPLE)next_b2;
700 // tick_bpf
701 inline SAMPLE tick_bpf( SAMPLE in )
703 SAMPLE y0, result;
705 // go: adapted from SC3's LPF
706 y0 = in + m_b1 * m_y1 + m_b2 * m_y2;
707 result = m_a0 * (y0 - m_y2);
708 m_y2 = m_y1;
709 m_y1 = y0;
711 // be normal
712 CK_DDN(m_y1);
713 CK_DDN(m_y2);
715 return result;
718 // set_brf
719 inline void set_brf( t_CKFLOAT freq, t_CKFLOAT Q )
721 t_CKFLOAT pfreq = freq * g_radians_per_sample;
722 t_CKFLOAT pbw = 1.0 / Q * pfreq * .5;
724 t_CKFLOAT C = ::tan(pbw);
725 t_CKFLOAT D = 2.0 * ::cos(pfreq);
726 t_CKFLOAT next_a0 = 1.0 / (1.0 + C);
727 t_CKFLOAT next_b1 = -D * next_a0 ;
728 t_CKFLOAT next_b2 = (1.f - C) * next_a0;
730 m_freq = freq;
731 m_Q = Q;
732 m_a0 = (SAMPLE)next_a0;
733 m_b1 = (SAMPLE)next_b1;
734 m_b2 = (SAMPLE)next_b2;
737 // tick_brf
738 inline SAMPLE tick_brf( SAMPLE in )
740 SAMPLE y0, result;
742 // go: adapted from SC3's HPF
743 // b1 is actually a1
744 y0 = in - m_b1 * m_y1 - m_b2 * m_y2;
745 result = m_a0 * (y0 + m_y2) + m_b1 * m_y1;
746 m_y2 = m_y1;
747 m_y1 = y0;
749 // be normal
750 CK_DDN(m_y1);
751 CK_DDN(m_y2);
753 return result;
756 // set_rlpf
757 inline void set_rlpf( t_CKFLOAT freq, t_CKFLOAT Q )
759 t_CKFLOAT qres = ck_max( .001, 1.0/Q );
760 t_CKFLOAT pfreq = freq * g_radians_per_sample;
762 t_CKFLOAT D = ::tan(pfreq * qres * 0.5);
763 t_CKFLOAT C = (1.0 - D) / (1.0 + D);
764 t_CKFLOAT cosf = ::cos(pfreq);
765 t_CKFLOAT next_b1 = (1.0 + C) * cosf;
766 t_CKFLOAT next_b2 = -C;
767 t_CKFLOAT next_a0 = (1.0 + C - next_b1) * 0.25;
769 m_freq = freq;
770 m_Q = 1.0 / qres;
771 m_a0 = (SAMPLE)next_a0;
772 m_b1 = (SAMPLE)next_b1;
773 m_b2 = (SAMPLE)next_b2;
776 // tick_rlpf
777 inline SAMPLE tick_rlpf( SAMPLE in )
779 SAMPLE y0, result;
781 // go: adapated from SC3's RLPF
782 y0 = m_a0 * in + m_b1 * m_y1 + m_b2 * m_y2;
783 result = y0 + 2 * m_y1 + m_y2;
784 m_y2 = m_y1;
785 m_y1 = y0;
787 // be normal
788 CK_DDN(m_y1);
789 CK_DDN(m_y2);
791 return result;
794 // set_rhpf
795 inline void set_rhpf( t_CKFLOAT freq, t_CKFLOAT Q )
797 t_CKFLOAT qres = ck_max( .001, 1.0/Q );
798 t_CKFLOAT pfreq = freq * g_radians_per_sample;
800 t_CKFLOAT D = ::tan(pfreq * qres * 0.5);
801 t_CKFLOAT C = (1.0 - D) / (1.0 + D);
802 t_CKFLOAT cosf = ::cos(pfreq);
803 t_CKFLOAT next_b1 = (1.0 + C) * cosf;
804 t_CKFLOAT next_b2 = -C;
805 t_CKFLOAT next_a0 = (1.0 + C + next_b1) * 0.25;
807 m_freq = freq;
808 m_Q = 1.0 / qres;
809 m_a0 = (SAMPLE)next_a0;
810 m_b1 = (SAMPLE)next_b1;
811 m_b2 = (SAMPLE)next_b2;
814 // tick_rhpf
815 inline SAMPLE tick_rhpf( SAMPLE in )
817 SAMPLE y0, result;
819 // go: adapted from SC3's RHPF
820 y0 = m_a0 * in + m_b1 * m_y1 + m_b2 * m_y2;
821 result = y0 - 2 * m_y1 + m_y2;
822 m_y2 = m_y1;
823 m_y1 = y0;
825 // be normal
826 CK_DDN(m_y1);
827 CK_DDN(m_y2);
829 return result;
832 // set_resonz
833 inline void set_resonz( t_CKFLOAT freq, t_CKFLOAT Q )
835 t_CKFLOAT pfreq = freq * g_radians_per_sample;
836 t_CKFLOAT B = pfreq / Q;
837 t_CKFLOAT R = 1.0 - B * 0.5;
838 t_CKFLOAT R2 = 2.0 * R;
839 t_CKFLOAT R22 = R * R;
840 t_CKFLOAT cost = (R2 * ::cos(pfreq)) / (1.0 + R22);
841 t_CKFLOAT next_b1 = R2 * cost;
842 t_CKFLOAT next_b2 = -R22;
843 t_CKFLOAT next_a0 = (1.0 - R22) * 0.5;
845 m_freq = freq;
846 m_Q = Q;
847 m_a0 = (SAMPLE)next_a0;
848 m_b1 = (SAMPLE)next_b1;
849 m_b2 = (SAMPLE)next_b2;
852 // tick_resonz
853 inline SAMPLE tick_resonz( SAMPLE in )
855 SAMPLE y0, result;
857 // go: adapted from SC3's ResonZ
858 y0 = in + m_b1 * m_y1 + m_b2 * m_y2;
859 result = m_a0 * (y0 - m_y2);
860 m_y2 = m_y1;
861 m_y1 = y0;
863 // be normal
864 CK_DDN(m_y1);
865 CK_DDN(m_y2);
867 return result;
872 struct Teabox_data
874 //Teabox sensor interface read
875 t_CKINT teabox_counter;
876 t_CKFLOAT teabox_data[9]; // one container for the data from each sensor
877 t_CKFLOAT teabox_hw_version; // version number (major.minor) of the connected Teabox
878 t_CKFLOAT teabox_last_value;
879 t_CKINT teabox_bitmask;
880 //tick for teabox
881 inline SAMPLE teabox_tick( SAMPLE in )
884 if(in < 0.0 || teabox_counter > 9){ // If the sample is the start flag...
885 if(teabox_last_value < 0.0) // Actually - if all 16 toggles on the Teabox digital inputs
886 teabox_data[8] = teabox_last_value; // are high, it will look identical to the start flag - so
887 // so we compensate for that here.
888 teabox_counter = 0;
890 else if(teabox_counter == 0){ // if the sample is hardware version number...
891 teabox_hw_version = in * 8.0;
892 teabox_counter++;
894 else{
895 teabox_data[teabox_counter - 1] = in * 8.0; // Normalize the range
896 teabox_counter++;
899 // POST-PROCESS TOGGLE INPUT BITMASK
900 if(teabox_data[8] < 0){
901 teabox_bitmask = (t_CKINT)(teabox_data[8] * 32768); // 4096 = 32768 / 8 (we already multiplied by 8)
902 teabox_bitmask ^= -32768;
903 teabox_bitmask = 32768 + (teabox_bitmask); // 2^3
905 else
906 teabox_bitmask = (t_CKINT)(teabox_data[8] * 4096); // 4096 = 32768 / 8 (we already multiplied by 8)
908 teabox_last_value = in; // store the input value for the next time around
910 return in;
916 //-----------------------------------------------------------------------------
917 // name: FilterBasic_ctor()
918 // desc: CTOR function ...
919 //-----------------------------------------------------------------------------
920 CK_DLL_CTOR( FilterBasic_ctor )
922 // set to zero
923 OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data) = 0;
927 //-----------------------------------------------------------------------------
928 // name: FilterBasic_dtor()
929 // desc: DTOR function ...
930 //-----------------------------------------------------------------------------
931 CK_DLL_DTOR( FilterBasic_dtor )
933 // get data
934 FilterBasic_data * d = (FilterBasic_data *)OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data);
935 // delete
936 SAFE_DELETE(d);
937 // set
938 OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data) = 0;
942 //-----------------------------------------------------------------------------
943 // name: FilterBasic_tick()
944 // desc: TICK function ...
945 //-----------------------------------------------------------------------------
946 CK_DLL_TICK( FilterBasic_tick )
948 fprintf( stderr, "FilterBasic.tick() --> FitlerBasic is virtual!\n" );
949 return TRUE;
953 //-----------------------------------------------------------------------------
954 // name: FilterBasic_ctrl_freq()
955 // desc: CTRL function ...
956 //-----------------------------------------------------------------------------
957 CK_DLL_CTRL( FilterBasic_ctrl_freq )
962 //-----------------------------------------------------------------------------
963 // name: FilterBasic_cget_freq()
964 // desc: CGET function
965 //-----------------------------------------------------------------------------
966 CK_DLL_CGET( FilterBasic_cget_freq )
971 //-----------------------------------------------------------------------------
972 // name: FilterBasic_ctrl_Q()
973 // desc: CTRL function
974 //-----------------------------------------------------------------------------
975 CK_DLL_CTRL( FilterBasic_ctrl_Q )
980 //-----------------------------------------------------------------------------
981 // name: FilterBasic_cget_Q()
982 // desc: CGET function
983 //-----------------------------------------------------------------------------
984 CK_DLL_CGET( FilterBasic_cget_Q )
989 //-----------------------------------------------------------------------------
990 // name: FilterBasic_ctrl_set()
991 // desc: CTRL function
992 //-----------------------------------------------------------------------------
993 CK_DLL_CTRL( FilterBasic_ctrl_set )
998 //-----------------------------------------------------------------------------
999 // name: FilterBasic_pmsg()
1000 // desc: PMSG function ...
1001 //-----------------------------------------------------------------------------
1002 CK_DLL_PMSG( FilterBasic_pmsg )
1004 return FALSE;
1010 //-----------------------------------------------------------------------------
1011 // name: LPF_ctor()
1012 // desc: CTOR function ...
1013 //-----------------------------------------------------------------------------
1014 CK_DLL_CTOR( LPF_ctor )
1016 FilterBasic_data * f = new FilterBasic_data;
1017 memset( f, 0, sizeof(FilterBasic_data) );
1018 OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data) = (t_CKUINT)f;
1022 //-----------------------------------------------------------------------------
1023 // name: LPF_tick()
1024 // desc: TICK function ...
1025 //-----------------------------------------------------------------------------
1026 CK_DLL_TICK( LPF_tick )
1028 FilterBasic_data * d = (FilterBasic_data *)OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data);
1029 *out = d->tick_lpf( in );
1030 return TRUE;
1034 //-----------------------------------------------------------------------------
1035 // name: LPF_ctrl_freq()
1036 // desc: CTRL function
1037 //-----------------------------------------------------------------------------
1038 CK_DLL_CTRL( LPF_ctrl_freq )
1040 // implementation: adapted from SC3's LPF
1041 FilterBasic_data * d = (FilterBasic_data *)OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data);
1042 t_CKFLOAT freq = GET_NEXT_FLOAT(ARGS);
1043 t_CKFLOAT pfreq = freq * g_radians_per_sample * 0.5;
1045 t_CKFLOAT C = 1.0 / ::tan(pfreq);
1046 t_CKFLOAT C2 = C * C;
1047 t_CKFLOAT sqrt2C = C * SQRT2;
1048 t_CKFLOAT next_a0 = 1.0 / (1.0 + sqrt2C + C2);
1049 t_CKFLOAT next_b1 = -2.0 * (1.0 - C2) * next_a0 ;
1050 t_CKFLOAT next_b2 = -(1.f - sqrt2C + C2) * next_a0;
1052 d->m_freq = freq;
1053 d->m_a0 = (SAMPLE)next_a0;
1054 d->m_b1 = (SAMPLE)next_b1;
1055 d->m_b2 = (SAMPLE)next_b2;
1057 RETURN->v_float = freq;
1061 //-----------------------------------------------------------------------------
1062 // name: LPF_cget_freq()
1063 // desc: CGET function
1064 //-----------------------------------------------------------------------------
1065 CK_DLL_CGET( LPF_cget_freq )
1067 FilterBasic_data * d = (FilterBasic_data *)OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data);
1069 // return
1070 RETURN->v_float = d->m_freq;
1074 //-----------------------------------------------------------------------------
1075 // name: LPF_pmsg()
1076 // desc: PMSG function ...
1077 //-----------------------------------------------------------------------------
1078 CK_DLL_PMSG( LPF_pmsg )
1080 return FALSE;
1086 //-----------------------------------------------------------------------------
1087 // name: HPF_ctor()
1088 // desc: CTOR function ...
1089 //-----------------------------------------------------------------------------
1090 CK_DLL_CTOR( HPF_ctor )
1092 FilterBasic_data * f = new FilterBasic_data;
1093 memset( f, 0, sizeof(FilterBasic_data) );
1094 OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data) = (t_CKUINT)f;
1098 //-----------------------------------------------------------------------------
1099 // name: HPF_tick()
1100 // desc: TICK function ...
1101 //-----------------------------------------------------------------------------
1102 CK_DLL_TICK( HPF_tick )
1104 FilterBasic_data * d = (FilterBasic_data *)OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data);
1105 *out = d->tick_hpf( in );
1106 return TRUE;
1110 //-----------------------------------------------------------------------------
1111 // name: HPF_ctrl_freq()
1112 // desc: CTRL function ...
1113 //-----------------------------------------------------------------------------
1114 CK_DLL_CTRL( HPF_ctrl_freq )
1116 // implementation: adapted from SC3's HPF
1117 FilterBasic_data * d = (FilterBasic_data *)OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data);
1118 t_CKFLOAT freq = GET_NEXT_FLOAT(ARGS);
1119 t_CKFLOAT pfreq = freq * g_radians_per_sample * 0.5;
1121 t_CKFLOAT C = ::tan(pfreq);
1122 t_CKFLOAT C2 = C * C;
1123 t_CKFLOAT sqrt2C = C * SQRT2;
1124 t_CKFLOAT next_a0 = 1.0 / (1.0 + sqrt2C + C2);
1125 t_CKFLOAT next_b1 = 2.0 * (1.0 - C2) * next_a0 ;
1126 t_CKFLOAT next_b2 = -(1.0 - sqrt2C + C2) * next_a0;
1128 d->m_freq = freq;
1129 d->m_a0 = (SAMPLE)next_a0;
1130 d->m_b1 = (SAMPLE)next_b1;
1131 d->m_b2 = (SAMPLE)next_b2;
1133 RETURN->v_float = freq;
1137 //-----------------------------------------------------------------------------
1138 // name: HPF_cget_freq()
1139 // desc: CGET function
1140 //-----------------------------------------------------------------------------
1141 CK_DLL_CGET( HPF_cget_freq )
1143 FilterBasic_data * d = (FilterBasic_data *)OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data);
1145 // return
1146 RETURN->v_float = d->m_freq;
1150 //-----------------------------------------------------------------------------
1151 // name: HPF_pmsg()
1152 // desc: PMSG function ...
1153 //-----------------------------------------------------------------------------
1154 CK_DLL_PMSG( HPF_pmsg )
1156 return FALSE;
1162 //-----------------------------------------------------------------------------
1163 // name: BPF_ctor()
1164 // desc: CTOR function ...
1165 //-----------------------------------------------------------------------------
1166 CK_DLL_CTOR( BPF_ctor )
1168 FilterBasic_data * f = new FilterBasic_data;
1169 memset( f, 0, sizeof(FilterBasic_data) );
1170 OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data) = (t_CKUINT)f;
1174 //-----------------------------------------------------------------------------
1175 // name: BPF_tick()
1176 // desc: TICK function ...
1177 //-----------------------------------------------------------------------------
1178 CK_DLL_TICK( BPF_tick )
1180 FilterBasic_data * d = (FilterBasic_data *)OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data);
1181 *out = d->tick_bpf( in );
1182 return TRUE;
1186 //-----------------------------------------------------------------------------
1187 // name: BPF_ctrl_freq()
1188 // desc: CTRL function
1189 //-----------------------------------------------------------------------------
1190 CK_DLL_CTRL( BPF_ctrl_freq )
1192 // implementation: adapted from SC3's BPF
1193 FilterBasic_data * d = (FilterBasic_data *)OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data);
1194 t_CKFLOAT freq = GET_NEXT_FLOAT(ARGS);
1196 // set
1197 d->set_bpf( freq, d->m_Q );
1199 // return
1200 RETURN->v_float = d->m_freq;
1204 //-----------------------------------------------------------------------------
1205 // name: BPF_cget_freq()
1206 // desc: CGET function
1207 //-----------------------------------------------------------------------------
1208 CK_DLL_CGET( BPF_cget_freq )
1210 FilterBasic_data * d = (FilterBasic_data *)OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data);
1212 // return
1213 RETURN->v_float = d->m_freq;
1217 //-----------------------------------------------------------------------------
1218 // name: BPF_ctrl_Q()
1219 // desc: CTRL function
1220 //-----------------------------------------------------------------------------
1221 CK_DLL_CTRL( BPF_ctrl_Q )
1223 // implementation: adapted from SC3's BPF
1224 FilterBasic_data * d = (FilterBasic_data *)OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data);
1225 t_CKFLOAT Q = GET_NEXT_FLOAT(ARGS);
1227 // set
1228 d->set_bpf( d->m_freq, Q );
1231 RETURN->v_float = d->m_Q;
1235 //-----------------------------------------------------------------------------
1236 // name: BPF_cget_Q()
1237 // desc: CGET function
1238 //-----------------------------------------------------------------------------
1239 CK_DLL_CGET( BPF_cget_Q )
1241 FilterBasic_data * d = (FilterBasic_data *)OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data);
1243 // return
1244 RETURN->v_float = d->m_Q;
1248 //-----------------------------------------------------------------------------
1249 // name: BPF_ctrl_set()
1250 // desc: CTRL function
1251 //-----------------------------------------------------------------------------
1252 CK_DLL_CTRL( BPF_ctrl_set )
1254 // implementation: adapted from SC3's BPF
1255 FilterBasic_data * d = (FilterBasic_data *)OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data);
1256 t_CKFLOAT freq = GET_NEXT_FLOAT(ARGS);
1257 t_CKFLOAT Q = GET_NEXT_FLOAT(ARGS);
1259 // set
1260 d->set_bpf( freq, Q );
1264 //-----------------------------------------------------------------------------
1265 // name: BPF_pmsg()
1266 // desc: PMSG function ...
1267 //-----------------------------------------------------------------------------
1268 CK_DLL_PMSG( BPF_pmsg )
1270 return FALSE;
1276 //-----------------------------------------------------------------------------
1277 // name: BRF_ctor()
1278 // desc: CTOR function ...
1279 //-----------------------------------------------------------------------------
1280 CK_DLL_CTOR( BRF_ctor )
1282 FilterBasic_data * f = new FilterBasic_data;
1283 memset( f, 0, sizeof(FilterBasic_data) );
1284 OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data) = (t_CKUINT)f;
1288 //-----------------------------------------------------------------------------
1289 // name: BRF_tick()
1290 // desc: TICK function ...
1291 //-----------------------------------------------------------------------------
1292 CK_DLL_TICK( BRF_tick )
1294 FilterBasic_data * d = (FilterBasic_data *)OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data);
1295 *out = d->tick_brf( in );
1296 return TRUE;
1300 //-----------------------------------------------------------------------------
1301 // name: BRF_ctrl_freq()
1302 // desc: CTRL function
1303 //-----------------------------------------------------------------------------
1304 CK_DLL_CTRL( BRF_ctrl_freq )
1306 // implementation: adapted from SC3's BRF
1307 FilterBasic_data * d = (FilterBasic_data *)OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data);
1308 t_CKFLOAT freq = GET_NEXT_FLOAT(ARGS);
1310 // set
1311 d->set_brf( freq, d->m_Q );
1313 // return
1314 RETURN->v_float = d->m_freq;
1318 //-----------------------------------------------------------------------------
1319 // name: BRF_cget_freq()
1320 // desc: CGET function
1321 //-----------------------------------------------------------------------------
1322 CK_DLL_CGET( BRF_cget_freq )
1324 FilterBasic_data * d = (FilterBasic_data *)OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data);
1326 // return
1327 RETURN->v_float = d->m_freq;
1331 //-----------------------------------------------------------------------------
1332 // name: BRF_ctrl_Q()
1333 // desc: CTRL function
1334 //-----------------------------------------------------------------------------
1335 CK_DLL_CTRL( BRF_ctrl_Q )
1337 // implementation: adapted from SC3's BRF
1338 FilterBasic_data * d = (FilterBasic_data *)OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data);
1339 t_CKFLOAT Q = GET_NEXT_FLOAT(ARGS);
1341 // set
1342 d->set_brf( d->m_freq, Q );
1344 // return
1345 RETURN->v_float = d->m_Q;
1349 //-----------------------------------------------------------------------------
1350 // name: BRF_cget_Q()
1351 // desc: CGET function
1352 //-----------------------------------------------------------------------------
1353 CK_DLL_CGET( BRF_cget_Q )
1355 FilterBasic_data * d = (FilterBasic_data *)OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data);
1357 // return
1358 RETURN->v_float = d->m_Q;
1362 //-----------------------------------------------------------------------------
1363 // name: BRF_ctrl_set()
1364 // desc: CTRL function
1365 //-----------------------------------------------------------------------------
1366 CK_DLL_CTRL( BRF_ctrl_set )
1368 // implementation: adapted from SC3's BRF
1369 FilterBasic_data * d = (FilterBasic_data *)OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data);
1370 t_CKFLOAT freq = GET_NEXT_FLOAT(ARGS);
1371 t_CKFLOAT Q = GET_NEXT_FLOAT(ARGS);
1373 // set
1374 d->set_brf( freq, Q );
1378 //-----------------------------------------------------------------------------
1379 // name: BRF_pmsg()
1380 // desc: PMSG function ...
1381 //-----------------------------------------------------------------------------
1382 CK_DLL_PMSG( BRF_pmsg )
1384 return FALSE;
1390 //-----------------------------------------------------------------------------
1391 // name: RLPF_ctor()
1392 // desc: CTOR function ...
1393 //-----------------------------------------------------------------------------
1394 CK_DLL_CTOR( RLPF_ctor )
1396 FilterBasic_data * f = new FilterBasic_data;
1397 memset( f, 0, sizeof(FilterBasic_data) );
1398 // default
1399 f->m_Q = 1.0;
1400 OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data) = (t_CKUINT)f;
1404 //-----------------------------------------------------------------------------
1405 // name: RLPF_tick()
1406 // desc: TICK function ...
1407 //-----------------------------------------------------------------------------
1408 CK_DLL_TICK( RLPF_tick )
1410 FilterBasic_data * d = (FilterBasic_data *)OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data);
1411 *out = d->tick_rlpf( in );
1412 return TRUE;
1416 //-----------------------------------------------------------------------------
1417 // name: RLPF_ctrl_freq()
1418 // desc: CTRL function
1419 //-----------------------------------------------------------------------------
1420 CK_DLL_CTRL( RLPF_ctrl_freq )
1422 FilterBasic_data * d = (FilterBasic_data *)OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data);
1423 t_CKFLOAT freq = GET_NEXT_FLOAT(ARGS);
1425 // set
1426 d->set_rlpf( freq, d->m_Q );
1428 // return
1429 RETURN->v_float = d->m_freq;
1433 //-----------------------------------------------------------------------------
1434 // name: RLPF_cget_freq()
1435 // desc: CGET function
1436 //-----------------------------------------------------------------------------
1437 CK_DLL_CGET( RLPF_cget_freq )
1439 FilterBasic_data * d = (FilterBasic_data *)OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data);
1441 // return
1442 RETURN->v_float = d->m_freq;
1446 //-----------------------------------------------------------------------------
1447 // name: RLPF_ctrl_Q()
1448 // desc: CTRL function
1449 //-----------------------------------------------------------------------------
1450 CK_DLL_CTRL( RLPF_ctrl_Q )
1452 FilterBasic_data * d = (FilterBasic_data *)OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data);
1453 t_CKFLOAT Q = GET_NEXT_FLOAT(ARGS);
1455 // set
1456 d->set_rlpf( d->m_freq, Q );
1458 // return
1459 RETURN->v_float = d->m_Q;
1463 //-----------------------------------------------------------------------------
1464 // name: RLPF_cget_Q()
1465 // desc: CGET function
1466 //-----------------------------------------------------------------------------
1467 CK_DLL_CGET( RLPF_cget_Q )
1469 FilterBasic_data * d = (FilterBasic_data *)OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data);
1471 // return
1472 RETURN->v_float = d->m_Q;
1476 //-----------------------------------------------------------------------------
1477 // name: RLPF_ctrl_set()
1478 // desc: CTRL function
1479 //-----------------------------------------------------------------------------
1480 CK_DLL_CTRL( RLPF_ctrl_set )
1482 // implementation: adapted from SC3's RLPF
1483 FilterBasic_data * d = (FilterBasic_data *)OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data);
1484 t_CKFLOAT freq = GET_NEXT_FLOAT(ARGS);
1485 t_CKFLOAT Q = GET_NEXT_FLOAT(ARGS);
1487 // set
1488 d->set_rlpf( freq, Q );
1490 RETURN->v_float = freq;
1494 //-----------------------------------------------------------------------------
1495 // name: RLPF_pmsg()
1496 // desc: PMSG function ...
1497 //-----------------------------------------------------------------------------
1498 CK_DLL_PMSG( RLPF_pmsg )
1500 return FALSE;
1506 //-----------------------------------------------------------------------------
1507 // name: ResonZ_ctor()
1508 // desc: CTOR function ...
1509 //-----------------------------------------------------------------------------
1510 CK_DLL_CTOR( ResonZ_ctor )
1512 FilterBasic_data * f = new FilterBasic_data;
1513 memset( f, 0, sizeof(FilterBasic_data) );
1514 // default
1515 f->set_resonz( 220, 1 );
1516 OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data) = (t_CKUINT)f;
1520 //-----------------------------------------------------------------------------
1521 // name: ResonZ_tick()
1522 // desc: TICK function ...
1523 //-----------------------------------------------------------------------------
1524 CK_DLL_TICK( ResonZ_tick )
1526 FilterBasic_data * d = (FilterBasic_data *)OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data);
1527 *out = d->tick_resonz( in );
1528 return TRUE;
1532 //-----------------------------------------------------------------------------
1533 // name: ResonZ_ctrl_freq()
1534 // desc: CTRL function
1535 //-----------------------------------------------------------------------------
1536 CK_DLL_CTRL( ResonZ_ctrl_freq )
1538 FilterBasic_data * d = (FilterBasic_data *)OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data);
1539 t_CKFLOAT freq = GET_NEXT_FLOAT(ARGS);
1541 // set
1542 d->set_resonz( freq, d->m_Q );
1544 // return
1545 RETURN->v_float = d->m_freq;
1549 //-----------------------------------------------------------------------------
1550 // name: ResonZ_cget_freq()
1551 // desc: CGET function
1552 //-----------------------------------------------------------------------------
1553 CK_DLL_CGET( ResonZ_cget_freq )
1555 FilterBasic_data * d = (FilterBasic_data *)OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data);
1557 // return
1558 RETURN->v_float = d->m_freq;
1562 //-----------------------------------------------------------------------------
1563 // name: ResonZ_ctrl_Q()
1564 // desc: CTRL function
1565 //-----------------------------------------------------------------------------
1566 CK_DLL_CTRL( ResonZ_ctrl_Q )
1568 FilterBasic_data * d = (FilterBasic_data *)OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data);
1569 t_CKFLOAT Q = GET_NEXT_FLOAT(ARGS);
1571 // set
1572 d->set_resonz( d->m_freq, Q );
1574 // return
1575 RETURN->v_float = d->m_Q;
1579 //-----------------------------------------------------------------------------
1580 // name: ResonZ_cget_Q()
1581 // desc: CGET function
1582 //-----------------------------------------------------------------------------
1583 CK_DLL_CGET( ResonZ_cget_Q )
1585 FilterBasic_data * d = (FilterBasic_data *)OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data);
1587 // return
1588 RETURN->v_float = d->m_Q;
1592 //-----------------------------------------------------------------------------
1593 // name: ResonZ_ctrl_set()
1594 // desc: CTRL function
1595 //-----------------------------------------------------------------------------
1596 CK_DLL_CTRL( ResonZ_ctrl_set )
1598 // implementation: adapted from SC3's RLPF
1599 FilterBasic_data * d = (FilterBasic_data *)OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data);
1600 t_CKFLOAT freq = GET_NEXT_FLOAT(ARGS);
1601 t_CKFLOAT Q = GET_NEXT_FLOAT(ARGS);
1603 // set
1604 d->set_resonz( freq, Q );
1606 RETURN->v_float = freq;
1610 //-----------------------------------------------------------------------------
1611 // name: ResonZ_pmsg()
1612 // desc: PMSG function ...
1613 //-----------------------------------------------------------------------------
1614 CK_DLL_PMSG( ResonZ_pmsg )
1616 return FALSE;
1622 //-----------------------------------------------------------------------------
1623 // name: RHPF_ctor()
1624 // desc: CTOR function ...
1625 //-----------------------------------------------------------------------------
1626 CK_DLL_CTOR( RHPF_ctor )
1628 FilterBasic_data * f = new FilterBasic_data;
1629 memset( f, 0, sizeof(FilterBasic_data) );
1630 // default
1631 f->m_Q = 1.0;
1632 OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data) = (t_CKUINT)f;
1636 //-----------------------------------------------------------------------------
1637 // name: RHPF_tick()
1638 // desc: TICK function ...
1639 //-----------------------------------------------------------------------------
1640 CK_DLL_TICK( RHPF_tick )
1642 FilterBasic_data * d = (FilterBasic_data *)OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data);
1643 *out = d->tick_rhpf( in );
1644 return TRUE;
1648 //-----------------------------------------------------------------------------
1649 // name: RHPF_ctrl_freq()
1650 // desc: CTRL function
1651 //-----------------------------------------------------------------------------
1652 CK_DLL_CTRL( RHPF_ctrl_freq )
1654 FilterBasic_data * d = (FilterBasic_data *)OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data);
1655 t_CKFLOAT freq = GET_NEXT_FLOAT(ARGS);
1657 // set
1658 d->set_rhpf( freq, d->m_Q );
1660 // return
1661 RETURN->v_float = d->m_freq;
1665 //-----------------------------------------------------------------------------
1666 // name: RHPF_cget_freq()
1667 // desc: CGET function
1668 //-----------------------------------------------------------------------------
1669 CK_DLL_CGET( RHPF_cget_freq )
1671 FilterBasic_data * d = (FilterBasic_data *)OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data);
1673 // return
1674 RETURN->v_float = d->m_freq;
1678 //-----------------------------------------------------------------------------
1679 // name: RHPF_ctrl_Q()
1680 // desc: CTRL function
1681 //-----------------------------------------------------------------------------
1682 CK_DLL_CTRL( RHPF_ctrl_Q )
1684 FilterBasic_data * d = (FilterBasic_data *)OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data);
1685 t_CKFLOAT Q = GET_NEXT_FLOAT(ARGS);
1687 // set
1688 d->set_rhpf( d->m_freq, Q );
1690 // return
1691 RETURN->v_float = d->m_Q;
1695 //-----------------------------------------------------------------------------
1696 // name: RHPF_cget_Q()
1697 // desc: CGET function
1698 //-----------------------------------------------------------------------------
1699 CK_DLL_CGET( RHPF_cget_Q )
1701 FilterBasic_data * d = (FilterBasic_data *)OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data);
1703 // return
1704 RETURN->v_float = d->m_Q;
1708 //-----------------------------------------------------------------------------
1709 // name: RHPF_ctrl_set()
1710 // desc: CTRL function
1711 //-----------------------------------------------------------------------------
1712 CK_DLL_CTRL( RHPF_ctrl_set )
1714 // implementation: adapted from SC3's RLPF
1715 FilterBasic_data * d = (FilterBasic_data *)OBJ_MEMBER_UINT(SELF, FilterBasic_offset_data);
1716 t_CKFLOAT freq = GET_NEXT_FLOAT(ARGS);
1717 t_CKFLOAT Q = GET_NEXT_FLOAT(ARGS);
1719 // set
1720 d->set_rlpf( freq, Q );
1724 //-----------------------------------------------------------------------------
1725 // name: RHPF_pmsg()
1726 // desc: PMSG function ...
1727 //-----------------------------------------------------------------------------
1728 CK_DLL_PMSG( RHPF_pmsg )
1730 return FALSE;
1735 //-----------------------------------------------------------------------------
1736 // name: teabox_ctor()
1737 // desc: CTOR function ...
1738 //-----------------------------------------------------------------------------
1739 CK_DLL_CTOR( teabox_ctor )
1741 Teabox_data * f = new Teabox_data;
1742 memset( f, 0, sizeof(Teabox_data) );
1743 f->teabox_hw_version = 0.; // version number (major.minor) of the connected Teabox
1744 f->teabox_last_value = 0.;
1745 OBJ_MEMBER_UINT(SELF, Teabox_offset_data) = (t_CKUINT)f;
1748 //-----------------------------------------------------------------------------
1749 // name: teabox_tick()
1750 // desc: TICK function ...
1751 //-----------------------------------------------------------------------------
1752 CK_DLL_TICK( teabox_tick )
1754 Teabox_data * d = (Teabox_data *)OBJ_MEMBER_UINT(SELF, Teabox_offset_data);
1755 *out = d->teabox_tick( in );
1756 return TRUE;
1760 //-----------------------------------------------------------------------------
1761 // name: teabox_cget_analog()
1762 // desc: CGET function
1763 //-----------------------------------------------------------------------------
1764 CK_DLL_CGET( teabox_cget_analog )
1766 t_CKINT which_in;
1767 Teabox_data * d = (Teabox_data *)OBJ_MEMBER_UINT(SELF, Teabox_offset_data);
1769 which_in = GET_CK_INT(ARGS);
1771 //constrain
1772 if(which_in < 0) which_in = 0;
1773 if(which_in > 7) which_in = 7;
1775 // return
1776 RETURN->v_float = d->teabox_data[which_in];
1779 CK_DLL_CGET( teabox_cget_digital )
1781 t_CKINT which_in;
1782 t_CKFLOAT out_val;
1783 t_CKINT which_pow;
1785 Teabox_data * d = (Teabox_data *)OBJ_MEMBER_UINT(SELF, Teabox_offset_data);
1787 which_in = GET_CK_INT(ARGS);
1789 //constrain
1790 if(which_in < 0) which_in = 0;
1791 if(which_in > 15) which_in = 15;
1793 // grab the needed bit from bitmask
1794 // which_pow = (t_CKINT)(::pow( 2, which_in ));
1795 which_pow = 1 >> which_in;
1796 out_val = ( d->teabox_bitmask & which_pow ) > 0;
1798 // return
1799 RETURN->v_float = out_val;
1802 //-----------------------------------------------------------------------------
1803 // name: teabox_pmsg()
1804 // desc: PMSG function ...
1805 //-----------------------------------------------------------------------------
1806 CK_DLL_PMSG( teabox_pmsg )
1808 return FALSE;
1812 //-----------------------------------------------------------------------------
1813 // name: biquad
1814 // desc: biquad filter
1815 //-----------------------------------------------------------------------------
1816 struct biquad_data
1818 SAMPLE m_a0, m_a1, m_a2;
1819 SAMPLE m_b0, m_b1, m_b2;
1821 SAMPLE m_input0, m_input1, m_input2;
1822 SAMPLE m_output0, m_output1, m_output2;
1824 t_CKFLOAT pfreq, zfreq;
1825 t_CKFLOAT prad, zrad;
1826 t_CKBOOL norm;
1827 t_CKUINT srate;
1829 biquad_data()
1831 m_a0 = m_b0 = 1.0f;
1832 m_a1 = m_a2 = 0.0f;
1833 m_b1 = 0.0f; m_b2 = 0.0f;
1835 m_input0 = m_input1 = m_input2 = 0.0f;
1836 m_output0 = m_output1 = m_output2 = 0.0f;
1838 pfreq = zfreq = 0.0f;
1839 prad = zrad = 0.0f;
1840 norm = FALSE;
1841 srate = g_srate;
1848 //-----------------------------------------------------------------------------
1849 // name: biquad_ctor()
1850 // desc: CTOR function ...
1851 //-----------------------------------------------------------------------------
1852 CK_DLL_CTOR( biquad_ctor )
1854 biquad_data* d = new biquad_data;
1855 OBJ_MEMBER_UINT( SELF, biquad_offset_data ) = (t_CKUINT)d;
1858 //-----------------------------------------------------------------------------
1859 // name: biquad_dtor()
1860 // desc: DTOR function ...
1861 //-----------------------------------------------------------------------------
1862 CK_DLL_DTOR( biquad_dtor )
1864 biquad_data * d = (biquad_data *)OBJ_MEMBER_UINT(SELF, biquad_offset_data );
1865 SAFE_DELETE( d );
1866 OBJ_MEMBER_UINT(SELF, biquad_offset_data) = 0;
1869 //-----------------------------------------------------------------------------
1870 // name: biquad_tick()
1871 // desc: TICK function ...
1872 //-----------------------------------------------------------------------------
1873 CK_DLL_TICK( biquad_tick )
1875 biquad_data * d = (biquad_data *)OBJ_MEMBER_UINT(SELF, biquad_offset_data );
1877 d->m_input0 = d->m_a0 * in;
1878 d->m_output0 = d->m_b0 * d->m_input0 + d->m_b1 * d->m_input1 + d->m_b2 * d->m_input2;
1879 d->m_output0 -= d->m_a2 * d->m_output2 + d->m_a1 * d->m_output1;
1880 d->m_input2 = d->m_input1;
1881 d->m_input1 = d->m_input0;
1882 d->m_output2 = d->m_output1;
1883 d->m_output1 = d->m_output0;
1885 // be normal
1886 CK_DDN(d->m_output1);
1887 CK_DDN(d->m_output2);
1889 *out = (SAMPLE)d->m_output0;
1891 return TRUE;
1894 void biquad_set_reson( biquad_data * d )
1896 d->m_a2 = (SAMPLE)(d->prad * d->prad);
1897 d->m_a1 = (SAMPLE)(-2.0 * d->prad * cos(2.0 * ONE_PI * d->pfreq / (double)d->srate));
1899 if ( d->norm ) {
1900 // Use zeros at +- 1 and normalize the filter peak gain.
1901 d->m_b0= 0.5f - 0.5f * d->m_a2;
1902 d->m_b1 = -1.0f;
1903 d->m_b2 = -d->m_b0;
1907 //-----------------------------------------------------------------------------
1908 // name: biquad_ctrl_pfreq()
1909 // desc: CTRL function ...
1910 //-----------------------------------------------------------------------------
1911 CK_DLL_CTRL( biquad_ctrl_pfreq )
1913 biquad_data * d = (biquad_data *)OBJ_MEMBER_UINT(SELF, biquad_offset_data );
1914 d->pfreq = GET_CK_FLOAT(ARGS);
1915 biquad_set_reson( d );
1916 RETURN->v_float = d->pfreq;
1919 //-----------------------------------------------------------------------------
1920 // name: biquad_cget_pfreq()
1921 // desc: CGET function ...
1922 //-----------------------------------------------------------------------------
1923 CK_DLL_CTRL( biquad_cget_pfreq )
1925 biquad_data * d = (biquad_data *)OBJ_MEMBER_UINT(SELF, biquad_offset_data );
1926 RETURN->v_float = d->pfreq;
1929 //-----------------------------------------------------------------------------
1930 // name: biquad_ctrl_prad()
1931 // desc: CTRL function ...
1932 //-----------------------------------------------------------------------------
1933 CK_DLL_CTRL( biquad_ctrl_prad )
1935 biquad_data * d = (biquad_data *)OBJ_MEMBER_UINT(SELF, biquad_offset_data );
1936 d->prad = GET_CK_FLOAT(ARGS);
1937 biquad_set_reson( d );
1938 RETURN->v_float = d->prad;
1941 //-----------------------------------------------------------------------------
1942 // name: biquad_cget_prad()
1943 // desc: CGET function ...
1944 //-----------------------------------------------------------------------------
1945 CK_DLL_CTRL( biquad_cget_prad )
1947 biquad_data * d = (biquad_data *)OBJ_MEMBER_UINT(SELF, biquad_offset_data );
1948 RETURN->v_float = d->prad;
1951 void biquad_set_notch( biquad_data * d )
1953 d->m_b2 = (SAMPLE)(d->zrad * d->zrad);
1954 d->m_b1 = (SAMPLE)(-2.0 * d->zrad * cos(2.0 * ONE_PI * d->zfreq / (double)d->srate));
1957 //-----------------------------------------------------------------------------
1958 // name: biquad_ctrl_zfreq()
1959 // desc: CTRL function ...
1960 //-----------------------------------------------------------------------------
1961 CK_DLL_CTRL( biquad_ctrl_zfreq )
1963 biquad_data * d = (biquad_data *)OBJ_MEMBER_UINT(SELF, biquad_offset_data );
1964 d->zfreq = GET_CK_FLOAT(ARGS);
1965 biquad_set_notch( d );
1966 RETURN->v_float = d->zfreq;
1969 //-----------------------------------------------------------------------------
1970 // name: biquad_cget_zfreq()
1971 // desc: CGET function ...
1972 //-----------------------------------------------------------------------------
1973 CK_DLL_CTRL( biquad_cget_zfreq )
1975 biquad_data * d = (biquad_data *)OBJ_MEMBER_UINT(SELF, biquad_offset_data );
1976 RETURN->v_float = d->zfreq;
1979 //-----------------------------------------------------------------------------
1980 // name: biquad_ctrl_zrad()
1981 // desc: CTRL function ...
1982 //-----------------------------------------------------------------------------
1983 CK_DLL_CTRL( biquad_ctrl_zrad )
1985 biquad_data * d = (biquad_data *)OBJ_MEMBER_UINT(SELF, biquad_offset_data );
1986 d->zrad = GET_CK_FLOAT(ARGS);
1987 biquad_set_notch( d );
1988 RETURN->v_float = d->zrad;
1991 //-----------------------------------------------------------------------------
1992 // name: biquad_cget_zrad()
1993 // desc: CGET function ...
1994 //-----------------------------------------------------------------------------
1995 CK_DLL_CTRL( biquad_cget_zrad )
1997 biquad_data * d = (biquad_data *)OBJ_MEMBER_UINT(SELF, biquad_offset_data );
1998 RETURN->v_float = d->zrad;
2001 //-----------------------------------------------------------------------------
2002 // name: biquad_ctrl_norm()
2003 // desc: CTRL function ...
2004 //-----------------------------------------------------------------------------
2005 CK_DLL_CTRL( biquad_ctrl_norm )
2007 biquad_data * d = (biquad_data *)OBJ_MEMBER_UINT(SELF, biquad_offset_data );
2008 d->norm = *(t_CKBOOL *)ARGS;
2009 biquad_set_reson( d );
2010 RETURN->v_int = d->norm;
2013 //-----------------------------------------------------------------------------
2014 // name: biquad_cget_norm()
2015 // desc: CGET function ...
2016 //-----------------------------------------------------------------------------
2017 CK_DLL_CTRL( biquad_cget_norm )
2019 biquad_data * d = (biquad_data *)OBJ_MEMBER_UINT(SELF, biquad_offset_data );
2020 RETURN->v_int = d->norm;
2023 //-----------------------------------------------------------------------------
2024 // name: biquad_ctrl_pregain()
2025 // desc: CTRL function ...
2026 //-----------------------------------------------------------------------------
2027 CK_DLL_CTRL( biquad_ctrl_pregain )
2029 biquad_data * d = (biquad_data *)OBJ_MEMBER_UINT(SELF, biquad_offset_data );
2030 d->m_a0 = (SAMPLE)GET_CK_FLOAT(ARGS);
2031 RETURN->v_float = d->m_a0;
2034 //-----------------------------------------------------------------------------
2035 // name: biquad_cget_pregain()
2036 // desc: CGET function ...
2037 //-----------------------------------------------------------------------------
2038 CK_DLL_CTRL( biquad_cget_pregain )
2040 biquad_data * d = (biquad_data *)OBJ_MEMBER_UINT(SELF, biquad_offset_data );
2041 RETURN->v_float = d->m_a0;
2044 //-----------------------------------------------------------------------------
2045 // name: biquad_ctrl_eqzs()
2046 // desc: CTRL function ...
2047 //-----------------------------------------------------------------------------
2048 CK_DLL_CTRL( biquad_ctrl_eqzs )
2050 if( *(t_CKUINT *)ARGS )
2052 biquad_data * d = (biquad_data *)OBJ_MEMBER_UINT(SELF, biquad_offset_data );
2053 d->m_b0 = 1.0f;
2054 d->m_b1 = 0.0f;
2055 d->m_b2 = -1.0f;
2057 RETURN->v_int = *(t_CKUINT *)ARGS;
2060 //-----------------------------------------------------------------------------
2061 // name: biquad_ctrl_b0()
2062 // desc: CTRL function ...
2063 //-----------------------------------------------------------------------------
2064 CK_DLL_CTRL( biquad_ctrl_b0 )
2066 biquad_data * d = (biquad_data *)OBJ_MEMBER_UINT(SELF, biquad_offset_data );
2067 d->m_b0 = (SAMPLE)GET_CK_FLOAT(ARGS);
2068 RETURN->v_float = d->m_b0;
2071 //-----------------------------------------------------------------------------
2072 // name: biquad_cget_b0()
2073 // desc: CGET function ...
2074 //-----------------------------------------------------------------------------
2075 CK_DLL_CTRL( biquad_cget_b0 )
2077 biquad_data * d = (biquad_data *)OBJ_MEMBER_UINT(SELF, biquad_offset_data );
2078 RETURN->v_float = d->m_b0;
2081 //-----------------------------------------------------------------------------
2082 // name: biquad_ctrl_b1()
2083 // desc: CTRL function ...
2084 //-----------------------------------------------------------------------------
2085 CK_DLL_CTRL( biquad_ctrl_b1 )
2087 biquad_data * d = (biquad_data *)OBJ_MEMBER_UINT(SELF, biquad_offset_data );
2088 d->m_b1 = (SAMPLE)GET_CK_FLOAT(ARGS);
2089 RETURN->v_float = d->m_b1;
2092 //-----------------------------------------------------------------------------
2093 // name: biquad_cget_b1()
2094 // desc: CGET function ...
2095 //-----------------------------------------------------------------------------
2096 CK_DLL_CTRL( biquad_cget_b1 )
2098 biquad_data * d = (biquad_data *)OBJ_MEMBER_UINT(SELF, biquad_offset_data );
2099 RETURN->v_float = d->m_b1;
2102 //-----------------------------------------------------------------------------
2103 // name: biquad_ctrl_b2()
2104 // desc: CTRL function ...
2105 //-----------------------------------------------------------------------------
2106 CK_DLL_CTRL( biquad_ctrl_b2 )
2108 biquad_data * d = (biquad_data *)OBJ_MEMBER_UINT(SELF, biquad_offset_data );
2109 d->m_b2 = (SAMPLE)GET_CK_FLOAT(ARGS);
2110 RETURN->v_float = d->m_b2;
2113 //-----------------------------------------------------------------------------
2114 // name: biquad_cget_b2()
2115 // desc: CGET function ...
2116 //-----------------------------------------------------------------------------
2117 CK_DLL_CTRL( biquad_cget_b2 )
2119 biquad_data * d = (biquad_data *)OBJ_MEMBER_UINT(SELF, biquad_offset_data );
2120 RETURN->v_float = d->m_b2;
2123 //-----------------------------------------------------------------------------
2124 // name: biquad_ctrl_a0()
2125 // desc: CTRL function ...
2126 //-----------------------------------------------------------------------------
2127 CK_DLL_CTRL( biquad_ctrl_a0 )
2129 biquad_data * d = (biquad_data *)OBJ_MEMBER_UINT(SELF, biquad_offset_data );
2130 d->m_a0 = (SAMPLE)GET_CK_FLOAT(ARGS);
2131 RETURN->v_float = d->m_a0;
2134 //-----------------------------------------------------------------------------
2135 // name: biquad_cget_a0()
2136 // desc: CGET function ...
2137 //-----------------------------------------------------------------------------
2138 CK_DLL_CTRL( biquad_cget_a0 )
2140 biquad_data * d = (biquad_data *)OBJ_MEMBER_UINT(SELF, biquad_offset_data );
2141 RETURN->v_float = d->m_a0;
2144 //-----------------------------------------------------------------------------
2145 // name: biquad_ctrl_a1()
2146 // desc: CTRL function ...
2147 //-----------------------------------------------------------------------------
2148 CK_DLL_CTRL( biquad_ctrl_a1 )
2150 biquad_data * d = (biquad_data *)OBJ_MEMBER_UINT(SELF, biquad_offset_data );
2151 d->m_a1 = (SAMPLE)GET_CK_FLOAT(ARGS);
2152 RETURN->v_float = d->m_a1;
2155 //-----------------------------------------------------------------------------
2156 // name: biquad_cget_a1()
2157 // desc: CGET function ...
2158 //-----------------------------------------------------------------------------
2159 CK_DLL_CTRL( biquad_cget_a1 )
2161 biquad_data * d = (biquad_data *)OBJ_MEMBER_UINT(SELF, biquad_offset_data );
2162 RETURN->v_float = d->m_a1;
2165 //-----------------------------------------------------------------------------
2166 // name: biquad_ctrl_a2()
2167 // desc: CTRL function ...
2168 //-----------------------------------------------------------------------------
2169 CK_DLL_CTRL( biquad_ctrl_a2 )
2171 biquad_data * d = (biquad_data *)OBJ_MEMBER_UINT(SELF, biquad_offset_data );
2172 d->m_a2 = (SAMPLE)GET_CK_FLOAT(ARGS);
2173 RETURN->v_float = d->m_a2;
2176 //-----------------------------------------------------------------------------
2177 // name: biquad_cget_a2()
2178 // desc: CGET function ...
2179 //-----------------------------------------------------------------------------
2180 CK_DLL_CTRL( biquad_cget_a2 )
2182 biquad_data * d = (biquad_data *)OBJ_MEMBER_UINT(SELF, biquad_offset_data );
2183 RETURN->v_float = d->m_a2;
2187 //-----------------------------------------------------------------------------
2188 // name: onepole
2189 // desc: onepole filter
2190 //-----------------------------------------------------------------------------
2193 //-----------------------------------------------------------------------------
2194 // name: onepole_tick()
2195 // desc: TICK function ...
2196 //-----------------------------------------------------------------------------
2197 CK_DLL_TICK( onepole_tick )
2199 biquad_data * d = (biquad_data *)OBJ_MEMBER_UINT(SELF, biquad_offset_data );
2201 d->m_input0 = in;
2202 d->m_output0 = d->m_b0 * d->m_input0 - d->m_a1 * d->m_output1;
2203 d->m_output1 = d->m_output0;
2205 *out = d->m_output0;
2207 return TRUE;
2210 //-----------------------------------------------------------------------------
2211 // name: onepole_ctrl_pole()
2212 // desc: CTRL function ...
2213 //-----------------------------------------------------------------------------
2214 CK_DLL_CTRL( onepole_ctrl_pole )
2216 float f = (float)GET_CK_FLOAT(ARGS);
2217 biquad_data * d = (biquad_data *)OBJ_MEMBER_UINT(SELF, biquad_offset_data );
2219 if( f > 0.0f )
2220 d->m_b0 = 1.0f - f;
2221 else
2222 d->m_b0 = 1.0f + f;
2224 d->m_a0 = -f;
2230 //-----------------------------------------------------------------------------
2231 // name: onezero
2232 // desc: onezero filter
2233 //-----------------------------------------------------------------------------
2235 //-----------------------------------------------------------------------------
2236 // name: onezero_tick()
2237 // desc: TICK function ...
2238 //-----------------------------------------------------------------------------
2239 CK_DLL_TICK( onezero_tick )
2241 biquad_data * d = (biquad_data *)OBJ_MEMBER_UINT(SELF, biquad_offset_data );
2243 d->m_input0 = in;
2244 d->m_output0 = d->m_b1 * d->m_input1 + d->m_b0 * d->m_input0;
2245 d->m_input1 = d->m_input0;
2247 *out = d->m_output0;
2249 return TRUE;
2252 //-----------------------------------------------------------------------------
2253 // name: onezero_ctrl_zero()
2254 // desc: CTRL function ...
2255 //-----------------------------------------------------------------------------
2256 CK_DLL_CTRL( onezero_ctrl_zero )
2258 float f = (float)GET_CK_FLOAT(ARGS);
2259 biquad_data * d = (biquad_data *)OBJ_MEMBER_UINT(SELF, biquad_offset_data );
2261 if( f > 0.0f )
2262 d->m_b0 = 1.0f / ( 1.0f + f );
2263 else
2264 d->m_b0 = 1.0f / ( 1.0f - f );
2266 d->m_b1 = -f * d->m_b0;
2272 //-----------------------------------------------------------------------------
2273 // name: twopole
2274 // desc: twopole filter
2275 //-----------------------------------------------------------------------------
2277 //-----------------------------------------------------------------------------
2278 // name: twopole_tick()
2279 // desc: TICK function ...
2280 //-----------------------------------------------------------------------------
2281 CK_DLL_TICK( twopole_tick )
2283 biquad_data * d = (biquad_data *)OBJ_MEMBER_UINT(SELF, biquad_offset_data );
2285 d->m_input0 = in;
2286 d->m_output0 = d->m_b0 * d->m_input0 - d->m_a2 * d->m_output2 - d->m_a1 * d->m_output1;
2287 d->m_output2 = d->m_output1;
2288 d->m_output1 = d->m_output0;
2290 *out = d->m_output0;
2292 return TRUE;
2295 //-----------------------------------------------------------------------------
2296 // name: twopole_ctrl_freq()
2297 // desc: CTRL function ...
2298 //-----------------------------------------------------------------------------
2299 CK_DLL_CTRL( twopole_ctrl_freq )
2301 biquad_data * d = (biquad_data *)OBJ_MEMBER_UINT(SELF, biquad_offset_data );
2302 d->pfreq = (float)GET_CK_FLOAT(ARGS);
2303 biquad_set_reson( d );
2305 if( d->norm )
2307 // Normalize the filter gain ... not terribly efficient.
2308 double real = 1.0 - d->prad + (d->m_a2 - d->prad) * cos( 2.0 * ONE_PI * d->pfreq / d->srate );
2309 double imag = (d->m_a2 - d->prad) * sin( 2.0 * ONE_PI * d->pfreq / d->srate );
2310 d->m_b0 = sqrt( real*real + imag*imag );
2314 //-----------------------------------------------------------------------------
2315 // name: twopole_ctrl_rad()
2316 // desc: CTRL function ...
2317 //-----------------------------------------------------------------------------
2318 CK_DLL_CTRL( twopole_ctrl_rad )
2320 biquad_data * d = (biquad_data *)OBJ_MEMBER_UINT(SELF, biquad_offset_data );
2321 d->prad = (float)GET_CK_FLOAT(ARGS);
2322 biquad_set_reson( d );
2324 if( d->norm )
2326 // Normalize the filter gain ... not terrbly efficient
2327 double real = 1.0 - d->prad + (d->m_a2 - d->prad) * cos( 2.0 * ONE_PI * d->pfreq / d->srate );
2328 double imag = (d->m_a2 - d->prad) * sin( 2.0 * ONE_PI * d->pfreq / d->srate );
2329 d->m_b0 = sqrt( real*real + imag*imag );
2333 //-----------------------------------------------------------------------------
2334 // name: twopole_ctrl_norm()
2335 // desc: CTRL function ...
2336 //-----------------------------------------------------------------------------
2337 CK_DLL_CTRL( twopole_ctrl_norm )
2339 biquad_data * d = (biquad_data *)OBJ_MEMBER_UINT(SELF, biquad_offset_data );
2340 d->norm = *(t_CKBOOL *)ARGS;
2342 if( d->norm )
2344 // Normalize the filter gain ... not terribly efficient
2345 double real = 1.0 - d->prad + (d->m_a2 - d->prad) * cos( 2.0 * ONE_PI * d->pfreq / d->srate );
2346 double imag = (d->m_a2 - d->prad) * sin( 2.0 * ONE_PI * d->pfreq / d->srate );
2347 d->m_b0 = sqrt( real*real + imag*imag );
2354 //-----------------------------------------------------------------------------
2355 // name: twozero
2356 // desc: twozero filter
2357 //-----------------------------------------------------------------------------
2359 //-----------------------------------------------------------------------------
2360 // name: twozero_tick()
2361 // desc: TICK function ...
2362 //-----------------------------------------------------------------------------
2363 CK_DLL_TICK( twozero_tick )
2365 biquad_data * d = (biquad_data *)OBJ_MEMBER_UINT(SELF, biquad_offset_data );
2367 d->m_input0 = in;
2368 d->m_output0 = d->m_b0 * d->m_input0 + d->m_b1 * d->m_input1 + d->m_b2 * d->m_input2;
2369 d->m_input2 = d->m_input1;
2370 d->m_input1 = d->m_input0;
2372 *out = d->m_output0;
2374 return TRUE;
2377 //-----------------------------------------------------------------------------
2378 // name: twozero_ctrl_freq()
2379 // desc: CTRL function ...
2380 //-----------------------------------------------------------------------------
2381 CK_DLL_CTRL( twozero_ctrl_freq )
2383 biquad_data * d = (biquad_data *)OBJ_MEMBER_UINT(SELF, biquad_offset_data );
2384 d->zfreq = (float)GET_CK_FLOAT(ARGS);
2385 biquad_set_notch( d );
2387 // normalize the filter gain
2388 if( d->m_b1 > 0.0f )
2389 d->m_b0 = 1.0f / (1.0f+d->m_b1+d->m_b2);
2390 else
2391 d->m_b0 = 1.0f / (1.0f-d->m_b1+d->m_b2);
2392 d->m_b1 *= d->m_b0;
2393 d->m_b2 *= d->m_b0;
2396 //-----------------------------------------------------------------------------
2397 // name: twozero_ctrl_rad()
2398 // desc: CTRL function ...
2399 //-----------------------------------------------------------------------------
2400 CK_DLL_CTRL( twozero_ctrl_rad )
2402 biquad_data * d = (biquad_data *)OBJ_MEMBER_UINT(SELF, biquad_offset_data );
2403 d->zrad = (float)GET_CK_FLOAT(ARGS);
2404 biquad_set_notch( d );
2406 // normalize the filter gain
2407 if( d->m_b1 > 0.0f )
2408 d->m_b0 = 1.0f / (1.0f+d->m_b1+d->m_b2);
2409 else
2410 d->m_b0 = 1.0f / (1.0f-d->m_b1+d->m_b2);
2411 d->m_b1 *= d->m_b0;
2412 d->m_b2 *= d->m_b0;
2418 //-----------------------------------------------------------------------------
2419 // name: gQ
2420 // desc: gQ filter - a la Dan Trueman
2421 //-----------------------------------------------------------------------------
2423 //-----------------------------------------------------------------------------
2424 // name: gQ_tick()
2425 // desc: TICK function ...
2426 //-----------------------------------------------------------------------------
2427 CK_DLL_TICK( gQ_tick )
2429 return TRUE;
2432 //-----------------------------------------------------------------------------
2433 // name: gQ_ctrl_freq()
2434 // desc: CTRL function ...
2435 //-----------------------------------------------------------------------------
2436 CK_DLL_CTRL( gQ_ctrl_freq )
2440 //-----------------------------------------------------------------------------
2441 // name: gQ_ctrl_rad()
2442 // desc: CTRL function ...
2443 //-----------------------------------------------------------------------------
2444 CK_DLL_CTRL( gQ_ctrl_rad )
2453 //-----------------------------------------------------------------------------
2454 // name: allpass
2455 // desc: allpass filter
2456 //-----------------------------------------------------------------------------
2458 //-----------------------------------------------------------------------------
2459 // name: allpass_tick()
2460 // desc: TICK function ...
2461 //-----------------------------------------------------------------------------
2462 CK_DLL_TICK( allpass_tick )
2464 return TRUE;
2467 //-----------------------------------------------------------------------------
2468 // name: allpass_pmsg()
2469 // desc: PMSG function ...
2470 //-----------------------------------------------------------------------------
2471 CK_DLL_PMSG( allpass_pmsg )
2473 return TRUE;
2479 //-----------------------------------------------------------------------------
2480 // name: delay
2481 // desc: ...
2482 //-----------------------------------------------------------------------------
2484 //-----------------------------------------------------------------------------
2485 // name: delay_ctor()
2486 // desc: CTOR function ...
2487 //-----------------------------------------------------------------------------
2488 CK_DLL_CTOR( delay_ctor )
2493 //-----------------------------------------------------------------------------
2494 // name: delay_tick()
2495 // desc: TICK function ...
2496 //-----------------------------------------------------------------------------
2497 CK_DLL_TICK( delay_tick )
2499 return TRUE;
2502 //-----------------------------------------------------------------------------
2503 // name: delay_ctrl_delay()
2504 // desc: CTRL function ...
2505 //-----------------------------------------------------------------------------
2506 CK_DLL_CTRL( delay_ctrl_delay )
2510 //-----------------------------------------------------------------------------
2511 // name: delay_ctrl_max()
2512 // desc: CTRL function ...
2513 //-----------------------------------------------------------------------------
2514 CK_DLL_CTRL( delay_ctrl_max )
2518 //-----------------------------------------------------------------------------
2519 // name: delay_ctrl_tap()
2520 // desc: CTRL function ...
2521 //-----------------------------------------------------------------------------
2522 CK_DLL_CTRL( delay_ctrl_tap )
2526 //-----------------------------------------------------------------------------
2527 // name: delay_ctrl_energy()
2528 // desc: CTRL function ...
2529 //-----------------------------------------------------------------------------
2530 CK_DLL_CTRL( delay_ctrl_energy )
2537 //-----------------------------------------------------------------------------
2538 // name: delayA
2539 // desc: delay - allpass interpolation
2540 //-----------------------------------------------------------------------------
2542 //-----------------------------------------------------------------------------
2543 // name: delayA_ctor()
2544 // desc: CTOR function ...
2545 //-----------------------------------------------------------------------------
2546 CK_DLL_CTOR( delayA_ctor )
2550 //-----------------------------------------------------------------------------
2551 // name: delayA_tick()
2552 // desc: TICK function ...
2553 //-----------------------------------------------------------------------------
2554 CK_DLL_TICK( delayA_tick )
2556 return TRUE;
2559 //-----------------------------------------------------------------------------
2560 // name: delayA_ctrl_delay()
2561 // desc: CTRL function ...
2562 //-----------------------------------------------------------------------------
2563 CK_DLL_CTRL( delayA_ctrl_delay )
2567 //-----------------------------------------------------------------------------
2568 // name: delayA_ctrl_max()
2569 // desc: CTRL function ...
2570 //-----------------------------------------------------------------------------
2571 CK_DLL_CTRL( delayA_ctrl_max )
2576 //-----------------------------------------------------------------------------
2577 // name: delayL
2578 // desc: delay - linear interpolation
2579 //-----------------------------------------------------------------------------
2581 //-----------------------------------------------------------------------------
2582 // name: delayL_ctor()
2583 // desc: CTOR function ...
2584 //-----------------------------------------------------------------------------
2585 CK_DLL_CTOR( delayL_ctor )
2589 //-----------------------------------------------------------------------------
2590 // name: delayL_tick()
2591 // desc: TICK function ...
2592 //-----------------------------------------------------------------------------
2593 CK_DLL_TICK( delayL_tick )
2595 return TRUE;
2598 //-----------------------------------------------------------------------------
2599 // name: delayL_ctrl_delay()
2600 // desc: CTRL function ...
2601 //-----------------------------------------------------------------------------
2602 CK_DLL_CTRL( delayL_ctrl_delay )
2606 //-----------------------------------------------------------------------------
2607 // name: delayL_ctrl_max()
2608 // desc: CTRL function ...
2609 //-----------------------------------------------------------------------------
2610 CK_DLL_CTRL( delayL_ctrl_max )