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) {
25 if ((sint_t)length <= 0) {
28 fvec_t * s = AUBIO_NEW(fvec_t);
30 s->data = AUBIO_ARRAY(smpl_t, s->length);
34 void del_fvec(fvec_t *s) {
39 void fvec_set_sample(fvec_t *s, smpl_t data, uint_t position) {
40 s->data[position] = data;
43 smpl_t fvec_get_sample(fvec_t *s, uint_t position) {
44 return s->data[position];
47 smpl_t * fvec_get_data(fvec_t *s) {
51 /* helper functions */
53 void fvec_print(fvec_t *s) {
55 for (j=0; j< s->length; j++) {
56 AUBIO_MSG(AUBIO_SMPL_FMT " ", s->data[j]);
61 void fvec_set_all (fvec_t *s, smpl_t val) {
63 for (j=0; j< s->length; j++) {
68 void fvec_zeros(fvec_t *s) {
70 memset(s->data, 0, s->length * sizeof(smpl_t));
76 void fvec_ones(fvec_t *s) {
80 void fvec_rev(fvec_t *s) {
82 for (j=0; j< FLOOR(s->length/2); j++) {
83 ELEM_SWAP(s->data[j], s->data[s->length-1-j]);
87 void fvec_weight(fvec_t *s, fvec_t *weight) {
89 uint_t length = MIN(s->length, weight->length);
90 for (j=0; j< length; j++) {
91 s->data[j] *= weight->data[j];
95 void fvec_copy(fvec_t *s, fvec_t *t) {
96 if (s->length != t->length) {
97 AUBIO_ERR("trying to copy %d elements to %d elements \n",
98 s->length, t->length);
101 #if HAVE_MEMCPY_HACKS
102 memcpy(t->data, s->data, t->length * sizeof(smpl_t));
105 for (j=0; j< t->length; j++) {
106 t->data[j] = s->data[j];