1/****************************************************************************** 2 * 3 * Copyright (C) 2015 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#include <stdio.h> 21#include <stdlib.h> 22#include <math.h> 23#include <string.h> 24#include "impd_type_def.h" 25#include "impd_drc_uni_tables.h" 26#include "impd_drc_uni_common.h" 27#include "impd_drc_uni_interface.h" 28#include "impd_drc_struct.h" 29#include "impd_drc_uni_gain_dec.h" 30#include "impd_drc_uni_loud_eq.h" 31#include "impd_parametric_drc_dec.h" 32#include "impd_drc_uni_multi_band.h" 33#include "impd_drc_filter_bank.h" 34#include "impd_drc_uni_process_audio.h" 35#include "impd_drc_rom.h" 36 37WORD32 impd_parametric_drc_instance_reset( 38 WORD32 instance_idx, ia_parametric_drc_instance_params_struct* 39 pstr_parametric_drc_instance_params) { 40 WORD32 err = 0; 41 42 if (pstr_parametric_drc_instance_params->parametric_drc_type == 43 PARAM_DRC_TYPE_FF) { 44 ia_parametric_drc_type_ff_params_struct* 45 pstr_parametric_ffwd_type_drc_params = 46 &(pstr_parametric_drc_instance_params 47 ->str_parametric_drc_type_ff_params); 48 err = impd_parametric_ffwd_type_drc_reset( 49 pstr_parametric_ffwd_type_drc_params); 50 if (err) return (err); 51 52 } else { 53 return (UNEXPECTED_ERROR); 54 } 55 56 return 0; 57} 58 59WORD32 impd_add_drc_band_audio( 60 ia_drc_instructions_struct* pstr_drc_instruction_arr, 61 const WORD32 drc_instructions_index, 62 ia_drc_params_struct* ia_drc_params_struct, 63 ia_audio_band_buffer_struct* audio_band_buffer, FLOAT32* audio_io_buf[]) { 64 WORD32 g, b, i, c; 65 FLOAT32 sum; 66 WORD32 signalIndex = 0; 67 FLOAT32** drcBandAudio; 68 FLOAT32** channel_audio; 69 ia_drc_instructions_struct* str_drc_instruction_str; 70 71 drcBandAudio = audio_band_buffer->non_interleaved_audio; 72 channel_audio = audio_io_buf; 73 74 if (drc_instructions_index >= 0) { 75 str_drc_instruction_str = 76 &(pstr_drc_instruction_arr[drc_instructions_index]); 77 } else { 78 return -1; 79 } 80 81 if (str_drc_instruction_str->drc_set_id > 0) { 82 for (c = 0; c < str_drc_instruction_str->audio_num_chan; c++) 83 84 { 85 g = str_drc_instruction_str->channel_group_of_ch[c]; 86 if (g >= 0) { 87 for (i = 0; i < ia_drc_params_struct->drc_frame_size; i++) { 88 sum = 0.0f; 89 for (b = 0; b < str_drc_instruction_str->band_count_of_ch_group[g]; 90 b++) { 91 sum += drcBandAudio[signalIndex + b][i]; 92 } 93 94 channel_audio[c][i] = sum; 95 } 96 signalIndex += str_drc_instruction_str->band_count_of_ch_group[g]; 97 } else { 98 signalIndex++; 99 } 100 } 101 } else { 102 for (c = 0; c < str_drc_instruction_str->audio_num_chan; c++) 103 104 { 105 for (i = 0; i < ia_drc_params_struct->drc_frame_size; i++) { 106 channel_audio[c][i] = drcBandAudio[c][i]; 107 } 108 } 109 } 110 return (0); 111} 112 113WORD32 removeTables(void) { return (0); } 114 115const ia_slope_code_table_struct* impd_get_slope_code_tbl_by_value(void) { 116 return (&(slopeCodeTableEntryByValue[0])); 117} 118 119FLOAT32 impd_decode_slope_idx(const WORD32 slopeCodeIndex) { 120 const ia_slope_code_table_struct* slopeCodeTable = 121 impd_get_slope_code_tbl_by_value(); 122 return slopeCodeTable[slopeCodeIndex].value; 123} 124 125FLOAT32 impd_decode_slope_idx_magnitude(const WORD32 slopeCodeIndex) { 126 const ia_slope_code_table_struct* slopeCodeTable = 127 impd_get_slope_code_tbl_by_value(); 128 return (FLOAT32)fabs((FLOAT64)slopeCodeTable[slopeCodeIndex].value); 129} 130 131WORD32 impd_get_multi_band_drc_present(ia_drc_config* pstr_drc_config, 132 WORD32 numSets[3], 133 WORD32 multiBandDrcPresent[3]) { 134 WORD32 err = 0, k, m; 135 for (k = 0; k < pstr_drc_config->drc_instructions_uni_drc_count; k++) { 136 if ((pstr_drc_config->str_drc_instruction_str[k].downmix_id[0] == 137 ID_FOR_BASE_LAYOUT) || 138 (pstr_drc_config->str_drc_instruction_str[k].drc_apply_to_dwnmix == 139 0)) { 140 numSets[0]++; 141 } else if (pstr_drc_config->str_drc_instruction_str[k].downmix_id[0] == 142 ID_FOR_ANY_DOWNMIX) { 143 numSets[1]++; 144 } else { 145 numSets[2]++; 146 } 147 for (m = 0; 148 m < pstr_drc_config->str_drc_instruction_str[k].num_drc_ch_groups; 149 m++) { 150 if (pstr_drc_config->str_p_loc_drc_coefficients_uni_drc[0] 151 .gain_set_params[pstr_drc_config->str_drc_instruction_str 152 ->gain_set_index_for_channel_group[m]] 153 .band_count > 1) { 154 if ((pstr_drc_config->str_drc_instruction_str[k].downmix_id[0] == 155 ID_FOR_BASE_LAYOUT) || 156 (pstr_drc_config->str_drc_instruction_str[k].drc_apply_to_dwnmix == 157 0)) { 158 multiBandDrcPresent[0] = 1; 159 } else if (pstr_drc_config->str_drc_instruction_str[k].downmix_id[0] == 160 ID_FOR_ANY_DOWNMIX) { 161 multiBandDrcPresent[1] = 1; 162 } else { 163 multiBandDrcPresent[2] = 1; 164 } 165 } 166 } 167 } 168 return err; 169} 170