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 },
};
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)
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);
break;
switch (opt) {
- case 0:
+ case 0:
if(strcmp(long_options[option_index].name, "ber") == 0) {
ber = atof(optarg);
error_mode = UNIFORM;
} 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++;
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);
}
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);