summaryrefslogtreecommitdiff
path: root/tests/test6
diff options
context:
space:
mode:
authorLudovic Pouzenc <ludovic@pouzenc.fr>2012-06-11 20:04:06 +0000
committerLudovic Pouzenc <ludovic@pouzenc.fr>2012-06-11 20:04:06 +0000
commit146badba51fe507d0c3f2e904dae6289d991766a (patch)
treea0c056c5ef584b484c9846ead40a53cd4c020509 /tests/test6
parent88f174d0b8b749cf96a38e284f266d3bdaa55ef4 (diff)
download2012-violon-leds-146badba51fe507d0c3f2e904dae6289d991766a.tar.gz
2012-violon-leds-146badba51fe507d0c3f2e904dae6289d991766a.tar.bz2
2012-violon-leds-146badba51fe507d0c3f2e904dae6289d991766a.zip
Préparation de quelques bouts de code pour tester les routines de maths proprement.
git-svn-id: file:///var/svn/2012-violon-leds/trunk@17 6be1fa4d-33ac-4c33-becc-79fcb3794bb6
Diffstat (limited to 'tests/test6')
-rw-r--r--tests/test6/test6.c33
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;
}