ref: 926131291f67b5ce998e25910aabafa397c9e061
parent: 7bf550ead4daf4ed50a9ac4b9b053d96d6bc1fe2
author: Gregory Maxwell <[email protected]>
date: Wed Oct 8 08:45:55 EDT 2008
Add support for a complexity argument to both testcelt and celtenc.
--- a/libcelt/testcelt.c
+++ b/libcelt/testcelt.c
@@ -52,6 +52,7 @@
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 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,18 +84,19 @@
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;
}
@@ -101,6 +103,12 @@
/* 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 @@
#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
--- a/tools/celtenc.c
+++ b/tools/celtenc.c
@@ -211,6 +211,7 @@
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 @@
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 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 @@
} 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 @@
fprintf (stderr, "Only mono and stereo are supported\n");
return 1;
}
+
mode = celt_mode_create(rate, chan, 256, NULL);
if (!mode)
return 1;
@@ -478,6 +485,14 @@
/*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)
{