]> git.rkrishnan.org Git - pihpsdr.git/commitdiff
second stage of manual merge
authorc vw <dl1ycf@darc.de>
Mon, 17 May 2021 07:57:27 +0000 (09:57 +0200)
committerc vw <dl1ycf@darc.de>
Mon, 17 May 2021 07:57:27 +0000 (09:57 +0200)
Makefile
hpsdrsim.c
iambic.c
newhpsdrsim.c
radio.c
toolbar.c

index a596532a543ec22cdba4a85f8d0ada80f08a6164..c87dbd5d3516491c43ff0a23494176aec5266afc 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -131,19 +131,22 @@ GPIO_SOURCES= \
   i2c.c \
   gpio.c \
   encoder_menu.c \
-  switch_menu.c
+  switch_menu.c \
+  actions.c
 GPIO_HEADERS= \
   configure.h \
   i2c.h \
   gpio.h \
   encoder_menu.h \
-  switch_menu.h
+  switch_menu.h \
+  actions.h
 GPIO_OBJS= \
   configure.o \
   i2c.o \
   gpio.o \
   encoder_menu.o \
-  switch_menu.o
+  switch_menu.o \
+  actions.o
 endif
 
 ifeq ($(LOCALCW_INCLUDE),LOCALCW)
@@ -294,12 +297,7 @@ ext.c \
 error_handler.c \
 cwramp.c \
 protocols.c \
-css.c \
-actions.c \
-i2c.c \
-gpio.c \
-encoder_menu.c \
-switch_menu.c
+css.c
 
 
 HEADERS= \
@@ -369,13 +367,7 @@ led.h \
 ext.h \
 error_handler.h \
 protocols.h \
-css.h \
-actions.h \
-configure.h \
-i2c.h \
-gpio.h \
-encoder_menu.h \
-switch_menu.h
+css.h
 
 
 OBJS= \
@@ -444,13 +436,7 @@ ext.o \
 error_handler.o \
 cwramp.o \
 protocols.o \
-css.o \
-actions.o \
-configure.o \
-i2c.o \
-gpio.o \
-encoder_menu.o \
-switch_menu.o
+css.o
 
 $(PROGRAM):  $(OBJS) $(AUDIO_OBJS) $(REMOTE_OBJS) $(USBOZY_OBJS) $(SOAPYSDR_OBJS) \
                $(LOCALCW_OBJS) $(PURESIGNAL_OBJS) \
@@ -533,13 +519,13 @@ controller2v2: clean $(PROGRAM)
 #############################################################################
 
 hpsdrsim.o:     hpsdrsim.c  hpsdrsim.h
-       $(CC) -c -O $(AUDIO_OPTIONS) hpsdrsim.c
+       $(CC) -c -O hpsdrsim.c
        
 newhpsdrsim.o: newhpsdrsim.c hpsdrsim.h
        $(CC) -c -O newhpsdrsim.c
 
 hpsdrsim:       hpsdrsim.o newhpsdrsim.o
-       $(CC) -o hpsdrsim $(AUDIO_LIBS) hpsdrsim.o newhpsdrsim.o -lportaudio -lm -lpthread
+       $(CC) -o hpsdrsim hpsdrsim.o newhpsdrsim.o -lm -lpthread
 
 debian:
        cp $(PROGRAM) pkg/pihpsdr/usr/local/bin
@@ -566,13 +552,11 @@ debian:
 #############################################################################
 
 .PHONY: app
-app:   $(OBJS) $(REMOTE_OBJS) \
-               $(USBOZY_OBJS)  $(SOAPYSDR_OBJS) \
+app:   $(OBJS) $(AUDIO_OBJS) $(REMOTE_OBJS) $(USBOZY_OBJS)  $(SOAPYSDR_OBJS) \
                $(LOCALCW_OBJS) $(PURESIGNAL_OBJS) \
                $(MIDI_OBJS) $(STEMLAB_OBJS) $(SERVER_OBJS)
-       $(CC)   -headerpad_max_install_names -o $(PROGRAM) $(OBJS) $(REMOTE_OBJS) \
-               $(USBOZY_OBJS)  $(SOAPYSDR_OBJS) \
-               $(LOCALCW_OBJS) $(PURESIGNAL_OBJS) \
+       $(CC)   -headerpad_max_install_names -o $(PROGRAM) $(OBJS) $(AUDIO_OBJS) $(REMOTE_OBJS)  $(USBOZY_OBJS)  \
+               $(SOAPYSDR_OBJS) $(LOCALCW_OBJS) $(PURESIGNAL_OBJS) \
                $(MIDI_OBJS) $(STEMLAB_OBJS) $(SERVER_OBJS) $(LIBS) $(LDFLAGS)
        @rm -rf pihpsdr.app
        @mkdir -p pihpsdr.app/Contents/MacOS
index d5735a78dc85038cf28506657d6e4f4eef26e9b6..083bc22b4f89f66f98b73172a8d5027dc35a3cb0 100644 (file)
 #include "MacOS.h"  // emulate clock_gettime on old MacOS systems
 #endif
 
-#define NEED_DUMMY_AUDIO 1
-
-#ifdef PORTAUDIO
-#include "portaudio.h"
-#undef NEED_DUMMY_AUDIO
-#endif
-#ifdef ALSASOUND
-#include <alsa/asoundlib.h>
-#undef NEED_DUMMY_AUDIO
-#endif
-
 #define EXTERN 
 #include "hpsdrsim.h"
 
@@ -185,7 +174,6 @@ static void *handler_ep6(void *arg);
 static double  last_i_sample=0.0;
 static double  last_q_sample=0.0;
 static int  txptr=0;
-static int  do_audio=0;  // 0: no audio, 1: audio
 static int  oldnew=3;    // 1: only P1, 2: only P2, 3: P1 and P2, 
 
 static double txlevel;
@@ -252,7 +240,6 @@ int main(int argc, char *argv[])
             if (!strncmp(argv[i],"-hermeslite2", 12))  {OLDDEVICE=DEVICE_HERMES_LITE2;NEWDEVICE=NEW_DEVICE_HERMES_LITE2;}
             if (!strncmp(argv[i],"-c25"    ,      4))  {OLDDEVICE=DEVICE_C25;         NEWDEVICE=NEW_DEVICE_HERMES;}
             if (!strncmp(argv[i],"-diversity",   10))  {diversity=1;}
-            if (!strncmp(argv[i],"-audio",        6))  {do_audio=1;}
             if (!strncmp(argv[i],"-P1",           3))  {oldnew=1;}
             if (!strncmp(argv[i],"-P2",           3))  {oldnew=2;}
             if (!strncmp(argv[i],"-nb",           3))  {
@@ -359,11 +346,6 @@ int main(int argc, char *argv[])
        memset (isample, 0, OLDRTXLEN*sizeof(double));
        memset (qsample, 0, OLDRTXLEN*sizeof(double));
 
-       if (do_audio) {
-         audio_get_cards();
-          audio_open_output();
-       }
-
        if ((sock_udp = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
        {
                perror("socket");
@@ -550,16 +532,7 @@ int main(int argc, char *argv[])
                                   bp=buffer+16;  // skip 8 header and 8 SYNC/C&C bytes
                                  sum=0.0;
                                   for (j=0; j<126; j++) {
-                                       if (do_audio) {
-                                         // write audio samples
-                                         r  = (int)((signed char) *bp++)<<8;
-                                         r |= (int)((signed char) *bp++ & 0xFF);
-                                         l  = (int)((signed char) *bp++)<<8;
-                                         l |= (int)((signed char) *bp++ & 0xFF);
-                                          audio_write(r,l);
-                                       } else {
-                                         bp +=4;
-                                       }
+                                       bp +=4;  // skip audio samples
                                        sample  = (int)((signed char) *bp++)<<8;
                                        sample |= (int) ((signed char) *bp++ & 0xFF);
                                        disample=(double) sample * 0.000030517578125;  // division by 32768
@@ -1480,321 +1453,3 @@ void *handler_ep6(void *arg)
        active_thread = 0;
        return NULL;
 }
-
-#ifdef PORTAUDIO
-// PORTAUDIO output function
-
-static int padev = -1;
-static float playback_buffer[256];
-static PaStream  *playback_handle=NULL;
-int playback_offset;
-
-
-void audio_get_cards()
-{
-  int i, numDevices;
-  const PaDeviceInfo *deviceInfo;
-  PaStreamParameters inputParameters, outputParameters;
-
-  PaError err;
-
-  err = Pa_Initialize();
-  if( err != paNoError )
-  {
-        fprintf(stderr, "PORTAUDIO ERROR: Pa_Initialize: %s\n", Pa_GetErrorText(err));
-        return;
-  }
-  numDevices = Pa_GetDeviceCount();
-  if( numDevices < 0 ) return;
-
-  for( i=0; i<numDevices; i++ )
-  {
-        deviceInfo = Pa_GetDeviceInfo( i );
-
-        outputParameters.device = i;
-        outputParameters.channelCount = 1;
-        outputParameters.sampleFormat = paFloat32;
-        outputParameters.suggestedLatency = 0; /* ignored by Pa_IsFormatSupported() */
-        outputParameters.hostApiSpecificStreamInfo = NULL;
-        if (Pa_IsFormatSupported(NULL, &outputParameters, 48000.0) == paFormatIsSupported) {
-          padev=i;
-          fprintf(stderr,"PORTAUDIO OUTPUT DEVICE, No=%d, Name=%s\n", i, deviceInfo->name);
-         return;
-        }
-  }
-}
-
-void audio_open_output()
-{
-  PaError err;
-  PaStreamParameters outputParameters;
-  long framesPerBuffer=256;
-
-  bzero( &outputParameters, sizeof( outputParameters ) ); //not necessary if you are filling in all the fields
-  outputParameters.channelCount = 1;   // Always MONO
-  outputParameters.device = padev;
-  outputParameters.hostApiSpecificStreamInfo = NULL;
-  outputParameters.sampleFormat = paFloat32;
-  outputParameters.suggestedLatency = Pa_GetDeviceInfo(padev)->defaultLowOutputLatency ;
-  outputParameters.hostApiSpecificStreamInfo = NULL; //See you specific host's API docs for info on using this field
-
-  // Try using AudioWrite without a call-back function
-
-  playback_offset=0;
-  err = Pa_OpenStream(&(playback_handle), NULL, &outputParameters, 48000.0, framesPerBuffer, paNoFlag, NULL, NULL);
-  if (err != paNoError) {
-    fprintf(stderr,"PORTAUDIO ERROR: AOO open stream: %s\n",Pa_GetErrorText(err));
-    playback_handle = NULL;
-    return;
-  }
-
-  err = Pa_StartStream(playback_handle);
-  if (err != paNoError) {
-    fprintf(stderr,"PORTAUDIO ERROR: AOO start stream:%s\n",Pa_GetErrorText(err));
-    playback_handle=NULL;
-    return;
-  }
-  // Write one buffer to avoid under-flow errors
-  // (this gives us 5 msec to pass before we have to call audio_write the first time)
-  bzero(playback_buffer, (size_t) (256*sizeof(float)));
-  err=Pa_WriteStream(playback_handle, (void *) playback_buffer, (unsigned long) 256);
-
-  return;
-}
-
-void audio_write (int16_t l, int16_t r)
-{
-  PaError err;
-  if (playback_handle != NULL) {
-    playback_buffer[playback_offset++] = (r + l) *0.000015259;  //   65536 --> 1.0
-    if (playback_offset == 256) {
-      playback_offset=0;
-      err=Pa_WriteStream(playback_handle, (void *) playback_buffer, (unsigned long) 256);
-    }
-  }
-}
-#endif
-#ifdef ALSASOUND
-//
-// Audio functions based on LINUX ALSA
-//
-
-static snd_pcm_t *playback_handle = NULL;
-static unsigned char playback_buffer[1024]; // 256 samples, left-and-right, two bytes per sample
-static int playback_offset;
-
-static char *device_id = NULL;
-
-void audio_get_cards() {
-  snd_ctl_card_info_t *info;
-  snd_pcm_info_t *pcminfo;
-  snd_ctl_card_info_alloca(&info);
-  snd_pcm_info_alloca(&pcminfo);
-  int i;
-  int card = -1;
-
-
-  while (snd_card_next(&card) >= 0 && card >= 0) {
-    int err = 0;
-    snd_ctl_t *handle;
-    char name[20];
-    snprintf(name, sizeof(name), "hw:%d", card);
-    if ((err = snd_ctl_open(&handle, name, 0)) < 0) {
-      continue;
-    }
-
-    if ((err = snd_ctl_card_info(handle, info)) < 0) {
-      snd_ctl_close(handle);
-      continue;
-    }
-
-    int dev = -1;
-
-    while (snd_ctl_pcm_next_device(handle, &dev) >= 0 && dev >= 0 && device_id == NULL) {
-      snd_pcm_info_set_device(pcminfo, dev);
-      snd_pcm_info_set_subdevice(pcminfo, 0);
-
-      // ouput devices
-      snd_pcm_info_set_stream(pcminfo, SND_PCM_STREAM_PLAYBACK);
-      if ((err = snd_ctl_pcm_info(handle, pcminfo)) == 0) {
-        device_id=malloc(64);
-        snprintf(device_id, 64, "plughw:%d,%d %s", card, dev, snd_ctl_card_info_get_name(info));
-        fprintf(stderr,"ALSA output_device: %s\n",device_id);
-      }
-    }
-
-    snd_ctl_close(handle);
-   
-  }
-
-  if (device_id != NULL) return; // found one
-
-  // look for dmix
-  void **hints, **n;
-  char *name, *descr, *io;
-
-  if (snd_device_name_hint(-1, "pcm", &hints) < 0)
-    return;
-  n = hints;
-  while (*n != NULL && device_id == NULL) {
-    name = snd_device_name_get_hint(*n, "NAME");
-    descr = snd_device_name_get_hint(*n, "DESC");
-    io = snd_device_name_get_hint(*n, "IOID");
-    
-    if(strncmp("dmix:", name, 5)==0) {
-      fprintf(stderr,"name=%s descr=%s io=%s\n",name, descr, io);
-      device_id=malloc(64);
-      
-      snprintf(device_id, 64, "%s", name);
-      fprintf(stderr,"ALSA output_device: %s\n",device_id);
-    }
-
-    if (name != NULL)
-      free(name);
-    if (descr != NULL)
-      free(descr);
-    if (io != NULL)
-      free(io);
-    n++;
-  }
-  snd_device_name_free_hint(hints);
-}
-
-
-void audio_open_output() {
-  int err;
-  snd_pcm_hw_params_t *hw_params;
-  int rate=48000;
-  int dir=0;
-
-  int i;
-  char hw[64];
-  char *selected=device_id;
-  i=0;
-  while(selected[i]!=' ') {
-    hw[i]=selected[i];
-    i++;
-  }
-  hw[i]='\0';
-  
-  if ((err = snd_pcm_open (&playback_handle, hw, SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
-    fprintf (stderr, "audio_open_output: cannot open audio device %s (%s)\n", 
-            hw,
-            snd_strerror (err));
-    playback_handle = NULL;
-    return;
-  }
-
-  if ((err = snd_pcm_hw_params_malloc (&hw_params)) < 0) {
-    fprintf (stderr, "audio_open_output: cannot allocate hardware parameter structure (%s)\n",
-            snd_strerror (err));
-    playback_handle=NULL;
-    return;
-  }
-
-  if ((err = snd_pcm_hw_params_any (playback_handle, hw_params)) < 0) {
-    fprintf (stderr, "audio_open_output: cannot initialize hardware parameter structure (%s)\n",
-            snd_strerror (err));
-    playback_handle=NULL;
-    return;
-  }
-
-  if ((err = snd_pcm_hw_params_set_access (playback_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) {
-    fprintf (stderr, "audio_open_output: cannot set access type (%s)\n",
-            snd_strerror (err));
-    playback_handle=NULL;
-    return;
-  }
-       
-  if ((err = snd_pcm_hw_params_set_format (playback_handle, hw_params, SND_PCM_FORMAT_S16_LE)) < 0) {
-    fprintf (stderr, "audio_open_output: cannot set sample format (%s)\n",
-            snd_strerror (err));
-    playback_handle=NULL;
-    return;
-  }
-       
-
-  if ((err = snd_pcm_hw_params_set_rate_near (playback_handle, hw_params, &rate, &dir)) < 0) {
-    fprintf (stderr, "audio_open_output: cannot set sample rate (%s)\n",
-            snd_strerror (err));
-    playback_handle=NULL;
-    return;
-  }
-       
-  if ((err = snd_pcm_hw_params_set_channels (playback_handle, hw_params, 2)) < 0) {
-    fprintf (stderr, "audio_open_output: cannot set channel count (%s)\n",
-            snd_strerror (err));
-    playback_handle=NULL;
-    return;
-  }
-       
-  if ((err = snd_pcm_hw_params (playback_handle, hw_params)) < 0) {
-    fprintf (stderr, "audio_open_output: cannot set parameters (%s)\n",
-            snd_strerror (err));
-    playback_handle=NULL;
-    return;
-  }
-       
-  snd_pcm_hw_params_free (hw_params);
-
-  playback_offset=0;
-  
-  return;
-}
-
-void audio_write(int16_t left_sample,int16_t right_sample) {
-  snd_pcm_sframes_t delay;
-  int error;
-  long trim;
-
-  if(playback_handle!=NULL) {
-    playback_buffer[playback_offset++]=right_sample;
-    playback_buffer[playback_offset++]=right_sample>>8;
-    playback_buffer[playback_offset++]=left_sample;
-    playback_buffer[playback_offset++]=left_sample>>8;
-
-    if(playback_offset==1024) {
-      trim=0;
-
-      if(snd_pcm_delay(playback_handle,&delay)==0) {
-        if(delay>2048) {
-          trim=delay-2048;
-        }
-      }
-
-      if ((error = snd_pcm_writei (playback_handle, playback_buffer, 256-trim)) != 256-trim) {
-        if(error==-EPIPE) {
-          if ((error = snd_pcm_prepare (playback_handle)) < 0) {
-            fprintf (stderr, "audio_write: cannot prepare audio interface for use (%s)\n",
-                    snd_strerror (error));
-            return;
-          }
-          if ((error = snd_pcm_writei (playback_handle, playback_buffer, 256-trim)) != 256) {
-            fprintf (stderr, "audio_write: write to audio interface failed (%s)\n",
-                    snd_strerror (error));
-            return;
-          }
-        }
-      }
-      playback_offset=0;
-    }
-  }
-}
-#endif
-
-//
-// Dummy audio functions if this is compiled without audio support
-//
-#ifdef NEED_DUMMY_AUDIO
-void audio_get_cards()
-{
-}
-void audio_open_output()
-{
-}
-void audio_write (int16_t l, int16_t r)
-{
-}
-#endif
-
index c81e7cfc8c1174a85112532f4470cf536220d810..cba20c3c9fc786573656c5e991e4a16a803ce121 100644 (file)
--- a/iambic.c
+++ b/iambic.c
@@ -249,11 +249,15 @@ static void keyer_straight_key(int state) {
     cw_key_down=960000;  // max. 20 sec to protect hardware
     cw_key_up=0;
     cw_key_hit=1;
+#ifdef GPIO
     gpio_cw_sidetone_set(1);
+#endif
   } else {
     cw_key_down=0;
     cw_key_up=0;
+#ifdef GPIO
     gpio_cw_sidetone_set(0);
+#endif
   }
 }
 
@@ -361,10 +365,12 @@ static void* keyer_thread(void *arg) {
        // If using GPIO side tone information, mute CW side tone
        // as long as the keyer thread is active
        //
+#ifdef GPIO
        if (gpio_cw_sidetone_enabled()) {
          old_volume=cw_keyer_sidetone_volume;
          cw_keyer_sidetone_volume=0;
        }
+#endif
 
        //
        // Normally the keyer will be used in "break-in" mode, that is, we switch to TX
@@ -481,7 +487,9 @@ static void* keyer_thread(void *arg) {
                 dash_held = *kdash;
                 cw_key_down=dot_samples;
                 cw_key_up=dot_samples;
+#ifdef GPIO
                 gpio_cw_sidetone_set(1);
+#endif
                 key_state=SENDDOT;
                 break;
 
@@ -490,7 +498,9 @@ static void* keyer_thread(void *arg) {
                 // wait for dot being complete
                 //
                 if (cw_key_down == 0) {
+#ifdef GPIO
                   gpio_cw_sidetone_set(0);
+#endif
                   key_state=DOTDELAY;
                 }
                 break;
@@ -536,7 +546,9 @@ static void* keyer_thread(void *arg) {
                dot_held = *kdot;  // remember if dot is still held at beginning of the dash
                 cw_key_down=dash_samples;
                 cw_key_up=dot_samples;
+#ifdef GPIO
                 gpio_cw_sidetone_set(1);
+#endif
                 key_state=SENDDASH;
                 break;
 
@@ -545,7 +557,9 @@ static void* keyer_thread(void *arg) {
                 // wait for dot being complete
                 //
                 if (cw_key_down == 0) {
+#ifdef GPIO
                   gpio_cw_sidetone_set(0);
+#endif
                   key_state=DASHDELAY;
                 }
                 break;
@@ -605,9 +619,11 @@ static void* keyer_thread(void *arg) {
        //
        // If we have reduced the side tone volume, restore it!
        //
+#ifdef GPIO
        if (gpio_cw_sidetone_enabled()) {
          cw_keyer_sidetone_volume = old_volume;
        }
+#endif
 
     }
     fprintf(stderr,"keyer_thread: EXIT\n");
index ed6244c1359c740282ef3e8f378183ff78bff304..f20823abe71ed8f1fe85951b7b46b94bb1f53822 100644 (file)
@@ -1177,14 +1177,7 @@ void *audio_thread(void *data) {
      if (seqnum != 0 &&seqnum != seqold+1 ) {
        fprintf(stderr,"Audio thread: SEQ ERROR, old=%lu new=%lu\n", seqold, seqnum);
      }
-     p=buffer+4;
-     for (i=0; i<64; i++) {
-       lsample  = ((signed char) *p++) << 8;   
-       lsample |= (*p++ & 0xff); 
-       rsample  = ((signed char) *p++) << 8;   
-       rsample |= (*p++ & 0xff); 
-       audio_write(lsample,rsample);
-    }
+     // just skip the audio samples
   }
   close (sock);
   return NULL;
diff --git a/radio.c b/radio.c
index b7ce5d0ff94d0ce31912613858ff116f46e6dcaf..84f1837bdfa279094af67bf021d79f0255c0e757 100644 (file)
--- a/radio.c
+++ b/radio.c
@@ -2085,7 +2085,9 @@ g_print("radioRestoreState: %s\n",property_path);
     memRestoreState();
     vfo_restore_state();
     modesettings_restore_state();
+#ifdef GPIO
     gpio_restore_actions();
+#endif
     value=getProperty("rigctl_enable");
     if(value) rigctl_enable=atoi(value);
     value=getProperty("rigctl_port_base");
index 246d89b3102da2d428d4ebf800b8a0070cf6a468..8df8b617bb2e9f9923302c51fbfc98240abfb5c5 100644 (file)
--- a/toolbar.c
+++ b/toolbar.c
@@ -83,7 +83,9 @@ static gint rit_minus_timer=-1;
 static gint xit_plus_timer=-1;
 static gint xit_minus_timer=-1;
 
+#ifdef GPIO
 SWITCH *toolbar_switches=switches_controller1[0];
+#endif
 
 static gboolean rit_timer_cb(gpointer data) {
   int i=GPOINTER_TO_INT(data);