diff peck_test.c @ 0:723f588b82ac

import
author Peter Meerwald <p.meerwald@bct-electronic.com>
date Fri, 16 Sep 2011 12:53:08 +0200
parents
children 2d6c49fcafcb
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/peck_test.c	Fri Sep 16 12:53:08 2011 +0200
@@ -0,0 +1,77 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <float.h>
+
+#include <peck_fft.h>
+#include <peck_fftr.h>
+
+void enable_runfast() {
+#ifdef __arm__
+        static const unsigned int x = 0x04086060;
+        static const unsigned int y = 0x03000000;
+        int r;
+        asm volatile (
+                "fmrx   %0, fpscr                       \n\t"   //r0 = FPSCR
+                "and    %0, %0, %1                      \n\t"   //r0 = r0 & 0x04086060
+                "orr    %0, %0, %2                      \n\t"   //r0 = r0 | 0x03000000
+                "fmxr   fpscr, %0                       \n\t"   //FPSCR = r0
+                : "=r"(r)
+                : "r"(x), "r"(y)
+        );
+#endif
+}
+
+int main(int argc, char *argv[]) {
+    unsigned int i, j;
+    peck_fftr_cfg p, pi;
+
+    enable_runfast();
+
+    const unsigned int N = 256;
+
+    peck_fft_scalar in[N];
+    peck_fft_cpx out[N/2 + 1];
+    peck_fft_scalar res[N];
+
+    for (i = 0; i < N; i++) {
+        in[i] = (i % 13) / 3; 
+    }
+
+    p = peck_fftr_alloc(N, 0, NULL, NULL);
+    pi = peck_fftr_alloc(N, 1, NULL, NULL);
+
+    for (j = 0; j < 10000; j++) {
+        if (j == 0) {
+            for (i = 0; i < 8; i++)
+                printf("%d: %f\n", i, in[i]);
+            printf("----\n");
+        }
+
+        peck_fftr(p, in, out);
+
+        if (j == 0) {
+            for (i = 0; i < 8; i++)
+                printf("%d: %f %f\n", i, out[i].r, out[i].i);
+            printf("----\n");
+        }
+        
+        peck_fftri(pi, out, res);
+
+        if (j == 0) {
+            for (i = 0; i < 8; i++)
+                printf("%d: %f\n", i, res[i] / N);
+        }
+    }
+    peck_fftr_free(p);    
+    peck_fftr_free(pi);    
+    peck_fft_cleanup();
+
+    for (i = 0; i < N; i++) {
+        if (fabs(in[i] - res[i]/N) > 0.00001) {
+            fprintf(stderr, "!!!! ERROR !!!! at %d\n", i);
+            exit(EXIT_FAILURE);
+        }
+    }
+
+    return EXIT_SUCCESS;
+}

Repositories maintained by Peter Meerwald, pmeerw@pmeerw.net.