summaryrefslogtreecommitdiff
path: root/silk/NSQ.c
diff options
context:
space:
mode:
authorJean-Marc Valin <jmvalin@jmvalin.ca>2016-04-20 03:37:32 -0400
committerJean-Marc Valin <jmvalin@jmvalin.ca>2016-07-17 15:05:54 -0400
commit894f7294172f70174e1a5d99d0cce79209967f76 (patch)
tree8f752db6bbb7cc0d8f3451311768633acd2437ea /silk/NSQ.c
parent89857b5c0c9246f2d24a8bf17031b001c3722c4e (diff)
downloadopus-894f7294172f70174e1a5d99d0cce79209967f76.tar.gz
Makes the encoder more aggressive about meeting the rate target
Diffstat (limited to 'silk/NSQ.c')
-rw-r--r--silk/NSQ.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/silk/NSQ.c b/silk/NSQ.c
index 43e3fee7..5032b9c5 100644
--- a/silk/NSQ.c
+++ b/silk/NSQ.c
@@ -226,6 +226,10 @@ void silk_noise_shape_quantizer(
silk_short_prediction_create_arch_coef(a_Q12_arch, a_Q12, predictLPCOrder);
#endif
+ /* We're getting desperate to hit the target -- pretend there's
+ no dithering to make hitting the target more likely. */
+ if (Lambda_Q10 > 3072) offset_Q10 = 0;
+
for( i = 0; i < length; i++ ) {
/* Generate dither */
NSQ->rand_seed = silk_RAND( NSQ->rand_seed );
@@ -287,6 +291,19 @@ void silk_noise_shape_quantizer(
/* Find two quantization level candidates and measure their rate-distortion */
q1_Q10 = silk_SUB32( r_Q10, offset_Q10 );
q1_Q0 = silk_RSHIFT( q1_Q10, 10 );
+ if (Lambda_Q10 > 2048) {
+ /* For aggressive RDO, the bias becomes more than one pulse. */
+ int rdo_offset = Lambda_Q10/2 - 512;
+ if (q1_Q10 > rdo_offset) {
+ q1_Q0 = silk_RSHIFT( q1_Q10 - rdo_offset, 10 );
+ } else if (q1_Q10 < -rdo_offset) {
+ q1_Q0 = silk_RSHIFT( q1_Q10 + rdo_offset, 10 );
+ } else if (q1_Q10 < 0) {
+ q1_Q0 = -1;
+ } else {
+ q1_Q0 = 0;
+ }
+ }
if( q1_Q0 > 0 ) {
q1_Q10 = silk_SUB32( silk_LSHIFT( q1_Q0, 10 ), QUANT_LEVEL_ADJUST_Q10 );
q1_Q10 = silk_ADD32( q1_Q10, offset_Q10 );