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 : /*====================================================================================
34 : EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
35 : ====================================================================================*/
36 :
37 : #include <stdint.h>
38 : #include "options.h"
39 : #include <math.h>
40 : #include "cnst.h"
41 : #include "prot.h"
42 : #include "rom_com.h"
43 : #include "wmc_auto.h"
44 :
45 :
46 : /*-------------------------------------------------------------------*
47 : * DTFS_dequant_cw()
48 : *
49 : * DTFS dequantization
50 : *-------------------------------------------------------------------*/
51 :
52 0 : static void DTFS_dequant_cw(
53 : int16_t pl, /* i : Previous lag */
54 : int16_t POWER_IDX, /* i : POWER index */
55 : const int16_t *AMP_IDX, /* i : Amp Shape index */
56 : float *lastLgainD, /* i/o: low band last gain */
57 : float *lastHgainD, /* i/o: high band last gain */
58 : float *lasterbD, /* i/o: last frame ERB vector */
59 : DTFS_STRUCTURE *X, /* o : DTFS structure dequantized */
60 : int16_t num_erb /* i : Number of ERB bands */
61 : )
62 : {
63 : float tmp, mfreq[NUM_ERB_WB], curr_erb[NUM_ERB_WB];
64 : int16_t slot[NUM_ERB_WB];
65 0 : const float( *PowerCB )[2] = NULL;
66 :
67 0 : if ( num_erb == NUM_ERB_NB )
68 : {
69 0 : PowerCB = PowerCB_NB;
70 : }
71 0 : else if ( num_erb == NUM_ERB_WB )
72 : {
73 0 : PowerCB = PowerCB_WB;
74 : }
75 :
76 : /* Amplitude Dequantization */
77 0 : erb_add( curr_erb, X->lag, lasterbD, pl, AMP_IDX, num_erb );
78 0 : curr_erb[0] = curr_erb[1] * 0.3f;
79 0 : curr_erb[num_erb - 2] = curr_erb[num_erb - 3] * 0.3f;
80 0 : curr_erb[num_erb - 1] = 0;
81 0 : erb_slot( X->lag, slot, mfreq, num_erb );
82 0 : DTFS_erb_inv( curr_erb, slot, mfreq, X, num_erb );
83 :
84 : /* Back up the lasterbD memory after power normalization */
85 0 : DTFS_setEngyHarm( 92.0, 1104.5, 0.0, 1104.5, 1.0, X );
86 0 : DTFS_setEngyHarm( 1104.5, X->upper_cut_off_freq_of_interest, 1104.5, X->upper_cut_off_freq, 1.0, X );
87 0 : DTFS_to_erb( *X, lasterbD );
88 :
89 : /* Power Dequantization */
90 0 : *lastLgainD += (float) PowerCB[POWER_IDX][0];
91 0 : *lastHgainD += (float) PowerCB[POWER_IDX][1];
92 0 : tmp = (float) pow( 10.0, (double) ( *lastLgainD ) ) / X->lag;
93 :
94 0 : if ( !( tmp >= 0.0 ) )
95 : {
96 0 : tmp = 0.0;
97 : }
98 :
99 0 : DTFS_setEngyHarm( 92.0, 1104.5, 0.0, 1104.5, tmp, X );
100 0 : tmp = (float) pow( 10.0, (double) ( *lastHgainD ) ) / X->lag;
101 :
102 0 : if ( !( tmp >= 0.0 ) )
103 : {
104 0 : tmp = 0.0;
105 : }
106 :
107 0 : DTFS_setEngyHarm( 1104.5, X->upper_cut_off_freq_of_interest, 1104.5, X->upper_cut_off_freq, tmp, X );
108 :
109 0 : return;
110 : }
111 :
112 : /*-------------------------------------------------------------------
113 : * ppp_quarter_decoder()
114 : *
115 : * PPP quarter decoder
116 : *-------------------------------------------------------------------*/
117 :
118 0 : ivas_error ppp_quarter_decoder(
119 : Decoder_State *st, /* i/o: decoder state structure */
120 : DTFS_STRUCTURE *CURRCW_Q_DTFS, /* i/o: Current CW DTFS */
121 : int16_t prevCW_lag, /* i : Previous lag */
122 : float *lastLgainD, /* i/o: Last gain lowband */
123 : float *lastHgainD, /* i/o: Last gain highwband */
124 : float *lasterbD, /* i/o: Last ERB vector */
125 : int16_t bfi, /* i : FER flag */
126 : DTFS_STRUCTURE PREV_CW_D /* i : Previous DTFS */
127 : )
128 : {
129 : DTFS_STRUCTURE *PREVDTFS;
130 0 : float tmp, temp_pl = (float) prevCW_lag, temp_l = (float) CURRCW_Q_DTFS->lag;
131 0 : int16_t l = CURRCW_Q_DTFS->lag;
132 : int16_t POWER_IDX, AMP_IDX[2];
133 0 : float Erot = 0.0, z = 0.0;
134 0 : int16_t num_erb = 24;
135 : ivas_error error;
136 :
137 0 : error = IVAS_ERR_OK;
138 0 : if ( ( error = DTFS_new( &PREVDTFS ) ) != IVAS_ERR_OK )
139 : {
140 0 : return error;
141 : }
142 :
143 0 : if ( CURRCW_Q_DTFS->upper_cut_off_freq == 4000.0 )
144 : {
145 0 : num_erb = 22;
146 : }
147 0 : else if ( CURRCW_Q_DTFS->upper_cut_off_freq == 6400.0 )
148 : {
149 0 : num_erb = 24;
150 : }
151 :
152 0 : DTFS_copy( PREVDTFS, PREV_CW_D );
153 0 : if ( bfi == 0 )
154 : {
155 0 : POWER_IDX = get_next_indice( st, 6 );
156 0 : AMP_IDX[0] = get_next_indice( st, 6 );
157 0 : AMP_IDX[1] = get_next_indice( st, 6 );
158 :
159 : /* Amplitude Dequantization */
160 0 : DTFS_dequant_cw( prevCW_lag, POWER_IDX, AMP_IDX, lastLgainD, lastHgainD, lasterbD, CURRCW_Q_DTFS, num_erb );
161 : }
162 :
163 : /* Copying phase spectrum over */
164 0 : DTFS_adjustLag( PREVDTFS, l );
165 :
166 0 : z = ( ( L_FRAME - temp_l ) * ( temp_l + temp_pl ) ) / ( 2 * temp_l * temp_pl );
167 :
168 0 : Erot = (float) ( temp_l - rint_new( temp_l * ( z - floor( z ) ) ) );
169 :
170 0 : DTFS_phaseShift( PREVDTFS, (float) ( PI2 * Erot / CURRCW_Q_DTFS->lag ) );
171 0 : DTFS_car2pol( PREVDTFS );
172 :
173 0 : mvr2r( PREVDTFS->b, CURRCW_Q_DTFS->b, (int16_t) ( CURRCW_Q_DTFS->lag >> 1 ) + 1 );
174 :
175 0 : DTFS_pol2car( CURRCW_Q_DTFS );
176 :
177 0 : tmp = (float) get_next_indice( st, 3 );
178 0 : DTFS_phaseShift( CURRCW_Q_DTFS, (float) ( PI2 * ( tmp - 3 ) / CURRCW_Q_DTFS->lag ) );
179 :
180 0 : free( PREVDTFS );
181 :
182 0 : return error;
183 : }
|