/src/libxaac/encoder/ixheaace_calc_ms_band_energy.c
Line | Count | Source |
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 | | |
23 | | #include "ixheaac_type_def.h" |
24 | | #include "ixheaace_aac_constants.h" |
25 | | |
26 | | #include "ixheaace_calc_ms_band_energy.h" |
27 | | |
28 | | VOID ia_enhaacplus_enc_calc_band_energy(const FLOAT32 *ptr_spec_coeffs, |
29 | | const WORD32 *ptr_band_offset, const WORD32 num_bands, |
30 | | FLOAT32 *ptr_band_energy, WORD32 sfb_count, |
31 | 1.47M | FLOAT32 *ptr_band_energy_sum) { |
32 | 1.47M | WORD32 i, j; |
33 | | |
34 | 1.47M | j = 0; |
35 | 1.47M | memset(ptr_band_energy, 0, sfb_count * sizeof(*ptr_band_energy)); |
36 | 1.47M | *ptr_band_energy_sum = 0; |
37 | | |
38 | 29.7M | for (i = 0; i < num_bands; i++) { |
39 | 362M | while (j < ptr_band_offset[i + 1]) { |
40 | 334M | ptr_band_energy[i] += (FLOAT32)((FLOAT64)ptr_spec_coeffs[j] * ptr_spec_coeffs[j]); |
41 | 334M | j++; |
42 | 334M | } |
43 | 28.3M | *ptr_band_energy_sum = *ptr_band_energy_sum + ptr_band_energy[i]; |
44 | 28.3M | } |
45 | 1.47M | } |
46 | | |
47 | | VOID ia_enhaacplus_enc_calc_band_energy_ms( |
48 | | const FLOAT32 *ptr_mdct_spectrum_left_fix, const FLOAT32 *ptr_mdct_spectrum_right_fix, |
49 | | const WORD32 *ptr_sfb_offset, const WORD32 num_sfb_active, const WORD32 num_sfb_total, |
50 | | FLOAT32 *ptr_band_nrg_mid, FLOAT32 *ptr_band_nrg_mid_sum, FLOAT32 *ptr_band_nrg_side, |
51 | 415k | FLOAT32 *ptr_band_nrg_side_sum) { |
52 | 415k | WORD32 i; |
53 | 415k | const FLOAT32 *ptr_spec_left = ptr_mdct_spectrum_left_fix; |
54 | 415k | const FLOAT32 *ptr_spec_right = ptr_mdct_spectrum_right_fix; |
55 | | |
56 | 415k | *ptr_band_nrg_mid_sum = 0; |
57 | 415k | *ptr_band_nrg_side_sum = 0; |
58 | | |
59 | 7.65M | for (i = 0; i < num_sfb_active; i++) { |
60 | 7.24M | WORD16 offset = (WORD16)(ptr_sfb_offset[i + 1] - ptr_sfb_offset[i]); |
61 | 7.24M | FLOAT32 band_nrgy_mid = 0, band_nrg_side = 0; |
62 | 7.24M | ptr_band_nrg_mid[i] = 0; |
63 | 7.24M | ptr_band_nrg_side[i] = 0; |
64 | 7.24M | FLOAT32 spec_mid, spec_side; |
65 | 7.24M | FLOAT32 temp_mid, temp_side; |
66 | | |
67 | 88.3M | while (offset--) { |
68 | 81.1M | spec_mid = (*ptr_spec_left + *ptr_spec_right) * 0.5f; |
69 | 81.1M | spec_side = (*ptr_spec_left++ - *ptr_spec_right++) * 0.5f; |
70 | | |
71 | 81.1M | temp_mid = (spec_mid * spec_mid); |
72 | 81.1M | temp_side = (spec_side * spec_side); |
73 | | |
74 | 81.1M | band_nrgy_mid = (band_nrgy_mid + temp_mid); |
75 | 81.1M | band_nrg_side = (band_nrg_side + temp_side); |
76 | 81.1M | } |
77 | | |
78 | 7.24M | ptr_band_nrg_mid[i] = band_nrgy_mid; |
79 | 7.24M | ptr_band_nrg_side[i] = band_nrg_side; |
80 | | |
81 | 7.24M | *ptr_band_nrg_mid_sum += ptr_band_nrg_mid[i]; |
82 | 7.24M | *ptr_band_nrg_side_sum += ptr_band_nrg_side[i]; |
83 | 7.24M | } |
84 | | |
85 | 415k | memset(&ptr_band_nrg_mid[num_sfb_active], 0, |
86 | 415k | (num_sfb_total - num_sfb_active) * sizeof(*ptr_band_nrg_mid)); |
87 | 415k | memset(&ptr_band_nrg_side[num_sfb_active], 0, |
88 | 415k | (num_sfb_total - num_sfb_active) * sizeof(*ptr_band_nrg_side)); |
89 | 415k | } |