random alsa stuff

pull/1/merge
Oona 2011-08-09 00:36:47 +03:00
rodzic 4b697b2b16
commit ccc5404555
8 zmienionych plików z 103 dodań i 165 usunięć

Wyświetl plik

@ -7,44 +7,38 @@
#include "common.h"
int VISmap[128];
int VISmap[128];
short int PcmBuffer[2048] = {0};
double *PCM = NULL;
int PcmPointer = 0;
int Sample = 0;
unsigned int SRate = 44100;
double *StoredFreq = NULL;
double StoredFreqRate = 0;
double HedrShift = 0;
int PWRdBthresh[10] = {0, -3, -5, -10, -15, -20, -25, -30, -35, -40};
int SNRdBthresh[10] = {30, 15, 10, 5, 3, 0, -3, -5, -10, -15};
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;
unsigned int SRate = 44100;
double PowerAcc[2048] = {0};
double MaxPower[2048] = {0};
double *StoredFreq = NULL;
double StoredFreqRate = 0;
double HedrShift = 0;
GtkWidget *mainwindow = NULL;
GtkWidget *notebook = NULL;
GdkPixbuf *RxPixbuf = NULL;
GdkPixbuf *DispPixbuf = NULL;
GtkWidget *RxImage = NULL;
GtkWidget *statusbar = NULL;
GtkWidget *snrbar = NULL;
GtkWidget *pwrbar = NULL;
GtkWidget *vugrid = NULL;
GdkPixbuf *VUpixbufPWR = NULL;
GdkPixbuf *VUpixbufDim = NULL;
GdkPixbuf *VUpixbufSNR = NULL;
GtkWidget *PWRimage[10] = {NULL};
GtkWidget *SNRimage[10] = {NULL};
GtkWidget *infolabel = NULL;
GtkWidget *aboutdialog = NULL;
GtkWidget *sdialog = NULL;
GtkWidget *cardcombo = NULL;
GtkWidget *mainwindow = NULL;
GtkWidget *notebook = NULL;
GdkPixbuf *RxPixbuf = NULL;
GdkPixbuf *DispPixbuf = NULL;
GtkWidget *RxImage = NULL;
GtkWidget *statusbar = NULL;
GtkWidget *snrbar = NULL;
GtkWidget *pwrbar = NULL;
GtkWidget *vugrid = NULL;
GdkPixbuf *VUpixbufPWR = NULL;
GdkPixbuf *VUpixbufDim = NULL;
GdkPixbuf *VUpixbufSNR = NULL;
GtkWidget *PWRimage[10] = {NULL};
GtkWidget *SNRimage[10] = {NULL};
GtkWidget *infolabel = NULL;
GtkWidget *aboutdialog = NULL;
GtkWidget *sdialog = NULL;
GtkWidget *cardcombo = NULL;
snd_pcm_t *pcm_handle = NULL;
snd_pcm_t *pcm_handle = NULL;
void ClearPixbuf(GdkPixbuf *pb, unsigned int width, unsigned int height) {
@ -76,9 +70,7 @@ unsigned char clip (double a) {
void setVU(short int PcmValue, double SNRdB) {
int i;
int PWRdBthresh[10] = {0, -1, -2, -3, -5, -7, -10, -15, -20, -25};
int SNRdBthresh[10] = {30, 15, 10, 5, 3, 0, -3, -5, -10, -15};
int PWRdB = (int)round(10 * log10(PcmValue/32767.0));
int PWRdB = (int)round(10 * log10(pow(PcmValue/32767.0,2)));
gdk_threads_enter();
for (i=0; i<10; i++) {

Wyświetl plik

@ -6,44 +6,38 @@
#define SNRSIZE 512
#define SRATE 44100
extern int VISmap[128];
extern FILE *PcmInStream;
extern short int PcmBuffer[2048];
extern double *PCM;
extern int PcmPointer;
extern int Sample;
extern int UseWav;
extern guchar *rgbbuf;
extern int maxpwr;
extern int minpwr;
extern int VISmap[128];
extern short int PcmBuffer[2048];
extern double *PCM;
extern int PcmPointer;
extern int Sample;
extern unsigned int SRate;
extern double PowerAcc[2048];
extern double MaxPower[2048];
extern double *StoredFreq;
extern double StoredFreqRate;
extern double HedrShift;
extern double *StoredFreq;
extern double StoredFreqRate;
extern double HedrShift;
extern int PWRdBthresh[10];
extern int SNRdBthresh[10];
extern GtkWidget *mainwindow;
extern GtkWidget *notebook;
extern GdkPixbuf *RxPixbuf;
extern GdkPixbuf *DispPixbuf;
extern GtkWidget *RxImage;
extern GtkWidget *statusbar;
extern GtkWidget *snrbar;
extern GtkWidget *pwrbar;
extern GtkWidget *vugrid;
extern GdkPixbuf *VUpixbufPWR;
extern GdkPixbuf *VUpixbufSNR;
extern GdkPixbuf *VUpixbufDim;
extern GtkWidget *PWRimage[10];
extern GtkWidget *SNRimage[10];
extern GtkWidget *infolabel;
extern GtkWidget *aboutdialog;
extern GtkWidget *sdialog;
extern GtkWidget *cardcombo;
extern GtkWidget *mainwindow;
extern GtkWidget *notebook;
extern GdkPixbuf *RxPixbuf;
extern GdkPixbuf *DispPixbuf;
extern GtkWidget *RxImage;
extern GtkWidget *statusbar;
extern GtkWidget *snrbar;
extern GtkWidget *pwrbar;
extern GtkWidget *vugrid;
extern GdkPixbuf *VUpixbufPWR;
extern GdkPixbuf *VUpixbufSNR;
extern GdkPixbuf *VUpixbufDim;
extern GtkWidget *PWRimage[10];
extern GtkWidget *SNRimage[10];
extern GtkWidget *infolabel;
extern GtkWidget *aboutdialog;
extern GtkWidget *sdialog;
extern GtkWidget *cardcombo;
extern snd_pcm_t *pcm_handle;
extern snd_pcm_t *pcm_handle;
enum {
UNKNOWN=0,
@ -60,8 +54,8 @@ enum {
};
typedef struct ModeSpecDef {
char *Name;
char *ShortName;
char *Name;
char *ShortName;
double SyncLen;
double PorchLen;
double SeparatorLen;
@ -75,21 +69,16 @@ typedef struct ModeSpecDef {
extern ModeSpecDef ModeSpec[];
void ClearPixbuf(GdkPixbuf *, unsigned int, unsigned int);
void createGUI ();
int GetVideo (int, double, int, int, int);
unsigned int GetBin (double, int);
unsigned char clip (double);
void setVU (short int, double);
int GetVIS ();
double FindSync (unsigned int, int, double, int*);
double deg2rad (double);
void initPcmDevice();
void delete_event ();
void ClearPixbuf (GdkPixbuf *, unsigned int, unsigned int);
void createGUI ();
int GetVideo (int, double, int, int, int);
unsigned int GetBin (double, int);
unsigned char clip (double);
void setVU (short int, double);
int GetVIS ();
double FindSync (unsigned int, int, double, int*);
double deg2rad (double);
void initPcmDevice ();
void delete_event ();
#endif

13
gui.c
Wyświetl plik

@ -41,9 +41,6 @@ void createGUI() {
/* PWR & SNR indicators */
int i;
int PWRdBthresh[10] = {0, -1, -2, -3, -5, -7, -10, -15, -20, -25};
int SNRdBthresh[10] = {30, 15, 10, 5, 3, 0, -3, -5, -10, -15};
char dbstr[40];
/* dB labels */
@ -81,7 +78,7 @@ void createGUI() {
for (y = 0; y < 14; y++) {
for (x = 0; x < 20; x++) {
p = pixels + y * rowstride + x * 3;
p[0] = p[1] = p[2] = (y % 2 ? 192 : 160);
p[0] = p[1] = p[2] = 3*(10-abs(x-10)) + (y % 2 ? 192 : 160);
}
}
@ -92,8 +89,8 @@ void createGUI() {
for (x = 0; x < 20; x++) {
p = pixels + y * rowstride + x * 3;
if (y % 2 == 0) {
p[0] = 42;
p[1] = 127;
p[0] = 42 + 15*(10-abs(x-10));
p[1] = 96 + 12*(10-abs(x-10));
p[2] = 255;
} else {
p[0] = p[1] = p[2] = 192;
@ -109,8 +106,8 @@ void createGUI() {
p = pixels + y * rowstride + x * 3;
if (y % 2 == 0) {
p[0] = 255;
p[1] = 127;
p[2] = 45;
p[1] = 96 + 12*(10-abs(x-10));
p[2] = 45 + 15*(10-abs(x-10));
} else {
p[0] = p[1] = p[2] = 192;
}

22
pcm.c
Wyświetl plik

@ -10,12 +10,13 @@
void initPcmDevice() {
// Select sound card
int card;
char *cardname;
int cardnum,numcards;
int card;
char *cardname;
int cardnum, numcards;
snd_pcm_stream_t PcmInStream = SND_PCM_STREAM_CAPTURE;
snd_pcm_hw_params_t *hwparams;
char pcm_name[30];
unsigned int exact_rate = 44100;
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(cardcombo), "default");
numcards = 0;
@ -29,6 +30,7 @@ void initPcmDevice() {
}
} while (card != -1);
// Select sound card
if (numcards == 0) {
printf("No sound cards found!\n");
@ -45,12 +47,8 @@ void initPcmDevice() {
cardnum = gtk_combo_box_get_active (GTK_COMBO_BOX(cardcombo));
}
snd_pcm_stream_t PcmInStream = SND_PCM_STREAM_CAPTURE;
snd_pcm_hw_params_t *hwparams;
gtk_widget_destroy(sdialog);
char pcm_name[30];
if (cardnum == 0) {
sprintf(pcm_name,"default");
} else {
@ -70,8 +68,6 @@ void initPcmDevice() {
exit(EXIT_FAILURE);
}
unsigned int exact_rate;
if (snd_pcm_hw_params_set_access(pcm_handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED) < 0) {
fprintf(stderr, "ALSA: Error setting interleaved access.\n");
exit(EXIT_FAILURE);
@ -80,8 +76,6 @@ void initPcmDevice() {
fprintf(stderr, "ALSA: Error setting format S16_LE.\n");
exit(EXIT_FAILURE);
}
exact_rate = 44100;
if (snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams, &exact_rate, 0) < 0) {
fprintf(stderr, "ALSA: Error setting sample rate.\n");
exit(EXIT_FAILURE);

Wyświetl plik

@ -33,7 +33,7 @@ void *Listen() {
unsigned char *Lum;
FILE *LumFile;
while (1) {
while (TRUE) {
// Wait for VIS
HedrShift = 0;
@ -41,6 +41,8 @@ void *Listen() {
gtk_widget_set_sensitive(vugrid, TRUE);
gdk_threads_leave();
snd_pcm_prepare(pcm_handle);
snd_pcm_start (pcm_handle);
Mode = GetVIS();
if (Mode == -1) exit(0);
@ -81,7 +83,6 @@ void *Listen() {
Skip = 0;
printf(" getvideo @ %.02f Hz, Skip %d, HedrShift %.0f Hz\n", Rate, Skip, HedrShift);
snd_pcm_start(pcm_handle);
GetVideo(Mode, Rate, Skip, TRUE, FALSE);
snd_pcm_drop(pcm_handle);

Wyświetl plik

@ -198,46 +198,6 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkFrame" id="frame3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkAlignment" id="alignment3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="top_padding">10</property>
<property name="bottom_padding">10</property>
<property name="left_padding">12</property>
<property name="right_padding">10</property>
<child>
<object class="GtkSwitch" id="rxswitch">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="label5">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Rx</property>
<property name="use_markup">True</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">5</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkFrame" id="frame2">
<property name="visible">True</property>
@ -256,6 +216,7 @@
<object class="GtkGrid" id="vugrid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="row_spacing">2</property>
<property name="n_rows">11</property>
<property name="n_columns">4</property>
<child>
@ -423,9 +384,12 @@
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">5</property>
<property name="position">1</property>
<property name="position">0</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>

Wyświetl plik

@ -42,14 +42,12 @@ int GetVideo(int Mode, double Rate, int Skip, int Adaptive, int Redraw) {
in = fftw_malloc(sizeof(double) * 2048);
if (in == NULL) {
perror("GetVideo: Unable to allocate memory for FFT");
pclose(PcmInStream);
free(PCM);
exit(EXIT_FAILURE);
}
out = fftw_malloc(sizeof(double) * 2048);
if (out == NULL) {
perror("GetVideo: Unable to allocate memory for FFT");
pclose(PcmInStream);
fftw_free(in);
free(PCM);
exit(EXIT_FAILURE);

15
vis.c
Wyświetl plik

@ -32,14 +32,12 @@ int GetVIS () {
in = fftw_malloc(sizeof(double) * FFTLen);
if (in == NULL) {
perror("GetVIS: Unable to allocate memory for FFT");
pclose(PcmInStream);
exit(EXIT_FAILURE);
}
out = fftw_malloc(sizeof(double) * FFTLen);
if (out == NULL) {
perror("GetVIS: Unable to allocate memory for FFT");
pclose(PcmInStream);
fftw_free(in);
exit(EXIT_FAILURE);
}
@ -64,7 +62,6 @@ int GetVIS () {
PCM = calloc(SRATE, sizeof(double));
if (PCM == NULL) {
perror("GetVIS: Unable to allocate memory for PCM");
pclose(PcmInStream);
exit(EXIT_FAILURE);
}
@ -76,6 +73,12 @@ int GetVIS () {
if (samplesread == -EPIPE) {
printf("ALSA buffer overrun :(\n");
exit(EXIT_FAILURE);
} else if (samplesread == -EBADFD) {
printf("ALSA: PCM is not in the right state\n");
exit(EXIT_FAILURE);
} else if (samplesread == -ESTRPIPE) {
printf("ALSA: a suspend event occurred\n");
exit(EXIT_FAILURE);
} else if (samplesread < 0) {
printf("ALSA error\n");
exit(EXIT_FAILURE);
@ -86,7 +89,7 @@ int GetVIS () {
PCM[i] = PCM[i + samplesread];
PCM[i+samplesread] = PcmBuffer[i];
// Keep track of max amplitude for VU meter
// Keep track of max power for VU meter
if (abs(PcmBuffer[i]) > MaxPcm) MaxPcm = abs(PcmBuffer[i]);
}
@ -144,8 +147,8 @@ int GetVIS () {
visfail = FALSE;
for (k = 0; k < 8; k++) {
if (tone[18+i+3*k] > tone[0+j] - 625 && tone[18+i+3*k] < tone[0+j] - 575) Bit[k] = 0; // logic zero
else if (tone[18+i+3*k] > tone[0+j] - 825 && tone[18+i+3*k] < tone[0+j] - 775) Bit[k] = 1; // logic one
if (tone[18+i+3*k] > tone[0+j] - 625 && tone[18+i+3*k] < tone[0+j] - 575) Bit[k] = 0;
else if (tone[18+i+3*k] > tone[0+j] - 825 && tone[18+i+3*k] < tone[0+j] - 775) Bit[k] = 1;
else { // erroneous bit
visfail = TRUE;
break;