xref: /aosp_15_r20/external/libxaac/encoder/ixheaace_resampler.h (revision 15dc779a375ca8b5125643b829a8aa4b70d7f451)
1*15dc779aSAndroid Build Coastguard Worker /******************************************************************************
2*15dc779aSAndroid Build Coastguard Worker  *                                                                            *
3*15dc779aSAndroid Build Coastguard Worker  * Copyright (C) 2023 The Android Open Source Project
4*15dc779aSAndroid Build Coastguard Worker  *
5*15dc779aSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
6*15dc779aSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
7*15dc779aSAndroid Build Coastguard Worker  * You may obtain a copy of the License at:
8*15dc779aSAndroid Build Coastguard Worker  *
9*15dc779aSAndroid Build Coastguard Worker  * http://www.apache.org/licenses/LICENSE-2.0
10*15dc779aSAndroid Build Coastguard Worker  *
11*15dc779aSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
12*15dc779aSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
13*15dc779aSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*15dc779aSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
15*15dc779aSAndroid Build Coastguard Worker  * limitations under the License.
16*15dc779aSAndroid Build Coastguard Worker  *
17*15dc779aSAndroid Build Coastguard Worker  *****************************************************************************
18*15dc779aSAndroid Build Coastguard Worker  * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19*15dc779aSAndroid Build Coastguard Worker  */
20*15dc779aSAndroid Build Coastguard Worker 
21*15dc779aSAndroid Build Coastguard Worker #pragma once
22*15dc779aSAndroid Build Coastguard Worker #define LEN_RING_BUF (12)
23*15dc779aSAndroid Build Coastguard Worker #define LEN_RING_BUF_SOS_1 (2)
24*15dc779aSAndroid Build Coastguard Worker #define LEN_RING_BUF_SOS_2 (10)
25*15dc779aSAndroid Build Coastguard Worker #define IIR_NUM_COEFFS (6)
26*15dc779aSAndroid Build Coastguard Worker #define IIR_DEN_COEFFS (11)
27*15dc779aSAndroid Build Coastguard Worker #define IIR_SOS_STAGES (5)
28*15dc779aSAndroid Build Coastguard Worker #define IIR_SOS_COEFFS (3)
29*15dc779aSAndroid Build Coastguard Worker 
30*15dc779aSAndroid Build Coastguard Worker typedef struct {
31*15dc779aSAndroid Build Coastguard Worker   const FLOAT32 *ptr_coeff_iir_num;
32*15dc779aSAndroid Build Coastguard Worker   const FLOAT32 *ptr_coeff_iir_den;
33*15dc779aSAndroid Build Coastguard Worker   WORD32 max;
34*15dc779aSAndroid Build Coastguard Worker   FLOAT32 ring_buf_1[LEN_RING_BUF];
35*15dc779aSAndroid Build Coastguard Worker   FLOAT32 ring_buf_2[LEN_RING_BUF];
36*15dc779aSAndroid Build Coastguard Worker } ixheaace_iir_filter;
37*15dc779aSAndroid Build Coastguard Worker 
38*15dc779aSAndroid Build Coastguard Worker typedef struct {
39*15dc779aSAndroid Build Coastguard Worker   const FLOAT32 *ptr_coeff_iir_num;
40*15dc779aSAndroid Build Coastguard Worker   const FLOAT32 *ptr_coeff_iir_den;
41*15dc779aSAndroid Build Coastguard Worker   FLOAT32 gain_sos;
42*15dc779aSAndroid Build Coastguard Worker   FLOAT32 ring_buf_sos_1[LEN_RING_BUF_SOS_1];
43*15dc779aSAndroid Build Coastguard Worker   FLOAT32 ring_buf_sos_2[LEN_RING_BUF_SOS_2];
44*15dc779aSAndroid Build Coastguard Worker } ixheaace_iir_sos_filter;
45*15dc779aSAndroid Build Coastguard Worker 
46*15dc779aSAndroid Build Coastguard Worker struct ixheaace_iir_params {
47*15dc779aSAndroid Build Coastguard Worker   const FLOAT32 coeff_iir_num[IIR_NUM_COEFFS];
48*15dc779aSAndroid Build Coastguard Worker   const FLOAT32 coeff_iir_den[IIR_DEN_COEFFS];
49*15dc779aSAndroid Build Coastguard Worker   const WORD32 max;
50*15dc779aSAndroid Build Coastguard Worker   const WORD32 delay;
51*15dc779aSAndroid Build Coastguard Worker };
52*15dc779aSAndroid Build Coastguard Worker 
53*15dc779aSAndroid Build Coastguard Worker struct ixheaace_iir_params_sos {
54*15dc779aSAndroid Build Coastguard Worker   const FLOAT32 coeff_iir_sos_num[IIR_SOS_STAGES][IIR_SOS_COEFFS];
55*15dc779aSAndroid Build Coastguard Worker   const FLOAT32 coeff_iir_sos_den[IIR_SOS_STAGES][IIR_SOS_COEFFS];
56*15dc779aSAndroid Build Coastguard Worker   const FLOAT32 gain_sos;
57*15dc779aSAndroid Build Coastguard Worker   const WORD32 delay;
58*15dc779aSAndroid Build Coastguard Worker };
59*15dc779aSAndroid Build Coastguard Worker 
60*15dc779aSAndroid Build Coastguard Worker typedef struct {
61*15dc779aSAndroid Build Coastguard Worker   struct ixheaace_iir_params const iir_param_set;
62*15dc779aSAndroid Build Coastguard Worker } ixheaace_resampler_table;
63*15dc779aSAndroid Build Coastguard Worker 
64*15dc779aSAndroid Build Coastguard Worker typedef struct {
65*15dc779aSAndroid Build Coastguard Worker   struct ixheaace_iir_params_sos const iir_param_set_sos;
66*15dc779aSAndroid Build Coastguard Worker } ixheaace_resampler_sos_table;
67*15dc779aSAndroid Build Coastguard Worker 
68*15dc779aSAndroid Build Coastguard Worker typedef struct {
69*15dc779aSAndroid Build Coastguard Worker   ixheaace_iir_filter iir_filter;
70*15dc779aSAndroid Build Coastguard Worker   WORD32 ratio;
71*15dc779aSAndroid Build Coastguard Worker   WORD32 delay;
72*15dc779aSAndroid Build Coastguard Worker   WORD32 pending;
73*15dc779aSAndroid Build Coastguard Worker } ixheaace_iir21_resampler;
74*15dc779aSAndroid Build Coastguard Worker 
75*15dc779aSAndroid Build Coastguard Worker typedef struct {
76*15dc779aSAndroid Build Coastguard Worker   ixheaace_iir_sos_filter iir_filter;
77*15dc779aSAndroid Build Coastguard Worker   WORD32 ratio;
78*15dc779aSAndroid Build Coastguard Worker   WORD32 delay;
79*15dc779aSAndroid Build Coastguard Worker   WORD32 pending;
80*15dc779aSAndroid Build Coastguard Worker } ixheaace_iir_sos_resampler;
81*15dc779aSAndroid Build Coastguard Worker 
82*15dc779aSAndroid Build Coastguard Worker typedef struct {
83*15dc779aSAndroid Build Coastguard Worker   FLOAT32 downsampler_in_buffer[INPUT_LEN_DOWNSAMPLE * IXHEAACE_MAX_CH_IN_BS_ELE * UPSAMPLE_FAC];
84*15dc779aSAndroid Build Coastguard Worker   FLOAT32
85*15dc779aSAndroid Build Coastguard Worker   downsampler_out_buffer[INPUT_LEN_DOWNSAMPLE * IXHEAACE_MAX_CH_IN_BS_ELE * UPSAMPLE_FAC];
86*15dc779aSAndroid Build Coastguard Worker   FLOAT32 scratch_buf1_temp[IIR_SOS_COEFFS];
87*15dc779aSAndroid Build Coastguard Worker   FLOAT32 scratch_buf2_temp[IIR_SOS_COEFFS];
88*15dc779aSAndroid Build Coastguard Worker   FLOAT32 ring_buf_temp[LEN_RING_BUF];
89*15dc779aSAndroid Build Coastguard Worker } ixheaace_resampler_scratch;
90*15dc779aSAndroid Build Coastguard Worker 
91*15dc779aSAndroid Build Coastguard Worker WORD32 ixheaace_resampler_scr_size(VOID);
92*15dc779aSAndroid Build Coastguard Worker 
93*15dc779aSAndroid Build Coastguard Worker VOID ixheaace_get_input_scratch_buf(VOID *ptr_scr, FLOAT32 **ptr_scratch_buf_inp);
94*15dc779aSAndroid Build Coastguard Worker 
95*15dc779aSAndroid Build Coastguard Worker IA_ERRORCODE ia_enhaacplus_enc_init_iir_resampler(ixheaace_iir21_resampler *pstr_resampler,
96*15dc779aSAndroid Build Coastguard Worker                                                   WORD32 ratio,
97*15dc779aSAndroid Build Coastguard Worker                                                   ixheaace_resampler_table *pstr_resampler_table);
98*15dc779aSAndroid Build Coastguard Worker 
99*15dc779aSAndroid Build Coastguard Worker VOID ia_enhaacplus_enc_iir_downsampler(ixheaace_iir21_resampler *pstr_down_sampler,
100*15dc779aSAndroid Build Coastguard Worker                                        FLOAT32 *ptr_in_samples, WORD32 num_in_samples,
101*15dc779aSAndroid Build Coastguard Worker                                        WORD32 in_stride, FLOAT32 *ptr_out_samples,
102*15dc779aSAndroid Build Coastguard Worker                                        WORD32 *num_out_samples, WORD32 out_stride,
103*15dc779aSAndroid Build Coastguard Worker                                        FLOAT32 *ptr_ring_buf1, FLOAT32 *ptr_ring_buf2,
104*15dc779aSAndroid Build Coastguard Worker                                        ixheaace_resampler_scratch *pstr_resampler_scratch);
105*15dc779aSAndroid Build Coastguard Worker 
106*15dc779aSAndroid Build Coastguard Worker VOID ia_enhaacplus_enc_iir_sos_downsampler(ixheaace_iir_sos_resampler *pstr_down_sampler,
107*15dc779aSAndroid Build Coastguard Worker                                            FLOAT32 *ptr_in_samples, WORD32 num_in_samples,
108*15dc779aSAndroid Build Coastguard Worker                                            WORD32 in_stride, FLOAT32 *ptr_out_samples,
109*15dc779aSAndroid Build Coastguard Worker                                            WORD32 *num_out_samples, FLOAT32 *ptr_ring_buf1,
110*15dc779aSAndroid Build Coastguard Worker                                            FLOAT32 *ptr_ring_buf2,
111*15dc779aSAndroid Build Coastguard Worker                                            ixheaace_resampler_scratch *pstr_resampler_scratch);
112*15dc779aSAndroid Build Coastguard Worker 
113*15dc779aSAndroid Build Coastguard Worker VOID ia_enhaacplus_enc_iir_sos_upsampler(ixheaace_iir_sos_resampler *pstr_up_sampler,
114*15dc779aSAndroid Build Coastguard Worker                                          FLOAT32 *ptr_in_samples, WORD32 num_in_samples,
115*15dc779aSAndroid Build Coastguard Worker                                          WORD32 in_stride, FLOAT32 *ptr_out_samples,
116*15dc779aSAndroid Build Coastguard Worker                                          WORD32 *num_out_samples, FLOAT32 *ptr_ring_buf1,
117*15dc779aSAndroid Build Coastguard Worker                                          FLOAT32 *ptr_ring_buf2,
118*15dc779aSAndroid Build Coastguard Worker                                          ixheaace_resampler_scratch *pstr_resampler_scratch);
119*15dc779aSAndroid Build Coastguard Worker 
120*15dc779aSAndroid Build Coastguard Worker WORD32 ia_enhaacplus_enc_compute_resampling_ratio(WORD32 ccfl_idx);
121*15dc779aSAndroid Build Coastguard Worker 
122*15dc779aSAndroid Build Coastguard Worker VOID ixheaace_upsampling_inp_buf_generation(FLOAT32 *ptr_inp_buf, FLOAT32 *ptr_temp_buf,
123*15dc779aSAndroid Build Coastguard Worker                                             WORD32 num_samples, WORD32 upsamp_fac, WORD32 offset);
124*15dc779aSAndroid Build Coastguard Worker 
125*15dc779aSAndroid Build Coastguard Worker IA_ERRORCODE
126*15dc779aSAndroid Build Coastguard Worker ia_enhaacplus_enc_init_iir_sos_resampler(ixheaace_iir_sos_resampler *pstr_resampler, WORD32 ratio,
127*15dc779aSAndroid Build Coastguard Worker                                          ixheaace_resampler_sos_table *pstr_resampler_table);