source: src/fvec.c @ 152ed05

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 152ed05 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
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#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 */
35#endif
36
37fvec_t * new_fvec( uint_t length) {
38  fvec_t * s;
39  if ((sint_t)length <= 0) {
40    return NULL;
41  }
42  s = AUBIO_NEW(fvec_t);
43  s->length = length;
44  s->data = AUBIO_ARRAY(smpl_t, s->length);
45  return s;
46}
47
48void del_fvec(fvec_t *s) {
49  AUBIO_FREE(s->data);
50  AUBIO_FREE(s);
51}
52
53void fvec_set_sample(fvec_t *s, smpl_t data, uint_t position) {
54  s->data[position] = data;
55}
56
57smpl_t fvec_get_sample(fvec_t *s, uint_t position) {
58  return s->data[position];
59}
60
61smpl_t * fvec_get_data(fvec_t *s) {
62  return s->data;
63}
64
65/* helper functions */
66
67void fvec_print(fvec_t *s) {
68  uint_t j;
69  for (j=0; j< s->length; j++) {
70    AUBIO_MSG(AUBIO_SMPL_FMT " ", s->data[j]);
71  }
72  AUBIO_MSG("\n");
73}
74
75void fvec_set_all (fvec_t *s, smpl_t val) {
76#ifndef HAVE_ACCELERATE
77  uint_t j;
78  for (j=0; j< s->length; j++) {
79    s->data[j] = val;
80  }
81#else
82  aubio_vDSP_vfill(&val, s->data, 1, s->length);
83#endif
84}
85
86void fvec_zeros(fvec_t *s) {
87#if !defined(HAVE_MEMCPY_HACKS) && !defined(HAVE_ACCELERATE)
88  fvec_set_all (s, 0.);
89#else
90#if defined(HAVE_MEMCPY_HACKS)
91  memset(s->data, 0, s->length * sizeof(smpl_t));
92#else
93  aubio_vDSP_vclr(s->data, 1, s->length);
94#endif
95#endif
96}
97
98void fvec_ones(fvec_t *s) {
99  fvec_set_all (s, 1.);
100}
101
102void fvec_rev(fvec_t *s) {
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]);
106  }
107}
108
109void fvec_weight(fvec_t *s, fvec_t *weight) {
110#ifndef HAVE_ACCELERATE
111  uint_t j;
112  uint_t length = MIN(s->length, weight->length);
113  for (j=0; j< length; j++) {
114    s->data[j] *= weight->data[j];
115  }
116#else
117  aubio_vDSP_vmul(s->data, 1, weight->data, 1, s->data, 1, s->length);
118#endif /* HAVE_ACCELERATE */
119}
120
121void fvec_copy(fvec_t *s, fvec_t *t) {
122  if (s->length != t->length) {
123    AUBIO_ERR("trying to copy %d elements to %d elements \n",
124        s->length, t->length);
125    return;
126  }
127#if !defined(HAVE_MEMCPY_HACKS) && !defined(HAVE_ACCELERATE)
128  uint_t j;
129  for (j=0; j< t->length; j++) {
130    t->data[j] = s->data[j];
131  }
132#else
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
139}
Note: See TracBrowser for help on using the repository browser.