slowrx/common.c

102 wiersze
2.7 KiB
C
Czysty Zwykły widok Historia

2011-07-07 14:09:57 +00:00
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
2011-07-29 20:09:42 +00:00
#include <gtk/gtk.h>
#include <alsa/asoundlib.h>
2011-07-07 14:09:57 +00:00
#include "common.h"
2011-08-03 20:25:05 +00:00
int VISmap[128];
2011-07-07 14:09:57 +00:00
FILE *PcmInStream = NULL;
short int PcmBuffer[2048] = {0};
double *PCM = NULL;
int PcmPointer = 0;
int Sample = 0;
int UseWav = FALSE;
guchar *rgbbuf = NULL;
int maxpwr = 0;
int minpwr = 0;
2011-07-29 20:09:42 +00:00
unsigned int SRate = 44100;
2011-07-07 14:09:57 +00:00
double PowerAcc[2048] = {0};
double MaxPower[2048] = {0};
double *StoredFreq = NULL;
double StoredFreqRate = 0;
double HedrShift = 0;
2011-08-02 23:42:56 +00:00
GtkWidget *mainwindow = NULL;
2011-07-07 14:09:57 +00:00
GtkWidget *notebook = NULL;
2011-08-02 23:42:56 +00:00
GdkPixbuf *RxPixbuf = NULL;
2011-07-29 13:01:30 +00:00
GdkPixbuf *DispPixbuf = NULL;
2011-08-02 23:42:56 +00:00
GtkWidget *RxImage = NULL;
2011-07-07 14:09:57 +00:00
GtkWidget *statusbar = NULL;
GtkWidget *snrbar = NULL;
GtkWidget *pwrbar = NULL;
2011-08-02 23:42:56 +00:00
GtkWidget *vugrid = NULL;
GdkPixbuf *VUpixbufPWR = NULL;
2011-07-07 14:09:57 +00:00
GdkPixbuf *VUpixbufDim = NULL;
GdkPixbuf *VUpixbufSNR = NULL;
2011-08-02 23:42:56 +00:00
GtkWidget *PWRimage[10] = {NULL};
2011-07-07 14:09:57 +00:00
GtkWidget *SNRimage[10] = {NULL};
GtkWidget *infolabel = NULL;
2011-08-02 23:42:56 +00:00
GtkWidget *aboutdialog = NULL;
2011-08-07 17:46:35 +00:00
GtkWidget *sdialog = NULL;
GtkWidget *cardcombo = NULL;
2011-07-07 14:09:57 +00:00
2011-08-03 20:25:05 +00:00
snd_pcm_t *pcm_handle = NULL;
2011-07-29 20:09:42 +00:00
2011-07-07 14:09:57 +00:00
void ClearPixbuf(GdkPixbuf *pb, unsigned int width, unsigned int height) {
unsigned int x,y,rowstride;
guchar *pixels, *p;
rowstride = gdk_pixbuf_get_rowstride (pb);
pixels = gdk_pixbuf_get_pixels(pb);
for (y = 0; y < height; y++) {
for (x = 0; x < width; x++) {
p = pixels + y * rowstride + x * 3;
p[0] = p[1] = p[2] = 192;
}
}
}
// Return the bin index matching the given frequency
2011-07-25 12:05:03 +00:00
unsigned int GetBin (double Freq, int FFTLen) {
2011-07-29 20:09:42 +00:00
return (Freq / SRATE * FFTLen);
2011-07-07 14:09:57 +00:00
}
// Clip to [0..255]
unsigned char clip (double a) {
if (a < 0) return 0;
else if (a > 255) return 255;
return (unsigned char)round(a);
}
void setVU(short int PcmValue, double SNRdB) {
int i;
2011-08-02 23:42:56 +00:00
int PWRdBthresh[10] = {0, -1, -2, -3, -5, -7, -10, -15, -20, -25};
2011-07-07 14:09:57 +00:00
int SNRdBthresh[10] = {30, 15, 10, 5, 3, 0, -3, -5, -10, -15};
2011-08-02 23:42:56 +00:00
int PWRdB = (int)round(10 * log10(PcmValue/32767.0));
2011-07-07 14:09:57 +00:00
gdk_threads_enter();
for (i=0; i<10; i++) {
2011-08-02 23:42:56 +00:00
if (PWRdB >= PWRdBthresh[i]) gtk_image_set_from_pixbuf(GTK_IMAGE(PWRimage[i]), VUpixbufPWR);
else gtk_image_set_from_pixbuf(GTK_IMAGE(PWRimage[i]), VUpixbufDim);
2011-07-07 14:09:57 +00:00
if (SNRdB >= SNRdBthresh[i]) gtk_image_set_from_pixbuf(GTK_IMAGE(SNRimage[i]), VUpixbufSNR);
else gtk_image_set_from_pixbuf(GTK_IMAGE(SNRimage[i]), VUpixbufDim);
}
gdk_threads_leave();
}
double deg2rad (double Deg) {
return (Deg / 180) * M_PI;
}
2011-08-02 23:42:56 +00:00
void delete_event() {
gtk_main_quit ();
}