1 /* 2 * Copyright (c) 2003-2010, 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 #ifndef KISS_FFT_S32_H 10 #define KISS_FFT_S32_H 11 12 #include <stdlib.h> 13 #include <stdio.h> 14 #include <math.h> 15 #include <string.h> 16 #include <stdint.h> 17 #include <glib.h> 18 19 #ifdef __cplusplus 20 extern "C" { 21 #endif 22 23 /* 24 ATTENTION! 25 If you would like a : 26 -- a utility that will handle the caching of fft objects 27 -- real-only (no imaginary time component ) FFT 28 -- a multi-dimensional FFT 29 -- a command-line utility to perform ffts 30 -- a command-line utility to perform fast-convolution filtering 31 32 Then see kfc.h kiss_fftr_s32.h kiss_fft_s32nd.h fftutil.c kiss_fastfir.c 33 in the tools/ directory. 34 */ 35 36 #define KISS_FFT_S32_MALLOC g_malloc 37 #define KISS_FFT_S32_FREE g_free 38 #define kiss_fft_s32_scalar int32_t 39 #define FIXED_POINT 32 40 41 typedef struct { 42 kiss_fft_s32_scalar r; 43 kiss_fft_s32_scalar i; 44 }kiss_fft_s32_cpx; 45 46 typedef struct kiss_fft_s32_state* kiss_fft_s32_cfg; 47 48 /* 49 * kiss_fft_s32_alloc 50 * 51 * Initialize a FFT (or IFFT) algorithm's cfg/state buffer. 52 * 53 * typical usage: kiss_fft_s32_cfg mycfg=kiss_fft_s32_alloc(1024,0,NULL,NULL); 54 * 55 * The return value from fft_alloc is a cfg buffer used internally 56 * by the fft routine or NULL. 57 * 58 * If lenmem is NULL, then kiss_fft_s32_alloc will allocate a cfg buffer using malloc. 59 * The returned value should be free()d when done to avoid memory leaks. 60 * 61 * The state can be placed in a user supplied buffer 'mem': 62 * If lenmem is not NULL and mem is not NULL and *lenmem is large enough, 63 * then the function places the cfg in mem and the size used in *lenmem 64 * and returns mem. 65 * 66 * If lenmem is not NULL and ( mem is NULL or *lenmem is not large enough), 67 * then the function returns NULL and places the minimum cfg 68 * buffer size in *lenmem. 69 * */ 70 71 kiss_fft_s32_cfg kiss_fft_s32_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem); 72 73 /* 74 * kiss_fft_s32(cfg,in_out_buf) 75 * 76 * Perform an FFT on a complex input buffer. 77 * for a forward FFT, 78 * fin should be f[0] , f[1] , ... ,f[nfft-1] 79 * fout will be F[0] , F[1] , ... ,F[nfft-1] 80 * Note that each element is complex and can be accessed like 81 f[k].r and f[k].i 82 * */ 83 void kiss_fft_s32(kiss_fft_s32_cfg cfg,const kiss_fft_s32_cpx *fin,kiss_fft_s32_cpx *fout); 84 85 /* 86 A more generic version of the above function. It reads its input from every Nth sample. 87 * */ 88 void kiss_fft_s32_stride(kiss_fft_s32_cfg cfg,const kiss_fft_s32_cpx *fin,kiss_fft_s32_cpx *fout,int fin_stride); 89 90 /* If kiss_fft_s32_alloc allocated a buffer, it is one contiguous 91 buffer and can be simply free()d when no longer needed*/ 92 #define kiss_fft_s32_free KISS_FFT_S32_FREE 93 94 /* 95 Cleans up some memory that gets managed internally. Not necessary to call, but it might clean up 96 your compiler output to call this before you exit. 97 */ 98 void kiss_fft_s32_cleanup(void); 99 100 101 /* 102 * Returns the smallest integer k, such that k>=n and k has only "fast" factors (2,3,5) 103 */ 104 int kiss_fft_s32_next_fast_size(int n); 105 106 /* for real ffts, we need an even size */ 107 #define kiss_fftr_s32_next_fast_size_real(n) \ 108 (kiss_fft_s32_next_fast_size( ((n)+1)>>1)<<1) 109 110 #ifdef __cplusplus 111 } 112 #endif 113 114 #endif 115