Coverage Report

Created: 2026-08-13 07:15

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/opus/silk/float/wrappers_FLP.c
Line
Count
Source
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 "config.h"
30
#endif
31
32
#include "main_FLP.h"
33
34
/* Wrappers. Calls flp / fix code */
35
36
/* Convert AR filter coefficients to NLSF parameters */
37
void silk_A2NLSF_FLP(
38
    opus_int16                      *NLSF_Q15,                          /* O    NLSF vector      [ LPC_order ]              */
39
    const silk_float                *pAR,                               /* I    LPC coefficients [ LPC_order ]              */
40
    const opus_int                  LPC_order                           /* I    LPC order                                   */
41
)
42
81.5M
{
43
81.5M
    opus_int   i;
44
81.5M
    opus_int32 a_fix_Q16[ MAX_LPC_ORDER ];
45
46
978M
    for( i = 0; i < LPC_order; i++ ) {
47
896M
        a_fix_Q16[ i ] = silk_float2int( pAR[ i ] * 65536.0f );
48
896M
    }
49
50
81.5M
    silk_A2NLSF( NLSF_Q15, a_fix_Q16, LPC_order );
51
81.5M
}
52
53
/* Convert LSF parameters to AR prediction filter coefficients */
54
void silk_NLSF2A_FLP(
55
    silk_float                      *pAR,                               /* O    LPC coefficients [ LPC_order ]              */
56
    const opus_int16                *NLSF_Q15,                          /* I    NLSF vector      [ LPC_order ]              */
57
    const opus_int                  LPC_order,                          /* I    LPC order                                   */
58
    int                             arch                                /* I    Run-time architecture                       */
59
)
60
29.2M
{
61
29.2M
    opus_int   i;
62
29.2M
    opus_int16 a_fix_Q12[ MAX_LPC_ORDER ];
63
64
29.2M
    silk_NLSF2A( a_fix_Q12, NLSF_Q15, LPC_order, arch );
65
66
348M
    for( i = 0; i < LPC_order; i++ ) {
67
319M
        pAR[ i ] = ( silk_float )a_fix_Q12[ i ] * ( 1.0f / 4096.0f );
68
319M
    }
69
29.2M
}
70
71
/******************************************/
72
/* Floating-point NLSF processing wrapper */
73
/******************************************/
74
void silk_process_NLSFs_FLP(
75
    silk_encoder_state              *psEncC,                            /* I/O  Encoder state                               */
76
    silk_float                      PredCoef[ 2 ][ MAX_LPC_ORDER ],     /* O    Prediction coefficients                     */
77
    opus_int16                      NLSF_Q15[      MAX_LPC_ORDER ],     /* I/O  Normalized LSFs (quant out) (0 - (2^15-1))  */
78
    const opus_int16                prev_NLSF_Q15[ MAX_LPC_ORDER ]      /* I    Previous Normalized LSFs (0 - (2^15-1))     */
79
)
80
67.3M
{
81
67.3M
    opus_int     i, j;
82
67.3M
    opus_int16   PredCoef_Q12[ 2 ][ MAX_LPC_ORDER ];
83
84
67.3M
    silk_process_NLSFs( psEncC, PredCoef_Q12, NLSF_Q15, prev_NLSF_Q15);
85
86
202M
    for( j = 0; j < 2; j++ ) {
87
1.62G
        for( i = 0; i < psEncC->predictLPCOrder; i++ ) {
88
1.48G
            PredCoef[ j ][ i ] = ( silk_float )PredCoef_Q12[ j ][ i ] * ( 1.0f / 4096.0f );
89
1.48G
        }
90
134M
    }
91
67.3M
}
92
93
/****************************************/
94
/* Floating-point Silk NSQ wrapper      */
95
/****************************************/
96
void silk_NSQ_wrapper_FLP(
97
    silk_encoder_state_FLP          *psEnc,                             /* I/O  Encoder state FLP                           */
98
    silk_encoder_control_FLP        *psEncCtrl,                         /* I/O  Encoder control FLP                         */
99
    SideInfoIndices                 *psIndices,                         /* I/O  Quantization indices                        */
100
    silk_nsq_state                  *psNSQ,                             /* I/O  Noise Shaping Quantzation state             */
101
    opus_int8                       pulses[],                           /* O    Quantized pulse signal                      */
102
    const silk_float                x[]                                 /* I    Prefiltered input signal                    */
103
)
104
71.0M
{
105
71.0M
    opus_int     i, j;
106
71.0M
    opus_int16   x16[ MAX_FRAME_LENGTH ];
107
71.0M
    opus_int32   Gains_Q16[ MAX_NB_SUBFR ];
108
71.0M
    silk_DWORD_ALIGN opus_int16 PredCoef_Q12[ 2 ][ MAX_LPC_ORDER ];
109
71.0M
    opus_int16   LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ];
110
71.0M
    opus_int     LTP_scale_Q14;
111
112
    /* Noise shaping parameters */
113
71.0M
    opus_int16   AR_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ];
114
71.0M
    opus_int32   LF_shp_Q14[ MAX_NB_SUBFR ];         /* Packs two int16 coefficients per int32 value             */
115
71.0M
    opus_int     Lambda_Q10;
116
71.0M
    opus_int     Tilt_Q14[ MAX_NB_SUBFR ];
117
71.0M
    opus_int     HarmShapeGain_Q14[ MAX_NB_SUBFR ];
118
119
    /* Convert control struct to fix control struct */
120
    /* Noise shape parameters */
121
308M
    for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) {
122
3.91G
        for( j = 0; j < psEnc->sCmn.shapingLPCOrder; j++ ) {
123
3.67G
            AR_Q13[ i * MAX_SHAPE_LPC_ORDER + j ] = silk_float2int( psEncCtrl->AR[ i * MAX_SHAPE_LPC_ORDER + j ] * 8192.0f );
124
3.67G
        }
125
237M
    }
126
127
308M
    for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) {
128
237M
        LF_shp_Q14[ i ] =   silk_LSHIFT32( silk_float2int( psEncCtrl->LF_AR_shp[ i ]     * 16384.0f ), 16 ) |
129
237M
                              (opus_uint16)silk_float2int( psEncCtrl->LF_MA_shp[ i ]     * 16384.0f );
130
237M
        Tilt_Q14[ i ]   =        (opus_int)silk_float2int( psEncCtrl->Tilt[ i ]          * 16384.0f );
131
237M
        HarmShapeGain_Q14[ i ] = (opus_int)silk_float2int( psEncCtrl->HarmShapeGain[ i ] * 16384.0f );
132
237M
    }
133
71.0M
    Lambda_Q10 = ( opus_int )silk_float2int( psEncCtrl->Lambda * 1024.0f );
134
135
    /* prediction and coding parameters */
136
1.25G
    for( i = 0; i < psEnc->sCmn.nb_subfr * LTP_ORDER; i++ ) {
137
1.18G
        LTPCoef_Q14[ i ] = (opus_int16)silk_float2int( psEncCtrl->LTPCoef[ i ] * 16384.0f );
138
1.18G
    }
139
140
213M
    for( j = 0; j < 2; j++ ) {
141
1.70G
        for( i = 0; i < psEnc->sCmn.predictLPCOrder; i++ ) {
142
1.56G
            PredCoef_Q12[ j ][ i ] = (opus_int16)silk_float2int( psEncCtrl->PredCoef[ j ][ i ] * 4096.0f );
143
1.56G
        }
144
142M
    }
145
146
308M
    for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) {
147
237M
        Gains_Q16[ i ] = silk_float2int( psEncCtrl->Gains[ i ] * 65536.0f );
148
237M
        silk_assert( Gains_Q16[ i ] > 0 );
149
237M
    }
150
151
71.0M
    if( psIndices->signalType == TYPE_VOICED ) {
152
1.86M
        LTP_scale_Q14 = silk_LTPScales_table_Q14[ psIndices->LTP_scaleIndex ];
153
69.2M
    } else {
154
69.2M
        LTP_scale_Q14 = 0;
155
69.2M
    }
156
157
    /* Convert input to fix */
158
12.1G
    for( i = 0; i < psEnc->sCmn.frame_length; i++ ) {
159
12.1G
        x16[ i ] = silk_float2int( x[ i ] );
160
12.1G
    }
161
162
    /* Call NSQ */
163
71.0M
    if( psEnc->sCmn.nStatesDelayedDecision > 1 || psEnc->sCmn.warping_Q16 > 0 ) {
164
43.8M
        silk_NSQ_del_dec( &psEnc->sCmn, psNSQ, psIndices, x16, pulses, PredCoef_Q12[ 0 ], LTPCoef_Q14,
165
43.8M
            AR_Q13, HarmShapeGain_Q14, Tilt_Q14, LF_shp_Q14, Gains_Q16, psEncCtrl->pitchL, Lambda_Q10, LTP_scale_Q14, psEnc->sCmn.arch );
166
43.8M
    } else {
167
27.2M
        silk_NSQ( &psEnc->sCmn, psNSQ, psIndices, x16, pulses, PredCoef_Q12[ 0 ], LTPCoef_Q14,
168
27.2M
            AR_Q13, HarmShapeGain_Q14, Tilt_Q14, LF_shp_Q14, Gains_Q16, psEncCtrl->pitchL, Lambda_Q10, LTP_scale_Q14, psEnc->sCmn.arch );
169
27.2M
    }
170
71.0M
}
171
172
/***********************************************/
173
/* Floating-point Silk LTP quantiation wrapper */
174
/***********************************************/
175
void silk_quant_LTP_gains_FLP(
176
    silk_float                      B[ MAX_NB_SUBFR * LTP_ORDER ],      /* O    Quantized LTP gains                            */
177
    opus_int8                       cbk_index[ MAX_NB_SUBFR ],          /* O    Codebook index                              */
178
    opus_int8                       *periodicity_index,                 /* O    Periodicity index                           */
179
    opus_int32                      *sum_log_gain_Q7,                   /* I/O  Cumulative max prediction gain  */
180
    silk_float                      *pred_gain_dB,                        /* O    LTP prediction gain                            */
181
    const silk_float                XX[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* I    Correlation matrix                    */
182
    const silk_float                xX[ MAX_NB_SUBFR * LTP_ORDER ],        /* I    Correlation vector                            */
183
    const opus_int                    subfr_len,                            /* I    Number of samples per subframe                */
184
    const opus_int                    nb_subfr,                           /* I    Number of subframes                            */
185
    int                             arch                                /* I    Run-time architecture                       */
186
)
187
587k
{
188
587k
    opus_int   i, pred_gain_dB_Q7;
189
587k
    opus_int16 B_Q14[ MAX_NB_SUBFR * LTP_ORDER ];
190
587k
    opus_int32 XX_Q17[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ];
191
587k
    opus_int32 xX_Q17[ MAX_NB_SUBFR * LTP_ORDER ];
192
193
587k
    i = 0;
194
52.4M
    do {
195
52.4M
        XX_Q17[ i ] = (opus_int32)silk_float2int( XX[ i ] * 131072.0f );
196
52.4M
    } while ( ++i < nb_subfr * LTP_ORDER * LTP_ORDER );
197
587k
    i = 0;
198
10.4M
    do {
199
10.4M
        xX_Q17[ i ] = (opus_int32)silk_float2int( xX[ i ] * 131072.0f );
200
10.4M
    } while ( ++i < nb_subfr * LTP_ORDER );
201
202
587k
    silk_quant_LTP_gains( B_Q14, cbk_index, periodicity_index, sum_log_gain_Q7, &pred_gain_dB_Q7, XX_Q17, xX_Q17, subfr_len, nb_subfr, arch );
203
204
11.0M
    for( i = 0; i < nb_subfr * LTP_ORDER; i++ ) {
205
10.4M
        B[ i ] = (silk_float)B_Q14[ i ] * ( 1.0f / 16384.0f );
206
10.4M
    }
207
208
587k
    *pred_gain_dB = (silk_float)pred_gain_dB_Q7 * ( 1.0f / 128.0f );
209
587k
}