From 6369f9cd5e8941c858030a2914d04b24d6d0e839 Mon Sep 17 00:00:00 2001 From: Oona Date: Mon, 21 Jan 2013 08:09:41 +0200 Subject: [PATCH] little FFT display --- common.h | 2 +- gui.c | 42 ++++++++++++++++++++---------------------- slowrx.c | 4 ++-- slowrx.ui | 2 +- video.c | 2 +- vis.c | 8 +++++--- 6 files changed, 30 insertions(+), 30 deletions(-) diff --git a/common.h b/common.h index a20bc18..67e520d 100644 --- a/common.h +++ b/common.h @@ -132,7 +132,7 @@ void *Listen (); void populateDeviceList (); void readPcm (gint numsamples); void saveCurrentPic(); -void setVU (short int PcmValue, int WinIdx); +void setVU (double *Power, int FFTLen, int WinIdx); void evt_AbortRx (); void evt_changeDevices (); diff --git a/gui.c b/gui.c index eb34a95..200922e 100644 --- a/gui.c +++ b/gui.c @@ -77,18 +77,19 @@ void createGUI() { gtk_entry_set_text(GTK_ENTRY(gui.entry_picdir),g_key_file_get_string(config,"slowrx","rxdir",NULL)); } - setVU(0, 6); + //setVU(0, 6); gtk_widget_show_all (gui.window_main); } // Draw signal level meters according to given values -void setVU (short int PcmValue, int WinIdx) { +void setVU (double *Power, int FFTLen, int WinIdx) { int x,y; int PWRdB; guchar *pixelsPWR, *pixelsSNR, *pPWR, *pSNR; unsigned int rowstridePWR,rowstrideSNR; + double logpow; rowstridePWR = gdk_pixbuf_get_rowstride (pixbuf_PWR); pixelsPWR = gdk_pixbuf_get_pixels (pixbuf_PWR); @@ -96,40 +97,37 @@ void setVU (short int PcmValue, int WinIdx) { rowstrideSNR = gdk_pixbuf_get_rowstride (pixbuf_SNR); pixelsSNR = gdk_pixbuf_get_pixels (pixbuf_SNR); - if (PcmValue == 0) - PWRdB = 0; - else - PWRdB = (int)round(10 * log10(pow(PcmValue/32767.0,2))); - for (y=0; y<20; y++) { for (x=0; x<100; x++) { pPWR = pixelsPWR + y * rowstridePWR + (99-x) * 3; pSNR = pixelsSNR + y * rowstrideSNR + (99-x) * 3; - if (y > 1 && y < 18 && x % 2 == 0) { + if (y > 3 && y < 16 && (99-x) % 16 >3 && x % 2 == 0) { - if (PWRdB >= -0.0075*pow(x,2)-3) { - pPWR[0] = 0x89; - pPWR[1] = 0xfe; - pPWR[2] = 0xf4; + if ((5-WinIdx) >= (99-x)/16) { + pSNR[0] = 0x34; + pSNR[1] = 0xe4; + pSNR[2] = 0x84; } else { - pPWR[0] = pPWR[1] = pPWR[2] = 0x80; - } - - if ((6-WinIdx)/0.06 > 100-x) { - pSNR[0] = 0xef; - pSNR[1] = 0xe4; - pSNR[2] = 0x34; - } else { - pSNR[0] = pSNR[1] = pSNR[2] = 0x80; + pSNR[0] = pSNR[2] = 0x60; + pSNR[1] = 0x60; } } else { - pPWR[0] = pPWR[1] = pPWR[2] = 0x40; pSNR[0] = pSNR[1] = pSNR[2] = 0x40; } + logpow = log(2*Power[(int)((99-x)*60/44100.0 * FFTLen)]); + + if (logpow > (19-y)/2.0) { + pPWR[1] = 0xaa; + pPWR[2] = 0xff; + pPWR[0] = 0x33; + } else { + pPWR[0] = pPWR[1] = pPWR[2] = 0; + } + } } diff --git a/slowrx.c b/slowrx.c index c410e62..2725176 100644 --- a/slowrx.c +++ b/slowrx.c @@ -136,7 +136,7 @@ void *Listen() { if (Finished && gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gui.tog_slant))) { // Fix slant - setVU(0,6); + //setVU(0,6); gdk_threads_enter (); gtk_statusbar_push (GTK_STATUSBAR(gui.statusbar), 0, "Calculating slant..." ); gtk_widget_set_sensitive (gui.grid_vu, FALSE); @@ -163,7 +163,7 @@ void *Listen() { // Save PNG if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(gui.tog_save))) { - setVU(0,6); + //setVU(0,6); /*ensure_dir_exists("rx-lum"); LumFile = fopen(lumfilename,"w"); diff --git a/slowrx.ui b/slowrx.ui index a9b56ed..85e5d62 100644 --- a/slowrx.ui +++ b/slowrx.ui @@ -752,7 +752,7 @@ True False - Power + FFT 0 diff --git a/video.c b/video.c index e935c54..1c1648e 100644 --- a/video.c +++ b/video.c @@ -403,7 +403,7 @@ gboolean GetVideo(guchar Mode, double Rate, int Skip, gboolean Redraw) { } /* endif (SampleNum == PixelGrid[PixelIdx].Time) */ if (!Redraw && SampleNum % 8820 == 0) { - setVU(pcm.PeakVal, WinIdx); + setVU(Power, FFTLen, WinIdx); pcm.PeakVal = 0; } diff --git a/vis.c b/vis.c index d690bf7..3e5ff31 100644 --- a/vis.c +++ b/vis.c @@ -52,9 +52,11 @@ guchar GetVIS () { // Find the bin with most power MaxBin = 0; - for (i = GetBin(500, FFTLen); i <= GetBin(3300, FFTLen); i++) { + for (i = 0; i <= GetBin(6000, FFTLen); i++) { Power[i] = pow(out[i], 2) + pow(out[FFTLen - i], 2); - if (MaxBin == 0 || Power[i] > Power[MaxBin]) MaxBin = i; + if ( (i >= GetBin(500,FFTLen) && i < GetBin(3300,FFTLen)) && + (MaxBin == 0 || Power[i] > Power[MaxBin])) + MaxBin = i; } // Find the peak frequency by Gaussian interpolation @@ -156,7 +158,7 @@ guchar GetVIS () { } if (++ptr == 25) { - setVU(pcm.PeakVal, 6); + setVU(Power, 2048, 6); pcm.PeakVal = 0; ptr = 0; }