source: src/fft.c @ d17f63e

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

import 0.1.7.1

  • Property mode set to 100644
File size: 3.1 KB
Line 
1/*
2   Copyright (C) 2003 Paul Brossier
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU General Public License as published by
6   the Free Software Foundation; either version 2 of the License, or
7   (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   GNU General Public License for more details.
13
14   You should have received a copy of the GNU General Public License
15   along with this program; if not, write to the Free Software
16   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18*/
19
20#include "aubio_priv.h"
21#include "sample.h"
22#include "mathutils.h"
23#include "fft.h"
24
25#if FFTW3F_SUPPORT
26#define fftw_malloc             fftwf_malloc
27#define fftw_free               fftwf_free
28#define fftw_execute            fftwf_execute
29#define fftw_plan_dft_r2c_1d    fftwf_plan_dft_r2c_1d
30#define fftw_plan_dft_c2r_1d    fftwf_plan_dft_c2r_1d
31#define fftw_plan               fftwf_plan
32#define fftw_destroy_plan       fftwf_destroy_plan
33#endif
34
35#if FFTW3F_SUPPORT
36#define real_t smpl_t
37#else               
38#define real_t lsmp_t
39#endif
40
41struct _aubio_fft_t {
42        uint_t fft_size;
43        uint_t channels;
44        real_t          *in, *out;
45        fft_data_t      *specdata;
46        fftw_plan       pfw, pbw;
47};
48
49static aubio_fft_t * aubio_fft_alloc(uint_t size);
50static void aubio_fft_free(aubio_fft_t *s);
51
52static aubio_fft_t * aubio_fft_alloc(uint_t size) {
53        aubio_fft_t * s = AUBIO_NEW(aubio_fft_t);
54        /* allocate memory */
55        s->in       = AUBIO_ARRAY(real_t,size);
56        s->out      = AUBIO_ARRAY(real_t,size);
57        s->specdata = (fft_data_t*)fftw_malloc(sizeof(fft_data_t)*size);
58        return s;
59}
60
61static void aubio_fft_free(aubio_fft_t * s) { 
62        /* destroy data */
63        fftw_destroy_plan(s->pfw);
64        fftw_destroy_plan(s->pbw);
65        if (s->specdata)        fftw_free(s->specdata);
66        if (s->out)             AUBIO_FREE(s->out);
67        if (s->in )             AUBIO_FREE(s->in );
68}
69
70aubio_fft_t * new_aubio_fft(uint_t size) {
71        aubio_fft_t * s =(aubio_fft_t *)aubio_fft_alloc(size);
72        /* create plans */
73        s->pfw = fftw_plan_dft_r2c_1d(size, s->in,  s->specdata, FFTW_ESTIMATE);
74        s->pbw = fftw_plan_dft_c2r_1d(size, s->specdata, s->out, FFTW_ESTIMATE);
75        return s;
76}
77
78void del_aubio_fft(aubio_fft_t * s) {
79        aubio_fft_free(s);
80}
81
82void aubio_fft_do(const aubio_fft_t * s, 
83                const smpl_t * data, fft_data_t * spectrum, 
84                const uint_t size) {
85        uint_t i;
86        for (i=0;i<size;i++) s->in[i] = data[i];
87        fftw_execute(s->pfw);
88        for (i=0;i<size;i++) spectrum[i] = s->specdata[i];
89}
90
91void aubio_fft_rdo(const aubio_fft_t * s, 
92                const fft_data_t * spectrum, 
93                smpl_t * data, 
94                const uint_t size) {
95        uint_t i;
96        const smpl_t renorm = 1./(smpl_t)size;
97        for (i=0;i<size;i++) s->specdata[i] = spectrum[i];
98        fftw_execute(s->pbw);
99        for (i=0;i<size;i++) data[i] = s->out[i]*renorm;
100}
101
102
103void aubio_fft_getnorm(smpl_t * norm, fft_data_t * spectrum, uint_t size) {
104        uint_t i;
105        for (i=0;i<size;i++) norm[i] = ABSC(spectrum[i]);
106}
107
108void aubio_fft_getphas(smpl_t * phas, fft_data_t * spectrum, uint_t size) {
109        uint_t i;
110        for (i=0;i<size;i++) phas[i] = ARGC(spectrum[i]);
111}
112
Note: See TracBrowser for help on using the repository browser.