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_F32_H 10 #define KISS_FFT_F32_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_f32.h kiss_fft_f32nd.h fftutil.c kiss_fastfir.c 33 in the tools/ directory. 34 */ 35 36 #define KISS_FFT_F32_MALLOC g_malloc 37 #define KISS_FFT_F32_FREE g_free 38 #define kiss_fft_f32_scalar float 39 40 typedef struct { 41 kiss_fft_f32_scalar r; 42 kiss_fft_f32_scalar i; 43 }kiss_fft_f32_cpx; 44 45 typedef struct kiss_fft_f32_state* kiss_fft_f32_cfg; 46 47 /* 48 * kiss_fft_f32_alloc 49 * 50 * Initialize a FFT (or IFFT) algorithm's cfg/state buffer. 51 * 52 * typical usage: kiss_fft_f32_cfg mycfg=kiss_fft_f32_alloc(1024,0,NULL,NULL); 53 * 54 * The return value from fft_alloc is a cfg buffer used internally 55 * by the fft routine or NULL. 56 * 57 * If lenmem is NULL, then kiss_fft_f32_alloc will allocate a cfg buffer using malloc. 58 * The returned value should be free()d when done to avoid memory leaks. 59 * 60 * The state can be placed in a user supplied buffer 'mem': 61 * If lenmem is not NULL and mem is not NULL and *lenmem is large enough, 62 * then the function places the cfg in mem and the size used in *lenmem 63 * and returns mem. 64 * 65 * If lenmem is not NULL and ( mem is NULL or *lenmem is not large enough), 66 * then the function returns NULL and places the minimum cfg 67 * buffer size in *lenmem. 68 * */ 69 70 kiss_fft_f32_cfg kiss_fft_f32_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem); 71 72 /* 73 * kiss_fft_f32(cfg,in_out_buf) 74 * 75 * Perform an FFT on a complex input buffer. 76 * for a forward FFT, 77 * fin should be f[0] , f[1] , ... ,f[nfft-1] 78 * fout will be F[0] , F[1] , ... ,F[nfft-1] 79 * Note that each element is complex and can be accessed like 80 f[k].r and f[k].i 81 * */ 82 void kiss_fft_f32(kiss_fft_f32_cfg cfg,const kiss_fft_f32_cpx *fin,kiss_fft_f32_cpx *fout); 83 84 /* 85 A more generic version of the above function. It reads its input from every Nth sample. 86 * */ 87 void kiss_fft_f32_stride(kiss_fft_f32_cfg cfg,const kiss_fft_f32_cpx *fin,kiss_fft_f32_cpx *fout,int fin_stride); 88 89 /* If kiss_fft_f32_alloc allocated a buffer, it is one contiguous 90 buffer and can be simply free()d when no longer needed*/ 91 #define kiss_fft_f32_free KISS_FFT_F32_FREE 92 93 /* 94 Cleans up some memory that gets managed internally. Not necessary to call, but it might clean up 95 your compiler output to call this before you exit. 96 */ 97 void kiss_fft_f32_cleanup(void); 98 99 100 /* 101 * Returns the smallest integer k, such that k>=n and k has only "fast" factors (2,3,5) 102 */ 103 int kiss_fft_f32_next_fast_size(int n); 104 105 /* for real ffts, we need an even size */ 106 #define kiss_fftr_f32_next_fast_size_real(n) \ 107 (kiss_fft_f32_next_fast_size( ((n)+1)>>1)<<1) 108 109 #ifdef __cplusplus 110 } 111 #endif 112 113 #endif 114