aboutsummaryrefslogtreecommitdiff
path: root/decoder/drc_src/impd_parametric_drc_dec.h
blob: 68292468684c5b8b0f96acd95309bacaccaff19c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/******************************************************************************
 *
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *****************************************************************************
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
*/
#ifndef IMPD_PARAMETRIC_DRC_DEC_H
#define IMPD_PARAMETRIC_DRC_DEC_H

#ifdef __cplusplus
extern "C" {
#endif

typedef struct ia_2nd_order_filt_coeff_struct_t {
  FLOAT32 b0, b1, b2;
  FLOAT32 a1, a2;
} ia_2nd_order_filt_coeff_struct;

typedef struct ia_2nd_order_filt_state_struct_t {
  FLOAT32 z1, z2;
} ia_2nd_order_filt_state_struct;

typedef struct ia_parametric_drc_type_ff_params_struct_t {
  WORD32 audio_num_chan;
  WORD32 frame_size;
  WORD32 sub_band_domain_mode;
  WORD32 sub_band_count;
  WORD32 level_estim_integration_time;
  WORD32 level_estim_frame_index;
  WORD32 level_estim_frame_count;
  FLOAT32 level[PARAM_DRC_TYPE_FF_LEVEL_ESTIM_FRAME_COUNT_MAX];
  WORD32 start_up_phase;
  FLOAT32 level_estim_ch_weight[MAX_CHANNEL_COUNT];
  WORD32 level_estim_k_weighting_type;
  ia_2nd_order_filt_coeff_struct pre_filt_coeff;
  ia_2nd_order_filt_coeff_struct rlb_filt_coeff;
  ia_2nd_order_filt_state_struct pre_filt_state[MAX_CHANNEL_COUNT];
  ia_2nd_order_filt_state_struct rlb_filt_state[MAX_CHANNEL_COUNT];
  FLOAT32 weighting_filt[AUDIO_CODEC_SUBBAND_COUNT_MAX];
  WORD32 sub_band_compensation_type;
  ia_2nd_order_filt_coeff_struct filt_coeff_subband;
  ia_2nd_order_filt_state_struct filt_state_subband_real[MAX_CHANNEL_COUNT];
  ia_2nd_order_filt_state_struct filt_state_subband_imag[MAX_CHANNEL_COUNT];
  FLOAT32 ref_level_parametric_drc;

  WORD32 node_count;
  WORD32 node_level[PARAM_DRC_TYPE_FF_NODE_COUNT_MAX];
  WORD32 node_gain[PARAM_DRC_TYPE_FF_NODE_COUNT_MAX];

  FLOAT32 gain_smooth_attack_alpha_slow;
  FLOAT32 gain_smooth_rel_alpha_slow;
  FLOAT32 gain_smooth_attack_alpha_fast;
  FLOAT32 gain_smooth_rel_alpha_fast;
  WORD32 gain_smooth_attack_threshold;
  WORD32 gain_smooth_rel_threshold;
  WORD32 gain_smooth_hold_off_count;
  FLOAT32 db_level_smooth;
  FLOAT32 db_gain_smooth;
  WORD32 hold_counter;

} ia_parametric_drc_type_ff_params_struct;

typedef struct ia_parametric_drc_type_lim_params_struct_t {
  WORD32 audio_num_chan;
  WORD32 frame_size;
  FLOAT32 level_estim_ch_weight[MAX_CHANNEL_COUNT];

  UWORD32 attack;
  FLOAT32 attack_constant;
  FLOAT32 release_constant;
  FLOAT32 attack_ms;
  FLOAT32 release_ms;
  FLOAT32 threshold;
  UWORD32 channels;
  UWORD32 sampling_rate;
  FLOAT32 cor;
  FLOAT32* max_buf;
  FLOAT32* max_buf_slow;
  UWORD32 max_buf_idx;
  UWORD32 max_buf_slow_idx;
  UWORD32 sec_len;
  UWORD32 num_max_buf_sec;
  UWORD32 max_buf_sec_idx;
  UWORD32 max_buf_sec_ctr;
  FLOAT64 smooth_state_0;

} ia_parametric_drc_type_lim_params_struct;

typedef struct ia_parametric_drc_instance_params_struct_t {
  WORD32 disable_paramteric_drc;
  WORD32 parametric_drc_type;
  ia_spline_nodes_struct str_spline_nodes;
  ia_parametric_drc_type_ff_params_struct str_parametric_drc_type_ff_params;
  ia_parametric_drc_type_lim_params_struct str_parametric_drc_type_lim_params;
} ia_parametric_drc_instance_params_struct;

typedef struct ia_parametric_drc_params_struct_t {
  WORD32 sampling_rate;
  WORD32 audio_num_chan;
  WORD32 sub_band_domain_mode;
  WORD32 sub_band_count;

  WORD32 num_nodes;
  WORD32 drc_frame_size;
  WORD32 parametric_drc_frame_size;
  WORD32 parametric_drc_look_ahead_samples_max;
  WORD32 reset_parametric_drc;

  WORD32 parametric_drc_instance_count;
  WORD32 parametric_drc_idx[PARAM_DRC_INSTANCE_COUNT_MAX];
  WORD32 gain_set_index[PARAM_DRC_INSTANCE_COUNT_MAX];
  WORD32 dwnmix_id_from_drc_instructions[PARAM_DRC_INSTANCE_COUNT_MAX];
  WORD32 channel_map[PARAM_DRC_INSTANCE_COUNT_MAX][MAX_CHANNEL_COUNT];

  ia_parametric_drc_instance_params_struct
      str_parametric_drc_instance_params[PARAM_DRC_INSTANCE_COUNT_MAX];

} ia_parametric_drc_params_struct;

WORD32 impd_init_parametric_drc(
    WORD32 drc_frame_size, WORD32 sampling_rate, WORD32 sub_band_domain_mode,
    ia_parametric_drc_params_struct* pstr_parametric_drc_params);

WORD32 impd_init_parametric_drc_after_config(
    ia_drc_config* pstr_drc_config,
    ia_drc_loudness_info_set_struct* pstr_loudness_info,
    ia_parametric_drc_params_struct* pstr_parametric_drc_params,
    pVOID* mem_ptr);

WORD32
impd_init_lvl_est_filt_time(WORD32 level_estim_k_weighting_type,
                            WORD32 sampling_rate,
                            ia_2nd_order_filt_coeff_struct* pre_filt_coeff,
                            ia_2nd_order_filt_coeff_struct* rlb_filt_coeff);

WORD32
impd_init_lvl_est_filt_subband(
    WORD32 level_estim_k_weighting_type, WORD32 sampling_rate,
    WORD32 sub_band_domain_mode, WORD32 sub_band_count,
    WORD32 sub_band_compensation_type, FLOAT32* weighting_filt,
    ia_2nd_order_filt_coeff_struct* filt_coeff_subband);

WORD32
impd_parametric_ffwd_type_drc_reset(ia_parametric_drc_type_ff_params_struct*
                                        pstr_parametric_ffwd_type_drc_params);

WORD32
impd_parametric_lim_type_drc_reset(WORD32 instance_idx,
                                   ia_parametric_drc_type_lim_params_struct*
                                       pstr_parametric_lim_type_drc_params);

WORD32
impd_parametric_drc_instance_process(
    FLOAT32* audio_in_out_buf[], FLOAT32* audio_real_buff[],
    FLOAT32* audio_imag_buff[],
    ia_parametric_drc_params_struct* pstr_parametric_drc_params,
    ia_parametric_drc_instance_params_struct*
        pstr_parametric_drc_instance_params);

WORD32
impd_parametric_ffwd_type_drc_process(FLOAT32* audio_in_out_buf[],
                                      FLOAT32* audio_real_buff[],
                                      FLOAT32* audio_imag_buff[],
                                      WORD32 nodeIdx,
                                      ia_parametric_drc_type_ff_params_struct*
                                          pstr_parametric_ffwd_type_drc_params,
                                      ia_spline_nodes_struct* str_spline_nodes);

WORD32
impd_parametric_lim_type_drc_process(FLOAT32* audio_in_out_buf[],
                                     FLOAT32 loudness_normalization_gain_db,
                                     ia_parametric_drc_type_lim_params_struct*
                                         pstr_parametric_lim_type_drc_params,
                                     FLOAT32* lpcm_gains);

#ifdef __cplusplus
}
#endif
#endif