| OLD | NEW |
| 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. |
| 11 - Neither the name of Internet Society, IETF or IETF Trust, nor the | 11 - Neither the name of Internet Society, IETF or IETF Trust, nor the |
| 12 names of specific contributors, may be used to endorse or promote | 12 names of specific contributors, may be used to endorse or promote |
| 13 products derived from this software without specific prior written | 13 products derived from this software without specific prior written |
| 14 permission. | 14 permission. |
| 15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” | 15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 16 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 16 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 17 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 17 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 18 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | 18 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 19 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 19 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 20 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 20 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 21 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 21 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 22 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 22 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 23 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 23 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 24 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 24 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 25 POSSIBILITY OF SUCH DAMAGE. | 25 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 "main.h" | 32 #include "main.h" |
| 33 #include "stack_alloc.h" |
| 33 | 34 |
| 34 /* Silk VAD noise level estimation */ | 35 /* Silk VAD noise level estimation */ |
| 35 static inline void silk_VAD_GetNoiseLevels( | 36 static inline void silk_VAD_GetNoiseLevels( |
| 36 const opus_int32 pX[ VAD_N_BANDS ], /* I subband energies
*/ | 37 const opus_int32 pX[ VAD_N_BANDS ], /* I subband energies
*/ |
| 37 silk_VAD_state *psSilk_VAD /* I/O Pointer to Silk VAD
state */ | 38 silk_VAD_state *psSilk_VAD /* I/O Pointer to Silk VAD
state */ |
| 38 ); | 39 ); |
| 39 | 40 |
| 40 /**********************************/ | 41 /**********************************/ |
| 41 /* Initialization of the Silk VAD */ | 42 /* Initialization of the Silk VAD */ |
| 42 /**********************************/ | 43 /**********************************/ |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 | 76 |
| 76 /***************************************/ | 77 /***************************************/ |
| 77 /* Get the speech activity level in Q8 */ | 78 /* Get the speech activity level in Q8 */ |
| 78 /***************************************/ | 79 /***************************************/ |
| 79 opus_int silk_VAD_GetSA_Q8( /* O Return v
alue, 0 if success */ | 80 opus_int silk_VAD_GetSA_Q8( /* O Return v
alue, 0 if success */ |
| 80 silk_encoder_state *psEncC, /* I/O Encoder
state */ | 81 silk_encoder_state *psEncC, /* I/O Encoder
state */ |
| 81 const opus_int16 pIn[] /* I PCM inpu
t */ | 82 const opus_int16 pIn[] /* I PCM inpu
t */ |
| 82 ) | 83 ) |
| 83 { | 84 { |
| 84 opus_int SA_Q15, pSNR_dB_Q7, input_tilt; | 85 opus_int SA_Q15, pSNR_dB_Q7, input_tilt; |
| 85 opus_int decimated_framelength, dec_subframe_length, dec_subframe_offset,
SNR_Q7, i, b, s; | 86 opus_int decimated_framelength1, decimated_framelength2; |
| 87 opus_int decimated_framelength; |
| 88 opus_int dec_subframe_length, dec_subframe_offset, SNR_Q7, i, b, s; |
| 86 opus_int32 sumSquared, smooth_coef_Q16; | 89 opus_int32 sumSquared, smooth_coef_Q16; |
| 87 opus_int16 HPstateTmp; | 90 opus_int16 HPstateTmp; |
| 88 opus_int16 X[ VAD_N_BANDS ][ MAX_FRAME_LENGTH / 2 ]; | 91 VARDECL( opus_int16, X ); |
| 89 opus_int32 Xnrg[ VAD_N_BANDS ]; | 92 opus_int32 Xnrg[ VAD_N_BANDS ]; |
| 90 opus_int32 NrgToNoiseRatio_Q8[ VAD_N_BANDS ]; | 93 opus_int32 NrgToNoiseRatio_Q8[ VAD_N_BANDS ]; |
| 91 opus_int32 speech_nrg, x_tmp; | 94 opus_int32 speech_nrg, x_tmp; |
| 95 opus_int X_offset[ VAD_N_BANDS ]; |
| 92 opus_int ret = 0; | 96 opus_int ret = 0; |
| 93 silk_VAD_state *psSilk_VAD = &psEncC->sVAD; | 97 silk_VAD_state *psSilk_VAD = &psEncC->sVAD; |
| 98 SAVE_STACK; |
| 94 | 99 |
| 95 /* Safety checks */ | 100 /* Safety checks */ |
| 96 silk_assert( VAD_N_BANDS == 4 ); | 101 silk_assert( VAD_N_BANDS == 4 ); |
| 97 silk_assert( MAX_FRAME_LENGTH >= psEncC->frame_length ); | 102 silk_assert( MAX_FRAME_LENGTH >= psEncC->frame_length ); |
| 98 silk_assert( psEncC->frame_length <= 512 ); | 103 silk_assert( psEncC->frame_length <= 512 ); |
| 99 silk_assert( psEncC->frame_length == 8 * silk_RSHIFT( psEncC->frame_length,
3 ) ); | 104 silk_assert( psEncC->frame_length == 8 * silk_RSHIFT( psEncC->frame_length,
3 ) ); |
| 100 | 105 |
| 101 /***********************/ | 106 /***********************/ |
| 102 /* Filter and Decimate */ | 107 /* Filter and Decimate */ |
| 103 /***********************/ | 108 /***********************/ |
| 109 decimated_framelength1 = silk_RSHIFT( psEncC->frame_length, 1 ); |
| 110 decimated_framelength2 = silk_RSHIFT( psEncC->frame_length, 2 ); |
| 111 decimated_framelength = silk_RSHIFT( psEncC->frame_length, 3 ); |
| 112 /* Decimate into 4 bands: |
| 113 0 L 3L L 3L 5L |
| 114 - -- - -- -- |
| 115 8 8 2 4 4 |
| 116 |
| 117 [0-1 kHz| temp. |1-2 kHz| 2-4 kHz | 4-8 kHz | |
| 118 |
| 119 They're arranged to allow the minimal ( frame_length / 4 ) extra |
| 120 scratch space during the downsampling process */ |
| 121 X_offset[ 0 ] = 0; |
| 122 X_offset[ 1 ] = decimated_framelength + decimated_framelength2; |
| 123 X_offset[ 2 ] = X_offset[ 1 ] + decimated_framelength; |
| 124 X_offset[ 3 ] = X_offset[ 2 ] + decimated_framelength2; |
| 125 ALLOC( X, X_offset[ 3 ] + decimated_framelength1, opus_int16 ); |
| 126 |
| 104 /* 0-8 kHz to 0-4 kHz and 4-8 kHz */ | 127 /* 0-8 kHz to 0-4 kHz and 4-8 kHz */ |
| 105 silk_ana_filt_bank_1( pIn, &psSilk_VAD->AnaState[ 0 ], &X[ 0 ][ 0
], &X[ 3 ][ 0 ], psEncC->frame_length ); | 128 silk_ana_filt_bank_1( pIn, &psSilk_VAD->AnaState[ 0 ], |
| 129 X, &X[ X_offset[ 3 ] ], psEncC->frame_length ); |
| 106 | 130 |
| 107 /* 0-4 kHz to 0-2 kHz and 2-4 kHz */ | 131 /* 0-4 kHz to 0-2 kHz and 2-4 kHz */ |
| 108 silk_ana_filt_bank_1( &X[ 0 ][ 0 ], &psSilk_VAD->AnaState1[ 0 ], &X[ 0 ][ 0
], &X[ 2 ][ 0 ], silk_RSHIFT( psEncC->frame_length, 1 ) ); | 132 silk_ana_filt_bank_1( X, &psSilk_VAD->AnaState1[ 0 ], |
| 133 X, &X[ X_offset[ 2 ] ], decimated_framelength1 ); |
| 109 | 134 |
| 110 /* 0-2 kHz to 0-1 kHz and 1-2 kHz */ | 135 /* 0-2 kHz to 0-1 kHz and 1-2 kHz */ |
| 111 silk_ana_filt_bank_1( &X[ 0 ][ 0 ], &psSilk_VAD->AnaState2[ 0 ], &X[ 0 ][ 0
], &X[ 1 ][ 0 ], silk_RSHIFT( psEncC->frame_length, 2 ) ); | 136 silk_ana_filt_bank_1( X, &psSilk_VAD->AnaState2[ 0 ], |
| 137 X, &X[ X_offset[ 1 ] ], decimated_framelength2 ); |
| 112 | 138 |
| 113 /*********************************************/ | 139 /*********************************************/ |
| 114 /* HP filter on lowest band (differentiator) */ | 140 /* HP filter on lowest band (differentiator) */ |
| 115 /*********************************************/ | 141 /*********************************************/ |
| 116 decimated_framelength = silk_RSHIFT( psEncC->frame_length, 3 ); | 142 X[ decimated_framelength - 1 ] = silk_RSHIFT( X[ decimated_framelength - 1 ]
, 1 ); |
| 117 X[ 0 ][ decimated_framelength - 1 ] = silk_RSHIFT( X[ 0 ][ decimated_framele
ngth - 1 ], 1 ); | 143 HPstateTmp = X[ decimated_framelength - 1 ]; |
| 118 HPstateTmp = X[ 0 ][ decimated_framelength - 1 ]; | |
| 119 for( i = decimated_framelength - 1; i > 0; i-- ) { | 144 for( i = decimated_framelength - 1; i > 0; i-- ) { |
| 120 X[ 0 ][ i - 1 ] = silk_RSHIFT( X[ 0 ][ i - 1 ], 1 ); | 145 X[ i - 1 ] = silk_RSHIFT( X[ i - 1 ], 1 ); |
| 121 X[ 0 ][ i ] -= X[ 0 ][ i - 1 ]; | 146 X[ i ] -= X[ i - 1 ]; |
| 122 } | 147 } |
| 123 X[ 0 ][ 0 ] -= psSilk_VAD->HPstate; | 148 X[ 0 ] -= psSilk_VAD->HPstate; |
| 124 psSilk_VAD->HPstate = HPstateTmp; | 149 psSilk_VAD->HPstate = HPstateTmp; |
| 125 | 150 |
| 126 /*************************************/ | 151 /*************************************/ |
| 127 /* Calculate the energy in each band */ | 152 /* Calculate the energy in each band */ |
| 128 /*************************************/ | 153 /*************************************/ |
| 129 for( b = 0; b < VAD_N_BANDS; b++ ) { | 154 for( b = 0; b < VAD_N_BANDS; b++ ) { |
| 130 /* Find the decimated framelength in the non-uniformly divided bands */ | 155 /* Find the decimated framelength in the non-uniformly divided bands */ |
| 131 decimated_framelength = silk_RSHIFT( psEncC->frame_length, silk_min_int(
VAD_N_BANDS - b, VAD_N_BANDS - 1 ) ); | 156 decimated_framelength = silk_RSHIFT( psEncC->frame_length, silk_min_int(
VAD_N_BANDS - b, VAD_N_BANDS - 1 ) ); |
| 132 | 157 |
| 133 /* Split length into subframe lengths */ | 158 /* Split length into subframe lengths */ |
| 134 dec_subframe_length = silk_RSHIFT( decimated_framelength, VAD_INTERNAL_S
UBFRAMES_LOG2 ); | 159 dec_subframe_length = silk_RSHIFT( decimated_framelength, VAD_INTERNAL_S
UBFRAMES_LOG2 ); |
| 135 dec_subframe_offset = 0; | 160 dec_subframe_offset = 0; |
| 136 | 161 |
| 137 /* Compute energy per sub-frame */ | 162 /* Compute energy per sub-frame */ |
| 138 /* initialize with summed energy of last subframe */ | 163 /* initialize with summed energy of last subframe */ |
| 139 Xnrg[ b ] = psSilk_VAD->XnrgSubfr[ b ]; | 164 Xnrg[ b ] = psSilk_VAD->XnrgSubfr[ b ]; |
| 140 for( s = 0; s < VAD_INTERNAL_SUBFRAMES; s++ ) { | 165 for( s = 0; s < VAD_INTERNAL_SUBFRAMES; s++ ) { |
| 141 sumSquared = 0; | 166 sumSquared = 0; |
| 142 for( i = 0; i < dec_subframe_length; i++ ) { | 167 for( i = 0; i < dec_subframe_length; i++ ) { |
| 143 /* The energy will be less than dec_subframe_length * ( silk_int
16_MIN / 8 ) ^ 2. */ | 168 /* The energy will be less than dec_subframe_length * ( silk_int
16_MIN / 8 ) ^ 2. */ |
| 144 /* Therefore we can accumulate with no risk of overflow (unless
dec_subframe_length > 128) */ | 169 /* Therefore we can accumulate with no risk of overflow (unless
dec_subframe_length > 128) */ |
| 145 x_tmp = silk_RSHIFT( X[ b ][ i + dec_subframe_offset ], 3 ); | 170 x_tmp = silk_RSHIFT( |
| 171 X[ X_offset[ b ] + i + dec_subframe_offset ], 3 ); |
| 146 sumSquared = silk_SMLABB( sumSquared, x_tmp, x_tmp ); | 172 sumSquared = silk_SMLABB( sumSquared, x_tmp, x_tmp ); |
| 147 | 173 |
| 148 /* Safety check */ | 174 /* Safety check */ |
| 149 silk_assert( sumSquared >= 0 ); | 175 silk_assert( sumSquared >= 0 ); |
| 150 } | 176 } |
| 151 | 177 |
| 152 /* Add/saturate summed energy of current subframe */ | 178 /* Add/saturate summed energy of current subframe */ |
| 153 if( s < VAD_INTERNAL_SUBFRAMES - 1 ) { | 179 if( s < VAD_INTERNAL_SUBFRAMES - 1 ) { |
| 154 Xnrg[ b ] = silk_ADD_POS_SAT32( Xnrg[ b ], sumSquared ); | 180 Xnrg[ b ] = silk_ADD_POS_SAT32( Xnrg[ b ], sumSquared ); |
| 155 } else { | 181 } else { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 /* compute smoothed energy-to-noise ratio per band */ | 282 /* compute smoothed energy-to-noise ratio per band */ |
| 257 psSilk_VAD->NrgRatioSmth_Q8[ b ] = silk_SMLAWB( psSilk_VAD->NrgRatioSmth
_Q8[ b ], | 283 psSilk_VAD->NrgRatioSmth_Q8[ b ] = silk_SMLAWB( psSilk_VAD->NrgRatioSmth
_Q8[ b ], |
| 258 NrgToNoiseRatio_Q8[ b ] - psSilk_VAD->NrgRatioSmth_Q8[ b ], smooth_c
oef_Q16 ); | 284 NrgToNoiseRatio_Q8[ b ] - psSilk_VAD->NrgRatioSmth_Q8[ b ], smooth_c
oef_Q16 ); |
| 259 | 285 |
| 260 /* signal to noise ratio in dB per band */ | 286 /* signal to noise ratio in dB per band */ |
| 261 SNR_Q7 = 3 * ( silk_lin2log( psSilk_VAD->NrgRatioSmth_Q8[b] ) - 8 * 128
); | 287 SNR_Q7 = 3 * ( silk_lin2log( psSilk_VAD->NrgRatioSmth_Q8[b] ) - 8 * 128
); |
| 262 /* quality = sigmoid( 0.25 * ( SNR_dB - 16 ) ); */ | 288 /* quality = sigmoid( 0.25 * ( SNR_dB - 16 ) ); */ |
| 263 psEncC->input_quality_bands_Q15[ b ] = silk_sigm_Q15( silk_RSHIFT( SNR_Q
7 - 16 * 128, 4 ) ); | 289 psEncC->input_quality_bands_Q15[ b ] = silk_sigm_Q15( silk_RSHIFT( SNR_Q
7 - 16 * 128, 4 ) ); |
| 264 } | 290 } |
| 265 | 291 |
| 292 RESTORE_STACK; |
| 266 return( ret ); | 293 return( ret ); |
| 267 } | 294 } |
| 268 | 295 |
| 269 /**************************/ | 296 /**************************/ |
| 270 /* Noise level estimation */ | 297 /* Noise level estimation */ |
| 271 /**************************/ | 298 /**************************/ |
| 272 static inline void silk_VAD_GetNoiseLevels( | 299 static inline void silk_VAD_GetNoiseLevels( |
| 273 const opus_int32 pX[ VAD_N_BANDS ], /* I subband energies
*/ | 300 const opus_int32 pX[ VAD_N_BANDS ], /* I subband energies
*/ |
| 274 silk_VAD_state *psSilk_VAD /* I/O Pointer to Silk VAD
state */ | 301 silk_VAD_state *psSilk_VAD /* I/O Pointer to Silk VAD
state */ |
| 275 ) | 302 ) |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 /* Limit noise levels (guarantee 7 bits of head room) */ | 348 /* Limit noise levels (guarantee 7 bits of head room) */ |
| 322 nl = silk_min( nl, 0x00FFFFFF ); | 349 nl = silk_min( nl, 0x00FFFFFF ); |
| 323 | 350 |
| 324 /* Store as part of state */ | 351 /* Store as part of state */ |
| 325 psSilk_VAD->NL[ k ] = nl; | 352 psSilk_VAD->NL[ k ] = nl; |
| 326 } | 353 } |
| 327 | 354 |
| 328 /* Increment frame counter */ | 355 /* Increment frame counter */ |
| 329 psSilk_VAD->counter++; | 356 psSilk_VAD->counter++; |
| 330 } | 357 } |
| OLD | NEW |