summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKoen Vos <koenvos@users.noreply.github.com>2016-02-19 10:44:09 +0800
committerJean-Marc Valin <jmvalin@jmvalin.ca>2016-06-02 15:13:35 -0400
commit6332665c9a683797310c19502bb6c8fedf404aec (patch)
tree2e9bee4e16a935f85bd5de3a2b0660d8ab447aa2
parentaeab4cc920a92ab5b9e019de1439f887501348d5 (diff)
downloadopus-6332665c9a683797310c19502bb6c8fedf404aec.tar.gz
sum_sqr_shift: reduced headroom (ie more preserved resolution); shift increments by one instead of two
-rw-r--r--silk/sum_sqr_shift.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/silk/sum_sqr_shift.c b/silk/sum_sqr_shift.c
index 129df191..e387391a 100644
--- a/silk/sum_sqr_shift.c
+++ b/silk/sum_sqr_shift.c
@@ -45,39 +45,39 @@ void silk_sum_sqr_shift(
nrg = 0;
shft = 0;
- len--;
- for( i = 0; i < len; i += 2 ) {
+ for( i = 0; i < len - 1; i += 2 ) {
nrg = silk_SMLABB_ovflw( nrg, x[ i ], x[ i ] );
nrg = silk_SMLABB_ovflw( nrg, x[ i + 1 ], x[ i + 1 ] );
if( nrg < 0 ) {
/* Scale down */
- nrg = (opus_int32)silk_RSHIFT_uint( (opus_uint32)nrg, 2 );
- shft = 2;
- i+=2;
+ nrg = (opus_int32)silk_RSHIFT_uint( (opus_uint32)nrg, 1 );
+ shft = 1;
+ i += 2;
break;
}
}
- for( ; i < len; i += 2 ) {
+ for( ; i < len - 1; i += 2 ) {
nrg_tmp = silk_SMULBB( x[ i ], x[ i ] );
nrg_tmp = silk_SMLABB_ovflw( nrg_tmp, x[ i + 1 ], x[ i + 1 ] );
nrg = (opus_int32)silk_ADD_RSHIFT_uint( nrg, (opus_uint32)nrg_tmp, shft );
if( nrg < 0 ) {
/* Scale down */
- nrg = (opus_int32)silk_RSHIFT_uint( (opus_uint32)nrg, 2 );
- shft += 2;
+ nrg = (opus_int32)silk_RSHIFT_uint( (opus_uint32)nrg, 1 );
+ shft++;
}
}
- if( i == len ) {
+ if( i < len ) {
/* One sample left to process */
nrg_tmp = silk_SMULBB( x[ i ], x[ i ] );
nrg = (opus_int32)silk_ADD_RSHIFT_uint( nrg, nrg_tmp, shft );
}
- /* Make sure to have at least one extra leading zero (two leading zeros in total) */
- if( nrg & 0xC0000000 ) {
- nrg = silk_RSHIFT_uint( (opus_uint32)nrg, 2 );
- shft += 2;
+ /* Make sure to have at least 10% headroom */
+ if( (opus_uint32)nrg > SILK_FIX_CONST( 0.9, 31 ) ) {
+ nrg = silk_RSHIFT_uint( (opus_uint32)nrg, 1 );
+ shft++;
}
+ silk_assert( nrg >= 0 );
/* Output arguments */
*shift = shft;