getting ready for next release

This commit is contained in:
Mark Borgerding
2003-10-26 04:07:32 +00:00
parent 52b4b9ab5c
commit 1db3d91ee5
9 changed files with 68 additions and 314 deletions

View File

@ -1,9 +1,17 @@
NFFT=840
ifeq "$(NFFT)" ""
NFFT=1024
endif
ALLUTILS=kfft kffts kfftd
NUMFFTS=10000
ifeq "$(NUMFFTS)" ""
NUMFFTS=10000
endif
UTILSRC=../kiss_fft.c fftutil.c
CFLAGS=-Wall -O3 -lm -I.. -ansi -DFUNCDECL= -pedantic
CFLAGS=-Wall -O3 -lm -I.. -ansi -pedantic
all: $(ALLUTILS)
@ -17,7 +25,7 @@ kfftd: $(UTILSRC)
time: all
@echo
@echo "#### timing $(NUMFFTS) x $(NFFT) point FFTs"
@echo -n "#### timing $(NUMFFTS) x $(NFFT) point FFTs. "; factor $(NFFT)
@echo "#### DOUBLE"
@time -f 'Elapsed:%E user:%U sys:%S' \
sh -c 'dd if=/dev/zero bs=$$((16*$(NFFT))) count=$(NUMFFTS) 2>/dev/null |./kfftd>/dev/null'
@ -28,6 +36,14 @@ time: all
@time -f 'Elapsed:%E user:%U sys:%S' \
sh -c 'dd if=/dev/zero bs=$$((4*$(NFFT))) count=$(NUMFFTS) 2>/dev/null |./kffts>/dev/null'
POW2=256 512 1024 2048
POW3=243 729 2187
mtime: all
@for n in $(POW2) ;do \
export NFFT=$$n;make time; \
done
snr: all
@which octave
@echo

View File

@ -1,87 +0,0 @@
#include <stdio.h>
#include <string.h>
#include <memory.h>
#include <malloc.h>
#include <stdio.h>
#include <math.h>
#include "kiss_fft.h"
#define NFFT 1024
int main(int argc, char ** argv)
{
int k;
void * st;
float fs=44100;
short sampsin[2*NFFT];
float lmag2[NFFT/2];
float rmag2[NFFT/2];
int peakr=0,peakl=0;
int removedc=1;
kiss_fft_cpx cbuf[NFFT];
int nbufs=0;
st = kiss_fft_alloc(NFFT,0);
memset( lmag2 , 0 , sizeof(lmag2) );
memset( rmag2 , 0 , sizeof(rmag2) );
while ( fread( sampsin , sizeof(short) * 2*NFFT, 1 , stdin ) == 1 ) {
//perform two ffts in parallel by packing the left&right channels into the real and imaginary
for (k=0;k<NFFT;++k) {
cbuf[k].r = sampsin[2*k];
cbuf[k].i = sampsin[2*k+1];
}
if (removedc) {
float dcr=0,dci=0;
for (k=0;k<NFFT;++k){
dcr += cbuf[k].r;
dci += cbuf[k].i;
}
dcr /= NFFT;
dci /= NFFT;
for (k=0;k<NFFT;++k) {
cbuf[k].r -= dcr;
cbuf[k].i -= dci;
}
}
// perform the fft on the L+R packed buffer
kiss_fft( st , cbuf );
// get the half-symmetric FFTs for the Left and Right Channels
for (k=0;k<NFFT/2;++k) {
int k2 = (NFFT-k)%NFFT;
kiss_fft_cpx r,l;
r.r = (cbuf[k].r + cbuf[k2].r) * 0.5;
r.i = (cbuf[k].i - cbuf[k2].i) * 0.5;
l.r = (cbuf[k].i + cbuf[k2].i) * 0.5;
l.i = (cbuf[k].r - cbuf[k2].r) * 0.5;
rmag2[k] += r.r * r.r + r.i * r.i;
lmag2[k] += l.r * l.r + l.i * l.i;
}
++nbufs;
}
free(st);
for (k=0;k<NFFT/2;++k) {
if (rmag2[peakr] < rmag2[k])
peakr = k;
if (lmag2[peakl] < lmag2[k])
peakl = k;
}
printf("%d buffers\n",nbufs);
printf("peak frequency R:%.3fdB @ %.1f Hz\n",10*log10(rmag2[peakr]) , peakr*fs/NFFT);
printf(" L:%.3fdB @ %.1f Hz\n",10*log10(lmag2[peakl]) , peakl*fs/NFFT);
return 0;
}

View File

@ -1,80 +0,0 @@
/*
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 <stdlib.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#ifndef BUFSIZE
# define BUFSIZE 1024
#endif
int main(int argc, char ** argv)
{
FILE * f1=stdin;
FILE * f2=stdin;
int i,n;
TYPE buf1[BUFSIZE];
TYPE buf2[BUFSIZE];
double sigpower=0;
double noisepower=0;
double snrdb=0;
double scale=0;
long ntotal=0;
if (argc>1 && strcmp( argv[1] ,"-") != 0 ) {
f1 = fopen(argv[1],"rb");
}
if (argc>2 && strcmp( argv[2] ,"-") != 0 ) {
f2 = fopen(argv[2],"rb");
}
// TODO LEFT OFF HERE
while ( ( n = fread( buf1 , sizeof(TYPE) , BUFSIZE , f1 ) ) > 0 ) {
if ( fread( buf2 , sizeof(TYPE) , BUFSIZE , f2 ) != n ) {
fprintf(stderr,"premature end of file 2\n");
exit(1);
}
for (i=0;i<n;++i) {
double s=buf1[i];
double n = s - buf2[i];
sigpower += s*s;
noisepower += n*n;
if (s!=0) {
++ntotal;
scale += buf2[i] / s;
}
}
}
if ( fread( buf2 , sizeof(TYPE) , BUFSIZE , f2 ) > 0 ) {
fprintf(stderr,"premature end of file 1\n");
exit(1);
}
scale /= ntotal;
if (noisepower>0)
snrdb = 10*log10( sigpower / noisepower );
else
snrdb = 200;
printf("snr = %.2f dB\n",snrdb);
printf("average output/input = %.5e\n",scale);
return 0;
}

View File

@ -1,46 +0,0 @@
/*
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 <stdlib.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#define BUFSIZE 1024
int main(int argc, char ** argv )
{
int i,n;
TYPE1 buf1[BUFSIZE];
TYPE2 buf2[BUFSIZE];
double mult=1.0;
for (i=1;i<argc;++i){
if (strcmp("-m",argv[i])==0){
mult *= atof(argv[i+1] );
++i;
}else if (strcmp("-d",argv[i])==0){
mult /= atof(argv[i+1] );
++i;
}
}
while ( ( n = fread( buf1 , sizeof(TYPE1) , BUFSIZE , stdin ) ) > 0 ) {
for (i=0;i<n;++i)
buf2[i] = (TYPE1)(mult * buf1[i]);
fwrite( buf2 , sizeof(TYPE2) , n , stdout );
}
return 0;
}