]> hackdaworld.org Git - sound-tools/hdrec.git/commitdiff
print frequency spectrum using directfb
authorhackbard <hackbard>
Fri, 24 Sep 2004 10:57:57 +0000 (10:57 +0000)
committerhackbard <hackbard>
Fri, 24 Sep 2004 10:57:57 +0000 (10:57 +0000)
Makefile
hdrec.c

index 6bd5fd0e38926aaed8fa0e37930f6954cd7aeef5..a27d210d02a9025115695301ec4f08fdd8a8c740 100644 (file)
--- 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 c6945f5d5f3d62fb7787ab0d396be1d73169c19c..bf36409d6733216d546c884c76a6cc6d0662026c 100644 (file)
--- a/hdrec.c
+++ b/hdrec.c
@@ -5,6 +5,7 @@
  *
  */
 
+#define _GNU_SOURCE
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 #include <errno.h>
 
+/* dfb */
+#include <directfb.h>
+
 #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;sample<fourier.data_len[0];sample++) fourier.data[sample].r=*((signed short *)buf+(set.format&AFMT_S16_LE?2:1)*sample);
+                               fourier_dft_1d(&fourier);
+                               /* print graph */
+                               primary->Clear(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;sample<fourier.data_len[0]/8;sample++) primary->FillRectangle(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))) {