1 /*
2 * Copyright (C) 2003 - 2016 Sony Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "ldac.h"
18
19 /***************************************************************************************************
20 Subfunction: Process MDCT Core
21 ***************************************************************************************************/
proc_mdct_core_ldac(SCALAR * p_x,SCALAR * p_y,int nlnn)22 static void proc_mdct_core_ldac(
23 SCALAR *p_x,
24 SCALAR *p_y,
25 int nlnn)
26 {
27 int i, j, k;
28 int loop1, loop2;
29 int coef, index0, index1, offset;
30 int nsmpl = npow2_ldac(nlnn);
31 const int *p_p;
32 const SCALAR *p_w, *p_c, *p_s;
33 SCALAR a_work[LDAC_MAXLSU];
34 SCALAR *p_work = a_work;
35 SCALAR a, b, c, d, tmp;
36 SCALAR cc, cs;
37
38 i = nlnn - LDAC_1FSLNN;
39 p_w = gaa_fwin_ldac[i];
40 p_c = gaa_wcos_ldac[i];
41 p_s = gaa_wsin_ldac[i];
42 p_p = gaa_perm_ldac[i];
43
44 /* Windowing */
45 for (i = 0; i < nsmpl>>1; i++) {
46 p_work[p_p[i]] = -p_x[3*nsmpl/2-1-i] * p_w[nsmpl/2+i] - p_x[3*nsmpl/2+i] * p_w[nsmpl/2-1-i];
47
48 p_work[p_p[nsmpl/2+i]] = p_x[i] * p_w[i] - p_x[nsmpl-1-i] * p_w[nsmpl-1-i];
49 }
50
51 /* Butterfly */
52 coef = 0;
53 for (i = 0; i < nlnn-1; ++i) {
54 loop1 = 1 << (nlnn-2-i);
55 loop2 = 1 << i;
56 index0 = 0;
57 index1 = 1 << (i+1);
58 offset = 1 << (i+2);
59
60 for (k = 0; k < loop2; ++k) {
61 cc = p_c[coef];
62 cs = p_s[coef++];
63 for (j = 0; j < loop1; ++j) {
64 a = p_work[index0+0];
65 b = p_work[index0+1];
66 c = p_work[index1+0] * cc + p_work[index1+1] * cs;
67 d = p_work[index1+0] * cs - p_work[index1+1] * cc;
68
69 p_work[index0+0] = a + c;
70 p_work[index0+1] = b + d;
71 p_work[index1+0] = a - c;
72 p_work[index1+1] = b - d;
73 index0 += offset;
74 index1 += offset;
75 }
76 index0 += 2 - nsmpl;
77 index1 += 2 - nsmpl;
78 }
79 }
80
81 tmp = _scalar(1.0) / (SCALAR)(nsmpl>>1);
82 for (i = 0; i < nsmpl>>1; i++) {
83 cc = p_c[coef];
84 cs = p_s[coef++];
85
86 index0 = i << 1;
87 a = p_work[index0] * cc + p_work[index0+1] * cs;
88 b = p_work[index0] * cs - p_work[index0+1] * cc;
89
90 p_y[index0] = a * tmp;
91 p_y[nsmpl-index0-1] = b * tmp;
92 }
93
94 return;
95 }
96
97 /***************************************************************************************************
98 Process MDCT
99 ***************************************************************************************************/
proc_mdct_ldac(SFINFO * p_sfinfo,int nlnn)100 DECLFUNC void proc_mdct_ldac(
101 SFINFO *p_sfinfo,
102 int nlnn)
103 {
104 AC *p_ac;
105 int ich;
106 int nchs = p_sfinfo->cfg.ch;
107
108 for (ich = 0; ich < nchs; ich++) {
109 p_ac = p_sfinfo->ap_ac[ich];
110 proc_mdct_core_ldac(p_ac->p_acsub->a_time, p_ac->p_acsub->a_spec, nlnn);
111 }
112
113 return;
114 }
115
116