source: src/fvec.c @ a4ec189

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since a4ec189 was c21acb9, checked in by Paul Brossier <piem@piem.org>, 11 years ago

src/: improve build with -Wdeclaration-after-statement

  • Property mode set to 100644
File size: 2.4 KB
RevLine 
[96fb8ad]1/*
[a6db140]2  Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
[96fb8ad]3
[a6db140]4  This file is part of aubio.
[96fb8ad]5
[a6db140]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.
[96fb8ad]10
[a6db140]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/>.
[96fb8ad]18
19*/
20
21#include "aubio_priv.h"
[6c7d49b]22#include "fvec.h"
[96fb8ad]23
[c7860af]24fvec_t * new_fvec( uint_t length) {
[c21acb9]25  fvec_t * s;
[767990e]26  if ((sint_t)length <= 0) {
27    return NULL;
28  }
[c21acb9]29  s = AUBIO_NEW(fvec_t);
[96fb8ad]30  s->length = length;
[c7860af]31  s->data = AUBIO_ARRAY(smpl_t, s->length);
[96fb8ad]32  return s;
33}
34
35void del_fvec(fvec_t *s) {
36  AUBIO_FREE(s->data);
37  AUBIO_FREE(s);
38}
39
[c34336e]40void fvec_set_sample(fvec_t *s, smpl_t data, uint_t position) {
[c7860af]41  s->data[position] = data;
[96fb8ad]42}
[c7860af]43
[c34336e]44smpl_t fvec_get_sample(fvec_t *s, uint_t position) {
[c7860af]45  return s->data[position];
[96fb8ad]46}
47
[c7860af]48smpl_t * fvec_get_data(fvec_t *s) {
[96fb8ad]49  return s->data;
50}
51
[3b2d32c]52/* helper functions */
53
[32f5a01]54void fvec_print(fvec_t *s) {
[c7860af]55  uint_t j;
56  for (j=0; j< s->length; j++) {
57    AUBIO_MSG(AUBIO_SMPL_FMT " ", s->data[j]);
[32f5a01]58  }
[c7860af]59  AUBIO_MSG("\n");
[32f5a01]60}
[3b2d32c]61
[c34336e]62void fvec_set_all (fvec_t *s, smpl_t val) {
[c7860af]63  uint_t j;
64  for (j=0; j< s->length; j++) {
65    s->data[j] = val;
[3b2d32c]66  }
67}
68
69void fvec_zeros(fvec_t *s) {
[923a7a8]70#if HAVE_MEMCPY_HACKS
71  memset(s->data, 0, s->length * sizeof(smpl_t));
72#else
[c34336e]73  fvec_set_all (s, 0.);
[923a7a8]74#endif
[3b2d32c]75}
76
77void fvec_ones(fvec_t *s) {
[c34336e]78  fvec_set_all (s, 1.);
[3b2d32c]79}
80
81void fvec_rev(fvec_t *s) {
[c7860af]82  uint_t j;
83  for (j=0; j< FLOOR(s->length/2); j++) {
84    ELEM_SWAP(s->data[j], s->data[s->length-1-j]);
[3b2d32c]85  }
86}
87
88void fvec_weight(fvec_t *s, fvec_t *weight) {
[c7860af]89  uint_t j;
[3b2d32c]90  uint_t length = MIN(s->length, weight->length);
[c7860af]91  for (j=0; j< length; j++) {
92    s->data[j] *= weight->data[j];
[3b2d32c]93  }
94}
95
96void fvec_copy(fvec_t *s, fvec_t *t) {
97  if (s->length != t->length) {
[923a7a8]98    AUBIO_ERR("trying to copy %d elements to %d elements \n",
[396103a]99        s->length, t->length);
[923a7a8]100    return;
[3b2d32c]101  }
[923a7a8]102#if HAVE_MEMCPY_HACKS
103  memcpy(t->data, s->data, t->length * sizeof(smpl_t));
104#else
105  uint_t j;
106  for (j=0; j< t->length; j++) {
[c7860af]107    t->data[j] = s->data[j];
[3b2d32c]108  }
[923a7a8]109#endif
[3b2d32c]110}
Note: See TracBrowser for help on using the repository browser.