Broke out deframer, starting work to change demod in buffer
authorbaobrien <baobrien@01035d8c-6547-0410-b346-abe4f91aad63>
Wed, 9 Mar 2016 18:29:46 +0000 (18:29 +0000)
committerbaobrien <baobrien@01035d8c-6547-0410-b346-abe4f91aad63>
Wed, 9 Mar 2016 18:29:46 +0000 (18:29 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@2720 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/src/CMakeLists.txt
codec2-dev/src/freedv_api.c
codec2-dev/src/freedv_vhf_framing.c
codec2-dev/src/freedv_vhf_framing.h
codec2-dev/src/fsk.c
codec2-dev/src/vhf_deframe_c2.c [new file with mode: 0644]

index 34f893043198e328931a0d61da49b152cea2cd9c..1f605c4528c2dab600c055375830c2da4bd35265 100644 (file)
@@ -261,6 +261,9 @@ target_link_libraries(fmfsk_mod ${CMAKE_REQUIRED_LIBRARIES} codec2)
 add_executable(fmfsk_demod fmfsk_demod.c modem_probe.c octave.c)
 target_link_libraries(fmfsk_demod ${CMAKE_REQUIRED_LIBRARIES} codec2)
 
+add_executable(vhf_deframe_c2 vhf_deframe_c2.c)
+target_link_libraries(vhf_deframe_c2  ${CMAKE_REQUIRED_LIBRARIES} codec2)
+
 add_executable(cohpsk_demod cohpsk_demod.c octave.c)
 target_link_libraries(cohpsk_demod ${CMAKE_REQUIRED_LIBRARIES} codec2)
 
index 46bb466a4e88f9021b007513474f69d67c222471..70c5be2f9a25a4cfb791816874217edbecbd33d6 100644 (file)
@@ -154,7 +154,7 @@ struct freedv *freedv_open(int mode) {
         if(f->deframer == NULL)
             return NULL;
   
-        f->fsk = fsk_create_hbr(48000,1200,10,4,1200,1200);
+        f->fsk = fsk_create_hbr(48000,1200,40,4,1200,1200);
         
         /* Note: fsk expects tx/rx bits as an array of uint8_ts, not ints */
         f->tx_bits = (int*)malloc(f->fsk->Nbits*sizeof(uint8_t));
index cf29896784372be72e1891cd5a88f831b09c98cb..66604fdd6d84f71d24ef1e3b2a31c5d63474296e 100644 (file)
@@ -279,7 +279,7 @@ int fvhff_deframe_bits(struct freedv_vhf_deframer * def,uint8_t codec2_out[],uin
     /* Possibly set up frame-specific params here */
     if(frame_type == FREEDV_VHF_FRAME_A){
         uw_first_tol = 1;   /* The UW bit-error tolerance for the first frame */
-        uw_sync_tol = 2;    /* The UW bit error tolerance for frames after sync */
+        uw_sync_tol = 3;    /* The UW bit error tolerance for frames after sync */
         miss_tol = 5;       /* How many UWs may be missed before going into the de-synced state */
     }else{
         return 0;
index c5ad034653067b7fa1447ab14f1709c81e224b91..7ced7f3589e8916cbc297b4cbc3749c54e6b92ad 100644 (file)
@@ -38,6 +38,7 @@
 
 /* Standard frame type */
 #define FREEDV_VHF_FRAME_A 1
+
 struct freedv_vhf_deframer {
     int ftype;          /* Type of frame to be looking for */
     int state;          /* State of deframer */
index 9d2bbc223fb12c94c144e002374b0070d4f2ca4a..c12f868a28a48ad15a2be3cb42e03b721013aa09 100644 (file)
@@ -133,8 +133,7 @@ struct FSK * fsk_create_hbr(int Fs, int Rs,int P,int M, int tx_f1, int tx_fs)
     int Ndft = 0;
     
     /* Number of symbols in a processing frame */
-    //int nsyms = 24;
-    //int nsyms = 192;
+    //int nsyms = 96;
     int nsyms = 48;
     /* Check configuration validity */
     assert(Fs > 0 );
@@ -174,12 +173,12 @@ struct FSK * fsk_create_hbr(int Fs, int Rs,int P,int M, int tx_f1, int tx_fs)
     
     fsk->Ndft = Ndft;
     
-    fsk->est_min = tx_f1-3*Rs;
+    fsk->est_min = Rs/2;
     if(fsk->est_min<0) fsk->est_min = 0;
     
     fsk->est_max = (Fs/2)-Rs;
     
-    fsk->est_space = Rs;
+    fsk->est_space = Rs-(Rs/5);
     
     /* Set up rx state */
     fsk->phi1_c = comp_exp_j(0);
@@ -679,10 +678,12 @@ void fsk2_demod(struct FSK *fsk, uint8_t rx_bits[], float fsk_in[]){
     }
     
     /* Figure out how many samples are needed the next modem cycle */
-    if(norm_rx_timing > 0.25)
+    if(norm_rx_timing > 0.25){
         fsk->nin = N+Ts/2;
-    else if(norm_rx_timing < -0.25)
+    }
+    else if(norm_rx_timing < -0.25){
         fsk->nin = N-Ts/2;
+    }
     else
         fsk->nin = N;
     
@@ -1022,13 +1023,18 @@ void fsk4_demod(struct FSK *fsk, uint8_t rx_bits[], float fsk_in[]){
     if(fabsf(d_norm_rx_timing) < .2){
         appm = 1e6*d_norm_rx_timing/(float)nsym;
         fsk->ppm = .9*fsk->ppm + .1*appm;
+        fprintf(stderr,"ppm:%f\n",fsk->ppm);
     }
     
     /* Figure out how many samples are needed the next modem cycle */
-    if(norm_rx_timing > 0.25)
+    if(norm_rx_timing > 0.25){
         fsk->nin = N+Ts/2;
-    else if(norm_rx_timing < -0.25)
+        fprintf(stderr,"+\n");
+    }
+    else if(norm_rx_timing < -0.25){
         fsk->nin = N-Ts/2;
+        fprintf(stderr,"-\n");
+    }
     else
         fsk->nin = N;
     
diff --git a/codec2-dev/src/vhf_deframe_c2.c b/codec2-dev/src/vhf_deframe_c2.c
new file mode 100644 (file)
index 0000000..1477bfb
--- /dev/null
@@ -0,0 +1,95 @@
+
+/*---------------------------------------------------------------------------*\
+
+  FILE........: vhf_deframe_c2.c
+  AUTHOR......: Brady O'Brien
+  DATE CREATED: 8 March 2016
+
+  C tool to extract codec2 data from freedv VHF 2400A/B/whatever frames
+   
+
+\*---------------------------------------------------------------------------*/
+
+/*
+  Copyright (C) 2016 David Rowe
+
+  All rights reserved.
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU Lesser General Public License version 2.1, as
+  published by the Free Software Foundation.  This program is
+  distributed in the hope that it will be useful, but WITHOUT ANY
+  WARRANTY; without even the implied warranty of MERCHANTABILITY or
+  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
+  License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with this program; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include "freedv_vhf_framing.h"
+
+int main(int argc,char *argv[]){
+    struct freedv_vhf_deframer * deframer;
+    FILE *fin,*fout;
+    uint8_t *bitbuf;
+    uint8_t *c2buf;
+    uint8_t zbuf[] = {0,0,0,0,0,0,0};
+    
+    if(argc<3){
+        fprintf(stderr,"usage: %s InputOneBitPerCharFile OutputC2File\n",argv[0]);
+        exit(1);
+    }
+    
+    /* Open files */
+    if(strcmp(argv[1],"-")==0){
+        fin = stdin;
+    }else{
+        fin = fopen(argv[1],"r");
+    }
+       
+    if(strcmp(argv[2],"-")==0){
+        fout = stdout;
+    }else{
+        fout = fopen(argv[2],"w");
+    }
+
+    /* Set up deframer */
+    deframer = fvhff_create_deframer(FREEDV_VHF_FRAME_A,0);
+    
+    if(fin==NULL || fout==NULL || deframer==NULL){
+        fprintf(stderr,"Couldn't open test vector files\n");
+        goto cleanup;
+    }
+    
+    /* allocate buffers for processing */
+    bitbuf = (uint8_t*)malloc(sizeof(uint8_t)*96);
+    c2buf = (uint8_t*)malloc(sizeof(uint8_t)*7);
+    
+    /* Deframe! */
+    while( fread(bitbuf,sizeof(uint8_t),96,fin) == 96 ){
+        if(fvhff_deframe_bits(deframer,c2buf,NULL,NULL,bitbuf))
+            fwrite(c2buf,sizeof(uint8_t),7,fout);
+        else
+            fwrite(zbuf,sizeof(uint8_t),7,fout);
+        
+        if(fin == stdin || fout == stdin){
+            fflush(fin);
+            fflush(fout);
+        }
+    }
+    
+    free(bitbuf);
+    free(c2buf);
+    
+    cleanup:
+    fclose(fin);
+    fclose(fout);
+    fvhff_destroy_deframer(deframer);
+    exit(0);
+}
+