Originally committed as revision 23647 to svn://svn.ffmpeg.org/ffmpeg/trunk
Alex Converse authored on 2010/06/19 23:14:51... | ... |
@@ -42,7 +42,7 @@ OBJS-$(CONFIG_VAAPI) += vaapi.o |
42 | 42 |
OBJS-$(CONFIG_VDPAU) += vdpau.o |
43 | 43 |
|
44 | 44 |
# decoders/encoders/hardware accelerators |
45 |
-OBJS-$(CONFIG_AAC_DECODER) += aacdec.o aactab.o aacsbr.o |
|
45 |
+OBJS-$(CONFIG_AAC_DECODER) += aacdec.o aactab.o aacsbr.o ps.o |
|
46 | 46 |
OBJS-$(CONFIG_AAC_ENCODER) += aacenc.o aaccoder.o \ |
47 | 47 |
aacpsy.o aactab.o \ |
48 | 48 |
psymodel.o iirfilter.o \ |
... | ... |
@@ -667,5 +667,6 @@ $(SUBDIR)mpegaudiodec.o: $(SUBDIR)mpegaudio_tables.h |
667 | 667 |
$(SUBDIR)mpegaudiodec_float.o: $(SUBDIR)mpegaudio_tables.h |
668 | 668 |
$(SUBDIR)motionpixels.o: $(SUBDIR)motionpixels_tables.h |
669 | 669 |
$(SUBDIR)pcm.o: $(SUBDIR)pcm_tables.h |
670 |
+$(SUBDIR)ps.o: $(SUBDIR)ps_tables.h |
|
670 | 671 |
$(SUBDIR)qdm2.o: $(SUBDIR)qdm2_tables.h |
671 | 672 |
endif |
... | ... |
@@ -67,7 +67,7 @@ |
67 | 67 |
* Y (not in this code) Layer-2 |
68 | 68 |
* Y (not in this code) Layer-3 |
69 | 69 |
* N SinuSoidal Coding (Transient, Sinusoid, Noise) |
70 |
- * N (planned) Parametric Stereo |
|
70 |
+ * Y Parametric Stereo |
|
71 | 71 |
* N Direct Stream Transfer |
72 | 72 |
* |
73 | 73 |
* Note: - HE AAC v1 comprises LC AAC with Spectral Band Replication. |
... | ... |
@@ -200,7 +200,8 @@ static av_cold int che_configure(AACContext *ac, |
200 | 200 |
ff_aac_sbr_ctx_init(&ac->che[type][id]->sbr); |
201 | 201 |
if (type != TYPE_CCE) { |
202 | 202 |
ac->output_data[(*channels)++] = ac->che[type][id]->ch[0].ret; |
203 |
- if (type == TYPE_CPE) { |
|
203 |
+ if (type == TYPE_CPE || |
|
204 |
+ (type == TYPE_SCE && ac->m4ac.ps == 1)) { |
|
204 | 205 |
ac->output_data[(*channels)++] = ac->che[type][id]->ch[1].ret; |
205 | 206 |
} |
206 | 207 |
} |
... | ... |
@@ -228,6 +229,7 @@ static av_cold int output_configure(AACContext *ac, |
228 | 228 |
AVCodecContext *avctx = ac->avctx; |
229 | 229 |
int i, type, channels = 0, ret; |
230 | 230 |
|
231 |
+ if (new_che_pos != che_pos) |
|
231 | 232 |
memcpy(che_pos, new_che_pos, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0])); |
232 | 233 |
|
233 | 234 |
if (channel_config) { |
... | ... |
@@ -471,6 +473,8 @@ static int decode_audio_specific_config(AACContext *ac, void *data, |
471 | 471 |
av_log(ac->avctx, AV_LOG_ERROR, "invalid sampling rate index %d\n", ac->m4ac.sampling_index); |
472 | 472 |
return -1; |
473 | 473 |
} |
474 |
+ if (ac->m4ac.sbr == 1 && ac->m4ac.ps == -1) |
|
475 |
+ ac->m4ac.ps = 1; |
|
474 | 476 |
|
475 | 477 |
skip_bits_long(&gb, i); |
476 | 478 |
|
... | ... |
@@ -1667,6 +1671,10 @@ static int decode_extension_payload(AACContext *ac, GetBitContext *gb, int cnt, |
1667 | 1667 |
av_log(ac->avctx, AV_LOG_ERROR, "Implicit SBR was found with a first occurrence after the first frame.\n"); |
1668 | 1668 |
skip_bits_long(gb, 8 * cnt - 4); |
1669 | 1669 |
return res; |
1670 |
+ } else if (ac->m4ac.ps == -1 && ac->output_configured < OC_LOCKED && ac->avctx->channels == 1) { |
|
1671 |
+ ac->m4ac.sbr = 1; |
|
1672 |
+ ac->m4ac.ps = 1; |
|
1673 |
+ output_configure(ac, ac->che_pos, ac->che_pos, ac->m4ac.chan_config, ac->output_configured); |
|
1670 | 1674 |
} else { |
1671 | 1675 |
ac->m4ac.sbr = 1; |
1672 | 1676 |
} |
... | ... |
@@ -1946,8 +1954,10 @@ static int parse_adts_frame_header(AACContext *ac, GetBitContext *gb) |
1946 | 1946 |
} else if (ac->output_configured != OC_LOCKED) { |
1947 | 1947 |
ac->output_configured = OC_NONE; |
1948 | 1948 |
} |
1949 |
- if (ac->output_configured != OC_LOCKED) |
|
1949 |
+ if (ac->output_configured != OC_LOCKED) { |
|
1950 | 1950 |
ac->m4ac.sbr = -1; |
1951 |
+ ac->m4ac.ps = -1; |
|
1952 |
+ } |
|
1951 | 1953 |
ac->m4ac.sample_rate = hdr_info.sample_rate; |
1952 | 1954 |
ac->m4ac.sampling_index = hdr_info.sampling_index; |
1953 | 1955 |
ac->m4ac.object_type = hdr_info.object_type; |
... | ... |
@@ -31,6 +31,7 @@ |
31 | 31 |
#include "aacsbr.h" |
32 | 32 |
#include "aacsbrdata.h" |
33 | 33 |
#include "fft.h" |
34 |
+#include "ps.h" |
|
34 | 35 |
|
35 | 36 |
#include <stdint.h> |
36 | 37 |
#include <float.h> |
... | ... |
@@ -120,6 +121,8 @@ av_cold void ff_aac_sbr_init(void) |
120 | 120 |
|
121 | 121 |
for (n = 0; n < 320; n++) |
122 | 122 |
sbr_qmf_window_ds[n] = sbr_qmf_window_us[2*n]; |
123 |
+ |
|
124 |
+ ff_ps_init(); |
|
123 | 125 |
} |
124 | 126 |
|
125 | 127 |
av_cold void ff_aac_sbr_ctx_init(SpectralBandReplication *sbr) |
... | ... |
@@ -130,6 +133,7 @@ av_cold void ff_aac_sbr_ctx_init(SpectralBandReplication *sbr) |
130 | 130 |
sbr->data[1].synthesis_filterbank_samples_offset = SBR_SYNTHESIS_BUF_SIZE - (1280 - 128); |
131 | 131 |
ff_mdct_init(&sbr->mdct, 7, 1, 1.0/64); |
132 | 132 |
ff_mdct_init(&sbr->mdct_ana, 7, 1, -2.0); |
133 |
+ ff_ps_ctx_init(&sbr->ps); |
|
133 | 134 |
} |
134 | 135 |
|
135 | 136 |
av_cold void ff_aac_sbr_ctx_close(SpectralBandReplication *sbr) |
... | ... |
@@ -890,7 +894,6 @@ static void read_sbr_extension(AACContext *ac, SpectralBandReplication *sbr, |
890 | 890 |
GetBitContext *gb, |
891 | 891 |
int bs_extension_id, int *num_bits_left) |
892 | 892 |
{ |
893 |
-//TODO - implement ps_data for parametric stereo parsing |
|
894 | 893 |
switch (bs_extension_id) { |
895 | 894 |
case EXTENSION_ID_PS: |
896 | 895 |
if (!ac->m4ac.ps) { |
... | ... |
@@ -898,8 +901,8 @@ static void read_sbr_extension(AACContext *ac, SpectralBandReplication *sbr, |
898 | 898 |
skip_bits_long(gb, *num_bits_left); // bs_fill_bits |
899 | 899 |
*num_bits_left = 0; |
900 | 900 |
} else { |
901 |
-#if 0 |
|
902 |
- *num_bits_left -= ff_ps_data(gb, ps); |
|
901 |
+#if 1 |
|
902 |
+ *num_bits_left -= ff_ps_read_data(ac->avctx, gb, &sbr->ps, *num_bits_left); |
|
903 | 903 |
#else |
904 | 904 |
av_log_missing_feature(ac->avctx, "Parametric Stereo is", 0); |
905 | 905 |
skip_bits_long(gb, *num_bits_left); // bs_fill_bits |
... | ... |
@@ -1008,6 +1011,11 @@ static unsigned int read_sbr_data(AACContext *ac, SpectralBandReplication *sbr, |
1008 | 1008 |
num_bits_left -= 2; |
1009 | 1009 |
read_sbr_extension(ac, sbr, gb, get_bits(gb, 2), &num_bits_left); // bs_extension_id |
1010 | 1010 |
} |
1011 |
+ if (num_bits_left < 0) { |
|
1012 |
+ av_log(ac->avctx, AV_LOG_ERROR, "SBR Extension over read.\n"); |
|
1013 |
+ } |
|
1014 |
+ if (num_bits_left > 0) |
|
1015 |
+ skip_bits(gb, num_bits_left); |
|
1011 | 1016 |
} |
1012 | 1017 |
|
1013 | 1018 |
return get_bits_count(gb) - cnt; |
... | ... |
@@ -1166,7 +1174,7 @@ static void sbr_qmf_analysis(DSPContext *dsp, FFTContext *mdct, const float *in, |
1166 | 1166 |
* (14496-3 sp04 p206) |
1167 | 1167 |
*/ |
1168 | 1168 |
static void sbr_qmf_synthesis(DSPContext *dsp, FFTContext *mdct, |
1169 |
- float *out, float X[2][32][64], |
|
1169 |
+ float *out, float X[2][38][64], |
|
1170 | 1170 |
float mdct_buf[2][64], |
1171 | 1171 |
float *v0, int *v_off, const unsigned int div, |
1172 | 1172 |
float bias, float scale) |
... | ... |
@@ -1402,7 +1410,7 @@ static int sbr_hf_gen(AACContext *ac, SpectralBandReplication *sbr, |
1402 | 1402 |
} |
1403 | 1403 |
|
1404 | 1404 |
/// Generate the subband filtered lowband |
1405 |
-static int sbr_x_gen(SpectralBandReplication *sbr, float X[2][32][64], |
|
1405 |
+static int sbr_x_gen(SpectralBandReplication *sbr, float X[2][38][64], |
|
1406 | 1406 |
const float X_low[32][40][2], const float Y[2][38][64][2], |
1407 | 1407 |
int ch) |
1408 | 1408 |
{ |
... | ... |
@@ -1424,7 +1432,7 @@ static int sbr_x_gen(SpectralBandReplication *sbr, float X[2][32][64], |
1424 | 1424 |
} |
1425 | 1425 |
|
1426 | 1426 |
for (k = 0; k < sbr->kx[1]; k++) { |
1427 |
- for (i = i_Temp; i < i_f; i++) { |
|
1427 |
+ for (i = i_Temp; i < 38; i++) { |
|
1428 | 1428 |
X[0][i][k] = X_low[k][i + ENVELOPE_ADJUSTMENT_OFFSET][0]; |
1429 | 1429 |
X[1][i][k] = X_low[k][i + ENVELOPE_ADJUSTMENT_OFFSET][1]; |
1430 | 1430 |
} |
... | ... |
@@ -1740,6 +1748,16 @@ void ff_sbr_apply(AACContext *ac, SpectralBandReplication *sbr, int id_aac, |
1740 | 1740 |
/* synthesis */ |
1741 | 1741 |
sbr_x_gen(sbr, sbr->X[ch], sbr->X_low, sbr->data[ch].Y, ch); |
1742 | 1742 |
} |
1743 |
+ |
|
1744 |
+ if (ac->m4ac.ps == 1) { |
|
1745 |
+ if (sbr->ps.start) { |
|
1746 |
+ ff_ps_apply(ac->avctx, &sbr->ps, sbr->X[0], sbr->X[1], sbr->kx[1] + sbr->m[1]); |
|
1747 |
+ } else { |
|
1748 |
+ memcpy(sbr->X[1], sbr->X[0], sizeof(sbr->X[0])); |
|
1749 |
+ } |
|
1750 |
+ nch = 2; |
|
1751 |
+ } |
|
1752 |
+ |
|
1743 | 1753 |
sbr_qmf_synthesis(&ac->dsp, &sbr->mdct, L, sbr->X[0], sbr->qmf_filter_scratch, |
1744 | 1754 |
sbr->data[0].synthesis_filterbank_samples, |
1745 | 1755 |
&sbr->data[0].synthesis_filterbank_samples_offset, |
... | ... |
@@ -30,7 +30,7 @@ |
30 | 30 |
#include "libavutil/avutil.h" |
31 | 31 |
|
32 | 32 |
#define LIBAVCODEC_VERSION_MAJOR 52 |
33 |
-#define LIBAVCODEC_VERSION_MINOR 76 |
|
33 |
+#define LIBAVCODEC_VERSION_MINOR 77 |
|
34 | 34 |
#define LIBAVCODEC_VERSION_MICRO 0 |
35 | 35 |
|
36 | 36 |
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ |
... | ... |
@@ -131,6 +131,14 @@ int ff_mpeg4audio_get_config(MPEG4AudioConfig *c, const uint8_t *buf, int buf_si |
131 | 131 |
get_bits1(&gb); // skip 1 bit |
132 | 132 |
} |
133 | 133 |
} |
134 |
+ |
|
135 |
+ //PS requires SBR |
|
136 |
+ if (!c->sbr) |
|
137 |
+ c->ps = 0; |
|
138 |
+ //Limit implicit PS to the HE-AACv2 Profile |
|
139 |
+ if ((c->ps == -1 && c->object_type != AOT_AAC_LC) || c->channels & ~0x01) |
|
140 |
+ c->ps = 0; |
|
141 |
+ |
|
134 | 142 |
return specific_config_bitindex; |
135 | 143 |
} |
136 | 144 |
|
137 | 145 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,1124 @@ |
0 |
+/* |
|
1 |
+ * MPEG-4 Parametric Stereo decoding functions |
|
2 |
+ * Copyright (c) 2010 Alex Converse <alex.converse@gmail.com> |
|
3 |
+ * |
|
4 |
+ * This file is part of FFmpeg. |
|
5 |
+ * |
|
6 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
7 |
+ * modify it under the terms of the GNU Lesser General Public |
|
8 |
+ * License as published by the Free Software Foundation; either |
|
9 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
10 |
+ * |
|
11 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
12 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 |
+ * Lesser General Public License for more details. |
|
15 |
+ * |
|
16 |
+ * You should have received a copy of the GNU Lesser General Public |
|
17 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
18 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
19 |
+ */ |
|
20 |
+ |
|
21 |
+#include <stdint.h> |
|
22 |
+#include "libavutil/mathematics.h" |
|
23 |
+#include "avcodec.h" |
|
24 |
+#include "get_bits.h" |
|
25 |
+#include "ps.h" |
|
26 |
+#include "ps_tablegen.h" |
|
27 |
+#include "psdata.c" |
|
28 |
+ |
|
29 |
+#define PS_BASELINE 0 |
|
30 |
+ |
|
31 |
+#define numQMFSlots 32 //numTimeSlots * RATE |
|
32 |
+ |
|
33 |
+static const int8_t num_env_tab[2][4] = { |
|
34 |
+ { 0, 1, 2, 4, }, |
|
35 |
+ { 1, 2, 3, 4, }, |
|
36 |
+}; |
|
37 |
+ |
|
38 |
+static const int8_t nr_iidicc_par_tab[] = { |
|
39 |
+ 10, 20, 34, 10, 20, 34, |
|
40 |
+}; |
|
41 |
+ |
|
42 |
+static const int8_t nr_iidopd_par_tab[] = { |
|
43 |
+ 5, 11, 17, 5, 11, 17, |
|
44 |
+}; |
|
45 |
+ |
|
46 |
+enum { |
|
47 |
+ huff_iid_df1, |
|
48 |
+ huff_iid_dt1, |
|
49 |
+ huff_iid_df0, |
|
50 |
+ huff_iid_dt0, |
|
51 |
+ huff_icc_df, |
|
52 |
+ huff_icc_dt, |
|
53 |
+ huff_ipd_df, |
|
54 |
+ huff_ipd_dt, |
|
55 |
+ huff_opd_df, |
|
56 |
+ huff_opd_dt, |
|
57 |
+}; |
|
58 |
+ |
|
59 |
+static const int huff_iid[] = { |
|
60 |
+ huff_iid_df0, |
|
61 |
+ huff_iid_df1, |
|
62 |
+ huff_iid_dt0, |
|
63 |
+ huff_iid_dt1, |
|
64 |
+}; |
|
65 |
+ |
|
66 |
+static VLC vlc_ps[10]; |
|
67 |
+ |
|
68 |
+/** |
|
69 |
+ * Read Inter-channel Intensity Difference parameters from the bitstream. |
|
70 |
+ * |
|
71 |
+ * @param avctx contains the current codec context |
|
72 |
+ * @param gb pointer to the input bitstream |
|
73 |
+ * @param ps pointer to the Parametric Stereo context |
|
74 |
+ * @param e envelope to decode |
|
75 |
+ * @param dt 1: time delta-coded, 0: frequency delta-coded |
|
76 |
+ */ |
|
77 |
+static int iid_data(AVCodecContext *avctx, GetBitContext *gb, PSContext *ps, int e, int dt) |
|
78 |
+{ |
|
79 |
+ int b; |
|
80 |
+ int table_idx = huff_iid[2*dt+ps->iid_quant]; |
|
81 |
+ VLC_TYPE (*vlc_table)[2] = vlc_ps[table_idx].table; |
|
82 |
+ if (dt) { |
|
83 |
+ int e_prev = e ? e - 1 : ps->num_env_old - 1; |
|
84 |
+ e_prev = FFMAX(e_prev, 0); |
|
85 |
+ for (b = 0; b < ps->nr_iid_par; b++) { |
|
86 |
+ ps->iid_par[e][b] = ps->iid_par[e_prev][b] + |
|
87 |
+ get_vlc2(gb, vlc_table, 9, 3) - |
|
88 |
+ huff_offset[table_idx]; |
|
89 |
+ if (FFABS(ps->iid_par[e][b]) > 7 + 8 * ps->iid_quant) |
|
90 |
+ goto err; |
|
91 |
+ } |
|
92 |
+ } else { |
|
93 |
+ int prev = 0; |
|
94 |
+ for (b = 0; b < ps->nr_iid_par; b++) { |
|
95 |
+ prev += get_vlc2(gb, vlc_table, 9, 3) - |
|
96 |
+ huff_offset[table_idx]; |
|
97 |
+ ps->iid_par[e][b] = prev; |
|
98 |
+ if (FFABS(ps->iid_par[e][b]) > 7 + 8 * ps->iid_quant) |
|
99 |
+ goto err; |
|
100 |
+ } |
|
101 |
+ } |
|
102 |
+ return 0; |
|
103 |
+err: |
|
104 |
+ av_log(avctx, AV_LOG_ERROR, "illegal iid\n"); |
|
105 |
+ return -1; |
|
106 |
+} |
|
107 |
+ |
|
108 |
+/** |
|
109 |
+ * Read Inter-Channel Coherence parameters from the bitstream. |
|
110 |
+ * |
|
111 |
+ * @param avctx contains the current codec context |
|
112 |
+ * @param gb pointer to the input bitstream |
|
113 |
+ * @param ps pointer to the Parametric Stereo context |
|
114 |
+ * @param e envelope to decode |
|
115 |
+ * @param dt 1: time delta-coded, 0: frequency delta-coded |
|
116 |
+ */ |
|
117 |
+static int icc_data(AVCodecContext *avctx, GetBitContext *gb, PSContext *ps, int e, int dt) |
|
118 |
+{ |
|
119 |
+ int b; |
|
120 |
+ int table_idx = dt ? huff_icc_dt : huff_icc_df; |
|
121 |
+ VLC_TYPE (*vlc_table)[2] = vlc_ps[table_idx].table; |
|
122 |
+ if (dt) { |
|
123 |
+ int e_prev = e ? e - 1 : ps->num_env_old - 1; |
|
124 |
+ e_prev = FFMAX(e_prev, 0); |
|
125 |
+ for (b = 0; b < ps->nr_icc_par; b++) { |
|
126 |
+ ps->icc_par[e][b] = ps->icc_par[e_prev][b] + get_vlc2(gb, vlc_table, 9, 3) - huff_offset[table_idx]; |
|
127 |
+ if (ps->icc_par[e][b] > 7U) |
|
128 |
+ goto err; |
|
129 |
+ } |
|
130 |
+ } else { |
|
131 |
+ int prev = 0; |
|
132 |
+ for (b = 0; b < ps->nr_icc_par; b++) { |
|
133 |
+ prev += get_vlc2(gb, vlc_table, 9, 3) - huff_offset[table_idx]; |
|
134 |
+ ps->icc_par[e][b] = prev; |
|
135 |
+ if (ps->icc_par[e][b] > 7U) |
|
136 |
+ goto err; |
|
137 |
+ } |
|
138 |
+ } |
|
139 |
+ return 0; |
|
140 |
+err: |
|
141 |
+ av_log(avctx, AV_LOG_ERROR, "illegal icc\n"); |
|
142 |
+ return -1; |
|
143 |
+} |
|
144 |
+ |
|
145 |
+/** |
|
146 |
+ * Read Inter-channel Phase Difference parameters from the bitstream. |
|
147 |
+ * |
|
148 |
+ * @param gb pointer to the input bitstream |
|
149 |
+ * @param ps pointer to the Parametric Stereo context |
|
150 |
+ * @param e envelope to decode |
|
151 |
+ * @param dt 1: time delta-coded, 0: frequency delta-coded |
|
152 |
+ */ |
|
153 |
+static void ipd_data(GetBitContext *gb, PSContext *ps, int e, int dt) |
|
154 |
+{ |
|
155 |
+ int b; |
|
156 |
+ int table_idx = dt ? huff_ipd_dt : huff_ipd_df; |
|
157 |
+ VLC_TYPE (*vlc_table)[2] = vlc_ps[table_idx].table; |
|
158 |
+ if (dt) { |
|
159 |
+ int e_prev = e ? e - 1 : ps->num_env_old - 1; |
|
160 |
+ e_prev = FFMAX(e_prev, 0); |
|
161 |
+ for (b = 0; b < ps->nr_ipdopd_par; b++) { |
|
162 |
+ ps->ipd_par[e][b] = (ps->ipd_par[e_prev][b] + get_vlc2(gb, vlc_table, 9, 1)) & 0x07; |
|
163 |
+ } |
|
164 |
+ } else { |
|
165 |
+ int prev = 0; |
|
166 |
+ for (b = 0; b < ps->nr_ipdopd_par; b++) { |
|
167 |
+ prev += get_vlc2(gb, vlc_table, 9, 3); |
|
168 |
+ prev &= 0x07; |
|
169 |
+ ps->ipd_par[e][b] = prev; |
|
170 |
+ } |
|
171 |
+ } |
|
172 |
+} |
|
173 |
+ |
|
174 |
+/** |
|
175 |
+ * Read Overall Phase Difference parameters from the bitstream. |
|
176 |
+ * |
|
177 |
+ * @param gb pointer to the input bitstream |
|
178 |
+ * @param ps pointer to the Parametric Stereo context |
|
179 |
+ * @param e envelope to decode |
|
180 |
+ * @param dt 1: time delta-coded, 0: frequency delta-coded |
|
181 |
+ */ |
|
182 |
+static void opd_data(GetBitContext *gb, PSContext *ps, int e, int dt) |
|
183 |
+{ |
|
184 |
+ int b; |
|
185 |
+ int table_idx = dt ? huff_opd_dt : huff_opd_df; |
|
186 |
+ VLC_TYPE (*vlc_table)[2] = vlc_ps[table_idx].table; |
|
187 |
+ if (dt) { |
|
188 |
+ int e_prev = e ? e - 1 : ps->num_env_old - 1; |
|
189 |
+ e_prev = FFMAX(e_prev, 0); |
|
190 |
+ for (b = 0; b < ps->nr_ipdopd_par; b++) { |
|
191 |
+ ps->opd_par[e][b] = (ps->opd_par[e_prev][b] + get_vlc2(gb, vlc_table, 9, 1)) & 0x07; |
|
192 |
+ } |
|
193 |
+ } else { |
|
194 |
+ int prev = 0; |
|
195 |
+ for (b = 0; b < ps->nr_ipdopd_par; b++) { |
|
196 |
+ prev += get_vlc2(gb, vlc_table, 9, 3); |
|
197 |
+ prev &= 0x07; |
|
198 |
+ ps->opd_par[e][b] = prev; |
|
199 |
+ } |
|
200 |
+ } |
|
201 |
+} |
|
202 |
+ |
|
203 |
+static int ps_extension(GetBitContext *gb, PSContext *ps, int ps_extension_id) |
|
204 |
+{ |
|
205 |
+ int e; |
|
206 |
+ int count = get_bits_count(gb); |
|
207 |
+ |
|
208 |
+ if (ps_extension_id) |
|
209 |
+ return 0; |
|
210 |
+ |
|
211 |
+ ps->enable_ipdopd = get_bits1(gb); |
|
212 |
+ if (ps->enable_ipdopd) { |
|
213 |
+ for (e = 0; e < ps->num_env; e++) { |
|
214 |
+ int dt = get_bits1(gb); |
|
215 |
+ ipd_data(gb, ps, e, dt); |
|
216 |
+ dt = get_bits1(gb); |
|
217 |
+ opd_data(gb, ps, e, dt); |
|
218 |
+ } |
|
219 |
+ } |
|
220 |
+ skip_bits1(gb); //reserved_ps |
|
221 |
+ return get_bits_count(gb) - count; |
|
222 |
+} |
|
223 |
+ |
|
224 |
+static void ipdopd_reset(int8_t *opd_hist, int8_t *ipd_hist) |
|
225 |
+{ |
|
226 |
+ int i; |
|
227 |
+ for (i = 0; i < PS_MAX_NR_IPDOPD; i++) { |
|
228 |
+ opd_hist[i] = 0; |
|
229 |
+ ipd_hist[i] = 0; |
|
230 |
+ } |
|
231 |
+} |
|
232 |
+ |
|
233 |
+int ff_ps_read_data(AVCodecContext *avctx, GetBitContext *gb_host, PSContext *ps, int bits_left) |
|
234 |
+{ |
|
235 |
+ int e; |
|
236 |
+ int bit_count_start = get_bits_count(gb_host); |
|
237 |
+ int header; |
|
238 |
+ int bits_consumed; |
|
239 |
+ GetBitContext gbc = *gb_host, *gb = &gbc; |
|
240 |
+ |
|
241 |
+ header = get_bits1(gb); |
|
242 |
+ if (header) { //enable_ps_header |
|
243 |
+ ps->enable_iid = get_bits1(gb); |
|
244 |
+ if (ps->enable_iid) { |
|
245 |
+ ps->iid_mode = get_bits(gb, 3); |
|
246 |
+ if (ps->iid_mode > 5) { |
|
247 |
+ av_log(avctx, AV_LOG_ERROR, "iid_mode %d is reserved.\n", |
|
248 |
+ ps->iid_mode); |
|
249 |
+ goto err; |
|
250 |
+ } |
|
251 |
+ ps->nr_iid_par = nr_iidicc_par_tab[ps->iid_mode]; |
|
252 |
+ ps->iid_quant = ps->iid_mode > 2; |
|
253 |
+ ps->nr_ipdopd_par = nr_iidopd_par_tab[ps->iid_mode]; |
|
254 |
+ } |
|
255 |
+ ps->enable_icc = get_bits1(gb); |
|
256 |
+ if (ps->enable_icc) { |
|
257 |
+ ps->icc_mode = get_bits(gb, 3); |
|
258 |
+ if (ps->icc_mode > 5) { |
|
259 |
+ av_log(avctx, AV_LOG_ERROR, "icc_mode %d is reserved.\n", |
|
260 |
+ ps->icc_mode); |
|
261 |
+ goto err; |
|
262 |
+ } |
|
263 |
+ ps->nr_icc_par = nr_iidicc_par_tab[ps->icc_mode]; |
|
264 |
+ } |
|
265 |
+ ps->enable_ext = get_bits1(gb); |
|
266 |
+ } |
|
267 |
+ |
|
268 |
+ ps->frame_class = get_bits1(gb); |
|
269 |
+ ps->num_env_old = ps->num_env; |
|
270 |
+ ps->num_env = num_env_tab[ps->frame_class][get_bits(gb, 2)]; |
|
271 |
+ |
|
272 |
+ ps->border_position[0] = -1; |
|
273 |
+ if (ps->frame_class) { |
|
274 |
+ for (e = 1; e <= ps->num_env; e++) |
|
275 |
+ ps->border_position[e] = get_bits(gb, 5); |
|
276 |
+ } else |
|
277 |
+ for (e = 1; e <= ps->num_env; e++) |
|
278 |
+ ps->border_position[e] = e * numQMFSlots / ps->num_env - 1; |
|
279 |
+ |
|
280 |
+ if (ps->enable_iid) { |
|
281 |
+ for (e = 0; e < ps->num_env; e++) { |
|
282 |
+ int dt = get_bits1(gb); |
|
283 |
+ if (iid_data(avctx, gb, ps, e, dt)) |
|
284 |
+ goto err; |
|
285 |
+ } |
|
286 |
+ } else |
|
287 |
+ memset(ps->iid_par, 0, sizeof(ps->iid_par)); |
|
288 |
+ |
|
289 |
+ if (ps->enable_icc) |
|
290 |
+ for (e = 0; e < ps->num_env; e++) { |
|
291 |
+ int dt = get_bits1(gb); |
|
292 |
+ if (icc_data(avctx, gb, ps, e, dt)) |
|
293 |
+ goto err; |
|
294 |
+ } |
|
295 |
+ else |
|
296 |
+ memset(ps->icc_par, 0, sizeof(ps->icc_par)); |
|
297 |
+ |
|
298 |
+ if (ps->enable_ext) { |
|
299 |
+ int cnt = get_bits(gb, 4); |
|
300 |
+ if (cnt == 15) { |
|
301 |
+ cnt += get_bits(gb, 8); |
|
302 |
+ } |
|
303 |
+ cnt *= 8; |
|
304 |
+ while (cnt > 7) { |
|
305 |
+ int ps_extension_id = get_bits(gb, 2); |
|
306 |
+ cnt -= 2 + ps_extension(gb, ps, ps_extension_id); |
|
307 |
+ } |
|
308 |
+ if (cnt < 0) { |
|
309 |
+ av_log(avctx, AV_LOG_ERROR, "ps extension overflow %d", cnt); |
|
310 |
+ goto err; |
|
311 |
+ } |
|
312 |
+ skip_bits(gb, cnt); |
|
313 |
+ } |
|
314 |
+ |
|
315 |
+ ps->enable_ipdopd &= !PS_BASELINE; |
|
316 |
+ |
|
317 |
+ //Fix up envelopes |
|
318 |
+ if (!ps->num_env || ps->border_position[ps->num_env] < numQMFSlots - 1) { |
|
319 |
+ //Create a fake envelope |
|
320 |
+ int source = ps->num_env ? ps->num_env - 1 : ps->num_env_old - 1; |
|
321 |
+ if (source >= 0 && source != ps->num_env) { |
|
322 |
+ if (ps->enable_iid && ps->num_env_old > 1) { |
|
323 |
+ memcpy(ps->iid_par+ps->num_env, ps->iid_par+source, sizeof(ps->iid_par[0])); |
|
324 |
+ } |
|
325 |
+ if (ps->enable_icc && ps->num_env_old > 1) { |
|
326 |
+ memcpy(ps->icc_par+ps->num_env, ps->icc_par+source, sizeof(ps->icc_par[0])); |
|
327 |
+ } |
|
328 |
+ if (ps->enable_ipdopd && ps->num_env_old > 1) { |
|
329 |
+ memcpy(ps->ipd_par+ps->num_env, ps->ipd_par+source, sizeof(ps->ipd_par[0])); |
|
330 |
+ memcpy(ps->opd_par+ps->num_env, ps->opd_par+source, sizeof(ps->opd_par[0])); |
|
331 |
+ } |
|
332 |
+ } |
|
333 |
+ ps->num_env++; |
|
334 |
+ ps->border_position[ps->num_env] = numQMFSlots - 1; |
|
335 |
+ } |
|
336 |
+ |
|
337 |
+ |
|
338 |
+ ps->is34bands_old = ps->is34bands; |
|
339 |
+ if (!PS_BASELINE && (ps->enable_iid || ps->enable_icc)) |
|
340 |
+ ps->is34bands = (ps->enable_iid && ps->nr_iid_par == 34) || |
|
341 |
+ (ps->enable_icc && ps->nr_icc_par == 34); |
|
342 |
+ |
|
343 |
+ //Baseline |
|
344 |
+ if (!ps->enable_ipdopd) { |
|
345 |
+ memset(ps->ipd_par, 0, sizeof(ps->ipd_par)); |
|
346 |
+ memset(ps->opd_par, 0, sizeof(ps->opd_par)); |
|
347 |
+ } |
|
348 |
+ |
|
349 |
+ if (header) |
|
350 |
+ ps->start = 1; |
|
351 |
+ |
|
352 |
+ bits_consumed = get_bits_count(gb) - bit_count_start; |
|
353 |
+ if (bits_consumed <= bits_left) { |
|
354 |
+ skip_bits_long(gb_host, bits_consumed); |
|
355 |
+ return bits_consumed; |
|
356 |
+ } |
|
357 |
+ av_log(avctx, AV_LOG_ERROR, "Expected to read %d PS bits actually read %d.\n", bits_left, bits_consumed); |
|
358 |
+err: |
|
359 |
+ ps->start = 0; |
|
360 |
+ skip_bits_long(gb_host, bits_left); |
|
361 |
+ return bits_left; |
|
362 |
+} |
|
363 |
+ |
|
364 |
+/** Split one subband into 2 subsubbands with a symmetric real filter. |
|
365 |
+ * The filter must have its non-center even coefficients equal to zero. */ |
|
366 |
+static void hybrid2_re(float (*in)[2], float (*out)[32][2], const float filter[7], int len, int reverse) |
|
367 |
+{ |
|
368 |
+ int i, j; |
|
369 |
+ for (i = 0; i < len; i++) { |
|
370 |
+ float re_in = filter[6] * in[6+i][0]; //real inphase |
|
371 |
+ float re_op = 0.0f; //real out of phase |
|
372 |
+ float im_in = filter[6] * in[6+i][1]; //imag inphase |
|
373 |
+ float im_op = 0.0f; //imag out of phase |
|
374 |
+ for (j = 0; j < 6; j += 2) { |
|
375 |
+ re_op += filter[j+1] * (in[i+j+1][0] + in[12-j-1+i][0]); |
|
376 |
+ im_op += filter[j+1] * (in[i+j+1][1] + in[12-j-1+i][1]); |
|
377 |
+ } |
|
378 |
+ out[ reverse][i][0] = re_in + re_op; |
|
379 |
+ out[ reverse][i][1] = im_in + im_op; |
|
380 |
+ out[!reverse][i][0] = re_in - re_op; |
|
381 |
+ out[!reverse][i][1] = im_in - im_op; |
|
382 |
+ } |
|
383 |
+} |
|
384 |
+ |
|
385 |
+/** Split one subband into 6 subsubbands with a complex filter */ |
|
386 |
+static void hybrid6_cx(float (*in)[2], float (*out)[32][2], const float (*filter)[7][2], int len) |
|
387 |
+{ |
|
388 |
+ int i, j, ssb; |
|
389 |
+ int N = 8; |
|
390 |
+ float temp[8][2]; |
|
391 |
+ |
|
392 |
+ for (i = 0; i < len; i++) { |
|
393 |
+ for (ssb = 0; ssb < N; ssb++) { |
|
394 |
+ float sum_re = filter[ssb][6][0] * in[i+6][0], sum_im = filter[ssb][6][0] * in[i+6][1]; |
|
395 |
+ for (j = 0; j < 6; j++) { |
|
396 |
+ float in0_re = in[i+j][0]; |
|
397 |
+ float in0_im = in[i+j][1]; |
|
398 |
+ float in1_re = in[i+12-j][0]; |
|
399 |
+ float in1_im = in[i+12-j][1]; |
|
400 |
+ sum_re += filter[ssb][j][0] * (in0_re + in1_re) - filter[ssb][j][1] * (in0_im - in1_im); |
|
401 |
+ sum_im += filter[ssb][j][0] * (in0_im + in1_im) + filter[ssb][j][1] * (in0_re - in1_re); |
|
402 |
+ } |
|
403 |
+ temp[ssb][0] = sum_re; |
|
404 |
+ temp[ssb][1] = sum_im; |
|
405 |
+ } |
|
406 |
+ out[0][i][0] = temp[6][0]; |
|
407 |
+ out[0][i][1] = temp[6][1]; |
|
408 |
+ out[1][i][0] = temp[7][0]; |
|
409 |
+ out[1][i][1] = temp[7][1]; |
|
410 |
+ out[2][i][0] = temp[0][0]; |
|
411 |
+ out[2][i][1] = temp[0][1]; |
|
412 |
+ out[3][i][0] = temp[1][0]; |
|
413 |
+ out[3][i][1] = temp[1][1]; |
|
414 |
+ out[4][i][0] = temp[2][0] + temp[5][0]; |
|
415 |
+ out[4][i][1] = temp[2][1] + temp[5][1]; |
|
416 |
+ out[5][i][0] = temp[3][0] + temp[4][0]; |
|
417 |
+ out[5][i][1] = temp[3][1] + temp[4][1]; |
|
418 |
+ } |
|
419 |
+} |
|
420 |
+ |
|
421 |
+static void hybrid4_8_12_cx(float (*in)[2], float (*out)[32][2], const float (*filter)[7][2], int N, int len) |
|
422 |
+{ |
|
423 |
+ int i, j, ssb; |
|
424 |
+ |
|
425 |
+ for (i = 0; i < len; i++) { |
|
426 |
+ for (ssb = 0; ssb < N; ssb++) { |
|
427 |
+ float sum_re = filter[ssb][6][0] * in[i+6][0], sum_im = filter[ssb][6][0] * in[i+6][1]; |
|
428 |
+ for (j = 0; j < 6; j++) { |
|
429 |
+ float in0_re = in[i+j][0]; |
|
430 |
+ float in0_im = in[i+j][1]; |
|
431 |
+ float in1_re = in[i+12-j][0]; |
|
432 |
+ float in1_im = in[i+12-j][1]; |
|
433 |
+ sum_re += filter[ssb][j][0] * (in0_re + in1_re) - filter[ssb][j][1] * (in0_im - in1_im); |
|
434 |
+ sum_im += filter[ssb][j][0] * (in0_im + in1_im) + filter[ssb][j][1] * (in0_re - in1_re); |
|
435 |
+ } |
|
436 |
+ out[ssb][i][0] = sum_re; |
|
437 |
+ out[ssb][i][1] = sum_im; |
|
438 |
+ } |
|
439 |
+ } |
|
440 |
+} |
|
441 |
+ |
|
442 |
+static void hybrid_analysis(float out[91][32][2], float in[5][44][2], float L[2][38][64], int is34, int len) |
|
443 |
+{ |
|
444 |
+ int i, j; |
|
445 |
+ for (i = 0; i < 5; i++) { |
|
446 |
+ for (j = 0; j < 38; j++) { |
|
447 |
+ in[i][j+6][0] = L[0][j][i]; |
|
448 |
+ in[i][j+6][1] = L[1][j][i]; |
|
449 |
+ } |
|
450 |
+ } |
|
451 |
+ if(is34) { |
|
452 |
+ hybrid4_8_12_cx(in[0], out, f34_0_12, 12, len); |
|
453 |
+ hybrid4_8_12_cx(in[1], out+12, f34_1_8, 8, len); |
|
454 |
+ hybrid4_8_12_cx(in[2], out+20, f34_2_4, 4, len); |
|
455 |
+ hybrid4_8_12_cx(in[3], out+24, f34_2_4, 4, len); |
|
456 |
+ hybrid4_8_12_cx(in[4], out+28, f34_2_4, 4, len); |
|
457 |
+ for (i = 0; i < 59; i++) { |
|
458 |
+ for (j = 0; j < len; j++) { |
|
459 |
+ out[i+32][j][0] = L[0][j][i+5]; |
|
460 |
+ out[i+32][j][1] = L[1][j][i+5]; |
|
461 |
+ } |
|
462 |
+ } |
|
463 |
+ } else { |
|
464 |
+ hybrid6_cx(in[0], out, f20_0_8, len); |
|
465 |
+ hybrid2_re(in[1], out+6, g1_Q2, len, 1); |
|
466 |
+ hybrid2_re(in[2], out+8, g1_Q2, len, 0); |
|
467 |
+ for (i = 0; i < 61; i++) { |
|
468 |
+ for (j = 0; j < len; j++) { |
|
469 |
+ out[i+10][j][0] = L[0][j][i+3]; |
|
470 |
+ out[i+10][j][1] = L[1][j][i+3]; |
|
471 |
+ } |
|
472 |
+ } |
|
473 |
+ } |
|
474 |
+ //update in_buf |
|
475 |
+ for (i = 0; i < 5; i++) { |
|
476 |
+ memcpy(in[i], in[i]+32, 6 * sizeof(in[i][0])); |
|
477 |
+ } |
|
478 |
+} |
|
479 |
+ |
|
480 |
+static void hybrid_synthesis(float out[2][38][64], float in[91][32][2], int is34, int len) |
|
481 |
+{ |
|
482 |
+ int i, n; |
|
483 |
+ if(is34) { |
|
484 |
+ for (n = 0; n < len; n++) { |
|
485 |
+ memset(out[0][n], 0, 5*sizeof(out[0][n][0])); |
|
486 |
+ memset(out[1][n], 0, 5*sizeof(out[1][n][0])); |
|
487 |
+ for(i = 0; i < 12; i++) { |
|
488 |
+ out[0][n][0] += in[ i][n][0]; |
|
489 |
+ out[1][n][0] += in[ i][n][1]; |
|
490 |
+ } |
|
491 |
+ for(i = 0; i < 8; i++) { |
|
492 |
+ out[0][n][1] += in[12+i][n][0]; |
|
493 |
+ out[1][n][1] += in[12+i][n][1]; |
|
494 |
+ } |
|
495 |
+ for(i = 0; i < 4; i++) { |
|
496 |
+ out[0][n][2] += in[20+i][n][0]; |
|
497 |
+ out[1][n][2] += in[20+i][n][1]; |
|
498 |
+ out[0][n][3] += in[24+i][n][0]; |
|
499 |
+ out[1][n][3] += in[24+i][n][1]; |
|
500 |
+ out[0][n][4] += in[28+i][n][0]; |
|
501 |
+ out[1][n][4] += in[28+i][n][1]; |
|
502 |
+ } |
|
503 |
+ } |
|
504 |
+ for (i = 0; i < 59; i++) { |
|
505 |
+ for (n = 0; n < len; n++) { |
|
506 |
+ out[0][n][i+5] = in[i+32][n][0]; |
|
507 |
+ out[1][n][i+5] = in[i+32][n][1]; |
|
508 |
+ } |
|
509 |
+ } |
|
510 |
+ } else { |
|
511 |
+ for (n = 0; n < len; n++) { |
|
512 |
+ out[0][n][0] = in[0][n][0] + in[1][n][0] + in[2][n][0] + |
|
513 |
+ in[3][n][0] + in[4][n][0] + in[5][n][0]; |
|
514 |
+ out[1][n][0] = in[0][n][1] + in[1][n][1] + in[2][n][1] + |
|
515 |
+ in[3][n][1] + in[4][n][1] + in[5][n][1]; |
|
516 |
+ out[0][n][1] = in[6][n][0] + in[7][n][0]; |
|
517 |
+ out[1][n][1] = in[6][n][1] + in[7][n][1]; |
|
518 |
+ out[0][n][2] = in[8][n][0] + in[9][n][0]; |
|
519 |
+ out[1][n][2] = in[8][n][1] + in[9][n][1]; |
|
520 |
+ } |
|
521 |
+ for (i = 0; i < 61; i++) { |
|
522 |
+ for (n = 0; n < len; n++) { |
|
523 |
+ out[0][n][i+3] = in[i+10][n][0]; |
|
524 |
+ out[1][n][i+3] = in[i+10][n][1]; |
|
525 |
+ } |
|
526 |
+ } |
|
527 |
+ } |
|
528 |
+} |
|
529 |
+ |
|
530 |
+/// All-pass filter decay slope |
|
531 |
+#define DECAY_SLOPE 0.05f |
|
532 |
+/// Number of frequency bands that can be addressed by the parameter index, b(k) |
|
533 |
+static const int NR_PAR_BANDS[] = { 20, 34 }; |
|
534 |
+/// Number of frequency bands that can be addressed by the sub subband index, k |
|
535 |
+static const int NR_BANDS[] = { 71, 91 }; |
|
536 |
+/// Start frequency band for the all-pass filter decay slope |
|
537 |
+static const int DECAY_CUTOFF[] = { 10, 32 }; |
|
538 |
+/// Number of all-pass filer bands |
|
539 |
+static const int NR_ALLPASS_BANDS[] = { 30, 50 }; |
|
540 |
+/// First stereo band using the short one sample delay |
|
541 |
+static const int SHORT_DELAY_BAND[] = { 42, 62 }; |
|
542 |
+ |
|
543 |
+/** Table 8.46 */ |
|
544 |
+static void map_idx_10_to_20(int8_t *par_mapped, const int8_t *par, int full) |
|
545 |
+{ |
|
546 |
+ int b; |
|
547 |
+ if (full) |
|
548 |
+ b = 9; |
|
549 |
+ else { |
|
550 |
+ b = 4; |
|
551 |
+ par_mapped[10] = 0; |
|
552 |
+ } |
|
553 |
+ for (; b >= 0; b--) { |
|
554 |
+ par_mapped[2*b+1] = par_mapped[2*b] = par[b]; |
|
555 |
+ } |
|
556 |
+} |
|
557 |
+ |
|
558 |
+static void map_idx_34_to_20(int8_t *par_mapped, const int8_t *par, int full) |
|
559 |
+{ |
|
560 |
+ par_mapped[ 0] = (2*par[ 0] + par[ 1]) / 3; |
|
561 |
+ par_mapped[ 1] = ( par[ 1] + 2*par[ 2]) / 3; |
|
562 |
+ par_mapped[ 2] = (2*par[ 3] + par[ 4]) / 3; |
|
563 |
+ par_mapped[ 3] = ( par[ 4] + 2*par[ 5]) / 3; |
|
564 |
+ par_mapped[ 4] = ( par[ 6] + par[ 7]) / 2; |
|
565 |
+ par_mapped[ 5] = ( par[ 8] + par[ 9]) / 2; |
|
566 |
+ par_mapped[ 6] = par[10]; |
|
567 |
+ par_mapped[ 7] = par[11]; |
|
568 |
+ par_mapped[ 8] = ( par[12] + par[13]) / 2; |
|
569 |
+ par_mapped[ 9] = ( par[14] + par[15]) / 2; |
|
570 |
+ par_mapped[10] = par[16]; |
|
571 |
+ if (full) { |
|
572 |
+ par_mapped[11] = par[17]; |
|
573 |
+ par_mapped[12] = par[18]; |
|
574 |
+ par_mapped[13] = par[19]; |
|
575 |
+ par_mapped[14] = ( par[20] + par[21]) / 2; |
|
576 |
+ par_mapped[15] = ( par[22] + par[23]) / 2; |
|
577 |
+ par_mapped[16] = ( par[24] + par[25]) / 2; |
|
578 |
+ par_mapped[17] = ( par[26] + par[27]) / 2; |
|
579 |
+ par_mapped[18] = ( par[28] + par[29] + par[30] + par[31]) / 4; |
|
580 |
+ par_mapped[19] = ( par[32] + par[33]) / 2; |
|
581 |
+ } |
|
582 |
+} |
|
583 |
+ |
|
584 |
+static void map_val_34_to_20(float par[PS_MAX_NR_IIDICC]) |
|
585 |
+{ |
|
586 |
+ par[ 0] = (2*par[ 0] + par[ 1]) * 0.33333333f; |
|
587 |
+ par[ 1] = ( par[ 1] + 2*par[ 2]) * 0.33333333f; |
|
588 |
+ par[ 2] = (2*par[ 3] + par[ 4]) * 0.33333333f; |
|
589 |
+ par[ 3] = ( par[ 4] + 2*par[ 5]) * 0.33333333f; |
|
590 |
+ par[ 4] = ( par[ 6] + par[ 7]) * 0.5f; |
|
591 |
+ par[ 5] = ( par[ 8] + par[ 9]) * 0.5f; |
|
592 |
+ par[ 6] = par[10]; |
|
593 |
+ par[ 7] = par[11]; |
|
594 |
+ par[ 8] = ( par[12] + par[13]) * 0.5f; |
|
595 |
+ par[ 9] = ( par[14] + par[15]) * 0.5f; |
|
596 |
+ par[10] = par[16]; |
|
597 |
+ par[11] = par[17]; |
|
598 |
+ par[12] = par[18]; |
|
599 |
+ par[13] = par[19]; |
|
600 |
+ par[14] = ( par[20] + par[21]) * 0.5f; |
|
601 |
+ par[15] = ( par[22] + par[23]) * 0.5f; |
|
602 |
+ par[16] = ( par[24] + par[25]) * 0.5f; |
|
603 |
+ par[17] = ( par[26] + par[27]) * 0.5f; |
|
604 |
+ par[18] = ( par[28] + par[29] + par[30] + par[31]) * 0.25f; |
|
605 |
+ par[19] = ( par[32] + par[33]) * 0.5f; |
|
606 |
+} |
|
607 |
+ |
|
608 |
+static void map_idx_10_to_34(int8_t *par_mapped, const int8_t *par, int full) |
|
609 |
+{ |
|
610 |
+ if (full) { |
|
611 |
+ par_mapped[33] = par[9]; |
|
612 |
+ par_mapped[32] = par[9]; |
|
613 |
+ par_mapped[31] = par[9]; |
|
614 |
+ par_mapped[30] = par[9]; |
|
615 |
+ par_mapped[29] = par[9]; |
|
616 |
+ par_mapped[28] = par[9]; |
|
617 |
+ par_mapped[27] = par[8]; |
|
618 |
+ par_mapped[26] = par[8]; |
|
619 |
+ par_mapped[25] = par[8]; |
|
620 |
+ par_mapped[24] = par[8]; |
|
621 |
+ par_mapped[23] = par[7]; |
|
622 |
+ par_mapped[22] = par[7]; |
|
623 |
+ par_mapped[21] = par[7]; |
|
624 |
+ par_mapped[20] = par[7]; |
|
625 |
+ par_mapped[19] = par[6]; |
|
626 |
+ par_mapped[18] = par[6]; |
|
627 |
+ par_mapped[17] = par[5]; |
|
628 |
+ par_mapped[16] = par[5]; |
|
629 |
+ } else { |
|
630 |
+ par_mapped[16] = 0; |
|
631 |
+ } |
|
632 |
+ par_mapped[15] = par[4]; |
|
633 |
+ par_mapped[14] = par[4]; |
|
634 |
+ par_mapped[13] = par[4]; |
|
635 |
+ par_mapped[12] = par[4]; |
|
636 |
+ par_mapped[11] = par[3]; |
|
637 |
+ par_mapped[10] = par[3]; |
|
638 |
+ par_mapped[ 9] = par[2]; |
|
639 |
+ par_mapped[ 8] = par[2]; |
|
640 |
+ par_mapped[ 7] = par[2]; |
|
641 |
+ par_mapped[ 6] = par[2]; |
|
642 |
+ par_mapped[ 5] = par[1]; |
|
643 |
+ par_mapped[ 4] = par[1]; |
|
644 |
+ par_mapped[ 3] = par[1]; |
|
645 |
+ par_mapped[ 2] = par[0]; |
|
646 |
+ par_mapped[ 1] = par[0]; |
|
647 |
+ par_mapped[ 0] = par[0]; |
|
648 |
+} |
|
649 |
+ |
|
650 |
+static void map_idx_20_to_34(int8_t *par_mapped, const int8_t *par, int full) |
|
651 |
+{ |
|
652 |
+ if (full) { |
|
653 |
+ par_mapped[33] = par[19]; |
|
654 |
+ par_mapped[32] = par[19]; |
|
655 |
+ par_mapped[31] = par[18]; |
|
656 |
+ par_mapped[30] = par[18]; |
|
657 |
+ par_mapped[29] = par[18]; |
|
658 |
+ par_mapped[28] = par[18]; |
|
659 |
+ par_mapped[27] = par[17]; |
|
660 |
+ par_mapped[26] = par[17]; |
|
661 |
+ par_mapped[25] = par[16]; |
|
662 |
+ par_mapped[24] = par[16]; |
|
663 |
+ par_mapped[23] = par[15]; |
|
664 |
+ par_mapped[22] = par[15]; |
|
665 |
+ par_mapped[21] = par[14]; |
|
666 |
+ par_mapped[20] = par[14]; |
|
667 |
+ par_mapped[19] = par[13]; |
|
668 |
+ par_mapped[18] = par[12]; |
|
669 |
+ par_mapped[17] = par[11]; |
|
670 |
+ } |
|
671 |
+ par_mapped[16] = par[10]; |
|
672 |
+ par_mapped[15] = par[ 9]; |
|
673 |
+ par_mapped[14] = par[ 9]; |
|
674 |
+ par_mapped[13] = par[ 8]; |
|
675 |
+ par_mapped[12] = par[ 8]; |
|
676 |
+ par_mapped[11] = par[ 7]; |
|
677 |
+ par_mapped[10] = par[ 6]; |
|
678 |
+ par_mapped[ 9] = par[ 5]; |
|
679 |
+ par_mapped[ 8] = par[ 5]; |
|
680 |
+ par_mapped[ 7] = par[ 4]; |
|
681 |
+ par_mapped[ 6] = par[ 4]; |
|
682 |
+ par_mapped[ 5] = par[ 3]; |
|
683 |
+ par_mapped[ 4] = (par[ 2] + par[ 3]) / 2; |
|
684 |
+ par_mapped[ 3] = par[ 2]; |
|
685 |
+ par_mapped[ 2] = par[ 1]; |
|
686 |
+ par_mapped[ 1] = (par[ 0] + par[ 1]) / 2; |
|
687 |
+ par_mapped[ 0] = par[ 0]; |
|
688 |
+} |
|
689 |
+ |
|
690 |
+static void map_val_20_to_34(float par[PS_MAX_NR_IIDICC]) |
|
691 |
+{ |
|
692 |
+ par[33] = par[19]; |
|
693 |
+ par[32] = par[19]; |
|
694 |
+ par[31] = par[18]; |
|
695 |
+ par[30] = par[18]; |
|
696 |
+ par[29] = par[18]; |
|
697 |
+ par[28] = par[18]; |
|
698 |
+ par[27] = par[17]; |
|
699 |
+ par[26] = par[17]; |
|
700 |
+ par[25] = par[16]; |
|
701 |
+ par[24] = par[16]; |
|
702 |
+ par[23] = par[15]; |
|
703 |
+ par[22] = par[15]; |
|
704 |
+ par[21] = par[14]; |
|
705 |
+ par[20] = par[14]; |
|
706 |
+ par[19] = par[13]; |
|
707 |
+ par[18] = par[12]; |
|
708 |
+ par[17] = par[11]; |
|
709 |
+ par[16] = par[10]; |
|
710 |
+ par[15] = par[ 9]; |
|
711 |
+ par[14] = par[ 9]; |
|
712 |
+ par[13] = par[ 8]; |
|
713 |
+ par[12] = par[ 8]; |
|
714 |
+ par[11] = par[ 7]; |
|
715 |
+ par[10] = par[ 6]; |
|
716 |
+ par[ 9] = par[ 5]; |
|
717 |
+ par[ 8] = par[ 5]; |
|
718 |
+ par[ 7] = par[ 4]; |
|
719 |
+ par[ 6] = par[ 4]; |
|
720 |
+ par[ 5] = par[ 3]; |
|
721 |
+ par[ 4] = (par[ 2] + par[ 3]) * 0.5f; |
|
722 |
+ par[ 3] = par[ 2]; |
|
723 |
+ par[ 2] = par[ 1]; |
|
724 |
+ par[ 1] = (par[ 0] + par[ 1]) * 0.5f; |
|
725 |
+ par[ 0] = par[ 0]; |
|
726 |
+} |
|
727 |
+ |
|
728 |
+static void decorrelation(PSContext *ps, float (*out)[32][2], const float (*s)[32][2], int is34) |
|
729 |
+{ |
|
730 |
+ float power[34][PS_QMF_TIME_SLOTS] = {{0}}; |
|
731 |
+ float transient_gain[34][PS_QMF_TIME_SLOTS]; |
|
732 |
+ float *peak_decay_nrg = ps->peak_decay_nrg; |
|
733 |
+ float *power_smooth = ps->power_smooth; |
|
734 |
+ float *peak_decay_diff_smooth = ps->peak_decay_diff_smooth; |
|
735 |
+ float (*delay)[PS_QMF_TIME_SLOTS + PS_MAX_DELAY][2] = ps->delay; |
|
736 |
+ float (*ap_delay)[PS_AP_LINKS][PS_QMF_TIME_SLOTS + PS_MAX_AP_DELAY][2] = ps->ap_delay; |
|
737 |
+ const int8_t *k_to_i = is34 ? k_to_i_34 : k_to_i_20; |
|
738 |
+ const float peak_decay_factor = 0.76592833836465f; |
|
739 |
+ const float transient_impact = 1.5f; |
|
740 |
+ const float a_smooth = 0.25f; //< Smoothing coefficient |
|
741 |
+ int i, k, m, n; |
|
742 |
+ int n0 = 0, nL = 32; |
|
743 |
+ static const int link_delay[] = { 3, 4, 5 }; |
|
744 |
+ static const float a[] = { 0.65143905753106f, |
|
745 |
+ 0.56471812200776f, |
|
746 |
+ 0.48954165955695f }; |
|
747 |
+ |
|
748 |
+ if (is34 != ps->is34bands_old) { |
|
749 |
+ memset(ps->peak_decay_nrg, 0, sizeof(ps->peak_decay_nrg)); |
|
750 |
+ memset(ps->power_smooth, 0, sizeof(ps->power_smooth)); |
|
751 |
+ memset(ps->peak_decay_diff_smooth, 0, sizeof(ps->peak_decay_diff_smooth)); |
|
752 |
+ memset(ps->delay, 0, sizeof(ps->delay)); |
|
753 |
+ memset(ps->ap_delay, 0, sizeof(ps->ap_delay)); |
|
754 |
+ } |
|
755 |
+ |
|
756 |
+ for (n = n0; n < nL; n++) { |
|
757 |
+ for (k = 0; k < NR_BANDS[is34]; k++) { |
|
758 |
+ int i = k_to_i[k]; |
|
759 |
+ power[i][n] += s[k][n][0] * s[k][n][0] + s[k][n][1] * s[k][n][1]; |
|
760 |
+ } |
|
761 |
+ } |
|
762 |
+ |
|
763 |
+ //Transient detection |
|
764 |
+ for (i = 0; i < NR_PAR_BANDS[is34]; i++) { |
|
765 |
+ for (n = n0; n < nL; n++) { |
|
766 |
+ float decayed_peak = peak_decay_factor * peak_decay_nrg[i]; |
|
767 |
+ float denom; |
|
768 |
+ peak_decay_nrg[i] = FFMAX(decayed_peak, power[i][n]); |
|
769 |
+ power_smooth[i] += a_smooth * (power[i][n] - power_smooth[i]); |
|
770 |
+ peak_decay_diff_smooth[i] += a_smooth * (peak_decay_nrg[i] - power[i][n] - peak_decay_diff_smooth[i]); |
|
771 |
+ denom = transient_impact * peak_decay_diff_smooth[i]; |
|
772 |
+ transient_gain[i][n] = (denom > power_smooth[i]) ? |
|
773 |
+ power_smooth[i] / denom : 1.0f; |
|
774 |
+ } |
|
775 |
+ } |
|
776 |
+ |
|
777 |
+ //Decorrelation and transient reduction |
|
778 |
+ // PS_AP_LINKS - 1 |
|
779 |
+ // ----- |
|
780 |
+ // | | Q_fract_allpass[k][m]*z^-link_delay[m] - a[m]*g_decay_slope[k] |
|
781 |
+ //H[k][z] = z^-2 * phi_fract[k] * | | ---------------------------------------------------------------- |
|
782 |
+ // | | 1 - a[m]*g_decay_slope[k]*Q_fract_allpass[k][m]*z^-link_delay[m] |
|
783 |
+ // m = 0 |
|
784 |
+ //d[k][z] (out) = transient_gain_mapped[k][z] * H[k][z] * s[k][z] |
|
785 |
+ for (k = 0; k < NR_ALLPASS_BANDS[is34]; k++) { |
|
786 |
+ int b = k_to_i[k]; |
|
787 |
+ float g_decay_slope = 1.f - DECAY_SLOPE * (k - DECAY_CUTOFF[is34]); |
|
788 |
+ float ag[PS_AP_LINKS]; |
|
789 |
+ g_decay_slope = av_clipf(g_decay_slope, 0.f, 1.f); |
|
790 |
+ memcpy(delay[k], delay[k]+nL, PS_MAX_DELAY*sizeof(delay[k][0])); |
|
791 |
+ memcpy(delay[k]+PS_MAX_DELAY, s[k], numQMFSlots*sizeof(delay[k][0])); |
|
792 |
+ for (m = 0; m < PS_AP_LINKS; m++) { |
|
793 |
+ memcpy(ap_delay[k][m], ap_delay[k][m]+numQMFSlots, 5*sizeof(ap_delay[k][m][0])); |
|
794 |
+ ag[m] = a[m] * g_decay_slope; |
|
795 |
+ } |
|
796 |
+ for (n = n0; n < nL; n++) { |
|
797 |
+ float in_re = delay[k][n+PS_MAX_DELAY-2][0] * phi_fract[is34][k][0] - |
|
798 |
+ delay[k][n+PS_MAX_DELAY-2][1] * phi_fract[is34][k][1]; |
|
799 |
+ float in_im = delay[k][n+PS_MAX_DELAY-2][0] * phi_fract[is34][k][1] + |
|
800 |
+ delay[k][n+PS_MAX_DELAY-2][1] * phi_fract[is34][k][0]; |
|
801 |
+ for (m = 0; m < PS_AP_LINKS; m++) { |
|
802 |
+ float a_re = ag[m] * in_re; |
|
803 |
+ float a_im = ag[m] * in_im; |
|
804 |
+ float link_delay_re = ap_delay[k][m][n+5-link_delay[m]][0]; |
|
805 |
+ float link_delay_im = ap_delay[k][m][n+5-link_delay[m]][1]; |
|
806 |
+ float fractional_delay_re = Q_fract_allpass[is34][k][m][0]; |
|
807 |
+ float fractional_delay_im = Q_fract_allpass[is34][k][m][1]; |
|
808 |
+ ap_delay[k][m][n+5][0] = in_re; |
|
809 |
+ ap_delay[k][m][n+5][1] = in_im; |
|
810 |
+ in_re = link_delay_re * fractional_delay_re - link_delay_im * fractional_delay_im - a_re; |
|
811 |
+ in_im = link_delay_re * fractional_delay_im + link_delay_im * fractional_delay_re - a_im; |
|
812 |
+ ap_delay[k][m][n+5][0] += ag[m] * in_re; |
|
813 |
+ ap_delay[k][m][n+5][1] += ag[m] * in_im; |
|
814 |
+ } |
|
815 |
+ out[k][n][0] = transient_gain[b][n] * in_re; |
|
816 |
+ out[k][n][1] = transient_gain[b][n] * in_im; |
|
817 |
+ } |
|
818 |
+ } |
|
819 |
+ for (; k < SHORT_DELAY_BAND[is34]; k++) { |
|
820 |
+ memcpy(delay[k], delay[k]+nL, PS_MAX_DELAY*sizeof(delay[k][0])); |
|
821 |
+ memcpy(delay[k]+PS_MAX_DELAY, s[k], numQMFSlots*sizeof(delay[k][0])); |
|
822 |
+ for (n = n0; n < nL; n++) { |
|
823 |
+ //H = delay 14 |
|
824 |
+ out[k][n][0] = transient_gain[k_to_i[k]][n] * delay[k][n+PS_MAX_DELAY-14][0]; |
|
825 |
+ out[k][n][1] = transient_gain[k_to_i[k]][n] * delay[k][n+PS_MAX_DELAY-14][1]; |
|
826 |
+ } |
|
827 |
+ } |
|
828 |
+ for (; k < NR_BANDS[is34]; k++) { |
|
829 |
+ memcpy(delay[k], delay[k]+nL, PS_MAX_DELAY*sizeof(delay[k][0])); |
|
830 |
+ memcpy(delay[k]+PS_MAX_DELAY, s[k], numQMFSlots*sizeof(delay[k][0])); |
|
831 |
+ for (n = n0; n < nL; n++) { |
|
832 |
+ //H = delay 1 |
|
833 |
+ out[k][n][0] = transient_gain[k_to_i[k]][n] * delay[k][n+PS_MAX_DELAY-1][0]; |
|
834 |
+ out[k][n][1] = transient_gain[k_to_i[k]][n] * delay[k][n+PS_MAX_DELAY-1][1]; |
|
835 |
+ } |
|
836 |
+ } |
|
837 |
+} |
|
838 |
+ |
|
839 |
+static void remap34(int8_t (**p_par_mapped)[PS_MAX_NR_IIDICC], |
|
840 |
+ int8_t (*par)[PS_MAX_NR_IIDICC], |
|
841 |
+ int num_par, int num_env, int full) |
|
842 |
+{ |
|
843 |
+ int8_t (*par_mapped)[PS_MAX_NR_IIDICC] = *p_par_mapped; |
|
844 |
+ int e; |
|
845 |
+ if (num_par == 20 || num_par == 11) { |
|
846 |
+ for (e = 0; e < num_env; e++) { |
|
847 |
+ map_idx_20_to_34(par_mapped[e], par[e], full); |
|
848 |
+ } |
|
849 |
+ } else if (num_par == 10 || num_par == 5) { |
|
850 |
+ for (e = 0; e < num_env; e++) { |
|
851 |
+ map_idx_10_to_34(par_mapped[e], par[e], full); |
|
852 |
+ } |
|
853 |
+ } else { |
|
854 |
+ *p_par_mapped = par; |
|
855 |
+ } |
|
856 |
+} |
|
857 |
+ |
|
858 |
+static void remap20(int8_t (**p_par_mapped)[PS_MAX_NR_IIDICC], |
|
859 |
+ int8_t (*par)[PS_MAX_NR_IIDICC], |
|
860 |
+ int num_par, int num_env, int full) |
|
861 |
+{ |
|
862 |
+ int8_t (*par_mapped)[PS_MAX_NR_IIDICC] = *p_par_mapped; |
|
863 |
+ int e; |
|
864 |
+ if (num_par == 34 || num_par == 17) { |
|
865 |
+ for (e = 0; e < num_env; e++) { |
|
866 |
+ map_idx_34_to_20(par_mapped[e], par[e], full); |
|
867 |
+ } |
|
868 |
+ } else if (num_par == 10 || num_par == 5) { |
|
869 |
+ for (e = 0; e < num_env; e++) { |
|
870 |
+ map_idx_10_to_20(par_mapped[e], par[e], full); |
|
871 |
+ } |
|
872 |
+ } else { |
|
873 |
+ *p_par_mapped = par; |
|
874 |
+ } |
|
875 |
+} |
|
876 |
+ |
|
877 |
+static void stereo_processing(PSContext *ps, float (*l)[32][2], float (*r)[32][2], int is34) |
|
878 |
+{ |
|
879 |
+ int e, b, k, n; |
|
880 |
+ |
|
881 |
+ float (*H11)[PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC] = ps->H11; |
|
882 |
+ float (*H12)[PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC] = ps->H12; |
|
883 |
+ float (*H21)[PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC] = ps->H21; |
|
884 |
+ float (*H22)[PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC] = ps->H22; |
|
885 |
+ int8_t *opd_hist = ps->opd_hist; |
|
886 |
+ int8_t *ipd_hist = ps->ipd_hist; |
|
887 |
+ int8_t iid_mapped_buf[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; |
|
888 |
+ int8_t icc_mapped_buf[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; |
|
889 |
+ int8_t ipd_mapped_buf[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; |
|
890 |
+ int8_t opd_mapped_buf[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; |
|
891 |
+ int8_t (*iid_mapped)[PS_MAX_NR_IIDICC] = iid_mapped_buf; |
|
892 |
+ int8_t (*icc_mapped)[PS_MAX_NR_IIDICC] = icc_mapped_buf; |
|
893 |
+ int8_t (*ipd_mapped)[PS_MAX_NR_IIDICC] = ipd_mapped_buf; |
|
894 |
+ int8_t (*opd_mapped)[PS_MAX_NR_IIDICC] = opd_mapped_buf; |
|
895 |
+ const int8_t *k_to_i = is34 ? k_to_i_34 : k_to_i_20; |
|
896 |
+ const float (*H_LUT)[8][4] = (PS_BASELINE || ps->icc_mode < 3) ? HA : HB; |
|
897 |
+ |
|
898 |
+ //Remapping |
|
899 |
+ for (b = 0; b < PS_MAX_NR_IIDICC; b++) { |
|
900 |
+ H11[0][0][b] = H11[0][ps->num_env_old][b]; |
|
901 |
+ H12[0][0][b] = H12[0][ps->num_env_old][b]; |
|
902 |
+ H21[0][0][b] = H21[0][ps->num_env_old][b]; |
|
903 |
+ H22[0][0][b] = H22[0][ps->num_env_old][b]; |
|
904 |
+ H11[1][0][b] = H11[1][ps->num_env_old][b]; |
|
905 |
+ H12[1][0][b] = H12[1][ps->num_env_old][b]; |
|
906 |
+ H21[1][0][b] = H21[1][ps->num_env_old][b]; |
|
907 |
+ H22[1][0][b] = H22[1][ps->num_env_old][b]; |
|
908 |
+ } |
|
909 |
+ if (is34) { |
|
910 |
+ remap34(&iid_mapped, ps->iid_par, ps->nr_iid_par, ps->num_env, 1); |
|
911 |
+ remap34(&icc_mapped, ps->icc_par, ps->nr_icc_par, ps->num_env, 1); |
|
912 |
+ if (ps->enable_ipdopd) { |
|
913 |
+ remap34(&ipd_mapped, ps->ipd_par, ps->nr_ipdopd_par, ps->num_env, 0); |
|
914 |
+ remap34(&opd_mapped, ps->opd_par, ps->nr_ipdopd_par, ps->num_env, 0); |
|
915 |
+ } |
|
916 |
+ if (!ps->is34bands_old) { |
|
917 |
+ map_val_20_to_34(H11[0][0]); |
|
918 |
+ map_val_20_to_34(H11[1][0]); |
|
919 |
+ map_val_20_to_34(H12[0][0]); |
|
920 |
+ map_val_20_to_34(H12[1][0]); |
|
921 |
+ map_val_20_to_34(H21[0][0]); |
|
922 |
+ map_val_20_to_34(H21[1][0]); |
|
923 |
+ map_val_20_to_34(H22[0][0]); |
|
924 |
+ map_val_20_to_34(H22[1][0]); |
|
925 |
+ ipdopd_reset(ipd_hist, opd_hist); |
|
926 |
+ } |
|
927 |
+ } else { |
|
928 |
+ remap20(&iid_mapped, ps->iid_par, ps->nr_iid_par, ps->num_env, 1); |
|
929 |
+ remap20(&icc_mapped, ps->icc_par, ps->nr_icc_par, ps->num_env, 1); |
|
930 |
+ if (ps->enable_ipdopd) { |
|
931 |
+ remap20(&ipd_mapped, ps->ipd_par, ps->nr_ipdopd_par, ps->num_env, 0); |
|
932 |
+ remap20(&opd_mapped, ps->opd_par, ps->nr_ipdopd_par, ps->num_env, 0); |
|
933 |
+ } |
|
934 |
+ if (ps->is34bands_old) { |
|
935 |
+ map_val_34_to_20(H11[0][0]); |
|
936 |
+ map_val_34_to_20(H11[1][0]); |
|
937 |
+ map_val_34_to_20(H12[0][0]); |
|
938 |
+ map_val_34_to_20(H12[1][0]); |
|
939 |
+ map_val_34_to_20(H21[0][0]); |
|
940 |
+ map_val_34_to_20(H21[1][0]); |
|
941 |
+ map_val_34_to_20(H22[0][0]); |
|
942 |
+ map_val_34_to_20(H22[1][0]); |
|
943 |
+ ipdopd_reset(ipd_hist, opd_hist); |
|
944 |
+ } |
|
945 |
+ } |
|
946 |
+ |
|
947 |
+ //Mixing |
|
948 |
+ for (e = 0; e < ps->num_env; e++) { |
|
949 |
+ for (b = 0; b < NR_PAR_BANDS[is34]; b++) { |
|
950 |
+ float h11, h12, h21, h22; |
|
951 |
+ h11 = H_LUT[iid_mapped[e][b] + 7 + 23 * ps->iid_quant][icc_mapped[e][b]][0]; |
|
952 |
+ h12 = H_LUT[iid_mapped[e][b] + 7 + 23 * ps->iid_quant][icc_mapped[e][b]][1]; |
|
953 |
+ h21 = H_LUT[iid_mapped[e][b] + 7 + 23 * ps->iid_quant][icc_mapped[e][b]][2]; |
|
954 |
+ h22 = H_LUT[iid_mapped[e][b] + 7 + 23 * ps->iid_quant][icc_mapped[e][b]][3]; |
|
955 |
+ if (!PS_BASELINE && ps->enable_ipdopd && b < ps->nr_ipdopd_par) { |
|
956 |
+ //The spec say says to only run this smoother when enable_ipdopd |
|
957 |
+ //is set but the reference decoder appears to run it constantly |
|
958 |
+ float h11i, h12i, h21i, h22i; |
|
959 |
+ float ipd_adj_re, ipd_adj_im; |
|
960 |
+ int opd_idx = opd_hist[b] * 8 + opd_mapped[e][b]; |
|
961 |
+ int ipd_idx = ipd_hist[b] * 8 + ipd_mapped[e][b]; |
|
962 |
+ float opd_re = pd_re_smooth[opd_idx]; |
|
963 |
+ float opd_im = pd_im_smooth[opd_idx]; |
|
964 |
+ float ipd_re = pd_re_smooth[ipd_idx]; |
|
965 |
+ float ipd_im = pd_im_smooth[ipd_idx]; |
|
966 |
+ opd_hist[b] = opd_idx & 0x3F; |
|
967 |
+ ipd_hist[b] = ipd_idx & 0x3F; |
|
968 |
+ |
|
969 |
+ ipd_adj_re = opd_re*ipd_re + opd_im*ipd_im; |
|
970 |
+ ipd_adj_im = opd_im*ipd_re - opd_re*ipd_im; |
|
971 |
+ h11i = h11 * opd_im; |
|
972 |
+ h11 = h11 * opd_re; |
|
973 |
+ h12i = h12 * ipd_adj_im; |
|
974 |
+ h12 = h12 * ipd_adj_re; |
|
975 |
+ h21i = h21 * opd_im; |
|
976 |
+ h21 = h21 * opd_re; |
|
977 |
+ h22i = h22 * ipd_adj_im; |
|
978 |
+ h22 = h22 * ipd_adj_re; |
|
979 |
+ H11[1][e+1][b] = h11i; |
|
980 |
+ H12[1][e+1][b] = h12i; |
|
981 |
+ H21[1][e+1][b] = h21i; |
|
982 |
+ H22[1][e+1][b] = h22i; |
|
983 |
+ } |
|
984 |
+ H11[0][e+1][b] = h11; |
|
985 |
+ H12[0][e+1][b] = h12; |
|
986 |
+ H21[0][e+1][b] = h21; |
|
987 |
+ H22[0][e+1][b] = h22; |
|
988 |
+ } |
|
989 |
+ for (k = 0; k < NR_BANDS[is34]; k++) { |
|
990 |
+ float h11r, h12r, h21r, h22r; |
|
991 |
+ float h11i, h12i, h21i, h22i; |
|
992 |
+ float h11r_step, h12r_step, h21r_step, h22r_step; |
|
993 |
+ float h11i_step, h12i_step, h21i_step, h22i_step; |
|
994 |
+ int start = ps->border_position[e]; |
|
995 |
+ int stop = ps->border_position[e+1]; |
|
996 |
+ float width = 1.f / (stop - start); |
|
997 |
+ b = k_to_i[k]; |
|
998 |
+ h11r = H11[0][e][b]; |
|
999 |
+ h12r = H12[0][e][b]; |
|
1000 |
+ h21r = H21[0][e][b]; |
|
1001 |
+ h22r = H22[0][e][b]; |
|
1002 |
+ if (!PS_BASELINE && ps->enable_ipdopd) { |
|
1003 |
+ //Is this necessary? ps_04_new seems unchanged |
|
1004 |
+ if ((is34 && k <= 13 && k >= 9) || (!is34 && k <= 1)) { |
|
1005 |
+ h11i = -H11[1][e][b]; |
|
1006 |
+ h12i = -H12[1][e][b]; |
|
1007 |
+ h21i = -H21[1][e][b]; |
|
1008 |
+ h22i = -H22[1][e][b]; |
|
1009 |
+ } else { |
|
1010 |
+ h11i = H11[1][e][b]; |
|
1011 |
+ h12i = H12[1][e][b]; |
|
1012 |
+ h21i = H21[1][e][b]; |
|
1013 |
+ h22i = H22[1][e][b]; |
|
1014 |
+ } |
|
1015 |
+ } |
|
1016 |
+ //Interpolation |
|
1017 |
+ h11r_step = (H11[0][e+1][b] - h11r) * width; |
|
1018 |
+ h12r_step = (H12[0][e+1][b] - h12r) * width; |
|
1019 |
+ h21r_step = (H21[0][e+1][b] - h21r) * width; |
|
1020 |
+ h22r_step = (H22[0][e+1][b] - h22r) * width; |
|
1021 |
+ if (!PS_BASELINE && ps->enable_ipdopd) { |
|
1022 |
+ h11i_step = (H11[1][e+1][b] - h11i) * width; |
|
1023 |
+ h12i_step = (H12[1][e+1][b] - h12i) * width; |
|
1024 |
+ h21i_step = (H21[1][e+1][b] - h21i) * width; |
|
1025 |
+ h22i_step = (H22[1][e+1][b] - h22i) * width; |
|
1026 |
+ } |
|
1027 |
+ for (n = start + 1; n <= stop; n++) { |
|
1028 |
+ //l is s, r is d |
|
1029 |
+ float l_re = l[k][n][0]; |
|
1030 |
+ float l_im = l[k][n][1]; |
|
1031 |
+ float r_re = r[k][n][0]; |
|
1032 |
+ float r_im = r[k][n][1]; |
|
1033 |
+ h11r += h11r_step; |
|
1034 |
+ h12r += h12r_step; |
|
1035 |
+ h21r += h21r_step; |
|
1036 |
+ h22r += h22r_step; |
|
1037 |
+ if (!PS_BASELINE && ps->enable_ipdopd) { |
|
1038 |
+ h11i += h11i_step; |
|
1039 |
+ h12i += h12i_step; |
|
1040 |
+ h21i += h21i_step; |
|
1041 |
+ h22i += h22i_step; |
|
1042 |
+ |
|
1043 |
+ l[k][n][0] = h11r*l_re + h21r*r_re - h11i*l_im - h21i*r_im; |
|
1044 |
+ l[k][n][1] = h11r*l_im + h21r*r_im + h11i*l_re + h21i*r_re; |
|
1045 |
+ r[k][n][0] = h12r*l_re + h22r*r_re - h12i*l_im - h22i*r_im; |
|
1046 |
+ r[k][n][1] = h12r*l_im + h22r*r_im + h12i*l_re + h22i*r_re; |
|
1047 |
+ } else { |
|
1048 |
+ l[k][n][0] = h11r*l_re + h21r*r_re; |
|
1049 |
+ l[k][n][1] = h11r*l_im + h21r*r_im; |
|
1050 |
+ r[k][n][0] = h12r*l_re + h22r*r_re; |
|
1051 |
+ r[k][n][1] = h12r*l_im + h22r*r_im; |
|
1052 |
+ } |
|
1053 |
+ } |
|
1054 |
+ } |
|
1055 |
+ } |
|
1056 |
+} |
|
1057 |
+ |
|
1058 |
+int ff_ps_apply(AVCodecContext *avctx, PSContext *ps, float L[2][38][64], float R[2][38][64], int top) |
|
1059 |
+{ |
|
1060 |
+ float Lbuf[91][32][2]; |
|
1061 |
+ float Rbuf[91][32][2]; |
|
1062 |
+ const int len = 32; |
|
1063 |
+ int is34 = ps->is34bands; |
|
1064 |
+ |
|
1065 |
+ top += NR_BANDS[is34] - 64; |
|
1066 |
+ memset(ps->delay+top, 0, (NR_BANDS[is34] - top)*sizeof(ps->delay[0])); |
|
1067 |
+ if (top < NR_ALLPASS_BANDS[is34]) |
|
1068 |
+ memset(ps->ap_delay + top, 0, (NR_ALLPASS_BANDS[is34] - top)*sizeof(ps->ap_delay[0])); |
|
1069 |
+ |
|
1070 |
+ hybrid_analysis(Lbuf, ps->in_buf, L, is34, len); |
|
1071 |
+ decorrelation(ps, Rbuf, Lbuf, is34); |
|
1072 |
+ stereo_processing(ps, Lbuf, Rbuf, is34); |
|
1073 |
+ hybrid_synthesis(L, Lbuf, is34, len); |
|
1074 |
+ hybrid_synthesis(R, Rbuf, is34, len); |
|
1075 |
+ |
|
1076 |
+ return 0; |
|
1077 |
+} |
|
1078 |
+ |
|
1079 |
+#define PS_INIT_VLC_STATIC(num, size) \ |
|
1080 |
+ INIT_VLC_STATIC(&vlc_ps[num], 9, ps_tmp[num].table_size / ps_tmp[num].elem_size, \ |
|
1081 |
+ ps_tmp[num].ps_bits, 1, 1, \ |
|
1082 |
+ ps_tmp[num].ps_codes, ps_tmp[num].elem_size, ps_tmp[num].elem_size, \ |
|
1083 |
+ size); |
|
1084 |
+ |
|
1085 |
+#define PS_VLC_ROW(name) \ |
|
1086 |
+ { name ## _codes, name ## _bits, sizeof(name ## _codes), sizeof(name ## _codes[0]) } |
|
1087 |
+ |
|
1088 |
+av_cold void ff_ps_init(void) { |
|
1089 |
+ // Syntax initialization |
|
1090 |
+ static const struct { |
|
1091 |
+ const void *ps_codes, *ps_bits; |
|
1092 |
+ const unsigned int table_size, elem_size; |
|
1093 |
+ } ps_tmp[] = { |
|
1094 |
+ PS_VLC_ROW(huff_iid_df1), |
|
1095 |
+ PS_VLC_ROW(huff_iid_dt1), |
|
1096 |
+ PS_VLC_ROW(huff_iid_df0), |
|
1097 |
+ PS_VLC_ROW(huff_iid_dt0), |
|
1098 |
+ PS_VLC_ROW(huff_icc_df), |
|
1099 |
+ PS_VLC_ROW(huff_icc_dt), |
|
1100 |
+ PS_VLC_ROW(huff_ipd_df), |
|
1101 |
+ PS_VLC_ROW(huff_ipd_dt), |
|
1102 |
+ PS_VLC_ROW(huff_opd_df), |
|
1103 |
+ PS_VLC_ROW(huff_opd_dt), |
|
1104 |
+ }; |
|
1105 |
+ |
|
1106 |
+ PS_INIT_VLC_STATIC(0, 1544); |
|
1107 |
+ PS_INIT_VLC_STATIC(1, 832); |
|
1108 |
+ PS_INIT_VLC_STATIC(2, 1024); |
|
1109 |
+ PS_INIT_VLC_STATIC(3, 1036); |
|
1110 |
+ PS_INIT_VLC_STATIC(4, 544); |
|
1111 |
+ PS_INIT_VLC_STATIC(5, 544); |
|
1112 |
+ PS_INIT_VLC_STATIC(6, 512); |
|
1113 |
+ PS_INIT_VLC_STATIC(7, 512); |
|
1114 |
+ PS_INIT_VLC_STATIC(8, 512); |
|
1115 |
+ PS_INIT_VLC_STATIC(9, 512); |
|
1116 |
+ |
|
1117 |
+ ps_tableinit(); |
|
1118 |
+} |
|
1119 |
+ |
|
1120 |
+av_cold void ff_ps_ctx_init(PSContext *ps) |
|
1121 |
+{ |
|
1122 |
+ ipdopd_reset(ps->ipd_hist, ps->opd_hist); |
|
1123 |
+} |
0 | 1124 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,80 @@ |
0 |
+/* |
|
1 |
+ * MPEG-4 Parametric Stereo definitions and declarations |
|
2 |
+ * Copyright (c) 2010 Alex Converse <alex.converse@gmail.com> |
|
3 |
+ * |
|
4 |
+ * This file is part of FFmpeg. |
|
5 |
+ * |
|
6 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
7 |
+ * modify it under the terms of the GNU Lesser General Public |
|
8 |
+ * License as published by the Free Software Foundation; either |
|
9 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
10 |
+ * |
|
11 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
12 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 |
+ * Lesser General Public License for more details. |
|
15 |
+ * |
|
16 |
+ * You should have received a copy of the GNU Lesser General Public |
|
17 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
18 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
19 |
+ */ |
|
20 |
+ |
|
21 |
+#ifndef AVCODEC_PS_H |
|
22 |
+#define AVCODEC_PS_H |
|
23 |
+ |
|
24 |
+#include <stdint.h> |
|
25 |
+ |
|
26 |
+#define PS_MAX_NUM_ENV 5 |
|
27 |
+#define PS_MAX_NR_IIDICC 34 |
|
28 |
+#define PS_MAX_NR_IPDOPD 17 |
|
29 |
+#define PS_MAX_SSB 91 |
|
30 |
+#define PS_MAX_AP_BANDS 50 |
|
31 |
+#define PS_QMF_TIME_SLOTS 32 |
|
32 |
+#define PS_MAX_DELAY 14 |
|
33 |
+#define PS_AP_LINKS 3 |
|
34 |
+#define PS_MAX_AP_DELAY 5 |
|
35 |
+ |
|
36 |
+typedef struct { |
|
37 |
+ int start; |
|
38 |
+ int enable_iid; |
|
39 |
+ int iid_mode; |
|
40 |
+ int iid_quant; |
|
41 |
+ int nr_iid_par; |
|
42 |
+ int nr_ipdopd_par; |
|
43 |
+ int enable_icc; |
|
44 |
+ int icc_mode; |
|
45 |
+ int nr_icc_par; |
|
46 |
+ int enable_ext; |
|
47 |
+ int frame_class; |
|
48 |
+ int num_env_old; |
|
49 |
+ int num_env; |
|
50 |
+ int enable_ipdopd; |
|
51 |
+ int border_position[PS_MAX_NUM_ENV+1]; |
|
52 |
+ int8_t iid_par[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; //<Inter-channel Intensity Difference Parameters |
|
53 |
+ int8_t icc_par[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; //<Inter-Channel Coherence Parameters |
|
54 |
+ /* ipd/opd is iid/icc sized so that the same functions can handle both */ |
|
55 |
+ int8_t ipd_par[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; //<Inter-channel Phase Difference Parameters |
|
56 |
+ int8_t opd_par[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; //<Overall Phase Difference Parameters |
|
57 |
+ int is34bands; |
|
58 |
+ int is34bands_old; |
|
59 |
+ |
|
60 |
+ float in_buf[5][44][2]; |
|
61 |
+ float delay[PS_MAX_SSB][PS_QMF_TIME_SLOTS + PS_MAX_DELAY][2]; |
|
62 |
+ float ap_delay[PS_MAX_AP_BANDS][PS_AP_LINKS][PS_QMF_TIME_SLOTS + PS_MAX_AP_DELAY][2]; |
|
63 |
+ float peak_decay_nrg[34]; |
|
64 |
+ float power_smooth[34]; |
|
65 |
+ float peak_decay_diff_smooth[34]; |
|
66 |
+ float H11[2][PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC]; |
|
67 |
+ float H12[2][PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC]; |
|
68 |
+ float H21[2][PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC]; |
|
69 |
+ float H22[2][PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC]; |
|
70 |
+ int8_t opd_hist[PS_MAX_NR_IIDICC]; |
|
71 |
+ int8_t ipd_hist[PS_MAX_NR_IIDICC]; |
|
72 |
+} PSContext; |
|
73 |
+ |
|
74 |
+void ff_ps_init(void); |
|
75 |
+void ff_ps_ctx_init(PSContext *ps); |
|
76 |
+int ff_ps_read_data(AVCodecContext *avctx, GetBitContext *gb, PSContext *ps, int bits_left); |
|
77 |
+int ff_ps_apply(AVCodecContext *avctx, PSContext *ps, float L[2][38][64], float R[2][38][64], int top); |
|
78 |
+ |
|
79 |
+#endif /* AVCODEC_PS_H */ |
0 | 80 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,93 @@ |
0 |
+/* |
|
1 |
+ * Generate a header file for hardcoded Parametric Stereo tables |
|
2 |
+ * |
|
3 |
+ * Copyright (c) 2010 Alex Converse <alex.converse@gmail.com> |
|
4 |
+ * |
|
5 |
+ * This file is part of FFmpeg. |
|
6 |
+ * |
|
7 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
8 |
+ * modify it under the terms of the GNU Lesser General Public |
|
9 |
+ * License as published by the Free Software Foundation; either |
|
10 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
11 |
+ * |
|
12 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
13 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
15 |
+ * Lesser General Public License for more details. |
|
16 |
+ * |
|
17 |
+ * You should have received a copy of the GNU Lesser General Public |
|
18 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
19 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
20 |
+ */ |
|
21 |
+ |
|
22 |
+#include <stdlib.h> |
|
23 |
+#define CONFIG_HARDCODED_TABLES 0 |
|
24 |
+#include "ps_tablegen.h" |
|
25 |
+#include "tableprint.h" |
|
26 |
+ |
|
27 |
+void write_float_3d_array (const void *p, int b, int c, int d) |
|
28 |
+{ |
|
29 |
+ int i; |
|
30 |
+ const float *f = p; |
|
31 |
+ for (i = 0; i < b; i++) { |
|
32 |
+ printf("{\n"); |
|
33 |
+ write_float_2d_array(f, c, d); |
|
34 |
+ printf("},\n"); |
|
35 |
+ f += c * d; |
|
36 |
+ } |
|
37 |
+} |
|
38 |
+ |
|
39 |
+void write_float_4d_array (const void *p, int a, int b, int c, int d) |
|
40 |
+{ |
|
41 |
+ int i; |
|
42 |
+ const float *f = p; |
|
43 |
+ for (i = 0; i < a; i++) { |
|
44 |
+ printf("{\n"); |
|
45 |
+ write_float_3d_array(f, b, c, d); |
|
46 |
+ printf("},\n"); |
|
47 |
+ f += b * c * d; |
|
48 |
+ } |
|
49 |
+} |
|
50 |
+ |
|
51 |
+int main(void) |
|
52 |
+{ |
|
53 |
+ ps_tableinit(); |
|
54 |
+ |
|
55 |
+ write_fileheader(); |
|
56 |
+ |
|
57 |
+ printf("static const float pd_re_smooth[8*8*8] = {\n"); |
|
58 |
+ write_float_array(pd_re_smooth, 8*8*8); |
|
59 |
+ printf("};\n"); |
|
60 |
+ printf("static const float pd_im_smooth[8*8*8] = {\n"); |
|
61 |
+ write_float_array(pd_im_smooth, 8*8*8); |
|
62 |
+ printf("};\n"); |
|
63 |
+ |
|
64 |
+ printf("static const float HA[46][8][4] = {\n"); |
|
65 |
+ write_float_3d_array(HA, 46, 8, 4); |
|
66 |
+ printf("};\n"); |
|
67 |
+ printf("static const float HB[46][8][4] = {\n"); |
|
68 |
+ write_float_3d_array(HB, 46, 8, 4); |
|
69 |
+ printf("};\n"); |
|
70 |
+ |
|
71 |
+ printf("static const float f20_0_8[8][7][2] = {\n"); |
|
72 |
+ write_float_3d_array(f20_0_8, 8, 7, 2); |
|
73 |
+ printf("};\n"); |
|
74 |
+ printf("static const float f34_0_12[12][7][2] = {\n"); |
|
75 |
+ write_float_3d_array(f34_0_12, 12, 7, 2); |
|
76 |
+ printf("};\n"); |
|
77 |
+ printf("static const float f34_1_8[8][7][2] = {\n"); |
|
78 |
+ write_float_3d_array(f34_1_8, 8, 7, 2); |
|
79 |
+ printf("};\n"); |
|
80 |
+ printf("static const float f34_2_4[4][7][2] = {\n"); |
|
81 |
+ write_float_3d_array(f34_2_4, 4, 7, 2); |
|
82 |
+ printf("};\n"); |
|
83 |
+ |
|
84 |
+ printf("static const float Q_fract_allpass[2][50][3][2] = {\n"); |
|
85 |
+ write_float_4d_array(Q_fract_allpass, 2, 50, 3, 2); |
|
86 |
+ printf("};\n"); |
|
87 |
+ printf("static const float phi_fract[2][50][2] = {\n"); |
|
88 |
+ write_float_3d_array(phi_fract, 2, 50, 2); |
|
89 |
+ printf("};\n"); |
|
90 |
+ |
|
91 |
+ return 0; |
|
92 |
+} |
0 | 93 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,221 @@ |
0 |
+/* |
|
1 |
+ * Header file for hardcoded Parametric Stereo tables |
|
2 |
+ * |
|
3 |
+ * Copyright (c) 2010 Alex Converse <alex.converse@gmail.com> |
|
4 |
+ * |
|
5 |
+ * This file is part of FFmpeg. |
|
6 |
+ * |
|
7 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
8 |
+ * modify it under the terms of the GNU Lesser General Public |
|
9 |
+ * License as published by the Free Software Foundation; either |
|
10 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
11 |
+ * |
|
12 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
13 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
15 |
+ * Lesser General Public License for more details. |
|
16 |
+ * |
|
17 |
+ * You should have received a copy of the GNU Lesser General Public |
|
18 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
19 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
20 |
+ */ |
|
21 |
+ |
|
22 |
+#ifndef PS_TABLEGEN_H |
|
23 |
+#define PS_TABLEGEN_H |
|
24 |
+ |
|
25 |
+#include <stdint.h> |
|
26 |
+#include <math.h> |
|
27 |
+ |
|
28 |
+#if CONFIG_HARDCODED_TABLES |
|
29 |
+#define ps_tableinit() |
|
30 |
+#include "libavcodec/ps_tables.h" |
|
31 |
+#else |
|
32 |
+#include "../libavutil/common.h" |
|
33 |
+#ifndef M_SQRT1_2 |
|
34 |
+#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ |
|
35 |
+#endif |
|
36 |
+#ifndef M_PI |
|
37 |
+#define M_PI 3.14159265358979323846 /* pi */ |
|
38 |
+#endif |
|
39 |
+#ifndef M_SQRT2 |
|
40 |
+#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ |
|
41 |
+#endif |
|
42 |
+#define NR_ALLPASS_BANDS20 30 |
|
43 |
+#define NR_ALLPASS_BANDS34 50 |
|
44 |
+#define PS_AP_LINKS 3 |
|
45 |
+static float pd_re_smooth[8*8*8]; |
|
46 |
+static float pd_im_smooth[8*8*8]; |
|
47 |
+static float HA[46][8][4]; |
|
48 |
+static float HB[46][8][4]; |
|
49 |
+static float f20_0_8 [ 8][7][2]; |
|
50 |
+static float f34_0_12[12][7][2]; |
|
51 |
+static float f34_1_8 [ 8][7][2]; |
|
52 |
+static float f34_2_4 [ 4][7][2]; |
|
53 |
+static float Q_fract_allpass[2][50][3][2]; |
|
54 |
+static float phi_fract[2][50][2]; |
|
55 |
+ |
|
56 |
+static const float g0_Q8[] = { |
|
57 |
+ 0.00746082949812f, 0.02270420949825f, 0.04546865930473f, 0.07266113929591f, |
|
58 |
+ 0.09885108575264f, 0.11793710567217f, 0.125f |
|
59 |
+}; |
|
60 |
+ |
|
61 |
+static const float g0_Q12[] = { |
|
62 |
+ 0.04081179924692f, 0.03812810994926f, 0.05144908135699f, 0.06399831151592f, |
|
63 |
+ 0.07428313801106f, 0.08100347892914f, 0.08333333333333f |
|
64 |
+}; |
|
65 |
+ |
|
66 |
+static const float g1_Q8[] = { |
|
67 |
+ 0.01565675600122f, 0.03752716391991f, 0.05417891378782f, 0.08417044116767f, |
|
68 |
+ 0.10307344158036f, 0.12222452249753f, 0.125f |
|
69 |
+}; |
|
70 |
+ |
|
71 |
+static const float g2_Q4[] = { |
|
72 |
+ -0.05908211155639f, -0.04871498374946f, 0.0f, 0.07778723915851f, |
|
73 |
+ 0.16486303567403f, 0.23279856662996f, 0.25f |
|
74 |
+}; |
|
75 |
+ |
|
76 |
+static void make_filters_from_proto(float (*filter)[7][2], const float *proto, int bands) |
|
77 |
+{ |
|
78 |
+ int q, n; |
|
79 |
+ for (q = 0; q < bands; q++) { |
|
80 |
+ for (n = 0; n < 7; n++) { |
|
81 |
+ double theta = 2 * M_PI * (q + 0.5) * (n - 6) / bands; |
|
82 |
+ filter[q][n][0] = proto[n] * cos(theta); |
|
83 |
+ filter[q][n][1] = proto[n] * -sin(theta); |
|
84 |
+ } |
|
85 |
+ } |
|
86 |
+} |
|
87 |
+ |
|
88 |
+static void ps_tableinit(void) |
|
89 |
+{ |
|
90 |
+ static const float ipdopd_sin[] = { 0, M_SQRT1_2, 1, M_SQRT1_2, 0, -M_SQRT1_2, -1, -M_SQRT1_2 }; |
|
91 |
+ static const float ipdopd_cos[] = { 1, M_SQRT1_2, 0, -M_SQRT1_2, -1, -M_SQRT1_2, 0, M_SQRT1_2 }; |
|
92 |
+ int pd0, pd1, pd2; |
|
93 |
+ |
|
94 |
+ static const float iid_par_dequant[] = { |
|
95 |
+ //iid_par_dequant_default |
|
96 |
+ 0.05623413251903, 0.12589254117942, 0.19952623149689, 0.31622776601684, |
|
97 |
+ 0.44668359215096, 0.63095734448019, 0.79432823472428, 1, |
|
98 |
+ 1.25892541179417, 1.58489319246111, 2.23872113856834, 3.16227766016838, |
|
99 |
+ 5.01187233627272, 7.94328234724282, 17.7827941003892, |
|
100 |
+ //iid_par_dequant_fine |
|
101 |
+ 0.00316227766017, 0.00562341325190, 0.01, 0.01778279410039, |
|
102 |
+ 0.03162277660168, 0.05623413251903, 0.07943282347243, 0.11220184543020, |
|
103 |
+ 0.15848931924611, 0.22387211385683, 0.31622776601684, 0.39810717055350, |
|
104 |
+ 0.50118723362727, 0.63095734448019, 0.79432823472428, 1, |
|
105 |
+ 1.25892541179417, 1.58489319246111, 1.99526231496888, 2.51188643150958, |
|
106 |
+ 3.16227766016838, 4.46683592150963, 6.30957344480193, 8.91250938133745, |
|
107 |
+ 12.5892541179417, 17.7827941003892, 31.6227766016838, 56.2341325190349, |
|
108 |
+ 100, 177.827941003892, 316.227766016837, |
|
109 |
+ }; |
|
110 |
+ static const float icc_invq[] = { |
|
111 |
+ 1, 0.937, 0.84118, 0.60092, 0.36764, 0, -0.589, -1 |
|
112 |
+ }; |
|
113 |
+ static const float acos_icc_invq[] = { |
|
114 |
+ 0, 0.35685527, 0.57133466, 0.92614472, 1.1943263, M_PI/2, 2.2006171, M_PI |
|
115 |
+ }; |
|
116 |
+ int iid, icc; |
|
117 |
+ |
|
118 |
+ int k, m; |
|
119 |
+ static const int8_t f_center_20[] = { |
|
120 |
+ -3, -1, 1, 3, 5, 7, 10, 14, 18, 22, |
|
121 |
+ }; |
|
122 |
+ static const int8_t f_center_34[] = { |
|
123 |
+ 2, 6, 10, 14, 18, 22, 26, 30, |
|
124 |
+ 34,-10, -6, -2, 51, 57, 15, 21, |
|
125 |
+ 27, 33, 39, 45, 54, 66, 78, 42, |
|
126 |
+ 102, 66, 78, 90,102,114,126, 90, |
|
127 |
+ }; |
|
128 |
+ static const float fractional_delay_links[] = { 0.43f, 0.75f, 0.347f }; |
|
129 |
+ const float fractional_delay_gain = 0.39f; |
|
130 |
+ |
|
131 |
+ for (pd0 = 0; pd0 < 8; pd0++) { |
|
132 |
+ float pd0_re = ipdopd_cos[pd0]; |
|
133 |
+ float pd0_im = ipdopd_sin[pd0]; |
|
134 |
+ for (pd1 = 0; pd1 < 8; pd1++) { |
|
135 |
+ float pd1_re = ipdopd_cos[pd1]; |
|
136 |
+ float pd1_im = ipdopd_sin[pd1]; |
|
137 |
+ for (pd2 = 0; pd2 < 8; pd2++) { |
|
138 |
+ float pd2_re = ipdopd_cos[pd2]; |
|
139 |
+ float pd2_im = ipdopd_sin[pd2]; |
|
140 |
+ float re_smooth = 0.25f * pd0_re + 0.5f * pd1_re + pd2_re; |
|
141 |
+ float im_smooth = 0.25f * pd0_im + 0.5f * pd1_im + pd2_im; |
|
142 |
+ float pd_mag = 1 / sqrt(im_smooth * im_smooth + re_smooth * re_smooth); |
|
143 |
+ pd_re_smooth[pd0*64+pd1*8+pd2] = re_smooth * pd_mag; |
|
144 |
+ pd_im_smooth[pd0*64+pd1*8+pd2] = im_smooth * pd_mag; |
|
145 |
+ } |
|
146 |
+ } |
|
147 |
+ } |
|
148 |
+ |
|
149 |
+ for (iid = 0; iid < 46; iid++) { |
|
150 |
+ float c = iid_par_dequant[iid]; //<Linear Inter-channel Intensity Difference |
|
151 |
+ float c1 = (float)M_SQRT2 / sqrtf(1.0f + c*c); |
|
152 |
+ float c2 = c * c1; |
|
153 |
+ for (icc = 0; icc < 8; icc++) { |
|
154 |
+ /*if (PS_BASELINE || ps->icc_mode < 3)*/ { |
|
155 |
+ float alpha = 0.5f * acos_icc_invq[icc]; |
|
156 |
+ float beta = alpha * (c1 - c2) * (float)M_SQRT1_2; |
|
157 |
+ HA[iid][icc][0] = c2 * cosf(beta + alpha); |
|
158 |
+ HA[iid][icc][1] = c1 * cosf(beta - alpha); |
|
159 |
+ HA[iid][icc][2] = c2 * sinf(beta + alpha); |
|
160 |
+ HA[iid][icc][3] = c1 * sinf(beta - alpha); |
|
161 |
+ } /* else */ { |
|
162 |
+ float alpha, gamma, mu, rho; |
|
163 |
+ float alpha_c, alpha_s, gamma_c, gamma_s; |
|
164 |
+ rho = FFMAX(icc_invq[icc], 0.05f); |
|
165 |
+ alpha = 0.5f * atan2f(2.0f * c * rho, c*c - 1.0f); |
|
166 |
+ mu = c + 1.0f / c; |
|
167 |
+ mu = sqrtf(1 + (4 * rho * rho - 4)/(mu * mu)); |
|
168 |
+ gamma = atanf(sqrtf((1.0f - mu)/(1.0f + mu))); |
|
169 |
+ if (alpha < 0) alpha += M_PI/2; |
|
170 |
+ alpha_c = cosf(alpha); |
|
171 |
+ alpha_s = sinf(alpha); |
|
172 |
+ gamma_c = cosf(gamma); |
|
173 |
+ gamma_s = sinf(gamma); |
|
174 |
+ HB[iid][icc][0] = M_SQRT2 * alpha_c * gamma_c; |
|
175 |
+ HB[iid][icc][1] = M_SQRT2 * alpha_s * gamma_c; |
|
176 |
+ HB[iid][icc][2] = -M_SQRT2 * alpha_s * gamma_s; |
|
177 |
+ HB[iid][icc][3] = M_SQRT2 * alpha_c * gamma_s; |
|
178 |
+ } |
|
179 |
+ } |
|
180 |
+ } |
|
181 |
+ |
|
182 |
+ for (k = 0; k < NR_ALLPASS_BANDS20; k++) { |
|
183 |
+ double f_center, theta; |
|
184 |
+ if (k < FF_ARRAY_ELEMS(f_center_20)) |
|
185 |
+ f_center = f_center_20[k] * 0.125; |
|
186 |
+ else |
|
187 |
+ f_center = k - 6.5f; |
|
188 |
+ for (m = 0; m < PS_AP_LINKS; m++) { |
|
189 |
+ theta = -M_PI * fractional_delay_links[m] * f_center; |
|
190 |
+ Q_fract_allpass[0][k][m][0] = cos(theta); |
|
191 |
+ Q_fract_allpass[0][k][m][1] = sin(theta); |
|
192 |
+ } |
|
193 |
+ theta = -M_PI*fractional_delay_gain*f_center; |
|
194 |
+ phi_fract[0][k][0] = cos(theta); |
|
195 |
+ phi_fract[0][k][1] = sin(theta); |
|
196 |
+ } |
|
197 |
+ for (k = 0; k < NR_ALLPASS_BANDS34; k++) { |
|
198 |
+ double f_center, theta; |
|
199 |
+ if (k < FF_ARRAY_ELEMS(f_center_34)) |
|
200 |
+ f_center = f_center_34[k] / 24.; |
|
201 |
+ else |
|
202 |
+ f_center = k - 26.5f; |
|
203 |
+ for (m = 0; m < PS_AP_LINKS; m++) { |
|
204 |
+ theta = -M_PI * fractional_delay_links[m] * f_center; |
|
205 |
+ Q_fract_allpass[1][k][m][0] = cos(theta); |
|
206 |
+ Q_fract_allpass[1][k][m][1] = sin(theta); |
|
207 |
+ } |
|
208 |
+ theta = -M_PI*fractional_delay_gain*f_center; |
|
209 |
+ phi_fract[1][k][0] = cos(theta); |
|
210 |
+ phi_fract[1][k][1] = sin(theta); |
|
211 |
+ } |
|
212 |
+ |
|
213 |
+ make_filters_from_proto(f20_0_8, g0_Q8, 8); |
|
214 |
+ make_filters_from_proto(f34_0_12, g0_Q12, 12); |
|
215 |
+ make_filters_from_proto(f34_1_8, g1_Q8, 8); |
|
216 |
+ make_filters_from_proto(f34_2_4, g2_Q4, 4); |
|
217 |
+} |
|
218 |
+#endif /* CONFIG_HARDCODED_TABLES */ |
|
219 |
+ |
|
220 |
+#endif /* PS_TABLEGEN_H */ |
0 | 221 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,163 @@ |
0 |
+/* |
|
1 |
+ * MPEG-4 Parametric Stereo data tables |
|
2 |
+ * Copyright (c) 2010 Alex Converse <alex.converse@gmail.com> |
|
3 |
+ * |
|
4 |
+ * This file is part of FFmpeg. |
|
5 |
+ * |
|
6 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
7 |
+ * modify it under the terms of the GNU Lesser General Public |
|
8 |
+ * License as published by the Free Software Foundation; either |
|
9 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
10 |
+ * |
|
11 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
12 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 |
+ * Lesser General Public License for more details. |
|
15 |
+ * |
|
16 |
+ * You should have received a copy of the GNU Lesser General Public |
|
17 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
18 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
19 |
+ */ |
|
20 |
+ |
|
21 |
+static const uint8_t huff_iid_df1_bits[] = { |
|
22 |
+ 18, 18, 18, 18, 18, 18, 18, 18, 18, 17, 18, 17, 17, 16, 16, 15, 14, 14, |
|
23 |
+ 13, 12, 12, 11, 10, 10, 8, 7, 6, 5, 4, 3, 1, 3, 4, 5, 6, 7, |
|
24 |
+ 8, 9, 10, 11, 11, 12, 13, 14, 14, 15, 16, 16, 17, 17, 18, 17, 18, 18, |
|
25 |
+ 18, 18, 18, 18, 18, 18, 18, |
|
26 |
+}; |
|
27 |
+ |
|
28 |
+static const uint32_t huff_iid_df1_codes[] = { |
|
29 |
+ 0x01FEB4, 0x01FEB5, 0x01FD76, 0x01FD77, 0x01FD74, 0x01FD75, 0x01FE8A, |
|
30 |
+ 0x01FE8B, 0x01FE88, 0x00FE80, 0x01FEB6, 0x00FE82, 0x00FEB8, 0x007F42, |
|
31 |
+ 0x007FAE, 0x003FAF, 0x001FD1, 0x001FE9, 0x000FE9, 0x0007EA, 0x0007FB, |
|
32 |
+ 0x0003FB, 0x0001FB, 0x0001FF, 0x00007C, 0x00003C, 0x00001C, 0x00000C, |
|
33 |
+ 0x000000, 0x000001, 0x000001, 0x000002, 0x000001, 0x00000D, 0x00001D, |
|
34 |
+ 0x00003D, 0x00007D, 0x0000FC, 0x0001FC, 0x0003FC, 0x0003F4, 0x0007EB, |
|
35 |
+ 0x000FEA, 0x001FEA, 0x001FD6, 0x003FD0, 0x007FAF, 0x007F43, 0x00FEB9, |
|
36 |
+ 0x00FE83, 0x01FEB7, 0x00FE81, 0x01FE89, 0x01FE8E, 0x01FE8F, 0x01FE8C, |
|
37 |
+ 0x01FE8D, 0x01FEB2, 0x01FEB3, 0x01FEB0, 0x01FEB1, |
|
38 |
+}; |
|
39 |
+ |
|
40 |
+static const uint8_t huff_iid_dt1_bits[] = { |
|
41 |
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 14, 14, 13, |
|
42 |
+ 13, 13, 12, 12, 11, 10, 9, 9, 7, 6, 5, 3, 1, 2, 5, 6, 7, 8, |
|
43 |
+ 9, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, |
|
44 |
+ 16, 16, 16, 16, 16, 16, 16, |
|
45 |
+}; |
|
46 |
+ |
|
47 |
+static const uint16_t huff_iid_dt1_codes[] = { |
|
48 |
+ 0x004ED4, 0x004ED5, 0x004ECE, 0x004ECF, 0x004ECC, 0x004ED6, 0x004ED8, |
|
49 |
+ 0x004F46, 0x004F60, 0x002718, 0x002719, 0x002764, 0x002765, 0x00276D, |
|
50 |
+ 0x0027B1, 0x0013B7, 0x0013D6, 0x0009C7, 0x0009E9, 0x0009ED, 0x0004EE, |
|
51 |
+ 0x0004F7, 0x000278, 0x000139, 0x00009A, 0x00009F, 0x000020, 0x000011, |
|
52 |
+ 0x00000A, 0x000003, 0x000001, 0x000000, 0x00000B, 0x000012, 0x000021, |
|
53 |
+ 0x00004C, 0x00009B, 0x00013A, 0x000279, 0x000270, 0x0004EF, 0x0004E2, |
|
54 |
+ 0x0009EA, 0x0009D8, 0x0013D7, 0x0013D0, 0x0027B2, 0x0027A2, 0x00271A, |
|
55 |
+ 0x00271B, 0x004F66, 0x004F67, 0x004F61, 0x004F47, 0x004ED9, 0x004ED7, |
|
56 |
+ 0x004ECD, 0x004ED2, 0x004ED3, 0x004ED0, 0x004ED1, |
|
57 |
+}; |
|
58 |
+ |
|
59 |
+static const uint8_t huff_iid_df0_bits[] = { |
|
60 |
+ 17, 17, 17, 17, 16, 15, 13, 10, 9, 7, 6, 5, 4, 3, 1, 3, 4, 5, |
|
61 |
+ 6, 6, 8, 11, 13, 14, 14, 15, 17, 18, 18, |
|
62 |
+}; |
|
63 |
+ |
|
64 |
+static const uint32_t huff_iid_df0_codes[] = { |
|
65 |
+ 0x01FFFB, 0x01FFFC, 0x01FFFD, 0x01FFFA, 0x00FFFC, 0x007FFC, 0x001FFD, |
|
66 |
+ 0x0003FE, 0x0001FE, 0x00007E, 0x00003C, 0x00001D, 0x00000D, 0x000005, |
|
67 |
+ 0x000000, 0x000004, 0x00000C, 0x00001C, 0x00003D, 0x00003E, 0x0000FE, |
|
68 |
+ 0x0007FE, 0x001FFC, 0x003FFC, 0x003FFD, 0x007FFD, 0x01FFFE, 0x03FFFE, |
|
69 |
+ 0x03FFFF, |
|
70 |
+}; |
|
71 |
+ |
|
72 |
+static const uint8_t huff_iid_dt0_bits[] = { |
|
73 |
+ 19, 19, 19, 20, 20, 20, 17, 15, 12, 10, 8, 6, 4, 2, 1, 3, 5, 7, |
|
74 |
+ 9, 11, 13, 14, 17, 19, 20, 20, 20, 20, 20, |
|
75 |
+}; |
|
76 |
+ |
|
77 |
+static const uint32_t huff_iid_dt0_codes[] = { |
|
78 |
+ 0x07FFF9, 0x07FFFA, 0x07FFFB, 0x0FFFF8, 0x0FFFF9, 0x0FFFFA, 0x01FFFD, |
|
79 |
+ 0x007FFE, 0x000FFE, 0x0003FE, 0x0000FE, 0x00003E, 0x00000E, 0x000002, |
|
80 |
+ 0x000000, 0x000006, 0x00001E, 0x00007E, 0x0001FE, 0x0007FE, 0x001FFE, |
|
81 |
+ 0x003FFE, 0x01FFFC, 0x07FFF8, 0x0FFFFB, 0x0FFFFC, 0x0FFFFD, 0x0FFFFE, |
|
82 |
+ 0x0FFFFF, |
|
83 |
+}; |
|
84 |
+ |
|
85 |
+static const uint8_t huff_icc_df_bits[] = { |
|
86 |
+ 14, 14, 12, 10, 7, 5, 3, 1, 2, 4, 6, 8, 9, 11, 13, |
|
87 |
+}; |
|
88 |
+ |
|
89 |
+static const uint16_t huff_icc_df_codes[] = { |
|
90 |
+ 0x3FFF, 0x3FFE, 0x0FFE, 0x03FE, 0x007E, 0x001E, 0x0006, 0x0000, |
|
91 |
+ 0x0002, 0x000E, 0x003E, 0x00FE, 0x01FE, 0x07FE, 0x1FFE, |
|
92 |
+}; |
|
93 |
+ |
|
94 |
+static const uint8_t huff_icc_dt_bits[] = { |
|
95 |
+ 14, 13, 11, 9, 7, 5, 3, 1, 2, 4, 6, 8, 10, 12, 14, |
|
96 |
+}; |
|
97 |
+ |
|
98 |
+static const uint16_t huff_icc_dt_codes[] = { |
|
99 |
+ 0x3FFE, 0x1FFE, 0x07FE, 0x01FE, 0x007E, 0x001E, 0x0006, 0x0000, |
|
100 |
+ 0x0002, 0x000E, 0x003E, 0x00FE, 0x03FE, 0x0FFE, 0x3FFF, |
|
101 |
+}; |
|
102 |
+ |
|
103 |
+static const uint8_t huff_ipd_df_bits[] = { |
|
104 |
+ 1, 3, 4, 4, 4, 4, 4, 4, |
|
105 |
+}; |
|
106 |
+ |
|
107 |
+static const uint8_t huff_ipd_df_codes[] = { |
|
108 |
+ 0x01, 0x00, 0x06, 0x04, 0x02, 0x03, 0x05, 0x07, |
|
109 |
+}; |
|
110 |
+ |
|
111 |
+static const uint8_t huff_ipd_dt_bits[] = { |
|
112 |
+ 1, 3, 4, 5, 5, 4, 4, 3, |
|
113 |
+}; |
|
114 |
+ |
|
115 |
+static const uint8_t huff_ipd_dt_codes[] = { |
|
116 |
+ 0x01, 0x02, 0x02, 0x03, 0x02, 0x00, 0x03, 0x03, |
|
117 |
+}; |
|
118 |
+ |
|
119 |
+static const uint8_t huff_opd_df_bits[] = { |
|
120 |
+ 1, 3, 4, 4, 5, 5, 4, 3, |
|
121 |
+}; |
|
122 |
+ |
|
123 |
+static const uint8_t huff_opd_df_codes[] = { |
|
124 |
+ 0x01, 0x01, 0x06, 0x04, 0x0F, 0x0E, 0x05, 0x00, |
|
125 |
+}; |
|
126 |
+ |
|
127 |
+static const uint8_t huff_opd_dt_bits[] = { |
|
128 |
+ 1, 3, 4, 5, 5, 4, 4, 3, |
|
129 |
+}; |
|
130 |
+ |
|
131 |
+static const uint8_t huff_opd_dt_codes[] = { |
|
132 |
+ 0x01, 0x02, 0x01, 0x07, 0x06, 0x00, 0x02, 0x03, |
|
133 |
+}; |
|
134 |
+ |
|
135 |
+static const int8_t huff_offset[] = { |
|
136 |
+ 30, 30, |
|
137 |
+ 14, 14, |
|
138 |
+ 7, 7, |
|
139 |
+ 0, 0, |
|
140 |
+ 0, 0, |
|
141 |
+}; |
|
142 |
+ |
|
143 |
+///Table 8.48 |
|
144 |
+static const int8_t k_to_i_20[] = { |
|
145 |
+ 1, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 14, 15, |
|
146 |
+ 15, 15, 16, 16, 16, 16, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, |
|
147 |
+ 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, |
|
148 |
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19 |
|
149 |
+}; |
|
150 |
+///Table 8.49 |
|
151 |
+static const int8_t k_to_i_34[] = { |
|
152 |
+ 0, 1, 2, 3, 4, 5, 6, 6, 7, 2, 1, 0, 10, 10, 4, 5, 6, 7, 8, |
|
153 |
+ 9, 10, 11, 12, 9, 14, 11, 12, 13, 14, 15, 16, 13, 16, 17, 18, 19, 20, 21, |
|
154 |
+ 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 27, 28, 28, 28, 29, 29, 29, |
|
155 |
+ 30, 30, 30, 31, 31, 31, 31, 32, 32, 32, 32, 33, 33, 33, 33, 33, 33, 33, 33, |
|
156 |
+ 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33 |
|
157 |
+}; |
|
158 |
+ |
|
159 |
+static const float g1_Q2[] = { |
|
160 |
+ 0.0f, 0.01899487526049f, 0.0f, -0.07293139167538f, |
|
161 |
+ 0.0f, 0.30596630545168f, 0.5f |
|
162 |
+}; |
... | ... |
@@ -31,6 +31,7 @@ |
31 | 31 |
|
32 | 32 |
#include <stdint.h> |
33 | 33 |
#include "fft.h" |
34 |
+#include "ps.h" |
|
34 | 35 |
|
35 | 36 |
/** |
36 | 37 |
* Spectral Band Replication header - spectrum parameters that invoke a reset if they differ from the previous header. |
... | ... |
@@ -133,6 +134,7 @@ typedef struct { |
133 | 133 |
///The number of frequency bands in f_master |
134 | 134 |
unsigned n_master; |
135 | 135 |
SBRData data[2]; |
136 |
+ PSContext ps; |
|
136 | 137 |
///N_Low and N_High respectively, the number of frequency bands for low and high resolution |
137 | 138 |
unsigned n[2]; |
138 | 139 |
///Number of noise floor bands |
... | ... |
@@ -157,7 +159,7 @@ typedef struct { |
157 | 157 |
///QMF output of the HF generator |
158 | 158 |
float X_high[64][40][2]; |
159 | 159 |
///QMF values of the reconstructed signal |
160 |
- DECLARE_ALIGNED(16, float, X)[2][2][32][64]; |
|
160 |
+ DECLARE_ALIGNED(16, float, X)[2][2][38][64]; |
|
161 | 161 |
///Zeroth coefficient used to filter the subband signals |
162 | 162 |
float alpha0[64][2]; |
163 | 163 |
///First coefficient used to filter the subband signals |