From: drowe67 Date: Fri, 25 Apr 2014 06:15:51 +0000 (+0000) Subject: natural encode and decode working OK X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=1e08c6aa6c8827af4f20c554b55b11ae7b0b470a;p=freetel-svn-tracking.git natural encode and decode working OK git-svn-id: https://svn.code.sf.net/p/freetel/code@1561 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2-dev/src/c2dec.c b/codec2-dev/src/c2dec.c index b63c6921..a0bc9b27 100644 --- a/codec2-dev/src/c2dec.c +++ b/codec2-dev/src/c2dec.c @@ -58,7 +58,7 @@ int main(int argc, char *argv[]) unsigned char mask; int natural, dump; - char* opt_string = ":"; + char* opt_string = "h:"; struct option long_options[] = { { "ber", required_argument, NULL, 0 }, { "range", required_argument, NULL, 0 }, @@ -72,6 +72,9 @@ int main(int argc, char *argv[]) }; int num_opts=sizeof(long_options)/sizeof(struct option); + if (argc < 4) + print_help(long_options, num_opts, argv); + if (strcmp(argv[1],"3200") == 0) mode = CODEC2_MODE_3200; else if (strcmp(argv[1],"2400") == 0) @@ -108,6 +111,7 @@ int main(int argc, char *argv[]) ber = 0.0; burst_length = burst_period = 0.0; burst_timer = 0.0; + dump = natural = 0; codec2 = codec2_create(mode); nsam = codec2_samples_per_frame(codec2); @@ -128,7 +132,7 @@ int main(int argc, char *argv[]) break; switch (opt) { - case 0: + case 0: if(strcmp(long_options[option_index].name, "ber") == 0) { ber = atof(optarg); error_mode = UNIFORM; @@ -140,28 +144,30 @@ int main(int argc, char *argv[]) } else if(strcmp(long_options[option_index].name, "berfile") == 0) { if ((fber = fopen(optarg,"wt")) == NULL) { fprintf(stderr, "Error opening BER file: %s %s.\n", - optarg, strerror(errno)); + optarg, strerror(errno)); exit(1); } + + } #ifdef DUMP - } else if(strcmp(long_options[option_index].name, "dump") == 0) { + else if(strcmp(long_options[option_index].name, "dump") == 0) { if (dump) dump_on(optarg); + } #endif break; - } - case 'h': + case 'h': print_help(long_options, num_opts, argv); break; - default: + default: /* This will never be reached */ break; } } - assert(nend_bit <= nbit); + codec2_set_natural_or_gray(codec2, !natural); while(fread(bits, sizeof(char), nbyte, fin) == (size_t)nbyte) { frames++; diff --git a/codec2-dev/src/c2enc.c b/codec2-dev/src/c2enc.c index 027f617b..f0d9bca1 100644 --- a/codec2-dev/src/c2enc.c +++ b/codec2-dev/src/c2enc.c @@ -41,11 +41,12 @@ int main(int argc, char *argv[]) FILE *fout; short *buf; unsigned char *bits; - int nsam, nbit, nbyte; + int nsam, nbit, nbyte, gray; - if (argc != 4) { - printf("usage: c2enc 3200|2400|1600|1400|1300|1200 InputRawspeechFile OutputBitFile\n"); + if (argc < 4) { + printf("usage: c2enc 3200|2400|1600|1400|1300|1200 InputRawspeechFile OutputBitFile [--natural]\n"); printf("e.g c2enc 1400 ../raw/hts1a.raw hts1a.c2\n"); + printf("e.g c2enc 1300 ../raw/hts1a.raw hts1a.c2 --natural\n"); exit(1); } @@ -88,6 +89,14 @@ int main(int argc, char *argv[]) bits = (unsigned char*)malloc(nbyte*sizeof(char)); + if (argc == 5) { + if (strcmp(argv[4], "--natural") == 0) + gray = 0; + else + gray = 1; + codec2_set_natural_or_gray(codec2, gray); + } + while(fread(buf, sizeof(short), nsam, fin) == (size_t)nsam) { codec2_encode(codec2, bits, buf); fwrite(bits, sizeof(char), nbyte, fout);