annotate aacps.c @ 12468:443f38ceeaad libavcodec

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