1 /****************************************************************************** 2 * * 3 * Copyright (C) 2023 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 21 #pragma once 22 #define LEN_RING_BUF (12) 23 #define LEN_RING_BUF_SOS_1 (2) 24 #define LEN_RING_BUF_SOS_2 (10) 25 #define IIR_NUM_COEFFS (6) 26 #define IIR_DEN_COEFFS (11) 27 #define IIR_SOS_STAGES (5) 28 #define IIR_SOS_COEFFS (3) 29 30 typedef struct { 31 const FLOAT32 *ptr_coeff_iir_num; 32 const FLOAT32 *ptr_coeff_iir_den; 33 WORD32 max; 34 FLOAT32 ring_buf_1[LEN_RING_BUF]; 35 FLOAT32 ring_buf_2[LEN_RING_BUF]; 36 } ixheaace_iir_filter; 37 38 typedef struct { 39 const FLOAT32 *ptr_coeff_iir_num; 40 const FLOAT32 *ptr_coeff_iir_den; 41 FLOAT32 gain_sos; 42 FLOAT32 ring_buf_sos_1[LEN_RING_BUF_SOS_1]; 43 FLOAT32 ring_buf_sos_2[LEN_RING_BUF_SOS_2]; 44 } ixheaace_iir_sos_filter; 45 46 struct ixheaace_iir_params { 47 const FLOAT32 coeff_iir_num[IIR_NUM_COEFFS]; 48 const FLOAT32 coeff_iir_den[IIR_DEN_COEFFS]; 49 const WORD32 max; 50 const WORD32 delay; 51 }; 52 53 struct ixheaace_iir_params_sos { 54 const FLOAT32 coeff_iir_sos_num[IIR_SOS_STAGES][IIR_SOS_COEFFS]; 55 const FLOAT32 coeff_iir_sos_den[IIR_SOS_STAGES][IIR_SOS_COEFFS]; 56 const FLOAT32 gain_sos; 57 const WORD32 delay; 58 }; 59 60 typedef struct { 61 struct ixheaace_iir_params const iir_param_set; 62 } ixheaace_resampler_table; 63 64 typedef struct { 65 struct ixheaace_iir_params_sos const iir_param_set_sos; 66 } ixheaace_resampler_sos_table; 67 68 typedef struct { 69 ixheaace_iir_filter iir_filter; 70 WORD32 ratio; 71 WORD32 delay; 72 WORD32 pending; 73 } ixheaace_iir21_resampler; 74 75 typedef struct { 76 ixheaace_iir_sos_filter iir_filter; 77 WORD32 ratio; 78 WORD32 delay; 79 WORD32 pending; 80 } ixheaace_iir_sos_resampler; 81 82 typedef struct { 83 FLOAT32 downsampler_in_buffer[INPUT_LEN_DOWNSAMPLE * IXHEAACE_MAX_CH_IN_BS_ELE * UPSAMPLE_FAC]; 84 FLOAT32 85 downsampler_out_buffer[INPUT_LEN_DOWNSAMPLE * IXHEAACE_MAX_CH_IN_BS_ELE * UPSAMPLE_FAC]; 86 FLOAT32 scratch_buf1_temp[IIR_SOS_COEFFS]; 87 FLOAT32 scratch_buf2_temp[IIR_SOS_COEFFS]; 88 FLOAT32 ring_buf_temp[LEN_RING_BUF]; 89 } ixheaace_resampler_scratch; 90 91 WORD32 ixheaace_resampler_scr_size(VOID); 92 93 VOID ixheaace_get_input_scratch_buf(VOID *ptr_scr, FLOAT32 **ptr_scratch_buf_inp); 94 95 IA_ERRORCODE ia_enhaacplus_enc_init_iir_resampler(ixheaace_iir21_resampler *pstr_resampler, 96 WORD32 ratio, 97 ixheaace_resampler_table *pstr_resampler_table); 98 99 VOID ia_enhaacplus_enc_iir_downsampler(ixheaace_iir21_resampler *pstr_down_sampler, 100 FLOAT32 *ptr_in_samples, WORD32 num_in_samples, 101 WORD32 in_stride, FLOAT32 *ptr_out_samples, 102 WORD32 *num_out_samples, WORD32 out_stride, 103 FLOAT32 *ptr_ring_buf1, FLOAT32 *ptr_ring_buf2, 104 ixheaace_resampler_scratch *pstr_resampler_scratch); 105 106 VOID ia_enhaacplus_enc_iir_sos_downsampler(ixheaace_iir_sos_resampler *pstr_down_sampler, 107 FLOAT32 *ptr_in_samples, WORD32 num_in_samples, 108 WORD32 in_stride, FLOAT32 *ptr_out_samples, 109 WORD32 *num_out_samples, FLOAT32 *ptr_ring_buf1, 110 FLOAT32 *ptr_ring_buf2, 111 ixheaace_resampler_scratch *pstr_resampler_scratch); 112 113 VOID ia_enhaacplus_enc_iir_sos_upsampler(ixheaace_iir_sos_resampler *pstr_up_sampler, 114 FLOAT32 *ptr_in_samples, WORD32 num_in_samples, 115 WORD32 in_stride, FLOAT32 *ptr_out_samples, 116 WORD32 *num_out_samples, FLOAT32 *ptr_ring_buf1, 117 FLOAT32 *ptr_ring_buf2, 118 ixheaace_resampler_scratch *pstr_resampler_scratch); 119 120 WORD32 ia_enhaacplus_enc_compute_resampling_ratio(WORD32 ccfl_idx); 121 122 VOID ixheaace_upsampling_inp_buf_generation(FLOAT32 *ptr_inp_buf, FLOAT32 *ptr_temp_buf, 123 WORD32 num_samples, WORD32 upsamp_fac, WORD32 offset); 124 125 IA_ERRORCODE 126 ia_enhaacplus_enc_init_iir_sos_resampler(ixheaace_iir_sos_resampler *pstr_resampler, WORD32 ratio, 127 ixheaace_resampler_sos_table *pstr_resampler_table);