xue@11
|
1 /*
|
xue@11
|
2 Harmonic sinusoidal modelling and tools
|
xue@11
|
3
|
xue@11
|
4 C++ code package for harmonic sinusoidal modelling and relevant signal processing.
|
xue@11
|
5 Centre for Digital Music, Queen Mary, University of London.
|
xue@11
|
6 This file copyright 2011 Wen Xue.
|
xue@11
|
7
|
xue@11
|
8 This program is free software; you can redistribute it and/or
|
xue@11
|
9 modify it under the terms of the GNU General Public License as
|
xue@11
|
10 published by the Free Software Foundation; either version 2 of the
|
xue@11
|
11 License, or (at your option) any later version.
|
xue@11
|
12 */
|
xue@1
|
13 #ifndef fftH
|
xue@1
|
14 #define fftH
|
xue@1
|
15
|
Chris@5
|
16 /**
|
Chris@5
|
17 \file fft.h - fast Fourier and cosine transforms
|
xue@1
|
18
|
xue@1
|
19 Arguments of the function in this unit roughly follow the following rules:
|
xue@1
|
20 Wid : size of transform
|
xue@1
|
21 Order : log2(Wid)
|
xue@1
|
22 W : FFT buffer: twiddle factors, standard size Wid/2
|
xue@1
|
23 X : FFT buffer: data buffer, standard size Wid
|
xue@1
|
24 bitinv: FFT buffer: table of bit-inversed integers, standard size Wid
|
xue@1
|
25 Window: window function, standard size Wid
|
xue@1
|
26 spec : complex spectrogram
|
xue@1
|
27 Amp : amplitude spectrogram
|
xue@1
|
28 Arg : phase spectrogram
|
xue@1
|
29 prefix h- : half-size
|
xue@1
|
30 prefix q- : quarter-size
|
xue@1
|
31 */
|
xue@1
|
32
|
xue@1
|
33
|
xue@1
|
34 #include <math.h>
|
xue@1
|
35 #include "xcomplex.h"
|
xue@1
|
36 #include "align8.h"
|
xue@1
|
37
|
xue@1
|
38 //---------------------------------------------------------------------------
|
Chris@5
|
39 /**
|
xue@1
|
40 macro AllocateFFTBuffer: allocates FFT buffers X and W of given length with an extra LDATA buffer the
|
xue@1
|
41 right size for hosting such arrays as the standard-size window function or output amplitude spectrum.
|
xue@1
|
42
|
xue@1
|
43 This macro allocates buffer with 64-bit alignment, which must be freed with free8() or FreeFFTBuffer
|
xue@1
|
44 macro.
|
xue@1
|
45 */
|
xue@1
|
46 #define AllocateFFTBuffer(_WID, _LDATA, _W, _X) \
|
xue@1
|
47 double *_LDATA=(double*)malloc8(sizeof(double)*_WID*4); \
|
xue@1
|
48 cdouble *_X=(cdouble*)&_LDATA[_WID]; \
|
xue@1
|
49 cdouble *_W=(cdouble*)&_X[_WID]; \
|
xue@1
|
50 SetTwiddleFactors(_WID, _W);
|
xue@1
|
51 #define FreeFFTBuffer(_LDATA) free8(_LDATA);
|
xue@1
|
52
|
xue@1
|
53 //--compelx FFT and IFFT-----------------------------------------------------
|
xue@1
|
54 void CFFTCbii(int Order, cdouble* W, cdouble* X); //complex FFT subroutine after bit-inversed ordering
|
xue@1
|
55 void CFFTC(int Order, cdouble* W, cdouble* X, int* bitinv=0); //complex FFT, compact in-place
|
xue@1
|
56 void CFFTC(cdouble* Input, double* Amp, double *Arg, int Order, cdouble* W, cdouble* X, int* bitinv=0); //complex FFT
|
xue@1
|
57 void CFFTCW(double* Window, int Order, cdouble* W, cdouble* X, int* bitinv=0); //complex FFT with window, compact in-place
|
xue@1
|
58 void CFFTCW(cdouble* Input, double* Window, double *Amp, double *Arg, int Order, cdouble* W, cdouble* X, int* bitinv=0); //complex FFT with window
|
xue@1
|
59 void CIFFTC(int Order, cdouble* W, cdouble* X, int* bitinv=0); //complex IFFT, compact in-place
|
xue@1
|
60 void CIFFTC(cdouble* Input, int Order, cdouble* W, cdouble* X, int* bitinv=0); //complex IFFT
|
xue@1
|
61
|
xue@1
|
62 //--real FFT and IFFT--------------------------------------------------------
|
xue@1
|
63 void RFFTC_ual(double* Input, double* Amp, double* Arg, int Order, cdouble* W, cdouble* X, int* hbitinv=0); //real-to-complex FFT
|
xue@1
|
64 void RFFTC_ual_old(double* Input, double *Amp, double *Arg, int Order, cdouble* W, double* XR, double* XI, int* bitinv=0); //depreciated
|
xue@1
|
65 void RFFTCW(double* Input, double* Window, double *Amp, double *Arg, int Order, cdouble* W, cdouble* X, int* hbitinv=0); //real-to-complex FFT with window, double-type input
|
xue@1
|
66 void RFFTCW(__int16* Input, double* Window, double *Amp, double *Arg, int Order, cdouble* W, cdouble* X, int* hbitinv=0); //real-to-complex FFT with window, __int16 input
|
xue@1
|
67 void CIFFTR(cdouble* Input, int Order, cdouble* W, double* X, int* hbitinv=0); //complex-to-real IFFT
|
xue@1
|
68
|
xue@1
|
69 /*
|
xue@1
|
70 macro RFFTC: was defined as RFFTC_ual (literally "unaligned RFFTC") enveloped by ALIGN8(). However, as
|
xue@1
|
71 ALIGN8() is currently disabled for lack of compiler support, RFFTC is equivalent to RFFTC_ual.
|
xue@1
|
72 */
|
xue@1
|
73 #define RFFTC(Input, Amp, Arg, Order, W, X, hbitinv) RFFTC_ual(Input, Amp, Arg, Order, W, X, hbitinv);
|
xue@1
|
74
|
xue@1
|
75 //--MFT----------------------------------------------------------------------
|
xue@1
|
76 void CMFTC(double* xR, double* xI, int Order, cdouble** X, cdouble* W); //complex fast multiresolution FT
|
xue@1
|
77
|
xue@1
|
78 //--DCT and IDCT-------------------------------------------------------------
|
xue@1
|
79 void RDCT1(double* Input, double* Output, int Order, cdouble* qW, cdouble* qX, int* qbitinv=0); //DCT1
|
xue@1
|
80 void RDCT4(double* Input, double* Output, int Order, cdouble* hW, cdouble* hX, int* hbitinv=0); //DCT4
|
xue@1
|
81 void RIDCT1(double* Input, double* Output, int Order, cdouble* qW, cdouble* qX, int* qbitinv=0); //IDCT1
|
xue@1
|
82 void RIDCT4(double* Input, double* Output, int Order, cdouble* hW, cdouble* hX, int* hbitinv=0); //IDCT4
|
xue@1
|
83
|
xue@1
|
84 //--LCT----------------------------------------------------------------------
|
xue@1
|
85 void RLCT(double** spec, double* data, int Count, int Order, int wid, double* g); //local cosine transform
|
xue@1
|
86 void RILCT(double* data, double** spec, int Fr, int Order, int wid, double* g); //inverse local cosine transform
|
xue@1
|
87
|
xue@1
|
88 //--tools--------------------------------------------------------------------
|
xue@1
|
89 double Atan2(double, double);
|
xue@11
|
90 int Log2(int);
|
xue@1
|
91 int* CreateBitInvTable(int Order); //creates table of bit-inversed integers
|
xue@1
|
92 void SetTwiddleFactors(int N, cdouble* w); //set twiddle factors
|
xue@1
|
93
|
xue@1
|
94
|
xue@1
|
95 #endif
|