| 1 |
/* |
| 2 |
* Copyright (c) 2003-2004, Mark Borgerding. All rights reserved. |
| 3 |
* This file is part of KISS FFT - https://github.com/mborgerding/kissfft |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: BSD-3-Clause |
| 6 |
* See COPYING file for more information. |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "kiss_fftndr.h"cxx . . $ `<file>/kiss_fftndr.h`/ |
| 10 |
#include "_kiss_fft_guts.h"cxx . . $ `<file>/_kiss_fft_guts.h`/ |
| 11 |
#define MAXcxx . . $ `kiss_fftndr.c:11:9`!(x,y) ( ( (x)<(y) )?(y):(x) ) |
| 12 |
|
| 13 |
struct kiss_fftndr_statecxx . . $ kiss_fftndr_state# |
| 14 |
{ |
| 15 |
int dimRealcxx . . $ kiss_fftndr_state#dimReal.; |
| •16 |
size_t dimOthercxx . . $ kiss_fftndr_state#dimOther.; |
| 17 |
kiss_fftr_cfgcxx . . $ kiss_fftr_cfg# cfg_rcxx . . $ kiss_fftndr_state#cfg_r.; |
| 18 |
kiss_fftnd_cfgcxx . . $ kiss_fftnd_cfg# cfg_ndcxx . . $ kiss_fftndr_state#cfg_nd.; |
| 19 |
void * tmpbufcxx . . $ kiss_fftndr_state#tmpbuf.; |
| 20 |
}; |
| 21 |
|
| •22 |
static size_t prodcxx . . $ prod(5900f7b8979368f5).(const int *dims, int ndims) |
| 23 |
{ |
| •24 |
size_t x=1; |
| 25 |
while (ndims--) |
| 26 |
x *= *dims++; |
| 27 |
return x; |
| 28 |
} |
| 29 |
|
| 30 |
kiss_fftndr_cfgcxx . . $ kiss_fftndr_cfg# kiss_fftndr_alloccxx . . $ kiss_fftndr_alloc(a5e88b44421e0326).(const int *dims,int ndims,int inverse_fft,void*mem,size_t*lenmem) |
| 31 |
{ |
| 32 |
KISS_FFT_ALIGN_CHECKcxx . . $ `kiss_fft.h:62:10`!(mem) |
| 33 |
|
| 34 |
kiss_fftndr_cfgcxx . . $ kiss_fftndr_cfg# st = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 35 |
size_t nr=0 , nd=0,ntmp=0; |
| 36 |
int dimReal = dims[ndims-1]; |
| •37 |
size_t dimOther = prodcxx . . $ prod(5900f7b8979368f5).(dims,ndims-1); |
| 38 |
size_t memneeded; |
| 39 |
char * ptr = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| •40 |
int k,check; |
| 41 |
|
| 42 |
(void)kiss_fftr_alloccxx . . $ kiss_fftr_alloc(5e9ec683d8ff9e6e).(dimReal,inverse_fft,NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!,&nr); |
| 43 |
(void)kiss_fftnd_alloccxx . . $ kiss_fftnd_alloc(aa249768aba330b0).(dims,ndims-1,inverse_fft,NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!,&nd); |
| 44 |
ntmp = |
| 45 |
MAXcxx . . $ `kiss_fftndr.c:11:9`!( 2*dimOther , dimReal+2) * sizeof(kiss_fft_scalarcxx . . $ `<built-in>:410:9`!) // freq buffer for one pass |
| •46 |
+ dimOther*(size_t)(dimReal+2) * sizeof(kiss_fft_scalarcxx . . $ `<built-in>:410:9`!); // large enough to hold entire input in case of in-place |
| 47 |
|
| 48 |
memneeded = KISS_FFT_ALIGN_SIZE_UPcxx . . $ `kiss_fft.h:63:10`!(sizeof( struct kiss_fftndr_state )) + KISS_FFT_ALIGN_SIZE_UPcxx . . $ `kiss_fft.h:63:10`!(nr) + KISS_FFT_ALIGN_SIZE_UPcxx . . $ `kiss_fft.h:63:10`!(nd) + KISS_FFT_ALIGN_SIZE_UPcxx . . $ `kiss_fft.h:63:10`!(ntmp); |
| 49 |
|
| •50 |
/* check for overflow */ |
| 51 |
check = memneeded; |
| 52 |
for (k=0;k<ndims;++k) { |
| 53 |
check /= dims[k]; |
| 54 |
if (check <= sizeof(kiss_fft_scalarcxx . . $ `<built-in>:410:9`!)) { |
| 55 |
if (lenmem!=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 56 |
*lenmem = (size_t)(-1); |
| 57 |
return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
if (lenmem==NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 62 |
ptr = (char*) malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(memneeded); |
| 63 |
}else{ |
| 64 |
if (*lenmem >= memneeded) |
| 65 |
ptr = (char *)mem; |
| 66 |
*lenmem = memneeded; |
| 67 |
} |
| 68 |
if (ptr==NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 69 |
return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 70 |
|
| 71 |
st = (kiss_fftndr_cfgcxx . . $ kiss_fftndr_cfg#) ptr; |
| 72 |
memsetcxx . . $ memset(d1de1e4fb215f1c6).( st , 0 , memneeded); |
| 73 |
ptr += KISS_FFT_ALIGN_SIZE_UPcxx . . $ `kiss_fft.h:63:10`!(sizeof(struct kiss_fftndr_state)); |
| 74 |
|
| 75 |
st->dimRealcxx . . $ kiss_fftndr_state#dimReal. = dimReal; |
| 76 |
st->dimOthercxx . . $ kiss_fftndr_state#dimOther. = dimOther; |
| 77 |
st->cfg_rcxx . . $ kiss_fftndr_state#cfg_r. = kiss_fftr_alloccxx . . $ kiss_fftr_alloc(5e9ec683d8ff9e6e).( dimReal,inverse_fft,ptr,&nr); |
| 78 |
ptr += KISS_FFT_ALIGN_SIZE_UPcxx . . $ `kiss_fft.h:63:10`!(nr); |
| 79 |
st->cfg_ndcxx . . $ kiss_fftndr_state#cfg_nd. = kiss_fftnd_alloccxx . . $ kiss_fftnd_alloc(aa249768aba330b0).(dims,ndims-1,inverse_fft, ptr,&nd); |
| 80 |
ptr += KISS_FFT_ALIGN_SIZE_UPcxx . . $ `kiss_fft.h:63:10`!(nd); |
| 81 |
st->tmpbufcxx . . $ kiss_fftndr_state#tmpbuf. = ptr; |
| 82 |
|
| 83 |
return st; |
| 84 |
} |
| 85 |
|
| 86 |
void kiss_fftndrcxx . . $ kiss_fftndr(c734ace5caf1cadf).(kiss_fftndr_cfgcxx . . $ kiss_fftndr_cfg# st,const kiss_fft_scalarcxx . . $ `<built-in>:410:9`! *timedata,kiss_fft_cpxcxx . . $ kiss_fft_cpx# *freqdata) |
| 87 |
{ |
| •88 |
size_t k1,k2; |
| 89 |
size_t dimReal = (size_t)st->dimRealcxx . . $ kiss_fftndr_state#dimReal.; |
| 90 |
size_t dimOther = st->dimOthercxx . . $ kiss_fftndr_state#dimOther.; |
| 91 |
int nrbins = dimReal/2+1; |
| 92 |
|
| 93 |
kiss_fft_cpxcxx . . $ kiss_fft_cpx# * tmp1 = (kiss_fft_cpxcxx . . $ kiss_fft_cpx#*)st->tmpbufcxx . . $ kiss_fftndr_state#tmpbuf.; |
| 94 |
kiss_fft_cpxcxx . . $ kiss_fft_cpx# * tmp2 = tmp1 + MAXcxx . . $ `kiss_fftndr.c:11:9`!(nrbins,dimOther); |
| 95 |
|
| 96 |
// timedata is N0 x N1 x ... x Nk real |
| 97 |
|
| 98 |
// take a real chunk of data, fft it and place the output at correct intervals |
| 99 |
for (k1=0;k1<dimOther;++k1) { |
| 100 |
kiss_fftrcxx . . $ kiss_fftr(ea85e744e2f2ed88).( st->cfg_rcxx . . $ kiss_fftndr_state#cfg_r., timedata + k1*dimReal , tmp1 ); // tmp1 now holds nrbins complex points |
| 101 |
for (k2=0;k2<nrbins;++k2) |
| 102 |
tmp2[ k2*dimOther+k1 ] = tmp1[k2]; |
| 103 |
} |
| 104 |
|
| 105 |
for (k2=0;k2<nrbins;++k2) { |
| 106 |
kiss_fftndcxx . . $ kiss_fftnd(ce145cadff9ba0b6).(st->cfg_ndcxx . . $ kiss_fftndr_state#cfg_nd., tmp2+k2*dimOther, tmp1); // tmp1 now holds dimOther complex points |
| 107 |
for (k1=0;k1<dimOther;++k1) |
| 108 |
freqdata[ k1*(nrbins) + k2] = tmp1[k1]; |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
void kiss_fftndricxx . . $ kiss_fftndri(648a49e7292feedf).(kiss_fftndr_cfgcxx . . $ kiss_fftndr_cfg# st,const kiss_fft_cpxcxx . . $ kiss_fft_cpx# *freqdata,kiss_fft_scalarcxx . . $ `<built-in>:410:9`! *timedata) |
| 113 |
{ |
| 114 |
int k1,k2; |
| 115 |
int dimReal = st->dimRealcxx . . $ kiss_fftndr_state#dimReal.; |
| 116 |
int dimOther = st->dimOthercxx . . $ kiss_fftndr_state#dimOther.; |
| 117 |
int nrbins = dimReal/2+1; |
| 118 |
kiss_fft_cpxcxx . . $ kiss_fft_cpx# * tmp1 = (kiss_fft_cpxcxx . . $ kiss_fft_cpx#*)st->tmpbufcxx . . $ kiss_fftndr_state#tmpbuf.; |
| 119 |
kiss_fft_cpxcxx . . $ kiss_fft_cpx# * tmp2 = tmp1 + MAXcxx . . $ `kiss_fftndr.c:11:9`!(nrbins,dimOther); |
| 120 |
|
| 121 |
for (k2=0;k2<nrbins;++k2) { |
| 122 |
for (k1=0;k1<dimOther;++k1) |
| 123 |
tmp1[k1] = freqdata[ k1*(nrbins) + k2 ]; |
| 124 |
kiss_fftndcxx . . $ kiss_fftnd(ce145cadff9ba0b6).(st->cfg_ndcxx . . $ kiss_fftndr_state#cfg_nd., tmp1, tmp2+k2*dimOther); |
| 125 |
} |
| 126 |
|
| 127 |
for (k1=0;k1<dimOther;++k1) { |
| 128 |
for (k2=0;k2<nrbins;++k2) |
| 129 |
tmp1[k2] = tmp2[ k2*dimOther+k1 ]; |
| 130 |
kiss_fftricxx . . $ kiss_fftri(8294ed4e0de8aee5).( st->cfg_rcxx . . $ kiss_fftndr_state#cfg_r.,tmp1,timedata + k1*dimReal); |
| 131 |
} |
| 132 |
} |