From 569bff52a611e35d7b35fe5f5c5cf1b8de25dbe2 Mon Sep 17 00:00:00 2001 From: Ed Kelly Date: Wed, 21 Sep 2005 12:24:06 +0000 Subject: This commit was generated by cvs2svn to compensate for changes in r3611, which included commits to RCS files with non-trunk default branches. svn path=/trunk/externals/ekext/; revision=3612 --- lpc~/lpc_anal/lpc_test.pd | 53 ++++++ lpc~/lpc_anal/lpc~.c | 203 ++++++++++++++++++++ lpc~/lpc_anal/makefile | 105 +++++++++++ lpc~/lpc_filter/beauty.wav | Bin 0 -> 177644 bytes lpc~/lpc_filter/drummach.wav | Bin 0 -> 211724 bytes lpc~/lpc_filter/lpc-cross-synthesis.pd | 327 +++++++++++++++++++++++++++++++++ lpc~/lpc_filter/lpc_test.pd | 53 ++++++ lpc~/lpc_filter/lpreson~.c | 131 +++++++++++++ lpc~/lpc_filter/makefile | 106 +++++++++++ 9 files changed, 978 insertions(+) create mode 100644 lpc~/lpc_anal/lpc_test.pd create mode 100644 lpc~/lpc_anal/lpc~.c create mode 100644 lpc~/lpc_anal/makefile create mode 100644 lpc~/lpc_filter/beauty.wav create mode 100644 lpc~/lpc_filter/drummach.wav create mode 100644 lpc~/lpc_filter/lpc-cross-synthesis.pd create mode 100644 lpc~/lpc_filter/lpc_test.pd create mode 100644 lpc~/lpc_filter/lpreson~.c create mode 100644 lpc~/lpc_filter/makefile diff --git a/lpc~/lpc_anal/lpc_test.pd b/lpc~/lpc_anal/lpc_test.pd new file mode 100644 index 0000000..7c9faea --- /dev/null +++ b/lpc~/lpc_anal/lpc_test.pd @@ -0,0 +1,53 @@ +#N canvas 0 0 917 300 10; +#X obj 185 160 lpc~ 10; +#N canvas 0 0 450 300 playsound 0; +#X obj 68 74 inlet; +#X obj 163 76 inlet; +#X obj 163 93 openpanel; +#X msg 163 110 read -resize \$1 testfile; +#X obj 26 91 tabplay~ testfile; +#X obj 163 127 soundfiler; +#X obj 163 144 / 44.1; +#X obj 163 161 outlet; +#X obj 26 108 outlet~; +#X obj 99 149 outlet; +#X connect 0 0 4 0; +#X connect 0 0 9 0; +#X connect 1 0 2 0; +#X connect 2 0 3 0; +#X connect 3 0 5 0; +#X connect 4 0 8 0; +#X connect 5 0 6 0; +#X connect 6 0 7 0; +#X restore 185 119 pd playsound; +#N canvas 0 0 450 300 graph1 0; +#X array testfile 1.7683e+06 float 0; +#X coords 0 1 1.7683e+06 -1 200 140 1; +#X restore 516 19 graph; +#X obj 264 104 bng 15 250 50 0 empty empty load 0 -6 0 8 -262144 -1 +-1; +#X obj 185 104 bng 15 250 50 0 empty empty play 0 -6 0 8 -262144 -1 +-1; +#X obj 134 118 metro; +#X obj 134 103 tgl 15 0 empty empty loop 0 -6 0 8 -262144 -1 -1 0 1 +; +#X obj 185 230 dac~; +#X obj 329 37 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1 +; +#X msg 329 68 \; pd dsp \$1; +#X floatatom 242 142 5 1 100 0 poles - -; +#X obj 184 183 lpreson~; +#X obj 185 206 hip~ 18; +#X connect 0 0 11 0; +#X connect 0 1 11 0; +#X connect 1 0 0 0; +#X connect 1 2 5 1; +#X connect 3 0 1 1; +#X connect 4 0 1 0; +#X connect 5 0 1 0; +#X connect 6 0 5 0; +#X connect 8 0 9 0; +#X connect 10 0 0 1; +#X connect 11 0 12 0; +#X connect 12 0 7 0; +#X connect 12 0 7 1; diff --git a/lpc~/lpc_anal/lpc~.c b/lpc~/lpc_anal/lpc~.c new file mode 100644 index 0000000..c9ad667 --- /dev/null +++ b/lpc~/lpc_anal/lpc~.c @@ -0,0 +1,203 @@ +/* Linear Predictive Coding - PARCOR and residual generation + * 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" +#include +#define MAXPOLES 100 + +static t_class *lpc_tilde_class; + +typedef struct _lpc_schur +{ + t_float *c_input, *c_residual; + /* just so we don't get clicks */ + t_atom x_last_parcors[MAXPOLES]; + t_atom x_parcors[MAXPOLES]; +} t_lpc_schur; + +typedef struct _lpc_tilde +{ + t_object x_obj; + t_float f_dummy; + t_float x_order, x_lastorder; + t_outlet *parcor_list; + t_lpc_schur x_schur; +} t_lpc_tilde; + +t_int *lpc_tilde_perform(t_int *w) +{ + t_lpc_tilde *x = (t_lpc_tilde *)(w[1]); + t_lpc_schur *schur = (t_lpc_schur *)(w[2]); + int n = (int)(w[3]); + t_float *in = schur->c_input; + t_float *res = schur->c_residual; +// t_float *parcors = schur->PARCORS; +// t_float *acf = schur->ACF; +// t_float *k = schur->K; +// t_float *p = schur->P; +// t_float *r = schur->r; + t_int ord = (int)x->x_order; + t_int l_ord = (int)x->x_lastorder; +// t_float parcors[ord]; + float acf[ord+1]; + float k[ord+1]; + float p[ord+1]; + float r[ord+1]; + float mem[ord]; + int i, j, bid, y, z; + int g, h; + float tmp, temp, sav, di; + float parcor_1; + for (i=0; ix_parcors[i],0); + mem[i] = 0.0; + } + for (j=0; j<=ord; j++) + { + acf[j] = 0; + for (i=j; ix_parcors[i],0); + } + } + for (i=0; i<=ord; i++) + { + p[i]=acf[i]; + if (i > 0 && i < ord) + { + k[ord+1-i] = acf[i]; + } + } + /* Schurr recursion */ + for (y=1; y<=ord; y++) + { + if (p[0] < fabs (p[1])) + { + for (i=y; i<=ord; i++) + { + r[i] = 0; + } + for (bid=1; bid <=ord; bid++) + { + SETFLOAT (&schur->x_parcors[bid-1],r[bid]); + // x->x_parcors[bid-1] = r[bid]; + } + } + r[y] = fabs(p[1])/p[0]; + + if (p[1] >0) + { + r[y] = -1.*r[y]; + } + if (y==ord) + { + for (bid=1; bid <=ord; bid++) + { + SETFLOAT (&schur->x_parcors[bid-1],r[bid]); + // x->x_parcors[bid-1] = r[bid]; + } + } + p[0] += p[1]*r[y]; + + for (z=1; z <=ord-y; z++) + { + p[z] = p[z+1] + k[ord+1-z]*r[y]; + k[ord+1-z] += p[z+1] * r[y]; + } + } + for (bid=1; bid <=ord; bid++) + { + SETFLOAT (&schur->x_parcors[bid-1],r[bid]); + } + parcor_1 = atom_getfloatarg(0,ord,schur->x_parcors); /* in order to avoid nil coefficients */ + if (parcor_1 > 1e-5 || parcor_1 < -1e-5) + { + outlet_list(x->parcor_list,gensym("list"),ord,schur->x_parcors); + + /* Analysis FIR lattice filtering */ + for (g=0; gx_parcors); + SETFLOAT (&schur->x_last_parcors[i],parcor); + x->x_lastorder = ord; + temp = mem[i] + parcor*di; + di += parcor*mem[i]; + mem[i] = sav; + sav = temp; + } + res[g] = di; + + } /* next g */ + } + else + { + outlet_list(x->parcor_list,gensym("list"),l_ord,schur->x_last_parcors); + for (g=0; gx_schur.c_input = sp[0]->s_vec; + x->x_schur.c_residual = sp[1]->s_vec; + dsp_add(lpc_tilde_perform, 3, x, &x->x_schur, sp[0]->s_n); + return (void *)x; +} + +void *lpc_tilde_new(t_floatarg f) +{ + t_lpc_tilde *x = (t_lpc_tilde *)pd_new(lpc_tilde_class); + x->x_order = f >= 1 ? (int)f : 5; + + floatinlet_new(&x->x_obj,&x->x_order); + outlet_new(&x->x_obj, &s_signal); + x->parcor_list = outlet_new(&x->x_obj, &s_list); + return (void *)x; +} + +void lpc_tilde_setup(void) +{ + lpc_tilde_class = class_new(gensym("lpc~"), (t_newmethod)lpc_tilde_new, 0, sizeof(t_lpc_tilde), CLASS_DEFAULT, A_DEFFLOAT, 0); + + post("\n. . Linear Predictive Coding. . . . . . . ."); + post(". . PARCOR coefficients from input. . . . ."); + post(". . by Nicolas Chetry . ."); + post(". & Edward Kelly ."); + + class_addmethod(lpc_tilde_class, (t_method)lpc_tilde_dsp, gensym("dsp"), 0); +// class_sethelpsymbol(lpc_tilde_class, gensym("help-lpc~")); + class_sethelpsymbol(lpc_tilde_class, gensym("lpc_test")); + CLASS_MAINSIGNALIN(lpc_tilde_class, t_lpc_tilde, f_dummy); +} diff --git a/lpc~/lpc_anal/makefile b/lpc~/lpc_anal/makefile new file mode 100644 index 0000000..c8fce3f --- /dev/null +++ b/lpc~/lpc_anal/makefile @@ -0,0 +1,105 @@ +current: + echo make pd_linux, pd_nt, pd_irix5, pd_irix6 or pd_darwin, then make install + +clean: ; rm -f *.pd_* *.o + +# ----------------------- NT ----------------------- + +pd_nt: lpc~.dll + +INSTALL_PREFIX="C:\pd\extra" +EXT=dll +.SUFFIXES: .obj .dll + +PDNTCFLAGS = /W3 /WX /DNT /DPD /nologo +VC="D:\Program Files\Microsoft Visual Studio\Vc98" + +PDNTINCLUDE = /I. /I\tcl\include /I..\..\src /I$(VC)\include + +PDNTLDIR = $(VC)\lib +PDNTLIB = $(PDNTLDIR)\libc.lib \ + $(PDNTLDIR)\oldnames.lib \ + $(PDNTLDIR)\kernel32.lib \ + ..\..\bin\pd.lib + +.c.dll: + cl $(PDNTCFLAGS) $(PDNTINCLUDE) /c $*.c + link /dll /export:$*_setup $*.obj $(PDNTLIB) + +# ----------------------- IRIX 5.x ----------------------- + +pd_irix5: lpc~.pd_irix5 + +INSTALL_PREFIX=/usr/local +EXT=pd_irix5 +.SUFFIXES: .pd_irix5 + +SGICFLAGS5 = -o32 -DPD -DUNIX -DIRIX -O2 + +SGIINCLUDE = -I/usr/local/include + +.c.pd_irix5: + cc $(SGICFLAGS5) $(SGIINCLUDE) -o $*.o -c $*.c + ld -elf -shared -rdata_shared -o $*.pd_irix5 $*.o + rm $*.o + +# ----------------------- IRIX 5.x ----------------------- + +pd_irix6: lpc~.pd_irix6 + +INSTALL_PREFIX=/usr/local +EXT=pd_irix6 +.SUFFIXES: .pd_irix6 + +SGICFLAGS5 = -o32 -DPD -DUNIX -DIRIX -O2 + +SGIINCLUDE = -I/usr/local/include + +.c.pd_irix6: + cc $(SGICFLAGS5) $(SGIINCLUDE) -o $*.o -c $*.c + ld -elf -shared -rdata_shared -o $*.pd_irix6 $*.o + rm $*.o + +# ----------------------- LINUX i386 ----------------------- + +pd_linux: lpc~.pd_linux + +INSTALL_PREFIX=/usr/local +EXT=pd_linux +.SUFFIXES: .pd_linux + +LINUXCFLAGS = -DPD -O2 -funroll-loops -fomit-frame-pointer \ + -Wall -W -Wshadow -Wstrict-prototypes -Werror \ + -Wno-unused -Wno-parentheses -Wno-switch + +LINUXINCLUDE = -I/usr/local/include + +.c.pd_linux: + cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c + ld -export_dynamic -shared -o $*.pd_linux $*.o -lc -lm + strip --strip-unneeded $*.pd_linux + rm $*.o + +# ----------------------- Mac OSX ----------------------- + +pd_darwin: lpc~.pd_darwin + +INSTALL_PREFIX=/usr/local +EXT=pd_darwin +.SUFFIXES: .pd_darwin + +DARWINCFLAGS = -DPD -O2 -Wall -W -Wshadow -Wstrict-prototypes \ + -Wno-unused -Wno-parentheses -Wno-switch + +.c.pd_darwin: + cc $(DARWINCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c + cc -bundle -undefined suppress -flat_namespace -o $*.pd_darwin $*.o + rm -f $*.o + +# ---------------------------------------------- + +install:: + install -d $(INSTALL_PREFIX)/lib/pd/extra +# install -m 644 *.$(EXT) $(INSTALL_PREFIX)/lib/pd/externs + -install -m 644 lpc~.$(EXT) $(INSTALL_PREFIX)/lib/pd/extra + install -m 644 *.pd $(INSTALL_PREFIX)/lib/pd/doc/5.reference diff --git a/lpc~/lpc_filter/beauty.wav b/lpc~/lpc_filter/beauty.wav new file mode 100644 index 0000000..689b25c Binary files /dev/null and b/lpc~/lpc_filter/beauty.wav differ diff --git a/lpc~/lpc_filter/drummach.wav b/lpc~/lpc_filter/drummach.wav new file mode 100644 index 0000000..cf8cd55 Binary files /dev/null and b/lpc~/lpc_filter/drummach.wav differ diff --git a/lpc~/lpc_filter/lpc-cross-synthesis.pd b/lpc~/lpc_filter/lpc-cross-synthesis.pd new file mode 100644 index 0000000..e49ea4a --- /dev/null +++ b/lpc~/lpc_filter/lpc-cross-synthesis.pd @@ -0,0 +1,327 @@ +#N canvas 87 183 604 300 10; +#X obj 247 210 hsl 121 15 100 10000 0 1 empty empty filter-f -2 -6 +0 8 -225280 -62784 -90133 3409 1; +#X floatatom 244 225 0 0 0 0 - - -; +#X obj 91 218 dac~; +#N canvas 0 0 453 387 lpc-resynth 0; +#X obj 27 199 lpreson~; +#X obj 28 244 hip~ 18; +#X obj 27 49 inlet~; +#X obj 145 64 inlet; +#X obj 202 34 inlet; +#X obj 99 118 inlet~; +#X obj 28 318 outlet~; +#X obj 27 94 hip~ 1000; +#X obj 99 135 hip~ 1000; +#X obj 27 216 lop~ 1000; +#X obj 316 54 inlet; +#X obj 27 111 lpc~ 32; +#X obj 27 152 *~ 1; +#X obj 99 152 *~ 0; +#X obj 202 51 sel 0 1; +#X text 164 280 filter with larger block sizes; +#X text 163 267 lpc~ produces a less glitchy; +#X msg 202 68 1; +#X msg 202 85 0; +#X msg 224 85 1; +#X msg 224 68 0; +#X text 294 23 pre-emphasis/; +#X text 275 36 de-emphasis frequency; +#X text 160 18 select excitation; +#X text 146 48 order; +#X obj 181 248 block~ 1024 2 1; +#X obj 28 284 *~; +#X obj 142 221 tabreceive~ hanning; +#X text 151 296 overlapping windows are essential; +#X text 151 308 otherwise clicks will result; +#X connect 0 0 9 0; +#X connect 1 0 26 0; +#X connect 2 0 7 0; +#X connect 3 0 11 1; +#X connect 4 0 14 0; +#X connect 5 0 8 0; +#X connect 7 0 11 0; +#X connect 8 0 13 0; +#X connect 9 0 1 0; +#X connect 10 0 9 1; +#X connect 10 0 7 1; +#X connect 10 0 8 1; +#X connect 11 0 12 0; +#X connect 11 1 0 0; +#X connect 12 0 0 0; +#X connect 13 0 0 0; +#X connect 14 0 17 0; +#X connect 14 0 18 0; +#X connect 14 1 20 0; +#X connect 14 1 19 0; +#X connect 17 0 12 1; +#X connect 18 0 13 1; +#X connect 19 0 13 1; +#X connect 20 0 12 1; +#X connect 26 0 6 0; +#X connect 27 0 26 1; +#X restore 92 184 pd lpc-resynth; +#N canvas 0 0 450 300 graph2 0; +#X array voice 88800 float 0; +#X coords 0 1 88799 -1 100 70 1; +#X restore 358 49 graph; +#N canvas 0 0 450 300 graph2 0; +#X array sample 105840 float 0; +#X coords 0 1 105839 -1 100 70 1; +#X restore 358 121 graph; +#X obj 75 55 bng 15 250 50 0 empty empty load-voice -38 -6 0 8 -262144 +-1 -1; +#X obj 111 55 bng 15 250 50 0 empty empty sample -10 -6 0 8 -262144 +-1 -1; +#N canvas 0 0 450 300 play 0; +#X obj 82 157 tabplay~ voice; +#X obj 237 157 tabplay~ sample; +#X obj 291 71 inlet; +#X obj 350 71 inlet; +#X obj 52 66 inlet; +#X obj 111 66 inlet; +#X obj 190 140 metro; +#X obj 48 140 metro; +#X obj 84 196 outlet~; +#X obj 238 269 outlet~; +#X obj 410 80 inlet; +#X obj 237 235 *~ 0; +#X connect 0 0 8 0; +#X connect 1 0 11 0; +#X connect 2 0 7 1; +#X connect 3 0 6 1; +#X connect 4 0 0 0; +#X connect 4 0 1 0; +#X connect 5 0 7 0; +#X connect 5 0 6 0; +#X connect 6 0 1 0; +#X connect 7 0 0 0; +#X connect 10 0 11 1; +#X connect 11 0 9 0; +#X restore 73 146 pd play; +#X obj 22 125 bng 15 250 50 0 empty empty play 0 -6 0 8 -262144 -1 +-1; +#X floatatom 195 97 5 1 100 2 order - -; +#X obj 210 142 tgl 15 1 empty empty select-excitation -25 -6 0 8 -262144 +-1 -1 1 1; +#X obj 52 111 tgl 15 0 empty empty loop 0 -6 0 8 -262144 -1 -1 1 1 +; +#N canvas 0 0 450 300 load 0; +#X obj 77 135 soundfiler; +#X obj 77 169 outlet; +#X obj 161 186 soundfiler; +#X obj 161 220 outlet; +#X msg 161 169 read -resize drummach.wav sample; +#X obj 161 101 loadbang; +#X obj 80 84 openpanel; +#X obj 80 27 inlet; +#X msg 8 101 read -resize \$1 voice; +#X msg 218 152 read -resize \$1 sample; +#X obj 77 152 / 44.1; +#X obj 114 47 samplerate~; +#X obj 114 64 / 1000; +#X obj 218 135 openpanel; +#X obj 218 25 inlet; +#X obj 161 203 / 44.1; +#X msg 77 118 read -resize beauty.wav voice; +#X connect 0 0 10 0; +#X connect 2 0 15 0; +#X connect 4 0 2 0; +#X connect 5 0 16 0; +#X connect 5 0 4 0; +#X connect 6 0 8 0; +#X connect 7 0 6 0; +#X connect 7 0 11 0; +#X connect 8 0 0 0; +#X connect 9 0 2 0; +#X connect 10 0 1 0; +#X connect 11 0 12 0; +#X connect 12 0 10 1; +#X connect 12 0 15 1; +#X connect 13 0 9 0; +#X connect 14 0 13 0; +#X connect 14 0 11 0; +#X connect 15 0 3 0; +#X connect 16 0 0 0; +#X restore 75 70 pd load; +#X text 192 70 filter; +#X msg 244 80 32; +#X obj 244 63 loadbang; +#X floatatom 138 84 5 0 100 0 - - -; +#X obj 138 98 dbtorms; +#X text 144 52 V; +#X text 144 45 |; +#X text 144 37 |; +#X text 144 30 |; +#X text 315 224 pre-emphasis/; +#X text 296 237 de-emphasis frequency; +#X msg 222 178 2500; +#X obj 216 161 loadbang; +#X text 36 18 sample level should be lower than for a regular filter +; +#X text 37 4 LPC CROSS SYNTHESIS; +#X text 128 262 (C) Edward Kelly and Nicolas Chetry 2005; +#X msg 138 67 88; +#X msg 472 52 \; pd dsp \$1; +#X obj 472 23 tgl 15 0 empty empty audio_on 0 -6 0 8 -262144 -1 -1 +0 1; +#N canvas 0 0 450 300 graph11 0; +#X array hanning 1024 float 1; +#A 0 0 9.41236e-06 3.76491e-05 8.47091e-05 0.000150591 0.000235291 +0.000338808 0.000461136 0.000602272 0.00076221 0.000940944 0.00113847 +0.00135477 0.00158985 0.00184369 0.00211629 0.00240764 0.00271771 0.00304651 +0.00339403 0.00376023 0.00414512 0.00454868 0.00497089 0.00541175 0.00587122 +0.00634929 0.00684595 0.00736118 0.00789495 0.00844726 0.00901807 0.00960736 +0.0102151 0.0108413 0.0114859 0.0121489 0.0128303 0.01353 0.0142481 +0.0149844 0.015739 0.0165118 0.0173028 0.018112 0.0189393 0.0197847 +0.0206483 0.0215298 0.0224294 0.023347 0.0242825 0.0252359 0.0262072 +0.0271963 0.0282033 0.029228 0.0302704 0.0313305 0.0324082 0.0335036 +0.0346165 0.035747 0.0368949 0.0380602 0.039243 0.0404431 0.0416605 +0.0428951 0.044147 0.045416 0.0467021 0.0480054 0.0493256 0.0506628 +0.0520169 0.0533879 0.0547756 0.0561802 0.0576015 0.0590394 0.0604939 +0.061965 0.0634525 0.0649565 0.0664769 0.0680136 0.0695665 0.0711357 +0.072721 0.0743224 0.0759398 0.0775732 0.0792225 0.0808876 0.0825686 +0.0842652 0.0859775 0.0877054 0.0894487 0.0912076 0.0929818 0.0947714 +0.0965762 0.0983962 0.100231 0.102082 0.103947 0.105827 0.107722 0.109631 +0.111556 0.113495 0.115448 0.117416 0.119399 0.121396 0.123407 0.125432 +0.127471 0.129524 0.131592 0.133673 0.135768 0.137876 0.139999 0.142135 +0.144284 0.146447 0.148623 0.150812 0.153014 0.15523 0.157458 0.159699 +0.161954 0.164221 0.1665 0.168792 0.171097 0.173414 0.175743 0.178084 +0.180438 0.182803 0.185181 0.18757 0.189971 0.192384 0.194809 0.197244 +0.199692 0.20215 0.20462 0.207101 0.209593 0.212096 0.21461 0.217134 +0.219669 0.222215 0.224771 0.227338 0.229914 0.232501 0.235098 0.237705 +0.240322 0.242949 0.245585 0.248231 0.250886 0.253551 0.256225 0.258908 +0.2616 0.264302 0.267012 0.269731 0.272458 0.275194 0.277939 0.280692 +0.283453 0.286222 0.289 0.291785 0.294578 0.297379 0.300188 0.303004 +0.305827 0.308658 0.311496 0.314341 0.317194 0.320052 0.322918 0.325791 +0.32867 0.331555 0.334447 0.337345 0.340249 0.343159 0.346075 0.348997 +0.351925 0.354858 0.357796 0.36074 0.363689 0.366644 0.369603 0.372567 +0.375536 0.37851 0.381488 0.384471 0.387458 0.390449 0.393445 0.396444 +0.399448 0.402455 0.405466 0.40848 0.411498 0.414519 0.417543 0.420571 +0.423601 0.426635 0.429671 0.43271 0.435751 0.438795 0.441841 0.444889 +0.447939 0.450991 0.454046 0.457101 0.460159 0.463218 0.466278 0.46934 +0.472402 0.475466 0.478531 0.481596 0.484663 0.487729 0.490797 0.493864 +0.496932 0.5 0.503068 0.506136 0.509203 0.512271 0.515337 0.518404 +0.521469 0.524534 0.527598 0.53066 0.533722 0.536782 0.539841 0.542899 +0.545954 0.549009 0.552061 0.555111 0.558159 0.561205 0.564249 0.56729 +0.570329 0.573365 0.576399 0.579429 0.582457 0.585481 0.588502 0.59152 +0.594534 0.597545 0.600552 0.603556 0.606555 0.609551 0.612542 0.615529 +0.618512 0.62149 0.624464 0.627433 0.630397 0.633356 0.636311 0.63926 +0.642204 0.645142 0.648075 0.651003 0.653925 0.656841 0.659751 0.662655 +0.665553 0.668445 0.67133 0.674209 0.677082 0.679947 0.682806 0.685659 +0.688504 0.691342 0.694173 0.696996 0.699812 0.702621 0.705422 0.708215 +0.711 0.713778 0.716547 0.719308 0.722061 0.724806 0.727542 0.730269 +0.732988 0.735698 0.7384 0.741092 0.743775 0.746449 0.749114 0.751769 +0.754415 0.757051 0.759678 0.762295 0.764902 0.767499 0.770086 0.772663 +0.775229 0.777785 0.780331 0.782866 0.78539 0.787904 0.790407 0.792899 +0.79538 0.79785 0.800308 0.802756 0.805191 0.807616 0.810029 0.81243 +0.814819 0.817197 0.819562 0.821916 0.824257 0.826586 0.828903 0.831208 +0.8335 0.835779 0.838046 0.840301 0.842542 0.84477 0.846986 0.849188 +0.851377 0.853553 0.855716 0.857865 0.860001 0.862124 0.864232 0.866327 +0.868408 0.870476 0.872529 0.874568 0.876593 0.878604 0.880601 0.882584 +0.884552 0.886505 0.888444 0.890369 0.892278 0.894173 0.896053 0.897918 +0.899769 0.901604 0.903424 0.905229 0.907018 0.908792 0.910551 0.912295 +0.914023 0.915735 0.917431 0.919112 0.920777 0.922427 0.92406 0.925678 +0.927279 0.928864 0.930433 0.931986 0.933523 0.935044 0.936548 0.938035 +0.939506 0.940961 0.942399 0.94382 0.945224 0.946612 0.947983 0.949337 +0.950674 0.951995 0.953298 0.954584 0.955853 0.957105 0.95834 0.959557 +0.960757 0.96194 0.963105 0.964253 0.965383 0.966496 0.967592 0.96867 +0.96973 0.970772 0.971797 0.972804 0.973793 0.974764 0.975717 0.976653 +0.977571 0.97847 0.979352 0.980215 0.981061 0.981888 0.982697 0.983488 +0.984261 0.985016 0.985752 0.98647 0.98717 0.987851 0.988514 0.989159 +0.989785 0.990393 0.990982 0.991553 0.992105 0.992639 0.993154 0.993651 +0.994129 0.994588 0.995029 0.995451 0.995855 0.99624 0.996606 0.996953 +0.997282 0.997592 0.997884 0.998156 0.99841 0.998645 0.998862 0.999059 +0.999238 0.999398 0.999539 0.999661 0.999765 0.999849 0.999915 0.999962 +0.999991 1 0.999991 0.999962 0.999915 0.999849 0.999765 0.999661 0.999539 +0.999398 0.999238 0.999059 0.998862 0.998645 0.99841 0.998156 0.997884 +0.997592 0.997282 0.996953 0.996606 0.99624 0.995855 0.995451 0.995029 +0.994588 0.994129 0.993651 0.993154 0.992639 0.992105 0.991553 0.990982 +0.990393 0.989785 0.989159 0.988514 0.987851 0.98717 0.98647 0.985752 +0.985016 0.984261 0.983488 0.982697 0.981888 0.981061 0.980215 0.979352 +0.97847 0.977571 0.976653 0.975717 0.974764 0.973793 0.972804 0.971797 +0.970772 0.96973 0.96867 0.967592 0.966496 0.965383 0.964253 0.963105 +0.96194 0.960757 0.959557 0.95834 0.957105 0.955853 0.954584 0.953298 +0.951995 0.950674 0.949337 0.947983 0.946612 0.945224 0.94382 0.942399 +0.940961 0.939506 0.938035 0.936548 0.935044 0.933523 0.931986 0.930433 +0.928864 0.927279 0.925678 0.92406 0.922427 0.920777 0.919112 0.917431 +0.915735 0.914023 0.912295 0.910551 0.908792 0.907018 0.905229 0.903424 +0.901604 0.899769 0.897918 0.896053 0.894173 0.892278 0.890369 0.888444 +0.886505 0.884552 0.882584 0.880601 0.878604 0.876593 0.874568 0.872529 +0.870476 0.868408 0.866327 0.864232 0.862124 0.860001 0.857865 0.855716 +0.853553 0.851377 0.849188 0.846986 0.84477 0.842542 0.840301 0.838046 +0.835779 0.8335 0.831208 0.828903 0.826586 0.824257 0.821916 0.819562 +0.817197 0.814819 0.81243 0.810029 0.807616 0.805191 0.802756 0.800308 +0.79785 0.79538 0.792899 0.790407 0.787904 0.78539 0.782866 0.780331 +0.777785 0.775229 0.772663 0.770086 0.767499 0.764902 0.762295 0.759678 +0.757051 0.754415 0.751769 0.749114 0.746449 0.743775 0.741092 0.7384 +0.735698 0.732988 0.730269 0.727542 0.724806 0.722061 0.719308 0.716547 +0.713778 0.711 0.708215 0.705422 0.702621 0.699812 0.696996 0.694173 +0.691342 0.688504 0.685659 0.682806 0.679947 0.677082 0.674209 0.67133 +0.668445 0.665553 0.662655 0.659751 0.656841 0.653925 0.651003 0.648075 +0.645142 0.642204 0.63926 0.636311 0.633356 0.630397 0.627433 0.624464 +0.62149 0.618512 0.615529 0.612542 0.609551 0.606555 0.603556 0.600552 +0.597545 0.594534 0.59152 0.588502 0.585481 0.582457 0.579429 0.576399 +0.573365 0.570329 0.56729 0.564249 0.561205 0.558159 0.555111 0.552061 +0.549009 0.545954 0.542899 0.539841 0.536782 0.533722 0.53066 0.527598 +0.524534 0.521469 0.518404 0.515337 0.512271 0.509203 0.506136 0.503068 +0.5 0.496932 0.493864 0.490797 0.487729 0.484663 0.481596 0.478531 +0.475466 0.472402 0.46934 0.466278 0.463218 0.460159 0.457101 0.454046 +0.450991 0.447939 0.444889 0.441841 0.438795 0.435751 0.43271 0.429671 +0.426635 0.423601 0.420571 0.417543 0.414519 0.411498 0.40848 0.405466 +0.402455 0.399448 0.396444 0.393445 0.390449 0.387458 0.384471 0.381488 +0.37851 0.375536 0.372567 0.369603 0.366644 0.363689 0.36074 0.357796 +0.354858 0.351925 0.348997 0.346075 0.343159 0.340249 0.337345 0.334447 +0.331555 0.32867 0.325791 0.322918 0.320052 0.317194 0.314341 0.311496 +0.308658 0.305827 0.303004 0.300188 0.297379 0.294578 0.291785 0.289 +0.286222 0.283453 0.280692 0.277939 0.275194 0.272458 0.269731 0.267012 +0.264302 0.2616 0.258908 0.256225 0.253551 0.250886 0.248231 0.245585 +0.242949 0.240322 0.237705 0.235098 0.232501 0.229914 0.227338 0.224771 +0.222215 0.219669 0.217134 0.21461 0.212096 0.209593 0.207101 0.20462 +0.20215 0.199692 0.197244 0.194809 0.192384 0.189971 0.18757 0.185181 +0.182803 0.180438 0.178084 0.175743 0.173414 0.171097 0.168792 0.1665 +0.164221 0.161954 0.159699 0.157458 0.15523 0.153014 0.150812 0.148623 +0.146447 0.144284 0.142135 0.139999 0.137876 0.135768 0.133673 0.131592 +0.129524 0.127471 0.125432 0.123407 0.121396 0.119399 0.117416 0.115448 +0.113495 0.111556 0.109631 0.107722 0.105827 0.103947 0.102082 0.100231 +0.0983962 0.0965762 0.0947714 0.0929818 0.0912076 0.0894487 0.0877054 +0.0859775 0.0842652 0.0825686 0.0808876 0.0792225 0.0775732 0.0759398 +0.0743224 0.072721 0.0711357 0.0695665 0.0680136 0.0664769 0.0649565 +0.0634525 0.061965 0.0604939 0.0590394 0.0576015 0.0561802 0.0547756 +0.0533879 0.0520169 0.0506628 0.0493256 0.0480054 0.0467021 0.045416 +0.044147 0.0428951 0.0416605 0.0404431 0.039243 0.0380602 0.0368949 +0.035747 0.0346165 0.0335036 0.0324082 0.0313305 0.0302704 0.029228 +0.0282033 0.0271963 0.0262072 0.0252359 0.0242825 0.023347 0.0224294 +0.0215298 0.0206483 0.0197847 0.0189393 0.018112 0.0173028 0.0165118 +0.015739 0.0149844 0.0142481 0.01353 0.0128303 0.0121489 0.0114859 +0.0108413 0.0102151 0.00960736 0.00901807 0.00844726 0.00789495 0.00736118 +0.00684595 0.00634929 0.00587122; +#A 1000 0.00541175 0.00497089 0.00454868 0.00414512 0.00376023 0.00339403 +0.00304651 0.00271771 0.00240764 0.00211629 0.00184369 0.00158985 0.00135477 +0.00113847 0.000940944 0.00076221 0.000602272 0.000461136 0.000338808 +0.000235291 0.000150591 8.47091e-05 3.76491e-05 9.41236e-06; +#X coords 0 1 1023 0 100 70 1; +#X restore 478 154 graph; +#X connect 0 0 1 0; +#X connect 1 0 3 4; +#X connect 3 0 2 0; +#X connect 3 0 2 1; +#X connect 6 0 13 0; +#X connect 7 0 13 1; +#X connect 8 0 3 0; +#X connect 8 1 3 1; +#X connect 9 0 8 0; +#X connect 10 0 3 2; +#X connect 11 0 3 3; +#X connect 12 0 8 1; +#X connect 13 0 8 2; +#X connect 13 1 8 3; +#X connect 15 0 10 0; +#X connect 16 0 15 0; +#X connect 16 0 30 0; +#X connect 17 0 18 0; +#X connect 18 0 8 4; +#X connect 25 0 0 0; +#X connect 26 0 25 0; +#X connect 30 0 17 0; +#X connect 32 0 31 0; diff --git a/lpc~/lpc_filter/lpc_test.pd b/lpc~/lpc_filter/lpc_test.pd new file mode 100644 index 0000000..7c9faea --- /dev/null +++ b/lpc~/lpc_filter/lpc_test.pd @@ -0,0 +1,53 @@ +#N canvas 0 0 917 300 10; +#X obj 185 160 lpc~ 10; +#N canvas 0 0 450 300 playsound 0; +#X obj 68 74 inlet; +#X obj 163 76 inlet; +#X obj 163 93 openpanel; +#X msg 163 110 read -resize \$1 testfile; +#X obj 26 91 tabplay~ testfile; +#X obj 163 127 soundfiler; +#X obj 163 144 / 44.1; +#X obj 163 161 outlet; +#X obj 26 108 outlet~; +#X obj 99 149 outlet; +#X connect 0 0 4 0; +#X connect 0 0 9 0; +#X connect 1 0 2 0; +#X connect 2 0 3 0; +#X connect 3 0 5 0; +#X connect 4 0 8 0; +#X connect 5 0 6 0; +#X connect 6 0 7 0; +#X restore 185 119 pd playsound; +#N canvas 0 0 450 300 graph1 0; +#X array testfile 1.7683e+06 float 0; +#X coords 0 1 1.7683e+06 -1 200 140 1; +#X restore 516 19 graph; +#X obj 264 104 bng 15 250 50 0 empty empty load 0 -6 0 8 -262144 -1 +-1; +#X obj 185 104 bng 15 250 50 0 empty empty play 0 -6 0 8 -262144 -1 +-1; +#X obj 134 118 metro; +#X obj 134 103 tgl 15 0 empty empty loop 0 -6 0 8 -262144 -1 -1 0 1 +; +#X obj 185 230 dac~; +#X obj 329 37 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1 +; +#X msg 329 68 \; pd dsp \$1; +#X floatatom 242 142 5 1 100 0 poles - -; +#X obj 184 183 lpreson~; +#X obj 185 206 hip~ 18; +#X connect 0 0 11 0; +#X connect 0 1 11 0; +#X connect 1 0 0 0; +#X connect 1 2 5 1; +#X connect 3 0 1 1; +#X connect 4 0 1 0; +#X connect 5 0 1 0; +#X connect 6 0 5 0; +#X connect 8 0 9 0; +#X connect 10 0 0 1; +#X connect 11 0 12 0; +#X connect 12 0 7 0; +#X connect 12 0 7 1; diff --git a/lpc~/lpc_filter/lpreson~.c b/lpc~/lpc_filter/lpreson~.c new file mode 100644 index 0000000..c89a8e5 --- /dev/null +++ b/lpc~/lpc_filter/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); +} diff --git a/lpc~/lpc_filter/makefile b/lpc~/lpc_filter/makefile new file mode 100644 index 0000000..23840c6 --- /dev/null +++ b/lpc~/lpc_filter/makefile @@ -0,0 +1,106 @@ +current: + echo make pd_linux, pd_nt, pd_irix5, pd_irix6 or pd_darwin, then make install + +clean: ; rm -f *.pd_* *.o + +# ----------------------- NT ----------------------- + +pd_nt: lpreson~.dll + +INSTALL_PREFIX="C:\pd\extra" +EXT=dll +.SUFFIXES: .obj .dll + +PDNTCFLAGS = /W3 /WX /DNT /DPD /nologo +VC="D:\Program Files\Microsoft Visual Studio\Vc98" + +PDNTINCLUDE = /I. /I\tcl\include /I..\..\src /I$(VC)\include + +PDNTLDIR = $(VC)\lib +PDNTLIB = $(PDNTLDIR)\libc.lib \ + $(PDNTLDIR)\oldnames.lib \ + $(PDNTLDIR)\kernel32.lib \ + ..\..\bin\pd.lib + +.c.dll: + cl $(PDNTCFLAGS) $(PDNTINCLUDE) /c $*.c + link /dll /export:$*_setup $*.obj $(PDNTLIB) + +# ----------------------- IRIX 5.x ----------------------- + +pd_irix5: lpreson~.pd_irix5 + +INSTALL_PREFIX=/usr/local +EXT=pd_irix5 +.SUFFIXES: .pd_irix5 + +SGICFLAGS5 = -o32 -DPD -DUNIX -DIRIX -O2 + +SGIINCLUDE = -I/usr/local/include + +.c.pd_irix5: + cc $(SGICFLAGS5) $(SGIINCLUDE) -o $*.o -c $*.c + ld -elf -shared -rdata_shared -o $*.pd_irix5 $*.o + rm $*.o + +# ----------------------- IRIX 5.x ----------------------- + +pd_irix6: lpreson~.pd_irix6 + +INSTALL_PREFIX=/usr/local +EXT=pd_irix6 +.SUFFIXES: .pd_irix6 + +SGICFLAGS5 = -o32 -DPD -DUNIX -DIRIX -O2 + +SGIINCLUDE = -I/usr/local/include + +.c.pd_irix6: + cc $(SGICFLAGS5) $(SGIINCLUDE) -o $*.o -c $*.c + ld -elf -shared -rdata_shared -o $*.pd_irix6 $*.o + rm $*.o + +# ----------------------- LINUX i386 ----------------------- + +pd_linux: lpreson~.pd_linux + +INSTALL_PREFIX=/usr/local +EXT=pd_linux +.SUFFIXES: .pd_linux + +LINUXCFLAGS = -DPD -O2 -funroll-loops -fomit-frame-pointer \ + -Wall -W -Wshadow -Wstrict-prototypes -Werror \ + -Wno-unused -Wno-parentheses -Wno-switch + +LINUXINCLUDE = -I/usr/local/include + +.c.pd_linux: + cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c + ld -export_dynamic -shared -o $*.pd_linux $*.o -lc -lm + strip --strip-unneeded $*.pd_linux + rm $*.o + +# ----------------------- Mac OSX ----------------------- + +pd_darwin: lpreson~.pd_darwin + +INSTALL_PREFIX=/usr/local +EXT=pd_darwin +.SUFFIXES: .pd_darwin + +DARWINCFLAGS = -DPD -O2 -Wall -W -Wshadow -Wstrict-prototypes \ + -Wno-unused -Wno-parentheses -Wno-switch + +.c.pd_darwin: + cc $(DARWINCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c + cc -bundle -undefined suppress -flat_namespace -o $*.pd_darwin $*.o + rm -f $*.o + +# ---------------------------------------------- + +install:: + install -d $(INSTALL_PREFIX)/lib/pd/extra +# install -m 644 *.$(EXT) $(INSTALL_PREFIX)/lib/pd/externs + -install -m 644 lpreson~.$(EXT) $(INSTALL_PREFIX)/lib/pd/extra + install -m 644 *.pd $(INSTALL_PREFIX)/lib/pd/doc/5.reference + install -m 644 *.wav $(INSTALL_PREFIX)/lib/pd/doc/5.reference -- cgit v1.2.1