source: src/fvec.c @ 7166ef8

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

src/fvec.{c,h}: add fvec_weighted_copy

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