pull/1/merge
Oona 2011-08-20 14:49:29 +03:00
rodzic f43de3c347
commit 84f325dc86
12 zmienionych plików z 76 dodań i 64 usunięć

Wyświetl plik

@ -12,7 +12,7 @@ Features
* Adaptive noise reduction
* Decode digital FSK ID
* Save received pictures as PNG
* Written in C
* Written in C99
Requirements
------------

Wyświetl plik

@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#include <gtk/gtk.h>
@ -12,15 +13,15 @@ gint16 *PcmBuffer = NULL;
int PcmPointer = 0;
int MaxPcm = 0;
guchar *StoredLum = NULL;
guchar *HasSync = NULL;
bool *HasSync = NULL;
double *in = NULL;
double *out = NULL;
gshort HedrShift = 0;
int PWRdBthresh[10] = {-3, -5, -10, -15, -20, -25, -30, -40, -50, 60};
int SNRdBthresh[10] = {30, 15, 10, 5, 3, 0, -3, -5, -10, -15};
gboolean Adaptive = TRUE;
gboolean ManualActivated = FALSE;
gboolean Abort = FALSE;
bool Adaptive = true;
bool ManualActivated = false;
bool Abort = false;
GtkWidget *RxImage = NULL;
GtkWidget *statusbar = NULL;
@ -82,10 +83,10 @@ void GetAdaptive() {
// Manual Start clicked
void ManualStart() {
ManualActivated = TRUE;
ManualActivated = true;
}
// Abort clicked
void AbortRx() {
Abort = TRUE;
Abort = true;
}

Wyświetl plik

@ -15,10 +15,10 @@ extern guchar *StoredLum;
extern double *in;
extern double *out;
extern gshort HedrShift;
extern gboolean Adaptive;
extern gboolean ManualActivated;
extern gboolean Abort;
extern guchar *HasSync;
extern bool Adaptive;
extern bool ManualActivated;
extern bool Abort;
extern bool *HasSync;
extern GtkWidget *RxImage;
extern GtkWidget *statusbar;
@ -84,7 +84,7 @@ typedef struct ModeSpecDef {
extern ModeSpecDef ModeSpec[];
void createGUI ();
gboolean GetVideo (guchar Mode, double Rate, int Skip, gboolean Redraw);
bool GetVideo (guchar Mode, double Rate, int Skip, bool Redraw);
guint GetBin (double Freq, guint FFTLen);
guchar clip (double a);
void setVU (short int PcmValue, double SNRdB);

11
fsk.c
Wyświetl plik

@ -1,4 +1,5 @@
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#include <fftw3.h>
#include <gtk/gtk.h>
@ -21,14 +22,14 @@ void GetFSK (char *dest) {
guint FFTLen = 2048, i=0, LoBin, HiBin, MidBin;
guchar AsciiByte = 0, ThisByteIndex = 0;
double HiPow,LoPow,Hann[970];
gboolean InFSK = FALSE, InCode = FALSE, EndFSK = FALSE;
bool InFSK = false, InCode = false, EndFSK = false;
for (i = 0; i < FFTLen; i++) in[i] = 0;
// Create 22ms Hann window
for (i = 0; i < 970; i++) Hann[i] = 0.5 * (1 - cos( 2 * M_PI * i / 969.0 ) );
while ( TRUE ) {
while ( true ) {
// Read 11 ms from DSP
readPcm(485);
@ -54,7 +55,7 @@ void GetFSK (char *dest) {
Bit = (HiPow<LoPow);
if (Bit != PrevBit) {
if (RunLength/2.0 > 3) InFSK = TRUE;
if (RunLength/2.0 > 3) InFSK = true;
if (InFSK) {
if (RunLength/2.0 < .5) break;
@ -68,7 +69,7 @@ void GetFSK (char *dest) {
if (ThisBitIndex > 0 && ThisBitIndex % 6 == 0) {
// Consider end of data when values would only produce special characters
if ( (AsciiByte&0x3F) < 0x0c) {
EndFSK = TRUE;
EndFSK = true;
break;
}
dest[ThisByteIndex] = (AsciiByte&0x3F)+0x20;
@ -78,7 +79,7 @@ void GetFSK (char *dest) {
if (AsciiByte == 0x55 && !InCode) {
ThisBitIndex=-1;
InCode = TRUE;
InCode = true;
}
}

19
gui.c
Wyświetl plik

@ -1,4 +1,5 @@
#include <stdlib.h>
#include <stdbool.h>
#include <gtk/gtk.h>
#include <alsa/asoundlib.h>
#include <math.h>
@ -55,26 +56,26 @@ void createGUI() {
g_signal_connect (btnstart, "clicked", G_CALLBACK(ManualStart), NULL);
g_signal_connect (btnabort, "clicked", G_CALLBACK(AbortRx), NULL);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(togslant), TRUE);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(togsave), TRUE);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(togadapt), TRUE);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(togrx), TRUE);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(togfsk), TRUE);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(togslant), true);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(togsave), true);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(togadapt), true);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(togrx), true);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(togfsk), true);
gtk_combo_box_set_active (GTK_COMBO_BOX(modecombo), 0);
gtk_widget_set_sensitive (btnabort, FALSE);
gtk_widget_set_sensitive (btnabort, false);
savedstore = gtk_list_store_new (2, GDK_TYPE_PIXBUF, G_TYPE_STRING);
gtk_icon_view_set_model (GTK_ICON_VIEW(iconview), GTK_TREE_MODEL(savedstore));
gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW(iconview), 0);
gtk_icon_view_set_text_column (GTK_ICON_VIEW(iconview), 1);
RxPixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 320, 256);
RxPixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, false, 8, 320, 256);
gdk_pixbuf_fill(RxPixbuf, 0);
DispPixbuf = gdk_pixbuf_scale_simple (RxPixbuf, 500, 400, GDK_INTERP_BILINEAR);
gtk_image_set_from_pixbuf(GTK_IMAGE(RxImage), DispPixbuf);
pixbufPWR = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 100, 20);
pixbufSNR = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 100, 20);
pixbufPWR = gdk_pixbuf_new (GDK_COLORSPACE_RGB, false, 8, 100, 20);
pixbufSNR = gdk_pixbuf_new (GDK_COLORSPACE_RGB, false, 8, 100, 20);
setVU(0, -100);

Wyświetl plik

@ -1,5 +1,6 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <gtk/gtk.h>
#include <alsa/asoundlib.h>
#include <fftw3.h>

1
pcm.c
Wyświetl plik

@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <gtk/gtk.h>

Wyświetl plik

@ -6,6 +6,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#include <time.h>
@ -28,7 +29,7 @@ void *Listen() {
struct tm *timeptr = NULL;
time_t timet;
FILE *LumFile;
gboolean Finished;
bool Finished;
GdkPixbuf *thumbbuf;
char id[20];
GtkTreeIter iter;
@ -52,11 +53,11 @@ void *Listen() {
Plan2048 = fftw_plan_r2r_1d(2048, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
while (TRUE) {
while (true) {
gdk_threads_enter ();
gtk_widget_set_sensitive (vugrid, TRUE);
gtk_widget_set_sensitive (btnabort, FALSE);
gtk_widget_set_sensitive (vugrid, true);
gtk_widget_set_sensitive (btnabort, false);
gdk_threads_leave ();
HedrShift = 0;
@ -89,7 +90,7 @@ void *Listen() {
}
// Allocate space for sync signal
HasSync = calloc((int)(ModeSpec[Mode].LineLen * ModeSpec[Mode].ImgHeight / 1.5e-3 +1), sizeof(guchar));
HasSync = calloc((int)(ModeSpec[Mode].LineLen * ModeSpec[Mode].ImgHeight / 1.5e-3 +1), sizeof(bool));
if (HasSync == NULL) {
perror("Listen: Unable to allocate memory for sync signal");
exit(EXIT_FAILURE);
@ -100,18 +101,18 @@ void *Listen() {
snprintf(infostr, sizeof(infostr)-1, "%s, %s UTC", ModeSpec[Mode].Name, rctime);
gdk_threads_enter ();
gtk_label_set_text (GTK_LABEL(idlabel), "");
gtk_widget_set_sensitive (manualframe, FALSE);
gtk_widget_set_sensitive (btnabort, TRUE);
gtk_widget_set_sensitive (manualframe, false);
gtk_widget_set_sensitive (btnabort, true);
gtk_statusbar_push (GTK_STATUSBAR(statusbar), 0, "Receiving video..." );
gtk_label_set_markup (GTK_LABEL(infolabel), infostr);
gdk_threads_leave ();
printf(" getvideo @ %.1f Hz, Skip %d, HedrShift %d Hz\n", 44100.0, 0, HedrShift);
Finished = GetVideo(Mode, 44100, 0, FALSE);
Finished = GetVideo(Mode, 44100, 0, false);
gdk_threads_enter ();
gtk_widget_set_sensitive (btnabort, FALSE);
gtk_widget_set_sensitive (manualframe, TRUE);
gtk_widget_set_sensitive (btnabort, false);
gtk_widget_set_sensitive (manualframe, true);
gdk_threads_leave ();
id[0] = '\0';
@ -135,7 +136,7 @@ void *Listen() {
setVU(0,-100);
gdk_threads_enter ();
gtk_statusbar_push (GTK_STATUSBAR(statusbar), 0, "Calculating slant..." );
gtk_widget_set_sensitive (vugrid, FALSE);
gtk_widget_set_sensitive (vugrid, false);
gdk_threads_leave ();
printf(" FindSync @ %.1f Hz\n",Rate);
Rate = FindSync(Mode, Rate, &Skip);
@ -145,7 +146,7 @@ void *Listen() {
gtk_statusbar_push (GTK_STATUSBAR(statusbar), 0, "Redrawing..." );
gdk_threads_leave ();
printf(" getvideo @ %.1f Hz, Skip %d, HedrShift %d Hz\n", Rate, Skip, HedrShift);
GetVideo(Mode, Rate, Skip, TRUE);
GetVideo(Mode, Rate, Skip, true);
}
free (HasSync);

Wyświetl plik

@ -410,8 +410,8 @@
<item translatable="yes">Pasokon P3</item>
<item translatable="yes">Pasokon P5</item>
<item translatable="yes">Pasokon P7</item>
<item translatable="yes">Wraase SC2 120</item>
<item translatable="yes">Wraase SC2 180</item>
<item translatable="yes">Wraase SC-2 120</item>
<item translatable="yes">Wraase SC-2 180</item>
</items>
</object>
<packing>
@ -695,6 +695,12 @@
<property name="height">1</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
</object>

5
sync.c
Wyświetl plik

@ -1,4 +1,5 @@
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#include <string.h>
#include <fftw3.h>
@ -23,12 +24,12 @@ double FindSync (guchar Mode, double Rate, int *Skip) {
gushort xAcc[700] = {0}, xmax, s;
gushort lines[600][(MAXSLANT-MINSLANT)*2];
gushort cy, cx, Retries = 0;
guchar SyncImg[700][630] = {{FALSE}};
bool SyncImg[700][630] = {{false}};
double t=0, slantAngle;
// Repeat until slant < 0.5° or until we give up
while (TRUE) {
while (true) {
// Draw the 2D sync signal at current rate

24
video.c
Wyświetl plik

@ -1,5 +1,6 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <math.h>
#include <string.h>
#include <fftw3.h>
@ -13,9 +14,9 @@
* Rate: exact sampling rate used
* Skip: number of PCM samples to skip at the beginning (for sync phase adjustment)
* Redraw: false = Apply windowing and FFT to the signal, true = Redraw from cached FFT data
* returns: TRUE when finished, FALSE when aborted
* returns: true when finished, false when aborted
*/
gboolean GetVideo(guchar Mode, double Rate, int Skip, gboolean Redraw) {
bool GetVideo(guchar Mode, double Rate, int Skip, bool Redraw) {
guint MaxBin = 0;
guint VideoPlusNoiseBins=0, ReceiverBins=0, NoiseOnlyBins=0;
@ -87,7 +88,7 @@ gboolean GetVideo(guchar Mode, double Rate, int Skip, gboolean Redraw) {
// Initialize pixbuffer
if (!Redraw) {
g_object_unref(RxPixbuf);
RxPixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, ModeSpec[Mode].ImgWidth, ModeSpec[Mode].ImgHeight);
RxPixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, false, 8, ModeSpec[Mode].ImgWidth, ModeSpec[Mode].ImgHeight);
gdk_pixbuf_fill(RxPixbuf, 0);
}
@ -106,7 +107,7 @@ gboolean GetVideo(guchar Mode, double Rate, int Skip, gboolean Redraw) {
Length = ModeSpec[Mode].LineLen * ModeSpec[Mode].ImgHeight * 44100;
SyncTargetBin = GetBin(1200+HedrShift, FFTLen);
LopassBin = GetBin(3000, FFTLen);
Abort = FALSE;
Abort = false;
SyncSample = 0;
// Loop through signal
@ -147,8 +148,8 @@ gboolean GetVideo(guchar Mode, double Rate, int Skip, gboolean Redraw) {
// If there is more than twice the amount of power per Hz in the
// sync band than in the rest of the band, we have a sync signal here
if (Psync > 2*Praw) HasSync[SyncSample] = TRUE;
else HasSync[SyncSample] = FALSE;
if (Psync > 2*Praw) HasSync[SyncSample] = true;
else HasSync[SyncSample] = false;
NextSyncTime += 1.5e-3;
SyncSample ++;
@ -267,7 +268,7 @@ gboolean GetVideo(guchar Mode, double Rate, int Skip, gboolean Redraw) {
InterpFreq = Freq;
} else {
// Clip if out of bounds
Freq = (MaxBin > GetBin(1900 + HedrShift, FFTLen)) ? 2300+HedrShift : 1500+HedrShift;
Freq = ( (MaxBin > GetBin(1900 + HedrShift, FFTLen)) ? 2300 : 1500 ) + HedrShift;
}
NextFFTtime += 0.3e-3;
@ -359,10 +360,7 @@ gboolean GetVideo(guchar Mode, double Rate, int Skip, gboolean Redraw) {
}
}
if (y > ModeSpec[Mode].ImgHeight-1) {
printf("y > ImgHeight-1\n");
break;
}
if (y > ModeSpec[Mode].ImgHeight-1) break;
// Calculate and draw pixels on line change
if (LineNum != prevline || (LineNum == ModeSpec[Mode].ImgHeight-1 && x == ModeSpec[Mode].ImgWidth-1)) {
@ -424,7 +422,7 @@ gboolean GetVideo(guchar Mode, double Rate, int Skip, gboolean Redraw) {
}
if (Abort) return FALSE;
else return TRUE;
if (Abort) return false;
else return true;
}

19
vis.c
Wyświetl plik

@ -1,4 +1,5 @@
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#include <fftw3.h>
#include <gtk/gtk.h>
@ -23,7 +24,7 @@ guchar GetVIS () {
guint FFTLen = 2048, i=0, j=0, k=0, MaxBin = 0;
double Power[2048] = {0}, HedrBuf[100] = {0}, tone[100] = {0}, Hann[882] = {0};
char infostr[60] = {0};
gboolean gotvis = FALSE;
bool gotvis = false;
guchar Bit[8] = {0}, ParityBit = 0;
for (i = 0; i < FFTLen; i++) in[i] = 0;
@ -31,7 +32,7 @@ guchar GetVIS () {
// Create 20ms Hann window
for (i = 0; i < 882; i++) Hann[i] = 0.5 * (1 - cos( (2 * M_PI * (double)i) / 881 ) );
ManualActivated = FALSE;
ManualActivated = false;
printf("Waiting for header\n");
@ -39,7 +40,7 @@ guchar GetVIS () {
gtk_statusbar_push( GTK_STATUSBAR(statusbar), 0, "Ready" );
gdk_threads_leave();
while ( TRUE ) {
while ( true ) {
// Read 10 ms from sound card
readPcm(441);
@ -75,7 +76,7 @@ guchar GetVIS () {
// Is there a pattern that looks like (the end of) a calibration header + VIS?
// Tolerance ±25 Hz
HedrShift = 0;
gotvis = FALSE;
gotvis = false;
for (i = 0; i < 3; i++) {
if (HedrShift != 0) break;
for (j = 0; j < 3; j++) {
@ -92,12 +93,12 @@ guchar GetVIS () {
// Attempt to read VIS
gotvis = TRUE;
gotvis = true;
for (k = 0; k < 8; k++) {
if (tone[6*3+i+3*k] > tone[0+j] - 625 && tone[6*3+i+3*k] < tone[0+j] - 575) Bit[k] = 0;
else if (tone[6*3+i+3*k] > tone[0+j] - 825 && tone[6*3+i+3*k] < tone[0+j] - 775) Bit[k] = 1;
else { // erroneous bit
gotvis = FALSE;
gotvis = false;
break;
}
}
@ -116,11 +117,11 @@ guchar GetVIS () {
if (Parity != ParityBit) {
printf(" Parity fail\n");
gotvis = FALSE;
gotvis = false;
} else if (VISmap[VIS] == UNKNOWN) {
printf(" Unknown VIS\n");
snprintf(infostr, sizeof(infostr)-1, "How to decode image with VIS %d (%02Xh)?", VIS, VIS);
gotvis = FALSE;
gotvis = false;
gdk_threads_enter();
gtk_label_set_markup(GTK_LABEL(infolabel), infostr);
gdk_threads_leave();
@ -139,7 +140,7 @@ guchar GetVIS () {
if (ManualActivated) {
gdk_threads_enter();
gtk_widget_set_sensitive( manualframe, FALSE );
gtk_widget_set_sensitive( manualframe, false );
gdk_threads_leave();
selmode = gtk_combo_box_get_active (GTK_COMBO_BOX(modecombo)) + 1;