[96fb8ad] | 1 | /* |
---|
[a47cd35] | 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 | |
---|
[96fb8ad] | 18 | */ |
---|
| 19 | |
---|
[2afdb0f] | 20 | /** \file |
---|
| 21 | |
---|
| 22 | Fast Fourier Transform object |
---|
| 23 | |
---|
| 24 | */ |
---|
[96fb8ad] | 25 | |
---|
| 26 | #ifndef FFT_H_ |
---|
| 27 | #define FFT_H_ |
---|
[66834b6] | 28 | |
---|
[2afdb0f] | 29 | /* note that <complex.h> is not included here but only in aubio_priv.h, so that |
---|
| 30 | * c++ projects can still use their own complex definition. */ |
---|
[96fb8ad] | 31 | #include <fftw3.h> |
---|
| 32 | |
---|
[3b3ec6c] | 33 | #ifdef HAVE_COMPLEX_H |
---|
[b511fa9] | 34 | #if HAVE_FFTW3F |
---|
[7cec717] | 35 | /** fft data type with complex.h and fftw3f */ |
---|
[96fb8ad] | 36 | #define FFTW_TYPE fftwf_complex |
---|
| 37 | #else |
---|
[7cec717] | 38 | /** fft data type with complex.h and fftw3 */ |
---|
[96fb8ad] | 39 | #define FFTW_TYPE fftw_complex |
---|
| 40 | #endif |
---|
[3b3ec6c] | 41 | #else |
---|
[b511fa9] | 42 | #if HAVE_FFTW3F |
---|
[7cec717] | 43 | /** fft data type without complex.h and with fftw3f */ |
---|
[3b3ec6c] | 44 | #define FFTW_TYPE float |
---|
| 45 | #else |
---|
[7cec717] | 46 | /** fft data type without complex.h and with fftw */ |
---|
[3b3ec6c] | 47 | #define FFTW_TYPE double |
---|
| 48 | #endif |
---|
| 49 | #endif |
---|
[96fb8ad] | 50 | |
---|
| 51 | #ifdef __cplusplus |
---|
| 52 | extern "C" { |
---|
| 53 | #endif |
---|
| 54 | |
---|
[d88ea06] | 55 | /** fft data type */ |
---|
[96fb8ad] | 56 | typedef FFTW_TYPE fft_data_t; |
---|
| 57 | |
---|
[2afdb0f] | 58 | /** FFT object |
---|
| 59 | |
---|
| 60 | This object computes forward and backward FFTs, using the complex type to |
---|
| 61 | store the results. The phase vocoder or aubio_mfft_t objects should be |
---|
| 62 | preferred to using directly aubio_fft_t. The FFT are computed using FFTW3 |
---|
| 63 | (although support for another library could be added). |
---|
| 64 | |
---|
| 65 | */ |
---|
[96fb8ad] | 66 | typedef struct _aubio_fft_t aubio_fft_t; |
---|
| 67 | |
---|
[2afdb0f] | 68 | /** create new FFT computation object |
---|
| 69 | |
---|
| 70 | \param size length of the FFT |
---|
[aadd27a] | 71 | \param channels number of channels |
---|
[2afdb0f] | 72 | |
---|
| 73 | */ |
---|
[aadd27a] | 74 | aubio_fft_t * new_aubio_fft(uint_t size, uint_t channels); |
---|
[2afdb0f] | 75 | /** delete FFT object |
---|
| 76 | |
---|
| 77 | \param s fft object as returned by new_aubio_fft |
---|
| 78 | |
---|
| 79 | */ |
---|
[227564e] | 80 | void del_aubio_fft(aubio_fft_t * s); |
---|
[aadd27a] | 81 | |
---|
[2afdb0f] | 82 | /** compute forward FFT |
---|
| 83 | |
---|
| 84 | \param s fft object as returned by new_aubio_fft |
---|
[aadd27a] | 85 | \param input input signal |
---|
[2afdb0f] | 86 | \param spectrum output spectrum |
---|
| 87 | |
---|
| 88 | */ |
---|
[aadd27a] | 89 | void aubio_fft_do (aubio_fft_t *s, fvec_t * input, cvec_t * spectrum); |
---|
[2afdb0f] | 90 | /** compute backward (inverse) FFT |
---|
| 91 | |
---|
| 92 | \param s fft object as returned by new_aubio_fft |
---|
| 93 | \param spectrum input spectrum |
---|
[aadd27a] | 94 | \param output output signal |
---|
[2afdb0f] | 95 | |
---|
| 96 | */ |
---|
[aadd27a] | 97 | void aubio_fft_rdo (aubio_fft_t *s, cvec_t * spectrum, fvec_t * output); |
---|
[2afdb0f] | 98 | |
---|
[aadd27a] | 99 | /** compute forward FFT |
---|
| 100 | |
---|
| 101 | \param s fft object as returned by new_aubio_fft |
---|
| 102 | \param input real input signal |
---|
| 103 | \param compspec complex output fft real/imag |
---|
[2afdb0f] | 104 | |
---|
| 105 | */ |
---|
[aadd27a] | 106 | void aubio_fft_do_complex (aubio_fft_t *s, fvec_t * input, fvec_t * compspec); |
---|
| 107 | /** compute backward (inverse) FFT from real/imag |
---|
| 108 | |
---|
| 109 | \param s fft object as returned by new_aubio_fft |
---|
| 110 | \param compspec real/imag input fft array |
---|
| 111 | \param output real output array |
---|
[2afdb0f] | 112 | |
---|
| 113 | */ |
---|
[aadd27a] | 114 | void aubio_fft_rdo_complex (aubio_fft_t *s, fvec_t * compspec, fvec_t * output); |
---|
[96fb8ad] | 115 | |
---|
[aadd27a] | 116 | /** convert real/imag spectrum to norm/phas spectrum |
---|
[f88a326] | 117 | |
---|
[aadd27a] | 118 | \param compspec real/imag input fft array |
---|
| 119 | \param spectrum cvec norm/phas output array |
---|
[2afdb0f] | 120 | |
---|
| 121 | */ |
---|
[aadd27a] | 122 | void aubio_fft_get_spectrum(fvec_t * compspec, cvec_t * spectrum); |
---|
| 123 | /** convert real/imag spectrum to norm/phas spectrum |
---|
[2afdb0f] | 124 | |
---|
[aadd27a] | 125 | \param compspec real/imag input fft array |
---|
| 126 | \param spectrum cvec norm/phas output array |
---|
[2afdb0f] | 127 | |
---|
| 128 | */ |
---|
[aadd27a] | 129 | void aubio_fft_get_realimag(cvec_t * spectrum, fvec_t * compspec); |
---|
| 130 | |
---|
| 131 | /** compute phas spectrum from real/imag parts |
---|
[2afdb0f] | 132 | |
---|
[aadd27a] | 133 | \param compspec real/imag input fft array |
---|
| 134 | \param spectrum cvec norm/phas output array |
---|
[2afdb0f] | 135 | |
---|
| 136 | */ |
---|
[aadd27a] | 137 | void aubio_fft_get_phas(fvec_t * compspec, cvec_t * spectrum); |
---|
| 138 | /** compute imaginary part from the norm/phas cvec |
---|
[2afdb0f] | 139 | |
---|
[aadd27a] | 140 | \param spectrum norm/phas input array |
---|
| 141 | \param compspec real/imag output fft array |
---|
[2afdb0f] | 142 | |
---|
| 143 | */ |
---|
[aadd27a] | 144 | void aubio_fft_get_imag(cvec_t * spectrum, fvec_t * compspec); |
---|
[2afdb0f] | 145 | |
---|
[aadd27a] | 146 | /** compute norm component from real/imag parts |
---|
| 147 | |
---|
| 148 | \param compspec real/imag input fft array |
---|
| 149 | \param spectrum cvec norm/phas output array |
---|
[2afdb0f] | 150 | |
---|
| 151 | */ |
---|
[aadd27a] | 152 | void aubio_fft_get_norm(fvec_t * compspec, cvec_t * spectrum); |
---|
| 153 | /** compute real part from norm/phas components |
---|
| 154 | |
---|
| 155 | \param spectrum norm/phas input array |
---|
| 156 | \param compspec real/imag output fft array |
---|
[f88a326] | 157 | |
---|
[aadd27a] | 158 | */ |
---|
| 159 | void aubio_fft_get_real(cvec_t * spectrum, fvec_t * compspec); |
---|
[f88a326] | 160 | |
---|
[96fb8ad] | 161 | #ifdef __cplusplus |
---|
| 162 | } |
---|
| 163 | #endif |
---|
| 164 | |
---|
[aadd27a] | 165 | #endif // FFT_H_ |
---|