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
ia_enhaacplus_enc_calc_band_energy(const FLOAT32 * ptr_spec_coeffs,const WORD32 * ptr_band_offset,const WORD32 num_bands,FLOAT32 * ptr_band_energy,WORD32 sfb_count,FLOAT32 * ptr_band_energy_sum)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 FLOAT32 *ptr_band_energy_sum) {
32 WORD32 i, j;
33
34 j = 0;
35 memset(ptr_band_energy, 0, sfb_count * sizeof(*ptr_band_energy));
36 *ptr_band_energy_sum = 0;
37
38 for (i = 0; i < num_bands; i++) {
39 while (j < ptr_band_offset[i + 1]) {
40 ptr_band_energy[i] += (FLOAT32)((FLOAT64)ptr_spec_coeffs[j] * ptr_spec_coeffs[j]);
41 j++;
42 }
43 *ptr_band_energy_sum = *ptr_band_energy_sum + ptr_band_energy[i];
44 }
45 }
46
ia_enhaacplus_enc_calc_band_energy_ms(const FLOAT32 * ptr_mdct_spectrum_left_fix,const FLOAT32 * ptr_mdct_spectrum_right_fix,const WORD32 * ptr_sfb_offset,const WORD32 num_sfb_active,const WORD32 num_sfb_total,FLOAT32 * ptr_band_nrg_mid,FLOAT32 * ptr_band_nrg_mid_sum,FLOAT32 * ptr_band_nrg_side,FLOAT32 * ptr_band_nrg_side_sum)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 FLOAT32 *ptr_band_nrg_side_sum) {
52 WORD32 i;
53 const FLOAT32 *ptr_spec_left = ptr_mdct_spectrum_left_fix;
54 const FLOAT32 *ptr_spec_right = ptr_mdct_spectrum_right_fix;
55
56 *ptr_band_nrg_mid_sum = 0;
57 *ptr_band_nrg_side_sum = 0;
58
59 for (i = 0; i < num_sfb_active; i++) {
60 WORD16 offset = (WORD16)(ptr_sfb_offset[i + 1] - ptr_sfb_offset[i]);
61 FLOAT32 band_nrgy_mid = 0, band_nrg_side = 0;
62 ptr_band_nrg_mid[i] = 0;
63 ptr_band_nrg_side[i] = 0;
64 FLOAT32 spec_mid, spec_side;
65 FLOAT32 temp_mid, temp_side;
66
67 while (offset--) {
68 spec_mid = (*ptr_spec_left + *ptr_spec_right) * 0.5f;
69 spec_side = (*ptr_spec_left++ - *ptr_spec_right++) * 0.5f;
70
71 temp_mid = (spec_mid * spec_mid);
72 temp_side = (spec_side * spec_side);
73
74 band_nrgy_mid = (band_nrgy_mid + temp_mid);
75 band_nrg_side = (band_nrg_side + temp_side);
76 }
77
78 ptr_band_nrg_mid[i] = band_nrgy_mid;
79 ptr_band_nrg_side[i] = band_nrg_side;
80
81 *ptr_band_nrg_mid_sum += ptr_band_nrg_mid[i];
82 *ptr_band_nrg_side_sum += ptr_band_nrg_side[i];
83 }
84
85 memset(&ptr_band_nrg_mid[num_sfb_active], 0,
86 (num_sfb_total - num_sfb_active) * sizeof(*ptr_band_nrg_mid));
87 memset(&ptr_band_nrg_side[num_sfb_active], 0,
88 (num_sfb_total - num_sfb_active) * sizeof(*ptr_band_nrg_side));
89 }
90