diff options
-rw-r--r-- | tests/test6/test6.c | 33 |
1 files changed, 32 insertions, 1 deletions
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 <stdio.h> #include <stdlib.h> +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;i<n;i++) { + t=fabs(f[i]); + mean+=t; + if (t>max) 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; } |