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_AUDIO_DELAY_MAX 1024 28 #define EQ_FIR_FILTER_SIZE_MAX 128 29 #define EQ_SUBBAND_COUNT_MAX 256 30 #define EQ_INTERMEDIATE_2ND_ORDER_PARAMS_COUNT_MAX 32 31 #define EQ_INTERMEDIATE_PARAMETER_COUNT_MAX 32 32 #define EQ_FILTER_SECTION_COUNT_MAX 8 33 #define EQ_FILTER_ELEMENT_COUNT_MAX 4 34 #define EQ_FILTER_COUNT_MAX 4 35 #define MATCHING_PHASE_FILTER_COUNT_MAX 32 36 37 #define EQ_FILTER_DOMAIN_NONE 0 38 #define EQ_FILTER_DOMAIN_TIME (1 << 0) 39 #define EQ_FILTER_DOMAIN_SUBBAND (1 << 1) 40 41 #ifdef __cplusplus 42 extern "C" { 43 #endif 44 45 typedef struct { 46 WORD32 delay; 47 FLOAT32 state[EQ_CHANNEL_COUNT_MAX][EQ_AUDIO_DELAY_MAX]; 48 } ia_audio_delay_struct; 49 50 typedef struct { 51 FLOAT32 radius; 52 FLOAT32 coeff[2]; 53 } ia_2nd_order_filt_params_struct; 54 55 typedef struct { 56 WORD32 coeff_count; 57 FLOAT32 coeff[EQ_FIR_FILTER_SIZE_MAX]; 58 FLOAT32 state[EQ_CHANNEL_COUNT_MAX][EQ_FIR_FILTER_SIZE_MAX]; 59 } ia_fir_filter_struct; 60 61 typedef struct { 62 WORD32 eq_frame_size_subband; 63 WORD32 coeff_count; 64 FLOAT32 subband_coeff[EQ_SUBBAND_COUNT_MAX]; 65 } ia_subband_filt_struct; 66 67 typedef struct { 68 WORD32 filter_format; 69 WORD32 filter_param_count_of_zeros; 70 ia_2nd_order_filt_params_struct 71 ord_2_filt_params_of_zeros[EQ_INTERMEDIATE_2ND_ORDER_PARAMS_COUNT_MAX]; 72 WORD32 filter_param_count_of_poles; 73 ia_2nd_order_filt_params_struct 74 ord_2_filt_params_of_poles[EQ_INTERMEDIATE_2ND_ORDER_PARAMS_COUNT_MAX]; 75 WORD32 filter_param_count_of_fir; 76 ia_fir_filter_struct fir_filter; 77 } ia_interm_filt_params_struct; 78 79 typedef struct { 80 WORD32 interm_filt_param_count; 81 ia_interm_filt_params_struct 82 interm_filt_params[EQ_INTERMEDIATE_PARAMETER_COUNT_MAX]; 83 } IntermediateParams; 84 85 typedef struct { 86 FLOAT32 in_state_1; 87 FLOAT32 in_state_2; 88 FLOAT32 out_state_1; 89 FLOAT32 out_state_2; 90 } ia_filt_sect_state_struct; 91 92 typedef struct { 93 FLOAT32 a1; 94 FLOAT32 a2; 95 FLOAT32 b1; 96 FLOAT32 b2; 97 ia_filt_sect_state_struct filt_sect_state[EQ_CHANNEL_COUNT_MAX]; 98 } ia_filt_sect_struct; 99 100 typedef struct { 101 WORD32 member_count; 102 WORD32 member_idx[EQ_CHANNEL_GROUP_COUNT_MAX]; 103 } ia_cascade_align_group_struct; 104 105 typedef struct { 106 WORD32 validity_flag; 107 WORD32 num_matches_filter; 108 WORD32 matches_filter[EQ_FILTER_SECTION_COUNT_MAX]; 109 FLOAT32 gain; 110 WORD32 section_count; 111 ia_filt_sect_struct filt_section[EQ_FILTER_SECTION_COUNT_MAX]; 112 ia_audio_delay_struct audio_delay; 113 } ia_ph_alignment_filt_struct; 114 115 typedef ia_ph_alignment_filt_struct ia_matching_ph_filt_struct; 116 117 typedef struct { 118 WORD32 matches_cascade_idx; 119 WORD32 all_pass_count; 120 ia_matching_ph_filt_struct matching_ph_filt[MATCHING_PHASE_FILTER_COUNT_MAX]; 121 } ia_all_pass_chain_struct; 122 123 typedef struct { 124 WORD32 section_count; 125 ia_filt_sect_struct filt_section[EQ_FILTER_SECTION_COUNT_MAX]; 126 WORD32 filt_coeffs_flag; 127 ia_fir_filter_struct fir_filter; 128 ia_audio_delay_struct audio_delay; 129 } ia_pole_zero_filt_struct; 130 131 typedef struct { 132 FLOAT32 elementGainLinear; 133 WORD32 format; 134 ia_pole_zero_filt_struct pstr_pole_zero_filt; 135 ia_fir_filter_struct fir_filter; 136 WORD32 num_ph_align_filt; 137 ia_ph_alignment_filt_struct ph_alignment_filt[EQ_FILTER_ELEMENT_COUNT_MAX]; 138 } ia_eq_filt_ele_struct; 139 140 typedef struct { 141 WORD32 element_count; 142 ia_eq_filt_ele_struct eq_filt_element[EQ_FILTER_ELEMENT_COUNT_MAX]; 143 ia_matching_ph_filt_struct matching_ph_filt_ele_0; 144 } ia_eq_filt_block_struct; 145 146 typedef struct { 147 FLOAT32 cascade_gain_linear; 148 WORD32 block_count; 149 ia_eq_filt_block_struct pstr_eq_filt_block[EQ_FILTER_BLOCK_COUNT_MAX]; 150 WORD32 num_ph_align_filt; 151 ia_ph_alignment_filt_struct 152 ph_alignment_filt[EQ_FILTER_BLOCK_COUNT_MAX * EQ_FILTER_BLOCK_COUNT_MAX]; 153 } ia_filt_cascade_td_struct; 154 155 typedef struct { 156 WORD32 domain; 157 WORD32 audio_num_chan; 158 WORD32 eq_ch_group_count; 159 WORD32 eq_ch_group_of_channel[EQ_CHANNEL_COUNT_MAX]; 160 ia_filt_cascade_td_struct filt_cascade_td[EQ_CHANNEL_GROUP_COUNT_MAX]; 161 ia_subband_filt_struct subband_filt[EQ_CHANNEL_GROUP_COUNT_MAX]; 162 } ia_eq_set_struct; 163 164 WORD32 165 impd_derive_eq_set(ia_eq_coeff_struct* str_eq_coeff, 166 ia_eq_instructions_struct* str_eq_instructions, 167 FLOAT32 sample_rate, WORD32 drc_frame_size, 168 WORD32 sub_band_domain_mode, ia_eq_set_struct* eq_set); 169 170 VOID impd_get_eq_set_delay(ia_eq_set_struct* eq_set, WORD32* cascade_delay); 171 WORD32 172 impd_process_eq_set_td(ia_eq_set_struct* eq_set, WORD32 channel, 173 FLOAT32 audio_in, FLOAT32* audio_out); 174 175 WORD32 impd_process_eq_set_time_domain(ia_eq_set_struct* eq_set, WORD32 channel, 176 FLOAT32* audio_in, FLOAT32* audio_out, 177 WORD32 frame_size); 178 WORD32 179 impd_process_eq_set_subband_domain(ia_eq_set_struct* eq_set, WORD32 channel, 180 FLOAT32* subbandSampleIn, 181 FLOAT32* subbandSampleOut); 182 183 #ifdef __cplusplus 184 } 185 #endif 186 #endif 187