From: John Melton - G0ORX/N6LYT <john.d.melton@googlemail.com>
Date: Sat, 20 Aug 2016 10:54:52 +0000 (+0000)
Subject: fixed buffer size on rate change with new protocol
X-Git-Url: https://git.rkrishnan.org/vdrive/components/(%5B%5E?a=commitdiff_plain;h=f3db0281e9cf1d6c702886ddd6fd8503d3faf38b;p=pihpsdr.git

fixed buffer size on rate change with new protocol
---

diff --git a/new_protocol.c b/new_protocol.c
index 3c134cc..537b64d 100644
--- a/new_protocol.c
+++ b/new_protocol.c
@@ -156,6 +156,29 @@ static void* new_protocol_timer_thread(void* arg);
 static void full_rx_buffer();
 static void full_tx_buffer();
 
+static void new_protocol_calc_buffers() {
+  switch(sample_rate) {
+    case 48000:
+      outputsamples=BUFFER_SIZE;
+      break;
+    case 96000:
+      outputsamples=BUFFER_SIZE/2;
+      break;
+    case 192000:
+      outputsamples=BUFFER_SIZE/4;
+      break;
+    case 384000:
+      outputsamples=BUFFER_SIZE/8;
+      break;
+    case 768000:
+      outputsamples=BUFFER_SIZE/16;
+      break;
+    case 1536000:
+      outputsamples=BUFFER_SIZE/32;
+      break;
+  }
+}
+
 void schedule_high_priority(int source) {
 fprintf(stderr,"new_protocol: schedule_high_priority: source=%d\n",source);
     sem_wait(&send_high_priority_sem);
@@ -201,6 +224,8 @@ void new_protocol_init(int rx,int pixels) {
       }
     }
 
+    new_protocol_calc_buffers();
+
     rc=sem_init(&response_sem, 0, 0);
     rc=sem_init(&send_high_priority_sem, 0, 1);
     rc=sem_init(&send_general_sem, 0, 1);
@@ -216,7 +241,7 @@ void new_protocol_init(int rx,int pixels) {
 void new_protocol_new_sample_rate(int rate) {
   new_protocol_high_priority(0,0,0);
   sample_rate=rate;
-  old_protocol_calc_buffers();
+  new_protocol_calc_buffers();
   wdsp_new_sample_rate(rate);
   new_protocol_high_priority(1,0,drive);
 }
diff --git a/pihpsdr b/pihpsdr
index 9feeac7..b39d2e3 100755
Binary files a/pihpsdr and b/pihpsdr differ
diff --git a/release/pihpsdr.tar b/release/pihpsdr.tar
index dc835a6..c69d382 100644
Binary files a/release/pihpsdr.tar and b/release/pihpsdr.tar differ
diff --git a/release/pihpsdr/pihpsdr b/release/pihpsdr/pihpsdr
index 9feeac7..b39d2e3 100755
Binary files a/release/pihpsdr/pihpsdr and b/release/pihpsdr/pihpsdr differ
diff --git a/wdsp_init.c b/wdsp_init.c
index 70a2b60..92325a6 100644
--- a/wdsp_init.c
+++ b/wdsp_init.c
@@ -80,19 +80,24 @@ static int SPECTRUM_UPDATES_PER_SECOND=10;
 static void initAnalyzer(int channel,int buffer_size);
 
 static void calc_tx_buffer_size() {
-  switch(sample_rate) {
-    case 48000:
-      tx_buffer_size=BUFFER_SIZE;
-      break;
-    case 96000:
-      tx_buffer_size=BUFFER_SIZE/2;
-      break;
-    case 192000:
-      tx_buffer_size=BUFFER_SIZE/4;
-      break;
-    case 384000:
-      tx_buffer_size=BUFFER_SIZE/8;
-      break;
+  if(protocol==ORIGINAL_PROTOCOL) {
+    switch(sample_rate) {
+      case 48000:
+        tx_buffer_size=BUFFER_SIZE;
+        break;
+      case 96000:
+        tx_buffer_size=BUFFER_SIZE/2;
+        break;
+      case 192000:
+        tx_buffer_size=BUFFER_SIZE/4;
+        break;
+      case 384000:
+        tx_buffer_size=BUFFER_SIZE/8;
+        break;
+    }
+  } else {
+    tx_buffer_size=BUFFER_SIZE*4;
+    // input always 48K -- output always 192K
   }
 }
 
@@ -398,11 +403,14 @@ void wdsp_init(int rx,int pixels,int protocol) {
 }
 
 void wdsp_new_sample_rate(int rate) {
-  SetChannelState(CHANNEL_TX,0,0);
-  calc_tx_buffer_size();
-  initAnalyzer(CHANNEL_TX,tx_buffer_size);
-  SetInputSamplerate(CHANNEL_TX,rate);
-  SetChannelState(CHANNEL_TX,1,0);
+
+  if(protocol==ORIGINAL_PROTOCOL) {
+    SetChannelState(CHANNEL_TX,0,0);
+    calc_tx_buffer_size();
+    initAnalyzer(CHANNEL_TX,tx_buffer_size);
+    SetInputSamplerate(CHANNEL_TX,rate);
+    SetChannelState(CHANNEL_TX,1,0);
+  }
 
   SetChannelState(receiver,0,0);
   SetInputSamplerate(receiver,rate);