xref: /aosp_15_r20/external/libxaac/encoder/ixheaace_psy_utils.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 #include "ixheaace_psy_utils.h"
26 #include "ixheaac_basic_ops32.h"
27 #include "ixheaac_basic_ops16.h"
28 #include "ixheaac_basic_ops40.h"
29 #include "ixheaac_basic_ops.h"
30 
ia_enhaacplus_enc_init_pre_echo_control(FLOAT32 * ptr_pb_threshold_nm1,WORD32 num_pb,FLOAT32 * ptr_pb_threshold_quiet)31 VOID ia_enhaacplus_enc_init_pre_echo_control(FLOAT32 *ptr_pb_threshold_nm1, WORD32 num_pb,
32                                              FLOAT32 *ptr_pb_threshold_quiet) {
33   memcpy(ptr_pb_threshold_nm1, ptr_pb_threshold_quiet, num_pb * sizeof(*ptr_pb_threshold_nm1));
34 }
35 
ia_enhaacplus_enc_pre_echo_control(FLOAT32 * ptr_threshold_nm1,WORD32 num_sfb,FLOAT32 min_rem_thr_factor,FLOAT32 * ptr_threshold)36 VOID ia_enhaacplus_enc_pre_echo_control(FLOAT32 *ptr_threshold_nm1, WORD32 num_sfb,
37                                         FLOAT32 min_rem_thr_factor, FLOAT32 *ptr_threshold) {
38   WORD32 i;
39   FLOAT32 tmp_threshold1, tmp_threshold2;
40   FLOAT32 *ptr_tmp_threshold = &ptr_threshold[0];
41   FLOAT32 *ptr_tmp_threshold_nm1 = &ptr_threshold_nm1[0];
42 
43   for (i = num_sfb - 1; i >= 0; i--) {
44     FLOAT32 tmp_var;
45 
46     tmp_var = *ptr_tmp_threshold;
47 
48     tmp_threshold1 = *ptr_tmp_threshold_nm1 * 2.0f;
49 
50     tmp_threshold2 = (min_rem_thr_factor * tmp_var);
51 
52     /* copy thresholds to internal memory */
53     *ptr_tmp_threshold_nm1++ = tmp_var;
54 
55     tmp_var = MIN(tmp_var, tmp_threshold1);
56 
57     tmp_var = MAX(tmp_var, tmp_threshold2);
58     *ptr_tmp_threshold++ = tmp_var;
59   }
60 }
61