Coverage Report

Created: 2025-07-18 06:38

/src/libxaac/encoder/ixheaace_mps_dct.c
Line
Count
Source (jump to first uncovered line)
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 "ixheaac_type_def.h"
22
#include "ixheaace_error_codes.h"
23
#include "ixheaac_error_standards.h"
24
#include "ixheaace_mps_common_fix.h"
25
#include "ixheaace_mps_defines.h"
26
#include "ixheaace_mps_common_define.h"
27
#include "ixheaace_bitbuffer.h"
28
29
#include "ixheaace_psy_const.h"
30
#include "ixheaace_tns.h"
31
#include "ixheaace_tns_params.h"
32
#include "ixheaace_rom.h"
33
#include "ixheaace_common_rom.h"
34
#include "ixheaace_fft.h"
35
36
#include "ixheaace_mps_dct.h"
37
#include "ixheaace_mps_buf.h"
38
#include "ixheaace_mps_lib.h"
39
#include "ixheaace_mps_main_structure.h"
40
41
#include "ixheaace_mps_bitstream.h"
42
#include "ixheaace_mps_frame_windowing.h"
43
#include "ixheaace_mps_param_extract.h"
44
#include "ixheaace_mps_static_gain.h"
45
#include "ixheaace_mps_filter.h"
46
#include "ixheaace_mps_delay.h"
47
#include "ixheaace_mps_dmx_tdom_enh.h"
48
#include "ixheaace_mps_tools_rom.h"
49
50
6.17M
IA_ERRORCODE ixheaace_mps_212_dct_iv(FLOAT32 *ptr_data, WORD32 length, WORD8 *ptr_scratch) {
51
6.17M
  WORD32 sin_step = 0;
52
6.17M
  WORD32 length_by_2 = length >> 1;
53
6.17M
  WORD32 step, idx;
54
6.17M
  FLOAT32 accu_1, accu_2, accu_3, accu_4;
55
6.17M
  FLOAT32 *ptr_data_0;
56
6.17M
  FLOAT32 *ptr_data_1;
57
6.17M
  const ixheaace_cmplx_str *ptr_cmplx_twiddle;
58
6.17M
  const ixheaace_cmplx_str *ptr_cmplx_sin_twiddle;
59
6.17M
  ixheaace_scratch_mem *pstr_scratch = (ixheaace_scratch_mem *)ptr_scratch;
60
61
6.17M
  if (length == 64) {
62
6.17M
    ptr_cmplx_twiddle = sine_window_64;
63
6.17M
    ptr_cmplx_sin_twiddle = sine_table_1024;
64
6.17M
    sin_step = 32;
65
6.17M
  } else {
66
0
    ptr_cmplx_twiddle = sine_window_32;
67
0
    ptr_cmplx_sin_twiddle = sine_table_1024;
68
0
    sin_step = 64;
69
0
  }
70
71
6.17M
  ptr_data_0 = &ptr_data[0];
72
6.17M
  ptr_data_1 = &ptr_data[length - 2];
73
104M
  for (idx = 0; idx < length_by_2 - 1; idx += 2, ptr_data_0 += 2, ptr_data_1 -= 2) {
74
98.7M
    accu_1 =
75
98.7M
        (ptr_data_1[1] * ptr_cmplx_twiddle[idx].re) - (ptr_data_0[0] * ptr_cmplx_twiddle[idx].im);
76
98.7M
    accu_2 =
77
98.7M
        (ptr_data_1[1] * ptr_cmplx_twiddle[idx].im) + (ptr_data_0[0] * ptr_cmplx_twiddle[idx].re);
78
98.7M
    accu_3 = (ptr_data_1[0] * ptr_cmplx_twiddle[idx + 1].re) -
79
98.7M
             (ptr_data_0[1] * ptr_cmplx_twiddle[idx + 1].im);
80
98.7M
    accu_4 = (ptr_data_1[0] * ptr_cmplx_twiddle[idx + 1].im) +
81
98.7M
             (ptr_data_0[1] * ptr_cmplx_twiddle[idx + 1].re);
82
83
98.7M
    ptr_data_0[0] = accu_2 / 4;
84
98.7M
    ptr_data_0[1] = accu_1 / 4;
85
98.7M
    ptr_data_1[0] = accu_4 / 4;
86
98.7M
    ptr_data_1[1] = -(accu_3 / 4);
87
98.7M
  }
88
6.17M
  ia_enhaacplus_enc_complex_fft(ptr_data, length_by_2, pstr_scratch);
89
6.17M
  if (length_by_2 == 32) {
90
401M
    for (idx = 0; idx < length; idx++) {
91
395M
      ptr_data[idx] = (ptr_data[idx] / (1 << (4)));
92
395M
    }
93
6.17M
  } else {
94
0
    for (idx = 0; idx < length; idx++) {
95
0
      ptr_data[idx] = (ptr_data[idx] / (1 << (3)));
96
0
    }
97
0
  }
98
99
6.17M
  ptr_data_0 = &ptr_data[0];
100
6.17M
  ptr_data_1 = &ptr_data[length - 2];
101
6.17M
  accu_1 = ptr_data_1[0];
102
6.17M
  accu_2 = ptr_data_1[1];
103
6.17M
  ptr_data_1[1] = -ptr_data_0[1];
104
105
98.7M
  for (step = sin_step, idx = 1; idx<(length_by_2 + 1)>> 1; idx++, step += sin_step) {
106
92.5M
    ixheaace_cmplx_str twd = ptr_cmplx_sin_twiddle[step];
107
92.5M
    accu_3 = (accu_1 * twd.re) - (accu_2 * twd.im);
108
92.5M
    accu_4 = (accu_1 * twd.im) + (accu_2 * twd.re);
109
92.5M
    ptr_data_0[1] = accu_3;
110
92.5M
    ptr_data_1[0] = accu_4;
111
112
92.5M
    ptr_data_0 += 2;
113
92.5M
    ptr_data_1 -= 2;
114
115
92.5M
    accu_3 = (ptr_data_0[1] * twd.re) - (ptr_data_0[0] * twd.im);
116
92.5M
    accu_4 = (ptr_data_0[1] * twd.im) + (ptr_data_0[0] * twd.re);
117
92.5M
    accu_1 = ptr_data_1[0];
118
92.5M
    accu_2 = ptr_data_1[1];
119
120
92.5M
    ptr_data_1[1] = -accu_3;
121
92.5M
    ptr_data_0[0] = accu_4;
122
92.5M
  }
123
6.17M
  accu_1 = (accu_1 * SQUARE_ROOT_TWO);
124
6.17M
  accu_2 = (accu_2 * SQUARE_ROOT_TWO);
125
126
6.17M
  ptr_data_1[0] = (accu_1 + accu_2) / 2;
127
6.17M
  ptr_data_0[1] = (accu_1 - accu_2) / 2;
128
129
6.17M
  return IA_NO_ERROR;
130
6.17M
}
131
132
6.17M
IA_ERRORCODE ixheaace_mps_212_dst_iv(FLOAT32 *ptr_data, WORD32 length, WORD8 *ptr_scratch) {
133
6.17M
  WORD32 sin_step = 0;
134
6.17M
  WORD32 step, idx;
135
6.17M
  WORD32 length_by_2 = length >> 1;
136
6.17M
  FLOAT32 accu_1, accu_2, accu_3, accu_4;
137
6.17M
  FLOAT32 *ptr_data_0;
138
6.17M
  FLOAT32 *ptr_data_1;
139
6.17M
  const ixheaace_cmplx_str *ptr_cmplx_twiddle;
140
6.17M
  const ixheaace_cmplx_str *ptr_cmplx_sin_twiddle;
141
6.17M
  ixheaace_scratch_mem *pstr_scratch = (ixheaace_scratch_mem *)ptr_scratch;
142
6.17M
  if (length == 64) {
143
6.17M
    ptr_cmplx_twiddle = sine_window_64;
144
6.17M
    ptr_cmplx_sin_twiddle = sine_table_1024;
145
6.17M
    sin_step = 32;
146
6.17M
  } else {
147
0
    ptr_cmplx_twiddle = sine_window_32;
148
0
    ptr_cmplx_sin_twiddle = sine_table_1024;
149
0
    sin_step = 64;
150
0
  }
151
152
6.17M
  ptr_data_0 = &ptr_data[0];
153
6.17M
  ptr_data_1 = &ptr_data[length - 2];
154
104M
  for (idx = 0; idx < length_by_2 - 1; idx += 2, ptr_data_0 += 2, ptr_data_1 -= 2) {
155
98.7M
    accu_1 = (ptr_data_1[1] * ptr_cmplx_twiddle[idx].re) -
156
98.7M
             ((-ptr_data_0[0]) * ptr_cmplx_twiddle[idx].im);
157
98.7M
    accu_2 = (ptr_data_1[1] * ptr_cmplx_twiddle[idx].im) +
158
98.7M
             ((-ptr_data_0[0]) * ptr_cmplx_twiddle[idx].re);
159
98.7M
    accu_3 = ((-ptr_data_1[0]) * ptr_cmplx_twiddle[idx + 1].re) -
160
98.7M
             (ptr_data_0[1] * ptr_cmplx_twiddle[idx + 1].im);
161
98.7M
    accu_4 = ((-ptr_data_1[0]) * ptr_cmplx_twiddle[idx + 1].im) +
162
98.7M
             (ptr_data_0[1] * ptr_cmplx_twiddle[idx + 1].re);
163
98.7M
    ptr_data_0[0] = accu_2 / 4;
164
98.7M
    ptr_data_0[1] = accu_1 / 4;
165
98.7M
    ptr_data_1[0] = accu_4 / 4;
166
98.7M
    ptr_data_1[1] = -(accu_3) / 4;
167
98.7M
  }
168
6.17M
  ia_enhaacplus_enc_complex_fft(ptr_data, length_by_2, pstr_scratch);
169
6.17M
  if (length_by_2 == 32) {
170
401M
    for (idx = 0; idx < length; idx++) {
171
395M
      ptr_data[idx] = (ptr_data[idx] / (1 << (4)));
172
395M
    }
173
6.17M
  } else {
174
0
    for (idx = 0; idx < length; idx++) {
175
0
      ptr_data[idx] = (ptr_data[idx] / (1 << (3)));
176
0
    }
177
0
  }
178
6.17M
  ptr_data_0 = &ptr_data[0];
179
6.17M
  ptr_data_1 = &ptr_data[length - 2];
180
6.17M
  accu_1 = ptr_data_1[0];
181
6.17M
  accu_2 = ptr_data_1[1];
182
6.17M
  ptr_data_1[1] = -ptr_data_0[0];
183
6.17M
  ptr_data_0[0] = ptr_data_0[1];
184
185
98.7M
  for (step = sin_step, idx = 1; idx<(length_by_2 + 1)>> 1; idx++, step += sin_step) {
186
92.5M
    ixheaace_cmplx_str twd = ptr_cmplx_sin_twiddle[step];
187
188
92.5M
    accu_3 = (accu_1 * twd.re) - (accu_2 * twd.im);
189
92.5M
    accu_4 = (accu_1 * twd.im) + (accu_2 * twd.re);
190
92.5M
    ptr_data_1[0] = -accu_3;
191
92.5M
    ptr_data_0[1] = -accu_4;
192
193
92.5M
    ptr_data_0 += 2;
194
92.5M
    ptr_data_1 -= 2;
195
196
92.5M
    accu_3 = (ptr_data_0[1] * twd.re) - (ptr_data_0[0] * twd.im);
197
92.5M
    accu_4 = (ptr_data_0[1] * twd.im) + (ptr_data_0[0] * twd.re);
198
92.5M
    accu_1 = ptr_data_1[0];
199
92.5M
    accu_2 = ptr_data_1[1];
200
201
92.5M
    ptr_data_0[0] = accu_3;
202
92.5M
    ptr_data_1[1] = -accu_4;
203
92.5M
  }
204
205
6.17M
  accu_1 = (accu_1 * SQUARE_ROOT_TWO);
206
6.17M
  accu_2 = (accu_2 * SQUARE_ROOT_TWO);
207
6.17M
  ptr_data_1[0] = (accu_1 + accu_2) / 2;
208
6.17M
  ptr_data_0[1] = (accu_1 - accu_2) / 2;
209
210
6.17M
  return IA_NO_ERROR;
211
6.17M
}