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 "prot.h"
36 : #include "ivas_prot_rend.h"
37 : #include "ivas_rom_rend.h"
38 : #include <math.h>
39 : #ifdef DEBUGGING
40 : #include "debug.h"
41 : #endif
42 : #include "wmc_auto.h"
43 :
44 :
45 : /*-----------------------------------------------------------------------------------------*
46 : * Local constants
47 : *-----------------------------------------------------------------------------------------*/
48 :
49 : #define DEFAULT_SRC_DIST ( 1.5f ) /* default source distance [m] for reverb dmx factor computing */
50 : #define CLDFB_CONVOLVER_NTAPS_MAX ( 16 )
51 : #define FFT_SPECTRUM_SIZE ( 1 + ( RV_FILTER_MAX_FFT_SIZE / 2 ) )
52 :
53 : #define N_INITIAL_IGNORED_FRAMES 4
54 :
55 : /*-----------------------------------------------------------------------------------------*
56 : * Local function prototypes
57 : *-----------------------------------------------------------------------------------------*/
58 :
59 : typedef struct cldfb_convolver_state
60 : {
61 : const float *filter_taps_left_re[CLDFB_NO_CHANNELS_MAX];
62 : const float *filter_taps_left_im[CLDFB_NO_CHANNELS_MAX];
63 : const float *filter_taps_right_re[CLDFB_NO_CHANNELS_MAX];
64 : const float *filter_taps_right_im[CLDFB_NO_CHANNELS_MAX];
65 : float filter_states_re[BINAURAL_CONVBANDS][CLDFB_CONVOLVER_NTAPS_MAX];
66 : float filter_states_im[BINAURAL_CONVBANDS][CLDFB_CONVOLVER_NTAPS_MAX];
67 : } cldfb_convolver_state;
68 :
69 : static void ivas_reverb_set_energies( const float *avg_pwr_l, const float *avg_pwr_r, const int32_t sampling_rate, float *avg_pwr_l_out, float *avg_pwr_r_out );
70 :
71 : /*-----------------------------------------------------------------------------------------*
72 : * Function ivas_reverb_prepare_cldfb_params()
73 : *
74 : * Prepares reverb parameters for CLDFB-based reverberator
75 : *-----------------------------------------------------------------------------------------*/
76 :
77 735 : ivas_error ivas_reverb_prepare_cldfb_params(
78 : const IVAS_ROOM_ACOUSTICS_CONFIG_DATA *pInput_params,
79 : const HRTFS_STATISTICS_HANDLE hHrtfStatistics,
80 : const int32_t output_Fs,
81 : float *pOutput_t60,
82 : float *pOutput_ene )
83 : {
84 : int16_t idx;
85 : float fc[CLDFB_NO_CHANNELS_MAX];
86 : float avg_pwr_left[CLDFB_NO_CHANNELS_MAX];
87 : float avg_pwr_right[CLDFB_NO_CHANNELS_MAX];
88 : float delay_diff, ln_1e6_inverted, exp_argument;
89 735 : const float dist = DEFAULT_SRC_DIST;
90 735 : const float dmx_gain_2 = 4.0f * EVS_PI * dist * dist / 0.001f;
91 :
92 44835 : for ( idx = 0; idx < CLDFB_NO_CHANNELS_MAX; idx++ )
93 : {
94 44100 : fc[idx] = ( (float) idx + 0.5f ) * ( (float) IVAS_MAX_SAMPLING_RATE / (float) ( 2 * IVAS_CLDFB_NO_CHANNELS_MAX ) );
95 : }
96 :
97 735 : ivas_reverb_interpolate_acoustic_data( pInput_params->nBands, pInput_params->pFc_input, pInput_params->pAcoustic_rt60, pInput_params->pAcoustic_dsr, CLDFB_NO_CHANNELS_MAX, fc, pOutput_t60, pOutput_ene );
98 :
99 : /* adjust DSR for the delay difference */
100 735 : delay_diff = pInput_params->inputPreDelay - pInput_params->acousticPreDelay;
101 735 : ln_1e6_inverted = 1.0f / logf( 1e06f );
102 44835 : for ( idx = 0; idx < CLDFB_NO_CHANNELS_MAX; idx++ )
103 : {
104 44100 : exp_argument = delay_diff / ( pOutput_t60[idx] * ln_1e6_inverted );
105 : /* Limit exponent to approx +/-100 dB in case of incoherent value of delay_diff, to prevent overflow */
106 44100 : exp_argument = min( exp_argument, 23.0f );
107 44100 : exp_argument = max( exp_argument, -23.0f );
108 44100 : pOutput_ene[idx] *= expf( exp_argument );
109 : }
110 :
111 735 : ivas_reverb_set_energies( hHrtfStatistics->average_energy_l, hHrtfStatistics->average_energy_r, output_Fs, avg_pwr_left, avg_pwr_right );
112 :
113 44835 : for ( idx = 0; idx < CLDFB_NO_CHANNELS_MAX; idx++ )
114 : {
115 44100 : pOutput_ene[idx] *= 0.5f * ( avg_pwr_left[idx] + avg_pwr_right[idx] ) * dmx_gain_2;
116 : }
117 :
118 735 : return IVAS_ERR_OK;
119 : }
120 :
121 :
122 : /*-----------------------------------------------------------------------------------------*
123 : * Function ivas_reverb_set_energies()
124 : *
125 : * Function gets the precalculated left/right energies and computes average
126 : * left/right energies to CLDFB bin center frequencies.
127 : *-----------------------------------------------------------------------------------------*/
128 :
129 735 : static void ivas_reverb_set_energies(
130 : const float *avg_pwr_l,
131 : const float *avg_pwr_r,
132 : const int32_t sampling_rate,
133 : float *avg_pwr_left,
134 : float *avg_pwr_right )
135 : {
136 : int16_t freq_idx;
137 735 : const int16_t cldfb_freq_halfstep = IVAS_MAX_SAMPLING_RATE / ( 4 * IVAS_CLDFB_NO_CHANNELS_MAX );
138 : float input_fc[FFT_SPECTRUM_SIZE];
139 : float output_fc[IVAS_CLDFB_NO_CHANNELS_MAX];
140 735 : const int16_t avg_pwr_len = sampling_rate == 16000 ? LR_IAC_LENGTH_NR_FC_16KHZ : LR_IAC_LENGTH_NR_FC;
141 :
142 152382 : for ( freq_idx = 0; freq_idx < avg_pwr_len; freq_idx++ )
143 : {
144 151647 : input_fc[freq_idx] = freq_idx * ( 0.5f * sampling_rate / (float) ( avg_pwr_len - 1 ) );
145 : }
146 :
147 44835 : for ( freq_idx = 0; freq_idx < IVAS_CLDFB_NO_CHANNELS_MAX; freq_idx++ )
148 : {
149 44100 : output_fc[freq_idx] = (float) ( ( 2 * freq_idx + 1 ) * cldfb_freq_halfstep );
150 : }
151 :
152 735 : ivas_reverb_interpolate_acoustic_data( avg_pwr_len, input_fc, avg_pwr_l, avg_pwr_r, IVAS_CLDFB_NO_CHANNELS_MAX, output_fc, avg_pwr_left, avg_pwr_right );
153 735 : }
|