comparison 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
comparison
equal deleted inserted replaced
426:4a22a0bdf9a9 427:adaa6a688a04
117 double *d2 = d; 117 double *d2 = d;
118 *l++ = audiodb_dot_product(d1, d2, dim); 118 *l++ = audiodb_dot_product(d1, d2, dim);
119 d += dim; 119 d += dim;
120 } 120 }
121 } 121 }
122
123 // This is a common pattern in sequence queries: what we are doing is
124 // taking a window of length seqlen over a buffer of length length,
125 // and placing the sum of the elements in that window in the first
126 // element of the window: thus replacing all but the last seqlen
127 // elements in the buffer with the corresponding windowed sum.
128 static inline void audiodb_sequence_sum(double *buffer, int length, int seqlen) {
129 double tmp1, tmp2, *ps;
130 int j, w;
131
132 tmp1 = *buffer;
133 j = 1;
134 w = seqlen - 1;
135 while(w--) {
136 *buffer += buffer[j++];
137 }
138 ps = buffer + 1;
139 w = length - seqlen; // +1 - 1
140 while(w--) {
141 tmp2 = *ps;
142 if(isfinite(tmp1)) {
143 *ps = *(ps - 1) - tmp1 + *(ps + seqlen - 1);
144 } else {
145 for(int i = 1; i < seqlen; i++) {
146 *ps += *(ps + i);
147 }
148 }
149 tmp1 = tmp2;
150 ps++;
151 }
152 }
153
154 // In contrast to audiodb_sequence_sum() above,
155 // audiodb_sequence_sqrt() and audiodb_sequence_average() below are
156 // simple mappers across the sequence.
157 static inline void audiodb_sequence_sqrt(double *buffer, int length, int seqlen) {
158 int w = length - seqlen + 1;
159 while(w--) {
160 *buffer = sqrt(*buffer);
161 buffer++;
162 }
163 }
164
165 static inline void audiodb_sequence_average(double *buffer, int length, int seqlen) {
166 int w = length - seqlen + 1;
167 while(w--) {
168 *buffer /= seqlen;
169 buffer++;
170 }
171 }