File indexing completed on 2024-05-12 04:53:39
0001 /* 0002 SPDX-FileCopyrightText: 2003-2010 Mark Borgerding <Mark@Borgerding.net> 0003 SPDX-License-Identifier: BSD-3-Clause 0004 */ 0005 0006 #pragma once 0007 0008 #include <config-kdenlive.h> 0009 0010 #include <math.h> 0011 #include <stdio.h> 0012 #include <stdlib.h> 0013 #include <string.h> 0014 #ifdef HAVE_MALLOC_H 0015 #include <malloc.h> 0016 #endif 0017 0018 #ifdef __cplusplus 0019 extern "C" { 0020 #endif 0021 0022 /* 0023 ATTENTION! 0024 If you would like a : 0025 -- a utility that will handle the caching of fft objects 0026 -- real-only (no imaginary time component ) FFT 0027 -- a multi-dimensional FFT 0028 -- a command-line utility to perform ffts 0029 -- a command-line utility to perform fast-convolution filtering 0030 0031 Then see kfc.h kiss_fftr.h kiss_fftnd.h fftutil.c kiss_fastfir.c 0032 in the tools/ directory. 0033 */ 0034 0035 #ifdef USE_SIMD 0036 #include <xmmintrin.h> 0037 #define kiss_fft_scalar __m128 0038 #define KISS_FFT_MALLOC(nbytes) _mm_malloc(nbytes, 16) 0039 #define KISS_FFT_FREE _mm_free 0040 #else 0041 #define KISS_FFT_MALLOC malloc 0042 #define KISS_FFT_FREE free 0043 #endif 0044 0045 #ifdef FIXED_POINT 0046 #include <sys/types.h> 0047 #if (FIXED_POINT == 32) 0048 #define kiss_fft_scalar int32_t 0049 #else 0050 #define kiss_fft_scalar int16_t 0051 #endif 0052 #else 0053 #ifndef kiss_fft_scalar 0054 /* default is float */ 0055 #define kiss_fft_scalar float 0056 #endif 0057 #endif 0058 0059 typedef struct 0060 { 0061 kiss_fft_scalar r; 0062 kiss_fft_scalar i; 0063 } kiss_fft_cpx; 0064 0065 typedef struct kiss_fft_state *kiss_fft_cfg; 0066 0067 /* 0068 * kiss_fft_alloc 0069 * 0070 * Initialize a FFT (or IFFT) algorithm's cfg/state buffer. 0071 * 0072 * typical usage: kiss_fft_cfg mycfg=kiss_fft_alloc(1024,0,NULL,NULL); 0073 * 0074 * The return value from fft_alloc is a cfg buffer used internally 0075 * by the fft routine or NULL. 0076 * 0077 * If lenmem is NULL, then kiss_fft_alloc will allocate a cfg buffer using malloc. 0078 * The returned value should be free()d when done to avoid memory leaks. 0079 * 0080 * The state can be placed in a user supplied buffer 'mem': 0081 * If lenmem is not NULL and mem is not NULL and *lenmem is large enough, 0082 * then the function places the cfg in mem and the size used in *lenmem 0083 * and returns mem. 0084 * 0085 * If lenmem is not NULL and ( mem is NULL or *lenmem is not large enough), 0086 * then the function returns NULL and places the minimum cfg 0087 * buffer size in *lenmem. 0088 * */ 0089 0090 kiss_fft_cfg kiss_fft_alloc(int nfft, int inverse_fft, void *mem, size_t *lenmem); 0091 0092 /* 0093 * kiss_fft(cfg,in_out_buf) 0094 * 0095 * Perform an FFT on a complex input buffer. 0096 * for a forward FFT, 0097 * fin should be f[0] , f[1] , ... ,f[nfft-1] 0098 * fout will be F[0] , F[1] , ... ,F[nfft-1] 0099 * Note that each element is complex and can be accessed like 0100 f[k].r and f[k].i 0101 * */ 0102 void kiss_fft(kiss_fft_cfg cfg, const kiss_fft_cpx *fin, kiss_fft_cpx *fout); 0103 0104 /* 0105 A more generic version of the above function. It reads its input from every Nth sample. 0106 * */ 0107 void kiss_fft_stride(kiss_fft_cfg cfg, const kiss_fft_cpx *fin, kiss_fft_cpx *fout, int fin_stride); 0108 0109 /* If kiss_fft_alloc allocated a buffer, it is one contiguous 0110 buffer and can be simply free()d when no longer needed*/ 0111 #define kiss_fft_free free 0112 0113 /* for real ffts, we need an even size */ 0114 #define kiss_fftr_next_fast_size_real(n) (kiss_fft_next_fast_size(((n) + 1) >> 1) << 1) 0115 0116 #ifdef __cplusplus 0117 } 0118 #endif