xref: /aosp_15_r20/external/libxaac/encoder/ixheaace_loudness_measurement.h (revision 15dc779a375ca8b5125643b829a8aa4b70d7f451)
1 /******************************************************************************
2  *                                                                            *
3  * Copyright (C) 2024 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 
23 #define IXHEAACE_LOUDNESS_NUM_TAPS (3)
24 #define IXHEAACE_LOUDNESS_PRE_FLT (0)
25 #define IXHEAACE_LOUDNESS_RLB_FLT (1)
26 #define IXHEAACE_LOUDNESS_DONT_PASS (-1)
27 #define IXHEAACE_ABS_GATE (-70)
28 #define IXHEAACE_MOMENTARY_LOUDNESS_OVERLAP (3)
29 #define IXHEAACE_SL_OVERLAP (20)
30 #define BYTE_ALIGN_8 (8)
31 #define MAX(a, b) ((a) > (b) ? (a) : (b))
32 #define IXHEAACE_DEFAULT_SHORT_TERM_LOUDENSS (-1000)
33 #define IXHEAACE_DEFAULT_MOMENTARY_LOUDENSS (-1000)
34 #define IXHEAACE_SEC_TO_100MS_FACTOR (60 * 10)
35 
36 typedef struct {
37   BOOL passes_abs_gate;
38   FLOAT64 short_term_loudness;
39   FLOAT64 int_val;
40 } short_term_frame_t;
41 
42 typedef struct {
43   BOOL passes_abs_gate;
44   FLOAT64 momentary_loudness;
45   FLOAT64 int_val;
46 } momentary_frame_t;
47 typedef struct {
48   UWORD32 num_samples_per_ch;
49   UWORD32 n_channels;
50   UWORD32 length;
51   UWORD32 sample_rate;
52   UWORD32 pcm_sz;
53   FLOAT64 sum_square;
54   FLOAT64 prev_four_sum_square[4];
55   FLOAT64 w[2][2][4];
56   UWORD32 count_fn_call_mmstl;
57   UWORD32 mom_loudness_first_time_flag;
58   FLOAT64 average_loudness_val;
59   FLOAT64 prev_thirty_sum_square[30];
60   WORD32 sl_first_time_flag;
61   WORD32 local_sl_count;
62   UWORD32 short_term_loudness_overlap;
63   short_term_frame_t stf_instances[100];
64   UWORD32 no_of_stf;
65   UWORD32 curr_stf_no;
66   UWORD32 loop_curr_stf_no;
67   UWORD32 no_of_stf_passing_abs_gate;
68   FLOAT64 tot_int_val_stf_passing_abs_gate;
69   FLOAT64 temp_stf_instances_loudness[100];
70   BOOL get_LRA;
71   UWORD32 max_lra_count;
72   UWORD32 no_of_mf;
73 
74   UWORD32 no_of_mf_passing_abs_gate;
75   FLOAT64 tot_int_val_mf_passing_abs_gate;
76   UWORD32 no_of_mf_passing_rel_gate;
77   FLOAT64 tot_int_val_mf_passing_rel_gate;
78   FLOAT64 rel_gate;
79   UWORD32 ml_count_fn_call;
80   UWORD32 loop_ml_count_fn_call;
81   momentary_frame_t mf_instances[1000];
82   WORD32 get_intergrated_loudness;
83   UWORD32 max_il_buf_size;
84   FLOAT64 max_sample_val;
85   WORD32 sample_rate_idx;
86 } ixheaace_loudness_struct;
87 
88 IA_ERRORCODE ixheaace_loudness_init_params(pVOID loudness_handle,
89                                            ixheaace_input_config *pstr_input_config,
90                                            ixheaace_output_config *pstr_output_config);
91 
92 FLOAT64 ixheaace_measure_loudness(pVOID loudness_handle, WORD16 **samples);
93 
94 FLOAT64 ixheaace_measure_integrated_loudness(pVOID loudness_handle);
95 
96 WORD32 ixheaace_loudness_info_get_handle_size();
97 
98 FLOAT32 ixheaace_measure_sample_peak_value(pVOID loudness_handle);