| 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_fft_guts.h"cxx . . $ `<file>/_kiss_fft_guts.h`/ |
| 10 |
|
| 11 |
|
| 12 |
/* |
| 13 |
Some definitions that allow real or complex filtering |
| 14 |
*/ |
| 15 |
#ifdef REAL_FASTFIRcxx . . $ `<built-in>:414:9`! |
| 16 |
#define MIN_FFT_LENcxx . . $ `tools/kiss_fastfir.c:16:9`! 2048 |
| 17 |
#include "kiss_fftr.h"cxx . . $ `<file>/kiss_fftr.h`/ |
| 18 |
typedef kiss_fft_scalarcxx . . $ `<built-in>:412:9`! kffsamp_tcxx . . $ kffsamp_t#; |
| 19 |
typedef kiss_fftr_cfgcxx . . $ kiss_fftr_cfg# kfcfg_tcxx . . $ kfcfg_t#; |
| 20 |
#define FFT_ALLOCcxx . . $ `tools/kiss_fastfir.c:20:9`! kiss_fftr_alloc |
| 21 |
#define FFTFWDcxx . . $ `tools/kiss_fastfir.c:21:9`! kiss_fftr |
| 22 |
#define FFTINVcxx . . $ `tools/kiss_fastfir.c:22:9`! kiss_fftri |
| 23 |
#else |
| 24 |
#define MIN_FFT_LENcxx . . $ `tools/kiss_fastfir.c:24:9`! 1024 |
| 25 |
typedef kiss_fft_cpxcxx . . $ kiss_fft_cpx# kffsamp_tcxx . . $ kffsamp_t#; |
| 26 |
typedef kiss_fft_cfgcxx . . $ kiss_fft_cfg# kfcfg_tcxx . . $ kfcfg_t#; |
| 27 |
#define FFT_ALLOCcxx . . $ `tools/kiss_fastfir.c:27:9`! kiss_fft_alloc |
| 28 |
#define FFTFWDcxx . . $ `tools/kiss_fastfir.c:28:9`! kiss_fft |
| 29 |
#define FFTINVcxx . . $ `tools/kiss_fastfir.c:29:9`! kiss_fft |
| 30 |
#endif |
| 31 |
|
| 32 |
typedef struct kiss_fastfir_statecxx . . $ kiss_fastfir_state# *kiss_fastfir_cfgcxx . . $ kiss_fastfir_cfg#; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
kiss_fastfir_cfgcxx . . $ kiss_fastfir_cfg# kiss_fastfir_alloccxx . . $ kiss_fastfir_alloc(ac78e89c690b9f1a).(const kffsamp_tcxx . . $ kffsamp_t# * imp_resp,size_tcxx . . $ size_t# n_imp_resp, |
| 37 |
size_tcxx . . $ size_t# * nfft,void * mem,size_tcxx . . $ size_t#*lenmem); |
| 38 |
|
| 39 |
/* see do_file_filter for usage */ |
| 40 |
size_tcxx . . $ size_t# kiss_fastfircxx . . $ kiss_fastfir(c3735b1f408c6acc).( kiss_fastfir_cfgcxx . . $ kiss_fastfir_cfg# cfg, kffsamp_tcxx . . $ kffsamp_t# * inbuf, kffsamp_tcxx . . $ kffsamp_t# * outbuf, size_tcxx . . $ size_t# n, size_tcxx . . $ size_t# *offset); |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
struct kiss_fastfir_statecxx . . $ kiss_fastfir_state#{ |
| 47 |
size_tcxx . . $ size_t# nfftcxx . . $ kiss_fastfir_state#nfft.; |
| 48 |
size_tcxx . . $ size_t# ngoodcxx . . $ kiss_fastfir_state#ngood.; |
| 49 |
kfcfg_tcxx . . $ kfcfg_t# fftcfgcxx . . $ kiss_fastfir_state#fftcfg.; |
| 50 |
kfcfg_tcxx . . $ kfcfg_t# ifftcfgcxx . . $ kiss_fastfir_state#ifftcfg.; |
| 51 |
kiss_fft_cpxcxx . . $ kiss_fft_cpx# * fir_freq_respcxx . . $ kiss_fastfir_state#fir_freq_resp.; |
| 52 |
kiss_fft_cpxcxx . . $ kiss_fft_cpx# * freqbufcxx . . $ kiss_fastfir_state#freqbuf.; |
| 53 |
size_tcxx . . $ size_t# n_freq_binscxx . . $ kiss_fastfir_state#n_freq_bins.; |
| 54 |
kffsamp_tcxx . . $ kffsamp_t# * tmpbufcxx . . $ kiss_fastfir_state#tmpbuf.; |
| 55 |
}; |
| 56 |
|
| 57 |
|
| 58 |
kiss_fastfir_cfgcxx . . $ kiss_fastfir_cfg# kiss_fastfir_alloccxx . . $ kiss_fastfir_alloc(ac78e89c690b9f1a).( |
| 59 |
const kffsamp_tcxx . . $ kffsamp_t# * imp_resp,size_tcxx . . $ size_t# n_imp_resp, |
| 60 |
size_tcxx . . $ size_t# *pnfft, /* if <= 0, an appropriate size will be chosen */ |
| 61 |
void * mem,size_tcxx . . $ size_t#*lenmem) |
| 62 |
{ |
| 63 |
kiss_fastfir_cfgcxx . . $ kiss_fastfir_cfg# st = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 64 |
size_tcxx . . $ size_t# len_fftcfg,len_ifftcfg; |
| 65 |
size_tcxx . . $ size_t# memneeded = sizeof(struct kiss_fastfir_statecxx . . $ kiss_fastfir_state#); |
| 66 |
char * ptr; |
| 67 |
size_tcxx . . $ size_t# i; |
| 68 |
size_tcxx . . $ size_t# nfft=0; |
| 69 |
float scale; |
| 70 |
size_tcxx . . $ size_t# n_freq_bins; |
| 71 |
if (pnfft) |
| 72 |
nfft=*pnfft; |
| 73 |
|
| 74 |
if (nfft<=0) { |
| 75 |
/* determine fft size as next power of two at least 2x |
| 76 |
the impulse response length*/ |
| 77 |
i=n_imp_resp-1; |
| 78 |
nfft=2; |
| 79 |
do{ |
| 80 |
nfft<<=1; |
| 81 |
}while (i>>=1); |
| 82 |
#ifdef MIN_FFT_LENcxx . . $ `tools/kiss_fastfir.c:24:9`! |
| 83 |
if ( nfft < MIN_FFT_LENcxx . . $ `tools/kiss_fastfir.c:16:9`! ) |
| 84 |
nfft=MIN_FFT_LENcxx . . $ `tools/kiss_fastfir.c:16:9`!; |
| 85 |
#endif |
| 86 |
} |
| 87 |
if (pnfft) |
| 88 |
*pnfft = nfft; |
| 89 |
|
| 90 |
#ifdef REAL_FASTFIRcxx . . $ `<built-in>:414:9`! |
| 91 |
n_freq_bins = nfft/2 + 1; |
| 92 |
#else |
| 93 |
n_freq_bins = nfft; |
| 94 |
#endif |
| 95 |
/*fftcfg*/ |
| 96 |
FFT_ALLOCcxx . . $ `tools/kiss_fastfir.c:27:9`! (nfft, 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, &len_fftcfg); |
| 97 |
memneeded += len_fftcfg; |
| 98 |
/*ifftcfg*/ |
| 99 |
FFT_ALLOCcxx . . $ `tools/kiss_fastfir.c:27:9`! (nfft, 1, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, &len_ifftcfg); |
| 100 |
memneeded += len_ifftcfg; |
| 101 |
/* tmpbuf */ |
| 102 |
memneeded += sizeof(kffsamp_tcxx . . $ kffsamp_t#) * nfft; |
| 103 |
/* fir_freq_resp */ |
| 104 |
memneeded += sizeof(kiss_fft_cpxcxx . . $ kiss_fft_cpx#) * n_freq_bins; |
| 105 |
/* freqbuf */ |
| 106 |
memneeded += sizeof(kiss_fft_cpxcxx . . $ kiss_fft_cpx#) * n_freq_bins; |
| 107 |
|
| 108 |
if (lenmem == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 109 |
st = (kiss_fastfir_cfgcxx . . $ kiss_fastfir_cfg#) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (memneeded); |
| 110 |
} else { |
| 111 |
if (*lenmem >= memneeded) |
| 112 |
st = (kiss_fastfir_cfgcxx . . $ kiss_fastfir_cfg#) mem; |
| 113 |
*lenmem = memneeded; |
| 114 |
} |
| 115 |
if (!st) |
| 116 |
return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 117 |
|
| 118 |
st->nfftcxx . . $ kiss_fastfir_state#nfft. = nfft; |
| 119 |
st->ngoodcxx . . $ kiss_fastfir_state#ngood. = nfft - n_imp_resp + 1; |
| 120 |
st->n_freq_binscxx . . $ kiss_fastfir_state#n_freq_bins. = n_freq_bins; |
| 121 |
ptr=(char*)(st+1); |
| 122 |
|
| 123 |
st->fftcfgcxx . . $ kiss_fastfir_state#fftcfg. = (kfcfg_tcxx . . $ kfcfg_t#)ptr; |
| 124 |
ptr += len_fftcfg; |
| 125 |
|
| 126 |
st->ifftcfgcxx . . $ kiss_fastfir_state#ifftcfg. = (kfcfg_tcxx . . $ kfcfg_t#)ptr; |
| 127 |
ptr += len_ifftcfg; |
| 128 |
|
| 129 |
st->tmpbufcxx . . $ kiss_fastfir_state#tmpbuf. = (kffsamp_tcxx . . $ kffsamp_t#*)ptr; |
| 130 |
ptr += sizeof(kffsamp_tcxx . . $ kffsamp_t#) * nfft; |
| 131 |
|
| 132 |
st->freqbufcxx . . $ kiss_fastfir_state#freqbuf. = (kiss_fft_cpxcxx . . $ kiss_fft_cpx#*)ptr; |
| 133 |
ptr += sizeof(kiss_fft_cpxcxx . . $ kiss_fft_cpx#) * n_freq_bins; |
| 134 |
|
| 135 |
st->fir_freq_respcxx . . $ kiss_fastfir_state#fir_freq_resp. = (kiss_fft_cpxcxx . . $ kiss_fft_cpx#*)ptr; |
| 136 |
ptr += sizeof(kiss_fft_cpxcxx . . $ kiss_fft_cpx#) * n_freq_bins; |
| 137 |
|
| 138 |
FFT_ALLOCcxx . . $ `tools/kiss_fastfir.c:27:9`! (nfft,0,st->fftcfgcxx . . $ kiss_fastfir_state#fftcfg. , &len_fftcfg); |
| 139 |
FFT_ALLOCcxx . . $ `tools/kiss_fastfir.c:27:9`! (nfft,1,st->ifftcfgcxx . . $ kiss_fastfir_state#ifftcfg. , &len_ifftcfg); |
| 140 |
|
| 141 |
memsetcxx . . $ memset(d1de1e4fb215f1c6).(st->tmpbufcxx . . $ kiss_fastfir_state#tmpbuf.,0,sizeof(kffsamp_tcxx . . $ kffsamp_t#)*nfft); |
| 142 |
/*zero pad in the middle to left-rotate the impulse response |
| 143 |
This puts the scrap samples at the end of the inverse fft'd buffer */ |
| 144 |
st->tmpbufcxx . . $ kiss_fastfir_state#tmpbuf.[0] = imp_resp[ n_imp_resp - 1 ]; |
| 145 |
for (i=0;i<n_imp_resp - 1; ++i) { |
| 146 |
st->tmpbufcxx . . $ kiss_fastfir_state#tmpbuf.[ nfft - n_imp_resp + 1 + i ] = imp_resp[ i ]; |
| 147 |
} |
| 148 |
|
| 149 |
FFTFWDcxx . . $ `tools/kiss_fastfir.c:28:9`!(st->fftcfgcxx . . $ kiss_fastfir_state#fftcfg.,st->tmpbufcxx . . $ kiss_fastfir_state#tmpbuf.,st->fir_freq_respcxx . . $ kiss_fastfir_state#fir_freq_resp.); |
| 150 |
|
| 151 |
/* TODO: this won't work for fixed point */ |
| 152 |
scale = 1.0f / st->nfftcxx . . $ kiss_fastfir_state#nfft.; |
| 153 |
|
| 154 |
for ( i=0; i < st->n_freq_binscxx . . $ kiss_fastfir_state#n_freq_bins.; ++i ) { |
| 155 |
#ifdef USE_SIMD |
| 156 |
st->fir_freq_resp[i].r *= _mm_set1_ps(scale); |
| 157 |
st->fir_freq_resp[i].i *= _mm_set1_ps(scale); |
| 158 |
#else |
| 159 |
st->fir_freq_respcxx . . $ kiss_fastfir_state#fir_freq_resp.[i].rcxx . . $ $anonymous_type_8e136e85b373da8_0#r. *= scale; |
| 160 |
st->fir_freq_respcxx . . $ kiss_fastfir_state#fir_freq_resp.[i].icxx . . $ $anonymous_type_8e136e85b373da8_0#i. *= scale; |
| 161 |
#endif |
| 162 |
} |
| 163 |
return st; |
| 164 |
} |
| 165 |
|
| 166 |
static void fastconv1bufcxx . . $ fastconv1buf(6d713c61351c8d6b).(const kiss_fastfir_cfgcxx . . $ kiss_fastfir_cfg# st,const kffsamp_tcxx . . $ kffsamp_t# * in,kffsamp_tcxx . . $ kffsamp_t# * out) |
| 167 |
{ |
| 168 |
size_tcxx . . $ size_t# i; |
| 169 |
/* multiply the frequency response of the input signal by |
| 170 |
that of the fir filter*/ |
| 171 |
FFTFWDcxx . . $ `tools/kiss_fastfir.c:21:9`!( st->fftcfgcxx . . $ kiss_fastfir_state#fftcfg., in , st->freqbufcxx . . $ kiss_fastfir_state#freqbuf. ); |
| 172 |
for ( i=0; i<st->n_freq_binscxx . . $ kiss_fastfir_state#n_freq_bins.; ++i ) { |
| 173 |
kiss_fft_cpxcxx . . $ kiss_fft_cpx# tmpsamp; |
| 174 |
C_MULcxx . . $ `_kiss_fft_guts.h:87:9`!(tmpsamp,st->freqbuf[i],st->fir_freq_resp[i]); |
| 175 |
st->freqbufcxx . . $ kiss_fastfir_state#freqbuf.[i] = tmpsamp; |
| 176 |
} |
| 177 |
|
| 178 |
/* perform the inverse fft*/ |
| 179 |
FFTINVcxx . . $ `tools/kiss_fastfir.c:22:9`!(st->ifftcfgcxx . . $ kiss_fastfir_state#ifftcfg.,st->freqbufcxx . . $ kiss_fastfir_state#freqbuf.,out); |
| 180 |
} |
| 181 |
|
| 182 |
/* n : the size of inbuf and outbuf in samples |
| 183 |
return value: the number of samples completely processed |
| 184 |
n-retval samples should be copied to the front of the next input buffer */ |
| 185 |
static size_tcxx . . $ size_t# kff_nocopycxx . . $ kff_nocopy(6f6b4ff0a1efce7f).( |
| 186 |
kiss_fastfir_cfgcxx . . $ kiss_fastfir_cfg# st, |
| 187 |
const kffsamp_tcxx . . $ kffsamp_t# * inbuf, |
| 188 |
kffsamp_tcxx . . $ kffsamp_t# * outbuf, |
| 189 |
size_tcxx . . $ size_t# n) |
| 190 |
{ |
| 191 |
size_tcxx . . $ size_t# norig=n; |
| 192 |
while (n >= st->nfftcxx . . $ kiss_fastfir_state#nfft. ) { |
| 193 |
fastconv1bufcxx . . $ fastconv1buf(b2b531c613c9ecb7).(st,inbuf,outbuf); |
| 194 |
inbuf += st->ngoodcxx . . $ kiss_fastfir_state#ngood.; |
| 195 |
outbuf += st->ngoodcxx . . $ kiss_fastfir_state#ngood.; |
| 196 |
n -= st->ngoodcxx . . $ kiss_fastfir_state#ngood.; |
| 197 |
} |
| 198 |
return norig - n; |
| 199 |
} |
| 200 |
|
| 201 |
static |
| 202 |
size_tcxx . . $ size_t# kff_flushcxx . . $ kff_flush(d8a0161f347e8c1f).(kiss_fastfir_cfgcxx . . $ kiss_fastfir_cfg# st,const kffsamp_tcxx . . $ kffsamp_t# * inbuf,kffsamp_tcxx . . $ kffsamp_t# * outbuf,size_tcxx . . $ size_t# n) |
| 203 |
{ |
| 204 |
size_tcxx . . $ size_t# zpad=0,ntmp; |
| 205 |
|
| 206 |
ntmp = kff_nocopycxx . . $ kff_nocopy(6f6b4ff0a1efce7f).(st,inbuf,outbuf,n); |
| 207 |
n -= ntmp; |
| 208 |
inbuf += ntmp; |
| 209 |
outbuf += ntmp; |
| 210 |
|
| 211 |
zpad = st->nfftcxx . . $ kiss_fastfir_state#nfft. - n; |
| 212 |
memsetcxx . . $ memset(d1de1e4fb215f1c6).(st->tmpbufcxx . . $ kiss_fastfir_state#tmpbuf.,0,sizeof(kffsamp_tcxx . . $ kffsamp_t#)*st->nfftcxx . . $ kiss_fastfir_state#nfft. ); |
| 213 |
memcpycxx . . $ memcpy(cc817cb175f282d).(st->tmpbufcxx . . $ kiss_fastfir_state#tmpbuf.,inbuf,sizeof(kffsamp_tcxx . . $ kffsamp_t#)*n ); |
| 214 |
|
| 215 |
fastconv1bufcxx . . $ fastconv1buf(b2b531c613c9ecb7).(st,st->tmpbufcxx . . $ kiss_fastfir_state#tmpbuf.,st->tmpbufcxx . . $ kiss_fastfir_state#tmpbuf.); |
| 216 |
|
| 217 |
memcpycxx . . $ memcpy(cc817cb175f282d).(outbuf,st->tmpbufcxx . . $ kiss_fastfir_state#tmpbuf.,sizeof(kffsamp_tcxx . . $ kffsamp_t#)*( st->ngoodcxx . . $ kiss_fastfir_state#ngood. - zpad )); |
| 218 |
return ntmp + st->ngoodcxx . . $ kiss_fastfir_state#ngood. - zpad; |
| 219 |
} |
| 220 |
|
| 221 |
size_tcxx . . $ size_t# kiss_fastfircxx . . $ kiss_fastfir(c3735b1f408c6acc).( |
| 222 |
kiss_fastfir_cfgcxx . . $ kiss_fastfir_cfg# vst, |
| 223 |
kffsamp_tcxx . . $ kffsamp_t# * inbuf, |
| 224 |
kffsamp_tcxx . . $ kffsamp_t# * outbuf, |
| 225 |
size_tcxx . . $ size_t# n_new, |
| 226 |
size_tcxx . . $ size_t# *offset) |
| 227 |
{ |
| 228 |
size_tcxx . . $ size_t# ntot = n_new + *offset; |
| 229 |
if (n_new==0) { |
| 230 |
return kff_flushcxx . . $ kff_flush(d8a0161f347e8c1f).(vst,inbuf,outbuf,ntot); |
| 231 |
}else{ |
| 232 |
size_tcxx . . $ size_t# nwritten = kff_nocopycxx . . $ kff_nocopy(6f6b4ff0a1efce7f).(vst,inbuf,outbuf,ntot); |
| 233 |
*offset = ntot - nwritten; |
| 234 |
/*save the unused or underused samples at the front of the input buffer */ |
| 235 |
memcpycxx . . $ memcpy(cc817cb175f282d).( inbuf , inbuf+nwritten , *offset * sizeof(kffsamp_tcxx . . $ kffsamp_t#) ); |
| 236 |
return nwritten; |
| 237 |
} |
| 238 |
} |
| 239 |
|
| 240 |
#ifdef FAST_FILT_UTILcxx . . $ `<built-in>:414:9`! |
| 241 |
#include <unistd.h> |
| 242 |
#include <sys/types.h> |
| 243 |
#include <sys/mman.h> |
| 244 |
#include <assert.h> |
| 245 |
|
| •246 |
static int verbosecxx . . $ verbose.=0; |
| 247 |
|
| 248 |
static |
| 249 |
void direct_file_filtercxx . . $ direct_file_filter(2f4d65125b8eaf0e).( |
| 250 |
FILEcxx . . $ FILE# * fin, |
| 251 |
FILEcxx . . $ FILE# * fout, |
| 252 |
const kffsamp_tcxx . . $ kffsamp_t# * imp_resp, |
| 253 |
size_tcxx . . $ size_t# n_imp_resp) |
| 254 |
{ |
| 255 |
size_tcxx . . $ size_t# nlag = n_imp_resp - 1; |
| 256 |
|
| 257 |
const kffsamp_tcxx . . $ kffsamp_t# *tmph; |
| 258 |
kffsamp_tcxx . . $ kffsamp_t# *buf, *circbuf; |
| 259 |
kffsamp_tcxx . . $ kffsamp_t# outval; |
| 260 |
size_tcxx . . $ size_t# nread; |
| 261 |
size_tcxx . . $ size_t# nbuf; |
| 262 |
size_tcxx . . $ size_t# oldestlag = 0; |
| 263 |
size_tcxx . . $ size_t# k, tap; |
| 264 |
#ifndef REAL_FASTFIRcxx . . $ `<built-in>:414:9`! |
| 265 |
kffsamp_tcxx . . $ kffsamp_t# tmp; |
| 266 |
#endif |
| 267 |
|
| 268 |
nbuf = 4096; |
| 269 |
buf = (kffsamp_tcxx . . $ kffsamp_t# *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). ( sizeof (kffsamp_tcxx . . $ kffsamp_t#) * nbuf); |
| 270 |
circbuf = (kffsamp_tcxx . . $ kffsamp_t# *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (sizeof (kffsamp_tcxx . . $ kffsamp_t#) * nlag); |
| 271 |
if (!circbuf || !buf) { |
| 272 |
perrorcxx . . $ perror(85c52e162fed56f9).("circbuf allocation"); |
| 273 |
exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 274 |
} |
| 275 |
|
| 276 |
if ( freadcxx . . $ fread(738fc8ac1d711e58). (circbuf, sizeof (kffsamp_tcxx . . $ kffsamp_t#), nlag, fin) != nlag ) { |
| 277 |
perrorcxx . . $ perror(85c52e162fed56f9). ("insufficient data to overcome transient"); |
| 278 |
exitcxx . . $ exit(3ca292c338df9bb3). (1); |
| 279 |
} |
| 280 |
|
| 281 |
do { |
| 282 |
nread = freadcxx . . $ fread(738fc8ac1d711e58). (buf, sizeof (kffsamp_tcxx . . $ kffsamp_t#), nbuf, fin); |
| 283 |
if (nread <= 0) |
| 284 |
break; |
| 285 |
|
| 286 |
for (k = 0; k < nread; ++k) { |
| 287 |
tmph = imp_resp+nlag; |
| 288 |
#ifdef REAL_FASTFIRcxx . . $ `<built-in>:414:9`! |
| 289 |
# ifdef USE_SIMD |
| 290 |
outval = _mm_set1_ps(0); |
| 291 |
#else |
| 292 |
outval = 0; |
| 293 |
#endif |
| 294 |
for (tap = oldestlag; tap < nlag; ++tap) |
| 295 |
outval += circbuf[tap] * *tmph--; |
| 296 |
for (tap = 0; tap < oldestlag; ++tap) |
| 297 |
outval += circbuf[tap] * *tmph--; |
| 298 |
outval += buf[k] * *tmph; |
| 299 |
#else |
| 300 |
# ifdef USE_SIMD |
| 301 |
outval.r = outval.i = _mm_set1_ps(0); |
| 302 |
#else |
| 303 |
outval.rcxx . . $ $anonymous_type_8e136e85b373da8_0#r. = outval.icxx . . $ $anonymous_type_8e136e85b373da8_0#i. = 0; |
| 304 |
#endif |
| 305 |
for (tap = oldestlag; tap < nlag; ++tap){ |
| 306 |
C_MULcxx . . $ `_kiss_fft_guts.h:87:9`!(tmp,circbuf[tap],*tmph); |
| 307 |
--tmph; |
| 308 |
C_ADDTOcxx . . $ `_kiss_fft_guts.h:112:9`!(outval,tmp); |
| 309 |
} |
| 310 |
|
| 311 |
for (tap = 0; tap < oldestlag; ++tap) { |
| 312 |
C_MULcxx . . $ $anonymous_type_8e136e85b373da8_0#r.(tmp,circbuf[tap],*tmph); |
| 313 |
--tmph; |
| 314 |
C_ADDTOcxx . . $ $anonymous_type_8e136e85b373da8_0#r.(outval,tmp); |
| 315 |
} |
| 316 |
C_MULcxx . . $ $anonymous_type_8e136e85b373da8_0#r.(tmp,buf[k],*tmph); |
| 317 |
C_ADDTOcxx . . $ $anonymous_type_8e136e85b373da8_0#i.(outval,tmp); |
| 318 |
#endif |
| 319 |
|
| 320 |
circbuf[oldestlag++] = buf[k]; |
| 321 |
buf[k] = outval; |
| 322 |
|
| 323 |
if (oldestlag == nlag) |
| 324 |
oldestlag = 0; |
| 325 |
} |
| 326 |
|
| 327 |
if (fwritecxx . . $ fwrite(ab0609fa07c47d6e). (buf, sizeof (buf[0]), nread, fout) != nread) { |
| 328 |
perrorcxx . . $ perror(85c52e162fed56f9). ("short write"); |
| 329 |
exitcxx . . $ exit(3ca292c338df9bb3). (1); |
| 330 |
} |
| 331 |
} while (nread); |
| 332 |
freecxx . . $ free(5d22bdacc48458e8). (buf); |
| 333 |
freecxx . . $ free(5d22bdacc48458e8). (circbuf); |
| 334 |
} |
| 335 |
|
| 336 |
static |
| 337 |
void do_file_filtercxx . . $ do_file_filter(1e120cbd3066ca79).( |
| 338 |
FILEcxx . . $ FILE# * fin, |
| 339 |
FILEcxx . . $ FILE# * fout, |
| 340 |
const kffsamp_tcxx . . $ kffsamp_t# * imp_resp, |
| 341 |
size_tcxx . . $ size_t# n_imp_resp, |
| 342 |
size_tcxx . . $ size_t# nfft ) |
| 343 |
{ |
| 344 |
int fdout; |
| 345 |
size_tcxx . . $ size_t# n_samps_buf; |
| 346 |
|
| 347 |
kiss_fastfir_cfgcxx . . $ kiss_fastfir_cfg# cfg; |
| 348 |
kffsamp_tcxx . . $ kffsamp_t# *inbuf,*outbuf; |
| 349 |
size_tcxx . . $ size_t# nread,nwrite; |
| 350 |
size_tcxx . . $ size_t# idx_inbuf; |
| 351 |
|
| 352 |
fdout = filenocxx . . $ fileno(89bc1efcdac0ca22).(fout); |
| 353 |
|
| 354 |
cfg=kiss_fastfir_alloccxx . . $ kiss_fastfir_alloc(ac78e89c690b9f1a).(imp_resp,n_imp_resp,&nfft,0,0); |
| 355 |
|
| 356 |
/* use length to minimize buffer shift*/ |
| 357 |
n_samps_buf = 8*4096/sizeof(kffsamp_tcxx . . $ kffsamp_t#); |
| 358 |
n_samps_buf = nfft + 4*(nfft-n_imp_resp+1); |
| 359 |
|
| 360 |
if (verbosecxx . . $ verbose.) fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"bufsize=%d\n",(int)(sizeof(kffsamp_tcxx . . $ kffsamp_t#)*n_samps_buf) ); |
| 361 |
|
| 362 |
|
| 363 |
/*allocate space and initialize pointers */ |
| 364 |
inbuf = (kffsamp_tcxx . . $ kffsamp_t#*)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(kffsamp_tcxx . . $ kffsamp_t#)*n_samps_buf); |
| 365 |
outbuf = (kffsamp_tcxx . . $ kffsamp_t#*)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(kffsamp_tcxx . . $ kffsamp_t#)*n_samps_buf); |
| 366 |
|
| 367 |
idx_inbuf=0; |
| 368 |
do{ |
| 369 |
/* start reading at inbuf[idx_inbuf] */ |
| 370 |
nread = freadcxx . . $ fread(738fc8ac1d711e58).( inbuf + idx_inbuf, sizeof(kffsamp_tcxx . . $ kffsamp_t#), n_samps_buf - idx_inbuf,fin ); |
| 371 |
|
| 372 |
/* If nread==0, then this is a flush. |
| 373 |
The total number of samples in input is idx_inbuf + nread . */ |
| 374 |
nwrite = kiss_fastfircxx . . $ kiss_fastfir(c3735b1f408c6acc).(cfg, inbuf, outbuf,nread,&idx_inbuf) * sizeof(kffsamp_tcxx . . $ kffsamp_t#); |
| 375 |
/* kiss_fastfir moved any unused samples to the front of inbuf and updated idx_inbuf */ |
| 376 |
|
| 377 |
ssize_tcxx . . $ ssize_t# written = writecxx . . $ write(41184a59d38b4f65).(fdout, outbuf, nwrite); |
| 378 |
if ( written < 0 || (size_tcxx . . $ size_t#)written != nwrite ) { |
| 379 |
perrorcxx . . $ perror(85c52e162fed56f9).("short write"); |
| 380 |
exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 381 |
} |
| 382 |
}while ( nread ); |
| 383 |
freecxx . . $ free(5d22bdacc48458e8).(cfg); |
| 384 |
freecxx . . $ free(5d22bdacc48458e8).(inbuf); |
| 385 |
freecxx . . $ free(5d22bdacc48458e8).(outbuf); |
| 386 |
} |
| 387 |
|
| 388 |
int maincxx . . $ main(afcd3168fc1188a4).(int argc,char**argv) |
| 389 |
{ |
| 390 |
kffsamp_tcxx . . $ kffsamp_t# * h; |
| 391 |
int use_direct=0; |
| 392 |
size_tcxx . . $ size_t# nh,nfft=0; |
| 393 |
FILEcxx . . $ FILE# *fin=stdincxx . . $ `<external>/232824719582829767/stdio.h:153:9`!; |
| 394 |
FILEcxx . . $ FILE# *fout=stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!; |
| 395 |
FILEcxx . . $ FILE# *filtfile=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 396 |
while (1) { |
| 397 |
int c=getoptcxx . . $ getopt(2483c31ff9bab884).(argc,argv,"n:h:i:o:vd"); |
| 398 |
if (c==-1) break; |
| 399 |
switch (c) { |
| 400 |
case 'v': |
| 401 |
verbosecxx . . $ verbose.=1; |
| 402 |
break; |
| 403 |
case 'n': |
| 404 |
nfft=atoicxx . . $ atoi(5c4306d8553b3696).(optargcxx . . $ optarg.); |
| 405 |
break; |
| 406 |
case 'i': |
| 407 |
fin = fopencxx . . $ fopen(82ec0787cd37e0a3).(optargcxx . . $ optarg.,"rb"); |
| 408 |
if (fin==NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 409 |
perrorcxx . . $ perror(85c52e162fed56f9).(optargcxx . . $ optarg.); |
| 410 |
exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 411 |
} |
| 412 |
break; |
| 413 |
case 'o': |
| 414 |
fout = fopencxx . . $ fopen(82ec0787cd37e0a3).(optargcxx . . $ optarg.,"w+b"); |
| 415 |
if (fout==NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 416 |
perrorcxx . . $ perror(85c52e162fed56f9).(optargcxx . . $ optarg.); |
| 417 |
exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 418 |
} |
| 419 |
break; |
| 420 |
case 'h': |
| 421 |
filtfile = fopencxx . . $ fopen(82ec0787cd37e0a3).(optargcxx . . $ optarg.,"rb"); |
| 422 |
if (filtfile==NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 423 |
perrorcxx . . $ perror(85c52e162fed56f9).(optargcxx . . $ optarg.); |
| 424 |
exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 425 |
} |
| 426 |
break; |
| 427 |
case 'd': |
| 428 |
use_direct=1; |
| 429 |
break; |
| 430 |
case '?': |
| 431 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"usage options:\n" |
| 432 |
"\t-n nfft: fft size to use\n" |
| 433 |
"\t-d : use direct FIR filtering, not fast convolution\n" |
| 434 |
"\t-i filename: input file\n" |
| 435 |
"\t-o filename: output(filtered) file\n" |
| 436 |
"\t-n nfft: fft size to use\n" |
| 437 |
"\t-h filename: impulse response\n"); |
| 438 |
exitcxx . . $ exit(3ca292c338df9bb3). (1); |
| 439 |
default:fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"bad %c\n",c);break; |
| 440 |
} |
| 441 |
} |
| 442 |
if (filtfile==NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 443 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"You must supply the FIR coeffs via -h\n"); |
| 444 |
exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 445 |
} |
| 446 |
fseekcxx . . $ fseek(543fae30d249f6b1).(filtfile,0,SEEK_ENDcxx . . $ `<external>/232824719582829767/stdio.h:112:9`!); |
| 447 |
nh = ftellcxx . . $ ftell(1dcafcd8ef4c6e6c).(filtfile) / sizeof(kffsamp_tcxx . . $ kffsamp_t#); |
| 448 |
if (verbosecxx . . $ verbose.) fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"%d samples in FIR filter\n",(int)nh); |
| 449 |
h = (kffsamp_tcxx . . $ kffsamp_t#*)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(kffsamp_tcxx . . $ kffsamp_t#)*nh); |
| 450 |
fseekcxx . . $ fseek(543fae30d249f6b1).(filtfile,0,SEEK_SETcxx . . $ `<external>/232824719582829767/stdio.h:110:9`!); |
| 451 |
if (freadcxx . . $ fread(738fc8ac1d711e58).(h,sizeof(kffsamp_tcxx . . $ kffsamp_t#),nh,filtfile) != nh) |
| 452 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"short read on filter file\n"); |
| 453 |
|
| 454 |
fclosecxx . . $ fclose(89bc1efcdac0ca22).(filtfile); |
| 455 |
|
| 456 |
if (use_direct) |
| 457 |
direct_file_filtercxx . . $ direct_file_filter(2f4d65125b8eaf0e).( fin, fout, h,nh); |
| 458 |
else |
| 459 |
do_file_filtercxx . . $ do_file_filter(1e120cbd3066ca79).( fin, fout, h,nh,nfft); |
| 460 |
|
| 461 |
if (fout!=stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!) fclosecxx . . $ fclose(89bc1efcdac0ca22).(fout); |
| 462 |
if (fin!=stdincxx . . $ `<external>/232824719582829767/stdio.h:153:9`!) fclosecxx . . $ fclose(89bc1efcdac0ca22).(fin); |
| 463 |
|
| 464 |
return 0; |
| 465 |
} |
| 466 |
#endif |