xref: /aosp_15_r20/external/libxaac/encoder/ixheaace_block_switch.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 
23*15dc779aSAndroid Build Coastguard Worker #define BLOCK_SWITCH_WINDOWS TRANS_FAC /* number of windows for energy calculation */
24*15dc779aSAndroid Build Coastguard Worker #define BLOCK_SWITCH_WINDOW_LEN \
25*15dc779aSAndroid Build Coastguard Worker   FRAME_LEN_SHORT_128 /* minimal granularity of energy calculation */
26*15dc779aSAndroid Build Coastguard Worker 
27*15dc779aSAndroid Build Coastguard Worker #define BLK_SWITCH_WIN 8
28*15dc779aSAndroid Build Coastguard Worker #define BLK_SWITCH_FILT_LEN 2
29*15dc779aSAndroid Build Coastguard Worker 
30*15dc779aSAndroid Build Coastguard Worker /* Block types */
31*15dc779aSAndroid Build Coastguard Worker #define LONG_WINDOW 0
32*15dc779aSAndroid Build Coastguard Worker #define START_WINDOW 1
33*15dc779aSAndroid Build Coastguard Worker #define SHORT_WINDOW 2
34*15dc779aSAndroid Build Coastguard Worker #define STOP_WINDOW 3
35*15dc779aSAndroid Build Coastguard Worker 
36*15dc779aSAndroid Build Coastguard Worker /* Window shapes */
37*15dc779aSAndroid Build Coastguard Worker #define SINE_WINDOW 0
38*15dc779aSAndroid Build Coastguard Worker #define KBD_WINDOW 1
39*15dc779aSAndroid Build Coastguard Worker 
40*15dc779aSAndroid Build Coastguard Worker #define MAXIMUM_NO_OF_GROUPS 4
41*15dc779aSAndroid Build Coastguard Worker 
42*15dc779aSAndroid Build Coastguard Worker #define ACC_WINDOW_NRG_FAC 0.3f
43*15dc779aSAndroid Build Coastguard Worker #define ONE_MINUS_ACC_WINDOW_NRG_FAC 0.7f
44*15dc779aSAndroid Build Coastguard Worker #define INV_ATTACK_RATIO_HIGH_BR 0.1f
45*15dc779aSAndroid Build Coastguard Worker #define INV_ATTACK_RATIO_LOW_BR 0.056f
46*15dc779aSAndroid Build Coastguard Worker #define MIN_ATTACK_NRG (1000000)
47*15dc779aSAndroid Build Coastguard Worker #define BLK_SWITCH_HIGH_BR_MONO (24000)
48*15dc779aSAndroid Build Coastguard Worker #define BLK_SWITCH_HIGH_BR_STEREO (16000)
49*15dc779aSAndroid Build Coastguard Worker 
50*15dc779aSAndroid Build Coastguard Worker typedef struct {
51*15dc779aSAndroid Build Coastguard Worker   FLOAT32 inv_attack_ratio;
52*15dc779aSAndroid Build Coastguard Worker   WORD32 win_seq;
53*15dc779aSAndroid Build Coastguard Worker   WORD32 nxt_win_seq;
54*15dc779aSAndroid Build Coastguard Worker   WORD32 attack;
55*15dc779aSAndroid Build Coastguard Worker   WORD32 lastattack;
56*15dc779aSAndroid Build Coastguard Worker   WORD32 attack_idx;
57*15dc779aSAndroid Build Coastguard Worker   WORD32 last_attack_idx;
58*15dc779aSAndroid Build Coastguard Worker   WORD32 total_groups_cnt;
59*15dc779aSAndroid Build Coastguard Worker   WORD32 group_len[TRANS_FAC];
60*15dc779aSAndroid Build Coastguard Worker   FLOAT32 win_energy[BLK_SWITCH_FILT_LEN][BLK_SWITCH_WIN];
61*15dc779aSAndroid Build Coastguard Worker   FLOAT32 win_energy_filt[BLK_SWITCH_FILT_LEN][BLK_SWITCH_WIN];
62*15dc779aSAndroid Build Coastguard Worker   FLOAT32 iir_states[BLK_SWITCH_FILT_LEN];
63*15dc779aSAndroid Build Coastguard Worker   FLOAT32 max_win_energy;
64*15dc779aSAndroid Build Coastguard Worker   FLOAT32 acc_win_energy;
65*15dc779aSAndroid Build Coastguard Worker   WORD32 win_seq_ld;      /* these are used to save window decision for LD. */
66*15dc779aSAndroid Build Coastguard Worker   WORD32 next_win_seq_ld; /* nxt_win_seq and win_seq are always set to
67*15dc779aSAndroid Build Coastguard Worker                                  LONG_WINDOW */
68*15dc779aSAndroid Build Coastguard Worker } ixheaace_block_switch_control;
69*15dc779aSAndroid Build Coastguard Worker 
70*15dc779aSAndroid Build Coastguard Worker VOID iaace_init_block_switching(ixheaace_block_switch_control *pstr_blk_switch_ctrl,
71*15dc779aSAndroid Build Coastguard Worker                                 const WORD32 bit_rate, const WORD32 num_chans);
72*15dc779aSAndroid Build Coastguard Worker 
73*15dc779aSAndroid Build Coastguard Worker VOID iaace_block_switching(ixheaace_block_switch_control *pstr_blk_switch_ctrl,
74*15dc779aSAndroid Build Coastguard Worker                            const FLOAT32 *ptr_time_signal, WORD32 frame_length, WORD32 num_chans);
75*15dc779aSAndroid Build Coastguard Worker 
76*15dc779aSAndroid Build Coastguard Worker VOID iaace_sync_block_switching(ixheaace_block_switch_control *pstr_blk_switch_left_ctrl,
77*15dc779aSAndroid Build Coastguard Worker                                 ixheaace_block_switch_control *pstr_blk_switch_right_ctrl,
78*15dc779aSAndroid Build Coastguard Worker                                 const WORD32 num_channels);
79