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 | #if defined HAVE_INTEL_IPP |
---|
25 | #include <ippcore.h> |
---|
26 | #include <ippvm.h> |
---|
27 | #include <ipps.h> |
---|
28 | #endif |
---|
29 | |
---|
30 | fvec_t * new_fvec(uint_t length) { |
---|
31 | fvec_t * s; |
---|
32 | if ((sint_t)length <= 0) { |
---|
33 | return NULL; |
---|
34 | } |
---|
35 | s = AUBIO_NEW(fvec_t); |
---|
36 | s->length = length; |
---|
37 | s->data = AUBIO_ARRAY(smpl_t, s->length); |
---|
38 | return s; |
---|
39 | } |
---|
40 | |
---|
41 | void del_fvec(fvec_t *s) { |
---|
42 | AUBIO_FREE(s->data); |
---|
43 | AUBIO_FREE(s); |
---|
44 | } |
---|
45 | |
---|
46 | void fvec_set_sample(fvec_t *s, smpl_t data, uint_t position) { |
---|
47 | s->data[position] = data; |
---|
48 | } |
---|
49 | |
---|
50 | smpl_t fvec_get_sample(const fvec_t *s, uint_t position) { |
---|
51 | return s->data[position]; |
---|
52 | } |
---|
53 | |
---|
54 | smpl_t * fvec_get_data(const fvec_t *s) { |
---|
55 | return s->data; |
---|
56 | } |
---|
57 | |
---|
58 | /* helper functions */ |
---|
59 | |
---|
60 | void fvec_print(const fvec_t *s) { |
---|
61 | uint_t j; |
---|
62 | for (j=0; j< s->length; j++) { |
---|
63 | AUBIO_MSG(AUBIO_SMPL_FMT " ", s->data[j]); |
---|
64 | } |
---|
65 | AUBIO_MSG("\n"); |
---|
66 | } |
---|
67 | |
---|
68 | void fvec_set_all (fvec_t *s, smpl_t val) { |
---|
69 | #if defined(HAVE_INTEL_IPP) |
---|
70 | #if HAVE_AUBIO_DOUBLE |
---|
71 | ippsSet_64f(val, s->data, (int)s->length); |
---|
72 | #else |
---|
73 | ippsSet_32f(val, s->data, (int)s->length); |
---|
74 | #endif |
---|
75 | #elif defined(HAVE_ATLAS) |
---|
76 | aubio_catlas_set(s->length, val, s->data, 1); |
---|
77 | #elif defined(HAVE_ACCELERATE) |
---|
78 | aubio_vDSP_vfill(&val, s->data, 1, s->length); |
---|
79 | #else |
---|
80 | uint_t j; |
---|
81 | for ( j = 0; j< s->length; j++ ) |
---|
82 | { |
---|
83 | s->data[j] = val; |
---|
84 | } |
---|
85 | #endif |
---|
86 | } |
---|
87 | |
---|
88 | void fvec_zeros(fvec_t *s) { |
---|
89 | #if defined(HAVE_INTEL_IPP) |
---|
90 | #if HAVE_AUBIO_DOUBLE |
---|
91 | ippsZero_64f(s->data, (int)s->length); |
---|
92 | #else |
---|
93 | ippsZero_32f(s->data, (int)s->length); |
---|
94 | #endif |
---|
95 | #elif defined(HAVE_ACCELERATE) |
---|
96 | aubio_vDSP_vclr(s->data, 1, s->length); |
---|
97 | #elif defined(HAVE_MEMCPY_HACKS) |
---|
98 | memset(s->data, 0, s->length * sizeof(smpl_t)); |
---|
99 | #else |
---|
100 | fvec_set_all(s, 0.); |
---|
101 | #endif |
---|
102 | } |
---|
103 | |
---|
104 | void fvec_ones(fvec_t *s) { |
---|
105 | fvec_set_all (s, 1.); |
---|
106 | } |
---|
107 | |
---|
108 | void fvec_rev(fvec_t *s) { |
---|
109 | uint_t j; |
---|
110 | for (j=0; j< FLOOR((smpl_t)s->length/2); j++) { |
---|
111 | ELEM_SWAP(s->data[j], s->data[s->length-1-j]); |
---|
112 | } |
---|
113 | } |
---|
114 | |
---|
115 | void fvec_weight(fvec_t *s, const fvec_t *weight) { |
---|
116 | uint_t length = MIN(s->length, weight->length); |
---|
117 | #if defined(HAVE_INTEL_IPP) |
---|
118 | #if HAVE_AUBIO_DOUBLE |
---|
119 | ippsMul_64f(s->data, weight->data, s->data, (int)length); |
---|
120 | #else |
---|
121 | ippsMul_32f(s->data, weight->data, s->data, (int)length); |
---|
122 | #endif |
---|
123 | #elif defined(HAVE_ACCELERATE) |
---|
124 | aubio_vDSP_vmul( s->data, 1, weight->data, 1, s->data, 1, length ); |
---|
125 | #else |
---|
126 | uint_t j; |
---|
127 | for (j = 0; j < length; j++) { |
---|
128 | s->data[j] *= weight->data[j]; |
---|
129 | } |
---|
130 | #endif /* HAVE_ACCELERATE */ |
---|
131 | } |
---|
132 | |
---|
133 | void fvec_weighted_copy(const fvec_t *in, const fvec_t *weight, fvec_t *out) { |
---|
134 | uint_t length = MIN(in->length, MIN(out->length, weight->length)); |
---|
135 | #if defined(HAVE_INTEL_IPP) |
---|
136 | #if HAVE_AUBIO_DOUBLE |
---|
137 | ippsMul_64f(in->data, weight->data, out->data, (int)length); |
---|
138 | #else |
---|
139 | ippsMul_32f(in->data, weight->data, out->data, (int)length); |
---|
140 | #endif |
---|
141 | #elif defined(HAVE_ACCELERATE) |
---|
142 | aubio_vDSP_vmul(in->data, 1, weight->data, 1, out->data, 1, length); |
---|
143 | #else |
---|
144 | uint_t j; |
---|
145 | for (j = 0; j < length; j++) { |
---|
146 | out->data[j] = in->data[j] * weight->data[j]; |
---|
147 | } |
---|
148 | #endif |
---|
149 | } |
---|
150 | |
---|
151 | void fvec_copy(const fvec_t *s, fvec_t *t) { |
---|
152 | if (s->length != t->length) { |
---|
153 | AUBIO_ERR("trying to copy %d elements to %d elements \n", |
---|
154 | s->length, t->length); |
---|
155 | return; |
---|
156 | } |
---|
157 | #if defined(HAVE_INTEL_IPP) |
---|
158 | #if HAVE_AUBIO_DOUBLE |
---|
159 | ippsCopy_64f(s->data, t->data, (int)s->length); |
---|
160 | #else |
---|
161 | ippsCopy_32f(s->data, t->data, (int)s->length); |
---|
162 | #endif |
---|
163 | #elif defined(HAVE_ATLAS) |
---|
164 | aubio_cblas_copy(s->length, s->data, 1, t->data, 1); |
---|
165 | #elif defined(HAVE_ACCELERATE) |
---|
166 | aubio_vDSP_mmov(s->data, t->data, 1, s->length, 1, 1); |
---|
167 | #elif defined(HAVE_MEMCPY_HACKS) |
---|
168 | memcpy(t->data, s->data, t->length * sizeof(smpl_t)); |
---|
169 | #else |
---|
170 | uint_t j; |
---|
171 | for (j = 0; j < t->length; j++) { |
---|
172 | t->data[j] = s->data[j]; |
---|
173 | } |
---|
174 | #endif |
---|
175 | } |
---|