diff --git a/tools/Makefile b/tools/Makefile index 5c8131f..59bd695 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -2,9 +2,6 @@ ifeq "$(DATATYPE)" "" DATATYPE=float endif -FFTUTIL=fft_$(DATATYPE) -FASTFILT=fastconv_$(DATATYPE) -FASTFILTREAL=fastconvr_$(DATATYPE) ifeq "$(DATATYPE)" "short" TYPEFLAGS=-DFIXED_POINT -Dkiss_fft_scalar=short @@ -12,8 +9,19 @@ else TYPEFLAGS=-Dkiss_fft_scalar=$(DATATYPE) endif +ifeq "$(DATATYPE)" "float" + FFTUTIL=fft + FASTFILT=fastconv + FASTFILTREAL=fastconvr + PSDPNG=psdpng +else + FFTUTIL=fft_$(DATATYPE) + FASTFILT=fastconv_$(DATATYPE) + FASTFILTREAL=fastconvr_$(DATATYPE) + PSDPNG=psdpng_$(DATATYPE) +endif -all: $(FFTUTIL) $(FASTFILT) $(FASTFILTREAL) +all: $(FFTUTIL) $(FASTFILT) $(FASTFILTREAL) $(PSDPNG) #CFLAGS=-Wall -O3 -pedantic -march=pentiumpro -ffast-math -fomit-frame-pointer # If the above flags do not work, try the following @@ -28,5 +36,8 @@ $(FASTFILT): ../kiss_fft.c kiss_fastfir.c $(FFTUTIL): ../kiss_fft.c fftutil.c kiss_fftnd.c kiss_fftr.c $(CC) -o $@ $(CFLAGS) -I.. $(TYPEFLAGS) -lm $+ +$(PSDPNG): ../kiss_fft.c psdpng.c kiss_fftr.c + $(CC) -o $@ $(CFLAGS) -I.. $(TYPEFLAGS) -lm -lpng $+ + clean: - rm -f *~ fft_* fastconv_* fastconvr_* + rm -f *~ fft fft_* fastconv fastconv_* fastconvr fastconvr_* psdpng psdpng_* diff --git a/tools/psdpng.c b/tools/psdpng.c new file mode 100644 index 0000000..10215e5 --- /dev/null +++ b/tools/psdpng.c @@ -0,0 +1,186 @@ +/* +Copyright (c) 2003, Mark Borgerding + +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + * Neither the author nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +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 +#include +#include +#include +#include +#include + +#include "kiss_fft.h" +#include "kiss_fftr.h" + +int nfft=1024; +int nfreqs=0; +int repeat=0; +int window=0; +int colors=256; +FILE * fin=NULL; +FILE * fout=NULL; + +int navg=20; +float * valbuf=NULL; + +png_bytepp row_pointers=NULL; +size_t nrows=0; + +void config(int argc,char** argv) +{ + while (1) { + int c = getopt (argc, argv, "n:rs"); + if (c == -1) + break; + switch (c) { + case 'n': + nfft=atoi(optarg); + case '?': + fprintf (stderr, "usage options:\n" + "\t-n d: fft dimension(s) default = 1024\n" + "stereo 16 bit machine format real input is assumed\n" + ); + default: + fprintf (stderr, "bad %c\n", c); + exit (1); + break; + } + } + if ( optind < argc ) { + if (strcmp("-",argv[optind]) !=0) + fin = fopen(argv[optind],"rb"); + ++optind; + } + + if ( optind < argc ) { + if ( strcmp("-",argv[optind]) !=0 ) + fout = fopen(argv[optind],"wb"); + ++optind; + } + if (fin==NULL) + fin=stdin; + if (fout==NULL) + fout=stdout; +} + +#define CHECKNULL(p) if ( (p)==NULL ) do { fprintf(stderr,"CHECKNULL failed @ %s(%d): %s\n",__FILE__,__LINE__,#p );exit(1);} while(0) + +typedef struct +{ + png_byte r; + png_byte g; + png_byte b; +} rgb_t; + +png_bytep cpx2pixels(kiss_fft_cpx * fbuf,size_t nfreqs) +{ + int i; + rgb_t * res = (rgb_t*)malloc(nfreqs*4 ); + //TODO + + for (i = 0; i < nfreqs; ++i) { + float binpower = fbuf[i].r * fbuf[i].r + fbuf[i].i * fbuf[i].i; + res[i].r = 0; + res[i].g = 0; + res[i].b = 0; + if (i&1) { + res[i].r = i/2; + } + + //valbuf[(nrows - 1) * nfreqs + i] = 10 * log10 (binpower); + } + return res; +} + +void transform_signal() +{ + short *inbuf; + void * cfg=NULL; + kiss_fft_scalar *tbuf; + kiss_fft_cpx *fbuf; + kiss_fft_cpx *avgbuf; + size_t i; + int n; + int avgctr=0; + + nfreqs=nfft/2+1; + + CHECKNULL( cfg=kiss_fftr_alloc(nfft,0,0,0) ); + CHECKNULL( inbuf=(short*)malloc(sizeof(short)*2*nfft ) ); + CHECKNULL( tbuf=(kiss_fft_scalar*)malloc(sizeof(kiss_fft_scalar)*nfft ) ); + CHECKNULL( fbuf=(kiss_fft_cpx*)malloc(sizeof(kiss_fft_cpx)*nfreqs ) ); + CHECKNULL( avgbuf=(kiss_fft_cpx*)malloc(sizeof(kiss_fft_cpx)*nfreqs ) ); + + while ( ( n = fread(inbuf,sizeof(short)*2,nfft,fin) ) == nfft ) { + //pack the shorts + for (i=0;i