xref: /aosp_15_r20/external/libxaac/encoder/ixheaace_interface.c (revision 15dc779a375ca8b5125643b829a8aa4b70d7f451)
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 #include <string.h>
22 #include "ixheaac_type_def.h"
23 #include "ixheaac_constants.h"
24 #include "ixheaace_aac_constants.h"
25 
26 #include "ixheaace_psy_const.h"
27 #include "ixheaace_tns.h"
28 #include "ixheaace_tns_params.h"
29 #include "ixheaace_rom.h"
30 #include "ixheaace_common_rom.h"
31 #include "ixheaace_bitbuffer.h"
32 #include "ixheaace_block_switch.h"
33 #include "ixheaace_psy_data.h"
34 #include "ixheaace_interface.h"
35 
ia_enhaacplus_enc_build_interface(FLOAT32 * ptr_grouped_mdct_spec,ixheaace_sfb_energy * pstr_grouped_sfb_thres,ixheaace_sfb_energy * pstr_grouped_sfb_nrg,ixheaace_sfb_energy * pstr_grouped_sfb_spreaded_nrg,const ixheaace_sfb_energy_sum sfb_nrg_sum_lr,const ixheaace_sfb_energy_sum sfb_nrg_sum_ms,const WORD32 win_seq,const WORD32 win_shape,const WORD32 grouped_sfb_cnt,const WORD32 * ptr_grouped_sfb_offset,const WORD32 max_sfb_per_grp,const FLOAT32 * ptr_grouped_sfb_min_snr,const WORD32 total_groups_cnt,const WORD32 * ptr_group_len,ixheaace_psy_out_channel * pstr_psy_out_ch)36 VOID ia_enhaacplus_enc_build_interface(
37     FLOAT32 *ptr_grouped_mdct_spec, ixheaace_sfb_energy *pstr_grouped_sfb_thres,
38     ixheaace_sfb_energy *pstr_grouped_sfb_nrg, ixheaace_sfb_energy *pstr_grouped_sfb_spreaded_nrg,
39     const ixheaace_sfb_energy_sum sfb_nrg_sum_lr, const ixheaace_sfb_energy_sum sfb_nrg_sum_ms,
40     const WORD32 win_seq, const WORD32 win_shape, const WORD32 grouped_sfb_cnt,
41     const WORD32 *ptr_grouped_sfb_offset, const WORD32 max_sfb_per_grp,
42     const FLOAT32 *ptr_grouped_sfb_min_snr, const WORD32 total_groups_cnt,
43     const WORD32 *ptr_group_len, ixheaace_psy_out_channel *pstr_psy_out_ch) {
44   WORD32 j;
45   WORD32 grp;
46   WORD32 mask;
47 
48   /* Copy values to psy_out */
49   pstr_psy_out_ch->max_sfb_per_grp = max_sfb_per_grp;
50   pstr_psy_out_ch->sfb_count = grouped_sfb_cnt;
51   pstr_psy_out_ch->sfb_per_group = grouped_sfb_cnt / total_groups_cnt;
52   pstr_psy_out_ch->window_sequence = win_seq;
53   pstr_psy_out_ch->window_shape = win_shape;
54   pstr_psy_out_ch->ptr_spec_coeffs = ptr_grouped_mdct_spec;
55 
56   pstr_psy_out_ch->ptr_sfb_energy = pstr_grouped_sfb_nrg->long_nrg;
57   pstr_psy_out_ch->ptr_sfb_thr = pstr_grouped_sfb_thres->long_nrg;
58   pstr_psy_out_ch->ptr_sfb_spread_energy = pstr_grouped_sfb_spreaded_nrg->long_nrg;
59 
60   memcpy(&pstr_psy_out_ch->sfb_offsets[0], &ptr_grouped_sfb_offset[0],
61          sizeof(pstr_psy_out_ch->sfb_offsets[0]) * (grouped_sfb_cnt + 1));
62   memcpy(&pstr_psy_out_ch->sfb_min_snr[0], &ptr_grouped_sfb_min_snr[0],
63          sizeof(pstr_psy_out_ch->sfb_min_snr[0]) * (grouped_sfb_cnt));
64 
65   /* Generate grouping mask */
66   mask = 0;
67 
68   for (grp = 0; grp < total_groups_cnt; grp++) {
69     mask <<= 1;
70 
71     for (j = 1; j < ptr_group_len[grp]; j++) {
72       mask <<= 1;
73       mask |= 1;
74     }
75   }
76   /* copy energy sums to psy_out for stereo preprocessing */
77   if (win_seq != SHORT_WINDOW) {
78     pstr_psy_out_ch->sfb_sum_lr_energy = sfb_nrg_sum_lr.long_nrg;
79     pstr_psy_out_ch->sfb_sum_ms_energy = sfb_nrg_sum_ms.long_nrg;
80   } else {
81     int i;
82 
83     pstr_psy_out_ch->sfb_sum_ms_energy = 0;
84     pstr_psy_out_ch->sfb_sum_lr_energy = 0;
85 
86     for (i = 0; i < TRANS_FAC; i++) {
87       pstr_psy_out_ch->sfb_sum_lr_energy += sfb_nrg_sum_lr.short_nrg[i];
88       pstr_psy_out_ch->sfb_sum_ms_energy += sfb_nrg_sum_ms.short_nrg[i];
89     }
90   }
91 
92   pstr_psy_out_ch->grouping_mask = mask;
93 }
94