From 128745865016d5dcfee8441564c4cc13dd82100e Mon Sep 17 00:00:00 2001 From: Ed Kelly Date: Sat, 15 Sep 2012 13:21:23 +0000 Subject: Version 0.1.4 of ekext, gemnotes v0.2.3 svn path=/trunk/externals/ekext/; revision=16234 --- mvcf~.c | 74 +++++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 42 insertions(+), 32 deletions(-) (limited to 'mvcf~.c') diff --git a/mvcf~.c b/mvcf~.c index b745b63..3832ff0 100644 --- a/mvcf~.c +++ b/mvcf~.c @@ -1,9 +1,30 @@ /* * moog vcf, 4-pole lowpass resonant filter * - * (c) Edward Kelly 2012 - * BSD License + * Copyright (c) 2012, Dr Edward Kelly + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * + * provided with the distribution. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + #include "m_pd.h" #include #define _limit 0.95 @@ -13,13 +34,12 @@ static t_class *mvcf_tilde_class; typedef struct _mvcf_tilde { t_object x_obj; t_float b0, b1, b2, b3, b4; //filter buffers to keep (beware denormals!) - t_float token, debug, safety; + t_float token, debug, safety, mode; t_outlet *lp; } t_mvcf_tilde; /* We could have a mode where the fc and res are only registered at the start of the block (quick) or are registered in signal mode (slow) - i.e. a flag */ - static inline float saturate( float input ) { //clamp without branching float x1 = fabsf( input + _limit ); float x2 = fabsf( input - _limit ); @@ -35,21 +55,6 @@ t_int *mvcf_tilde_perform(t_int *w) { t_sample *out = (t_sample *)(w[5]); int n = (int)(w[6]); - //x *b0 = - - /* - q = 1.0f - frequency; - p = frequency + 0.8f * frequency * q; - f = p + p - 1.0f; - q = resonance * (1.0f + 0.5f * q * (1.0f - q + 5.6f * q * q)); - */ - - // while (n--) { - // float f = *(in++); - // setup_svf(obj, *(freq++), *(res++)); - // *(out++) = run_svf(obj, f + ((obj->b) * (*(res++)))); - // } - float t1 = 0; float t2 = 0; float xb0 = x->b0; @@ -89,8 +94,13 @@ t_int *mvcf_tilde_perform(t_int *w) { xb4 = saturate(xb4); xb4 = xb4 - xb4 * xb4 * xb4 * 0.01f; xb0 = i1; - *out++ = xb4; // lowpass mode - // *out++ = i1 - x->b4; // highpass mode + if(x->mode == 0) { + *out++ = xb4; // lowpass mode + } else if (x->mode == 1) { + *out++ = i1 - x->b4; // highpass mode + } else if (x->mode == 2) { + *out++ = xb3 - xb4; + } // Lowpass output: xb4 // Highpass output: in - xb4; // Bandpass output: 3.0f * (b3 - xb4); @@ -101,13 +111,13 @@ t_int *mvcf_tilde_perform(t_int *w) { x->b2 = xb2; x->b3 = xb3; x->b4 = xb4; - if(x->debug != 0) { - x->token +=1; - if(x->token == 15) { - post("q = %f, p=%f, fcoeff=%f, b0=%f, b1=%f, b2=%f, b3=%f, b4=%f",q,p,fcoeff,xb0,xb1,xb2,xb3,xb4); - x->token = 0; - } - } +// if(x->debug != 0) { +// x->token +=1; +// if(x->token == 15) { +// post("q = %f, p=%f, fcoeff=%f, b0=%f, b1=%f, b2=%f, b3=%f, b4=%f",q,p,fcoeff,xb0,xb1,xb2,xb3,xb4); +// x->token = 0; +// } +// } return (w+7); } @@ -119,10 +129,10 @@ void mvcf_tilde_safety(t_mvcf_tilde *x, t_floatarg f) { x->safety = f != 0 ? 1 : 0; } -/*void mvcf_tilde_mode(t_mvcf_tilde *x, t_floatarg f) { +void mvcf_tilde_mode(t_mvcf_tilde *x, t_floatarg f) { x->mode = f < 1 ? 0 : f > 1 ? 2 : 1; } - */ + void mvcf_tilde_clear(t_mvcf_tilde *x) { x->b0 = 0; @@ -145,7 +155,7 @@ void *mvcf_tilde_new(t_floatarg f) { x->b3 = 0; x->b4 = 0; x->token = 0; - x->safety = 1; + x->safety = 0; inlet_new (&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal); inlet_new (&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal); @@ -168,5 +178,5 @@ void mvcf_tilde_setup(void) { class_addmethod(mvcf_tilde_class, (t_method)mvcf_tilde_clear, gensym("clear"), 0); class_addmethod(mvcf_tilde_class, (t_method)mvcf_tilde_debug, gensym("debug"), 0); class_addmethod(mvcf_tilde_class, (t_method)mvcf_tilde_safety, gensym("safe"), 0); - // class_addmethod(mvcf_tilde_class, (t_method)mvcf_tilde_mode, gensym("mode"), A_DEFFLOAT, 0); + class_addmethod(mvcf_tilde_class, (t_method)mvcf_tilde_mode, gensym("mode"), A_DEFFLOAT, 0); } -- cgit v1.2.1