source: src/fvec.c @ b5d32cb

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

src/fvec.c: use macros for single/double precision, prefere memset/memcpy over Accelerate

  • Property mode set to 100644
File size: 3.2 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
[5b896e0]24#ifdef HAVE_ACCELERATE
25#include <Accelerate/Accelerate.h>
[1dd95c7]26#if !HAVE_AUBIO_DOUBLE
27#define aubio_vDSP_mmov       vDSP_mmov
28#define aubio_vDSP_vmul       vDSP_vmul
29#define aubio_vDSP_vfill      vDSP_vfill
30#else /* HAVE_AUBIO_DOUBLE */
31#define aubio_vDSP_mmov       vDSP_mmovD
32#define aubio_vDSP_vmul       vDSP_vmulD
33#define aubio_vDSP_vfill      vDSP_vfillD
34#endif /* HAVE_AUBIO_DOUBLE */
[5b896e0]35#endif
36
[c7860af]37fvec_t * new_fvec( uint_t length) {
[c21acb9]38  fvec_t * s;
[767990e]39  if ((sint_t)length <= 0) {
40    return NULL;
41  }
[c21acb9]42  s = AUBIO_NEW(fvec_t);
[96fb8ad]43  s->length = length;
[c7860af]44  s->data = AUBIO_ARRAY(smpl_t, s->length);
[96fb8ad]45  return s;
46}
47
48void del_fvec(fvec_t *s) {
49  AUBIO_FREE(s->data);
50  AUBIO_FREE(s);
51}
52
[c34336e]53void fvec_set_sample(fvec_t *s, smpl_t data, uint_t position) {
[c7860af]54  s->data[position] = data;
[96fb8ad]55}
[c7860af]56
[c34336e]57smpl_t fvec_get_sample(fvec_t *s, uint_t position) {
[c7860af]58  return s->data[position];
[96fb8ad]59}
60
[c7860af]61smpl_t * fvec_get_data(fvec_t *s) {
[96fb8ad]62  return s->data;
63}
64
[3b2d32c]65/* helper functions */
66
[32f5a01]67void fvec_print(fvec_t *s) {
[c7860af]68  uint_t j;
69  for (j=0; j< s->length; j++) {
70    AUBIO_MSG(AUBIO_SMPL_FMT " ", s->data[j]);
[32f5a01]71  }
[c7860af]72  AUBIO_MSG("\n");
[32f5a01]73}
[3b2d32c]74
[c34336e]75void fvec_set_all (fvec_t *s, smpl_t val) {
[5b896e0]76#ifndef HAVE_ACCELERATE
[c7860af]77  uint_t j;
78  for (j=0; j< s->length; j++) {
79    s->data[j] = val;
[3b2d32c]80  }
[5b896e0]81#else
[1dd95c7]82  aubio_vDSP_vfill(&val, s->data, 1, s->length);
[5b896e0]83#endif
[3b2d32c]84}
85
86void fvec_zeros(fvec_t *s) {
[1dd95c7]87#if !defined(HAVE_MEMCPY_HACKS) && !defined(HAVE_ACCELERATE)
88  fvec_set_all (s, 0.);
89#else
90#if defined(HAVE_MEMCPY_HACKS)
[923a7a8]91  memset(s->data, 0, s->length * sizeof(smpl_t));
92#else
[1dd95c7]93  aubio_vDSP_vclr(s->data, 1, s->length);
[923a7a8]94#endif
[5b896e0]95#endif
[3b2d32c]96}
97
98void fvec_ones(fvec_t *s) {
[c34336e]99  fvec_set_all (s, 1.);
[3b2d32c]100}
101
102void fvec_rev(fvec_t *s) {
[c7860af]103  uint_t j;
104  for (j=0; j< FLOOR(s->length/2); j++) {
105    ELEM_SWAP(s->data[j], s->data[s->length-1-j]);
[3b2d32c]106  }
107}
108
109void fvec_weight(fvec_t *s, fvec_t *weight) {
[5b896e0]110#ifndef HAVE_ACCELERATE
[c7860af]111  uint_t j;
[3b2d32c]112  uint_t length = MIN(s->length, weight->length);
[c7860af]113  for (j=0; j< length; j++) {
114    s->data[j] *= weight->data[j];
[3b2d32c]115  }
[5b896e0]116#else
[1dd95c7]117  aubio_vDSP_vmul(s->data, 1, weight->data, 1, s->data, 1, s->length);
[5b896e0]118#endif /* HAVE_ACCELERATE */
[3b2d32c]119}
120
121void fvec_copy(fvec_t *s, fvec_t *t) {
122  if (s->length != t->length) {
[923a7a8]123    AUBIO_ERR("trying to copy %d elements to %d elements \n",
[396103a]124        s->length, t->length);
[923a7a8]125    return;
[3b2d32c]126  }
[1dd95c7]127#if !defined(HAVE_MEMCPY_HACKS) && !defined(HAVE_ACCELERATE)
[923a7a8]128  uint_t j;
129  for (j=0; j< t->length; j++) {
[c7860af]130    t->data[j] = s->data[j];
[3b2d32c]131  }
[5b896e0]132#else
[1dd95c7]133#if defined(HAVE_MEMCPY_HACKS)
134  memcpy(t->data, s->data, t->length * sizeof(smpl_t));
135#else
136  aubio_vDSP_mmov(s->data, t->data, 1, s->length, 1, 1);
137#endif
138#endif
[3b2d32c]139}
Note: See TracBrowser for help on using the repository browser.