diff options
| author | drowe67 <[email protected]> | 2023-07-20 08:59:48 +0930 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-07-20 08:59:48 +0930 |
| commit | 06d4c11e699b0351765f10398abb4f663a984f36 (patch) | |
| tree | 33e22af0814c5b6c3d676f096ae8c2ac8a3ed9f0 /src/vhf_frame_c2.c | |
| parent | 6588e77f38bdebd7adffe091b22e7760d95d0ccb (diff) | |
| parent | 4d6c143c0abec15e1d6ed1fd95d36f80e6cb7df8 (diff) | |
Merge pull request #3 from drowe67/dr-cleanup21.2.0
Cleanup Part 2
Diffstat (limited to 'src/vhf_frame_c2.c')
| -rw-r--r-- | src/vhf_frame_c2.c | 140 |
1 files changed, 71 insertions, 69 deletions
diff --git a/src/vhf_frame_c2.c b/src/vhf_frame_c2.c index 10fdf31..b9e312a 100644 --- a/src/vhf_frame_c2.c +++ b/src/vhf_frame_c2.c @@ -6,7 +6,7 @@ DATE CREATED: 8 March 2016 C tool to extract codec2 data from freedv VHF 2400A/B/whatever frames - + \*---------------------------------------------------------------------------*/ @@ -27,79 +27,81 @@ along with this program; if not, see <http://www.gnu.org/licenses/>. */ -#include <stdio.h> #include <stdint.h> +#include <stdio.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; - int frame_fmt = 0; - int fsize,c2size; - - if(argc<3){ - fprintf(stderr,"usage: %s (A|B) InpuC2File OutputOneBitPerCharFile\n",argv[0]); - exit(1); - } - - if(strcmp(argv[1],"A")==0){ - frame_fmt = FREEDV_VHF_FRAME_A; - } else if (strcmp(argv[1],"B")==0) { - frame_fmt = FREEDV_HF_FRAME_B; - } else { - fprintf(stderr,"usage: %s (A|B) InpuC2File OutputOneBitPerCharFile\n",argv[0]); - exit(1); - } - - /* Open files */ - if(strcmp(argv[2],"-")==0){ - fin = stdin; - }else{ - fin = fopen(argv[2],"r"); - } - - if(strcmp(argv[3],"-")==0){ - fout = stdout; - }else{ - fout = fopen(argv[3],"w"); - } +int main(int argc, char *argv[]) { + struct freedv_vhf_deframer *deframer; + FILE *fin, *fout; + uint8_t *bitbuf; + uint8_t *c2buf; + int frame_fmt = 0; + int fsize, c2size; - /* Set up deframer */ - deframer = fvhff_create_deframer(frame_fmt,0); - - if(fin==NULL || fout==NULL || deframer==NULL){ - fprintf(stderr,"Couldn't open test vector files\n"); - goto cleanup; - } - - c2size = fvhff_get_codec2_size(deframer); - fsize = fvhff_get_frame_size(deframer); - - /* allocate buffers for processing */ - bitbuf = (uint8_t*)malloc(sizeof(uint8_t)*fsize); - c2buf = (uint8_t*)malloc(sizeof(uint8_t)*c2size); - - /* Deframe! */ - while( fread(c2buf,sizeof(uint8_t),c2size,fin) == c2size ){ - fvhff_frame_bits(frame_fmt,bitbuf,c2buf,NULL,NULL); - fwrite(bitbuf,sizeof(uint8_t),fsize,fout); - - if(fout == stdin){ - fflush(fout); - } + if (argc < 3) { + fprintf(stderr, "usage: %s (A|B) InpuC2File OutputOneBitPerCharFile\n", + argv[0]); + exit(1); + } + + if (strcmp(argv[1], "A") == 0) { + frame_fmt = FREEDV_VHF_FRAME_A; + } else if (strcmp(argv[1], "B") == 0) { + frame_fmt = FREEDV_HF_FRAME_B; + } else { + fprintf(stderr, "usage: %s (A|B) InpuC2File OutputOneBitPerCharFile\n", + argv[0]); + exit(1); + } + + /* Open files */ + if (strcmp(argv[2], "-") == 0) { + fin = stdin; + } else { + fin = fopen(argv[2], "r"); + } + + if (strcmp(argv[3], "-") == 0) { + fout = stdout; + } else { + fout = fopen(argv[3], "w"); + } + + /* Set up deframer */ + deframer = fvhff_create_deframer(frame_fmt, 0); + + if (fin == NULL || fout == NULL || deframer == NULL) { + fprintf(stderr, "Couldn't open test vector files\n"); + goto cleanup; + } + + c2size = fvhff_get_codec2_size(deframer); + fsize = fvhff_get_frame_size(deframer); + + /* allocate buffers for processing */ + bitbuf = (uint8_t *)malloc(sizeof(uint8_t) * fsize); + c2buf = (uint8_t *)malloc(sizeof(uint8_t) * c2size); + + /* Deframe! */ + while (fread(c2buf, sizeof(uint8_t), c2size, fin) == c2size) { + fvhff_frame_bits(frame_fmt, bitbuf, c2buf, NULL, NULL); + fwrite(bitbuf, sizeof(uint8_t), fsize, fout); + + if (fout == stdin) { + fflush(fout); } - - free(bitbuf); - free(c2buf); - - cleanup: - fclose(fin); - fclose(fout); - fvhff_destroy_deframer(deframer); - exit(0); -} + } + free(bitbuf); + free(c2buf); + +cleanup: + fclose(fin); + fclose(fout); + fvhff_destroy_deframer(deframer); + exit(0); +} |
