From efa45f81b5dcb9609b1e2365a51b7a25a1ba2ce0 Mon Sep 17 00:00:00 2001 From: Georg Holzmann Date: Tue, 12 Jul 2005 14:09:53 +0000 Subject: initial commit of adaptive svn path=/trunk/externals/grh/; revision=3317 --- adaptive/src/adaptive.c | 158 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100755 adaptive/src/adaptive.c (limited to 'adaptive/src/adaptive.c') diff --git a/adaptive/src/adaptive.c b/adaptive/src/adaptive.c new file mode 100755 index 0000000..223bb0a --- /dev/null +++ b/adaptive/src/adaptive.c @@ -0,0 +1,158 @@ +/****************************************************** + * + * Adaptive Systems for PD + * + * copyleft (c) Gerda Strobl, Georg Holzmann + * 2005 + * + * for complaints, suggestions: grh@mur.at + * + ****************************************************** + * + * license: GNU General Public License v.2 + * + ******************************************************/ + +#include "adaptive.h" + +typedef struct _adaptive +{ + t_object x_obj; +} t_adaptive; + +t_class *adaptive_class; + +static void adaptive_help(void) +{ + post("\n-----------------------------------------------"); + post("adaptive systems for PD"); + post("copyleft (c) Gerda Strobl, Georg Holzmann, 2005"); + post(""); + post("for more info look at the help patches!"); + post("-----------------------------------------------\n"); +} + +void *adaptive_new(void) +{ + t_adaptive *x = (t_adaptive *)pd_new(adaptive_class); + return (void *)x; +} + +//----------------------------------------------------- +// declaration of the setup functions: +void lms_tilde_setup(); +void lms2_tilde_setup(); +void nlms_tilde_setup(); +void nlms2_tilde_setup(); +void nlms3_tilde_setup(); +//-end-of-declaration---------------------------------- + +void adaptive_setup(void) +{ + //--------------------------------------------------- + // call all the setup functions: + lms_tilde_setup(); + lms2_tilde_setup(); + nlms_tilde_setup(); + nlms2_tilde_setup(); + nlms3_tilde_setup(); + //-end----------------------------------------------- + + post("\nadaptive: 2005 by Gerda Strobl and Georg Holzmann"); + + adaptive_class = class_new(gensym("adaptive"), adaptive_new, 0, sizeof(t_adaptive), 0, 0); + class_addmethod(adaptive_class, (t_method)adaptive_help, gensym("help"), 0); +} + + +/* ---------------------- helpers ----------------------- */ + +void adaptation_write(const char *filename, t_int N, t_float mu, t_float *c) +{ + FILE *f=0; + int i; + + // open file + f = fopen(filename, "w"); + if(!f) + { + post("adaptive, save: error open file"); + return; + } + + // write little header, number of coefficients and mu + fprintf(f, "adaptivePD\n"); + fprintf(f, "size: %d\n", N); + fprintf(f, "mu: %.30f\n", mu); + + // write coefficients + for(i=0; i