• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  * Copyright (C) 2018 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *****************************************************************************
18  * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19 */
20 #ifndef IMPD_DRC_EQ_H
21 #define IMPD_DRC_EQ_H
22 
23 #ifndef COMPILE_FOR_DRC_ENCODER
24 #endif
25 
26 #define EQ_CHANNEL_COUNT_MAX 8
27 #define EQ_FIR_FILTER_SIZE_MAX 128
28 #define EQ_SUBBAND_COUNT_MAX 256
29 #define EQ_INTERMEDIATE_2ND_ORDER_PARAMS_COUNT_MAX 32
30 #define EQ_INTERMEDIATE_PARAMETER_COUNT_MAX 32
31 #define EQ_FILTER_SECTION_COUNT_MAX 8
32 #define EQ_FILTER_ELEMENT_COUNT_MAX 4
33 #define EQ_FILTER_COUNT_MAX 4
34 #define MATCHING_PHASE_FILTER_COUNT_MAX 32
35 
36 #define EQ_FILTER_DOMAIN_NONE 0
37 #define EQ_FILTER_DOMAIN_TIME (1 << 0)
38 #define EQ_FILTER_DOMAIN_SUBBAND (1 << 1)
39 
40 #define EQ_REAL_ZERO_CNT 63    /*Max Value of a 6 bit number*/
41 #define EQ_GENERIC_ZERO_CNT 63 /*Max Value of a 6 bit number*/
42 #define EQ_AUDIO_DELAY_MAX (EQ_REAL_ZERO_CNT + (EQ_GENERIC_ZERO_CNT * 2))
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 typedef struct {
49   WORD32 delay;
50   FLOAT32 state[EQ_CHANNEL_COUNT_MAX][EQ_AUDIO_DELAY_MAX];
51 } ia_audio_delay_struct;
52 
53 typedef struct {
54   FLOAT32 radius;
55   FLOAT32 coeff[2];
56 } ia_2nd_order_filt_params_struct;
57 
58 typedef struct {
59   WORD32 coeff_count;
60   FLOAT32 coeff[EQ_FIR_FILTER_SIZE_MAX];
61   FLOAT32 state[EQ_CHANNEL_COUNT_MAX][EQ_FIR_FILTER_SIZE_MAX];
62 } ia_fir_filter_struct;
63 
64 typedef struct {
65   WORD32 eq_frame_size_subband;
66   WORD32 coeff_count;
67   FLOAT32 subband_coeff[EQ_SUBBAND_COUNT_MAX];
68 } ia_subband_filt_struct;
69 
70 typedef struct {
71   WORD32 filter_format;
72   WORD32 filter_param_count_of_zeros;
73   ia_2nd_order_filt_params_struct
74       ord_2_filt_params_of_zeros[EQ_INTERMEDIATE_2ND_ORDER_PARAMS_COUNT_MAX];
75   WORD32 filter_param_count_of_poles;
76   ia_2nd_order_filt_params_struct
77       ord_2_filt_params_of_poles[EQ_INTERMEDIATE_2ND_ORDER_PARAMS_COUNT_MAX];
78   WORD32 filter_param_count_of_fir;
79   ia_fir_filter_struct fir_filter;
80 } ia_interm_filt_params_struct;
81 
82 typedef struct {
83   WORD32 interm_filt_param_count;
84   ia_interm_filt_params_struct
85       interm_filt_params[EQ_INTERMEDIATE_PARAMETER_COUNT_MAX];
86 } IntermediateParams;
87 
88 typedef struct {
89   FLOAT32 in_state_1;
90   FLOAT32 in_state_2;
91   FLOAT32 out_state_1;
92   FLOAT32 out_state_2;
93 } ia_filt_sect_state_struct;
94 
95 typedef struct {
96   FLOAT32 a1;
97   FLOAT32 a2;
98   FLOAT32 b1;
99   FLOAT32 b2;
100   ia_filt_sect_state_struct filt_sect_state[EQ_CHANNEL_COUNT_MAX];
101 } ia_filt_sect_struct;
102 
103 typedef struct {
104   WORD32 member_count;
105   WORD32 member_idx[EQ_CHANNEL_GROUP_COUNT_MAX];
106 } ia_cascade_align_group_struct;
107 
108 typedef struct {
109   WORD32 validity_flag;
110   WORD32 num_matches_filter;
111   WORD32 matches_filter[EQ_FILTER_SECTION_COUNT_MAX];
112   FLOAT32 gain;
113   WORD32 section_count;
114   ia_filt_sect_struct filt_section[EQ_FILTER_SECTION_COUNT_MAX];
115   ia_audio_delay_struct audio_delay;
116 } ia_ph_alignment_filt_struct;
117 
118 typedef ia_ph_alignment_filt_struct ia_matching_ph_filt_struct;
119 
120 typedef struct {
121   WORD32 matches_cascade_idx;
122   WORD32 all_pass_count;
123   ia_matching_ph_filt_struct matching_ph_filt[MATCHING_PHASE_FILTER_COUNT_MAX];
124 } ia_all_pass_chain_struct;
125 
126 typedef struct {
127   WORD32 section_count;
128   ia_filt_sect_struct filt_section[EQ_FILTER_SECTION_COUNT_MAX];
129   WORD32 filt_coeffs_flag;
130   ia_fir_filter_struct fir_filter;
131   ia_audio_delay_struct audio_delay;
132 } ia_pole_zero_filt_struct;
133 
134 typedef struct {
135   FLOAT32 elementGainLinear;
136   WORD32 format;
137   ia_pole_zero_filt_struct pstr_pole_zero_filt;
138   ia_fir_filter_struct fir_filter;
139   WORD32 num_ph_align_filt;
140   ia_ph_alignment_filt_struct ph_alignment_filt[EQ_FILTER_ELEMENT_COUNT_MAX];
141 } ia_eq_filt_ele_struct;
142 
143 typedef struct {
144   WORD32 element_count;
145   ia_eq_filt_ele_struct eq_filt_element[EQ_FILTER_ELEMENT_COUNT_MAX];
146   ia_matching_ph_filt_struct matching_ph_filt_ele_0;
147 } ia_eq_filt_block_struct;
148 
149 typedef struct {
150   FLOAT32 cascade_gain_linear;
151   WORD32 block_count;
152   ia_eq_filt_block_struct pstr_eq_filt_block[EQ_FILTER_BLOCK_COUNT_MAX];
153   WORD32 num_ph_align_filt;
154   ia_ph_alignment_filt_struct
155       ph_alignment_filt[EQ_FILTER_BLOCK_COUNT_MAX * EQ_FILTER_BLOCK_COUNT_MAX];
156 } ia_filt_cascade_td_struct;
157 
158 typedef struct {
159   WORD32 domain;
160   WORD32 audio_num_chan;
161   WORD32 eq_ch_group_count;
162   WORD32 eq_ch_group_of_channel[EQ_CHANNEL_COUNT_MAX];
163   ia_filt_cascade_td_struct filt_cascade_td[EQ_CHANNEL_GROUP_COUNT_MAX];
164   ia_subband_filt_struct subband_filt[EQ_CHANNEL_GROUP_COUNT_MAX];
165 } ia_eq_set_struct;
166 
167 WORD32
168 impd_derive_eq_set(ia_eq_coeff_struct* str_eq_coeff,
169                    ia_eq_instructions_struct* str_eq_instructions,
170                    FLOAT32 sample_rate, WORD32 drc_frame_size,
171                    WORD32 sub_band_domain_mode, ia_eq_set_struct* eq_set);
172 
173 VOID impd_get_eq_set_delay(ia_eq_set_struct* eq_set, WORD32* cascade_delay);
174 WORD32
175 impd_process_eq_set_td(ia_eq_set_struct* eq_set, WORD32 channel,
176                        FLOAT32 audio_in, FLOAT32* audio_out);
177 
178 WORD32 impd_process_eq_set_time_domain(ia_eq_set_struct* eq_set, WORD32 channel,
179                                        FLOAT32* audio_in, FLOAT32* audio_out,
180                                        WORD32 frame_size);
181 #ifdef __cplusplus
182 }
183 #endif
184 #endif
185