annotate ps.c @ 11895:775714d113cd libavcodec

Cosmetics: whitespace.
author alexc
date Sun, 20 Jun 2010 20:13:11 +0000
parents 335524dba347
children 47b770054db4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11886
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
1 /*
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
2 * MPEG-4 Parametric Stereo decoding functions
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
3 * Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
4 *
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
5 * This file is part of FFmpeg.
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
6 *
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
11 *
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
15 * Lesser General Public License for more details.
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
16 *
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
20 */
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
21
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
22 #include <stdint.h>
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
23 #include "libavutil/mathematics.h"
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
24 #include "avcodec.h"
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
25 #include "get_bits.h"
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
26 #include "ps.h"
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
27 #include "ps_tablegen.h"
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
28 #include "psdata.c"
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
29
11891
72441b6700d4 Document the PS_BASELINE define.
alexc
parents: 11890
diff changeset
30 #define PS_BASELINE 0 //< Operate in Baseline PS mode
72441b6700d4 Document the PS_BASELINE define.
alexc
parents: 11890
diff changeset
31 //< Baseline implies 10 or 20 stereo bands,
72441b6700d4 Document the PS_BASELINE define.
alexc
parents: 11890
diff changeset
32 //< mixing mode A, and no ipd/opd
11886
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
33
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
34 #define numQMFSlots 32 //numTimeSlots * RATE
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
35
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
36 static const int8_t num_env_tab[2][4] = {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
37 { 0, 1, 2, 4, },
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
38 { 1, 2, 3, 4, },
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
39 };
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
40
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
41 static const int8_t nr_iidicc_par_tab[] = {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
42 10, 20, 34, 10, 20, 34,
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
43 };
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
44
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
45 static const int8_t nr_iidopd_par_tab[] = {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
46 5, 11, 17, 5, 11, 17,
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
47 };
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
48
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
49 enum {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
50 huff_iid_df1,
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
51 huff_iid_dt1,
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
52 huff_iid_df0,
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
53 huff_iid_dt0,
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
54 huff_icc_df,
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
55 huff_icc_dt,
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
56 huff_ipd_df,
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
57 huff_ipd_dt,
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
58 huff_opd_df,
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
59 huff_opd_dt,
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
60 };
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
61
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
62 static const int huff_iid[] = {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
63 huff_iid_df0,
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
64 huff_iid_df1,
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
65 huff_iid_dt0,
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
66 huff_iid_dt1,
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
67 };
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
68
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
69 static VLC vlc_ps[10];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
70
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
71 /**
11887
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
72 * Read Inter-channel Intensity Difference/Inter-Channel Coherence/
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
73 * Inter-channel Phase Difference/Overall Phase Difference parameters from the
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
74 * bitstream.
11886
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
75 *
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
76 * @param avctx contains the current codec context
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
77 * @param gb pointer to the input bitstream
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
78 * @param ps pointer to the Parametric Stereo context
11887
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
79 * @param par pointer to the parameter to be read
11886
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
80 * @param e envelope to decode
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
81 * @param dt 1: time delta-coded, 0: frequency delta-coded
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
82 */
11887
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
83 #define READ_PAR_DATA(PAR, OFFSET, MASK, ERR_CONDITION) \
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
84 static int PAR ## _data(AVCodecContext *avctx, GetBitContext *gb, PSContext *ps, \
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
85 int8_t (*PAR)[PS_MAX_NR_IIDICC], int table_idx, int e, int dt) \
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
86 { \
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
87 int b, num = ps->nr_ ## PAR ## _par; \
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
88 VLC_TYPE (*vlc_table)[2] = vlc_ps[table_idx].table; \
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
89 if (dt) { \
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
90 int e_prev = e ? e - 1 : ps->num_env_old - 1; \
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
91 e_prev = FFMAX(e_prev, 0); \
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
92 for (b = 0; b < num; b++) { \
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
93 int val = PAR[e_prev][b] + get_vlc2(gb, vlc_table, 9, 3) - OFFSET; \
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
94 if (MASK) val &= MASK; \
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
95 PAR[e][b] = val; \
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
96 if (ERR_CONDITION) \
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
97 goto err; \
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
98 } \
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
99 } else { \
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
100 int val = 0; \
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
101 for (b = 0; b < num; b++) { \
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
102 val += get_vlc2(gb, vlc_table, 9, 3) - OFFSET; \
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
103 if (MASK) val &= MASK; \
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
104 PAR[e][b] = val; \
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
105 if (ERR_CONDITION) \
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
106 goto err; \
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
107 } \
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
108 } \
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
109 return 0; \
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
110 err: \
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
111 av_log(avctx, AV_LOG_ERROR, "illegal "#PAR"\n"); \
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
112 return -1; \
11886
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
113 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
114
11887
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
115 READ_PAR_DATA(iid, huff_offset[table_idx], 0, FFABS(ps->iid_par[e][b]) > 7 + 8 * ps->iid_quant)
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
116 READ_PAR_DATA(icc, huff_offset[table_idx], 0, ps->icc_par[e][b] > 7U)
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
117 READ_PAR_DATA(ipdopd, 0, 0x07, 0)
11886
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
118
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
119 static int ps_extension(GetBitContext *gb, PSContext *ps, int ps_extension_id)
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
120 {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
121 int e;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
122 int count = get_bits_count(gb);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
123
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
124 if (ps_extension_id)
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
125 return 0;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
126
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
127 ps->enable_ipdopd = get_bits1(gb);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
128 if (ps->enable_ipdopd) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
129 for (e = 0; e < ps->num_env; e++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
130 int dt = get_bits1(gb);
11887
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
131 ipdopd_data(NULL, gb, ps, ps->ipd_par, dt ? huff_ipd_dt : huff_ipd_df, e, dt);
11886
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
132 dt = get_bits1(gb);
11887
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
133 ipdopd_data(NULL, gb, ps, ps->opd_par, dt ? huff_opd_dt : huff_opd_df, e, dt);
11886
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
134 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
135 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
136 skip_bits1(gb); //reserved_ps
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
137 return get_bits_count(gb) - count;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
138 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
139
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
140 static void ipdopd_reset(int8_t *opd_hist, int8_t *ipd_hist)
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
141 {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
142 int i;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
143 for (i = 0; i < PS_MAX_NR_IPDOPD; i++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
144 opd_hist[i] = 0;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
145 ipd_hist[i] = 0;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
146 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
147 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
148
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
149 int ff_ps_read_data(AVCodecContext *avctx, GetBitContext *gb_host, PSContext *ps, int bits_left)
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
150 {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
151 int e;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
152 int bit_count_start = get_bits_count(gb_host);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
153 int header;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
154 int bits_consumed;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
155 GetBitContext gbc = *gb_host, *gb = &gbc;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
156
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
157 header = get_bits1(gb);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
158 if (header) { //enable_ps_header
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
159 ps->enable_iid = get_bits1(gb);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
160 if (ps->enable_iid) {
11890
747ea58d1ac6 Remove iid_mode from the PS context.
alexc
parents: 11887
diff changeset
161 int iid_mode = get_bits(gb, 3);
747ea58d1ac6 Remove iid_mode from the PS context.
alexc
parents: 11887
diff changeset
162 if (iid_mode > 5) {
11886
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
163 av_log(avctx, AV_LOG_ERROR, "iid_mode %d is reserved.\n",
11890
747ea58d1ac6 Remove iid_mode from the PS context.
alexc
parents: 11887
diff changeset
164 iid_mode);
11886
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
165 goto err;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
166 }
11890
747ea58d1ac6 Remove iid_mode from the PS context.
alexc
parents: 11887
diff changeset
167 ps->nr_iid_par = nr_iidicc_par_tab[iid_mode];
747ea58d1ac6 Remove iid_mode from the PS context.
alexc
parents: 11887
diff changeset
168 ps->iid_quant = iid_mode > 2;
747ea58d1ac6 Remove iid_mode from the PS context.
alexc
parents: 11887
diff changeset
169 ps->nr_ipdopd_par = nr_iidopd_par_tab[iid_mode];
11886
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
170 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
171 ps->enable_icc = get_bits1(gb);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
172 if (ps->enable_icc) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
173 ps->icc_mode = get_bits(gb, 3);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
174 if (ps->icc_mode > 5) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
175 av_log(avctx, AV_LOG_ERROR, "icc_mode %d is reserved.\n",
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
176 ps->icc_mode);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
177 goto err;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
178 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
179 ps->nr_icc_par = nr_iidicc_par_tab[ps->icc_mode];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
180 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
181 ps->enable_ext = get_bits1(gb);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
182 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
183
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
184 ps->frame_class = get_bits1(gb);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
185 ps->num_env_old = ps->num_env;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
186 ps->num_env = num_env_tab[ps->frame_class][get_bits(gb, 2)];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
187
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
188 ps->border_position[0] = -1;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
189 if (ps->frame_class) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
190 for (e = 1; e <= ps->num_env; e++)
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
191 ps->border_position[e] = get_bits(gb, 5);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
192 } else
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
193 for (e = 1; e <= ps->num_env; e++)
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
194 ps->border_position[e] = e * numQMFSlots / ps->num_env - 1;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
195
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
196 if (ps->enable_iid) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
197 for (e = 0; e < ps->num_env; e++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
198 int dt = get_bits1(gb);
11887
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
199 if (iid_data(avctx, gb, ps, ps->iid_par, huff_iid[2*dt+ps->iid_quant], e, dt))
11886
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
200 goto err;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
201 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
202 } else
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
203 memset(ps->iid_par, 0, sizeof(ps->iid_par));
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
204
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
205 if (ps->enable_icc)
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
206 for (e = 0; e < ps->num_env; e++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
207 int dt = get_bits1(gb);
11887
c432b63b345e psdec: Factorize iid/icc/ipd/opd parameter bitstream reading.
alexc
parents: 11886
diff changeset
208 if (icc_data(avctx, gb, ps, ps->icc_par, dt ? huff_icc_dt : huff_icc_df, e, dt))
11886
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
209 goto err;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
210 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
211 else
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
212 memset(ps->icc_par, 0, sizeof(ps->icc_par));
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
213
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
214 if (ps->enable_ext) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
215 int cnt = get_bits(gb, 4);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
216 if (cnt == 15) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
217 cnt += get_bits(gb, 8);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
218 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
219 cnt *= 8;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
220 while (cnt > 7) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
221 int ps_extension_id = get_bits(gb, 2);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
222 cnt -= 2 + ps_extension(gb, ps, ps_extension_id);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
223 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
224 if (cnt < 0) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
225 av_log(avctx, AV_LOG_ERROR, "ps extension overflow %d", cnt);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
226 goto err;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
227 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
228 skip_bits(gb, cnt);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
229 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
230
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
231 ps->enable_ipdopd &= !PS_BASELINE;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
232
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
233 //Fix up envelopes
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
234 if (!ps->num_env || ps->border_position[ps->num_env] < numQMFSlots - 1) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
235 //Create a fake envelope
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
236 int source = ps->num_env ? ps->num_env - 1 : ps->num_env_old - 1;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
237 if (source >= 0 && source != ps->num_env) {
11893
5ee87f2c9bc8 Allow PS envelope fixup when ps->num_env_old <= 1.
alexc
parents: 11891
diff changeset
238 if (ps->enable_iid) {
11886
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
239 memcpy(ps->iid_par+ps->num_env, ps->iid_par+source, sizeof(ps->iid_par[0]));
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
240 }
11893
5ee87f2c9bc8 Allow PS envelope fixup when ps->num_env_old <= 1.
alexc
parents: 11891
diff changeset
241 if (ps->enable_icc) {
11886
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
242 memcpy(ps->icc_par+ps->num_env, ps->icc_par+source, sizeof(ps->icc_par[0]));
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
243 }
11893
5ee87f2c9bc8 Allow PS envelope fixup when ps->num_env_old <= 1.
alexc
parents: 11891
diff changeset
244 if (ps->enable_ipdopd) {
11886
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
245 memcpy(ps->ipd_par+ps->num_env, ps->ipd_par+source, sizeof(ps->ipd_par[0]));
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
246 memcpy(ps->opd_par+ps->num_env, ps->opd_par+source, sizeof(ps->opd_par[0]));
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
247 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
248 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
249 ps->num_env++;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
250 ps->border_position[ps->num_env] = numQMFSlots - 1;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
251 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
252
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
253
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
254 ps->is34bands_old = ps->is34bands;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
255 if (!PS_BASELINE && (ps->enable_iid || ps->enable_icc))
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
256 ps->is34bands = (ps->enable_iid && ps->nr_iid_par == 34) ||
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
257 (ps->enable_icc && ps->nr_icc_par == 34);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
258
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
259 //Baseline
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
260 if (!ps->enable_ipdopd) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
261 memset(ps->ipd_par, 0, sizeof(ps->ipd_par));
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
262 memset(ps->opd_par, 0, sizeof(ps->opd_par));
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
263 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
264
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
265 if (header)
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
266 ps->start = 1;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
267
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
268 bits_consumed = get_bits_count(gb) - bit_count_start;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
269 if (bits_consumed <= bits_left) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
270 skip_bits_long(gb_host, bits_consumed);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
271 return bits_consumed;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
272 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
273 av_log(avctx, AV_LOG_ERROR, "Expected to read %d PS bits actually read %d.\n", bits_left, bits_consumed);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
274 err:
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
275 ps->start = 0;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
276 skip_bits_long(gb_host, bits_left);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
277 return bits_left;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
278 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
279
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
280 /** Split one subband into 2 subsubbands with a symmetric real filter.
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
281 * The filter must have its non-center even coefficients equal to zero. */
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
282 static void hybrid2_re(float (*in)[2], float (*out)[32][2], const float filter[7], int len, int reverse)
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
283 {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
284 int i, j;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
285 for (i = 0; i < len; i++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
286 float re_in = filter[6] * in[6+i][0]; //real inphase
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
287 float re_op = 0.0f; //real out of phase
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
288 float im_in = filter[6] * in[6+i][1]; //imag inphase
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
289 float im_op = 0.0f; //imag out of phase
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
290 for (j = 0; j < 6; j += 2) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
291 re_op += filter[j+1] * (in[i+j+1][0] + in[12-j-1+i][0]);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
292 im_op += filter[j+1] * (in[i+j+1][1] + in[12-j-1+i][1]);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
293 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
294 out[ reverse][i][0] = re_in + re_op;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
295 out[ reverse][i][1] = im_in + im_op;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
296 out[!reverse][i][0] = re_in - re_op;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
297 out[!reverse][i][1] = im_in - im_op;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
298 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
299 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
300
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
301 /** Split one subband into 6 subsubbands with a complex filter */
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
302 static void hybrid6_cx(float (*in)[2], float (*out)[32][2], const float (*filter)[7][2], int len)
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
303 {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
304 int i, j, ssb;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
305 int N = 8;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
306 float temp[8][2];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
307
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
308 for (i = 0; i < len; i++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
309 for (ssb = 0; ssb < N; ssb++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
310 float sum_re = filter[ssb][6][0] * in[i+6][0], sum_im = filter[ssb][6][0] * in[i+6][1];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
311 for (j = 0; j < 6; j++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
312 float in0_re = in[i+j][0];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
313 float in0_im = in[i+j][1];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
314 float in1_re = in[i+12-j][0];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
315 float in1_im = in[i+12-j][1];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
316 sum_re += filter[ssb][j][0] * (in0_re + in1_re) - filter[ssb][j][1] * (in0_im - in1_im);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
317 sum_im += filter[ssb][j][0] * (in0_im + in1_im) + filter[ssb][j][1] * (in0_re - in1_re);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
318 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
319 temp[ssb][0] = sum_re;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
320 temp[ssb][1] = sum_im;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
321 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
322 out[0][i][0] = temp[6][0];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
323 out[0][i][1] = temp[6][1];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
324 out[1][i][0] = temp[7][0];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
325 out[1][i][1] = temp[7][1];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
326 out[2][i][0] = temp[0][0];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
327 out[2][i][1] = temp[0][1];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
328 out[3][i][0] = temp[1][0];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
329 out[3][i][1] = temp[1][1];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
330 out[4][i][0] = temp[2][0] + temp[5][0];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
331 out[4][i][1] = temp[2][1] + temp[5][1];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
332 out[5][i][0] = temp[3][0] + temp[4][0];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
333 out[5][i][1] = temp[3][1] + temp[4][1];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
334 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
335 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
336
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
337 static void hybrid4_8_12_cx(float (*in)[2], float (*out)[32][2], const float (*filter)[7][2], int N, int len)
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
338 {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
339 int i, j, ssb;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
340
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
341 for (i = 0; i < len; i++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
342 for (ssb = 0; ssb < N; ssb++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
343 float sum_re = filter[ssb][6][0] * in[i+6][0], sum_im = filter[ssb][6][0] * in[i+6][1];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
344 for (j = 0; j < 6; j++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
345 float in0_re = in[i+j][0];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
346 float in0_im = in[i+j][1];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
347 float in1_re = in[i+12-j][0];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
348 float in1_im = in[i+12-j][1];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
349 sum_re += filter[ssb][j][0] * (in0_re + in1_re) - filter[ssb][j][1] * (in0_im - in1_im);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
350 sum_im += filter[ssb][j][0] * (in0_im + in1_im) + filter[ssb][j][1] * (in0_re - in1_re);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
351 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
352 out[ssb][i][0] = sum_re;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
353 out[ssb][i][1] = sum_im;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
354 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
355 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
356 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
357
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
358 static void hybrid_analysis(float out[91][32][2], float in[5][44][2], float L[2][38][64], int is34, int len)
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
359 {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
360 int i, j;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
361 for (i = 0; i < 5; i++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
362 for (j = 0; j < 38; j++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
363 in[i][j+6][0] = L[0][j][i];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
364 in[i][j+6][1] = L[1][j][i];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
365 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
366 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
367 if(is34) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
368 hybrid4_8_12_cx(in[0], out, f34_0_12, 12, len);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
369 hybrid4_8_12_cx(in[1], out+12, f34_1_8, 8, len);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
370 hybrid4_8_12_cx(in[2], out+20, f34_2_4, 4, len);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
371 hybrid4_8_12_cx(in[3], out+24, f34_2_4, 4, len);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
372 hybrid4_8_12_cx(in[4], out+28, f34_2_4, 4, len);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
373 for (i = 0; i < 59; i++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
374 for (j = 0; j < len; j++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
375 out[i+32][j][0] = L[0][j][i+5];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
376 out[i+32][j][1] = L[1][j][i+5];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
377 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
378 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
379 } else {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
380 hybrid6_cx(in[0], out, f20_0_8, len);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
381 hybrid2_re(in[1], out+6, g1_Q2, len, 1);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
382 hybrid2_re(in[2], out+8, g1_Q2, len, 0);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
383 for (i = 0; i < 61; i++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
384 for (j = 0; j < len; j++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
385 out[i+10][j][0] = L[0][j][i+3];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
386 out[i+10][j][1] = L[1][j][i+3];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
387 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
388 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
389 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
390 //update in_buf
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
391 for (i = 0; i < 5; i++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
392 memcpy(in[i], in[i]+32, 6 * sizeof(in[i][0]));
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
393 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
394 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
395
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
396 static void hybrid_synthesis(float out[2][38][64], float in[91][32][2], int is34, int len)
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
397 {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
398 int i, n;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
399 if(is34) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
400 for (n = 0; n < len; n++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
401 memset(out[0][n], 0, 5*sizeof(out[0][n][0]));
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
402 memset(out[1][n], 0, 5*sizeof(out[1][n][0]));
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
403 for(i = 0; i < 12; i++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
404 out[0][n][0] += in[ i][n][0];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
405 out[1][n][0] += in[ i][n][1];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
406 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
407 for(i = 0; i < 8; i++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
408 out[0][n][1] += in[12+i][n][0];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
409 out[1][n][1] += in[12+i][n][1];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
410 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
411 for(i = 0; i < 4; i++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
412 out[0][n][2] += in[20+i][n][0];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
413 out[1][n][2] += in[20+i][n][1];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
414 out[0][n][3] += in[24+i][n][0];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
415 out[1][n][3] += in[24+i][n][1];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
416 out[0][n][4] += in[28+i][n][0];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
417 out[1][n][4] += in[28+i][n][1];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
418 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
419 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
420 for (i = 0; i < 59; i++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
421 for (n = 0; n < len; n++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
422 out[0][n][i+5] = in[i+32][n][0];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
423 out[1][n][i+5] = in[i+32][n][1];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
424 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
425 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
426 } else {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
427 for (n = 0; n < len; n++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
428 out[0][n][0] = in[0][n][0] + in[1][n][0] + in[2][n][0] +
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
429 in[3][n][0] + in[4][n][0] + in[5][n][0];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
430 out[1][n][0] = in[0][n][1] + in[1][n][1] + in[2][n][1] +
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
431 in[3][n][1] + in[4][n][1] + in[5][n][1];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
432 out[0][n][1] = in[6][n][0] + in[7][n][0];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
433 out[1][n][1] = in[6][n][1] + in[7][n][1];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
434 out[0][n][2] = in[8][n][0] + in[9][n][0];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
435 out[1][n][2] = in[8][n][1] + in[9][n][1];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
436 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
437 for (i = 0; i < 61; i++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
438 for (n = 0; n < len; n++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
439 out[0][n][i+3] = in[i+10][n][0];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
440 out[1][n][i+3] = in[i+10][n][1];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
441 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
442 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
443 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
444 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
445
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
446 /// All-pass filter decay slope
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
447 #define DECAY_SLOPE 0.05f
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
448 /// Number of frequency bands that can be addressed by the parameter index, b(k)
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
449 static const int NR_PAR_BANDS[] = { 20, 34 };
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
450 /// Number of frequency bands that can be addressed by the sub subband index, k
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
451 static const int NR_BANDS[] = { 71, 91 };
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
452 /// Start frequency band for the all-pass filter decay slope
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
453 static const int DECAY_CUTOFF[] = { 10, 32 };
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
454 /// Number of all-pass filer bands
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
455 static const int NR_ALLPASS_BANDS[] = { 30, 50 };
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
456 /// First stereo band using the short one sample delay
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
457 static const int SHORT_DELAY_BAND[] = { 42, 62 };
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
458
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
459 /** Table 8.46 */
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
460 static void map_idx_10_to_20(int8_t *par_mapped, const int8_t *par, int full)
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
461 {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
462 int b;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
463 if (full)
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
464 b = 9;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
465 else {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
466 b = 4;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
467 par_mapped[10] = 0;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
468 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
469 for (; b >= 0; b--) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
470 par_mapped[2*b+1] = par_mapped[2*b] = par[b];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
471 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
472 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
473
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
474 static void map_idx_34_to_20(int8_t *par_mapped, const int8_t *par, int full)
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
475 {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
476 par_mapped[ 0] = (2*par[ 0] + par[ 1]) / 3;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
477 par_mapped[ 1] = ( par[ 1] + 2*par[ 2]) / 3;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
478 par_mapped[ 2] = (2*par[ 3] + par[ 4]) / 3;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
479 par_mapped[ 3] = ( par[ 4] + 2*par[ 5]) / 3;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
480 par_mapped[ 4] = ( par[ 6] + par[ 7]) / 2;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
481 par_mapped[ 5] = ( par[ 8] + par[ 9]) / 2;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
482 par_mapped[ 6] = par[10];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
483 par_mapped[ 7] = par[11];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
484 par_mapped[ 8] = ( par[12] + par[13]) / 2;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
485 par_mapped[ 9] = ( par[14] + par[15]) / 2;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
486 par_mapped[10] = par[16];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
487 if (full) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
488 par_mapped[11] = par[17];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
489 par_mapped[12] = par[18];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
490 par_mapped[13] = par[19];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
491 par_mapped[14] = ( par[20] + par[21]) / 2;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
492 par_mapped[15] = ( par[22] + par[23]) / 2;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
493 par_mapped[16] = ( par[24] + par[25]) / 2;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
494 par_mapped[17] = ( par[26] + par[27]) / 2;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
495 par_mapped[18] = ( par[28] + par[29] + par[30] + par[31]) / 4;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
496 par_mapped[19] = ( par[32] + par[33]) / 2;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
497 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
498 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
499
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
500 static void map_val_34_to_20(float par[PS_MAX_NR_IIDICC])
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
501 {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
502 par[ 0] = (2*par[ 0] + par[ 1]) * 0.33333333f;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
503 par[ 1] = ( par[ 1] + 2*par[ 2]) * 0.33333333f;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
504 par[ 2] = (2*par[ 3] + par[ 4]) * 0.33333333f;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
505 par[ 3] = ( par[ 4] + 2*par[ 5]) * 0.33333333f;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
506 par[ 4] = ( par[ 6] + par[ 7]) * 0.5f;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
507 par[ 5] = ( par[ 8] + par[ 9]) * 0.5f;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
508 par[ 6] = par[10];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
509 par[ 7] = par[11];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
510 par[ 8] = ( par[12] + par[13]) * 0.5f;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
511 par[ 9] = ( par[14] + par[15]) * 0.5f;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
512 par[10] = par[16];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
513 par[11] = par[17];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
514 par[12] = par[18];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
515 par[13] = par[19];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
516 par[14] = ( par[20] + par[21]) * 0.5f;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
517 par[15] = ( par[22] + par[23]) * 0.5f;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
518 par[16] = ( par[24] + par[25]) * 0.5f;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
519 par[17] = ( par[26] + par[27]) * 0.5f;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
520 par[18] = ( par[28] + par[29] + par[30] + par[31]) * 0.25f;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
521 par[19] = ( par[32] + par[33]) * 0.5f;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
522 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
523
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
524 static void map_idx_10_to_34(int8_t *par_mapped, const int8_t *par, int full)
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
525 {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
526 if (full) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
527 par_mapped[33] = par[9];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
528 par_mapped[32] = par[9];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
529 par_mapped[31] = par[9];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
530 par_mapped[30] = par[9];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
531 par_mapped[29] = par[9];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
532 par_mapped[28] = par[9];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
533 par_mapped[27] = par[8];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
534 par_mapped[26] = par[8];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
535 par_mapped[25] = par[8];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
536 par_mapped[24] = par[8];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
537 par_mapped[23] = par[7];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
538 par_mapped[22] = par[7];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
539 par_mapped[21] = par[7];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
540 par_mapped[20] = par[7];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
541 par_mapped[19] = par[6];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
542 par_mapped[18] = par[6];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
543 par_mapped[17] = par[5];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
544 par_mapped[16] = par[5];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
545 } else {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
546 par_mapped[16] = 0;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
547 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
548 par_mapped[15] = par[4];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
549 par_mapped[14] = par[4];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
550 par_mapped[13] = par[4];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
551 par_mapped[12] = par[4];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
552 par_mapped[11] = par[3];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
553 par_mapped[10] = par[3];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
554 par_mapped[ 9] = par[2];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
555 par_mapped[ 8] = par[2];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
556 par_mapped[ 7] = par[2];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
557 par_mapped[ 6] = par[2];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
558 par_mapped[ 5] = par[1];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
559 par_mapped[ 4] = par[1];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
560 par_mapped[ 3] = par[1];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
561 par_mapped[ 2] = par[0];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
562 par_mapped[ 1] = par[0];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
563 par_mapped[ 0] = par[0];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
564 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
565
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
566 static void map_idx_20_to_34(int8_t *par_mapped, const int8_t *par, int full)
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
567 {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
568 if (full) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
569 par_mapped[33] = par[19];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
570 par_mapped[32] = par[19];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
571 par_mapped[31] = par[18];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
572 par_mapped[30] = par[18];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
573 par_mapped[29] = par[18];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
574 par_mapped[28] = par[18];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
575 par_mapped[27] = par[17];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
576 par_mapped[26] = par[17];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
577 par_mapped[25] = par[16];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
578 par_mapped[24] = par[16];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
579 par_mapped[23] = par[15];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
580 par_mapped[22] = par[15];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
581 par_mapped[21] = par[14];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
582 par_mapped[20] = par[14];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
583 par_mapped[19] = par[13];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
584 par_mapped[18] = par[12];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
585 par_mapped[17] = par[11];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
586 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
587 par_mapped[16] = par[10];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
588 par_mapped[15] = par[ 9];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
589 par_mapped[14] = par[ 9];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
590 par_mapped[13] = par[ 8];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
591 par_mapped[12] = par[ 8];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
592 par_mapped[11] = par[ 7];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
593 par_mapped[10] = par[ 6];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
594 par_mapped[ 9] = par[ 5];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
595 par_mapped[ 8] = par[ 5];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
596 par_mapped[ 7] = par[ 4];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
597 par_mapped[ 6] = par[ 4];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
598 par_mapped[ 5] = par[ 3];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
599 par_mapped[ 4] = (par[ 2] + par[ 3]) / 2;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
600 par_mapped[ 3] = par[ 2];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
601 par_mapped[ 2] = par[ 1];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
602 par_mapped[ 1] = (par[ 0] + par[ 1]) / 2;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
603 par_mapped[ 0] = par[ 0];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
604 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
605
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
606 static void map_val_20_to_34(float par[PS_MAX_NR_IIDICC])
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
607 {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
608 par[33] = par[19];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
609 par[32] = par[19];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
610 par[31] = par[18];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
611 par[30] = par[18];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
612 par[29] = par[18];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
613 par[28] = par[18];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
614 par[27] = par[17];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
615 par[26] = par[17];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
616 par[25] = par[16];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
617 par[24] = par[16];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
618 par[23] = par[15];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
619 par[22] = par[15];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
620 par[21] = par[14];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
621 par[20] = par[14];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
622 par[19] = par[13];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
623 par[18] = par[12];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
624 par[17] = par[11];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
625 par[16] = par[10];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
626 par[15] = par[ 9];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
627 par[14] = par[ 9];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
628 par[13] = par[ 8];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
629 par[12] = par[ 8];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
630 par[11] = par[ 7];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
631 par[10] = par[ 6];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
632 par[ 9] = par[ 5];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
633 par[ 8] = par[ 5];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
634 par[ 7] = par[ 4];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
635 par[ 6] = par[ 4];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
636 par[ 5] = par[ 3];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
637 par[ 4] = (par[ 2] + par[ 3]) * 0.5f;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
638 par[ 3] = par[ 2];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
639 par[ 2] = par[ 1];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
640 par[ 1] = (par[ 0] + par[ 1]) * 0.5f;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
641 par[ 0] = par[ 0];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
642 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
643
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
644 static void decorrelation(PSContext *ps, float (*out)[32][2], const float (*s)[32][2], int is34)
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
645 {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
646 float power[34][PS_QMF_TIME_SLOTS] = {{0}};
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
647 float transient_gain[34][PS_QMF_TIME_SLOTS];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
648 float *peak_decay_nrg = ps->peak_decay_nrg;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
649 float *power_smooth = ps->power_smooth;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
650 float *peak_decay_diff_smooth = ps->peak_decay_diff_smooth;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
651 float (*delay)[PS_QMF_TIME_SLOTS + PS_MAX_DELAY][2] = ps->delay;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
652 float (*ap_delay)[PS_AP_LINKS][PS_QMF_TIME_SLOTS + PS_MAX_AP_DELAY][2] = ps->ap_delay;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
653 const int8_t *k_to_i = is34 ? k_to_i_34 : k_to_i_20;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
654 const float peak_decay_factor = 0.76592833836465f;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
655 const float transient_impact = 1.5f;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
656 const float a_smooth = 0.25f; //< Smoothing coefficient
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
657 int i, k, m, n;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
658 int n0 = 0, nL = 32;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
659 static const int link_delay[] = { 3, 4, 5 };
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
660 static const float a[] = { 0.65143905753106f,
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
661 0.56471812200776f,
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
662 0.48954165955695f };
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
663
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
664 if (is34 != ps->is34bands_old) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
665 memset(ps->peak_decay_nrg, 0, sizeof(ps->peak_decay_nrg));
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
666 memset(ps->power_smooth, 0, sizeof(ps->power_smooth));
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
667 memset(ps->peak_decay_diff_smooth, 0, sizeof(ps->peak_decay_diff_smooth));
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
668 memset(ps->delay, 0, sizeof(ps->delay));
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
669 memset(ps->ap_delay, 0, sizeof(ps->ap_delay));
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
670 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
671
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
672 for (n = n0; n < nL; n++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
673 for (k = 0; k < NR_BANDS[is34]; k++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
674 int i = k_to_i[k];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
675 power[i][n] += s[k][n][0] * s[k][n][0] + s[k][n][1] * s[k][n][1];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
676 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
677 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
678
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
679 //Transient detection
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
680 for (i = 0; i < NR_PAR_BANDS[is34]; i++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
681 for (n = n0; n < nL; n++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
682 float decayed_peak = peak_decay_factor * peak_decay_nrg[i];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
683 float denom;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
684 peak_decay_nrg[i] = FFMAX(decayed_peak, power[i][n]);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
685 power_smooth[i] += a_smooth * (power[i][n] - power_smooth[i]);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
686 peak_decay_diff_smooth[i] += a_smooth * (peak_decay_nrg[i] - power[i][n] - peak_decay_diff_smooth[i]);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
687 denom = transient_impact * peak_decay_diff_smooth[i];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
688 transient_gain[i][n] = (denom > power_smooth[i]) ?
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
689 power_smooth[i] / denom : 1.0f;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
690 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
691 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
692
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
693 //Decorrelation and transient reduction
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
694 // PS_AP_LINKS - 1
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
695 // -----
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
696 // | | Q_fract_allpass[k][m]*z^-link_delay[m] - a[m]*g_decay_slope[k]
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
697 //H[k][z] = z^-2 * phi_fract[k] * | | ----------------------------------------------------------------
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
698 // | | 1 - a[m]*g_decay_slope[k]*Q_fract_allpass[k][m]*z^-link_delay[m]
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
699 // m = 0
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
700 //d[k][z] (out) = transient_gain_mapped[k][z] * H[k][z] * s[k][z]
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
701 for (k = 0; k < NR_ALLPASS_BANDS[is34]; k++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
702 int b = k_to_i[k];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
703 float g_decay_slope = 1.f - DECAY_SLOPE * (k - DECAY_CUTOFF[is34]);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
704 float ag[PS_AP_LINKS];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
705 g_decay_slope = av_clipf(g_decay_slope, 0.f, 1.f);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
706 memcpy(delay[k], delay[k]+nL, PS_MAX_DELAY*sizeof(delay[k][0]));
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
707 memcpy(delay[k]+PS_MAX_DELAY, s[k], numQMFSlots*sizeof(delay[k][0]));
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
708 for (m = 0; m < PS_AP_LINKS; m++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
709 memcpy(ap_delay[k][m], ap_delay[k][m]+numQMFSlots, 5*sizeof(ap_delay[k][m][0]));
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
710 ag[m] = a[m] * g_decay_slope;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
711 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
712 for (n = n0; n < nL; n++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
713 float in_re = delay[k][n+PS_MAX_DELAY-2][0] * phi_fract[is34][k][0] -
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
714 delay[k][n+PS_MAX_DELAY-2][1] * phi_fract[is34][k][1];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
715 float in_im = delay[k][n+PS_MAX_DELAY-2][0] * phi_fract[is34][k][1] +
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
716 delay[k][n+PS_MAX_DELAY-2][1] * phi_fract[is34][k][0];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
717 for (m = 0; m < PS_AP_LINKS; m++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
718 float a_re = ag[m] * in_re;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
719 float a_im = ag[m] * in_im;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
720 float link_delay_re = ap_delay[k][m][n+5-link_delay[m]][0];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
721 float link_delay_im = ap_delay[k][m][n+5-link_delay[m]][1];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
722 float fractional_delay_re = Q_fract_allpass[is34][k][m][0];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
723 float fractional_delay_im = Q_fract_allpass[is34][k][m][1];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
724 ap_delay[k][m][n+5][0] = in_re;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
725 ap_delay[k][m][n+5][1] = in_im;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
726 in_re = link_delay_re * fractional_delay_re - link_delay_im * fractional_delay_im - a_re;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
727 in_im = link_delay_re * fractional_delay_im + link_delay_im * fractional_delay_re - a_im;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
728 ap_delay[k][m][n+5][0] += ag[m] * in_re;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
729 ap_delay[k][m][n+5][1] += ag[m] * in_im;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
730 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
731 out[k][n][0] = transient_gain[b][n] * in_re;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
732 out[k][n][1] = transient_gain[b][n] * in_im;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
733 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
734 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
735 for (; k < SHORT_DELAY_BAND[is34]; k++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
736 memcpy(delay[k], delay[k]+nL, PS_MAX_DELAY*sizeof(delay[k][0]));
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
737 memcpy(delay[k]+PS_MAX_DELAY, s[k], numQMFSlots*sizeof(delay[k][0]));
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
738 for (n = n0; n < nL; n++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
739 //H = delay 14
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
740 out[k][n][0] = transient_gain[k_to_i[k]][n] * delay[k][n+PS_MAX_DELAY-14][0];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
741 out[k][n][1] = transient_gain[k_to_i[k]][n] * delay[k][n+PS_MAX_DELAY-14][1];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
742 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
743 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
744 for (; k < NR_BANDS[is34]; k++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
745 memcpy(delay[k], delay[k]+nL, PS_MAX_DELAY*sizeof(delay[k][0]));
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
746 memcpy(delay[k]+PS_MAX_DELAY, s[k], numQMFSlots*sizeof(delay[k][0]));
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
747 for (n = n0; n < nL; n++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
748 //H = delay 1
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
749 out[k][n][0] = transient_gain[k_to_i[k]][n] * delay[k][n+PS_MAX_DELAY-1][0];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
750 out[k][n][1] = transient_gain[k_to_i[k]][n] * delay[k][n+PS_MAX_DELAY-1][1];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
751 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
752 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
753 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
754
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
755 static void remap34(int8_t (**p_par_mapped)[PS_MAX_NR_IIDICC],
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
756 int8_t (*par)[PS_MAX_NR_IIDICC],
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
757 int num_par, int num_env, int full)
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
758 {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
759 int8_t (*par_mapped)[PS_MAX_NR_IIDICC] = *p_par_mapped;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
760 int e;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
761 if (num_par == 20 || num_par == 11) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
762 for (e = 0; e < num_env; e++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
763 map_idx_20_to_34(par_mapped[e], par[e], full);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
764 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
765 } else if (num_par == 10 || num_par == 5) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
766 for (e = 0; e < num_env; e++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
767 map_idx_10_to_34(par_mapped[e], par[e], full);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
768 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
769 } else {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
770 *p_par_mapped = par;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
771 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
772 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
773
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
774 static void remap20(int8_t (**p_par_mapped)[PS_MAX_NR_IIDICC],
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
775 int8_t (*par)[PS_MAX_NR_IIDICC],
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
776 int num_par, int num_env, int full)
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
777 {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
778 int8_t (*par_mapped)[PS_MAX_NR_IIDICC] = *p_par_mapped;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
779 int e;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
780 if (num_par == 34 || num_par == 17) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
781 for (e = 0; e < num_env; e++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
782 map_idx_34_to_20(par_mapped[e], par[e], full);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
783 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
784 } else if (num_par == 10 || num_par == 5) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
785 for (e = 0; e < num_env; e++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
786 map_idx_10_to_20(par_mapped[e], par[e], full);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
787 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
788 } else {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
789 *p_par_mapped = par;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
790 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
791 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
792
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
793 static void stereo_processing(PSContext *ps, float (*l)[32][2], float (*r)[32][2], int is34)
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
794 {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
795 int e, b, k, n;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
796
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
797 float (*H11)[PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC] = ps->H11;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
798 float (*H12)[PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC] = ps->H12;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
799 float (*H21)[PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC] = ps->H21;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
800 float (*H22)[PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC] = ps->H22;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
801 int8_t *opd_hist = ps->opd_hist;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
802 int8_t *ipd_hist = ps->ipd_hist;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
803 int8_t iid_mapped_buf[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
804 int8_t icc_mapped_buf[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
805 int8_t ipd_mapped_buf[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
806 int8_t opd_mapped_buf[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
807 int8_t (*iid_mapped)[PS_MAX_NR_IIDICC] = iid_mapped_buf;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
808 int8_t (*icc_mapped)[PS_MAX_NR_IIDICC] = icc_mapped_buf;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
809 int8_t (*ipd_mapped)[PS_MAX_NR_IIDICC] = ipd_mapped_buf;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
810 int8_t (*opd_mapped)[PS_MAX_NR_IIDICC] = opd_mapped_buf;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
811 const int8_t *k_to_i = is34 ? k_to_i_34 : k_to_i_20;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
812 const float (*H_LUT)[8][4] = (PS_BASELINE || ps->icc_mode < 3) ? HA : HB;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
813
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
814 //Remapping
11894
335524dba347 Use memcpy() where appropriate in PS stereo processing remapping.
alexc
parents: 11893
diff changeset
815 memcpy(H11[0][0], H11[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H11[0][0][0]));
335524dba347 Use memcpy() where appropriate in PS stereo processing remapping.
alexc
parents: 11893
diff changeset
816 memcpy(H11[1][0], H11[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H11[1][0][0]));
335524dba347 Use memcpy() where appropriate in PS stereo processing remapping.
alexc
parents: 11893
diff changeset
817 memcpy(H12[0][0], H12[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H12[0][0][0]));
335524dba347 Use memcpy() where appropriate in PS stereo processing remapping.
alexc
parents: 11893
diff changeset
818 memcpy(H12[1][0], H12[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H12[1][0][0]));
335524dba347 Use memcpy() where appropriate in PS stereo processing remapping.
alexc
parents: 11893
diff changeset
819 memcpy(H21[0][0], H21[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H21[0][0][0]));
335524dba347 Use memcpy() where appropriate in PS stereo processing remapping.
alexc
parents: 11893
diff changeset
820 memcpy(H21[1][0], H21[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H21[1][0][0]));
335524dba347 Use memcpy() where appropriate in PS stereo processing remapping.
alexc
parents: 11893
diff changeset
821 memcpy(H22[0][0], H22[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H22[0][0][0]));
335524dba347 Use memcpy() where appropriate in PS stereo processing remapping.
alexc
parents: 11893
diff changeset
822 memcpy(H22[1][0], H22[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H22[1][0][0]));
11886
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
823 if (is34) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
824 remap34(&iid_mapped, ps->iid_par, ps->nr_iid_par, ps->num_env, 1);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
825 remap34(&icc_mapped, ps->icc_par, ps->nr_icc_par, ps->num_env, 1);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
826 if (ps->enable_ipdopd) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
827 remap34(&ipd_mapped, ps->ipd_par, ps->nr_ipdopd_par, ps->num_env, 0);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
828 remap34(&opd_mapped, ps->opd_par, ps->nr_ipdopd_par, ps->num_env, 0);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
829 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
830 if (!ps->is34bands_old) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
831 map_val_20_to_34(H11[0][0]);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
832 map_val_20_to_34(H11[1][0]);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
833 map_val_20_to_34(H12[0][0]);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
834 map_val_20_to_34(H12[1][0]);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
835 map_val_20_to_34(H21[0][0]);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
836 map_val_20_to_34(H21[1][0]);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
837 map_val_20_to_34(H22[0][0]);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
838 map_val_20_to_34(H22[1][0]);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
839 ipdopd_reset(ipd_hist, opd_hist);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
840 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
841 } else {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
842 remap20(&iid_mapped, ps->iid_par, ps->nr_iid_par, ps->num_env, 1);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
843 remap20(&icc_mapped, ps->icc_par, ps->nr_icc_par, ps->num_env, 1);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
844 if (ps->enable_ipdopd) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
845 remap20(&ipd_mapped, ps->ipd_par, ps->nr_ipdopd_par, ps->num_env, 0);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
846 remap20(&opd_mapped, ps->opd_par, ps->nr_ipdopd_par, ps->num_env, 0);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
847 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
848 if (ps->is34bands_old) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
849 map_val_34_to_20(H11[0][0]);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
850 map_val_34_to_20(H11[1][0]);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
851 map_val_34_to_20(H12[0][0]);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
852 map_val_34_to_20(H12[1][0]);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
853 map_val_34_to_20(H21[0][0]);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
854 map_val_34_to_20(H21[1][0]);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
855 map_val_34_to_20(H22[0][0]);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
856 map_val_34_to_20(H22[1][0]);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
857 ipdopd_reset(ipd_hist, opd_hist);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
858 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
859 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
860
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
861 //Mixing
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
862 for (e = 0; e < ps->num_env; e++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
863 for (b = 0; b < NR_PAR_BANDS[is34]; b++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
864 float h11, h12, h21, h22;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
865 h11 = H_LUT[iid_mapped[e][b] + 7 + 23 * ps->iid_quant][icc_mapped[e][b]][0];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
866 h12 = H_LUT[iid_mapped[e][b] + 7 + 23 * ps->iid_quant][icc_mapped[e][b]][1];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
867 h21 = H_LUT[iid_mapped[e][b] + 7 + 23 * ps->iid_quant][icc_mapped[e][b]][2];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
868 h22 = H_LUT[iid_mapped[e][b] + 7 + 23 * ps->iid_quant][icc_mapped[e][b]][3];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
869 if (!PS_BASELINE && ps->enable_ipdopd && b < ps->nr_ipdopd_par) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
870 //The spec say says to only run this smoother when enable_ipdopd
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
871 //is set but the reference decoder appears to run it constantly
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
872 float h11i, h12i, h21i, h22i;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
873 float ipd_adj_re, ipd_adj_im;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
874 int opd_idx = opd_hist[b] * 8 + opd_mapped[e][b];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
875 int ipd_idx = ipd_hist[b] * 8 + ipd_mapped[e][b];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
876 float opd_re = pd_re_smooth[opd_idx];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
877 float opd_im = pd_im_smooth[opd_idx];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
878 float ipd_re = pd_re_smooth[ipd_idx];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
879 float ipd_im = pd_im_smooth[ipd_idx];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
880 opd_hist[b] = opd_idx & 0x3F;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
881 ipd_hist[b] = ipd_idx & 0x3F;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
882
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
883 ipd_adj_re = opd_re*ipd_re + opd_im*ipd_im;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
884 ipd_adj_im = opd_im*ipd_re - opd_re*ipd_im;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
885 h11i = h11 * opd_im;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
886 h11 = h11 * opd_re;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
887 h12i = h12 * ipd_adj_im;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
888 h12 = h12 * ipd_adj_re;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
889 h21i = h21 * opd_im;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
890 h21 = h21 * opd_re;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
891 h22i = h22 * ipd_adj_im;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
892 h22 = h22 * ipd_adj_re;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
893 H11[1][e+1][b] = h11i;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
894 H12[1][e+1][b] = h12i;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
895 H21[1][e+1][b] = h21i;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
896 H22[1][e+1][b] = h22i;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
897 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
898 H11[0][e+1][b] = h11;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
899 H12[0][e+1][b] = h12;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
900 H21[0][e+1][b] = h21;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
901 H22[0][e+1][b] = h22;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
902 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
903 for (k = 0; k < NR_BANDS[is34]; k++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
904 float h11r, h12r, h21r, h22r;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
905 float h11i, h12i, h21i, h22i;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
906 float h11r_step, h12r_step, h21r_step, h22r_step;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
907 float h11i_step, h12i_step, h21i_step, h22i_step;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
908 int start = ps->border_position[e];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
909 int stop = ps->border_position[e+1];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
910 float width = 1.f / (stop - start);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
911 b = k_to_i[k];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
912 h11r = H11[0][e][b];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
913 h12r = H12[0][e][b];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
914 h21r = H21[0][e][b];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
915 h22r = H22[0][e][b];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
916 if (!PS_BASELINE && ps->enable_ipdopd) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
917 //Is this necessary? ps_04_new seems unchanged
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
918 if ((is34 && k <= 13 && k >= 9) || (!is34 && k <= 1)) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
919 h11i = -H11[1][e][b];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
920 h12i = -H12[1][e][b];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
921 h21i = -H21[1][e][b];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
922 h22i = -H22[1][e][b];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
923 } else {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
924 h11i = H11[1][e][b];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
925 h12i = H12[1][e][b];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
926 h21i = H21[1][e][b];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
927 h22i = H22[1][e][b];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
928 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
929 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
930 //Interpolation
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
931 h11r_step = (H11[0][e+1][b] - h11r) * width;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
932 h12r_step = (H12[0][e+1][b] - h12r) * width;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
933 h21r_step = (H21[0][e+1][b] - h21r) * width;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
934 h22r_step = (H22[0][e+1][b] - h22r) * width;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
935 if (!PS_BASELINE && ps->enable_ipdopd) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
936 h11i_step = (H11[1][e+1][b] - h11i) * width;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
937 h12i_step = (H12[1][e+1][b] - h12i) * width;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
938 h21i_step = (H21[1][e+1][b] - h21i) * width;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
939 h22i_step = (H22[1][e+1][b] - h22i) * width;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
940 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
941 for (n = start + 1; n <= stop; n++) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
942 //l is s, r is d
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
943 float l_re = l[k][n][0];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
944 float l_im = l[k][n][1];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
945 float r_re = r[k][n][0];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
946 float r_im = r[k][n][1];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
947 h11r += h11r_step;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
948 h12r += h12r_step;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
949 h21r += h21r_step;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
950 h22r += h22r_step;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
951 if (!PS_BASELINE && ps->enable_ipdopd) {
11895
775714d113cd Cosmetics: whitespace.
alexc
parents: 11894
diff changeset
952 h11i += h11i_step;
775714d113cd Cosmetics: whitespace.
alexc
parents: 11894
diff changeset
953 h12i += h12i_step;
775714d113cd Cosmetics: whitespace.
alexc
parents: 11894
diff changeset
954 h21i += h21i_step;
775714d113cd Cosmetics: whitespace.
alexc
parents: 11894
diff changeset
955 h22i += h22i_step;
11886
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
956
11895
775714d113cd Cosmetics: whitespace.
alexc
parents: 11894
diff changeset
957 l[k][n][0] = h11r*l_re + h21r*r_re - h11i*l_im - h21i*r_im;
775714d113cd Cosmetics: whitespace.
alexc
parents: 11894
diff changeset
958 l[k][n][1] = h11r*l_im + h21r*r_im + h11i*l_re + h21i*r_re;
775714d113cd Cosmetics: whitespace.
alexc
parents: 11894
diff changeset
959 r[k][n][0] = h12r*l_re + h22r*r_re - h12i*l_im - h22i*r_im;
775714d113cd Cosmetics: whitespace.
alexc
parents: 11894
diff changeset
960 r[k][n][1] = h12r*l_im + h22r*r_im + h12i*l_re + h22i*r_re;
11886
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
961 } else {
11895
775714d113cd Cosmetics: whitespace.
alexc
parents: 11894
diff changeset
962 l[k][n][0] = h11r*l_re + h21r*r_re;
775714d113cd Cosmetics: whitespace.
alexc
parents: 11894
diff changeset
963 l[k][n][1] = h11r*l_im + h21r*r_im;
775714d113cd Cosmetics: whitespace.
alexc
parents: 11894
diff changeset
964 r[k][n][0] = h12r*l_re + h22r*r_re;
775714d113cd Cosmetics: whitespace.
alexc
parents: 11894
diff changeset
965 r[k][n][1] = h12r*l_im + h22r*r_im;
11886
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
966 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
967 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
968 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
969 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
970 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
971
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
972 int ff_ps_apply(AVCodecContext *avctx, PSContext *ps, float L[2][38][64], float R[2][38][64], int top)
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
973 {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
974 float Lbuf[91][32][2];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
975 float Rbuf[91][32][2];
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
976 const int len = 32;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
977 int is34 = ps->is34bands;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
978
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
979 top += NR_BANDS[is34] - 64;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
980 memset(ps->delay+top, 0, (NR_BANDS[is34] - top)*sizeof(ps->delay[0]));
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
981 if (top < NR_ALLPASS_BANDS[is34])
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
982 memset(ps->ap_delay + top, 0, (NR_ALLPASS_BANDS[is34] - top)*sizeof(ps->ap_delay[0]));
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
983
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
984 hybrid_analysis(Lbuf, ps->in_buf, L, is34, len);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
985 decorrelation(ps, Rbuf, Lbuf, is34);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
986 stereo_processing(ps, Lbuf, Rbuf, is34);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
987 hybrid_synthesis(L, Lbuf, is34, len);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
988 hybrid_synthesis(R, Rbuf, is34, len);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
989
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
990 return 0;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
991 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
992
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
993 #define PS_INIT_VLC_STATIC(num, size) \
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
994 INIT_VLC_STATIC(&vlc_ps[num], 9, ps_tmp[num].table_size / ps_tmp[num].elem_size, \
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
995 ps_tmp[num].ps_bits, 1, 1, \
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
996 ps_tmp[num].ps_codes, ps_tmp[num].elem_size, ps_tmp[num].elem_size, \
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
997 size);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
998
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
999 #define PS_VLC_ROW(name) \
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
1000 { name ## _codes, name ## _bits, sizeof(name ## _codes), sizeof(name ## _codes[0]) }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
1001
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
1002 av_cold void ff_ps_init(void) {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
1003 // Syntax initialization
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
1004 static const struct {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
1005 const void *ps_codes, *ps_bits;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
1006 const unsigned int table_size, elem_size;
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
1007 } ps_tmp[] = {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
1008 PS_VLC_ROW(huff_iid_df1),
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
1009 PS_VLC_ROW(huff_iid_dt1),
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
1010 PS_VLC_ROW(huff_iid_df0),
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
1011 PS_VLC_ROW(huff_iid_dt0),
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
1012 PS_VLC_ROW(huff_icc_df),
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
1013 PS_VLC_ROW(huff_icc_dt),
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
1014 PS_VLC_ROW(huff_ipd_df),
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
1015 PS_VLC_ROW(huff_ipd_dt),
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
1016 PS_VLC_ROW(huff_opd_df),
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
1017 PS_VLC_ROW(huff_opd_dt),
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
1018 };
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
1019
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
1020 PS_INIT_VLC_STATIC(0, 1544);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
1021 PS_INIT_VLC_STATIC(1, 832);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
1022 PS_INIT_VLC_STATIC(2, 1024);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
1023 PS_INIT_VLC_STATIC(3, 1036);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
1024 PS_INIT_VLC_STATIC(4, 544);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
1025 PS_INIT_VLC_STATIC(5, 544);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
1026 PS_INIT_VLC_STATIC(6, 512);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
1027 PS_INIT_VLC_STATIC(7, 512);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
1028 PS_INIT_VLC_STATIC(8, 512);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
1029 PS_INIT_VLC_STATIC(9, 512);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
1030
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
1031 ps_tableinit();
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
1032 }
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
1033
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
1034 av_cold void ff_ps_ctx_init(PSContext *ps)
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
1035 {
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
1036 ipdopd_reset(ps->ipd_hist, ps->opd_hist);
2d81202be6e2 Add HE-AAC v2 support to the AAC decoder.
alexc
parents:
diff changeset
1037 }