From 591b74945dda62afb08d9c964876c11d8ed387f7 Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Sat, 8 Oct 2011 10:22:10 -0400 Subject: [PATCH] Redundancy fixes No longer encoding the redundancy flag for SILK since we can infer redundancy from the length of the frame. Also, we skip encoding the flag for hybrid mode when we know the decoder will not read it. --- src/opus_decoder.c | 7 +++++-- src/opus_encoder.c | 14 +++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/opus_decoder.c b/src/opus_decoder.c index 00fd2abf..6b72efa2 100644 --- a/src/opus_decoder.c +++ b/src/opus_decoder.c @@ -321,10 +321,13 @@ static int opus_decode_frame(OpusDecoder *st, const unsigned char *data, } start_band = 0; - if (mode != MODE_CELT_ONLY && data != NULL && ec_tell(&dec)+29+8*(st->mode == MODE_HYBRID) < 8*len) + if (mode != MODE_CELT_ONLY && data != NULL && ec_tell(&dec)+17+20*(st->mode == MODE_HYBRID) < 8*len) { /* Check if we have a redundant 0-8 kHz band */ - redundancy = ec_dec_bit_logp(&dec, 12); + if (mode == MODE_HYBRID) + redundancy = ec_dec_bit_logp(&dec, 12); + else + redundancy = 1; if (redundancy) { celt_to_silk = ec_dec_bit_logp(&dec, 1); diff --git a/src/opus_encoder.c b/src/opus_encoder.c index f14414c8..586091fb 100644 --- a/src/opus_encoder.c +++ b/src/opus_encoder.c @@ -917,15 +917,19 @@ int opus_encode_float(OpusEncoder *st, const opus_val16 *pcm, int frame_size, } } - if (st->mode != MODE_CELT_ONLY && ec_tell(&enc)+29+8*(st->mode == MODE_HYBRID) < 8*nb_compr_bytes) + if ( st->mode != MODE_CELT_ONLY && ec_tell(&enc)+17+20*(st->mode == MODE_HYBRID) < 8*(max_data_bytes-1)) { - /* Check if we have a redundant 0-8 kHz band */ - ec_enc_bit_logp(&enc, redundancy, 12); + /* For SILK mode, the redundancy is inferred from the length */ + if (st->mode == MODE_HYBRID && (redundancy || ec_tell(&enc)+37 < 8*nb_compr_bytes)) + ec_enc_bit_logp(&enc, redundancy, 12); if (redundancy) { int max_redundancy; ec_enc_bit_logp(&enc, celt_to_silk, 1); - max_redundancy = nb_compr_bytes-((ec_tell(&enc)+7)>>3)-(st->mode == MODE_HYBRID); + if (st->mode == MODE_HYBRID) + max_redundancy = (max_data_bytes-1)-nb_compr_bytes-1; + else + max_redundancy = (max_data_bytes-1)-((ec_tell(&enc)+7)>>3); /* Target the same bit-rate for redundancy as for the rest, up to a max of 257 bytes */ redundancy_bytes = IMIN(max_redundancy, st->bitrate_bps/1600); @@ -953,7 +957,7 @@ int opus_encode_float(OpusEncoder *st, const opus_val16 *pcm, int frame_size, while(ret>2&&data[ret-1]==0)ret--; nb_compr_bytes = ret; } else { - nb_compr_bytes = IMIN(1275-redundancy_bytes, nb_compr_bytes); + nb_compr_bytes = IMIN((max_data_bytes-1)-redundancy_bytes, nb_compr_bytes); ec_enc_shrink(&enc, nb_compr_bytes); }