Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(823)

Side by Side Diff: third_party/opus/src/silk/sum_sqr_shift.c

Issue 2962373002: [Opus] Update to v1.2.1 (Closed)
Patch Set: Pre-increment instead of post-increment Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/opus/src/silk/structs.h ('k') | third_party/opus/src/silk/tables.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /*********************************************************************** 1 /***********************************************************************
2 Copyright (c) 2006-2011, Skype Limited. All rights reserved. 2 Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3 Redistribution and use in source and binary forms, with or without 3 Redistribution and use in source and binary forms, with or without
4 modification, are permitted provided that the following conditions 4 modification, are permitted provided that the following conditions
5 are met: 5 are met:
6 - Redistributions of source code must retain the above copyright notice, 6 - Redistributions of source code must retain the above copyright notice,
7 this list of conditions and the following disclaimer. 7 this list of conditions and the following disclaimer.
8 - Redistributions in binary form must reproduce the above copyright 8 - Redistributions in binary form must reproduce the above copyright
9 notice, this list of conditions and the following disclaimer in the 9 notice, this list of conditions and the following disclaimer in the
10 documentation and/or other materials provided with the distribution. 10 documentation and/or other materials provided with the distribution.
(...skipping 23 matching lines...) Expand all
34 /* Compute number of bits to right shift the sum of squares of a vector */ 34 /* Compute number of bits to right shift the sum of squares of a vector */
35 /* of int16s to make it fit in an int32 */ 35 /* of int16s to make it fit in an int32 */
36 void silk_sum_sqr_shift( 36 void silk_sum_sqr_shift(
37 opus_int32 *energy, /* O Energy of x, after sh ifting to the right */ 37 opus_int32 *energy, /* O Energy of x, after sh ifting to the right */
38 opus_int *shift, /* O Number of bits right shift applied to energy */ 38 opus_int *shift, /* O Number of bits right shift applied to energy */
39 const opus_int16 *x, /* I Input vector */ 39 const opus_int16 *x, /* I Input vector */
40 opus_int len /* I Length of input vecto r */ 40 opus_int len /* I Length of input vecto r */
41 ) 41 )
42 { 42 {
43 opus_int i, shft; 43 opus_int i, shft;
44 opus_int32 nrg_tmp, nrg; 44 opus_uint32 nrg_tmp;
45 opus_int32 nrg;
45 46
46 nrg = 0; 47 /* Do a first run with the maximum shift we could have. */
47 shft = 0; 48 shft = 31-silk_CLZ32(len);
48 len--; 49 /* Let's be conservative with rounding and start with nrg=len. */
49 for( i = 0; i < len; i += 2 ) { 50 nrg = len;
50 nrg = silk_SMLABB_ovflw( nrg, x[ i ], x[ i ] ); 51 for( i = 0; i < len - 1; i += 2 ) {
51 nrg = silk_SMLABB_ovflw( nrg, x[ i + 1 ], x[ i + 1 ] );
52 if( nrg < 0 ) {
53 /* Scale down */
54 nrg = (opus_int32)silk_RSHIFT_uint( (opus_uint32)nrg, 2 );
55 shft = 2;
56 i+=2;
57 break;
58 }
59 }
60 for( ; i < len; i += 2 ) {
61 nrg_tmp = silk_SMULBB( x[ i ], x[ i ] ); 52 nrg_tmp = silk_SMULBB( x[ i ], x[ i ] );
62 nrg_tmp = silk_SMLABB_ovflw( nrg_tmp, x[ i + 1 ], x[ i + 1 ] ); 53 nrg_tmp = silk_SMLABB_ovflw( nrg_tmp, x[ i + 1 ], x[ i + 1 ] );
63 nrg = (opus_int32)silk_ADD_RSHIFT_uint( nrg, (opus_uint32)nrg_tmp, shft ); 54 nrg = (opus_int32)silk_ADD_RSHIFT_uint( nrg, nrg_tmp, shft );
64 if( nrg < 0 ) {
65 /* Scale down */
66 nrg = (opus_int32)silk_RSHIFT_uint( (opus_uint32)nrg, 2 );
67 shft += 2;
68 }
69 } 55 }
70 if( i == len ) { 56 if( i < len ) {
57 /* One sample left to process */
58 nrg_tmp = silk_SMULBB( x[ i ], x[ i ] );
59 nrg = (opus_int32)silk_ADD_RSHIFT_uint( nrg, nrg_tmp, shft );
60 }
61 silk_assert( nrg >= 0 );
62 /* Make sure the result will fit in a 32-bit signed integer with two bits
63 of headroom. */
64 shft = silk_max_32(0, shft+3 - silk_CLZ32(nrg));
65 nrg = 0;
66 for( i = 0 ; i < len - 1; i += 2 ) {
67 nrg_tmp = silk_SMULBB( x[ i ], x[ i ] );
68 nrg_tmp = silk_SMLABB_ovflw( nrg_tmp, x[ i + 1 ], x[ i + 1 ] );
69 nrg = (opus_int32)silk_ADD_RSHIFT_uint( nrg, nrg_tmp, shft );
70 }
71 if( i < len ) {
71 /* One sample left to process */ 72 /* One sample left to process */
72 nrg_tmp = silk_SMULBB( x[ i ], x[ i ] ); 73 nrg_tmp = silk_SMULBB( x[ i ], x[ i ] );
73 nrg = (opus_int32)silk_ADD_RSHIFT_uint( nrg, nrg_tmp, shft ); 74 nrg = (opus_int32)silk_ADD_RSHIFT_uint( nrg, nrg_tmp, shft );
74 } 75 }
75 76
76 /* Make sure to have at least one extra leading zero (two leading zeros in t otal) */ 77 silk_assert( nrg >= 0 );
77 if( nrg & 0xC0000000 ) {
78 nrg = silk_RSHIFT_uint( (opus_uint32)nrg, 2 );
79 shft += 2;
80 }
81 78
82 /* Output arguments */ 79 /* Output arguments */
83 *shift = shft; 80 *shift = shft;
84 *energy = nrg; 81 *energy = nrg;
85 } 82 }
86 83
OLDNEW
« no previous file with comments | « third_party/opus/src/silk/structs.h ('k') | third_party/opus/src/silk/tables.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698