annotate src/opus-1.3/silk/NLSF2A.c @ 169:223a55898ab9 tip default

Add null config files
author Chris Cannam <cannam@all-day-breakfast.com>
date Mon, 02 Mar 2020 14:03:47 +0000
parents 4664ac0c1032
children
rev   line source
cannam@154 1 /***********************************************************************
cannam@154 2 Copyright (c) 2006-2011, Skype Limited. All rights reserved.
cannam@154 3 Redistribution and use in source and binary forms, with or without
cannam@154 4 modification, are permitted provided that the following conditions
cannam@154 5 are met:
cannam@154 6 - Redistributions of source code must retain the above copyright notice,
cannam@154 7 this list of conditions and the following disclaimer.
cannam@154 8 - Redistributions in binary form must reproduce the above copyright
cannam@154 9 notice, this list of conditions and the following disclaimer in the
cannam@154 10 documentation and/or other materials provided with the distribution.
cannam@154 11 - Neither the name of Internet Society, IETF or IETF Trust, nor the
cannam@154 12 names of specific contributors, may be used to endorse or promote
cannam@154 13 products derived from this software without specific prior written
cannam@154 14 permission.
cannam@154 15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
cannam@154 16 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
cannam@154 17 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
cannam@154 18 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
cannam@154 19 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
cannam@154 20 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
cannam@154 21 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
cannam@154 22 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
cannam@154 23 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
cannam@154 24 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
cannam@154 25 POSSIBILITY OF SUCH DAMAGE.
cannam@154 26 ***********************************************************************/
cannam@154 27
cannam@154 28 #ifdef HAVE_CONFIG_H
cannam@154 29 #include "config.h"
cannam@154 30 #endif
cannam@154 31
cannam@154 32 /* conversion between prediction filter coefficients and LSFs */
cannam@154 33 /* order should be even */
cannam@154 34 /* a piecewise linear approximation maps LSF <-> cos(LSF) */
cannam@154 35 /* therefore the result is not accurate LSFs, but the two */
cannam@154 36 /* functions are accurate inverses of each other */
cannam@154 37
cannam@154 38 #include "SigProc_FIX.h"
cannam@154 39 #include "tables.h"
cannam@154 40
cannam@154 41 #define QA 16
cannam@154 42
cannam@154 43 /* helper function for NLSF2A(..) */
cannam@154 44 static OPUS_INLINE void silk_NLSF2A_find_poly(
cannam@154 45 opus_int32 *out, /* O intermediate polynomial, QA [dd+1] */
cannam@154 46 const opus_int32 *cLSF, /* I vector of interleaved 2*cos(LSFs), QA [d] */
cannam@154 47 opus_int dd /* I polynomial order (= 1/2 * filter order) */
cannam@154 48 )
cannam@154 49 {
cannam@154 50 opus_int k, n;
cannam@154 51 opus_int32 ftmp;
cannam@154 52
cannam@154 53 out[0] = silk_LSHIFT( 1, QA );
cannam@154 54 out[1] = -cLSF[0];
cannam@154 55 for( k = 1; k < dd; k++ ) {
cannam@154 56 ftmp = cLSF[2*k]; /* QA*/
cannam@154 57 out[k+1] = silk_LSHIFT( out[k-1], 1 ) - (opus_int32)silk_RSHIFT_ROUND64( silk_SMULL( ftmp, out[k] ), QA );
cannam@154 58 for( n = k; n > 1; n-- ) {
cannam@154 59 out[n] += out[n-2] - (opus_int32)silk_RSHIFT_ROUND64( silk_SMULL( ftmp, out[n-1] ), QA );
cannam@154 60 }
cannam@154 61 out[1] -= ftmp;
cannam@154 62 }
cannam@154 63 }
cannam@154 64
cannam@154 65 /* compute whitening filter coefficients from normalized line spectral frequencies */
cannam@154 66 void silk_NLSF2A(
cannam@154 67 opus_int16 *a_Q12, /* O monic whitening filter coefficients in Q12, [ d ] */
cannam@154 68 const opus_int16 *NLSF, /* I normalized line spectral frequencies in Q15, [ d ] */
cannam@154 69 const opus_int d, /* I filter order (should be even) */
cannam@154 70 int arch /* I Run-time architecture */
cannam@154 71 )
cannam@154 72 {
cannam@154 73 /* This ordering was found to maximize quality. It improves numerical accuracy of
cannam@154 74 silk_NLSF2A_find_poly() compared to "standard" ordering. */
cannam@154 75 static const unsigned char ordering16[16] = {
cannam@154 76 0, 15, 8, 7, 4, 11, 12, 3, 2, 13, 10, 5, 6, 9, 14, 1
cannam@154 77 };
cannam@154 78 static const unsigned char ordering10[10] = {
cannam@154 79 0, 9, 6, 3, 4, 5, 8, 1, 2, 7
cannam@154 80 };
cannam@154 81 const unsigned char *ordering;
cannam@154 82 opus_int k, i, dd;
cannam@154 83 opus_int32 cos_LSF_QA[ SILK_MAX_ORDER_LPC ];
cannam@154 84 opus_int32 P[ SILK_MAX_ORDER_LPC / 2 + 1 ], Q[ SILK_MAX_ORDER_LPC / 2 + 1 ];
cannam@154 85 opus_int32 Ptmp, Qtmp, f_int, f_frac, cos_val, delta;
cannam@154 86 opus_int32 a32_QA1[ SILK_MAX_ORDER_LPC ];
cannam@154 87
cannam@154 88 silk_assert( LSF_COS_TAB_SZ_FIX == 128 );
cannam@154 89 celt_assert( d==10 || d==16 );
cannam@154 90
cannam@154 91 /* convert LSFs to 2*cos(LSF), using piecewise linear curve from table */
cannam@154 92 ordering = d == 16 ? ordering16 : ordering10;
cannam@154 93 for( k = 0; k < d; k++ ) {
cannam@154 94 silk_assert( NLSF[k] >= 0 );
cannam@154 95
cannam@154 96 /* f_int on a scale 0-127 (rounded down) */
cannam@154 97 f_int = silk_RSHIFT( NLSF[k], 15 - 7 );
cannam@154 98
cannam@154 99 /* f_frac, range: 0..255 */
cannam@154 100 f_frac = NLSF[k] - silk_LSHIFT( f_int, 15 - 7 );
cannam@154 101
cannam@154 102 silk_assert(f_int >= 0);
cannam@154 103 silk_assert(f_int < LSF_COS_TAB_SZ_FIX );
cannam@154 104
cannam@154 105 /* Read start and end value from table */
cannam@154 106 cos_val = silk_LSFCosTab_FIX_Q12[ f_int ]; /* Q12 */
cannam@154 107 delta = silk_LSFCosTab_FIX_Q12[ f_int + 1 ] - cos_val; /* Q12, with a range of 0..200 */
cannam@154 108
cannam@154 109 /* Linear interpolation */
cannam@154 110 cos_LSF_QA[ordering[k]] = silk_RSHIFT_ROUND( silk_LSHIFT( cos_val, 8 ) + silk_MUL( delta, f_frac ), 20 - QA ); /* QA */
cannam@154 111 }
cannam@154 112
cannam@154 113 dd = silk_RSHIFT( d, 1 );
cannam@154 114
cannam@154 115 /* generate even and odd polynomials using convolution */
cannam@154 116 silk_NLSF2A_find_poly( P, &cos_LSF_QA[ 0 ], dd );
cannam@154 117 silk_NLSF2A_find_poly( Q, &cos_LSF_QA[ 1 ], dd );
cannam@154 118
cannam@154 119 /* convert even and odd polynomials to opus_int32 Q12 filter coefs */
cannam@154 120 for( k = 0; k < dd; k++ ) {
cannam@154 121 Ptmp = P[ k+1 ] + P[ k ];
cannam@154 122 Qtmp = Q[ k+1 ] - Q[ k ];
cannam@154 123
cannam@154 124 /* the Ptmp and Qtmp values at this stage need to fit in int32 */
cannam@154 125 a32_QA1[ k ] = -Qtmp - Ptmp; /* QA+1 */
cannam@154 126 a32_QA1[ d-k-1 ] = Qtmp - Ptmp; /* QA+1 */
cannam@154 127 }
cannam@154 128
cannam@154 129 /* Convert int32 coefficients to Q12 int16 coefs */
cannam@154 130 silk_LPC_fit( a_Q12, a32_QA1, 12, QA + 1, d );
cannam@154 131
cannam@154 132 for( i = 0; silk_LPC_inverse_pred_gain( a_Q12, d, arch ) == 0 && i < MAX_LPC_STABILIZE_ITERATIONS; i++ ) {
cannam@154 133 /* Prediction coefficients are (too close to) unstable; apply bandwidth expansion */
cannam@154 134 /* on the unscaled coefficients, convert to Q12 and measure again */
cannam@154 135 silk_bwexpander_32( a32_QA1, d, 65536 - silk_LSHIFT( 2, i ) );
cannam@154 136 for( k = 0; k < d; k++ ) {
cannam@154 137 a_Q12[ k ] = (opus_int16)silk_RSHIFT_ROUND( a32_QA1[ k ], QA + 1 - 12 ); /* QA+1 -> Q12 */
cannam@154 138 }
cannam@154 139 }
cannam@154 140 }
cannam@154 141