source: src/spectral/dct_ooura.c @ 60583a3

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

src/spectral/dct.h: add dct type II using ooura

  • Property mode set to 100644
File size: 2.4 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 "cvec.h"
24#include "spectral/dct.h"
25
26extern void aubio_ooura_ddct(int, int, smpl_t *, int *, smpl_t *);
27
28struct _aubio_dct_t {
29  uint_t size;
30  fvec_t *input;
31  smpl_t *w;
32  int *ip;
33};
34
35aubio_dct_t * new_aubio_dct (uint_t size) {
36  aubio_dct_t * s = AUBIO_NEW(aubio_dct_t);
37  if (aubio_is_power_of_two(size) != 1) {
38    AUBIO_ERR("dct: can only create with sizes power of two, requested %d\n",
39        size);
40    goto beach;
41  }
42  s->size = size;
43  s->input = new_fvec(s->size);
44  s->w = AUBIO_ARRAY(smpl_t, s->size * 5 / 4);
45  s->ip = AUBIO_ARRAY(int, 3 + (1 << (int)FLOOR(LOG(s->size/2) / LOG(2))) / 2);
46  s->ip[0] = 0;
47  return s;
48beach:
49  AUBIO_FREE(s);
50  return NULL;
51}
52
53void del_aubio_dct(aubio_dct_t *s) {
54  del_fvec(s->input);
55  AUBIO_FREE(s->ip);
56  AUBIO_FREE(s->w);
57  AUBIO_FREE(s);
58}
59
60void aubio_dct_do(aubio_dct_t *s, const fvec_t *input, fvec_t *output) {
61  uint_t i = 0;
62  fvec_copy(input, s->input);
63  aubio_ooura_ddct(s->size, -1, s->input->data, s->ip, s->w);
64  // apply orthonormal scaling
65  s->input->data[0] *= 2.* SQRT(1./(4.*s->input->length));
66  for (i = 1; i < s->input->length; i++) {
67    s->input->data[i] *= 2. * SQRT(1./(2.*s->input->length));
68  }
69  fvec_copy(s->input, output);
70}
71
72void aubio_dct_rdo(aubio_dct_t *s, const fvec_t *input, fvec_t *output) {
73  uint_t i = 0;
74  fvec_copy(input, s->input);
75  s->input->data[0] /= 2.* SQRT(1./(4.*s->input->length));
76  for (i = 1; i < s->input->length; i++) {
77    s->input->data[i] /= 2. * SQRT(1./(2.*s->input->length));
78  }
79  s->input->data[0] *= .5;
80  aubio_ooura_ddct(s->size, 1, s->input->data, s->ip, s->w);
81  for (i = 0; i < s->input->length; i++) {
82    s->input->data[i] *= 2./s->input->length;
83  }
84  fvec_copy(s->input, output);
85}
Note: See TracBrowser for help on using the repository browser.