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_ACCELERATE) && !defined(HAVE_ATLAS)
65 for (j=0; j< s->length; j++) {
68 #elif defined(HAVE_ATLAS)
69 aubio_catlas_set(s->length, val, s->data, 1);
70 #elif defined(HAVE_ACCELERATE)
71 aubio_vDSP_vfill(&val, s->data, 1, s->length);
75 void fvec_zeros(fvec_t *s) {
76 #if !defined(HAVE_MEMCPY_HACKS) && !defined(HAVE_ACCELERATE)
79 #if defined(HAVE_MEMCPY_HACKS)
80 memset(s->data, 0, s->length * sizeof(smpl_t));
82 aubio_vDSP_vclr(s->data, 1, s->length);
87 void fvec_ones(fvec_t *s) {
91 void fvec_rev(fvec_t *s) {
93 for (j=0; j< FLOOR(s->length/2); j++) {
94 ELEM_SWAP(s->data[j], s->data[s->length-1-j]);
98 void fvec_weight(fvec_t *s, const fvec_t *weight) {
99 #ifndef HAVE_ACCELERATE
101 uint_t length = MIN(s->length, weight->length);
102 for (j=0; j< length; j++) {
103 s->data[j] *= weight->data[j];
106 aubio_vDSP_vmul(s->data, 1, weight->data, 1, s->data, 1, s->length);
107 #endif /* HAVE_ACCELERATE */
110 void fvec_weighted_copy(const fvec_t *in, const fvec_t *weight, fvec_t *out) {
111 #ifndef HAVE_ACCELERATE
113 uint_t length = MIN(out->length, weight->length);
114 for (j=0; j< length; j++) {
115 out->data[j] = in->data[j] * weight->data[j];
118 aubio_vDSP_vmul(in->data, 1, weight->data, 1, out->data, 1, out->length);
119 #endif /* HAVE_ACCELERATE */
122 void fvec_copy(const fvec_t *s, fvec_t *t) {
123 if (s->length != t->length) {
124 AUBIO_ERR("trying to copy %d elements to %d elements \n",
125 s->length, t->length);
130 for (j=0; j< t->length; j++) {
131 t->data[j] = s->data[j];
133 #elif defined(HAVE_MEMCPY_HACKS)
134 memcpy(t->data, s->data, t->length * sizeof(smpl_t));
135 #elif defined(HAVE_ATLAS)
136 aubio_cblas_copy(s->length, s->data, 1, t->data, 1);
137 #elif defined(HAVE_ACCELERATE)
138 aubio_vDSP_mmov(s->data, t->data, 1, s->length, 1, 1);