From 08596048cf2b13cfba6d7fabe5ad5604875d9a45 Mon Sep 17 00:00:00 2001 From: Ed Kelly Date: Thu, 1 Dec 2005 11:22:08 +0000 Subject: This commit was generated by cvs2svn to compensate for changes in r4096, which included commits to RCS files with non-trunk default branches. svn path=/trunk/; revision=4097 --- externals/build/src/lpreson~.c | 131 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 externals/build/src/lpreson~.c (limited to 'externals/build/src/lpreson~.c') diff --git a/externals/build/src/lpreson~.c b/externals/build/src/lpreson~.c new file mode 100644 index 00000000..c89a8e56 --- /dev/null +++ b/externals/build/src/lpreson~.c @@ -0,0 +1,131 @@ +/* Lattice IIR filter from PARCOR coefficients + * Copyright (C) 2005 Nicolas Chetry + * and Edward Kelly + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "m_pd.h" + +static t_class *lpreson_tilde_class; + +typedef struct _lpreson_control +{ + t_float *c_residual, *c_output; + t_atom *x_parcors; + /* t_atom x_parc_interp_one[MAXPOLES]; + t_int x_parc_ord_one; + t_atom x_parc_interp_two[MAXPOLES]; + t_int x_parc_ord_two; */ +} t_lpreson_control; + +typedef struct _lpreson_tilde +{ + t_object x_obj; + t_float f_dummy; + t_int x_order; + t_lpreson_control x_ctl; +} t_lpreson_tilde; + +t_int *lpreson_tilde_perform(t_int *w) +{ + t_object x_obj; + t_lpreson_tilde *x = (t_lpreson_tilde *)(w[1]); + t_lpreson_control *ctl = (t_lpreson_control *)(w[2]); + int n = (int)(w[3]); + t_float *in = ctl->c_residual; + t_float *out = ctl->c_output; + t_int ord = x->x_order; + float mem[ord+1]; +/* + * Do the inverse filtering + * + * 'data_in' : residual signal (length 'len') + * 'data_out' : output frame (length 'len') + * 'coeff' : the parcor coefficients (length 'tap') + * 'lattice_iir' : filter memory - Previously initialised using init_lattice_iir_filter() + * + */ + int k, i; + float sri; + + for (i=0;i<=ord;i++) + { + // SETFLOAT (&schur->x_parcors[i],0); + mem[i] = 0.0; + } + + for (k = 0; k < n; k++ ) + { + /* Synthesis filter - Lattice structure */ + sri = in[k]; + for (i=0; ix_parcors); + sri = sri - parcor * mem[ord-1-i]; + mem[ord-i] = mem[ord-1-i] + parcor*sri; + } + out[k] = sri; + mem[0] = sri; + + } /* next k */ + return(w+4); +} + +static void lpreson_tilde_list(t_lpreson_tilde *x, t_symbol *s, int argc, t_atom *argv) +{ + if (argc) + { + // x->x_ctl.parc_interp_two = copybytes(x->x_ctl.parc_interp_one, x->x_ctl.parc_ord_one * sizeof(t_atom)); + // x->x_ctl.parc_ord_two = x->x_ctl.parc_ord_one; + // x->x_ctl.parc_interp_one = copybytes(x->x_ctl.parcors, x->x_order * sizeof(t_atom)); + // x->x_ctl.parc_ord_one = x->x_order; + freebytes(x->x_ctl.x_parcors, x->x_order * sizeof(t_atom)); + } + + x->x_ctl.x_parcors = copybytes(argv, argc * sizeof(t_atom)); + x->x_order = argc; +} + +void *lpreson_tilde_dsp(t_lpreson_tilde *x, t_signal **sp) +{ + x->x_ctl.c_residual = sp[0]->s_vec; + x->x_ctl.c_output = sp[1]->s_vec; + dsp_add(lpreson_tilde_perform, 3, x, &x->x_ctl, sp[0]->s_n); + return (void *)x; +} + +void *lpreson_tilde_new(t_floatarg f) +{ + t_lpreson_tilde *x = (t_lpreson_tilde *)pd_new(lpreson_tilde_class); + x->x_order = f >= 1 ? (int)f : 5; + + outlet_new(&x->x_obj, &s_signal); + return (void *)x; +} + +void lpreson_tilde_setup(void) +{ + lpreson_tilde_class = class_new(gensym("lpreson~"), (t_newmethod)lpreson_tilde_new, 0, sizeof(t_lpreson_tilde), CLASS_DEFAULT, A_DEFFLOAT, 0); + + post(". . Lattice IIR filter for lpc. . . . . . ."); + post(". . by Nicolas Chetry . ."); + post(". & Edward Kelly ."); + + class_addmethod(lpreson_tilde_class, (t_method)lpreson_tilde_dsp, gensym("dsp"), 0); +// class_sethelpsymbol(lpreson_tilde_class, gensym("help-lpc~")); + class_addlist(lpreson_tilde_class, lpreson_tilde_list); + class_sethelpsymbol(lpreson_tilde_class, gensym("lpc-cross-synthesis.pd")); + CLASS_MAINSIGNALIN(lpreson_tilde_class, t_lpreson_tilde, f_dummy); +} -- cgit v1.2.1