natural encode and decode working OK
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Fri, 25 Apr 2014 06:15:51 +0000 (06:15 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Fri, 25 Apr 2014 06:15:51 +0000 (06:15 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@1561 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/src/c2dec.c
codec2-dev/src/c2enc.c

index b63c69219883c97f2e011b8c3791861c55761a43..a0bc9b278adf2599168212ce4a38d0bcc3ef0ea2 100644 (file)
@@ -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++;
index 027f617b261e62e170fc2f8978685abb1c5ec85d..f0d9bca1e000886cb54a2c410009d6a3ee6450e2 100644 (file)
@@ -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);