source: src/spectral/dct_accelerate.c @ a363759

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5
Last change on this file since a363759 was 49b19d4, checked in by Paul Brossier <piem@piem.org>, 6 years ago

src/spectral/dct_accelerate.c: add accelerate suffix

  • Property mode set to 100644
File size: 2.8 KB
Line 
1/*
2  Copyright (C) 2017 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#include "spectral/dct.h"
24
25#if defined(HAVE_ACCELERATE)
26
27#if HAVE_AUBIO_DOUBLE
28#warning "no double-precision dct with accelerate"
29#endif
30
31struct _aubio_dct_accelerate_t {
32  uint_t size;
33  fvec_t *tmp;
34  vDSP_DFT_Setup setup;
35  vDSP_DFT_Setup setupInv;
36};
37
38typedef struct _aubio_dct_accelerate_t aubio_dct_accelerate_t;
39
40void del_aubio_dct_accelerate (aubio_dct_accelerate_t *s);
41
42aubio_dct_accelerate_t * new_aubio_dct_accelerate (uint_t size) {
43  aubio_dct_accelerate_t * s = AUBIO_NEW(aubio_dct_accelerate_t);
44
45  if ((sint_t)size < 16 || !aubio_is_power_of_two(size)) {
46    AUBIO_ERR("dct: can only create with sizes greater than 16 and"
47        " that are powers of two, requested %d\n", size);
48    goto beach;
49  }
50
51  s->setup = vDSP_DCT_CreateSetup(NULL, (vDSP_Length)size, vDSP_DCT_II);
52  s->setupInv = vDSP_DCT_CreateSetup(NULL, (vDSP_Length)size, vDSP_DCT_III);
53  if (s->setup == NULL || s->setupInv == NULL) {
54    goto beach;
55  }
56
57  s->size = size;
58
59  return s;
60
61beach:
62  del_aubio_dct_accelerate(s);
63  return NULL;
64}
65
66void del_aubio_dct_accelerate(aubio_dct_accelerate_t *s) {
67  if (s->setup) vDSP_DFT_DestroySetup(s->setup);
68  if (s->setupInv) vDSP_DFT_DestroySetup(s->setupInv);
69  AUBIO_FREE(s);
70}
71
72void aubio_dct_accelerate_do(aubio_dct_accelerate_t *s, const fvec_t *input, fvec_t *output) {
73
74  vDSP_DCT_Execute(s->setup, (const float *)input->data, (float *)output->data);
75
76  // apply orthonormal scaling
77  output->data[0] *= SQRT(1./s->size);
78  smpl_t scaler = SQRT(2./s->size);
79
80  aubio_vDSP_vsmul(output->data + 1, 1, &scaler, output->data + 1, 1,
81      output->length - 1);
82
83}
84
85void aubio_dct_accelerate_rdo(aubio_dct_accelerate_t *s, const fvec_t *input, fvec_t *output) {
86
87  output->data[0] = input->data[0] / SQRT(1./s->size);
88  smpl_t scaler = 1./SQRT(2./s->size);
89
90  aubio_vDSP_vsmul(input->data + 1, 1, &scaler, output->data + 1, 1,
91      output->length - 1);
92
93  vDSP_DCT_Execute(s->setupInv, (const float *)output->data,
94      (float *)output->data);
95
96  scaler = 2./s->size;
97
98  aubio_vDSP_vsmul(output->data, 1, &scaler, output->data, 1, output->length);
99
100}
101
102#endif //defined(HAVE_ACCELERATE)
Note: See TracBrowser for help on using the repository browser.