source: src/fvec.c @ c59e693

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since c59e693 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
Line 
1/*
2  Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
3
4  This file is part of aubio.
5
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.
10
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/>.
18
19*/
20
21#include "aubio_priv.h"
22#include "fvec.h"
23
24#ifdef HAVE_ACCELERATE
25#include <Accelerate/Accelerate.h>
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#define aubio_catlas_set      catlas_sset
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
35#define aubio_catlas_set      catlas_dset
36#endif /* HAVE_AUBIO_DOUBLE */
37#endif
38
39fvec_t * new_fvec( uint_t length) {
40  fvec_t * s;
41  if ((sint_t)length <= 0) {
42    return NULL;
43  }
44  s = AUBIO_NEW(fvec_t);
45  s->length = length;
46  s->data = AUBIO_ARRAY(smpl_t, s->length);
47  return s;
48}
49
50void del_fvec(fvec_t *s) {
51  AUBIO_FREE(s->data);
52  AUBIO_FREE(s);
53}
54
55void fvec_set_sample(fvec_t *s, smpl_t data, uint_t position) {
56  s->data[position] = data;
57}
58
59smpl_t fvec_get_sample(fvec_t *s, uint_t position) {
60  return s->data[position];
61}
62
63smpl_t * fvec_get_data(fvec_t *s) {
64  return s->data;
65}
66
67/* helper functions */
68
69void fvec_print(fvec_t *s) {
70  uint_t j;
71  for (j=0; j< s->length; j++) {
72    AUBIO_MSG(AUBIO_SMPL_FMT " ", s->data[j]);
73  }
74  AUBIO_MSG("\n");
75}
76
77void fvec_set_all (fvec_t *s, smpl_t val) {
78#ifndef HAVE_ACCELERATE
79  uint_t j;
80  for (j=0; j< s->length; j++) {
81    s->data[j] = val;
82  }
83#else
84  //aubio_catlas_set(s->length, val, s->data, 1);
85  aubio_vDSP_vfill(&val, s->data, 1, s->length);
86#endif
87}
88
89void fvec_zeros(fvec_t *s) {
90#if !defined(HAVE_MEMCPY_HACKS) && !defined(HAVE_ACCELERATE)
91  fvec_set_all (s, 0.);
92#else
93#if defined(HAVE_MEMCPY_HACKS)
94  memset(s->data, 0, s->length * sizeof(smpl_t));
95#else
96  aubio_vDSP_vclr(s->data, 1, s->length);
97#endif
98#endif
99}
100
101void fvec_ones(fvec_t *s) {
102  fvec_set_all (s, 1.);
103}
104
105void fvec_rev(fvec_t *s) {
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]);
109  }
110}
111
112void fvec_weight(fvec_t *s, fvec_t *weight) {
113#ifndef HAVE_ACCELERATE
114  uint_t j;
115  uint_t length = MIN(s->length, weight->length);
116  for (j=0; j< length; j++) {
117    s->data[j] *= weight->data[j];
118  }
119#else
120  aubio_vDSP_vmul(s->data, 1, weight->data, 1, s->data, 1, s->length);
121#endif /* HAVE_ACCELERATE */
122}
123
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
136void fvec_copy(fvec_t *s, fvec_t *t) {
137  if (s->length != t->length) {
138    AUBIO_ERR("trying to copy %d elements to %d elements \n",
139        s->length, t->length);
140    return;
141  }
142#if !defined(HAVE_MEMCPY_HACKS) && !defined(HAVE_ACCELERATE)
143  uint_t j;
144  for (j=0; j< t->length; j++) {
145    t->data[j] = s->data[j];
146  }
147#else
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
154}
Note: See TracBrowser for help on using the repository browser.