Coverage Report

Created: 2025-11-24 07:40

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/opus/silk/float/find_pitch_lags_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 <stdlib.h>
33
#include "main_FLP.h"
34
#include "tuning_parameters.h"
35
36
void silk_find_pitch_lags_FLP(
37
    silk_encoder_state_FLP          *psEnc,                             /* I/O  Encoder state FLP                           */
38
    silk_encoder_control_FLP        *psEncCtrl,                         /* I/O  Encoder control FLP                         */
39
    silk_float                      res[],                              /* O    Residual                                    */
40
    const silk_float                x[],                                /* I    Speech signal                               */
41
    int                             arch                                /* I    Run-time architecture                       */
42
)
43
236k
{
44
236k
    opus_int   buf_len;
45
236k
    silk_float thrhld, res_nrg;
46
236k
    const silk_float *x_buf_ptr, *x_buf;
47
236k
    silk_float auto_corr[ MAX_FIND_PITCH_LPC_ORDER + 1 ];
48
236k
    silk_float A[         MAX_FIND_PITCH_LPC_ORDER ];
49
236k
    silk_float refl_coef[ MAX_FIND_PITCH_LPC_ORDER ];
50
236k
    silk_float Wsig[      FIND_PITCH_LPC_WIN_MAX ];
51
236k
    silk_float *Wsig_ptr;
52
53
    /******************************************/
54
    /* Set up buffer lengths etc based on Fs  */
55
    /******************************************/
56
236k
    buf_len = psEnc->sCmn.la_pitch + psEnc->sCmn.frame_length + psEnc->sCmn.ltp_mem_length;
57
58
    /* Safety check */
59
236k
    celt_assert( buf_len >= psEnc->sCmn.pitch_LPC_win_length );
60
61
236k
    x_buf = x - psEnc->sCmn.ltp_mem_length;
62
63
    /******************************************/
64
    /* Estimate LPC AR coefficients           */
65
    /******************************************/
66
67
    /* Calculate windowed signal */
68
69
    /* First LA_LTP samples */
70
236k
    x_buf_ptr = x_buf + buf_len - psEnc->sCmn.pitch_LPC_win_length;
71
236k
    Wsig_ptr  = Wsig;
72
236k
    silk_apply_sine_window_FLP( Wsig_ptr, x_buf_ptr, 1, psEnc->sCmn.la_pitch );
73
74
    /* Middle non-windowed samples */
75
236k
    Wsig_ptr  += psEnc->sCmn.la_pitch;
76
236k
    x_buf_ptr += psEnc->sCmn.la_pitch;
77
236k
    silk_memcpy( Wsig_ptr, x_buf_ptr, ( psEnc->sCmn.pitch_LPC_win_length - ( psEnc->sCmn.la_pitch << 1 ) ) * sizeof( silk_float ) );
78
79
    /* Last LA_LTP samples */
80
236k
    Wsig_ptr  += psEnc->sCmn.pitch_LPC_win_length - ( psEnc->sCmn.la_pitch << 1 );
81
236k
    x_buf_ptr += psEnc->sCmn.pitch_LPC_win_length - ( psEnc->sCmn.la_pitch << 1 );
82
236k
    silk_apply_sine_window_FLP( Wsig_ptr, x_buf_ptr, 2, psEnc->sCmn.la_pitch );
83
84
    /* Calculate autocorrelation sequence */
85
236k
    silk_autocorrelation_FLP( auto_corr, Wsig, psEnc->sCmn.pitch_LPC_win_length, psEnc->sCmn.pitchEstimationLPCOrder + 1, arch );
86
87
    /* Add white noise, as a fraction of the energy */
88
236k
    auto_corr[ 0 ] += auto_corr[ 0 ] * FIND_PITCH_WHITE_NOISE_FRACTION + 1;
89
90
    /* Calculate the reflection coefficients using Schur */
91
236k
    res_nrg = silk_schur_FLP( refl_coef, auto_corr, psEnc->sCmn.pitchEstimationLPCOrder );
92
93
    /* Prediction gain */
94
236k
    psEncCtrl->predGain = auto_corr[ 0 ] / silk_max_float( res_nrg, 1.0f );
95
96
    /* Convert reflection coefficients to prediction coefficients */
97
236k
    silk_k2a_FLP( A, refl_coef, psEnc->sCmn.pitchEstimationLPCOrder );
98
99
    /* Bandwidth expansion */
100
236k
    silk_bwexpander_FLP( A, psEnc->sCmn.pitchEstimationLPCOrder, FIND_PITCH_BANDWIDTH_EXPANSION );
101
102
    /*****************************************/
103
    /* LPC analysis filtering                */
104
    /*****************************************/
105
236k
    silk_LPC_analysis_filter_FLP( res, A, x_buf, buf_len, psEnc->sCmn.pitchEstimationLPCOrder );
106
107
236k
    if( psEnc->sCmn.indices.signalType != TYPE_NO_VOICE_ACTIVITY && psEnc->sCmn.first_frame_after_reset == 0 ) {
108
        /* Threshold for pitch estimator */
109
92.1k
        thrhld  = 0.6f;
110
92.1k
        thrhld -= 0.004f * psEnc->sCmn.pitchEstimationLPCOrder;
111
92.1k
        thrhld -= 0.1f   * psEnc->sCmn.speech_activity_Q8 * ( 1.0f /  256.0f );
112
92.1k
        thrhld -= 0.15f  * (psEnc->sCmn.prevSignalType >> 1);
113
92.1k
        thrhld -= 0.1f   * psEnc->sCmn.input_tilt_Q15 * ( 1.0f / 32768.0f );
114
115
        /*****************************************/
116
        /* Call Pitch estimator                  */
117
        /*****************************************/
118
92.1k
        if( silk_pitch_analysis_core_FLP( res, psEncCtrl->pitchL, &psEnc->sCmn.indices.lagIndex,
119
92.1k
            &psEnc->sCmn.indices.contourIndex, &psEnc->LTPCorr, psEnc->sCmn.prevLag, psEnc->sCmn.pitchEstimationThreshold_Q16 / 65536.0f,
120
92.1k
            thrhld, psEnc->sCmn.fs_kHz, psEnc->sCmn.pitchEstimationComplexity, psEnc->sCmn.nb_subfr, arch ) == 0 )
121
33.1k
        {
122
33.1k
            psEnc->sCmn.indices.signalType = TYPE_VOICED;
123
58.9k
        } else {
124
58.9k
            psEnc->sCmn.indices.signalType = TYPE_UNVOICED;
125
58.9k
        }
126
144k
    } else {
127
144k
        silk_memset( psEncCtrl->pitchL, 0, sizeof( psEncCtrl->pitchL ) );
128
144k
        psEnc->sCmn.indices.lagIndex = 0;
129
144k
        psEnc->sCmn.indices.contourIndex = 0;
130
144k
        psEnc->LTPCorr = 0;
131
144k
    }
132
236k
}