diff options
author | Timothy B. Terriberry <tterribe@xiph.org> | 2011-10-15 00:38:24 +0400 |
---|---|---|
committer | Jean-Marc Valin <jmvalin@jmvalin.ca> | 2011-10-18 00:03:41 +0400 |
commit | 53cc1a033a3183c9d137b03446db58d2e58c0e0a (patch) | |
tree | 24476c962dbb081126c89d6f26dd9d02f7bf88e7 /silk/float | |
parent | 7ef6c7c1b465df4ef3b4ece2ecbf9d35c625beb4 (diff) |
Fix the side frame conditional coding rules.
b24e5746 introduced changes to LastGainIndex which broke
conditional coding for side frames after a mid-only frame (i.e.,
in a 60 ms frame where the side is coded, not coded, then coded
again).
These rules were a mess in general, however, because the side
channel state kept a different nFramesDecoded count from the mid
channel state, and had no way to tell if the prior side frame was
coded.
This patch attempts to rationalize them by moving the conditional
coding decision up to the top level, where all this information is
available.
The first coded side frame after an uncoded side frame now always
uses independent coding.
If such a frame is also not the first side frame in an Opus frame,
then it doesn't include an LTP scaling parameter (because the LTP
state is well-defined).
Diffstat (limited to 'silk/float')
-rw-r--r-- | silk/float/LTP_scale_ctrl_FLP.c | 5 | ||||
-rw-r--r-- | silk/float/encode_frame_FLP.c | 19 | ||||
-rw-r--r-- | silk/float/find_pred_coefs_FLP.c | 5 | ||||
-rw-r--r-- | silk/float/main_FLP.h | 12 | ||||
-rw-r--r-- | silk/float/process_gains_FLP.c | 5 |
5 files changed, 28 insertions, 18 deletions
diff --git a/silk/float/LTP_scale_ctrl_FLP.c b/silk/float/LTP_scale_ctrl_FLP.c index 76290b14..cbac1005 100644 --- a/silk/float/LTP_scale_ctrl_FLP.c +++ b/silk/float/LTP_scale_ctrl_FLP.c @@ -33,7 +33,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. void silk_LTP_scale_ctrl_FLP( silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ - silk_encoder_control_FLP *psEncCtrl /* I/O Encoder control FLP */ + silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */ + opus_int condCoding /* I The type of conditional coding to use */ ) { opus_int round_loss; @@ -45,7 +46,7 @@ void silk_LTP_scale_ctrl_FLP( psEnc->prevLTPredCodGain = psEncCtrl->LTPredCodGain; /* Only scale if first frame in packet */ - if( psEnc->sCmn.nFramesEncoded == 0 ) { + if( condCoding == CODE_INDEPENDENTLY ) { round_loss = psEnc->sCmn.PacketLoss_perc + psEnc->sCmn.nFramesPerPacket; psEnc->sCmn.indices.LTP_scaleIndex = (opus_int8)silk_LIMIT( round_loss * psEnc->HPLTPredCodGain * 0.1f, 0.0f, 2.0f ); } else { diff --git a/silk/float/encode_frame_FLP.c b/silk/float/encode_frame_FLP.c index 4d156a03..d1056428 100644 --- a/silk/float/encode_frame_FLP.c +++ b/silk/float/encode_frame_FLP.c @@ -36,7 +36,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. static inline void silk_LBRR_encode_FLP( silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */ - const silk_float xfw[] /* I Input signal */ + const silk_float xfw[], /* I Input signal */ + opus_int condCoding /* I The type of conditional coding used so far for this frame */ ); /****************/ @@ -45,7 +46,8 @@ static inline void silk_LBRR_encode_FLP( opus_int silk_encode_frame_FLP( silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ opus_int32 *pnBytesOut, /* O Number of payload bytes */ - ec_enc *psRangeEnc /* I/O compressor data structure */ + ec_enc *psRangeEnc, /* I/O compressor data structure */ + opus_int condCoding /* I The type of conditional coding to use */ ) { silk_encoder_control_FLP sEncCtrl; @@ -128,14 +130,14 @@ TOC(NOISE_SHAPE_ANALYSIS) /* Find linear prediction coefficients (LPC + LTP) */ /***************************************************/ TIC(FIND_PRED_COEF) - silk_find_pred_coefs_FLP( psEnc, &sEncCtrl, res_pitch, x_frame ); + silk_find_pred_coefs_FLP( psEnc, &sEncCtrl, res_pitch, x_frame, condCoding ); TOC(FIND_PRED_COEF) /****************************************/ /* Process gains */ /****************************************/ TIC(PROCESS_GAINS) - silk_process_gains_FLP( psEnc, &sEncCtrl ); + silk_process_gains_FLP( psEnc, &sEncCtrl, condCoding ); TOC(PROCESS_GAINS) /*****************************************/ @@ -149,7 +151,7 @@ TOC(PREFILTER) /* Low Bitrate Redundant Encoding */ /****************************************/ TIC(LBRR) - silk_LBRR_encode_FLP( psEnc, &sEncCtrl, xfw ); + silk_LBRR_encode_FLP( psEnc, &sEncCtrl, xfw, condCoding ); TOC(LBRR) /*****************************************/ @@ -178,7 +180,7 @@ TOC(NSQ) /* Encode Parameters */ /****************************************/ TIC(ENCODE_PARAMS) - silk_encode_indices( &psEnc->sCmn, psRangeEnc, psEnc->sCmn.nFramesEncoded, 0 ); + silk_encode_indices( &psEnc->sCmn, psRangeEnc, psEnc->sCmn.nFramesEncoded, 0, condCoding ); TOC(ENCODE_PARAMS) /****************************************/ @@ -222,7 +224,8 @@ TOC(ENCODE_FRAME) static inline void silk_LBRR_encode_FLP( silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */ - const silk_float xfw[] /* I Input signal */ + const silk_float xfw[], /* I Input signal */ + opus_int condCoding /* I The type of conditional coding used so far for this frame */ ) { opus_int k; @@ -255,7 +258,7 @@ static inline void silk_LBRR_encode_FLP( /* Decode to get gains in sync with decoder */ silk_gains_dequant( Gains_Q16, psIndices_LBRR->GainsIndices, - &psEnc->sCmn.LBRRprevLastGainIndex, psEnc->sCmn.nFramesEncoded, psEnc->sCmn.nb_subfr ); + &psEnc->sCmn.LBRRprevLastGainIndex, condCoding == CODE_CONDITIONALLY, psEnc->sCmn.nb_subfr ); /* Overwrite unquantized gains with quantized gains and convert back to Q0 from Q16 */ for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { diff --git a/silk/float/find_pred_coefs_FLP.c b/silk/float/find_pred_coefs_FLP.c index 49c29d36..04881855 100644 --- a/silk/float/find_pred_coefs_FLP.c +++ b/silk/float/find_pred_coefs_FLP.c @@ -36,7 +36,8 @@ void silk_find_pred_coefs_FLP( silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */ const silk_float res_pitch[], /* I Residual from pitch analysis */ - const silk_float x[] /* I Speech signal */ + const silk_float x[], /* I Speech signal */ + opus_int condCoding /* I The type of conditional coding to use */ ) { opus_int i; @@ -73,7 +74,7 @@ void silk_find_pred_coefs_FLP( WLTP, psEnc->sCmn.mu_LTP_Q9, psEnc->sCmn.LTPQuantLowComplexity, psEnc->sCmn.nb_subfr ); /* Control LTP scaling */ - silk_LTP_scale_ctrl_FLP( psEnc, psEncCtrl ); + silk_LTP_scale_ctrl_FLP( psEnc, psEncCtrl, condCoding ); /* Create LTP residual */ silk_LTP_analysis_filter_FLP( LPC_in_pre, x - psEnc->sCmn.predictLPCOrder, psEncCtrl->LTPCoef, diff --git a/silk/float/main_FLP.h b/silk/float/main_FLP.h index 605fd384..d0c2de7c 100644 --- a/silk/float/main_FLP.h +++ b/silk/float/main_FLP.h @@ -57,7 +57,8 @@ void silk_HP_variable_cutoff( opus_int silk_encode_frame_FLP( silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ opus_int32 *pnBytesOut, /* O Number of payload bytes; */ - ec_enc *psRangeEnc /* I/O compressor data structure */ + ec_enc *psRangeEnc, /* I/O compressor data structure */ + opus_int condCoding /* I The type of conditional coding to use */ ); /* Initializes the Silk encoder state */ @@ -108,7 +109,8 @@ void silk_warped_autocorrelation_FLP( /* Calculation of LTP state scaling */ void silk_LTP_scale_ctrl_FLP( silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ - silk_encoder_control_FLP *psEncCtrl /* I/O Encoder control FLP */ + silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */ + opus_int condCoding /* I The type of conditional coding to use */ ); /**********************************************/ @@ -127,7 +129,8 @@ void silk_find_pred_coefs_FLP( silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */ const silk_float res_pitch[], /* I Residual from pitch analysis */ - const silk_float x[] /* I Speech signal */ + const silk_float x[], /* I Speech signal */ + opus_int condCoding /* I The type of conditional coding to use */ ); /* LPC analysis */ @@ -234,7 +237,8 @@ void silk_VQ_WMat_EC_FLP( /* Processing of gains */ void silk_process_gains_FLP( silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ - silk_encoder_control_FLP *psEncCtrl /* I/O Encoder control FLP */ + silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */ + opus_int condCoding /* I The type of conditional coding to use */ ); /******************/ diff --git a/silk/float/process_gains_FLP.c b/silk/float/process_gains_FLP.c index e0c18a97..2c7dfdd0 100644 --- a/silk/float/process_gains_FLP.c +++ b/silk/float/process_gains_FLP.c @@ -35,7 +35,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /* Processing of gains */ void silk_process_gains_FLP( silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ - silk_encoder_control_FLP *psEncCtrl /* I/O Encoder control FLP */ + silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */ + opus_int condCoding /* I The type of conditional coding to use */ ) { silk_shape_state_FLP *psShapeSt = &psEnc->sShape; @@ -68,7 +69,7 @@ void silk_process_gains_FLP( /* Noise shaping quantization */ silk_gains_quant( psEnc->sCmn.indices.GainsIndices, pGains_Q16, - &psShapeSt->LastGainIndex, psEnc->sCmn.nFramesEncoded, psEnc->sCmn.nb_subfr ); + &psShapeSt->LastGainIndex, condCoding == CODE_CONDITIONALLY, psEnc->sCmn.nb_subfr ); /* Overwrite unquantized gains with quantized gains and convert back to Q0 from Q16 */ for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { |