21 kiss_fft_cfg substate;
29kiss_fftr_cfg kiss_fftr_alloc(
int nfft,
int inverse_fft,
void * mem,
size_t * lenmem)
32 kiss_fftr_cfg st = NULL;
33 size_t subsize = 0, memneeded;
36 fprintf(stderr,
"Real FFT optimization must be even.\n");
45 st = (kiss_fftr_cfg) KISS_FFT_MALLOC (memneeded);
47 if (*lenmem >= memneeded)
48 st = (kiss_fftr_cfg) mem;
54 st->substate = (kiss_fft_cfg) (st + 1);
55 st->tmpbuf = (
kiss_fft_cpx *) (((
char *) st->substate) + subsize);
56 st->super_twiddles = st->tmpbuf + nfft;
59 for (i = 0; i < nfft/2; ++i) {
61 -3.14159265358979323846264338327 * ((double) (i+1) / nfft + .5);
64 kf_cexp (st->super_twiddles+i,phase);
69void kiss_fftr(kiss_fftr_cfg st,
const kiss_fft_scalar *timedata,
kiss_fft_cpx *freqdata)
75 if ( st->substate->inverse) {
76 fprintf(stderr,
"kiss fft usage error: improper alloc\n");
80 ncfft = st->substate->nfft;
94 tdc.r = st->tmpbuf[0].r;
95 tdc.i = st->tmpbuf[0].i;
97 CHECK_OVERFLOW_OP(tdc.r ,+, tdc.i);
98 CHECK_OVERFLOW_OP(tdc.r ,-, tdc.i);
99 freqdata[0].r = tdc.r + tdc.i;
100 freqdata[ncfft].r = tdc.r - tdc.i;
102 freqdata[ncfft].i = freqdata[0].i = _mm_set1_ps(0);
104 freqdata[ncfft].i = freqdata[0].i = 0;
107 for ( k=1;k <= ncfft/2 ; ++k ) {
109 fpnk.r = st->tmpbuf[ncfft-k].r;
110 fpnk.i = - st->tmpbuf[ncfft-k].i;
114 C_ADD( f1k, fpk , fpnk );
115 C_SUB( f2k, fpk , fpnk );
116 C_MUL( tw , f2k , st->super_twiddles[k-1]);
118 freqdata[k].r = HALF_OF(f1k.r + tw.r);
119 freqdata[k].i = HALF_OF(f1k.i + tw.i);
120 freqdata[ncfft-k].r = HALF_OF(f1k.r - tw.r);
121 freqdata[ncfft-k].i = HALF_OF(tw.i - f1k.i);
125void kiss_fftri(kiss_fftr_cfg st,
const kiss_fft_cpx *freqdata,kiss_fft_scalar *timedata)
130 if (st->substate->inverse == 0) {
131 fprintf (stderr,
"kiss fft usage error: improper alloc\n");
135 ncfft = st->substate->nfft;
137 st->tmpbuf[0].r = freqdata[0].r + freqdata[ncfft].r;
138 st->tmpbuf[0].i = freqdata[0].r - freqdata[ncfft].r;
139 C_FIXDIV(st->tmpbuf[0],2);
141 for (k = 1; k <= ncfft / 2; ++k) {
144 fnkc.r = freqdata[ncfft - k].r;
145 fnkc.i = -freqdata[ncfft - k].i;
147 C_FIXDIV( fnkc , 2 );
149 C_ADD (fek, fk, fnkc);
150 C_SUB (tmp, fk, fnkc);
151 C_MUL (fok, tmp, st->super_twiddles[k-1]);
152 C_ADD (st->tmpbuf[k], fek, fok);
153 C_SUB (st->tmpbuf[ncfft - k], fek, fok);
155 st->tmpbuf[ncfft - k].i *= _mm_set1_ps(-1.0);
157 st->tmpbuf[ncfft - k].i *= -1;
KISS FFT internals, taken from: https://github.com/mborgerding/kissfft.
void kiss_fft(kiss_fft_cfg cfg, const kiss_fft_cpx *fin, kiss_fft_cpx *fout)
kiss_fft(cfg,in_out_buf)
kiss_fft_cfg kiss_fft_alloc(int nfft, int inverse_fft, void *mem, size_t *lenmem)
kiss_fft_alloc
The default real <-> half-complex FFT.
Complex data type used by kissFFT.
Internal KissFFT structure.