annotate src/opus-1.3/silk/fixed/residual_energy16_FIX.c @ 83:ae30d91d2ffe

Replace these with versions built using an older toolset (so as to avoid ABI compatibilities when linking on Ubuntu 14.04 for packaging purposes)
author Chris Cannam
date Fri, 07 Feb 2020 11:51:13 +0000
parents 7aeed7906520
children
rev   line source
Chris@69 1 /***********************************************************************
Chris@69 2 Copyright (c) 2006-2011, Skype Limited. All rights reserved.
Chris@69 3 Redistribution and use in source and binary forms, with or without
Chris@69 4 modification, are permitted provided that the following conditions
Chris@69 5 are met:
Chris@69 6 - Redistributions of source code must retain the above copyright notice,
Chris@69 7 this list of conditions and the following disclaimer.
Chris@69 8 - Redistributions in binary form must reproduce the above copyright
Chris@69 9 notice, this list of conditions and the following disclaimer in the
Chris@69 10 documentation and/or other materials provided with the distribution.
Chris@69 11 - Neither the name of Internet Society, IETF or IETF Trust, nor the
Chris@69 12 names of specific contributors, may be used to endorse or promote
Chris@69 13 products derived from this software without specific prior written
Chris@69 14 permission.
Chris@69 15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Chris@69 16 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Chris@69 17 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Chris@69 18 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
Chris@69 19 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
Chris@69 20 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
Chris@69 21 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
Chris@69 22 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
Chris@69 23 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
Chris@69 24 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
Chris@69 25 POSSIBILITY OF SUCH DAMAGE.
Chris@69 26 ***********************************************************************/
Chris@69 27
Chris@69 28 #ifdef HAVE_CONFIG_H
Chris@69 29 #include "config.h"
Chris@69 30 #endif
Chris@69 31
Chris@69 32 #include "main_FIX.h"
Chris@69 33
Chris@69 34 /* Residual energy: nrg = wxx - 2 * wXx * c + c' * wXX * c */
Chris@69 35 opus_int32 silk_residual_energy16_covar_FIX(
Chris@69 36 const opus_int16 *c, /* I Prediction vector */
Chris@69 37 const opus_int32 *wXX, /* I Correlation matrix */
Chris@69 38 const opus_int32 *wXx, /* I Correlation vector */
Chris@69 39 opus_int32 wxx, /* I Signal energy */
Chris@69 40 opus_int D, /* I Dimension */
Chris@69 41 opus_int cQ /* I Q value for c vector 0 - 15 */
Chris@69 42 )
Chris@69 43 {
Chris@69 44 opus_int i, j, lshifts, Qxtra;
Chris@69 45 opus_int32 c_max, w_max, tmp, tmp2, nrg;
Chris@69 46 opus_int cn[ MAX_MATRIX_SIZE ];
Chris@69 47 const opus_int32 *pRow;
Chris@69 48
Chris@69 49 /* Safety checks */
Chris@69 50 celt_assert( D >= 0 );
Chris@69 51 celt_assert( D <= 16 );
Chris@69 52 celt_assert( cQ > 0 );
Chris@69 53 celt_assert( cQ < 16 );
Chris@69 54
Chris@69 55 lshifts = 16 - cQ;
Chris@69 56 Qxtra = lshifts;
Chris@69 57
Chris@69 58 c_max = 0;
Chris@69 59 for( i = 0; i < D; i++ ) {
Chris@69 60 c_max = silk_max_32( c_max, silk_abs( (opus_int32)c[ i ] ) );
Chris@69 61 }
Chris@69 62 Qxtra = silk_min_int( Qxtra, silk_CLZ32( c_max ) - 17 );
Chris@69 63
Chris@69 64 w_max = silk_max_32( wXX[ 0 ], wXX[ D * D - 1 ] );
Chris@69 65 Qxtra = silk_min_int( Qxtra, silk_CLZ32( silk_MUL( D, silk_RSHIFT( silk_SMULWB( w_max, c_max ), 4 ) ) ) - 5 );
Chris@69 66 Qxtra = silk_max_int( Qxtra, 0 );
Chris@69 67 for( i = 0; i < D; i++ ) {
Chris@69 68 cn[ i ] = silk_LSHIFT( ( opus_int )c[ i ], Qxtra );
Chris@69 69 silk_assert( silk_abs(cn[i]) <= ( silk_int16_MAX + 1 ) ); /* Check that silk_SMLAWB can be used */
Chris@69 70 }
Chris@69 71 lshifts -= Qxtra;
Chris@69 72
Chris@69 73 /* Compute wxx - 2 * wXx * c */
Chris@69 74 tmp = 0;
Chris@69 75 for( i = 0; i < D; i++ ) {
Chris@69 76 tmp = silk_SMLAWB( tmp, wXx[ i ], cn[ i ] );
Chris@69 77 }
Chris@69 78 nrg = silk_RSHIFT( wxx, 1 + lshifts ) - tmp; /* Q: -lshifts - 1 */
Chris@69 79
Chris@69 80 /* Add c' * wXX * c, assuming wXX is symmetric */
Chris@69 81 tmp2 = 0;
Chris@69 82 for( i = 0; i < D; i++ ) {
Chris@69 83 tmp = 0;
Chris@69 84 pRow = &wXX[ i * D ];
Chris@69 85 for( j = i + 1; j < D; j++ ) {
Chris@69 86 tmp = silk_SMLAWB( tmp, pRow[ j ], cn[ j ] );
Chris@69 87 }
Chris@69 88 tmp = silk_SMLAWB( tmp, silk_RSHIFT( pRow[ i ], 1 ), cn[ i ] );
Chris@69 89 tmp2 = silk_SMLAWB( tmp2, tmp, cn[ i ] );
Chris@69 90 }
Chris@69 91 nrg = silk_ADD_LSHIFT32( nrg, tmp2, lshifts ); /* Q: -lshifts - 1 */
Chris@69 92
Chris@69 93 /* Keep one bit free always, because we add them for LSF interpolation */
Chris@69 94 if( nrg < 1 ) {
Chris@69 95 nrg = 1;
Chris@69 96 } else if( nrg > silk_RSHIFT( silk_int32_MAX, lshifts + 2 ) ) {
Chris@69 97 nrg = silk_int32_MAX >> 1;
Chris@69 98 } else {
Chris@69 99 nrg = silk_LSHIFT( nrg, lshifts + 1 ); /* Q0 */
Chris@69 100 }
Chris@69 101 return nrg;
Chris@69 102
Chris@69 103 }