2 Copyright (C) 2017 Paul Brossier <piem@aubio.org>
4 This file is part of aubio.
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.
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.
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/>.
21 #include "aubio_priv.h"
24 #include "spectral/dct.h"
26 #if defined(HAVE_ACCELERATE)
29 #warning "no double-precision dct with accelerate"
36 vDSP_DFT_Setup setupInv;
39 aubio_dct_t * new_aubio_dct (uint_t size) {
40 aubio_dct_t * s = AUBIO_NEW(aubio_dct_t);
42 if ((sint_t)size < 16 || !aubio_is_power_of_two(size)) {
43 AUBIO_ERR("dct: can only create with sizes greater than 16 and"
44 "that are powers of two, requested %d\n", size);
48 s->setup = vDSP_DCT_CreateSetup(NULL, (vDSP_Length)size, vDSP_DCT_II);
49 s->setupInv = vDSP_DCT_CreateSetup(NULL, (vDSP_Length)size, vDSP_DCT_III);
50 if (s->setup == NULL || s->setupInv == NULL) {
63 void del_aubio_dct(aubio_dct_t *s) {
64 if (s->setup) vDSP_DFT_DestroySetup(s->setup);
65 if (s->setupInv) vDSP_DFT_DestroySetup(s->setupInv);
69 void aubio_dct_do(aubio_dct_t *s, const fvec_t *input, fvec_t *output) {
71 vDSP_DCT_Execute(s->setup, (const float *)input->data, (float *)output->data);
73 // apply orthonormal scaling
74 output->data[0] *= SQRT(1./s->size);
75 smpl_t scaler = SQRT(2./s->size);
77 aubio_vDSP_vsmul(output->data + 1, 1, &scaler, output->data + 1, 1,
82 void aubio_dct_rdo(aubio_dct_t *s, const fvec_t *input, fvec_t *output) {
84 output->data[0] = input->data[0] / SQRT(1./s->size);
85 smpl_t scaler = 1./SQRT(2./s->size);
87 aubio_vDSP_vsmul(input->data + 1, 1, &scaler, output->data + 1, 1,
90 vDSP_DCT_Execute(s->setupInv, (const float *)output->data,
91 (float *)output->data);
95 aubio_vDSP_vsmul(output->data, 1, &scaler, output->data, 1, output->length);
99 #endif //defined(HAVE_ACCELERATE)