diff options
author | musil <tmusil@users.sourceforge.net> | 2008-03-05 13:56:25 +0000 |
---|---|---|
committer | musil <tmusil@users.sourceforge.net> | 2008-03-05 13:56:25 +0000 |
commit | 16d6e00d809c28e3597ad1085d12809e2d0f8d89 (patch) | |
tree | ab7f9827768c9ff7088981246efec74e624018a0 /iemlib1 | |
parent | 60fcf9db02c0c555df6ca47421f709a8059a21d1 (diff) |
new peak envelope follower with peak hold time and release time and immediately attack behavior
svn path=/trunk/externals/iemlib/; revision=9533
Diffstat (limited to 'iemlib1')
-rw-r--r-- | iemlib1/src/iemlib1.c | 6 | ||||
-rw-r--r-- | iemlib1/src/makefile_d_fat | 1 | ||||
-rw-r--r-- | iemlib1/src/makefile_d_ppc | 1 | ||||
-rw-r--r-- | iemlib1/src/makefile_darwin | 1 | ||||
-rw-r--r-- | iemlib1/src/makefile_linux | 3 | ||||
-rw-r--r-- | iemlib1/src/makefile_win | 1 | ||||
-rw-r--r-- | iemlib1/src/peakenv_hold~.c | 121 |
7 files changed, 131 insertions, 3 deletions
diff --git a/iemlib1/src/iemlib1.c b/iemlib1/src/iemlib1.c index e8e7bb9..f7123d2 100644 --- a/iemlib1/src/iemlib1.c +++ b/iemlib1/src/iemlib1.c @@ -1,7 +1,7 @@ /* For information on usage and redistribution, and for a DISCLAIMER OF ALL * WARRANTIES, see the file, "LICENSE.txt," in this distribution. -iemlib1 written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2006 */ +iemlib1 written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2008 */ #include "m_pd.h" @@ -32,6 +32,7 @@ void lp1_t_tilde_setup(void); void mov_avrg_kern_tilde_setup(void); void para_bp2_tilde_setup(void); void peakenv_tilde_setup(void); +void peakenv_hold_tilde_setup(void); void prvu_tilde_setup(void); void pvu_tilde_setup(void); void rvu_tilde_setup(void); @@ -64,6 +65,7 @@ void iemlib1_setup(void) mov_avrg_kern_tilde_setup(); para_bp2_tilde_setup(); peakenv_tilde_setup(); + peakenv_hold_tilde_setup(); prvu_tilde_setup(); pvu_tilde_setup(); rvu_tilde_setup(); @@ -73,6 +75,6 @@ void iemlib1_setup(void) v2db_setup(); vcf_filter_tilde_setup(); - post("iemlib1 (R-1.17) library loaded! (c) Thomas Musil 11.2006"); + post("iemlib1 (R-1.17) library loaded! (c) Thomas Musil 03.2008"); post(" musil%ciem.at iem KUG Graz Austria", '@'); } diff --git a/iemlib1/src/makefile_d_fat b/iemlib1/src/makefile_d_fat index 7180455..38af12a 100644 --- a/iemlib1/src/makefile_d_fat +++ b/iemlib1/src/makefile_d_fat @@ -29,6 +29,7 @@ SRC = biquad_freq_resp.c \ mov_avrg_kern~.c \ para_bp2~.c \ peakenv~.c \ + peakenv_hold~.c \ prvu~.c \ pvu~.c \ rvu~.c \ diff --git a/iemlib1/src/makefile_d_ppc b/iemlib1/src/makefile_d_ppc index 633bcca..a90c68b 100644 --- a/iemlib1/src/makefile_d_ppc +++ b/iemlib1/src/makefile_d_ppc @@ -29,6 +29,7 @@ SRC = biquad_freq_resp.c \ mov_avrg_kern~.c \ para_bp2~.c \ peakenv~.c \ + peakenv_hold~.c \ prvu~.c \ pvu~.c \ rvu~.c \ diff --git a/iemlib1/src/makefile_darwin b/iemlib1/src/makefile_darwin index 6837f94..11e7d68 100644 --- a/iemlib1/src/makefile_darwin +++ b/iemlib1/src/makefile_darwin @@ -34,6 +34,7 @@ SRC = biquad_freq_resp.c \ mov_avrg_kern~.c \ para_bp2~.c \ peakenv~.c \ + peakenv_hold~.c \ prvu~.c \ pvu~.c \ rvu~.c \ diff --git a/iemlib1/src/makefile_linux b/iemlib1/src/makefile_linux index 7f3881f..6448376 100644 --- a/iemlib1/src/makefile_linux +++ b/iemlib1/src/makefile_linux @@ -11,7 +11,7 @@ LIB = -ldl -lm -lpthread CFLAGS = -DPD -DUNIX -W -Werror -Wno-unused \ -Wno-parentheses -Wno-switch -O6 -funroll-loops -fomit-frame-pointer -fno-strict-aliasing \ - -DDL_OPEN + -DDL_OPEN -fPIC SYSTEM = $(shell uname -m) @@ -33,6 +33,7 @@ SRC = biquad_freq_resp.c \ mov_avrg_kern~.c \ para_bp2~.c \ peakenv~.c \ + peakenv_hold~.c \ prvu~.c \ pvu~.c \ rvu~.c \ diff --git a/iemlib1/src/makefile_win b/iemlib1/src/makefile_win index 2e5cb7c..cdd4f0f 100644 --- a/iemlib1/src/makefile_win +++ b/iemlib1/src/makefile_win @@ -33,6 +33,7 @@ SRC = biquad_freq_resp.c \ mov_avrg_kern~.c \ para_bp2~.c \ peakenv~.c \ + peakenv_hold~.c \ prvu~.c \ pvu~.c \ rvu~.c \ diff --git a/iemlib1/src/peakenv_hold~.c b/iemlib1/src/peakenv_hold~.c new file mode 100644 index 0000000..9019527 --- /dev/null +++ b/iemlib1/src/peakenv_hold~.c @@ -0,0 +1,121 @@ +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL +* WARRANTIES, see the file, "LICENSE.txt," in this distribution. + +iemlib1 written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2008 */ + + +#include "m_pd.h" +#include "iemlib.h" +#include <math.h> + +/* ---------------- peakenv_hold~ - simple peak-envelope-converter with peak hold time and release time. ----------------- */ + +typedef struct _peakenv_hold_tilde +{ + t_object x_obj; + t_float x_sr; + t_float x_old_peak; + t_float x_c1; + t_float x_releasetime; + t_float x_holdtime; + t_int x_n_hold; + t_int x_counter; + t_float x_msi; +} t_peakenv_hold_tilde; + +static t_class *peakenv_hold_tilde_class; + +static void peakenv_hold_tilde_reset(t_peakenv_hold_tilde *x) +{ + x->x_old_peak = 0.0f; +} + +static void peakenv_hold_tilde_ft1(t_peakenv_hold_tilde *x, t_float t_hold)/* hold-time in ms */ +{ + double dhold; + + if(t_hold < 0.0f) + t_hold = 0.0f; + x->x_holdtime = t_hold; + dhold = (double)x->x_sr*(double)0.001*(double)x->x_holdtime; + if(dhold > 2147483647.0) + dhold = 2147483647.0; + x->x_n_hold = (t_int)(dhold + (double)0.5); +} + +static void peakenv_hold_tilde_ft2(t_peakenv_hold_tilde *x, t_float t_rel)/* release-time in ms */ +{ + if(t_rel < 0.0f) + t_rel = 0.0f; + x->x_releasetime = t_rel; + x->x_c1 = exp(-1.0/(x->x_sr*0.001*x->x_releasetime)); +} + +static t_int *peakenv_hold_tilde_perform(t_int *w) +{ + t_float *in = (t_float *)(w[1]); + t_float *out = (t_float *)(w[2]); + t_peakenv_hold_tilde *x = (t_peakenv_hold_tilde *)(w[3]); + int n = (int)(w[4]); + t_float peak = x->x_old_peak; + t_float c1 = x->x_c1; + t_float absolute; + t_int i, counter; + + counter = x->x_counter; + for(i=0; i<n; i++) + { + absolute = fabs(*in++); + if(counter > 0) + counter--;// hold peride + else + peak *= c1;// release periode + if(absolute > peak) + { + peak = absolute; + counter = x->x_n_hold;// new hold initialisation + } + *out++ = peak; + } + /* NAN protect */ + if(IEM_DENORMAL(peak)) + peak = 0.0f; + x->x_old_peak = peak; + x->x_counter = counter; + return(w+5); +} + +static void peakenv_hold_tilde_dsp(t_peakenv_hold_tilde *x, t_signal **sp) +{ + x->x_sr = (t_float)sp[0]->s_sr; + peakenv_hold_tilde_ft1(x, x->x_holdtime); + peakenv_hold_tilde_ft2(x, x->x_releasetime); + dsp_add(peakenv_hold_tilde_perform, 4, sp[0]->s_vec, sp[1]->s_vec, x, sp[0]->s_n); +} + +static void *peakenv_hold_tilde_new(t_float t_hold, t_float t_rel) +{ + t_peakenv_hold_tilde *x = (t_peakenv_hold_tilde *)pd_new(peakenv_hold_tilde_class); + + x->x_sr = 44100.0f; + peakenv_hold_tilde_ft1(x, t_hold); + peakenv_hold_tilde_ft2(x, t_rel); + x->x_old_peak = 0.0f; + x->x_counter = 0; + inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("ft1")); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("ft2")); + outlet_new(&x->x_obj, &s_signal); + x->x_msi = 0; + return(x); +} + +void peakenv_hold_tilde_setup(void) +{ + peakenv_hold_tilde_class = class_new(gensym("peakenv_hold~"), (t_newmethod)peakenv_hold_tilde_new, + 0, sizeof(t_peakenv_hold_tilde), 0, A_DEFFLOAT, A_DEFFLOAT, 0); + CLASS_MAINSIGNALIN(peakenv_hold_tilde_class, t_peakenv_hold_tilde, x_msi); + class_addmethod(peakenv_hold_tilde_class, (t_method)peakenv_hold_tilde_dsp, gensym("dsp"), 0); + class_addmethod(peakenv_hold_tilde_class, (t_method)peakenv_hold_tilde_ft1, gensym("ft1"), A_FLOAT, 0); + class_addmethod(peakenv_hold_tilde_class, (t_method)peakenv_hold_tilde_ft2, gensym("ft2"), A_FLOAT, 0); + class_addmethod(peakenv_hold_tilde_class, (t_method)peakenv_hold_tilde_reset, gensym("reset"), 0); +} |