comparison l2norm.cpp @ 426:4a22a0bdf9a9 api-inversion

Deal with audioDB::UnitNorm Deal with it by removing it completely, that is. New inline function audiodb_l2norm_buffer(), replacing the three instances of that functionality dotted throughout the code.
author mas01cr
date Wed, 24 Dec 2008 10:55:20 +0000
parents d7e590d58c85
children
comparison
equal deleted inserted replaced
425:d65410f4bb85 426:4a22a0bdf9a9
4 #include "audioDB-internals.h" 4 #include "audioDB-internals.h"
5 } 5 }
6 6
7 static int audiodb_l2norm_existing(adb_t *adb) { 7 static int audiodb_l2norm_existing(adb_t *adb) {
8 double *data_buffer, *l2norm_buffer; 8 double *data_buffer, *l2norm_buffer;
9 double *dp, *lp;
10 adb_header_t *header = adb->header; 9 adb_header_t *header = adb->header;
11 size_t data_buffer_size = ALIGN_PAGE_UP(header->length); 10 size_t data_buffer_size = ALIGN_PAGE_UP(header->length);
12 size_t nvectors = header->length / (sizeof(double) * header->dim); 11 size_t nvectors = header->length / (sizeof(double) * header->dim);
13 /* FIXME: this map of the vector data will lose if we ever turn the 12 /* FIXME: this map of the vector data will lose if we ever turn the
14 * l2norm flag on when we have already inserted a large number of 13 * l2norm flag on when we have already inserted a large number of
17 mmap_or_goto_error(double *, data_buffer, header->dataOffset, data_buffer_size); 16 mmap_or_goto_error(double *, data_buffer, header->dataOffset, data_buffer_size);
18 l2norm_buffer = (double *) malloc(nvectors * sizeof(double)); 17 l2norm_buffer = (double *) malloc(nvectors * sizeof(double));
19 if(!l2norm_buffer) { 18 if(!l2norm_buffer) {
20 goto error; 19 goto error;
21 } 20 }
22 21 audiodb_l2norm_buffer(data_buffer, header->dim, nvectors, l2norm_buffer);
23 dp = data_buffer;
24 lp = l2norm_buffer;
25 for(size_t i = 0; i < nvectors; i++) {
26 *lp = 0;
27 for(unsigned int k = 0; k < header->dim; k++) {
28 *lp += (*dp)*(*dp);
29 dp++;
30 }
31 lp++;
32 }
33
34 if(lseek(adb->fd, adb->header->l2normTableOffset, SEEK_SET) == (off_t) -1) { 22 if(lseek(adb->fd, adb->header->l2normTableOffset, SEEK_SET) == (off_t) -1) {
35 goto error; 23 goto error;
36 } 24 }
37 write_or_goto_error(adb->fd, l2norm_buffer, nvectors * sizeof(double)); 25 write_or_goto_error(adb->fd, l2norm_buffer, nvectors * sizeof(double));
38 26