151aa06e124ba688ca810b25ee0b5bb66678aac14Ray Essick/****************************************************************************** 24908247643e9e97852e847c00bfe7c4259279538Ray Essick * 34908247643e9e97852e847c00bfe7c4259279538Ray Essick * Copyright (C) 2018 The Android Open Source Project 44908247643e9e97852e847c00bfe7c4259279538Ray Essick * 54908247643e9e97852e847c00bfe7c4259279538Ray Essick * Licensed under the Apache License, Version 2.0 (the "License"); 64908247643e9e97852e847c00bfe7c4259279538Ray Essick * you may not use this file except in compliance with the License. 74908247643e9e97852e847c00bfe7c4259279538Ray Essick * You may obtain a copy of the License at: 84908247643e9e97852e847c00bfe7c4259279538Ray Essick * 94908247643e9e97852e847c00bfe7c4259279538Ray Essick * http://www.apache.org/licenses/LICENSE-2.0 104908247643e9e97852e847c00bfe7c4259279538Ray Essick * 114908247643e9e97852e847c00bfe7c4259279538Ray Essick * Unless required by applicable law or agreed to in writing, software 124908247643e9e97852e847c00bfe7c4259279538Ray Essick * distributed under the License is distributed on an "AS IS" BASIS, 134908247643e9e97852e847c00bfe7c4259279538Ray Essick * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 144908247643e9e97852e847c00bfe7c4259279538Ray Essick * See the License for the specific language governing permissions and 154908247643e9e97852e847c00bfe7c4259279538Ray Essick * limitations under the License. 164908247643e9e97852e847c00bfe7c4259279538Ray Essick * 1751aa06e124ba688ca810b25ee0b5bb66678aac14Ray Essick ***************************************************************************** 184908247643e9e97852e847c00bfe7c4259279538Ray Essick * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore 194908247643e9e97852e847c00bfe7c4259279538Ray Essick*/ 2051aa06e124ba688ca810b25ee0b5bb66678aac14Ray Essick#include <stdio.h> 2151aa06e124ba688ca810b25ee0b5bb66678aac14Ray Essick#include <stdlib.h> 2251aa06e124ba688ca810b25ee0b5bb66678aac14Ray Essick#include <math.h> 2351aa06e124ba688ca810b25ee0b5bb66678aac14Ray Essick#include <string.h> 2451aa06e124ba688ca810b25ee0b5bb66678aac14Ray Essick 2551aa06e124ba688ca810b25ee0b5bb66678aac14Ray Essick#include "impd_type_def.h" 2651aa06e124ba688ca810b25ee0b5bb66678aac14Ray Essick#include "impd_drc_extr_delta_coded_info.h" 2751aa06e124ba688ca810b25ee0b5bb66678aac14Ray Essick#include "impd_drc_common.h" 2851aa06e124ba688ca810b25ee0b5bb66678aac14Ray Essick#include "impd_drc_struct.h" 2951aa06e124ba688ca810b25ee0b5bb66678aac14Ray Essick#include "impd_parametric_drc_dec.h" 3051aa06e124ba688ca810b25ee0b5bb66678aac14Ray Essick#include "impd_drc_filter_bank.h" 3151aa06e124ba688ca810b25ee0b5bb66678aac14Ray Essick#include "impd_drc_multi_band.h" 3251aa06e124ba688ca810b25ee0b5bb66678aac14Ray Essick#include "impd_drc_gain_dec.h" 3351aa06e124ba688ca810b25ee0b5bb66678aac14Ray Essick#include "impd_drc_process_audio.h" 3451aa06e124ba688ca810b25ee0b5bb66678aac14Ray Essick#include "impd_drc_interface.h" 3551aa06e124ba688ca810b25ee0b5bb66678aac14Ray Essick#include "impd_drc_gain_dec.h" 3651aa06e124ba688ca810b25ee0b5bb66678aac14Ray Essick#include "impd_drc_eq.h" 3751aa06e124ba688ca810b25ee0b5bb66678aac14Ray Essick#include "impd_drc_gain_decoder.h" 3851aa06e124ba688ca810b25ee0b5bb66678aac14Ray Essick#include "impd_drc_rom.h" 3951aa06e124ba688ca810b25ee0b5bb66678aac14Ray Essick 4051aa06e124ba688ca810b25ee0b5bb66678aac14Ray EssickWORD32 impd_shape_filt_block_adapt(const FLOAT32 drc_gain, 41b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block* shape_filter_block) { 42b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri // WORD32 err = 0; 43b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri WORD32 i; 44b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri FLOAT32 warpedGain, x1, y1; 45b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->drc_gain_last = drc_gain; 46b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri for (i = 0; i < 4; i++) { 47b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri if (shape_filter_block->shape_filter[i].type == SHAPE_FILTER_TYPE_OFF) 48b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri continue; 49b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri else if (shape_filter_block->shape_filter[i].type == 50b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri SHAPE_FILTER_TYPE_LF_CUT || 51b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[i].type == 52b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri SHAPE_FILTER_TYPE_HF_CUT) { 53b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri if (drc_gain < 1.0f) 54b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri warpedGain = -1.0f; 55b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri else 56b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri warpedGain = 57b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri (drc_gain - 1.0f) / 58b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri (drc_gain - 1.0f + shape_filter_block->shape_filter[i].gain_offset); 59b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri x1 = shape_filter_block->shape_filter[i].a1; 60b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri } else if (shape_filter_block->shape_filter[i].type == 61b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri SHAPE_FILTER_TYPE_LF_BOOST || 62b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[i].type == 63b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri SHAPE_FILTER_TYPE_HF_BOOST) { 64b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri if (drc_gain >= 1.0f) 65b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri warpedGain = -1.0f; 66b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri else 67b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri warpedGain = 68b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri (1.0f - drc_gain) / 69b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri (1.0f + 70b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri drc_gain * 71b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri (shape_filter_block->shape_filter[i].gain_offset - 1.0f)); 72b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri x1 = shape_filter_block->shape_filter[i].b1; 7351aa06e124ba688ca810b25ee0b5bb66678aac14Ray Essick } 744908247643e9e97852e847c00bfe7c4259279538Ray Essick 75b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri if (warpedGain <= 0.0f) { 76b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri y1 = x1; 77b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri } else if (warpedGain < 78b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[i].warped_gain_max) { 79b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri y1 = x1 + shape_filter_block->shape_filter[i].factor * warpedGain; 80b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri } else { 81b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri y1 = shape_filter_block->shape_filter[i].y1_bound; 8251aa06e124ba688ca810b25ee0b5bb66678aac14Ray Essick } 83b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri if (shape_filter_block->shape_filter[i].type == SHAPE_FILTER_TYPE_LF_CUT) { 84b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[i].b1 = y1; 85b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri } else if (shape_filter_block->shape_filter[i].type == 86b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri SHAPE_FILTER_TYPE_HF_CUT) { 87b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[i].g_norm = 88b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[i].coeff_sum / 89b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri (shape_filter_block->shape_filter[i].partial_coeff_sum + y1); 90b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[i].b1 = y1; 91b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri } else if (shape_filter_block->shape_filter[i].type == 92b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri SHAPE_FILTER_TYPE_HF_BOOST) { 93b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[i].g_norm = 94b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri (shape_filter_block->shape_filter[i].partial_coeff_sum + y1) / 95b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[i].coeff_sum; 96b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[i].a1 = y1; 97b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri } else if (shape_filter_block->shape_filter[i].type == 98b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri SHAPE_FILTER_TYPE_LF_BOOST) { 99b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[i].a1 = y1; 10051aa06e124ba688ca810b25ee0b5bb66678aac14Ray Essick } 101b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri } 102b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri return (0); 10351aa06e124ba688ca810b25ee0b5bb66678aac14Ray Essick} 10451aa06e124ba688ca810b25ee0b5bb66678aac14Ray Essick 105b3226ce6f80c78946aa3190cec158fb9852272eaRamesh KaturiWORD32 resetshape_flter_block(shape_filter_block* shape_filter_block) { 106b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri WORD32 i, c; 107b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->drc_gain_last = -1.0f; 108b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri impd_shape_filt_block_adapt(1.0f, shape_filter_block); 109b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri for (i = 0; i < 4; i++) { 110b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri for (c = 0; c < MAX_CHANNEL_COUNT; c++) { 111b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[i].audio_in_state_1[c] = 0.0f; 112b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[i].audio_in_state_2[c] = 0.0f; 113b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[i].audio_out_state_1[c] = 0.0f; 114b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[i].audio_out_state_2[c] = 0.0f; 11551aa06e124ba688ca810b25ee0b5bb66678aac14Ray Essick } 116b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri } 117b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri return (0); 11851aa06e124ba688ca810b25ee0b5bb66678aac14Ray Essick} 11951aa06e124ba688ca810b25ee0b5bb66678aac14Ray Essick 120b3226ce6f80c78946aa3190cec158fb9852272eaRamesh KaturiWORD32 impd_shape_filt_block_init( 121b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri ia_shape_filter_block_params_struct* shape_flter_block_params, 122b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block* shape_filter_block) { 123b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri // WORD32 err = 0; 124b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri FLOAT32 x1; 125b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri FLOAT32 x2 = 0.0f; 126b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri FLOAT32 radius; 127b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri if (shape_flter_block_params->lf_cut_filter_present) { 128b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri ia_shape_filter_params_struct* params = 129b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri &shape_flter_block_params->str_lf_cut_params; 130b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[0].type = SHAPE_FILTER_TYPE_LF_CUT; 131b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[0].gain_offset = 132b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filt_lf_gain_offset_tbl[params->corner_freq_index] 133b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri [params->filter_strength_index]; 134b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[0].y1_bound = 135b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filt_lf_y1_bound_tbl[params->corner_freq_index] 136b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri [params->filter_strength_index]; 137b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri x1 = -shape_filt_lf_radius_tbl[params->corner_freq_index]; 138b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[0].warped_gain_max = 139b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri SHAPE_FILTER_DRC_GAIN_MAX_MINUS_ONE / 140b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri (SHAPE_FILTER_DRC_GAIN_MAX_MINUS_ONE + 141b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[0].gain_offset); 142b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[0].factor = 143b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri (shape_filter_block->shape_filter[0].y1_bound - x1) / 144b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[0].warped_gain_max; 145b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[0].a1 = x1; 1464908247643e9e97852e847c00bfe7c4259279538Ray Essick 147b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri } else { 148b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[0].type = SHAPE_FILTER_TYPE_OFF; 149b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri } 150b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri if (shape_flter_block_params->lf_boost_filter_present) { 151b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri ia_shape_filter_params_struct* params = 152b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri &shape_flter_block_params->str_lf_boost_params; 153b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[1].type = SHAPE_FILTER_TYPE_LF_BOOST; 154b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[1].gain_offset = 155b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filt_lf_gain_offset_tbl[params->corner_freq_index] 156b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri [params->filter_strength_index]; 157b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[1].y1_bound = 158b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filt_lf_y1_bound_tbl[params->corner_freq_index] 159b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri [params->filter_strength_index]; 160b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri x1 = -shape_filt_lf_radius_tbl[params->corner_freq_index]; 161b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[1].warped_gain_max = 162b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri SHAPE_FILTER_DRC_GAIN_MAX_MINUS_ONE / 163b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri (SHAPE_FILTER_DRC_GAIN_MAX_MINUS_ONE + 164b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[1].gain_offset); 165b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[1].factor = 166b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri (shape_filter_block->shape_filter[1].y1_bound - x1) / 167b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[1].warped_gain_max; 168b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[1].b1 = x1; 1694908247643e9e97852e847c00bfe7c4259279538Ray Essick 170b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri } else { 171b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[1].type = SHAPE_FILTER_TYPE_OFF; 172b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri } 173b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri if (shape_flter_block_params->hf_cut_filter_present) { 174b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri ia_shape_filter_params_struct* params = 175b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri &shape_flter_block_params->str_hfCutParams; 176b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[2].type = SHAPE_FILTER_TYPE_HF_CUT; 177b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[2].gain_offset = 178b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filt_hf_gain_offset_tbl[params->corner_freq_index] 179b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri [params->filter_strength_index]; 180b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[2].y1_bound = 181b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filt_hf_y1_bound_tbl[params->corner_freq_index] 182b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri [params->filter_strength_index]; 183b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri radius = shape_filt_hf_radius_tbl[params->corner_freq_index]; 184b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri x1 = (FLOAT32)( 185b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri -2.0f * radius * 186b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri cos(2.0f * M_PI * 187b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filt_cutoff_freq_norm_hf_tbl[params->corner_freq_index])); 188b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri x2 = radius * radius; 189b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[2].warped_gain_max = 190b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri SHAPE_FILTER_DRC_GAIN_MAX_MINUS_ONE / 191b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri (SHAPE_FILTER_DRC_GAIN_MAX_MINUS_ONE + 192b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[2].gain_offset); 193b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[2].factor = 194b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri (shape_filter_block->shape_filter[2].y1_bound - x1) / 195b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[2].warped_gain_max; 196b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[2].coeff_sum = 1.0f + x1 + x2; 197b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[2].partial_coeff_sum = 1.0f + x2; 198b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[2].a1 = x1; 199b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[2].a2 = x2; 200b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[2].b2 = x2; 201b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri } else { 202b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[2].type = SHAPE_FILTER_TYPE_OFF; 203b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri } 204b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri if (shape_flter_block_params->hf_boost_filter_present) { 205b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri ia_shape_filter_params_struct* params = 206b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri &shape_flter_block_params->str_hf_boost_params; 207b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[3].type = SHAPE_FILTER_TYPE_HF_BOOST; 208b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[3].gain_offset = 209b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filt_hf_gain_offset_tbl[params->corner_freq_index] 210b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri [params->filter_strength_index]; 211b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[3].y1_bound = 212b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filt_hf_y1_bound_tbl[params->corner_freq_index] 213b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri [params->filter_strength_index]; 214b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri radius = shape_filt_hf_radius_tbl[params->corner_freq_index]; 215b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri x1 = (FLOAT32)( 216b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri -2.0f * radius * 217b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri cos(2.0f * M_PI * 218b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filt_cutoff_freq_norm_hf_tbl[params->corner_freq_index])); 219b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri x2 = radius * radius; 220b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[3].warped_gain_max = 221b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri SHAPE_FILTER_DRC_GAIN_MAX_MINUS_ONE / 222b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri (SHAPE_FILTER_DRC_GAIN_MAX_MINUS_ONE + 223b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[3].gain_offset); 224b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[3].factor = 225b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri (shape_filter_block->shape_filter[3].y1_bound - x1) / 226b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[3].warped_gain_max; 227b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[3].coeff_sum = 1.0f + x1 + x2; 228b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[3].partial_coeff_sum = 1.0f + x2; 229b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[3].b1 = x1; 230b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[3].b2 = x2; 231b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[3].a2 = x2; 2324908247643e9e97852e847c00bfe7c4259279538Ray Essick 233b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri } else { 234b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[3].type = SHAPE_FILTER_TYPE_OFF; 235b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri } 236b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri resetshape_flter_block(shape_filter_block); 237b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_flter_block_flag = 1; 238b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri return (0); 23951aa06e124ba688ca810b25ee0b5bb66678aac14Ray Essick} 24051aa06e124ba688ca810b25ee0b5bb66678aac14Ray Essick 241b3226ce6f80c78946aa3190cec158fb9852272eaRamesh KaturiWORD32 impd_shape_filt_block_time_process( 242b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block* shape_filter_block, FLOAT32* drc_gain, 243b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri const WORD32 channel, FLOAT32* audio_in, WORD32 start, WORD32 end) { 244b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri WORD32 i, j, err = 0; 245b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri FLOAT32 audio_out; 24651aa06e124ba688ca810b25ee0b5bb66678aac14Ray Essick 247b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri if (shape_filter_block->shape_flter_block_flag) { 248b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri for (i = start; i < end; i++) { 249b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri FLOAT32 tmp = audio_in[i]; 250b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri for (j = 0; j < 4; j++) { 251b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri if (shape_filter_block->shape_filter[j].type == 252b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri SHAPE_FILTER_TYPE_LF_CUT || 253b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[j].type == 254b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri SHAPE_FILTER_TYPE_LF_BOOST) { 255b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri audio_out = tmp + 256b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[j].b1 * 257b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[j] 258b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri .audio_in_state_1[channel] - 259b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[j].a1 * 260b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[j] 261b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri .audio_out_state_1[channel]; 262b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[j].audio_in_state_1[channel] = tmp; 263b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[j].audio_out_state_1[channel] = 264b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri audio_out; 26551aa06e124ba688ca810b25ee0b5bb66678aac14Ray Essick 266b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri } else if (shape_filter_block->shape_filter[j].type == 267b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri SHAPE_FILTER_TYPE_HF_CUT || 268b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[j].type == 269b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri SHAPE_FILTER_TYPE_HF_BOOST) { 270b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri audio_out = shape_filter_block->shape_filter[j].g_norm * tmp + 271b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[j].b1 * 272b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[j] 273b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri .audio_in_state_1[channel] + 274b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[j].b2 * 275b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[j] 276b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri .audio_in_state_2[channel] - 277b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[j].a1 * 278b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[j] 279b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri .audio_out_state_1[channel] - 280b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[j].a2 * 281b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[j] 282b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri .audio_out_state_2[channel]; 283b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[j].audio_in_state_2[channel] = 284b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[j].audio_in_state_1[channel]; 285b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[j].audio_in_state_1[channel] = 286b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[j].g_norm * tmp; 287b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[j].audio_out_state_2[channel] = 288b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[j].audio_out_state_1[channel]; 289b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri shape_filter_block->shape_filter[j].audio_out_state_1[channel] = 290b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri audio_out; 291b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri } else { 292b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri audio_out = tmp; 29351aa06e124ba688ca810b25ee0b5bb66678aac14Ray Essick } 294b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri tmp = audio_out; 295b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri } 29651aa06e124ba688ca810b25ee0b5bb66678aac14Ray Essick 297b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri audio_in[i] = audio_out * drc_gain[i]; 29851aa06e124ba688ca810b25ee0b5bb66678aac14Ray Essick } 2994908247643e9e97852e847c00bfe7c4259279538Ray Essick 300b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri } else { 301b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri for (i = start; i < end; i++) { 302b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri audio_in[i] = audio_in[i] * drc_gain[i]; 30351aa06e124ba688ca810b25ee0b5bb66678aac14Ray Essick } 304b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri } 3054908247643e9e97852e847c00bfe7c4259279538Ray Essick 306b3226ce6f80c78946aa3190cec158fb9852272eaRamesh Katuri return err; 30751aa06e124ba688ca810b25ee0b5bb66678aac14Ray Essick} 308