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

Side by Side Diff: silk/x86/VAD_sse.c

Issue 882843002: Update to opus-HEAD-66611f1. (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/opus.git@master
Patch Set: Add the contents of Makefile.mips back. Created 5 years, 10 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 | « silk/x86/SigProc_FIX_sse.h ('k') | silk/x86/VQ_WMat_EC_sse.c » ('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 /* Copyright (c) 2014, Cisco Systems, INC
2 Copyright (c) 2006-2011, Skype Limited. All rights reserved. 2 Written by XiangMingZhu WeiZhou MinPeng YanWang
3 Redistribution and use in source and binary forms, with or without 3
4 modification, are permitted provided that the following conditions 4 Redistribution and use in source and binary forms, with or without
5 are met: 5 modification, are permitted provided that the following conditions
6 - Redistributions of source code must retain the above copyright notice, 6 are met:
7 this list of conditions and the following disclaimer. 7
8 - Redistributions in binary form must reproduce the above copyright 8 - Redistributions of source code must retain 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.
10 documentation and/or other materials provided with the distribution. 10
11 - Neither the name of Internet Society, IETF or IETF Trust, nor the 11 - Redistributions in binary form must reproduce the above copyright
12 names of specific contributors, may be used to endorse or promote 12 notice, this list of conditions and the following disclaimer in the
13 products derived from this software without specific prior written 13 documentation and/or other materials provided with the distribution.
14 permission. 14
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 18 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
19 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 POSSIBILITY OF SUCH DAMAGE. 25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 ***********************************************************************/ 26 */
27 27
28 #ifdef HAVE_CONFIG_H 28 #ifdef HAVE_CONFIG_H
29 #include "config.h" 29 #include "config.h"
30 #endif 30 #endif
31 31
32 #include <xmmintrin.h>
33 #include <emmintrin.h>
34 #include <smmintrin.h>
35
32 #include "main.h" 36 #include "main.h"
33 #include "stack_alloc.h" 37 #include "stack_alloc.h"
34 38
35 /* Silk VAD noise level estimation */
36 static OPUS_INLINE void silk_VAD_GetNoiseLevels(
37 const opus_int32 pX[ VAD_N_BANDS ], /* I subband energies */
38 silk_VAD_state *psSilk_VAD /* I/O Pointer to Silk VAD state */
39 );
40
41 /**********************************/
42 /* Initialization of the Silk VAD */
43 /**********************************/
44 opus_int silk_VAD_Init( /* O Return v alue, 0 if success */
45 silk_VAD_state *psSilk_VAD /* I/O Pointer to Silk VAD state */
46 )
47 {
48 opus_int b, ret = 0;
49
50 /* reset state memory */
51 silk_memset( psSilk_VAD, 0, sizeof( silk_VAD_state ) );
52
53 /* init noise levels */
54 /* Initialize array with approx pink noise levels (psd proportional to inver se of frequency) */
55 for( b = 0; b < VAD_N_BANDS; b++ ) {
56 psSilk_VAD->NoiseLevelBias[ b ] = silk_max_32( silk_DIV32_16( VAD_NOISE_ LEVELS_BIAS, b + 1 ), 1 );
57 }
58
59 /* Initialize state */
60 for( b = 0; b < VAD_N_BANDS; b++ ) {
61 psSilk_VAD->NL[ b ] = silk_MUL( 100, psSilk_VAD->NoiseLevelBias[ b ] );
62 psSilk_VAD->inv_NL[ b ] = silk_DIV32( silk_int32_MAX, psSilk_VAD->NL[ b ] );
63 }
64 psSilk_VAD->counter = 15;
65
66 /* init smoothed energy-to-noise ratio*/
67 for( b = 0; b < VAD_N_BANDS; b++ ) {
68 psSilk_VAD->NrgRatioSmth_Q8[ b ] = 100 * 256; /* 100 * 256 --> 20 dB SNR */
69 }
70
71 return( ret );
72 }
73
74 /* Weighting factors for tilt measure */ 39 /* Weighting factors for tilt measure */
75 static const opus_int32 tiltWeights[ VAD_N_BANDS ] = { 30000, 6000, -12000, -120 00 }; 40 static const opus_int32 tiltWeights[ VAD_N_BANDS ] = { 30000, 6000, -12000, -120 00 };
76 41
77 /***************************************/ 42 /***************************************/
78 /* Get the speech activity level in Q8 */ 43 /* Get the speech activity level in Q8 */
79 /***************************************/ 44 /***************************************/
80 opus_int silk_VAD_GetSA_Q8( /* O Return v alue, 0 if success */ 45 opus_int silk_VAD_GetSA_Q8_sse4_1( /* O Return value, 0 if s uccess */
81 silk_encoder_state *psEncC, /* I/O Encoder state */ 46 silk_encoder_state *psEncC, /* I/O Encoder state */
82 const opus_int16 pIn[] /* I PCM inpu t */ 47 const opus_int16 pIn[] /* I PCM input */
83 ) 48 )
84 { 49 {
85 opus_int SA_Q15, pSNR_dB_Q7, input_tilt; 50 opus_int SA_Q15, pSNR_dB_Q7, input_tilt;
86 opus_int decimated_framelength1, decimated_framelength2; 51 opus_int decimated_framelength1, decimated_framelength2;
87 opus_int decimated_framelength; 52 opus_int decimated_framelength;
88 opus_int dec_subframe_length, dec_subframe_offset, SNR_Q7, i, b, s; 53 opus_int dec_subframe_length, dec_subframe_offset, SNR_Q7, i, b, s;
89 opus_int32 sumSquared, smooth_coef_Q16; 54 opus_int32 sumSquared, smooth_coef_Q16;
90 opus_int16 HPstateTmp; 55 opus_int16 HPstateTmp;
91 VARDECL( opus_int16, X ); 56 VARDECL( opus_int16, X );
92 opus_int32 Xnrg[ VAD_N_BANDS ]; 57 opus_int32 Xnrg[ VAD_N_BANDS ];
93 opus_int32 NrgToNoiseRatio_Q8[ VAD_N_BANDS ]; 58 opus_int32 NrgToNoiseRatio_Q8[ VAD_N_BANDS ];
94 opus_int32 speech_nrg, x_tmp; 59 opus_int32 speech_nrg, x_tmp;
95 opus_int X_offset[ VAD_N_BANDS ]; 60 opus_int X_offset[ VAD_N_BANDS ];
96 opus_int ret = 0; 61 opus_int ret = 0;
97 silk_VAD_state *psSilk_VAD = &psEncC->sVAD; 62 silk_VAD_state *psSilk_VAD = &psEncC->sVAD;
63
98 SAVE_STACK; 64 SAVE_STACK;
99 65
100 /* Safety checks */ 66 /* Safety checks */
101 silk_assert( VAD_N_BANDS == 4 ); 67 silk_assert( VAD_N_BANDS == 4 );
102 silk_assert( MAX_FRAME_LENGTH >= psEncC->frame_length ); 68 silk_assert( MAX_FRAME_LENGTH >= psEncC->frame_length );
103 silk_assert( psEncC->frame_length <= 512 ); 69 silk_assert( psEncC->frame_length <= 512 );
104 silk_assert( psEncC->frame_length == 8 * silk_RSHIFT( psEncC->frame_length, 3 ) ); 70 silk_assert( psEncC->frame_length == 8 * silk_RSHIFT( psEncC->frame_length, 3 ) );
105 71
106 /***********************/ 72 /***********************/
107 /* Filter and Decimate */ 73 /* Filter and Decimate */
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 decimated_framelength = silk_RSHIFT( psEncC->frame_length, silk_min_int( VAD_N_BANDS - b, VAD_N_BANDS - 1 ) ); 122 decimated_framelength = silk_RSHIFT( psEncC->frame_length, silk_min_int( VAD_N_BANDS - b, VAD_N_BANDS - 1 ) );
157 123
158 /* Split length into subframe lengths */ 124 /* Split length into subframe lengths */
159 dec_subframe_length = silk_RSHIFT( decimated_framelength, VAD_INTERNAL_S UBFRAMES_LOG2 ); 125 dec_subframe_length = silk_RSHIFT( decimated_framelength, VAD_INTERNAL_S UBFRAMES_LOG2 );
160 dec_subframe_offset = 0; 126 dec_subframe_offset = 0;
161 127
162 /* Compute energy per sub-frame */ 128 /* Compute energy per sub-frame */
163 /* initialize with summed energy of last subframe */ 129 /* initialize with summed energy of last subframe */
164 Xnrg[ b ] = psSilk_VAD->XnrgSubfr[ b ]; 130 Xnrg[ b ] = psSilk_VAD->XnrgSubfr[ b ];
165 for( s = 0; s < VAD_INTERNAL_SUBFRAMES; s++ ) { 131 for( s = 0; s < VAD_INTERNAL_SUBFRAMES; s++ ) {
132 __m128i xmm_X, xmm_acc;
166 sumSquared = 0; 133 sumSquared = 0;
167 for( i = 0; i < dec_subframe_length; i++ ) { 134
135 xmm_acc = _mm_setzero_si128();
136
137 for( i = 0; i < dec_subframe_length - 7; i += 8 )
138 {
139 xmm_X = _mm_loadu_si128( (__m128i *)&(X[ X_offset[ b ] + i + d ec_subframe_offset ] ) );
140 xmm_X = _mm_srai_epi16( xmm_X, 3 );
141 xmm_X = _mm_madd_epi16( xmm_X, xmm_X );
142 xmm_acc = _mm_add_epi32( xmm_acc, xmm_X );
143 }
144
145 xmm_acc = _mm_add_epi32( xmm_acc, _mm_unpackhi_epi64( xmm_acc, xmm_a cc ) );
146 xmm_acc = _mm_add_epi32( xmm_acc, _mm_shufflelo_epi16( xmm_acc, 0x0E ) );
147
148 sumSquared += _mm_cvtsi128_si32( xmm_acc );
149
150 for( ; i < dec_subframe_length; i++ ) {
168 /* The energy will be less than dec_subframe_length * ( silk_int 16_MIN / 8 ) ^ 2. */ 151 /* The energy will be less than dec_subframe_length * ( silk_int 16_MIN / 8 ) ^ 2. */
169 /* Therefore we can accumulate with no risk of overflow (unless dec_subframe_length > 128) */ 152 /* Therefore we can accumulate with no risk of overflow (unless dec_subframe_length > 128) */
170 x_tmp = silk_RSHIFT( 153 x_tmp = silk_RSHIFT(
171 X[ X_offset[ b ] + i + dec_subframe_offset ], 3 ); 154 X[ X_offset[ b ] + i + dec_subframe_offset ], 3 );
172 sumSquared = silk_SMLABB( sumSquared, x_tmp, x_tmp ); 155 sumSquared = silk_SMLABB( sumSquared, x_tmp, x_tmp );
173 156
174 /* Safety check */ 157 /* Safety check */
175 silk_assert( sumSquared >= 0 ); 158 silk_assert( sumSquared >= 0 );
176 } 159 }
177 160
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 268
286 /* signal to noise ratio in dB per band */ 269 /* signal to noise ratio in dB per band */
287 SNR_Q7 = 3 * ( silk_lin2log( psSilk_VAD->NrgRatioSmth_Q8[b] ) - 8 * 128 ); 270 SNR_Q7 = 3 * ( silk_lin2log( psSilk_VAD->NrgRatioSmth_Q8[b] ) - 8 * 128 );
288 /* quality = sigmoid( 0.25 * ( SNR_dB - 16 ) ); */ 271 /* quality = sigmoid( 0.25 * ( SNR_dB - 16 ) ); */
289 psEncC->input_quality_bands_Q15[ b ] = silk_sigm_Q15( silk_RSHIFT( SNR_Q 7 - 16 * 128, 4 ) ); 272 psEncC->input_quality_bands_Q15[ b ] = silk_sigm_Q15( silk_RSHIFT( SNR_Q 7 - 16 * 128, 4 ) );
290 } 273 }
291 274
292 RESTORE_STACK; 275 RESTORE_STACK;
293 return( ret ); 276 return( ret );
294 } 277 }
295
296 /**************************/
297 /* Noise level estimation */
298 /**************************/
299 static OPUS_INLINE void silk_VAD_GetNoiseLevels(
300 const opus_int32 pX[ VAD_N_BANDS ], /* I subband energies */
301 silk_VAD_state *psSilk_VAD /* I/O Pointer to Silk VAD state */
302 )
303 {
304 opus_int k;
305 opus_int32 nl, nrg, inv_nrg;
306 opus_int coef, min_coef;
307
308 /* Initially faster smoothing */
309 if( psSilk_VAD->counter < 1000 ) { /* 1000 = 20 sec */
310 min_coef = silk_DIV32_16( silk_int16_MAX, silk_RSHIFT( psSilk_VAD->count er, 4 ) + 1 );
311 } else {
312 min_coef = 0;
313 }
314
315 for( k = 0; k < VAD_N_BANDS; k++ ) {
316 /* Get old noise level estimate for current band */
317 nl = psSilk_VAD->NL[ k ];
318 silk_assert( nl >= 0 );
319
320 /* Add bias */
321 nrg = silk_ADD_POS_SAT32( pX[ k ], psSilk_VAD->NoiseLevelBias[ k ] );
322 silk_assert( nrg > 0 );
323
324 /* Invert energies */
325 inv_nrg = silk_DIV32( silk_int32_MAX, nrg );
326 silk_assert( inv_nrg >= 0 );
327
328 /* Less update when subband energy is high */
329 if( nrg > silk_LSHIFT( nl, 3 ) ) {
330 coef = VAD_NOISE_LEVEL_SMOOTH_COEF_Q16 >> 3;
331 } else if( nrg < nl ) {
332 coef = VAD_NOISE_LEVEL_SMOOTH_COEF_Q16;
333 } else {
334 coef = silk_SMULWB( silk_SMULWW( inv_nrg, nl ), VAD_NOISE_LEVEL_SMOO TH_COEF_Q16 << 1 );
335 }
336
337 /* Initially faster smoothing */
338 coef = silk_max_int( coef, min_coef );
339
340 /* Smooth inverse energies */
341 psSilk_VAD->inv_NL[ k ] = silk_SMLAWB( psSilk_VAD->inv_NL[ k ], inv_nrg - psSilk_VAD->inv_NL[ k ], coef );
342 silk_assert( psSilk_VAD->inv_NL[ k ] >= 0 );
343
344 /* Compute noise level by inverting again */
345 nl = silk_DIV32( silk_int32_MAX, psSilk_VAD->inv_NL[ k ] );
346 silk_assert( nl >= 0 );
347
348 /* Limit noise levels (guarantee 7 bits of head room) */
349 nl = silk_min( nl, 0x00FFFFFF );
350
351 /* Store as part of state */
352 psSilk_VAD->NL[ k ] = nl;
353 }
354
355 /* Increment frame counter */
356 psSilk_VAD->counter++;
357 }
OLDNEW
« no previous file with comments | « silk/x86/SigProc_FIX_sse.h ('k') | silk/x86/VQ_WMat_EC_sse.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698