Coverage Report

Created: 2026-01-17 06:57

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
7.16M
    FLOAT32 *real_subband, FLOAT32 *imag_subband, WORD8 *ptr_scratch) {
43
7.16M
  IA_ERRORCODE error;
44
7.16M
  WORD32 idx;
45
7.16M
  WORD32 qmf_bands = pstr_qmf_filter_bank->no_channels;
46
7.16M
  WORD32 qmf_bands_by_2 = qmf_bands << 1;
47
7.16M
  FLOAT32 intermediate_band;
48
7.16M
  FLOAT32 x0, x1, y0, y1;
49
7.16M
  if (qmf_bands == 64) {
50
7.16M
    x0 = time_in[1];
51
7.16M
    y0 = time_in[0];
52
7.16M
    real_subband[0] = (x0 + y0) / 2;
53
7.16M
    imag_subband[0] = (x0 - y0) / 2;
54
458M
    for (idx = 1; idx < qmf_bands; idx++) {
55
451M
      x0 = time_in[idx + 1];
56
451M
      y0 = time_in[qmf_bands_by_2 - idx];
57
451M
      real_subband[idx] = (x0 - y0) / 2;
58
451M
      imag_subband[idx] = (x0 + y0) / 2;
59
451M
    }
60
7.16M
  } 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
7.16M
  error = ixheaace_mps_212_dct_iv(real_subband, qmf_bands, ptr_scratch);
74
7.16M
  if (error != IA_NO_ERROR) {
75
0
    return error;
76
0
  }
77
7.16M
  error = ixheaace_mps_212_dst_iv(imag_subband, qmf_bands, ptr_scratch);
78
7.16M
  if (error != IA_NO_ERROR) {
79
0
    return error;
80
0
  }
81
82
236M
  for (idx = 0; idx < MIN(pstr_qmf_filter_bank->lsb, qmf_bands); idx += 2) {
83
229M
    intermediate_band = real_subband[idx];
84
229M
    real_subband[idx] = -imag_subband[idx];
85
229M
    imag_subband[idx] = intermediate_band;
86
87
229M
    intermediate_band = -real_subband[idx + 1];
88
229M
    real_subband[idx + 1] = imag_subband[idx + 1];
89
229M
    imag_subband[idx + 1] = intermediate_band;
90
229M
  }
91
7.16M
  return IA_NO_ERROR;
92
7.16M
}
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
7.16M
                                                        FLOAT32 *ptr_filter_states) {
98
7.16M
  const FLOAT32 *p_flt = ptr_filter;
99
7.16M
  WORD32 poly, band;
100
7.16M
  FLOAT32 accumlate;
101
102
924M
  for (band = 0; band < 2 * qmf_bands; band++) {
103
916M
    accumlate = 0;
104
916M
    p_flt += QMF_NO_POLY * (stride - 1);
105
5.50G
    for (poly = 0; poly < QMF_NO_POLY; poly++) {
106
4.58G
      accumlate += (((*p_flt++) * ptr_filter_states[2 * qmf_bands * poly]));
107
4.58G
    }
108
916M
    ptr_analysis_buffer[2 * qmf_bands - 1 - band] = accumlate;
109
916M
    ptr_filter_states++;
110
916M
  }
111
7.16M
}
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
7.16M
    WORD8 *ptr_scratch) {
117
7.16M
  IA_ERRORCODE error = IA_NO_ERROR;
118
7.16M
  WORD32 idx;
119
7.16M
  WORD32 offset = pstr_qmf_filter_bank->no_channels * (QMF_NO_POLY * 2 - 1);
120
7.16M
  FLOAT32 *pstr_filter_states_ana_tmp =
121
7.16M
      ((FLOAT32 *)pstr_qmf_filter_bank->ptr_filter_states) + offset;
122
465M
  for (idx = 0; idx < pstr_qmf_filter_bank->no_channels; idx++) {
123
458M
    *pstr_filter_states_ana_tmp++ = (FLOAT32)*time_in;
124
458M
    time_in += stride;
125
458M
  }
126
7.16M
  ixheaace_mps_212_qmf_ana_prototype_fir_slot(
127
7.16M
      p_work_buffer, pstr_qmf_filter_bank->no_channels, pstr_qmf_filter_bank->pstr_filter,
128
7.16M
      pstr_qmf_filter_bank->p_stride, (FLOAT32 *)pstr_qmf_filter_bank->ptr_filter_states);
129
130
7.16M
  error = ixheaace_mps_212_qmf_forward_modulation_hq(pstr_qmf_filter_bank, p_work_buffer,
131
7.16M
                                                     real_subband, imag_subband, ptr_scratch);
132
7.16M
  if (error != IA_NO_ERROR) {
133
0
    return error;
134
0
  }
135
136
7.16M
  memmove(pstr_qmf_filter_bank->ptr_filter_states,
137
7.16M
          (FLOAT32 *)pstr_qmf_filter_bank->ptr_filter_states + pstr_qmf_filter_bank->no_channels,
138
7.16M
          offset * sizeof(FLOAT32));
139
7.16M
  return error;
140
7.16M
}
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
2.91k
                                      WORD32 usb, WORD32 no_channels) {
146
2.91k
  memset(pstr_qmf_filter_bank, 0, sizeof(ixheaace_mps_qmf_filter_bank));
147
2.91k
  pstr_qmf_filter_bank->no_channels = no_channels;
148
2.91k
  pstr_qmf_filter_bank->no_col = num_cols;
149
2.91k
  pstr_qmf_filter_bank->lsb = MIN(lsb, pstr_qmf_filter_bank->no_channels);
150
2.91k
  pstr_qmf_filter_bank->usb = MIN(usb, pstr_qmf_filter_bank->no_channels);
151
2.91k
  pstr_qmf_filter_bank->ptr_filter_states = (VOID *)ptr_filter_states;
152
2.91k
  memset(pstr_qmf_filter_bank->ptr_filter_states, 0,
153
2.91k
         (2 * QMF_NO_POLY - 1) * pstr_qmf_filter_bank->no_channels * sizeof(FLOAT32));
154
2.91k
  pstr_qmf_filter_bank->p_stride = 1;
155
2.91k
  if (no_channels == 64) {
156
2.91k
    pstr_qmf_filter_bank->pstr_filter = qmf_mps_ld_fb_640;
157
2.91k
    pstr_qmf_filter_bank->filter_size = 640;
158
2.91k
  } 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
2.91k
  return IA_NO_ERROR;
164
2.91k
}