diff options
author | Jean-Marc Valin <jmvalin@jmvalin.ca> | 2011-10-31 06:49:35 +0400 |
---|---|---|
committer | Jean-Marc Valin <jmvalin@jmvalin.ca> | 2011-10-31 06:49:35 +0400 |
commit | a05a379fc420bfca0ad50842a89b7f2db476b213 (patch) | |
tree | d21cd4f2f942a1d63129852a5e83eace4d848850 /src | |
parent | 23f3a1f1d763c9a9cf350b9915f4cc69469d0d61 (diff) |
Adds -random_framesize and -sweep_max options to opus_demo
Undocumented for now.
Diffstat (limited to 'src')
-rw-r--r-- | src/opus_demo.c | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/src/opus_demo.c b/src/opus_demo.c index e1884f37..7c161600 100644 --- a/src/opus_demo.c +++ b/src/opus_demo.c @@ -37,6 +37,7 @@ #include "opus.h" #include "debug.h" #include "opus_types.h" +#include "opus_private.h" #define MAX_PACKET 1500 @@ -139,6 +140,8 @@ int main(int argc, char *argv[]) int max_frame_size = 960*6; int curr_read=0; int sweep_bps = 0; + int random_framesize=0, newsize=0, delayed_celt=0; + int sweep_max=0, sweep_min=0; if (argc < 5 ) { @@ -286,6 +289,14 @@ int main(int argc, char *argv[]) check_encoder_option(decode_only, "-sweep"); sweep_bps = atoi( argv[ args + 1 ] ); args += 2; + } else if( STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-random_framesize" ) == 0 ) { + check_encoder_option(decode_only, "-random_framesize"); + random_framesize = 1; + args++; + } else if( STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-sweep_max" ) == 0 ) { + check_encoder_option(decode_only, "-sweep_max"); + sweep_max = atoi( argv[ args + 1 ] ); + args += 2; } else { printf( "Error: unrecognized setting: %s\n\n", argv[ args ] ); print_usage( argv ); @@ -293,6 +304,9 @@ int main(int argc, char *argv[]) } } + if (sweep_max) + sweep_min = bitrate_bps; + if (max_payload_bytes < 0 || max_payload_bytes > MAX_PACKET) { fprintf (stderr, "max_payload_bytes must be between 0 and %d\n", @@ -385,7 +399,7 @@ int main(int argc, char *argv[]) (long)sampling_rate, bitrate_bps*0.001, bandwidth_string, frame_size); - in = (short*)malloc(frame_size*channels*sizeof(short)); + in = (short*)malloc(max_frame_size*channels*sizeof(short)); out = (short*)malloc(max_frame_size*channels*sizeof(short)); data[0] = (unsigned char*)calloc(max_payload_bytes,sizeof(char)); if ( use_inbandfec ) { @@ -393,6 +407,30 @@ int main(int argc, char *argv[]) } while (!stop) { + if (delayed_celt) + { + frame_size = newsize; + delayed_celt = 0; + } else if (random_framesize && rand()%20==0) + { + newsize = rand()%6; + switch(newsize) + { + case 0: newsize=sampling_rate/400; break; + case 1: newsize=sampling_rate/200; break; + case 2: newsize=sampling_rate/100; break; + case 3: newsize=sampling_rate/50; break; + case 4: newsize=sampling_rate/25; break; + case 5: newsize=3*sampling_rate/50; break; + } + if (newsize < sampling_rate/100 && frame_size >= sampling_rate/100) + { + opus_encoder_ctl(enc, OPUS_SET_FORCE_MODE(MODE_CELT_ONLY)); + delayed_celt=1; + } else { + frame_size = newsize; + } + } if (decode_only) { unsigned char ch[4]; @@ -430,6 +468,13 @@ int main(int argc, char *argv[]) if (sweep_bps!=0) { bitrate_bps += sweep_bps; + if (sweep_max) + { + if (bitrate_bps > sweep_max) + sweep_bps = -sweep_bps; + else if (bitrate_bps < sweep_min) + sweep_bps = -sweep_bps; + } /* safety */ if (bitrate_bps<1000) bitrate_bps = 1000; |