]> git.rkrishnan.org Git - pihpsdr.git/commitdiff
changes to CW and Tune functions. Codec2 support started.
authorJohn Melton g0orx/n6lyt <john.d.melton@googlemail.com>
Wed, 11 May 2016 11:20:17 +0000 (11:20 +0000)
committerJohn Melton g0orx/n6lyt <john.d.melton@googlemail.com>
Wed, 11 May 2016 11:20:17 +0000 (11:20 +0000)
20 files changed:
Makefile
band.h
discovered.h
filter.c
filter.h
gpio.c
mode.c
mode.h
new_protocol.c
old_protocol.c
pihpsdr
radio.c
release/pihpsdr.tar
release/pihpsdr/install.sh [new file with mode: 0755]
release/pihpsdr/libSoapySDR.so [deleted file]
release/pihpsdr/libSoapySDR.so.0.5-1 [new file with mode: 0755]
release/pihpsdr/libcodec2.so.0.5 [new file with mode: 0755]
release/pihpsdr/pihpsdr
toolbar.c
wdsp_init.c

index 952b62142ca45a9511a62ed29ba2b50e2ed74591..709985fe3dc12075381bbac2d9ebdc5b6d1df7bc 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -12,7 +12,18 @@ LINK=gcc
 #LIMESDR_OBJS= \
 #lime_discovery.o
 
-OPTIONS=-g -D $(UNAME_N) $(LIMESDR_OPTIONS) -O3
+
+#required for FREEDV (uncomment lines below)
+#FREEDV_OPTIONS=-D FREEDV
+#FREEDVLIBS=-lcodec2
+#FREEDV_SOURCES= \
+#freedv.c
+#FREEDV_HEADERS= \
+#freedv.h
+#FREEDV_OBJS= \
+#freedv.o
+
+OPTIONS=-g -D $(UNAME_N) $(LIMESDR_OPTIONS) $(FREEDV_OPTIONS) -O3
 GTKINCLUDES=`pkg-config --cflags gtk+-3.0`
 GTKLIBS=`pkg-config --libs gtk+-3.0`
 
@@ -23,7 +34,7 @@ endif
 ifeq ($(UNAME_N),odroid)
 GPIOLIBS=-lwiringPi
 endif
-LIBS=-lrt -lm -lwdsp -lpthread $(GTKLIBS) $(GPIOLIBS) $(SOAPYSDRLIBS)
+LIBS=-lcodec2 -lrt -lm -lwdsp -lpthread $(GTKLIBS) $(GPIOLIBS) $(SOAPYSDRLIBS) $(FREEDVLIBS)
 INCLUDES=$(GTKINCLUDES)
 
 COMPILE=$(CC) $(OPTIONS) $(INCLUDES)
@@ -113,13 +124,13 @@ vfo.o \
 waterfall.o \
 wdsp_init.o
 
-all: prebuild $(PROGRAM) $(HEADERS) $(LIMESDR_HEADERS) $(SOURCES) $(LIMESDR_SOURCES)
+all: prebuild $(PROGRAM) $(HEADERS) $(LIMESDR_HEADERS) $(SOURCES) $(LIMESDR_SOURCES) $(FREEDV_SOURCES)
 
 prebuild:
        rm -f version.o
 
-$(PROGRAM): $(OBJS) $(LIMESDR_OBJS)
-       $(LINK) -o $(PROGRAM) $(OBJS) $(LIMESDR_OBJS) $(LIBS)
+$(PROGRAM): $(OBJS) $(LIMESDR_OBJS) $(FREEDV_OBJS)
+       $(LINK) -o $(PROGRAM) $(OBJS) $(LIMESDR_OBJS) $(FREEDV_OBJS) $(LIBS)
 
 .c.o:
        $(COMPILE) -c -o $@ $<
@@ -132,4 +143,5 @@ clean:
 install:
        cp pihpsdr ../pihpsdr
        cp pihpsdr ./release/pihpsdr
+       cd release; tar cvf pihpsdr.tar pihpsdr
 
diff --git a/band.h b/band.h
index 61e61ae950a808d916612324a105f15779e6acf0..5916e5da4f1686842d3c7589c7f2fc54a814ca5a 100644 (file)
--- a/band.h
+++ b/band.h
@@ -33,7 +33,6 @@
 #define band6 10
 #ifdef LIMESDR
 #define band70 11
-#define band144 12
 #define band220 13
 #define band430 14
 #define band902 15
index 110561e456f8e388b7ef4308006f37bc87ea09f3..d57010aa50ecbc931050f10b43bf55357e57d9a7 100644 (file)
 #define NEW_DEVICE_ORION2 5
 #define NEW_DEVICE_HERMES_LITE 6
 
+#define LIMESDR_DEVICE 0
+
 #define STATE_AVAILABLE 2
 #define STATE_SENDING 3
 
 #define ORIGINAL_PROTOCOL 0
 #define NEW_PROTOCOL 1
-#define LIME_SDR 2
+#define LIMESDR_PROTOCOL 2
 
 struct _DISCOVERED {
     int protocol;
index c6a4ff8f7e96e24695d577539a9f121aa3678cad..84f12e375100e9a93e39ba49e45a8d0459174022 100644 (file)
--- a/filter.c
+++ b/filter.c
@@ -199,5 +199,21 @@ FILTER filterDRM[FILTERS]={
     {-3300,3300,"Var2"}*/
     };
 
-FILTER *filters[]={filterLSB,filterUSB,filterDSB,filterCWL,filterCWU,filterFMN,filterAM,filterDIGU,filterSPEC,filterDIGL,filterSAM,filterDRM};
+FILTER filterFREEDV[FILTERS]={
+    {150,5150,"5.0k"},
+    {150,4550,"4.4k"},
+    {150,3950,"3.8k"},
+    {150,3450,"3.3k"},
+    {150,3050,"2.9k"},
+    {150,2850,"2.7k"},
+    {150,2550,"2.4k"},
+    {150,2250,"2.1k"},
+    {150,1950,"1.8k"},
+    {150,1150,"1.0k"}/*,
+    {150,2850,"Var1"},
+    {150,2850,"Var2"}*/
+    };
+
+
+FILTER *filters[]={filterLSB,filterUSB,filterDSB,filterCWL,filterCWU,filterFMN,filterAM,filterDIGU,filterSPEC,filterDIGL,filterSAM,filterDRM,filterFREEDV};
 
index c6e05036f9e505ea5d30fae89acb0c2bee7b6079..e0cbe07e5f5dde4ee56d68f074b7b252818222e8 100644 (file)
--- a/filter.h
+++ b/filter.h
@@ -61,12 +61,3 @@ int filterVar2High;
 
 FILTER *filters[MODES];
 
-/*
-int updateFilter(void * data);
-GtkWidget* buildFilterUI();
-void filterSaveState();
-void filterRestoreState();
-void setFilterValues(int mode);
-void setFilter(int filter);
-void setTxFilters();
-*/
diff --git a/gpio.c b/gpio.c
index efadf09b7a646ab8490f598db3d75008436c8c0a..b30a50ebfb6e546219af42029d0fe08140e8713f 100644 (file)
--- a/gpio.c
+++ b/gpio.c
@@ -23,6 +23,7 @@
 
 #include "band.h"
 #include "channel.h"
+#include "discovered.h"
 #include "mode.h"
 #include "filter.h"
 #include "bandstack.h"
@@ -855,11 +856,25 @@ fprintf(stderr,"band_pressed\n");
     if(b<0) {
       b=BANDS-1;
     }
+#ifdef LIMESDR
+    if(protocol!=LIMESDR_PROTOCOL) {
+      if(b==band3400) {
+        b=band6;
+      }
+    }
+#endif
   } else {
     b++;
     if(b>=BANDS) {
       b=0;
     }
+#ifdef LIMESDR
+    if(protocol!=LIMESDR_PROTOCOL) {
+      if(b==band70) {
+        b=bandGen;
+      }
+    }
+#endif
   }
   band=band_set_current(b);
   entry=bandstack_entry_get_current();
diff --git a/mode.c b/mode.c
index 9b6048f66962df46412f857805e8c530227b0f04..8bf7706cde46620a8e4d5c25fa90ce69cef40e73 100644 (file)
--- a/mode.c
+++ b/mode.c
@@ -17,5 +17,5 @@
 *
 */
 
-char *mode_string[]={"LSB","USB","DSB","CWL","CWU","FMN","AM","DIGU","SPEC","DIGL","SAM","DRM"};
+char *mode_string[]={"LSB","USB","DSB","CWL","CWU","FMN","AM","DIGU","SPEC","DIGL","SAM","DRM","FREEDV"};
 
diff --git a/mode.h b/mode.h
index 154bab644a0e0ed09389dcd1cadf4502e5fe50a6..6176396ca86eb14c244801aa1c033efa1d618f3d 100644 (file)
--- a/mode.h
+++ b/mode.h
 #define modeDIGL 9
 #define modeSAM 10
 #define modeDRM 11
+#define modeFREEDV 12
 
-#define MODES 12
+#define MODES 13
 
 int mode;
 
 char *mode_string[MODES];
 
-/*
-int updateMode(void * data);
-
-void setMode(int mode);
-void modeSaveState();
-void modeRestoreState();
-GtkWidget* buildModeUI();
-char* modeToString();
-*/
index 736fc90574626ba1be84da80c4ead86ed15f620d..a308cf738e4e103036e633a299c5b141734f5828 100644 (file)
@@ -523,17 +523,6 @@ void new_protocol_stop() {
     sleep(1);
 }
 
-/*
-float sineWave(float* buf, int samples, float phase, float freq) {
-    float phase_step = 2 * PI * freq / 192000.0F;
-    int i;
-    for (i = 0; i < samples; i++) {
-        buf[i] = (float) sin(phase);
-        phase += phase_step;
-    }
-    return phase;
-}
-*/
 float sineWave(double* buf, int samples, float phase, float freq) {
     float phase_step = 2 * PI * freq / 192000.0F;
     int i;
index 88bee2583df88ce32ab9f28f977d34339cf3b12a..9e02f864b8cc296fb0a951f40cf5d27f7120a7c4 100644 (file)
@@ -43,6 +43,7 @@
 #include "old_protocol.h"
 #include "radio.h"
 #include "toolbar.h"
+#include "freedv.h"
 
 #define SYNC0 0
 #define SYNC1 1
@@ -176,7 +177,7 @@ void schedule_frequency_changed() {
 }
 
 static float sineWave(double* buf, int samples, float phase, float freq) {
-    float phase_step = 2 * PI * freq / 192000.0F;
+    float phase_step = 2 * PI * freq / 48000.0F;
     int i;
     for (i = 0; i < samples; i++) {
         buf[i*2] = (double) sin(phase);
@@ -439,10 +440,25 @@ static void process_ozy_input_buffer(char  *buffer) {
 
       // add to buffer
       if(isTransmitting()) {
-        micinputbuffer[samples*2]=(double)mic_sample_float*mic_gain;
-        micinputbuffer[(samples*2)+1]=(double)mic_sample_float*mic_gain;
-        samples++;
+#ifdef FREEDV
+        if(mode==modeFREEDV) {
+          int modem_samples=mod_sample_freedv(mic_sample);
+          if(modem_samples!=0) {
+            
+          }
+        } else {
+#endif
+          micinputbuffer[samples*2]=(double)mic_sample_float*mic_gain;
+          micinputbuffer[(samples*2)+1]=(double)mic_sample_float*mic_gain;
+          iqinputbuffer[samples*2]=0.0;
+          iqinputbuffer[(samples*2)+1]=0.0;
+          samples++;
+#ifdef FREEDV
+        }
+#endif
       } else {
+        micinputbuffer[samples*2]=0.0;
+        micinputbuffer[(samples*2)+1]=0.0;
         iqinputbuffer[samples*2]=(double)left_sample_float;
         iqinputbuffer[(samples*2)+1]=(double)right_sample_float;
         samples++;
@@ -496,24 +512,62 @@ static void process_ozy_input_buffer(char  *buffer) {
             fprintf(stderr,"fexchange2 (CHANNEL_RX0) returned error: %d\n", error);
           }
           Spectrum0(1, CHANNEL_RX0, 0, 0, iqinputbuffer);
-          for(j=0;j<output_buffer_size;j++) {
-            left_rx_sample=(short)(audiooutputbuffer[j*2]*32767.0*volume);
-            right_rx_sample=(short)(audiooutputbuffer[(j*2)+1]*32767.0*volume);
-            left_tx_sample=0;
-            right_tx_sample=0;
-            output_buffer[output_buffer_index++]=left_rx_sample>>8;
-            output_buffer[output_buffer_index++]=left_rx_sample;
-            output_buffer[output_buffer_index++]=right_rx_sample>>8;
-            output_buffer[output_buffer_index++]=right_rx_sample;
-            output_buffer[output_buffer_index++]=left_tx_sample>>8;
-            output_buffer[output_buffer_index++]=left_tx_sample;
-            output_buffer[output_buffer_index++]=right_tx_sample>>8;
-            output_buffer[output_buffer_index++]=right_tx_sample;
-            if(output_buffer_index>=OZY_BUFFER_SIZE) {
-              ozy_send_buffer();
-              output_buffer_index=8;
+
+#ifdef FREEDV
+          if(mode==modeFREEDV) {
+            int demod_samples;
+            int increment=6; // 48000 to 8000
+            for(j=0;j<output_buffer_size;j+=increment) {
+              left_rx_sample=(short)(audiooutputbuffer[j*2]*32767.0*volume);
+              demod_samples=demod_sample_freedv(left_rx_sample);
+              if(demod_samples!=0) {
+                int s;
+                int t;
+                for(s=0;s<demod_samples;s++) {
+                  for(t=0;t<6;t++) { // 8k to 48k
+                    left_rx_sample=speech_out[s];
+                    right_rx_sample=speech_out[s];
+                    left_tx_sample=0;
+                    right_tx_sample=0;
+                   output_buffer[output_buffer_index++]=left_rx_sample>>8;
+                   output_buffer[output_buffer_index++]=left_rx_sample;
+                   output_buffer[output_buffer_index++]=right_rx_sample>>8;
+                   output_buffer[output_buffer_index++]=right_rx_sample;
+                   output_buffer[output_buffer_index++]=left_tx_sample>>8;
+                   output_buffer[output_buffer_index++]=left_tx_sample;
+                   output_buffer[output_buffer_index++]=right_tx_sample>>8;
+                   output_buffer[output_buffer_index++]=right_tx_sample;
+                   if(output_buffer_index>=OZY_BUFFER_SIZE) {
+                     ozy_send_buffer();
+                     output_buffer_index=8;
+                   }
+                  }
+                }
+              }
+            }
+          } else {
+#endif
+            for(j=0;j<output_buffer_size;j++) {
+              left_rx_sample=(short)(audiooutputbuffer[j*2]*32767.0*volume);
+              right_rx_sample=(short)(audiooutputbuffer[(j*2)+1]*32767.0*volume);
+              left_tx_sample=0;
+              right_tx_sample=0;
+              output_buffer[output_buffer_index++]=left_rx_sample>>8;
+              output_buffer[output_buffer_index++]=left_rx_sample;
+              output_buffer[output_buffer_index++]=right_rx_sample>>8;
+              output_buffer[output_buffer_index++]=right_rx_sample;
+              output_buffer[output_buffer_index++]=left_tx_sample>>8;
+              output_buffer[output_buffer_index++]=left_tx_sample;
+              output_buffer[output_buffer_index++]=right_tx_sample>>8;
+              output_buffer[output_buffer_index++]=right_tx_sample;
+              if(output_buffer_index>=OZY_BUFFER_SIZE) {
+                ozy_send_buffer();
+                output_buffer_index=8;
+              }
             }
+#ifdef FREEDV
           }
+#endif
         }
         samples=0;
       }
@@ -758,7 +812,7 @@ void ozy_send_buffer() {
       if(mode!=modeCWU && mode!=modeCWL) {
         // output_buffer[C1]|=0x00;
       } else {
-        if((tune==1) || (cw_keyer_internal==0)) {
+        if((tune==1) || (mox==1) || (cw_keyer_internal==0)) {
           // output_buffer[C1]|=0x00;
         } else {
           output_buffer[C1]|=0x01;
@@ -783,9 +837,7 @@ void ozy_send_buffer() {
       output_buffer[C0]|=0x01;
     }
   } else {
-    if(tune==1) {
-      output_buffer[C0]|=0x01;
-    } else {
+    if(tune==0) {
       if(cw_keyer_internal==0) {
         output_buffer[C0]|=0x01;
       }
diff --git a/pihpsdr b/pihpsdr
index e3eb205d7f45c1e489bec15b50a7a3aa84b1cb0c..e230a638271f1446bd35b731b5a775fe4072a5dd 100755 (executable)
Binary files a/pihpsdr and b/pihpsdr differ
diff --git a/radio.c b/radio.c
index 8be22cfe8d85776b2307e72c8caa448a56cd2345..657811f0d2d4248fdc0d4d4b1ecf402d2fed2c44 100644 (file)
--- a/radio.c
+++ b/radio.c
@@ -237,13 +237,6 @@ int getTune() {
 }
 
 int isTransmitting() {
-/*
-  BANDSTACK_ENTRY *entry;
-  entry=bandstack_entry_get_current();
-  if((entry->mode==modeCWL || entry->mode==modeCWU) && cw_keyer_internal==1 && ptt==1) {
-    return 0;
-  }
-*/
   return ptt!=0 || mox!=0 || tune!=0;
 }
 
@@ -266,7 +259,6 @@ double getDrive() {
 }
 
 void setDrive(double value) {
-//fprintf(stderr,"setDrive: protocol=%d\n", protocol);
     drive=(int)(value*255.0);
     if(protocol==NEW_PROTOCOL) {
       schedule_high_priority(6);
index a2ad1a0fd330ac51676bdf7c81bed46a29dfbdec..4f18e648ffb9f1995f677a975c6c98562945d146 100644 (file)
Binary files a/release/pihpsdr.tar and b/release/pihpsdr.tar differ
diff --git a/release/pihpsdr/install.sh b/release/pihpsdr/install.sh
new file mode 100755 (executable)
index 0000000..f838b18
--- /dev/null
@@ -0,0 +1,7 @@
+cp libwdsp.so /usr/local/lib
+cp libcodec2.so.0.5 /usr/local/lib
+cp libSoapySDR.so.0.5-1 /usr/local/lib
+cd /usr/local/lib; ln -s libcodec2.so.0.5 libcodec2.so
+cd /usr/local/lib; ln -s libSoapySDR.so.0.5-1 libSoapySDR.so.0.5.0
+cd /usr/local/lib; ln -s libSoapySDR.so.0.5-1 libSoapySDR.so
+ldconfig
diff --git a/release/pihpsdr/libSoapySDR.so b/release/pihpsdr/libSoapySDR.so
deleted file mode 100755 (executable)
index 3c0232f..0000000
Binary files a/release/pihpsdr/libSoapySDR.so and /dev/null differ
diff --git a/release/pihpsdr/libSoapySDR.so.0.5-1 b/release/pihpsdr/libSoapySDR.so.0.5-1
new file mode 100755 (executable)
index 0000000..3c0232f
Binary files /dev/null and b/release/pihpsdr/libSoapySDR.so.0.5-1 differ
diff --git a/release/pihpsdr/libcodec2.so.0.5 b/release/pihpsdr/libcodec2.so.0.5
new file mode 100755 (executable)
index 0000000..364d31c
Binary files /dev/null and b/release/pihpsdr/libcodec2.so.0.5 differ
index e3eb205d7f45c1e489bec15b50a7a3aa84b1cb0c..e230a638271f1446bd35b731b5a775fe4072a5dd 100755 (executable)
Binary files a/release/pihpsdr/pihpsdr and b/release/pihpsdr/pihpsdr differ
index ac179e0385bcb1cb620adf07d685cc560ef14115..3c413c9702e7fa43fa85a04c762d8ba86f2ee641 100644 (file)
--- a/toolbar.c
+++ b/toolbar.c
@@ -101,6 +101,13 @@ static void band_cb(GtkWidget *widget, gpointer data) {
   GtkWidget *b;
   int i;
   for(i=0;i<BANDS;i++) {
+#ifdef LIMESDR
+    if(protocol!=LIMESDR_PROTOCOL) {
+      if(i>=band70 && i<=band3400) {
+        continue;
+      }
+    }
+#endif
     BAND* band=band_get_band(i);
     GtkWidget *b=gtk_button_new_with_label(band->title);
     gtk_widget_override_background_color(b, GTK_STATE_NORMAL, &white);
@@ -789,11 +796,25 @@ fprintf(stderr,"sim_band_cb\n");
     if(b<0) {
       b=BANDS-1;
     }
+#ifdef LIMESDR
+    if(protocol!=LIMESDR_PROTOCOL) {
+      if(b==band3400) {
+        b=band6;
+      }
+    }
+#endif
   } else {
     b++;
     if(b>=BANDS) {
       b=0;
     }
+#ifdef LIMESDR
+    if(protocol!=LIMESDR_PROTOCOL) {
+      if(b==band70) { 
+        b=bandGen;
+      }
+    }
+#endif
   }
   band=band_set_current(b);
   entry=bandstack_entry_get_current();
index 1add75c18d5149b8cd0db61a2d48ac6e1ce6bbb2..ff25aa673731d8ae85c38fbb190cf3d99dc9bdcd 100644 (file)
@@ -47,6 +47,7 @@
 #include "vfo.h"
 #include "toolbar.h"
 #include "wdsp_init.h"
+#include "freedv.h"
 
 #define PI 3.1415926535897932F
 #define min(x,y) (x<y?x:y)
@@ -70,10 +71,25 @@ static int SPECTRUM_UPDATES_PER_SECOND=10;
 
 static void initAnalyzer(int channel,int buffer_size);
 
+void setRXMode(int m) {
+    SetRXAMode(receiver, mode==modeFREEDV?modeUSB:mode);
+}
+
+void setTXMode(int m) {
+    SetTXAMode(CHANNEL_TX, mode==modeFREEDV?modeUSB:mode);
+}
+
 void setMode(int m) {
+#ifdef FREEDV
+    if(mode!=modeFREEDV && m==modeFREEDV) {
+      init_freedv();
+    } if(mode==modeFREEDV && m!=modeFREEDV) {
+      close_freedv();
+    }
+#endif
     mode=m;
-    SetRXAMode(receiver, mode);
-    SetTXAMode(CHANNEL_TX, mode);
+    setRXMode(m);
+    setTXMode(m);
 }
 
 int getMode() {
@@ -203,7 +219,7 @@ void wdsp_init(int rx,int pixels,int protocol) {
         }
     initAnalyzer(CHANNEL_TX,tx_buffer_size);
 
-    SetRXAMode(rx, mode);
+    setRXMode(mode);
     SetRXABandpassFreqs(rx, (double)filterLow, (double)filterHigh);
     SetRXAAGCMode(rx, agc);
     SetRXAAGCTop(rx,agc_gain);
@@ -222,7 +238,7 @@ void wdsp_init(int rx,int pixels,int protocol) {
     SetRXAANFRun(CHANNEL_RX0, anf);
     SetRXASNBARun(CHANNEL_RX0, snb);
 
-    SetTXAMode(CHANNEL_TX, mode);
+    setTXMode(mode);
     SetTXABandpassFreqs(CHANNEL_TX, (double)filterLow, (double)filterHigh);
     SetTXABandpassWindow(CHANNEL_TX, 1);
     SetTXABandpassRun(CHANNEL_TX, 1);
@@ -236,7 +252,7 @@ void wdsp_init(int rx,int pixels,int protocol) {
     SetTXAPreGenRun(CHANNEL_TX, 0);
     SetTXAPostGenRun(CHANNEL_TX, 0);
 
-    SetChannelState(CHANNEL_TX,0,0);
+    SetChannelState(CHANNEL_TX,1,0);
     SetChannelState(CHANNEL_RX0,1,0);
 
 }