xref: /aosp_15_r20/external/libxaac/encoder/iusace_tns_usac.h (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 #pragma once
22 #define LN (2048)
23 #define SN (256)
24 #define LN2 (LN / 2)
25 #define NSHORT (LN / SN)
26 
27 #define TNS_MAX_ORDER 31
28 #define DEF_TNS_GAIN_THRESH 1.41
29 #define DEF_TNS_COEFF_THRESH 0.1
30 #define DEF_TNS_RES_OFFSET 3
31 
32 #ifndef PI
33 #define PI 3.14159265358979323846
34 #endif
35 
36 typedef struct {
37   WORD32 order;                        /**< Filter order */
38   WORD32 direction;                    /**< Filtering direction */
39   WORD32 coef_compress;                /**< Are coeffs compressed? */
40   WORD32 length;                       /**< Length, in bands */
41   FLOAT64 a_coeffs[TNS_MAX_ORDER + 1]; /**< AR Coefficients */
42   FLOAT64 k_coeffs[TNS_MAX_ORDER + 1]; /**< Reflection Coefficients */
43   WORD32 index[TNS_MAX_ORDER + 1];     /**< Coefficient indices */
44 } ia_tns_filter_data;
45 
46 typedef struct {
47   WORD32 n_filt;                    /**< number of filters */
48   WORD32 coef_res;                  /**< Coefficient resolution */
49   ia_tns_filter_data tns_filter[3]; /**< TNS filters */
50   FLOAT64 tns_pred_gain;
51   WORD32 tns_active;
52 } ia_tns_window_data;
53 
54 typedef struct {
55   WORD32 tns_data_present;
56   WORD32 tns_min_band_number_long;
57   WORD32 tns_min_band_number_short;
58   WORD32 tns_max_bands_long;
59   WORD32 tns_max_bands_short;
60   WORD32 tns_max_order_long;
61   WORD32 tns_max_order_short;
62   WORD32 lpc_start_band_long;
63   WORD32 lpc_start_band_short;
64   WORD32 lpc_stop_band_long;
65   WORD32 lpc_stop_band_short;
66   ia_tns_window_data window_data[NSHORT]; /**< TNS data per window */
67   WORD32 *sfb_offset_table_short;         /**< Scalefactor band offset table */
68   WORD32 *sfb_offset_table_short_tcx;     /**< Scalefactor band offset table */
69   WORD32 *sfb_offset_table_long;          /**< Scalefactor band offset table */
70   WORD32 max_sfb_short;                   /**< max_sfb */
71   WORD32 max_sfb_long;                    /**< max_sfb */
72   FLOAT32 threshold;
73   FLOAT32 tns_time_res_short;
74   FLOAT32 tns_time_res_long;
75   FLOAT64 win_short[8];
76   FLOAT64 win_long[16];
77   WORD32 block_type;      /**< block type */
78   WORD32 number_of_bands; /**< number of bands per window */
79   FLOAT64 *spec;          /**< Spectral data array */
80 } ia_tns_info;
81 
82 IA_ERRORCODE iusace_tns_init(WORD32 sampling_rate, WORD32 bit_rate, ia_tns_info *pstr_tns_info,
83                              WORD32 num_channels);
84 
85 VOID iusace_tns_encode(ia_tns_info *pstr_tns_info_ch2, ia_tns_info *pstr_tns_info,
86                        FLOAT32 *ptr_sfb_energy, WORD32 w, WORD32 i_ch, WORD32 low_pass_line,
87                        FLOAT64 *ptr_scratch_tns_filter, WORD32 core_mode,
88                        FLOAT64 *ptr_tns_scratch);
89