added kiss_fft_next_fast_size() to determine the next number divisible by the radices 2,3,5

This commit is contained in:
Mark Borgerding 2006-06-28 03:25:02 +00:00
parent a2c69eb8ea
commit 2cce2ea306
4 changed files with 24 additions and 1 deletions

View File

@ -383,3 +383,17 @@ void kiss_fft_cleanup(void)
tmpbuf=NULL;
ntmpbuf=0;
}
int kiss_fft_next_fast_size(int n)
{
while(1) {
int m=n;
while ( (m%2) == 0 ) m/=2;
while ( (m%3) == 0 ) m/=3;
while ( (m%5) == 0 ) m/=5;
if (m<=1)
break; /* n is completely factorable by twos, threes, and fives */
n++;
}
return n;
}

View File

@ -107,6 +107,11 @@ void kiss_fft_stride(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout
void kiss_fft_cleanup(void);
/*
* Returns the smallest integer k, such that k>=n and k has only "fast" factors (2,3,5)
*/
int kiss_fft_next_fast_size(int n);
#ifdef __cplusplus
}
#endif

View File

@ -23,6 +23,10 @@ int main(int argc,char ** argv)
switch (c) {
case 'n':
nfft = atoi (optarg);
if (nfft != kiss_fft_next_fast_size(nfft) ) {
int ng = kiss_fft_next_fast_size(nfft);
fprintf(stderr,"warning: %d might be a better choice for speed than %d\n",ng,nfft);
}
break;
case 'x':
numffts = atoi (optarg);

View File

@ -73,7 +73,7 @@ kiss_fftnd_cfg kiss_fftnd_alloc(const int *dims,int ndims,int inverse_fft,void*m
st->states[i] = kiss_fft_alloc (st->dims[i], inverse_fft, ptr,&len);
ptr += len;
}
if ( ptr - (char*)st != memneeded ) {
if ( ptr - (char*)st != (int)memneeded ) {
fprintf(stderr,
"################################################################################\n"
"Internal error! Memory allocation miscalculation\n"