From: hackbard Date: Fri, 24 Sep 2004 10:57:57 +0000 (+0000) Subject: print frequency spectrum using directfb X-Git-Url: https://hackdaworld.org/gitweb/?a=commitdiff_plain;h=10957fd9492f1a6ddd041f69b45e28f9ae8895bf;p=sound-tools%2Fhdrec.git print frequency spectrum using directfb --- diff --git a/Makefile b/Makefile index 6bd5fd0..a27d210 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ # Makefile of hdrec -CFLAGS = -O3 -Wall +CFLAGS = -O3 -Wall -I/usr/include/directfb CC = gcc TARGETS = hdrec @@ -8,7 +8,7 @@ TARGETS = hdrec all: $(TARGETS) hdrec: - $(CC) $(CFLAGS) -Wall oss_api.c hdrec.c -o hdrec + $(CC) $(CFLAGS) -Wall fourier.c oss_api.c hdrec.c -o hdrec -lm -ldirectfb clean: rm $(OBJS) hdrec diff --git a/hdrec.c b/hdrec.c index c6945f5..bf36409 100644 --- a/hdrec.c +++ b/hdrec.c @@ -5,6 +5,7 @@ * */ +#define _GNU_SOURCE #include #include #include @@ -18,9 +19,15 @@ #include #include +/* dfb */ +#include + #include "oss_api.h" #include "hdrec.h" +/* fourier */ +#include "fourier.h" + int usage(void) { printf("usage:\n\n"); printf("-h \t\t print this help\n"); @@ -61,6 +68,18 @@ int main(int argc,char **argv) { struct timeval fds_tv; char c; + /* dfb */ + IDirectFB *dfb; + IDirectFBSurface *primary; + DFBSurfaceDescription dsc; + int width,height; + + /* fourier */ + t_fourier fourier; + int sample; + int dx; + int a_f; + /* defaults */ strcpy(device,""); set.format=AFMT_S16_LE; @@ -192,6 +211,7 @@ int main(int argc,char **argv) { perror("malloc"); return -1; } + if((mode&RECORD) && (mode&PLAY)) { if((buf2=malloc(set.bufsize*sizeof(unsigned char)))==NULL) { printf("allocating 2nd memory failed :(\n"); @@ -201,12 +221,49 @@ int main(int argc,char **argv) { } if((mode&PLAY) && (!(mode&RECORD))) { + + /* dfb */ + DirectFBInit(&argc,&argv); + DirectFBCreate(&dfb); + dfb->SetCooperativeLevel(dfb,DFSCL_FULLSCREEN); + dsc.flags=DSDESC_CAPS; + dsc.caps=DSCAPS_PRIMARY|DSCAPS_FLIPPING; + dfb->CreateSurface(dfb,&dsc,&primary); + primary->GetSize(primary,&width,&height); + dprintf(1,"graphical equalizer dims: %dx%d\n",width,height); + primary->SetColor(primary,0x80,0x80,0xff,0xff); + //primary->Flip(primary,NULL,DSFLIP_WAITFORSYNC); + + /* fourier */ + fourier_init(&fourier,1); + fourier.type=FWD|DFT; + fourier.dim=1; + fourier.data_len[0]=set.bufsize/(set.format&AFMT_S16_LE?4:2); + fourier_alloc_data(&fourier); + printf("debug: allocated size for %d samples to do dft\n",fourier.data_len[0]); + dx=8*width/fourier.data_len[0]; + printf("debug: dx = %d ???\n",dx); + printf("playing file %s ...\n",play_file); if(mode&REVERSED) printf("but we do it reversed!\n"); rw=1; if(!(mode&REVERSED)) { while(rw) { + /* read samples */ rw=read(pfile_fd,buf,set.bufsize); + /* do fourier trafo */ + for(sample=0;sampleClear(primary,0,0,0,0xff); + a_f=dx*fourier.data_len[0]*440/set.freq; + primary->DrawLine(primary,a_f,height,a_f,0); + for(sample=0;sampleFillRectangle(primary,sample*dx,0,dx,height*sqrt(fourier.ftdata[sample].r*fourier.ftdata[sample].r+fourier.ftdata[sample].i*fourier.ftdata[sample].i)/0x7fff); + primary->Flip(primary,NULL,DSFLIP_WAITFORSYNC); + //fcount=0; + + //} + write(audio_fd,buf,set.bufsize); } } else { @@ -229,6 +286,11 @@ int main(int argc,char **argv) { write(audio_fd,buf,set.bufsize); } } + + /* dfb release */ + primary->Release(primary); + dfb->Release(dfb); + } if((mode&RECORD) && (!(mode&PLAY))) {