Coverage Report

Created: 2025-11-10 06:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libxaac/encoder/ixheaace_mps_qmf.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
#include <stdlib.h>
23
#include "ixheaac_type_def.h"
24
#include "ixheaac_error_standards.h"
25
#include "ixheaace_error_codes.h"
26
#include "ixheaace_mps_common_fix.h"
27
#include "ixheaace_mps_defines.h"
28
#include "ixheaace_mps_common_define.h"
29
#include "ixheaace_mps_buf.h"
30
#include "ixheaace_mps_lib.h"
31
#include "ixheaace_mps_main_structure.h"
32
#include "ixheaace_mps_tools_rom.h"
33
#include "ixheaace_mps_dct.h"
34
#include "ixheaace_mps_qmf.h"
35
#include "ixheaac_constants.h"
36
#include "ixheaac_basic_ops32.h"
37
#include "ixheaac_basic_ops40.h"
38
#include "ixheaac_basic_ops.h"
39
40
static IA_ERRORCODE ixheaace_mps_212_qmf_forward_modulation_hq(
41
    ixheaace_mps_pstr_qmf_filter_bank pstr_qmf_filter_bank, const FLOAT32 *time_in,
42
8.14M
    FLOAT32 *real_subband, FLOAT32 *imag_subband, WORD8 *ptr_scratch) {
43
8.14M
  IA_ERRORCODE error;
44
8.14M
  WORD32 idx;
45
8.14M
  WORD32 qmf_bands = pstr_qmf_filter_bank->no_channels;
46
8.14M
  WORD32 qmf_bands_by_2 = qmf_bands << 1;
47
8.14M
  FLOAT32 intermediate_band;
48
8.14M
  FLOAT32 x0, x1, y0, y1;
49
8.14M
  if (qmf_bands == 64) {
50
8.14M
    x0 = time_in[1];
51
8.14M
    y0 = time_in[0];
52
8.14M
    real_subband[0] = (x0 + y0) / 2;
53
8.14M
    imag_subband[0] = (x0 - y0) / 2;
54
521M
    for (idx = 1; idx < qmf_bands; idx++) {
55
513M
      x0 = time_in[idx + 1];
56
513M
      y0 = time_in[qmf_bands_by_2 - idx];
57
513M
      real_subband[idx] = (x0 - y0) / 2;
58
513M
      imag_subband[idx] = (x0 + y0) / 2;
59
513M
    }
60
8.14M
  } else {
61
0
    for (idx = 0; idx < qmf_bands; idx += 2) {
62
0
      x0 = time_in[idx + 0];
63
0
      x1 = time_in[idx + 1];
64
0
      y0 = time_in[qmf_bands_by_2 - 1 - idx];
65
0
      y1 = time_in[qmf_bands_by_2 - 2 - idx];
66
67
0
      real_subband[idx + 0] = (x0 - y0) / 2;
68
0
      real_subband[idx + 1] = (x1 - y1) / 2;
69
0
      imag_subband[idx + 0] = (x0 + y0) / 2;
70
0
      imag_subband[idx + 1] = (x1 + y1) / 2;
71
0
    }
72
0
  }
73
8.14M
  error = ixheaace_mps_212_dct_iv(real_subband, qmf_bands, ptr_scratch);
74
8.14M
  if (error != IA_NO_ERROR) {
75
0
    return error;
76
0
  }
77
8.14M
  error = ixheaace_mps_212_dst_iv(imag_subband, qmf_bands, ptr_scratch);
78
8.14M
  if (error != IA_NO_ERROR) {
79
0
    return error;
80
0
  }
81
82
268M
  for (idx = 0; idx < MIN(pstr_qmf_filter_bank->lsb, qmf_bands); idx += 2) {
83
260M
    intermediate_band = real_subband[idx];
84
260M
    real_subband[idx] = -imag_subband[idx];
85
260M
    imag_subband[idx] = intermediate_band;
86
87
260M
    intermediate_band = -real_subband[idx + 1];
88
260M
    real_subband[idx + 1] = imag_subband[idx + 1];
89
260M
    imag_subband[idx + 1] = intermediate_band;
90
260M
  }
91
8.14M
  return IA_NO_ERROR;
92
8.14M
}
93
94
static VOID ixheaace_mps_212_qmf_ana_prototype_fir_slot(FLOAT32 *ptr_analysis_buffer,
95
                                                        WORD32 qmf_bands,
96
                                                        const FLOAT32 *ptr_filter, WORD32 stride,
97
8.14M
                                                        FLOAT32 *ptr_filter_states) {
98
8.14M
  const FLOAT32 *p_flt = ptr_filter;
99
8.14M
  WORD32 poly, band;
100
8.14M
  FLOAT32 accumlate;
101
102
1.05G
  for (band = 0; band < 2 * qmf_bands; band++) {
103
1.04G
    accumlate = 0;
104
1.04G
    p_flt += QMF_NO_POLY * (stride - 1);
105
6.25G
    for (poly = 0; poly < QMF_NO_POLY; poly++) {
106
5.21G
      accumlate += (((*p_flt++) * ptr_filter_states[2 * qmf_bands * poly]));
107
5.21G
    }
108
1.04G
    ptr_analysis_buffer[2 * qmf_bands - 1 - band] = accumlate;
109
1.04G
    ptr_filter_states++;
110
1.04G
  }
111
8.14M
}
112
113
IA_ERRORCODE ixheaace_mps_212_qmf_analysis_filtering_slot(
114
    ixheaace_mps_pstr_qmf_filter_bank pstr_qmf_filter_bank, FLOAT32 *real_subband,
115
    FLOAT32 *imag_subband, const FLOAT32 *time_in, const WORD32 stride, FLOAT32 *p_work_buffer,
116
8.14M
    WORD8 *ptr_scratch) {
117
8.14M
  IA_ERRORCODE error = IA_NO_ERROR;
118
8.14M
  WORD32 idx;
119
8.14M
  WORD32 offset = pstr_qmf_filter_bank->no_channels * (QMF_NO_POLY * 2 - 1);
120
8.14M
  FLOAT32 *pstr_filter_states_ana_tmp =
121
8.14M
      ((FLOAT32 *)pstr_qmf_filter_bank->ptr_filter_states) + offset;
122
529M
  for (idx = 0; idx < pstr_qmf_filter_bank->no_channels; idx++) {
123
521M
    *pstr_filter_states_ana_tmp++ = (FLOAT32)*time_in;
124
521M
    time_in += stride;
125
521M
  }
126
8.14M
  ixheaace_mps_212_qmf_ana_prototype_fir_slot(
127
8.14M
      p_work_buffer, pstr_qmf_filter_bank->no_channels, pstr_qmf_filter_bank->pstr_filter,
128
8.14M
      pstr_qmf_filter_bank->p_stride, (FLOAT32 *)pstr_qmf_filter_bank->ptr_filter_states);
129
130
8.14M
  error = ixheaace_mps_212_qmf_forward_modulation_hq(pstr_qmf_filter_bank, p_work_buffer,
131
8.14M
                                                     real_subband, imag_subband, ptr_scratch);
132
8.14M
  if (error != IA_NO_ERROR) {
133
0
    return error;
134
0
  }
135
136
8.14M
  memmove(pstr_qmf_filter_bank->ptr_filter_states,
137
8.14M
          (FLOAT32 *)pstr_qmf_filter_bank->ptr_filter_states + pstr_qmf_filter_bank->no_channels,
138
8.14M
          offset * sizeof(FLOAT32));
139
8.14M
  return error;
140
8.14M
}
141
142
IA_ERRORCODE
143
ixheaace_mps_212_qmf_init_filter_bank(ixheaace_mps_pstr_qmf_filter_bank pstr_qmf_filter_bank,
144
                                      VOID *ptr_filter_states, WORD32 num_cols, WORD32 lsb,
145
3.09k
                                      WORD32 usb, WORD32 no_channels) {
146
3.09k
  memset(pstr_qmf_filter_bank, 0, sizeof(ixheaace_mps_qmf_filter_bank));
147
3.09k
  pstr_qmf_filter_bank->no_channels = no_channels;
148
3.09k
  pstr_qmf_filter_bank->no_col = num_cols;
149
3.09k
  pstr_qmf_filter_bank->lsb = MIN(lsb, pstr_qmf_filter_bank->no_channels);
150
3.09k
  pstr_qmf_filter_bank->usb = MIN(usb, pstr_qmf_filter_bank->no_channels);
151
3.09k
  pstr_qmf_filter_bank->ptr_filter_states = (VOID *)ptr_filter_states;
152
3.09k
  memset(pstr_qmf_filter_bank->ptr_filter_states, 0,
153
3.09k
         (2 * QMF_NO_POLY - 1) * pstr_qmf_filter_bank->no_channels * sizeof(FLOAT32));
154
3.09k
  pstr_qmf_filter_bank->p_stride = 1;
155
3.09k
  if (no_channels == 64) {
156
3.09k
    pstr_qmf_filter_bank->pstr_filter = qmf_mps_ld_fb_640;
157
3.09k
    pstr_qmf_filter_bank->filter_size = 640;
158
3.09k
  } else {
159
0
    pstr_qmf_filter_bank->pstr_filter = qmf_mps_ld_fb_320;
160
0
    pstr_qmf_filter_bank->filter_size = 320;
161
0
  }
162
163
3.09k
  return IA_NO_ERROR;
164
3.09k
}