From 49a984301599054e1a7c1ca75a42732f2a1701e5 Mon Sep 17 00:00:00 2001 From: baobrien Date: Wed, 9 Mar 2016 18:29:46 +0000 Subject: [PATCH] Broke out deframer, starting work to change demod in buffer git-svn-id: https://svn.code.sf.net/p/freetel/code@2720 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/src/CMakeLists.txt | 3 + codec2-dev/src/freedv_api.c | 2 +- codec2-dev/src/freedv_vhf_framing.c | 2 +- codec2-dev/src/freedv_vhf_framing.h | 1 + codec2-dev/src/fsk.c | 22 ++++--- codec2-dev/src/vhf_deframe_c2.c | 95 +++++++++++++++++++++++++++++ 6 files changed, 115 insertions(+), 10 deletions(-) create mode 100644 codec2-dev/src/vhf_deframe_c2.c diff --git a/codec2-dev/src/CMakeLists.txt b/codec2-dev/src/CMakeLists.txt index 34f89304..1f605c45 100644 --- a/codec2-dev/src/CMakeLists.txt +++ b/codec2-dev/src/CMakeLists.txt @@ -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) diff --git a/codec2-dev/src/freedv_api.c b/codec2-dev/src/freedv_api.c index 46bb466a..70c5be2f 100644 --- a/codec2-dev/src/freedv_api.c +++ b/codec2-dev/src/freedv_api.c @@ -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)); diff --git a/codec2-dev/src/freedv_vhf_framing.c b/codec2-dev/src/freedv_vhf_framing.c index cf298967..66604fdd 100644 --- a/codec2-dev/src/freedv_vhf_framing.c +++ b/codec2-dev/src/freedv_vhf_framing.c @@ -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; diff --git a/codec2-dev/src/freedv_vhf_framing.h b/codec2-dev/src/freedv_vhf_framing.h index c5ad0346..7ced7f35 100644 --- a/codec2-dev/src/freedv_vhf_framing.h +++ b/codec2-dev/src/freedv_vhf_framing.h @@ -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 */ diff --git a/codec2-dev/src/fsk.c b/codec2-dev/src/fsk.c index 9d2bbc22..c12f868a 100644 --- a/codec2-dev/src/fsk.c +++ b/codec2-dev/src/fsk.c @@ -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 index 00000000..1477bfbc --- /dev/null +++ b/codec2-dev/src/vhf_deframe_c2.c @@ -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 . +*/ + +#include +#include +#include +#include +#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); +} + -- 2.25.1