2 Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
4 This file is part of aubio.
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.
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.
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/>.
21 #include "aubio_priv.h"
24 fvec_t * new_fvec(uint_t length) {
26 if ((sint_t)length <= 0) {
29 s = AUBIO_NEW(fvec_t);
31 s->data = AUBIO_ARRAY(smpl_t, s->length);
35 void del_fvec(fvec_t *s) {
40 void fvec_set_sample(fvec_t *s, smpl_t data, uint_t position) {
41 s->data[position] = data;
44 smpl_t fvec_get_sample(const fvec_t *s, uint_t position) {
45 return s->data[position];
48 smpl_t * fvec_get_data(const fvec_t *s) {
52 /* helper functions */
54 void fvec_print(const fvec_t *s) {
56 for (j=0; j< s->length; j++) {
57 AUBIO_MSG(AUBIO_SMPL_FMT " ", s->data[j]);
62 void fvec_set_all (fvec_t *s, smpl_t val) {
63 #if defined(HAVE_INTEL_IPP)
64 aubio_ippsSet(val, s->data, (int)s->length);
65 #elif defined(HAVE_ATLAS)
66 aubio_catlas_set(s->length, val, s->data, 1);
67 #elif defined(HAVE_ACCELERATE)
68 aubio_vDSP_vfill(&val, s->data, 1, s->length);
71 for ( j = 0; j< s->length; j++ )
78 void fvec_zeros(fvec_t *s) {
79 #if defined(HAVE_INTEL_IPP)
80 aubio_ippsZero(s->data, (int)s->length);
81 #elif defined(HAVE_ACCELERATE)
82 aubio_vDSP_vclr(s->data, 1, s->length);
83 #elif defined(HAVE_MEMCPY_HACKS)
84 memset(s->data, 0, s->length * sizeof(smpl_t));
90 void fvec_ones(fvec_t *s) {
94 void fvec_rev(fvec_t *s) {
96 for (j=0; j< FLOOR((smpl_t)s->length/2); j++) {
97 ELEM_SWAP(s->data[j], s->data[s->length-1-j]);
101 void fvec_weight(fvec_t *s, const fvec_t *weight) {
102 uint_t length = MIN(s->length, weight->length);
103 #if defined(HAVE_INTEL_IPP)
104 aubio_ippsMul(s->data, weight->data, s->data, (int)length);
105 #elif defined(HAVE_ACCELERATE)
106 aubio_vDSP_vmul( s->data, 1, weight->data, 1, s->data, 1, length );
109 for (j = 0; j < length; j++) {
110 s->data[j] *= weight->data[j];
112 #endif /* HAVE_ACCELERATE */
115 void fvec_weighted_copy(const fvec_t *in, const fvec_t *weight, fvec_t *out) {
116 uint_t length = MIN(in->length, MIN(out->length, weight->length));
117 #if defined(HAVE_INTEL_IPP)
118 aubio_ippsMul(in->data, weight->data, out->data, (int)length);
119 #elif defined(HAVE_ACCELERATE)
120 aubio_vDSP_vmul(in->data, 1, weight->data, 1, out->data, 1, length);
123 for (j = 0; j < length; j++) {
124 out->data[j] = in->data[j] * weight->data[j];
129 void fvec_copy(const fvec_t *s, fvec_t *t) {
130 if (s->length != t->length) {
131 AUBIO_ERR("trying to copy %d elements to %d elements \n",
132 s->length, t->length);
135 #if defined(HAVE_INTEL_IPP)
136 aubio_ippsCopy(s->data, t->data, (int)s->length);
137 #elif defined(HAVE_BLAS)
138 aubio_cblas_copy(s->length, s->data, 1, t->data, 1);
139 #elif defined(HAVE_ACCELERATE)
140 aubio_vDSP_mmov(s->data, t->data, 1, s->length, 1, 1);
141 #elif defined(HAVE_MEMCPY_HACKS)
142 memcpy(t->data, s->data, t->length * sizeof(smpl_t));
145 for (j = 0; j < t->length; j++) {
146 t->data[j] = s->data[j];