Commit 8f67b20a authored by Koen Vos's avatar Koen Vos Committed by Jean-Marc Valin
Browse files

Testing the range coder final state

parent 0a0d07c1
silk @ a81e6dc2
Subproject commit 4e28e7426638655959294670c36d0c52be44fb74
Subproject commit a81e6dc2bc337c25156e6e908e45cbf7a5e0f104
......@@ -47,6 +47,8 @@ extern "C" {
#define __check_int(x) (((void)((x) == (int)0)), (int)(x))
#define __check_int_ptr(ptr) ((ptr) + ((ptr) - (int*)(ptr)))
#define OPUS_TEST_RANGE_CODER_STATE 1
#define MODE_SILK_ONLY 1000
#define MODE_HYBRID 1001
#define MODE_CELT_ONLY 1002
......@@ -104,8 +106,9 @@ typedef struct OpusDecoder OpusDecoder;
OpusEncoder *opus_encoder_create(int Fs, int channels);
/* returns length of data payload (in bytes) */
int opus_encode(OpusEncoder *st, const short *pcm, int frame_size,
unsigned char *data, int bytes_per_packet);
unsigned char *data, int max_data_bytes);
void opus_encoder_destroy(OpusEncoder *st);
......@@ -113,6 +116,7 @@ void opus_encoder_ctl(OpusEncoder *st, int request, ...);
OpusDecoder *opus_decoder_create(int Fs, int channels);
/* returns (CELT) error code */
int opus_decode(OpusDecoder *st, const unsigned char *data, int len,
short *pcm, int frame_size);
......@@ -120,6 +124,12 @@ void opus_decoder_ctl(OpusDecoder *st, int request, ...);
void opus_decoder_destroy(OpusDecoder *st);
#if OPUS_TEST_RANGE_CODER_STATE
int opus_encoder_get_final_range(OpusEncoder *st);
int opus_decoder_get_final_range(OpusDecoder *st);
#endif
#ifdef __cplusplus
}
#endif
......
......@@ -73,6 +73,7 @@ OpusDecoder *opus_decoder_create(int Fs, int channels)
return st;
}
int opus_decode(OpusDecoder *st, const unsigned char *data,
int len, short *pcm, int frame_size)
{
......@@ -199,6 +200,11 @@ int opus_decode(OpusDecoder *st, const unsigned char *data,
for (i=0;i<frame_size*st->channels;i++)
pcm[i] = ADD_SAT16(pcm[i], pcm_celt[i]);
}
#if OPUS_TEST_RANGE_CODER_STATE
st->rangeFinal = dec.rng;
#endif
return celt_ret<0 ? celt_ret : audiosize;
}
......@@ -247,3 +253,10 @@ void opus_decoder_destroy(OpusDecoder *st)
{
free(st);
}
#if OPUS_TEST_RANGE_CODER_STATE
int opus_decoder_get_final_range(OpusDecoder *st)
{
return st->rangeFinal;
}
#endif
......@@ -45,6 +45,10 @@ struct OpusDecoder {
int bandwidth;
/* Sampling rate (at the API level) */
int Fs;
#ifdef OPUS_TEST_RANGE_CODER_STATE
int rangeFinal;
#endif
};
inline short ADD_SAT16(a, b) {
......
......@@ -74,7 +74,7 @@ OpusEncoder *opus_encoder_create(int Fs, int channels)
st->silk_mode.packetLossPercentage = 0;
st->silk_mode.useInBandFEC = 0;
st->silk_mode.useDTX = 0;
st->silk_mode.complexity = 2;
st->silk_mode.complexity = 10;
/* Create CELT encoder */
/* Initialize CELT encoder */
......@@ -246,6 +246,10 @@ int opus_encode(OpusEncoder *st, const short *pcm, int frame_size,
data[0] |= (st->stream_channels==2)<<2;
/*printf ("%x\n", (int)data[0]);*/
#if OPUS_TEST_RANGE_CODER_STATE
st->rangeFinal = enc.rng;
#endif
return ret+1;
}
......@@ -374,3 +378,9 @@ void opus_encoder_destroy(OpusEncoder *st)
free(st);
}
#if OPUS_TEST_RANGE_CODER_STATE
int opus_encoder_get_final_range(OpusEncoder *st)
{
return st->rangeFinal;
}
#endif
......@@ -54,6 +54,10 @@ struct OpusEncoder {
int bitrate_bps;
short delay_buffer[ENCODER_DELAY_COMPENSATION*2];
#ifdef OPUS_TEST_RANGE_CODER_STATE
int rangeFinal;
#endif
};
......
......@@ -53,7 +53,7 @@ void print_usage( char* argv[] )
fprintf(stderr, "-vbr : enable variable bitrate (recommended for SILK)\n" );
fprintf(stderr, "-bandwidth <NB|MB|WB|SWB|FB> : audio bandwidth (from narrowband to fullband)\n" );
fprintf(stderr, "-max_payload <bytes> : maximum payload size in bytes, default: 1024\n" );
fprintf(stderr, "-complexity <comp> : SILK complexity, 0: low, 1: medium, 2: high; default: 2\n" );
fprintf(stderr, "-complexity <comp> : complexity, 0 (lowest) ... 10 (highest); default: 10\n" );
fprintf(stderr, "-inbandfec : enable SILK inband FEC\n" );
fprintf(stderr, "-dtx : enable SILK DTX\n" );
fprintf(stderr, "-loss <perc> : simulate packet loss, in percent (0-100); default: 0\n" );
......@@ -93,6 +93,7 @@ int main(int argc, char *argv[])
short *in, *out;
int mode;
double bits=0.0, bits_act=0.0, bits2=0.0, nrg;
int bandwidth=-1;
if (argc < 8 )
{
......@@ -108,10 +109,10 @@ int main(int argc, char *argv[])
/* defaults: */
use_vbr = 0;
int bandwidth=-1;
bandwidth=-1;
internal_sampling_rate_Hz = sampling_rate;
max_payload_bytes = MAX_PACKET;
complexity = 2;
complexity = 10;
use_inbandfec = 0;
use_dtx = 0;
packet_loss_perc = 0;
......@@ -147,7 +148,7 @@ int main(int argc, char *argv[])
} else if( STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-inbandfec" ) == 0 ) {
use_inbandfec = 1;
args++;
} else if( STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-fec") == 0 ) {
} else if( STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-dtx") == 0 ) {
use_dtx = 1;
args++;
} else if( STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-loss" ) == 0 ) {
......@@ -195,7 +196,7 @@ int main(int argc, char *argv[])
if (mode==MODE_SILK_ONLY)
{
if (bandwidth == BANDWIDTH_SUPERWIDEBAND || bandwidth == BANDWIDTH_SUPERWIDEBAND)
if (bandwidth == BANDWIDTH_SUPERWIDEBAND || bandwidth == BANDWIDTH_FULLBAND)
{
fprintf (stderr, "Predictive mode only supports up to wideband\n");
return 1;
......@@ -268,6 +269,14 @@ int main(int argc, char *argv[])
fwrite(out+skip, sizeof(short), (write_samples-skip)*channels, fout);
skip = 0;
#if OPUS_TEST_RANGE_CODER_STATE
/* compare final range encoder rng values of encoder and decoder */
if( opus_decoder_get_final_range( dec ) != opus_encoder_get_final_range( enc ) ) {
fprintf (stderr, "Error: Range coder state mismatch between encoder and decoder.\n");
return 0;
}
#endif
/* count bits */
bits += len*8;
nrg = 0.0;
......
Supports Markdown
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