Debian Codegraph @

external/opusfile/opus/silk/NLSF2A.c

raw symbols SCIP
1 /***********************************************************************
2 Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3 Redistribution and use in source and binary forms, with or without
4 modification, are permitted provided that the following conditions
5 are met:
6 - Redistributions of source code must retain the above copyright notice,
7 this list of conditions and the following disclaimer.
8 - Redistributions in binary form must reproduce the above copyright
9 notice, this list of conditions and the following disclaimer in the
10 documentation and/or other materials provided with the distribution.
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
13 products derived from this software without specific prior written
14 permission.
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
17 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
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
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
25 POSSIBILITY OF SUCH DAMAGE.
26 ***********************************************************************/
27
28 //#ifdef HAVE_CONFIG_H
29 #include "opus__config.h"cxx . . $ `<file>/external/opusfile/opus/opus__config.h`/
30 //#endif
31
32 /* conversion between prediction filter coefficients and LSFs */
33 /* order should be even */
34 /* a piecewise linear approximation maps LSF <-> cos(LSF) */
35 /* therefore the result is not accurate LSFs, but the two */
36 /* functions are accurate inverses of each other */
37
38 #include "SigProc_FIX.h"cxx . . $ `<file>/external/opusfile/opus/silk/SigProc_FIX.h`/
39 #include "tables.h"cxx . . $ `<file>/external/opusfile/opus/silk/tables.h`/
40
41 #define QAcxx . . $ `external/opusfile/opus/silk/NLSF2A.c:41:9`! 16
42
43 /* helper function for NLSF2A(..) */
44 static OPUS_INLINEcxx . . $ `external/opusfile/opus/opus_defines.h:110:10`! void silk_NLSF2A_find_polycxx . . $ silk_NLSF2A_find_poly(2295dd52fa21b3fe).(
45 opus_int32cxx . . $ opus_int32# *out, /* O intermediate polynomial, QA [dd+1] */
46 const opus_int32cxx . . $ opus_int32# *cLSF, /* I vector of interleaved 2*cos(LSFs), QA [d] */
47 opus_intcxx . . $ `external/opusfile/opus/opus_types.h:36:9`! dd /* I polynomial order (= 1/2 * filter order) */
48 )
49 {
50 opus_intcxx . . $ `external/opusfile/opus/opus_types.h:36:9`! k, n;
51 opus_int32cxx . . $ opus_int32# ftmp;
52
53 out[0] = silk_LSHIFTcxx . . $ `external/opusfile/opus/silk/SigProc_FIX.h:505:9`!( 1, QAcxx . . $ `external/opusfile/opus/silk/NLSF2A.c:41:9`! );
54 out[1] = -cLSF[0];
55 for( k = 1; k < dd; k++ ) {
56 ftmp = cLSF[2*k]; /* QA*/
57 out[k+1] = silk_LSHIFTcxx . . $ `external/opusfile/opus/silk/SigProc_FIX.h:505:9`!( out[k-1], 1 ) - (opus_int32cxx . . $ opus_int32#)silk_RSHIFT_ROUND64cxx . . $ `external/opusfile/opus/silk/SigProc_FIX.h:532:9`!( silk_SMULLcxx . . $ `external/opusfile/opus/silk/SigProc_FIX.h:447:9`!( ftmp, out[k] ), QAcxx . . $ `external/opusfile/opus/silk/NLSF2A.c:41:9`! );
58 for( n = k; n > 1; n-- ) {
59 out[n] += out[n-2] - (opus_int32cxx . . $ opus_int32#)silk_RSHIFT_ROUND64cxx . . $ `external/opusfile/opus/silk/SigProc_FIX.h:532:9`!( silk_SMULLcxx . . $ `external/opusfile/opus/silk/SigProc_FIX.h:447:9`!( ftmp, out[n-1] ), QAcxx . . $ `external/opusfile/opus/silk/NLSF2A.c:41:9`! );
60 }
61 out[1] -= ftmp;
62 }
63 }
64
65 /* compute whitening filter coefficients from normalized line spectral frequencies */
66 void silk_NLSF2Acxx . . $ silk_NLSF2A(f180bfede03221d3).(
67 opus_int16cxx . . $ opus_int16# *a_Q12, /* O monic whitening filter coefficients in Q12, [ d ] */
68 const opus_int16cxx . . $ opus_int16# *NLSF, /* I normalized line spectral frequencies in Q15, [ d ] */
69 const opus_intcxx . . $ `external/opusfile/opus/opus_types.h:36:9`! d, /* I filter order (should be even) */
70 int arch /* I Run-time architecture */
71 )
72 {
73 /* This ordering was found to maximize quality. It improves numerical accuracy of
74 silk_NLSF2A_find_poly() compared to "standard" ordering. */
75 static const unsigned char ordering16[16] = {
76 0, 15, 8, 7, 4, 11, 12, 3, 2, 13, 10, 5, 6, 9, 14, 1
77 };
78 static const unsigned char ordering10[10] = {
79 0, 9, 6, 3, 4, 5, 8, 1, 2, 7
80 };
81 const unsigned char *ordering;
82 opus_intcxx . . $ `external/opusfile/opus/opus_types.h:36:9`! k, i, dd;
83 opus_int32cxx . . $ opus_int32# cos_LSF_QA[ SILK_MAX_ORDER_LPCcxx . . $ `external/opusfile/opus/silk/SigProc_FIX.h:38:9`! ];
84 opus_int32cxx . . $ opus_int32# P[ SILK_MAX_ORDER_LPCcxx . . $ `external/opusfile/opus/silk/SigProc_FIX.h:38:9`! / 2 + 1 ], Q[ SILK_MAX_ORDER_LPCcxx . . $ `external/opusfile/opus/silk/SigProc_FIX.h:38:9`! / 2 + 1 ];
85 opus_int32cxx . . $ opus_int32# Ptmp, Qtmp, f_int, f_frac, cos_val, delta;
86 opus_int32cxx . . $ opus_int32# a32_QA1[ SILK_MAX_ORDER_LPCcxx . . $ `external/opusfile/opus/silk/SigProc_FIX.h:38:9`! ];
87
88 silk_assertcxx . . $ `external/opusfile/opus/silk/typedef.h:74:11`!( LSF_COS_TAB_SZ_FIX == 128 );
89 celt_assertcxx . . $ `external/opusfile/opus/celt/arch.h:80:9`!( d==10 || d==16 );
90
91 /* convert LSFs to 2*cos(LSF), using piecewise linear curve from table */
92 ordering = d == 16 ? ordering16 : ordering10;
93 for( k = 0; k < d; k++ ) {
94 silk_assertcxx . . $ `external/opusfile/opus/silk/typedef.h:74:11`!( NLSF[k] >= 0 );
95
96 /* f_int on a scale 0-127 (rounded down) */
97 f_int = silk_RSHIFTcxx . . $ `external/opusfile/opus/silk/SigProc_FIX.h:511:9`!( NLSF[k], 15 - 7 );
98
99 /* f_frac, range: 0..255 */
100 f_frac = NLSF[k] - silk_LSHIFTcxx . . $ `external/opusfile/opus/silk/SigProc_FIX.h:505:9`!( f_int, 15 - 7 );
101
102 silk_assertcxx . . $ `external/opusfile/opus/silk/typedef.h:74:11`!(f_int >= 0);
103 silk_assertcxx . . $ `external/opusfile/opus/silk/typedef.h:74:11`!(f_int < LSF_COS_TAB_SZ_FIX );
104
105 /* Read start and end value from table */
106 cos_val = silk_LSFCosTab_FIX_Q12cxx . . $ silk_LSFCosTab_FIX_Q12.[ f_int ]; /* Q12 */
107 delta = silk_LSFCosTab_FIX_Q12cxx . . $ silk_LSFCosTab_FIX_Q12.[ f_int + 1 ] - cos_val; /* Q12, with a range of 0..200 */
108
109 /* Linear interpolation */
110 cos_LSF_QA[ordering[k]] = silk_RSHIFT_ROUNDcxx . . $ `external/opusfile/opus/silk/SigProc_FIX.h:531:9`!( silk_LSHIFTcxx . . $ `external/opusfile/opus/silk/SigProc_FIX.h:505:9`!( cos_val, 8 ) + silk_MULcxx . . $ `external/opusfile/opus/silk/SigProc_FIX.h:427:9`!( delta, f_frac ), 20 - QAcxx . . $ `external/opusfile/opus/silk/NLSF2A.c:41:9`! ); /* QA */
111 }
112
113 dd = silk_RSHIFTcxx . . $ `external/opusfile/opus/silk/SigProc_FIX.h:511:9`!( d, 1 );
114
115 /* generate even and odd polynomials using convolution */
116 silk_NLSF2A_find_polycxx . . $ silk_NLSF2A_find_poly(2295dd52fa21b3fe).( P, &cos_LSF_QA[ 0 ], dd );
117 silk_NLSF2A_find_polycxx . . $ silk_NLSF2A_find_poly(2295dd52fa21b3fe).( Q, &cos_LSF_QA[ 1 ], dd );
118
119 /* convert even and odd polynomials to opus_int32 Q12 filter coefs */
120 for( k = 0; k < dd; k++ ) {
121 Ptmp = P[ k+1 ] + P[ k ];
122 Qtmp = Q[ k+1 ] - Q[ k ];
123
124 /* the Ptmp and Qtmp values at this stage need to fit in int32 */
125 a32_QA1[ k ] = -Qtmp - Ptmp; /* QA+1 */
126 a32_QA1[ d-k-1 ] = Qtmp - Ptmp; /* QA+1 */
127 }
128
129 /* Convert int32 coefficients to Q12 int16 coefs */
130 silk_LPC_fitcxx . . $ silk_LPC_fit(d95ad93ccae598da).( a_Q12, a32_QA1, 12, QAcxx . . $ `external/opusfile/opus/silk/NLSF2A.c:41:9`! + 1, d );
131
132 for( i = 0; silk_LPC_inverse_pred_gaincxx . . $ `external/opusfile/opus/silk/SigProc_FIX.h:167:9`!( a_Q12, d, arch ) == 0 && i < MAX_LPC_STABILIZE_ITERATIONScxx . . $ `external/opusfile/opus/silk/define.h:138:9`!; i++ ) {
133 /* Prediction coefficients are (too close to) unstable; apply bandwidth expansion */
134 /* on the unscaled coefficients, convert to Q12 and measure again */
135 silk_bwexpander_32cxx . . $ silk_bwexpander_32(5f3888e91f92d472).( a32_QA1, d, 65536 - silk_LSHIFTcxx . . $ `external/opusfile/opus/silk/SigProc_FIX.h:505:9`!( 2, i ) );
136 for( k = 0; k < d; k++ ) {
137 a_Q12[ k ] = (opus_int16cxx . . $ opus_int16#)silk_RSHIFT_ROUNDcxx . . $ `external/opusfile/opus/silk/SigProc_FIX.h:531:9`!( a32_QA1[ k ], QAcxx . . $ `external/opusfile/opus/silk/NLSF2A.c:41:9`! + 1 - 12 ); /* QA+1 -> Q12 */
138 }
139 }
140 }
141