shun_iwasawa a35b8f
#ifndef KISS_FFT_H
shun_iwasawa a35b8f
#define KISS_FFT_H
shun_iwasawa a35b8f
shun_iwasawa a35b8f
#include <stdlib.h></stdlib.h>
shun_iwasawa a35b8f
#include <stdio.h></stdio.h>
shun_iwasawa a35b8f
#include <math.h></math.h>
shun_iwasawa a35b8f
#include <string.h></string.h>
shun_iwasawa a35b8f
shun_iwasawa a35b8f
#ifdef __cplusplus
shun_iwasawa a35b8f
extern "C" {
shun_iwasawa a35b8f
#endif
shun_iwasawa a35b8f
shun_iwasawa a35b8f
/*
shun_iwasawa a35b8f
 ATTENTION!
shun_iwasawa a35b8f
 If you would like a :
shun_iwasawa a35b8f
 -- a utility that will handle the caching of fft objects
shun_iwasawa a35b8f
 -- real-only (no imaginary time component ) FFT
shun_iwasawa a35b8f
 -- a multi-dimensional FFT
shun_iwasawa a35b8f
 -- a command-line utility to perform ffts
shun_iwasawa a35b8f
 -- a command-line utility to perform fast-convolution filtering
shun_iwasawa a35b8f
shun_iwasawa a35b8f
 Then see kfc.h kiss_fftr.h kiss_fftnd.h fftutil.c kiss_fastfir.c
shun_iwasawa a35b8f
  in the tools/ directory.
shun_iwasawa a35b8f
*/
shun_iwasawa a35b8f
shun_iwasawa a35b8f
#ifdef USE_SIMD
shun_iwasawa a35b8f
# include <xmmintrin.h></xmmintrin.h>
shun_iwasawa a35b8f
# define kiss_fft_scalar __m128
shun_iwasawa a35b8f
#define KISS_FFT_MALLOC(nbytes) _mm_malloc(nbytes,16)
shun_iwasawa a35b8f
#define KISS_FFT_FREE _mm_free
shun_iwasawa a35b8f
#else	
shun_iwasawa a35b8f
#define KISS_FFT_MALLOC malloc
shun_iwasawa a35b8f
#define KISS_FFT_FREE free
shun_iwasawa a35b8f
#endif	
shun_iwasawa a35b8f
shun_iwasawa a35b8f
shun_iwasawa a35b8f
#ifdef FIXED_POINT
shun_iwasawa a35b8f
#include <sys types.h="">	</sys>
shun_iwasawa a35b8f
# if (FIXED_POINT == 32)
shun_iwasawa a35b8f
#  define kiss_fft_scalar int32_t
shun_iwasawa a35b8f
# else	
shun_iwasawa a35b8f
#  define kiss_fft_scalar int16_t
shun_iwasawa a35b8f
# endif
shun_iwasawa a35b8f
#else
shun_iwasawa a35b8f
# ifndef kiss_fft_scalar
shun_iwasawa a35b8f
/*  default is float */
shun_iwasawa a35b8f
#   define kiss_fft_scalar float
shun_iwasawa a35b8f
# endif
shun_iwasawa a35b8f
#endif
shun_iwasawa a35b8f
shun_iwasawa a35b8f
typedef struct {
shun_iwasawa a35b8f
    kiss_fft_scalar r;
shun_iwasawa a35b8f
    kiss_fft_scalar i;
shun_iwasawa a35b8f
}kiss_fft_cpx;
shun_iwasawa a35b8f
shun_iwasawa a35b8f
typedef struct kiss_fft_state* kiss_fft_cfg;
shun_iwasawa a35b8f
shun_iwasawa a35b8f
/* 
shun_iwasawa a35b8f
 *  kiss_fft_alloc
shun_iwasawa a35b8f
 *  
shun_iwasawa a35b8f
 *  Initialize a FFT (or IFFT) algorithm's cfg/state buffer.
shun_iwasawa a35b8f
 *
shun_iwasawa a35b8f
 *  typical usage:      kiss_fft_cfg mycfg=kiss_fft_alloc(1024,0,NULL,NULL);
shun_iwasawa a35b8f
 *
shun_iwasawa a35b8f
 *  The return value from fft_alloc is a cfg buffer used internally
shun_iwasawa a35b8f
 *  by the fft routine or NULL.
shun_iwasawa a35b8f
 *
shun_iwasawa a35b8f
 *  If lenmem is NULL, then kiss_fft_alloc will allocate a cfg buffer using malloc.
shun_iwasawa a35b8f
 *  The returned value should be free()d when done to avoid memory leaks.
shun_iwasawa a35b8f
 *  
shun_iwasawa a35b8f
 *  The state can be placed in a user supplied buffer 'mem':
shun_iwasawa a35b8f
 *  If lenmem is not NULL and mem is not NULL and *lenmem is large enough,
shun_iwasawa a35b8f
 *      then the function places the cfg in mem and the size used in *lenmem
shun_iwasawa a35b8f
 *      and returns mem.
shun_iwasawa a35b8f
 *  
shun_iwasawa a35b8f
 *  If lenmem is not NULL and ( mem is NULL or *lenmem is not large enough),
shun_iwasawa a35b8f
 *      then the function returns NULL and places the minimum cfg 
shun_iwasawa a35b8f
 *      buffer size in *lenmem.
shun_iwasawa a35b8f
 * */
shun_iwasawa a35b8f
shun_iwasawa a35b8f
kiss_fft_cfg kiss_fft_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem); 
shun_iwasawa a35b8f
shun_iwasawa a35b8f
/*
shun_iwasawa a35b8f
 * kiss_fft(cfg,in_out_buf)
shun_iwasawa a35b8f
 *
shun_iwasawa a35b8f
 * Perform an FFT on a complex input buffer.
shun_iwasawa a35b8f
 * for a forward FFT,
shun_iwasawa a35b8f
 * fin should be  f[0] , f[1] , ... ,f[nfft-1]
shun_iwasawa a35b8f
 * fout will be   F[0] , F[1] , ... ,F[nfft-1]
shun_iwasawa a35b8f
 * Note that each element is complex and can be accessed like
shun_iwasawa a35b8f
    f[k].r and f[k].i
shun_iwasawa a35b8f
 * */
shun_iwasawa a35b8f
void kiss_fft(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout);
shun_iwasawa a35b8f
shun_iwasawa a35b8f
/*
shun_iwasawa a35b8f
 A more generic version of the above function. It reads its input from every Nth sample.
shun_iwasawa a35b8f
 * */
shun_iwasawa a35b8f
void kiss_fft_stride(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int fin_stride);
shun_iwasawa a35b8f
shun_iwasawa a35b8f
/* If kiss_fft_alloc allocated a buffer, it is one contiguous 
shun_iwasawa a35b8f
   buffer and can be simply free()d when no longer needed*/
shun_iwasawa a35b8f
#define kiss_fft_free free
shun_iwasawa a35b8f
shun_iwasawa a35b8f
/*
shun_iwasawa a35b8f
 Cleans up some memory that gets managed internally. Not necessary to call, but it might clean up 
shun_iwasawa a35b8f
 your compiler output to call this before you exit.
shun_iwasawa a35b8f
*/
shun_iwasawa a35b8f
void kiss_fft_cleanup(void);
shun_iwasawa a35b8f
	
shun_iwasawa a35b8f
shun_iwasawa a35b8f
/*
shun_iwasawa a35b8f
 * Returns the smallest integer k, such that k>=n and k has only "fast" factors (2,3,5)
shun_iwasawa a35b8f
 */
shun_iwasawa a35b8f
int kiss_fft_next_fast_size(int n);
shun_iwasawa a35b8f
shun_iwasawa a35b8f
/* for real ffts, we need an even size */
shun_iwasawa a35b8f
#define kiss_fftr_next_fast_size_real(n) \
shun_iwasawa a35b8f
        (kiss_fft_next_fast_size( ((n)+1)>>1)<<1)
shun_iwasawa a35b8f
shun_iwasawa a35b8f
#ifdef __cplusplus
shun_iwasawa a35b8f
} 
shun_iwasawa a35b8f
#endif
shun_iwasawa a35b8f
shun_iwasawa a35b8f
#endif