mirror of
https://github.com/mborgerding/kissfft.git
synced 2025-06-04 01:28:23 -04:00
getting ready for 1.2.4
This commit is contained in:
parent
f088e415b4
commit
070d040425
10
CHANGELOG
10
CHANGELOG
@ -1,3 +1,13 @@
|
|||||||
|
1.2.4 (Oct 27, 2005) The "oops, inverse fixed point real fft was borked" release.
|
||||||
|
Fixed scaling bug for inverse fixed point real fft -- also fixed test code that should've been failing.
|
||||||
|
Thanks to Jean-Marc Valin for bug report.
|
||||||
|
|
||||||
|
Use sys/types.h for more portable types than short,int,long => int16_t,int32_t,int64_t
|
||||||
|
If your system does not have these, you may need to define them -- but at least it breaks in a
|
||||||
|
loud and easily fixable way -- unlike silently using the wrong size type.
|
||||||
|
|
||||||
|
Hopefully tools/psdpng.c is fixed -- thanks to Steve Kellog for pointing out the weirdness.
|
||||||
|
|
||||||
1.2.3 (June 25, 2005) The "you want to use WHAT as a sample" release.
|
1.2.3 (June 25, 2005) The "you want to use WHAT as a sample" release.
|
||||||
Added ability to use 32 bit fixed point samples -- requires a 64 bit intermediate result, a la 'long long'
|
Added ability to use 32 bit fixed point samples -- requires a 64 bit intermediate result, a la 'long long'
|
||||||
|
|
||||||
|
@ -22,35 +22,35 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|||||||
#include "kiss_fft.h"
|
#include "kiss_fft.h"
|
||||||
#include "kiss_fftr.h"
|
#include "kiss_fftr.h"
|
||||||
|
|
||||||
size_t nfft=1024;
|
int nfft=1024;
|
||||||
size_t nfreqs=0;
|
|
||||||
int repeat=0;
|
|
||||||
int window=0;
|
|
||||||
int colors=256;
|
|
||||||
FILE * fin=NULL;
|
FILE * fin=NULL;
|
||||||
FILE * fout=NULL;
|
FILE * fout=NULL;
|
||||||
|
|
||||||
int navg=20;
|
int navg=20;
|
||||||
float * valbuf=NULL;
|
int remove_dc=0;
|
||||||
int remove_dc=1;
|
int nrows=0;
|
||||||
|
|
||||||
size_t nrows=0;
|
|
||||||
float * vals=NULL;
|
float * vals=NULL;
|
||||||
|
int stereo=0;
|
||||||
|
|
||||||
static
|
static
|
||||||
void config(int argc,char** argv)
|
void config(int argc,char** argv)
|
||||||
{
|
{
|
||||||
while (1) {
|
while (1) {
|
||||||
int c = getopt (argc, argv, "n:rs");
|
int c = getopt (argc, argv, "n:r:as");
|
||||||
if (c == -1)
|
if (c == -1)
|
||||||
break;
|
break;
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'n':
|
case 'n': nfft=(int)atoi(optarg);break;
|
||||||
nfft=(size_t)atoi(optarg);
|
case 'r': navg=(int)atoi(optarg);break;
|
||||||
|
case 'a': remove_dc=1;break;
|
||||||
|
case 's': stereo=1;break;
|
||||||
case '?':
|
case '?':
|
||||||
fprintf (stderr, "usage options:\n"
|
fprintf (stderr, "usage options:\n"
|
||||||
"\t-n d: fft dimension(s) default = 1024\n"
|
"\t-n d: fft dimension(s) [1024]\n"
|
||||||
"stereo 16 bit machine format real input is assumed\n"
|
"\t-r d: number of rows to average [20]\n"
|
||||||
|
"\t-a : remove average from each fft buffer\n"
|
||||||
|
"\t-s : input is stereo, channels will be combined before fft\n"
|
||||||
|
"16 bit machine format real input is assumed\n"
|
||||||
);
|
);
|
||||||
default:
|
default:
|
||||||
fprintf (stderr, "bad %c\n", c);
|
fprintf (stderr, "bad %c\n", c);
|
||||||
@ -91,6 +91,7 @@ void val2rgb(float x,rgb_t *p)
|
|||||||
p->g = (int)(255*sin(x*pi));
|
p->g = (int)(255*sin(x*pi));
|
||||||
p->r = (int)(255*abs(sin(x*pi*3/2)));
|
p->r = (int)(255*abs(sin(x*pi*3/2)));
|
||||||
p->b = (int)(255*abs(sin(x*pi*5/2)));
|
p->b = (int)(255*abs(sin(x*pi*5/2)));
|
||||||
|
//fprintf(stderr,"%.2f : %d,%d,%d\n",x,(int)p->r,(int)p->g,(int)p->b);
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
@ -105,7 +106,12 @@ void cpx2pixels(rgb_t * res,const float * fbuf,size_t n)
|
|||||||
if (fbuf[i] < minval) minval = fbuf[i];
|
if (fbuf[i] < minval) minval = fbuf[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fprintf(stderr,"min ==%f,max=%f\n",minval,maxval);
|
||||||
valrange = maxval-minval;
|
valrange = maxval-minval;
|
||||||
|
if (valrange == 0) {
|
||||||
|
fprintf(stderr,"min == max == %f\n",minval);
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < n; ++i)
|
for (i = 0; i < n; ++i)
|
||||||
val2rgb( (fbuf[i] - minval)/valrange , res+i );
|
val2rgb( (fbuf[i] - minval)/valrange , res+i );
|
||||||
@ -118,53 +124,57 @@ void transform_signal(void)
|
|||||||
kiss_fftr_cfg cfg=NULL;
|
kiss_fftr_cfg cfg=NULL;
|
||||||
kiss_fft_scalar *tbuf;
|
kiss_fft_scalar *tbuf;
|
||||||
kiss_fft_cpx *fbuf;
|
kiss_fft_cpx *fbuf;
|
||||||
kiss_fft_cpx *avgbuf;
|
float *mag2buf;
|
||||||
size_t i;
|
int i;
|
||||||
size_t n;
|
int n;
|
||||||
int avgctr=0;
|
int avgctr=0;
|
||||||
|
|
||||||
nfreqs=nfft/2+1;
|
int nfreqs=nfft/2+1;
|
||||||
|
|
||||||
CHECKNULL( cfg=kiss_fftr_alloc(nfft,0,0,0) );
|
CHECKNULL( cfg=kiss_fftr_alloc(nfft,0,0,0) );
|
||||||
CHECKNULL( inbuf=(short*)malloc(sizeof(short)*2*nfft ) );
|
CHECKNULL( inbuf=(short*)malloc(sizeof(short)*2*nfft ) );
|
||||||
CHECKNULL( tbuf=(kiss_fft_scalar*)malloc(sizeof(kiss_fft_scalar)*nfft ) );
|
CHECKNULL( tbuf=(kiss_fft_scalar*)malloc(sizeof(kiss_fft_scalar)*nfft ) );
|
||||||
CHECKNULL( fbuf=(kiss_fft_cpx*)malloc(sizeof(kiss_fft_cpx)*nfreqs ) );
|
CHECKNULL( fbuf=(kiss_fft_cpx*)malloc(sizeof(kiss_fft_cpx)*nfreqs ) );
|
||||||
CHECKNULL( avgbuf=(kiss_fft_cpx*)malloc(sizeof(kiss_fft_cpx)*nfreqs ) );
|
CHECKNULL( mag2buf=(float*)malloc(sizeof(float)*nfreqs ) );
|
||||||
|
|
||||||
while (1){
|
memset(mag2buf,0,sizeof(mag2buf)*nfreqs);
|
||||||
n = fread(inbuf,sizeof(short)*2,nfft,fin);
|
|
||||||
if (n != nfft )
|
|
||||||
break;
|
|
||||||
|
|
||||||
/* pack the shorts */
|
while (1) {
|
||||||
for (i=0;i<nfft;++i){
|
if (stereo) {
|
||||||
tbuf[i] = inbuf[2*i] + inbuf[2*i+1];
|
n = fread(inbuf,sizeof(short)*2,nfft,fin);
|
||||||
|
if (n != nfft )
|
||||||
|
break;
|
||||||
|
for (i=0;i<nfft;++i)
|
||||||
|
tbuf[i] = inbuf[2*i] + inbuf[2*i+1];
|
||||||
|
}else{
|
||||||
|
n = fread(inbuf,sizeof(short),nfft,fin);
|
||||||
|
if (n != nfft )
|
||||||
|
break;
|
||||||
|
for (i=0;i<nfft;++i)
|
||||||
|
tbuf[i] = inbuf[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (remove_dc) {
|
||||||
|
float avg = 0;
|
||||||
|
for (i=0;i<nfft;++i) avg += tbuf[i];
|
||||||
|
avg /= nfft;
|
||||||
|
for (i=0;i<nfft;++i) tbuf[i] -= (kiss_fft_scalar)avg;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* do FFT */
|
/* do FFT */
|
||||||
kiss_fftr(cfg,tbuf,fbuf);
|
kiss_fftr(cfg,tbuf,fbuf);
|
||||||
|
|
||||||
if (remove_dc) {
|
for (i=0;i<nfreqs;++i)
|
||||||
fbuf[0].r = 0;
|
mag2buf[i] += fbuf[i].r * fbuf[i].r + fbuf[i].i * fbuf[i].i;
|
||||||
fbuf[0].i = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i=0;i<nfreqs;++i){
|
|
||||||
avgbuf[i].r += fbuf[i].r;
|
|
||||||
avgbuf[i].i += fbuf[i].i;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (++avgctr == navg) {
|
if (++avgctr == navg) {
|
||||||
avgctr=0;
|
avgctr=0;
|
||||||
++nrows;
|
++nrows;
|
||||||
vals = (float*)realloc(vals,sizeof(float)*nrows*nfreqs);
|
vals = (float*)realloc(vals,sizeof(float)*nrows*nfreqs);
|
||||||
|
float eps = 1;
|
||||||
for (i=0;i<nfreqs;++i) {
|
for (i=0;i<nfreqs;++i)
|
||||||
float binpower = fbuf[i].r * fbuf[i].r + fbuf[i].i * fbuf[i].i;
|
vals[(nrows - 1) * nfreqs + i] = 10 * log10 ( mag2buf[i] / navg + eps );
|
||||||
vals[(nrows - 1) * nfreqs + i] = 10 * log10 (binpower);
|
memset(mag2buf,0,sizeof(mag2buf[0])*nfreqs);
|
||||||
}
|
|
||||||
|
|
||||||
memset(avgbuf,0,sizeof(avgbuf[0])*nfreqs);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,7 +182,7 @@ void transform_signal(void)
|
|||||||
free(inbuf);
|
free(inbuf);
|
||||||
free(tbuf);
|
free(tbuf);
|
||||||
free(fbuf);
|
free(fbuf);
|
||||||
free(avgbuf);
|
free(mag2buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
@ -180,7 +190,8 @@ void make_png(void)
|
|||||||
{
|
{
|
||||||
png_bytepp row_pointers=NULL;
|
png_bytepp row_pointers=NULL;
|
||||||
rgb_t * row_data=NULL;
|
rgb_t * row_data=NULL;
|
||||||
size_t i;
|
int i;
|
||||||
|
int nfreqs = nfft/2+1;
|
||||||
|
|
||||||
png_structp png_ptr=NULL;
|
png_structp png_ptr=NULL;
|
||||||
png_infop info_ptr=NULL;
|
png_infop info_ptr=NULL;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user