mirror of
https://github.com/mborgerding/kissfft.git
synced 2025-05-27 21:20:27 -04:00
replaced void pointers with pointers to forward declared structs
This commit is contained in:
parent
d1e99f297b
commit
dda6f9638e
@ -18,14 +18,14 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
typedef struct { kiss_fft_scalar r; kiss_fft_scalar i; }kiss_fft_cpx; */
|
||||
#include "kiss_fft.h"
|
||||
|
||||
typedef struct {
|
||||
struct kiss_fft_state{
|
||||
int nfft;
|
||||
int inverse;
|
||||
int *factors;
|
||||
kiss_fft_cpx * twiddles;
|
||||
kiss_fft_cpx * tmpbuf;
|
||||
kiss_fft_cpx * scratch;
|
||||
}kiss_fft_state;
|
||||
};
|
||||
|
||||
/*
|
||||
Explanation of macros dealing with complex math:
|
||||
@ -70,7 +70,7 @@ typedef struct {
|
||||
#define C_SUBFROM( res , a)\
|
||||
do { (res).r -= (a).r; (res).i -= (a).i; }while(0)
|
||||
|
||||
static inline
|
||||
static
|
||||
kiss_fft_cpx kf_cexp(double phase) /* returns e ** (j*phase) */
|
||||
{
|
||||
kiss_fft_cpx x;
|
||||
|
31
kiss_fft.c
31
kiss_fft.c
@ -27,7 +27,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
static void kf_bfly2(
|
||||
kiss_fft_cpx * Fout,
|
||||
const int fstride,
|
||||
const kiss_fft_state * st,
|
||||
const kiss_fft_cfg st,
|
||||
int m
|
||||
)
|
||||
{
|
||||
@ -50,7 +50,7 @@ static void kf_bfly2(
|
||||
static void kf_bfly4(
|
||||
kiss_fft_cpx * Fout,
|
||||
const int fstride,
|
||||
const kiss_fft_state * st,
|
||||
const kiss_fft_cfg st,
|
||||
const size_t m
|
||||
)
|
||||
{
|
||||
@ -97,7 +97,7 @@ static void kf_bfly4(
|
||||
static void kf_bfly3(
|
||||
kiss_fft_cpx * Fout,
|
||||
const int fstride,
|
||||
const kiss_fft_state * st,
|
||||
const kiss_fft_cfg st,
|
||||
int m
|
||||
)
|
||||
{
|
||||
@ -143,7 +143,7 @@ static void kf_bfly3(
|
||||
static void kf_bfly5(
|
||||
kiss_fft_cpx * Fout,
|
||||
const int fstride,
|
||||
const kiss_fft_state * st,
|
||||
const kiss_fft_cfg st,
|
||||
int m
|
||||
)
|
||||
{
|
||||
@ -205,7 +205,7 @@ static void kf_bfly5(
|
||||
static void kf_bfly_generic(
|
||||
kiss_fft_cpx * Fout,
|
||||
const int fstride,
|
||||
const kiss_fft_state * st,
|
||||
const kiss_fft_cfg st,
|
||||
int m,
|
||||
int p
|
||||
)
|
||||
@ -246,7 +246,7 @@ void kf_work(
|
||||
const int fstride,
|
||||
int in_stride,
|
||||
int * factors,
|
||||
const kiss_fft_state * st
|
||||
const kiss_fft_cfg st
|
||||
)
|
||||
{
|
||||
kiss_fft_cpx * Fout_beg=Fout;
|
||||
@ -284,7 +284,7 @@ void kf_work(
|
||||
void kf_factor(int n,int * facbuf)
|
||||
{
|
||||
int p=4;
|
||||
int floor_sqrt = floor (sqrt (n));
|
||||
int floor_sqrt = (int)floor (sqrt (n));
|
||||
|
||||
/*factor out powers of 4, powers of 2, then any remaining primes */
|
||||
do {
|
||||
@ -310,20 +310,20 @@ void kf_factor(int n,int * facbuf)
|
||||
* The return value is a contiguous block of memory, allocated with malloc. As such,
|
||||
* It can be freed with free(), rather than a kiss_fft-specific function.
|
||||
* */
|
||||
void * kiss_fft_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem )
|
||||
kiss_fft_cfg kiss_fft_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem )
|
||||
{
|
||||
kiss_fft_state * st=NULL;
|
||||
size_t memneeded = sizeof(kiss_fft_state)
|
||||
kiss_fft_cfg st=NULL;
|
||||
size_t memneeded = sizeof(struct kiss_fft_state)
|
||||
+ sizeof(kiss_fft_cpx)*nfft /* twiddle factors*/
|
||||
+ sizeof(kiss_fft_cpx)*nfft /* tmpbuf*/
|
||||
+ sizeof(int)*2*MAXFACTORS /* factors*/
|
||||
+ sizeof(kiss_fft_cpx)*nfft; /* scratch*/
|
||||
|
||||
if ( lenmem==NULL ) {
|
||||
st = ( kiss_fft_state *)malloc( memneeded );
|
||||
st = ( kiss_fft_cfg)malloc( memneeded );
|
||||
}else{
|
||||
if (*lenmem >= memneeded)
|
||||
st = ( kiss_fft_state *)mem;
|
||||
st = (kiss_fft_cfg)mem;
|
||||
*lenmem = memneeded;
|
||||
}
|
||||
if (st){
|
||||
@ -345,12 +345,11 @@ void * kiss_fft_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem )
|
||||
|
||||
kf_factor(nfft,st->factors);
|
||||
}
|
||||
return st;
|
||||
return (kiss_fft_cfg)st;
|
||||
}
|
||||
|
||||
void kiss_fft_stride(const void * cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int in_stride)
|
||||
void kiss_fft_stride(kiss_fft_cfg st,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int in_stride)
|
||||
{
|
||||
const kiss_fft_state * st = cfg;
|
||||
if (st->nfft < 0) {
|
||||
fprintf(stderr,"usage error: invalid kiss_fft_state. make sure the correct kiss_fft_alloc routine was used.\n");
|
||||
exit(1);
|
||||
@ -364,7 +363,7 @@ void kiss_fft_stride(const void * cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout
|
||||
}
|
||||
}
|
||||
|
||||
void kiss_fft(const void * cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout)
|
||||
void kiss_fft(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout)
|
||||
{
|
||||
kiss_fft_stride(cfg,fin,fout,1);
|
||||
}
|
||||
|
17
kiss_fft.h
17
kiss_fft.h
@ -6,6 +6,10 @@
|
||||
#include <math.h>
|
||||
#include <memory.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
ATTENTION!
|
||||
If you would like a :
|
||||
@ -32,6 +36,8 @@ typedef struct {
|
||||
kiss_fft_scalar i;
|
||||
}kiss_fft_cpx;
|
||||
|
||||
typedef struct kiss_fft_state* kiss_fft_cfg;
|
||||
|
||||
/*
|
||||
* kiss_fft_alloc
|
||||
*
|
||||
@ -54,7 +60,8 @@ typedef struct {
|
||||
* then the function returns NULL and places the minimum cfg
|
||||
* buffer size in *lenmem.
|
||||
* */
|
||||
void* kiss_fft_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem);
|
||||
|
||||
kiss_fft_cfg kiss_fft_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem);
|
||||
|
||||
/*
|
||||
* kiss_fft(cfg,in_out_buf)
|
||||
@ -66,12 +73,16 @@ void* kiss_fft_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem);
|
||||
* Note that each element is complex and can be accessed like
|
||||
f[k].r and f[k].i
|
||||
* */
|
||||
void kiss_fft(const void * cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout);
|
||||
void kiss_fft(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout);
|
||||
|
||||
void kiss_fft_stride(const void * cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int fin_stride);
|
||||
void kiss_fft_stride(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int fin_stride);
|
||||
|
||||
/* If kiss_fft_alloc allocated a buffer, it is one contiguous
|
||||
buffer and can be simply free()d when no longer needed*/
|
||||
#define kiss_fft_free free
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -24,7 +24,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
|
||||
void fft_file(FILE * fin,FILE * fout,int nfft,int isinverse)
|
||||
{
|
||||
void *st;
|
||||
kiss_fft_cfg st;
|
||||
kiss_fft_cpx * buf;
|
||||
kiss_fft_cpx * bufout;
|
||||
|
||||
@ -62,7 +62,7 @@ void fft_filend(FILE * fin,FILE * fout,int *dims,int ndims,int isinverse)
|
||||
|
||||
void fft_file_real(FILE * fin,FILE * fout,int nfft,int isinverse)
|
||||
{
|
||||
void *st;
|
||||
kiss_fftr_cfg st;
|
||||
kiss_fft_scalar * rbuf;
|
||||
kiss_fft_cpx * cbuf;
|
||||
|
||||
|
@ -18,14 +18,14 @@ typedef struct
|
||||
{
|
||||
int nfft;
|
||||
int inverse;
|
||||
void * cfg;
|
||||
kiss_fft_cfg cfg;
|
||||
void * next;
|
||||
} cached_fft;
|
||||
|
||||
static cached_fft *cache_root=NULL;
|
||||
static int ncached=0;
|
||||
|
||||
static const void * find_cached_fft(int nfft,int inverse)
|
||||
static kiss_fft_cfg find_cached_fft(int nfft,int inverse)
|
||||
{
|
||||
size_t len;
|
||||
cached_fft * cur=cache_root;
|
||||
@ -42,7 +42,7 @@ static const void * find_cached_fft(int nfft,int inverse)
|
||||
cur = (cached_fft*)malloc(sizeof(cached_fft) + len );
|
||||
if (cur == NULL)
|
||||
return NULL;
|
||||
cur->cfg = cur+1;
|
||||
cur->cfg = (kiss_fft_cfg)(cur+1);
|
||||
kiss_fft_alloc(nfft,inverse,cur->cfg,&len);
|
||||
cur->nfft=nfft;
|
||||
cur->inverse=inverse;
|
||||
|
@ -1,6 +1,11 @@
|
||||
#ifndef KFC_H
|
||||
#define KFC_H
|
||||
#include "kiss_fft.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
KFC -- Kiss FFT Cache
|
||||
|
||||
@ -34,4 +39,8 @@ void kfc_ifft(int nfft, const kiss_fft_cpx * fin,kiss_fft_cpx * fout);
|
||||
/*free all cached objects*/
|
||||
void kfc_cleanup();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -20,7 +20,7 @@ typedef struct {
|
||||
int dimprod; /* dimsum would be mighty tasty right now */
|
||||
int ndims;
|
||||
int *dims;
|
||||
void **states; /* cfg states for each dimension */
|
||||
kiss_fft_cfg *states; /* cfg states for each dimension */
|
||||
kiss_fft_cpx * tmpbuf; /*buffer capable of hold the entire buffer */
|
||||
}kiss_fftnd_state;
|
||||
|
||||
@ -56,7 +56,7 @@ void * kiss_fftnd_alloc(int *dims,int ndims,int inverse_fft,void*mem,size_t*lenm
|
||||
st->ndims = ndims;
|
||||
ptr=(char*)(st+1);
|
||||
|
||||
st->states = (void**)ptr;
|
||||
st->states = (kiss_fft_cfg *)ptr;
|
||||
ptr += sizeof(void*) * ndims;
|
||||
|
||||
st->dims = (int*)ptr;
|
||||
@ -69,9 +69,8 @@ void * kiss_fftnd_alloc(int *dims,int ndims,int inverse_fft,void*mem,size_t*lenm
|
||||
size_t len;
|
||||
st->dims[i] = dims[i];
|
||||
kiss_fft_alloc (st->dims[i], inverse_fft, NULL, &len);
|
||||
st->states[i] = ptr;
|
||||
st->states[i] = kiss_fft_alloc (st->dims[i], inverse_fft, ptr,&len);
|
||||
ptr += len;
|
||||
kiss_fft_alloc (st->dims[i], inverse_fft, st->states[i], &len);
|
||||
}
|
||||
return st;
|
||||
}
|
||||
|
@ -3,7 +3,14 @@
|
||||
|
||||
#include "kiss_fft.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void * kiss_fftnd_alloc(int *dims,int ndims,int inverse_fft,void*mem,size_t*lenmem);
|
||||
void kiss_fftnd(void * cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
@ -12,19 +12,19 @@ Redistribution and use in source and binary forms, with or without modification,
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "kiss_fftr.h"
|
||||
#include "_kiss_fft_guts.h"
|
||||
|
||||
typedef struct {
|
||||
int minus3; /*magic to signify a 1-d real transform*/
|
||||
kiss_fft_state * substate;
|
||||
struct kiss_fftr_state{
|
||||
kiss_fft_cfg substate;
|
||||
kiss_fft_cpx * tmpbuf;
|
||||
kiss_fft_cpx * super_twiddles;
|
||||
}kiss_fftr_state;
|
||||
};
|
||||
|
||||
void * kiss_fftr_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem)
|
||||
kiss_fftr_cfg kiss_fftr_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem)
|
||||
{
|
||||
int i;
|
||||
kiss_fftr_state *st = NULL;
|
||||
kiss_fftr_cfg st = NULL;
|
||||
size_t subsize, memneeded;
|
||||
|
||||
if (nfft & 1) {
|
||||
@ -34,20 +34,19 @@ void * kiss_fftr_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem)
|
||||
nfft >>= 1;
|
||||
|
||||
kiss_fft_alloc (nfft, inverse_fft, NULL, &subsize);
|
||||
memneeded = sizeof(kiss_fftr_state) + subsize + sizeof(kiss_fft_cpx) * ( nfft * 2);
|
||||
memneeded = sizeof(struct kiss_fftr_state) + subsize + sizeof(kiss_fft_cpx) * ( nfft * 2);
|
||||
|
||||
if (lenmem == NULL) {
|
||||
st = (kiss_fftr_state *) malloc (memneeded);
|
||||
st = (kiss_fftr_cfg) malloc (memneeded);
|
||||
} else {
|
||||
if (*lenmem >= memneeded)
|
||||
st = (kiss_fftr_state *) mem;
|
||||
st = (kiss_fftr_cfg) mem;
|
||||
*lenmem = memneeded;
|
||||
}
|
||||
if (!st)
|
||||
return NULL;
|
||||
|
||||
st->minus3 = -3;
|
||||
st->substate = (kiss_fft_state *) (st + 1); /*just beyond kiss_fftr_state struct */
|
||||
st->substate = (kiss_fft_cfg) (st + 1); /*just beyond kiss_fftr_state struct */
|
||||
st->tmpbuf = (kiss_fft_cpx *) (((char *) st->substate) + subsize);
|
||||
st->super_twiddles = st->tmpbuf + nfft;
|
||||
kiss_fft_alloc(nfft, inverse_fft, st->substate, &subsize);
|
||||
@ -62,13 +61,12 @@ void * kiss_fftr_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem)
|
||||
return st;
|
||||
}
|
||||
|
||||
void kiss_fftr(const void * cfg,const kiss_fft_scalar *timedata,kiss_fft_cpx *freqdata)
|
||||
void kiss_fftr(kiss_fftr_cfg st,const kiss_fft_scalar *timedata,kiss_fft_cpx *freqdata)
|
||||
{
|
||||
/* input buffer timedata is stored row-wise */
|
||||
kiss_fftr_state *st = ( kiss_fftr_state *)cfg;
|
||||
int k,N;
|
||||
|
||||
if ( st->minus3 != -3 || st->substate->inverse) {
|
||||
if ( st->substate->inverse) {
|
||||
fprintf(stderr,"kiss fft usage error: improper alloc\n");
|
||||
exit(1);
|
||||
}
|
||||
@ -107,13 +105,12 @@ void kiss_fftr(const void * cfg,const kiss_fft_scalar *timedata,kiss_fft_cpx *fr
|
||||
C_FIXDIV(freqdata[N],2);
|
||||
}
|
||||
|
||||
void kiss_fftri(const void * cfg,const kiss_fft_cpx *freqdata,kiss_fft_scalar *timedata)
|
||||
void kiss_fftri(kiss_fftr_cfg st,const kiss_fft_cpx *freqdata,kiss_fft_scalar *timedata)
|
||||
{
|
||||
/* input buffer timedata is stored row-wise */
|
||||
kiss_fftr_state *st = (kiss_fftr_state *) cfg;
|
||||
int k, N;
|
||||
|
||||
if (st->minus3 != -3 || st->substate->inverse == 0) {
|
||||
if (st->substate->inverse == 0) {
|
||||
fprintf (stderr, "kiss fft usage error: improper alloc\n");
|
||||
exit (1);
|
||||
}
|
||||
|
@ -2,11 +2,23 @@
|
||||
#define KISS_FTR_H
|
||||
|
||||
#include "kiss_fft.h"
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Real optimized version can save about 45% cpu time vs. complex fft of a real seq.
|
||||
*/
|
||||
void * kiss_fftr_alloc(int nfft,int inverse_fft,void * mem, size_t * lenmem);
|
||||
void kiss_fftr(const void * cfg,const kiss_fft_scalar *timedata,kiss_fft_cpx *freqdata);
|
||||
void kiss_fftri(const void * cfg,const kiss_fft_cpx *freqdata,kiss_fft_scalar *timedata);
|
||||
|
||||
typedef struct kiss_fftr_state *kiss_fftr_cfg;
|
||||
|
||||
kiss_fftr_cfg kiss_fftr_alloc(int nfft,int inverse_fft,void * mem, size_t * lenmem);
|
||||
void kiss_fftr(kiss_fftr_cfg cfg,const kiss_fft_scalar *timedata,kiss_fft_cpx *freqdata);
|
||||
void kiss_fftri(kiss_fftr_cfg cfg,const kiss_fft_cpx *freqdata,kiss_fft_scalar *timedata);
|
||||
|
||||
#define kiss_fftr_free free
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user