12bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian/***********************************************************************
22bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh VenkatasubramanianCopyright (c) 2006-2011, Skype Limited. All rights reserved.
32bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh VenkatasubramanianRedistribution and use in source and binary forms, with or without
42bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanianmodification, are permitted provided that the following conditions
52bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanianare met:
62bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian- Redistributions of source code must retain the above copyright notice,
72bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanianthis list of conditions and the following disclaimer.
82bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian- Redistributions in binary form must reproduce the above copyright
92bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramaniannotice, this list of conditions and the following disclaimer in the
102bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramaniandocumentation and/or other materials provided with the distribution.
112bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian- Neither the name of Internet Society, IETF or IETF Trust, nor the
122bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramaniannames of specific contributors, may be used to endorse or promote
132bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanianproducts derived from this software without specific prior written
142bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanianpermission.
152bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh VenkatasubramanianTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
162bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh VenkatasubramanianAND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
172bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh VenkatasubramanianIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
182bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh VenkatasubramanianARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
192bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh VenkatasubramanianLIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
202bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh VenkatasubramanianCONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
212bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh VenkatasubramanianSUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
222bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh VenkatasubramanianINTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
232bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh VenkatasubramanianCONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
242bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh VenkatasubramanianARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
252bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh VenkatasubramanianPOSSIBILITY OF SUCH DAMAGE.
262bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian***********************************************************************/
272bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian
282bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian#ifdef HAVE_CONFIG_H
292bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian#include "config.h"
302bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian#endif
312bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian
322bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian#include "main_FIX.h"
332bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian
34c91ee5b5642fcc4969150f73d5f6848f88bf1638flim#if defined(MIPSr1_ASM)
35c91ee5b5642fcc4969150f73d5f6848f88bf1638flim#include "mips/warped_autocorrelation_FIX_mipsr1.h"
36c91ee5b5642fcc4969150f73d5f6848f88bf1638flim#endif
37c91ee5b5642fcc4969150f73d5f6848f88bf1638flim
38c91ee5b5642fcc4969150f73d5f6848f88bf1638flim
392bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian/* Autocorrelations for a warped frequency axis */
400c2090c324e4f2ba2a8621c8b083559bab74c7c5Felicia Limvoid silk_warped_autocorrelation_FIX_c(
412bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian          opus_int32                *corr,                                  /* O    Result [order + 1]                                                          */
422bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian          opus_int                  *scale,                                 /* O    Scaling of the correlation vector                                           */
432bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian    const opus_int16                *input,                                 /* I    Input data to correlate                                                     */
442bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian    const opus_int                  warping_Q16,                            /* I    Warping coefficient                                                         */
452bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian    const opus_int                  length,                                 /* I    Length of input                                                             */
462bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian    const opus_int                  order                                   /* I    Correlation order (even)                                                    */
472bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian)
482bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian{
492bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian    opus_int   n, i, lsh;
502bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian    opus_int32 tmp1_QS, tmp2_QS;
512bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian    opus_int32 state_QS[ MAX_SHAPE_LPC_ORDER + 1 ] = { 0 };
522bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian    opus_int64 corr_QC[  MAX_SHAPE_LPC_ORDER + 1 ] = { 0 };
532bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian
542bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian    /* Order must be even */
552bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian    silk_assert( ( order & 1 ) == 0 );
562bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian    silk_assert( 2 * QS - QC >= 0 );
572bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian
582bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian    /* Loop over samples */
592bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian    for( n = 0; n < length; n++ ) {
602bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian        tmp1_QS = silk_LSHIFT32( (opus_int32)input[ n ], QS );
612bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian        /* Loop over allpass sections */
622bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian        for( i = 0; i < order; i += 2 ) {
632bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian            /* Output of allpass section */
642bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian            tmp2_QS = silk_SMLAWB( state_QS[ i ], state_QS[ i + 1 ] - tmp1_QS, warping_Q16 );
652bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian            state_QS[ i ]  = tmp1_QS;
662bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian            corr_QC[  i ] += silk_RSHIFT64( silk_SMULL( tmp1_QS, state_QS[ 0 ] ), 2 * QS - QC );
672bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian            /* Output of allpass section */
682bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian            tmp1_QS = silk_SMLAWB( state_QS[ i + 1 ], state_QS[ i + 2 ] - tmp2_QS, warping_Q16 );
692bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian            state_QS[ i + 1 ]  = tmp2_QS;
702bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian            corr_QC[  i + 1 ] += silk_RSHIFT64( silk_SMULL( tmp2_QS, state_QS[ 0 ] ), 2 * QS - QC );
712bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian        }
722bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian        state_QS[ order ] = tmp1_QS;
732bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian        corr_QC[  order ] += silk_RSHIFT64( silk_SMULL( tmp1_QS, state_QS[ 0 ] ), 2 * QS - QC );
742bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian    }
752bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian
762bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian    lsh = silk_CLZ64( corr_QC[ 0 ] ) - 35;
772bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian    lsh = silk_LIMIT( lsh, -12 - QC, 30 - QC );
782bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian    *scale = -( QC + lsh );
792bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian    silk_assert( *scale >= -30 && *scale <= 12 );
802bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian    if( lsh >= 0 ) {
812bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian        for( i = 0; i < order + 1; i++ ) {
822bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian            corr[ i ] = (opus_int32)silk_CHECK_FIT32( silk_LSHIFT64( corr_QC[ i ], lsh ) );
832bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian        }
842bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian    } else {
852bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian        for( i = 0; i < order + 1; i++ ) {
862bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian            corr[ i ] = (opus_int32)silk_CHECK_FIT32( silk_RSHIFT64( corr_QC[ i ], -lsh ) );
872bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian        }
882bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian    }
892bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian    silk_assert( corr_QC[ 0 ] >= 0 ); /* If breaking, decrease QC*/
902bd8b54017b5320bc0c1df9bf86f4cdc9f8db242Vignesh Venkatasubramanian}
91