diff audioDB-internals.h @ 427:adaa6a688a04 api-inversion

Move sequence_foo() functions out of audioDB:: namespace... ... and into the internals header, mostly to get them out of the way. That means they have to be inline, which is probably suboptimal but will do for now.
author mas01cr
date Wed, 24 Dec 2008 10:55:24 +0000
parents 4a22a0bdf9a9
children 2d14d21f826b
line wrap: on
line diff
--- a/audioDB-internals.h	Wed Dec 24 10:55:20 2008 +0000
+++ b/audioDB-internals.h	Wed Dec 24 10:55:24 2008 +0000
@@ -119,3 +119,53 @@
     d += dim;
   }
 }
+
+// This is a common pattern in sequence queries: what we are doing is
+// taking a window of length seqlen over a buffer of length length,
+// and placing the sum of the elements in that window in the first
+// element of the window: thus replacing all but the last seqlen
+// elements in the buffer with the corresponding windowed sum.
+static inline void audiodb_sequence_sum(double *buffer, int length, int seqlen) {
+  double tmp1, tmp2, *ps;
+  int j, w;
+
+  tmp1 = *buffer;
+  j = 1;
+  w = seqlen - 1;
+  while(w--) {
+    *buffer += buffer[j++];
+  }
+  ps = buffer + 1;
+  w = length - seqlen; // +1 - 1
+  while(w--) {
+    tmp2 = *ps;
+    if(isfinite(tmp1)) {
+      *ps = *(ps - 1) - tmp1 + *(ps + seqlen - 1);
+    } else {
+      for(int i = 1; i < seqlen; i++) {
+        *ps += *(ps + i);
+      }
+    }
+    tmp1 = tmp2;
+    ps++;
+  }
+}
+
+// In contrast to audiodb_sequence_sum() above,
+// audiodb_sequence_sqrt() and audiodb_sequence_average() below are
+// simple mappers across the sequence.
+static inline void audiodb_sequence_sqrt(double *buffer, int length, int seqlen) {
+  int w = length - seqlen + 1;
+  while(w--) {
+    *buffer = sqrt(*buffer);
+    buffer++;
+  }
+}
+
+static inline void audiodb_sequence_average(double *buffer, int length, int seqlen) {
+  int w = length - seqlen + 1;
+  while(w--) {
+    *buffer /= seqlen;
+    buffer++;
+  }
+}