1 | /* |
---|
2 | Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org> |
---|
3 | |
---|
4 | This file is part of aubio. |
---|
5 | |
---|
6 | aubio is free software: you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation, either version 3 of the License, or |
---|
9 | (at your option) any later version. |
---|
10 | |
---|
11 | aubio is distributed in the hope that it will be useful, |
---|
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | GNU General Public License for more details. |
---|
15 | |
---|
16 | You should have received a copy of the GNU General Public License |
---|
17 | along with aubio. If not, see <http://www.gnu.org/licenses/>. |
---|
18 | |
---|
19 | */ |
---|
20 | |
---|
21 | #include "aubio_priv.h" |
---|
22 | #include "fvec.h" |
---|
23 | |
---|
24 | fvec_t * new_fvec( uint_t length) { |
---|
25 | fvec_t * s = AUBIO_NEW(fvec_t); |
---|
26 | uint_t j; |
---|
27 | s->length = length; |
---|
28 | s->data = AUBIO_ARRAY(smpl_t, s->length); |
---|
29 | for (j=0; j< s->length; j++) { |
---|
30 | s->data[j]=0.; |
---|
31 | } |
---|
32 | return s; |
---|
33 | } |
---|
34 | |
---|
35 | void del_fvec(fvec_t *s) { |
---|
36 | AUBIO_FREE(s->data); |
---|
37 | AUBIO_FREE(s); |
---|
38 | } |
---|
39 | |
---|
40 | void fvec_write_sample(fvec_t *s, smpl_t data, uint_t position) { |
---|
41 | s->data[position] = data; |
---|
42 | } |
---|
43 | |
---|
44 | smpl_t fvec_read_sample(fvec_t *s, uint_t position) { |
---|
45 | return s->data[position]; |
---|
46 | } |
---|
47 | |
---|
48 | smpl_t * fvec_get_data(fvec_t *s) { |
---|
49 | return s->data; |
---|
50 | } |
---|
51 | |
---|
52 | /* helper functions */ |
---|
53 | |
---|
54 | void fvec_print(fvec_t *s) { |
---|
55 | uint_t j; |
---|
56 | for (j=0; j< s->length; j++) { |
---|
57 | AUBIO_MSG(AUBIO_SMPL_FMT " ", s->data[j]); |
---|
58 | } |
---|
59 | AUBIO_MSG("\n"); |
---|
60 | } |
---|
61 | |
---|
62 | void fvec_set(fvec_t *s, smpl_t val) { |
---|
63 | uint_t j; |
---|
64 | for (j=0; j< s->length; j++) { |
---|
65 | s->data[j] = val; |
---|
66 | } |
---|
67 | } |
---|
68 | |
---|
69 | void fvec_zeros(fvec_t *s) { |
---|
70 | fvec_set(s, 0.); |
---|
71 | } |
---|
72 | |
---|
73 | void fvec_ones(fvec_t *s) { |
---|
74 | fvec_set(s, 1.); |
---|
75 | } |
---|
76 | |
---|
77 | void fvec_rev(fvec_t *s) { |
---|
78 | uint_t j; |
---|
79 | for (j=0; j< FLOOR(s->length/2); j++) { |
---|
80 | ELEM_SWAP(s->data[j], s->data[s->length-1-j]); |
---|
81 | } |
---|
82 | } |
---|
83 | |
---|
84 | void fvec_weight(fvec_t *s, fvec_t *weight) { |
---|
85 | uint_t j; |
---|
86 | uint_t length = MIN(s->length, weight->length); |
---|
87 | for (j=0; j< length; j++) { |
---|
88 | s->data[j] *= weight->data[j]; |
---|
89 | } |
---|
90 | } |
---|
91 | |
---|
92 | void fvec_copy(fvec_t *s, fvec_t *t) { |
---|
93 | uint_t j; |
---|
94 | uint_t length = MIN(s->length, t->length); |
---|
95 | if (s->length != t->length) { |
---|
96 | AUBIO_WRN("trying to copy %d elements to %d elements \n", |
---|
97 | s->length, t->length); |
---|
98 | } |
---|
99 | for (j=0; j< length; j++) { |
---|
100 | t->data[j] = s->data[j]; |
---|
101 | } |
---|
102 | } |
---|
103 | |
---|