From 146badba51fe507d0c3f2e904dae6289d991766a Mon Sep 17 00:00:00 2001 From: Ludovic Pouzenc Date: Mon, 11 Jun 2012 20:04:06 +0000 Subject: Préparation de quelques bouts de code pour tester les routines de maths proprement. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: file:///var/svn/2012-violon-leds/trunk@17 6be1fa4d-33ac-4c33-becc-79fcb3794bb6 --- tests/test6/test6.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/tests/test6/test6.c b/tests/test6/test6.c index 2cb7074..abaa3e4 100644 --- a/tests/test6/test6.c +++ b/tests/test6/test6.c @@ -2,6 +2,9 @@ #include #include +typedef void (*cb_processdata_t)(int n, float *); + + //#if 1 //(UGLY_IEEE754_FLOAT32_HACK :-) /* static inline float todB_a(const float *x){ @@ -51,9 +54,37 @@ void dump_testfile() { fclose(fh); } +void parse_testfile(cb_processdata_t cb) { + int n; + float f[2048]; + FILE *fh=fopen("./test.raw", "r"); + if (fh==NULL) return; + + n=128; + while ( (n=fread(f, sizeof(float), n, fh)) > 0 ) { + cb(n,f); + n=128+256*(rand()%7); + } + fclose(fh); +} + +void process_mean_max(int n, float *f) { + int i; + float t, mean=0, max=0; + for(i=0;imax) max=t; + } + mean/=n; + + printf("%+.3f %+.3f %4i\n", mean, max, n); +} + int main() { //test_todb_a(); - dump_testfile(); + //dump_testfile(); + parse_testfile(process_mean_max); return 0; } -- cgit v1.2.3