Line data Source code
1 : /******************************************************************************************************
2 :
3 : (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
4 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
5 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
6 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
7 : contributors to this repository. All Rights Reserved.
8 :
9 : This software is protected by copyright law and by international treaties.
10 : The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
11 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
12 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
13 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
14 : contributors to this repository retain full ownership rights in their respective contributions in
15 : the software. This notice grants no license of any kind, including but not limited to patent
16 : license, nor is any license granted by implication, estoppel or otherwise.
17 :
18 : Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
19 : contributions.
20 :
21 : This software is provided "AS IS", without any express or implied warranties. The software is in the
22 : development stage. It is intended exclusively for experts who have experience with such software and
23 : solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
24 : and fitness for a particular purpose are hereby disclaimed and excluded.
25 :
26 : Any dispute, controversy or claim arising under or in relation to providing this software shall be
27 : submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
28 : accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
29 : the United Nations Convention on Contracts on the International Sales of Goods.
30 :
31 : *******************************************************************************************************/
32 :
33 : #include <stdint.h>
34 : #include "options.h"
35 : #include "ivas_rom_com.h"
36 : #include "ivas_prot.h"
37 : #include "prot.h"
38 : #include "ivas_prot.h"
39 : #include "wmc_auto.h"
40 : #include <assert.h>
41 :
42 : /*-------------------------------------------------------------------*
43 : * SpectrumWeighting_Init()
44 : *
45 : *
46 : *-------------------------------------------------------------------*/
47 :
48 223360 : static void SpectrumWeighting_Init(
49 : SpectrumWarping const *pSpectrumWarping,
50 : const int16_t isTCX20,
51 : PsychoacousticParameters *pPsychParams )
52 : {
53 223360 : if ( isTCX20 )
54 : {
55 111680 : pPsychParams->bandLengths = pSpectrumWarping->bandLengthsTCX20;
56 : }
57 : else
58 : {
59 111680 : pPsychParams->bandLengths = pSpectrumWarping->bandLengthsTCX10;
60 : }
61 :
62 223360 : return;
63 : }
64 :
65 : /*-------------------------------------------------------------------*
66 : * PsychoacousticParameters_Init()
67 : *
68 : * initialize a PsychoacousticParameters structure
69 : *-------------------------------------------------------------------*/
70 :
71 287514 : ivas_error PsychoacousticParameters_Init(
72 : const int32_t sr_core, /* i : sampling rate of core-coder */
73 : const int16_t nBins, /* i : Number of bins (spectral lines) */
74 : const int8_t nBands, /* i : Number of spectrum subbands */
75 : const int16_t isTCX20, /* i : Flag indicating if the subband division is for TCX20 or TCX10 */
76 : const int16_t isWarped, /* i : Flag indicating if the scale is linear or warped */
77 : PsychoacousticParameters *pPsychParams )
78 : {
79 :
80 287514 : if ( pPsychParams == NULL )
81 : {
82 0 : return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "PsychParams handle is NULL" );
83 : }
84 :
85 287514 : pPsychParams->nBins = nBins;
86 287514 : pPsychParams->nBands = nBands;
87 :
88 287514 : if ( !isWarped )
89 : {
90 64154 : pPsychParams->bandLengths = NULL;
91 : }
92 : else
93 : {
94 223360 : assert( pPsychParams->nBands == 64 );
95 223360 : switch ( sr_core )
96 : {
97 102852 : case 16000:
98 102852 : SpectrumWeighting_Init( sw16000Hz, isTCX20, pPsychParams );
99 102852 : break;
100 65804 : case 25600:
101 65804 : SpectrumWeighting_Init( sw25600Hz, isTCX20, pPsychParams );
102 65804 : break;
103 54704 : case 32000:
104 54704 : SpectrumWeighting_Init( sw32000Hz, isTCX20, pPsychParams );
105 54704 : break;
106 0 : default:
107 0 : return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Subband division not defined for this sampling rate" );
108 : }
109 : }
110 :
111 287514 : return IVAS_ERR_OK;
112 : }
113 :
114 : /*-------------------------------------------------------------------*
115 : * InitPsychLPC()
116 : *
117 : *
118 : *-------------------------------------------------------------------*/
119 :
120 64154 : void InitPsychLPC(
121 : const int32_t sr_core, /* i : sampling rate of core-coder */
122 : const int16_t L_frame, /* i : frame length */
123 : const TCX_CONFIG_HANDLE hTcxCfg /* i : TCX configuration handle */
124 : )
125 : {
126 64154 : int16_t L_frame_ext = L_frame + L_frame / 4;
127 :
128 64154 : hTcxCfg->psychParamsCurrent = NULL;
129 :
130 64154 : PsychoacousticParameters_Init( sr_core, L_frame / 2, 64, 0, 1, &hTcxCfg->psychParamsTCX10 );
131 64154 : PsychoacousticParameters_Init( sr_core, L_frame, 64, 1, 1, &hTcxCfg->psychParamsTCX20 );
132 64154 : PsychoacousticParameters_Init( sr_core, L_frame_ext, 64, 1, 0, &hTcxCfg->psychParamsTCX20AfterACELP );
133 :
134 64154 : return;
135 : }
136 :
137 : /*-------------------------------------------------------------------*
138 : * SetCurrentPsychParams()
139 : *
140 : *
141 : *-------------------------------------------------------------------*/
142 :
143 2524433 : void SetCurrentPsychParams(
144 : const int16_t core,
145 : const int16_t last_frame_was_concealed_cng,
146 : TCX_CONFIG_HANDLE hTcxCfg )
147 : {
148 2524433 : if ( hTcxCfg->tcx_last_overlap_mode == TRANSITION_OVERLAP && !last_frame_was_concealed_cng )
149 : {
150 5336 : assert( core == TCX_20_CORE );
151 5336 : hTcxCfg->psychParamsCurrent = &hTcxCfg->psychParamsTCX20AfterACELP;
152 : }
153 : else
154 : {
155 2519097 : hTcxCfg->psychParamsCurrent = ( core == TCX_10_CORE ) ? &hTcxCfg->psychParamsTCX10 : &hTcxCfg->psychParamsTCX20;
156 : }
157 :
158 2524433 : return;
159 : }
|