Commit 92613129 authored by Gregory Maxwell's avatar Gregory Maxwell Committed by Jean-Marc Valin
Browse files

Add support for a complexity argument to both testcelt and celtenc.

parent 7bf550ea
......@@ -52,6 +52,7 @@ int main(int argc, char *argv[])
int bytes_per_packet;
unsigned char data[1024];
int rate;
int complexity;
#if !(defined (FIXED_POINT) && defined(STATIC_MODES))
int i;
double rmsd = 0;
......@@ -59,9 +60,9 @@ int main(int argc, char *argv[])
int count = 0;
celt_int32_t skip;
celt_int16_t *in, *out;
if (argc != 8 && argc != 7)
if (argc != 9 && argc != 8 && argc != 7)
{
fprintf (stderr, "Usage: testcelt <rate> <channels> <frame size> <bytes per packet> <input> <output>\n");
fprintf (stderr, "Usage: testcelt <rate> <channels> <frame size> <bytes per packet> [<complexity> [packet loss rate]] <input> <output>\n");
return 1;
}
......@@ -83,24 +84,31 @@ int main(int argc, char *argv[])
fprintf (stderr, "bytes per packet must be between 10 and 200\n");
return 1;
}
inFile = argv[5];
inFile = argv[argc-2];
fin = fopen(inFile, "rb");
if (!fin)
{
fprintf (stderr, "Could not open input file %s\n", argv[5]);
fprintf (stderr, "Could not open input file %s\n", argv[argc-2]);
return 1;
}
outFile = argv[6];
outFile = argv[argc-1];
fout = fopen(outFile, "wb+");
if (!fout)
{
fprintf (stderr, "Could not open output file %s\n", argv[6]);
fprintf (stderr, "Could not open output file %s\n", argv[argc-1]);
return 1;
}
/* Use mode4 for stereo and don't forget to change the value of CHANNEL above */
enc = celt_encoder_create(mode);
dec = celt_decoder_create(mode);
if (argc>7)
{
complexity=atoi(argv[5]);
celt_encoder_ctl(enc,CELT_SET_COMPLEXITY(complexity));
}
celt_mode_info(mode, CELT_GET_FRAME_SIZE, &frame_size);
celt_mode_info(mode, CELT_GET_NB_CHANNELS, &channels);
......@@ -141,7 +149,7 @@ int main(int argc, char *argv[])
#endif
#if 1 /* Set to zero to use the encoder's output instead */
/* This is to simulate packet loss */
if (argc==9 && rand()%1000<atoi(argv[7]))
if (argc==10 && rand()%1000<atoi(argv[argc-3]))
/*if (errors && (errors%2==0))*/
celt_decode(dec, NULL, len, out);
else
......
......@@ -211,6 +211,7 @@ void usage(void)
printf ("\n");
printf ("Options:\n");
printf (" --bitrate n Encoding bit-rate\n");
printf (" --comp n Encoding complexity (0-10)\n");
printf (" --skeleton Outputs ogg skeleton metadata (may cause incompatibilities)\n");
printf (" --comment Add the given string as an extra comment. This may be\n");
printf (" used multiple times\n");
......@@ -249,6 +250,7 @@ int main(int argc, char **argv)
struct option long_options[] =
{
{"bitrate", required_argument, NULL, 0},
{"comp", required_argument, NULL, 0},
{"skeleton",no_argument,NULL, 0},
{"help", no_argument, NULL, 0},
{"quiet", no_argument, NULL, 0},
......@@ -289,6 +291,7 @@ int main(int argc, char **argv)
int wave_input=0;
celt_int32_t lookahead = 0;
int bytes_per_packet=48;
int complexity=-127;
snprintf(vendor_string, sizeof(vendor_string), "Encoded with CELT\n");
......@@ -347,6 +350,9 @@ int main(int argc, char **argv)
} else if (strcmp(long_options[option_index].name,"rate")==0)
{
rate=atoi (optarg);
} else if (strcmp(long_options[option_index].name,"comp")==0)
{
complexity=atoi (optarg);
} else if (strcmp(long_options[option_index].name,"comment")==0)
{
if (!strchr(optarg, '='))
......@@ -455,6 +461,7 @@ int main(int argc, char **argv)
fprintf (stderr, "Only mono and stereo are supported\n");
return 1;
}
mode = celt_mode_create(rate, chan, 256, NULL);
if (!mode)
return 1;
......@@ -479,6 +486,14 @@ int main(int argc, char **argv)
/*Initialize CELT encoder*/
st = celt_encoder_create(mode);
if (complexity!=-127) {
if (celt_encoder_ctl(st, CELT_SET_COMPLEXITY(complexity)) != CELT_OK)
{
fprintf (stderr, "Only complexity 0 through 10 is supported\n");
return 1;
}
}
if (strcmp(outFile,"-")==0)
{
#if defined WIN32 || defined _WIN32
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment