source: src/fvec.c @ 5b896e0

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

src/fvec.c: Accelerate fvec_set_all, fvec_zeros, fvec_weight, fvec_copy

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