A large portion of this code was orignally authored by Robert Swain. The rest
was written by me. Full history is available at:
svn://svn.ffmpeg.org/soc/aac-sbr
http://github.com/aconverse/ffmpeg-heaac/tree/sbr_pub
Originally committed as revision 22316 to svn://svn.ffmpeg.org/ffmpeg/trunk
| ... | ... |
@@ -41,7 +41,7 @@ OBJS-$(CONFIG_VAAPI) += vaapi.o |
| 41 | 41 |
OBJS-$(CONFIG_VDPAU) += vdpau.o |
| 42 | 42 |
|
| 43 | 43 |
# decoders/encoders/hardware accelerators |
| 44 |
-OBJS-$(CONFIG_AAC_DECODER) += aac.o aactab.o |
|
| 44 |
+OBJS-$(CONFIG_AAC_DECODER) += aac.o aactab.o aacsbr.o |
|
| 45 | 45 |
OBJS-$(CONFIG_AAC_ENCODER) += aacenc.o aaccoder.o \ |
| 46 | 46 |
aacpsy.o aactab.o \ |
| 47 | 47 |
psymodel.o iirfilter.o \ |
| ... | ... |
@@ -62,7 +62,7 @@ |
| 62 | 62 |
* N MIDI |
| 63 | 63 |
* N Harmonic and Individual Lines plus Noise |
| 64 | 64 |
* N Text-To-Speech Interface |
| 65 |
- * N (in progress) Spectral Band Replication |
|
| 65 |
+ * Y Spectral Band Replication |
|
| 66 | 66 |
* Y (not in this code) Layer-1 |
| 67 | 67 |
* Y (not in this code) Layer-2 |
| 68 | 68 |
* Y (not in this code) Layer-3 |
| ... | ... |
@@ -86,6 +86,8 @@ |
| 86 | 86 |
#include "aac.h" |
| 87 | 87 |
#include "aactab.h" |
| 88 | 88 |
#include "aacdectab.h" |
| 89 |
+#include "sbr.h" |
|
| 90 |
+#include "aacsbr.h" |
|
| 89 | 91 |
#include "mpeg4audio.h" |
| 90 | 92 |
#include "aac_parser.h" |
| 91 | 93 |
|
| ... | ... |
@@ -180,14 +182,18 @@ static av_cold int che_configure(AACContext *ac, |
| 180 | 180 |
if (che_pos[type][id]) {
|
| 181 | 181 |
if (!ac->che[type][id] && !(ac->che[type][id] = av_mallocz(sizeof(ChannelElement)))) |
| 182 | 182 |
return AVERROR(ENOMEM); |
| 183 |
+ ff_aac_sbr_ctx_init(&ac->che[type][id]->sbr); |
|
| 183 | 184 |
if (type != TYPE_CCE) {
|
| 184 | 185 |
ac->output_data[(*channels)++] = ac->che[type][id]->ch[0].ret; |
| 185 | 186 |
if (type == TYPE_CPE) {
|
| 186 | 187 |
ac->output_data[(*channels)++] = ac->che[type][id]->ch[1].ret; |
| 187 | 188 |
} |
| 188 | 189 |
} |
| 189 |
- } else |
|
| 190 |
+ } else {
|
|
| 191 |
+ if (ac->che[type][id]) |
|
| 192 |
+ ff_aac_sbr_ctx_close(&ac->che[type][id]->sbr); |
|
| 190 | 193 |
av_freep(&ac->che[type][id]); |
| 194 |
+ } |
|
| 191 | 195 |
return 0; |
| 192 | 196 |
} |
| 193 | 197 |
|
| ... | ... |
@@ -530,6 +536,8 @@ static av_cold int aac_decode_init(AVCodecContext *avccontext) |
| 530 | 530 |
AAC_INIT_VLC_STATIC( 9, 366); |
| 531 | 531 |
AAC_INIT_VLC_STATIC(10, 462); |
| 532 | 532 |
|
| 533 |
+ ff_aac_sbr_init(); |
|
| 534 |
+ |
|
| 533 | 535 |
dsputil_init(&ac->dsp, avccontext); |
| 534 | 536 |
|
| 535 | 537 |
ac->random_state = 0x1f2e3d4c; |
| ... | ... |
@@ -1545,23 +1553,6 @@ static int decode_cce(AACContext *ac, GetBitContext *gb, ChannelElement *che) |
| 1545 | 1545 |
} |
| 1546 | 1546 |
|
| 1547 | 1547 |
/** |
| 1548 |
- * Decode Spectral Band Replication extension data; reference: table 4.55. |
|
| 1549 |
- * |
|
| 1550 |
- * @param crc flag indicating the presence of CRC checksum |
|
| 1551 |
- * @param cnt length of TYPE_FIL syntactic element in bytes |
|
| 1552 |
- * |
|
| 1553 |
- * @return Returns number of bytes consumed from the TYPE_FIL element. |
|
| 1554 |
- */ |
|
| 1555 |
-static int decode_sbr_extension(AACContext *ac, GetBitContext *gb, |
|
| 1556 |
- int crc, int cnt) |
|
| 1557 |
-{
|
|
| 1558 |
- // TODO : sbr_extension implementation |
|
| 1559 |
- av_log_missing_feature(ac->avccontext, "SBR", 0); |
|
| 1560 |
- skip_bits_long(gb, 8 * cnt - 4); // -4 due to reading extension type |
|
| 1561 |
- return cnt; |
|
| 1562 |
-} |
|
| 1563 |
- |
|
| 1564 |
-/** |
|
| 1565 | 1548 |
* Parse whether channels are to be excluded from Dynamic Range Compression; reference: table 4.53. |
| 1566 | 1549 |
* |
| 1567 | 1550 |
* @return Returns number of bytes consumed. |
| ... | ... |
@@ -1641,7 +1632,8 @@ static int decode_dynamic_range(DynamicRangeControl *che_drc, |
| 1641 | 1641 |
* |
| 1642 | 1642 |
* @return Returns number of bytes consumed |
| 1643 | 1643 |
*/ |
| 1644 |
-static int decode_extension_payload(AACContext *ac, GetBitContext *gb, int cnt) |
|
| 1644 |
+static int decode_extension_payload(AACContext *ac, GetBitContext *gb, int cnt, |
|
| 1645 |
+ ChannelElement *che, enum RawDataBlockType elem_type) |
|
| 1645 | 1646 |
{
|
| 1646 | 1647 |
int crc_flag = 0; |
| 1647 | 1648 |
int res = cnt; |
| ... | ... |
@@ -1649,7 +1641,21 @@ static int decode_extension_payload(AACContext *ac, GetBitContext *gb, int cnt) |
| 1649 | 1649 |
case EXT_SBR_DATA_CRC: |
| 1650 | 1650 |
crc_flag++; |
| 1651 | 1651 |
case EXT_SBR_DATA: |
| 1652 |
- res = decode_sbr_extension(ac, gb, crc_flag, cnt); |
|
| 1652 |
+ if (!che) {
|
|
| 1653 |
+ av_log(ac->avccontext, AV_LOG_ERROR, "SBR was found before the first channel element.\n"); |
|
| 1654 |
+ return res; |
|
| 1655 |
+ } else if (!ac->m4ac.sbr) {
|
|
| 1656 |
+ av_log(ac->avccontext, AV_LOG_ERROR, "SBR signaled to be not-present but was found in the bitstream.\n"); |
|
| 1657 |
+ skip_bits_long(gb, 8 * cnt - 4); |
|
| 1658 |
+ return res; |
|
| 1659 |
+ } else if (ac->m4ac.sbr == -1 && ac->output_configured == OC_LOCKED) {
|
|
| 1660 |
+ av_log(ac->avccontext, AV_LOG_ERROR, "Implicit SBR was found with a first occurrence after the first frame.\n"); |
|
| 1661 |
+ skip_bits_long(gb, 8 * cnt - 4); |
|
| 1662 |
+ return res; |
|
| 1663 |
+ } else {
|
|
| 1664 |
+ ac->m4ac.sbr = 1; |
|
| 1665 |
+ } |
|
| 1666 |
+ res = ff_decode_sbr_extension(ac, &che->sbr, gb, crc_flag, cnt, elem_type); |
|
| 1653 | 1667 |
break; |
| 1654 | 1668 |
case EXT_DYNAMIC_RANGE: |
| 1655 | 1669 |
res = decode_dynamic_range(&ac->che_drc, gb, cnt); |
| ... | ... |
@@ -1830,8 +1836,9 @@ static void apply_independent_coupling(AACContext *ac, |
| 1830 | 1830 |
const float bias = ac->add_bias; |
| 1831 | 1831 |
const float *src = cce->ch[0].ret; |
| 1832 | 1832 |
float *dest = target->ret; |
| 1833 |
+ const int len = 1024 << (ac->m4ac.sbr == 1); |
|
| 1833 | 1834 |
|
| 1834 |
- for (i = 0; i < 1024; i++) |
|
| 1835 |
+ for (i = 0; i < len; i++) |
|
| 1835 | 1836 |
dest[i] += gain * (src[i] - bias); |
| 1836 | 1837 |
} |
| 1837 | 1838 |
|
| ... | ... |
@@ -1889,10 +1896,18 @@ static void spectral_to_sample(AACContext *ac) |
| 1889 | 1889 |
apply_tns(che->ch[1].coeffs, &che->ch[1].tns, &che->ch[1].ics, 1); |
| 1890 | 1890 |
if (type <= TYPE_CPE) |
| 1891 | 1891 |
apply_channel_coupling(ac, che, type, i, BETWEEN_TNS_AND_IMDCT, apply_dependent_coupling); |
| 1892 |
- if (type != TYPE_CCE || che->coup.coupling_point == AFTER_IMDCT) |
|
| 1892 |
+ if (type != TYPE_CCE || che->coup.coupling_point == AFTER_IMDCT) {
|
|
| 1893 | 1893 |
imdct_and_windowing(ac, &che->ch[0]); |
| 1894 |
- if (type == TYPE_CPE) |
|
| 1894 |
+ if (ac->m4ac.sbr > 0) {
|
|
| 1895 |
+ ff_sbr_dequant(ac, &che->sbr, type == TYPE_CPE ? TYPE_CPE : TYPE_SCE); |
|
| 1896 |
+ ff_sbr_apply(ac, &che->sbr, 0, che->ch[0].ret, che->ch[0].ret); |
|
| 1897 |
+ } |
|
| 1898 |
+ } |
|
| 1899 |
+ if (type == TYPE_CPE) {
|
|
| 1895 | 1900 |
imdct_and_windowing(ac, &che->ch[1]); |
| 1901 |
+ if (ac->m4ac.sbr > 0) |
|
| 1902 |
+ ff_sbr_apply(ac, &che->sbr, 1, che->ch[1].ret, che->ch[1].ret); |
|
| 1903 |
+ } |
|
| 1896 | 1904 |
if (type <= TYPE_CCE) |
| 1897 | 1905 |
apply_channel_coupling(ac, che, type, i, AFTER_IMDCT, apply_independent_coupling); |
| 1898 | 1906 |
} |
| ... | ... |
@@ -1942,9 +1957,9 @@ static int aac_decode_frame(AVCodecContext *avccontext, void *data, |
| 1942 | 1942 |
const uint8_t *buf = avpkt->data; |
| 1943 | 1943 |
int buf_size = avpkt->size; |
| 1944 | 1944 |
AACContext *ac = avccontext->priv_data; |
| 1945 |
- ChannelElement *che = NULL; |
|
| 1945 |
+ ChannelElement *che = NULL, *che_prev = NULL; |
|
| 1946 | 1946 |
GetBitContext gb; |
| 1947 |
- enum RawDataBlockType elem_type; |
|
| 1947 |
+ enum RawDataBlockType elem_type, elem_type_prev = TYPE_END; |
|
| 1948 | 1948 |
int err, elem_id, data_size_tmp; |
| 1949 | 1949 |
int buf_consumed; |
| 1950 | 1950 |
int samples = 1024, multiplier; |
| ... | ... |
@@ -2014,7 +2029,7 @@ static int aac_decode_frame(AVCodecContext *avccontext, void *data, |
| 2014 | 2014 |
return -1; |
| 2015 | 2015 |
} |
| 2016 | 2016 |
while (elem_id > 0) |
| 2017 |
- elem_id -= decode_extension_payload(ac, &gb, elem_id); |
|
| 2017 |
+ elem_id -= decode_extension_payload(ac, &gb, elem_id, che_prev, elem_type_prev); |
|
| 2018 | 2018 |
err = 0; /* FIXME */ |
| 2019 | 2019 |
break; |
| 2020 | 2020 |
|
| ... | ... |
@@ -2023,6 +2038,9 @@ static int aac_decode_frame(AVCodecContext *avccontext, void *data, |
| 2023 | 2023 |
break; |
| 2024 | 2024 |
} |
| 2025 | 2025 |
|
| 2026 |
+ che_prev = che; |
|
| 2027 |
+ elem_type_prev = elem_type; |
|
| 2028 |
+ |
|
| 2026 | 2029 |
if (err) |
| 2027 | 2030 |
return err; |
| 2028 | 2031 |
|
| ... | ... |
@@ -2034,14 +2052,14 @@ static int aac_decode_frame(AVCodecContext *avccontext, void *data, |
| 2034 | 2034 |
|
| 2035 | 2035 |
spectral_to_sample(ac); |
| 2036 | 2036 |
|
| 2037 |
- multiplier = 0; |
|
| 2037 |
+ multiplier = (ac->m4ac.sbr == 1) ? ac->m4ac.ext_sample_rate > ac->m4ac.sample_rate : 0; |
|
| 2038 | 2038 |
samples <<= multiplier; |
| 2039 | 2039 |
if (ac->output_configured < OC_LOCKED) {
|
| 2040 | 2040 |
avccontext->sample_rate = ac->m4ac.sample_rate << multiplier; |
| 2041 | 2041 |
avccontext->frame_size = samples; |
| 2042 | 2042 |
} |
| 2043 | 2043 |
|
| 2044 |
- data_size_tmp = 1024 * avccontext->channels * sizeof(int16_t); |
|
| 2044 |
+ data_size_tmp = samples * avccontext->channels * sizeof(int16_t); |
|
| 2045 | 2045 |
if (*data_size < data_size_tmp) {
|
| 2046 | 2046 |
av_log(avccontext, AV_LOG_ERROR, |
| 2047 | 2047 |
"Output buffer too small (%d) or trying to output too many samples (%d) for this frame.\n", |
| ... | ... |
@@ -2050,7 +2068,7 @@ static int aac_decode_frame(AVCodecContext *avccontext, void *data, |
| 2050 | 2050 |
} |
| 2051 | 2051 |
*data_size = data_size_tmp; |
| 2052 | 2052 |
|
| 2053 |
- ac->dsp.float_to_int16_interleave(data, (const float **)ac->output_data, 1024, avccontext->channels); |
|
| 2053 |
+ ac->dsp.float_to_int16_interleave(data, (const float **)ac->output_data, samples, avccontext->channels); |
|
| 2054 | 2054 |
|
| 2055 | 2055 |
if (ac->output_configured) |
| 2056 | 2056 |
ac->output_configured = OC_LOCKED; |
| ... | ... |
@@ -2065,8 +2083,11 @@ static av_cold int aac_decode_close(AVCodecContext *avccontext) |
| 2065 | 2065 |
int i, type; |
| 2066 | 2066 |
|
| 2067 | 2067 |
for (i = 0; i < MAX_ELEM_ID; i++) {
|
| 2068 |
- for (type = 0; type < 4; type++) |
|
| 2068 |
+ for (type = 0; type < 4; type++) {
|
|
| 2069 |
+ if (ac->che[type][i]) |
|
| 2070 |
+ ff_aac_sbr_ctx_close(&ac->che[type][i]->sbr); |
|
| 2069 | 2071 |
av_freep(&ac->che[type][i]); |
| 2072 |
+ } |
|
| 2070 | 2073 |
} |
| 2071 | 2074 |
|
| 2072 | 2075 |
ff_mdct_end(&ac->mdct); |
| ... | ... |
@@ -34,6 +34,7 @@ |
| 34 | 34 |
#include "dsputil.h" |
| 35 | 35 |
#include "fft.h" |
| 36 | 36 |
#include "mpeg4audio.h" |
| 37 |
+#include "sbr.h" |
|
| 37 | 38 |
|
| 38 | 39 |
#include <stdint.h> |
| 39 | 40 |
|
| ... | ... |
@@ -217,7 +218,7 @@ typedef struct {
|
| 217 | 217 |
uint8_t zeroes[128]; ///< band is not coded (used by encoder) |
| 218 | 218 |
DECLARE_ALIGNED(16, float, coeffs)[1024]; ///< coefficients for IMDCT |
| 219 | 219 |
DECLARE_ALIGNED(16, float, saved)[1024]; ///< overlap |
| 220 |
- DECLARE_ALIGNED(16, float, ret)[1024]; ///< PCM output |
|
| 220 |
+ DECLARE_ALIGNED(16, float, ret)[2048]; ///< PCM output |
|
| 221 | 221 |
PredictorState predictor_state[MAX_PREDICTORS]; |
| 222 | 222 |
} SingleChannelElement; |
| 223 | 223 |
|
| ... | ... |
@@ -233,6 +234,7 @@ typedef struct {
|
| 233 | 233 |
SingleChannelElement ch[2]; |
| 234 | 234 |
// CCE specific |
| 235 | 235 |
ChannelCoupling coup; |
| 236 |
+ SpectralBandReplication sbr; |
|
| 236 | 237 |
} ChannelElement; |
| 237 | 238 |
|
| 238 | 239 |
/** |
| 239 | 240 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,1759 @@ |
| 0 |
+/* |
|
| 1 |
+ * AAC Spectral Band Replication decoding functions |
|
| 2 |
+ * Copyright (c) 2008-2009 Robert Swain ( rob opendot cl ) |
|
| 3 |
+ * Copyright (c) 2009-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 |
+/** |
|
| 23 |
+ * @file libavcodec/aacsbr.c |
|
| 24 |
+ * AAC Spectral Band Replication decoding functions |
|
| 25 |
+ * @author Robert Swain ( rob opendot cl ) |
|
| 26 |
+ */ |
|
| 27 |
+ |
|
| 28 |
+#include "aac.h" |
|
| 29 |
+#include "sbr.h" |
|
| 30 |
+#include "aacsbr.h" |
|
| 31 |
+#include "aacsbrdata.h" |
|
| 32 |
+ |
|
| 33 |
+#include <stdint.h> |
|
| 34 |
+#include <float.h> |
|
| 35 |
+ |
|
| 36 |
+#define ENVELOPE_ADJUSTMENT_OFFSET 2 |
|
| 37 |
+#define NOISE_FLOOR_OFFSET 6.0f |
|
| 38 |
+ |
|
| 39 |
+/** |
|
| 40 |
+ * SBR VLC tables |
|
| 41 |
+ */ |
|
| 42 |
+enum {
|
|
| 43 |
+ T_HUFFMAN_ENV_1_5DB, |
|
| 44 |
+ F_HUFFMAN_ENV_1_5DB, |
|
| 45 |
+ T_HUFFMAN_ENV_BAL_1_5DB, |
|
| 46 |
+ F_HUFFMAN_ENV_BAL_1_5DB, |
|
| 47 |
+ T_HUFFMAN_ENV_3_0DB, |
|
| 48 |
+ F_HUFFMAN_ENV_3_0DB, |
|
| 49 |
+ T_HUFFMAN_ENV_BAL_3_0DB, |
|
| 50 |
+ F_HUFFMAN_ENV_BAL_3_0DB, |
|
| 51 |
+ T_HUFFMAN_NOISE_3_0DB, |
|
| 52 |
+ T_HUFFMAN_NOISE_BAL_3_0DB, |
|
| 53 |
+}; |
|
| 54 |
+ |
|
| 55 |
+/** |
|
| 56 |
+ * bs_frame_class - frame class of current SBR frame (14496-3 sp04 p98) |
|
| 57 |
+ */ |
|
| 58 |
+enum {
|
|
| 59 |
+ FIXFIX, |
|
| 60 |
+ FIXVAR, |
|
| 61 |
+ VARFIX, |
|
| 62 |
+ VARVAR, |
|
| 63 |
+}; |
|
| 64 |
+ |
|
| 65 |
+enum {
|
|
| 66 |
+ EXTENSION_ID_PS = 2, |
|
| 67 |
+}; |
|
| 68 |
+ |
|
| 69 |
+static VLC vlc_sbr[10]; |
|
| 70 |
+static const int8_t vlc_sbr_lav[10] = |
|
| 71 |
+ { 60, 60, 24, 24, 31, 31, 12, 12, 31, 12 };
|
|
| 72 |
+static DECLARE_ALIGNED(16, float, analysis_cos_pre)[64]; |
|
| 73 |
+static DECLARE_ALIGNED(16, float, analysis_sin_pre)[64]; |
|
| 74 |
+static DECLARE_ALIGNED(16, float, analysis_cossin_post)[32][2]; |
|
| 75 |
+static const DECLARE_ALIGNED(16, float, zero64)[64]; |
|
| 76 |
+ |
|
| 77 |
+#define SBR_INIT_VLC_STATIC(num, size) \ |
|
| 78 |
+ INIT_VLC_STATIC(&vlc_sbr[num], 9, sbr_tmp[num].table_size / sbr_tmp[num].elem_size, \ |
|
| 79 |
+ sbr_tmp[num].sbr_bits , 1, 1, \ |
|
| 80 |
+ sbr_tmp[num].sbr_codes, sbr_tmp[num].elem_size, sbr_tmp[num].elem_size, \ |
|
| 81 |
+ size) |
|
| 82 |
+ |
|
| 83 |
+#define SBR_VLC_ROW(name) \ |
|
| 84 |
+ { name ## _codes, name ## _bits, sizeof(name ## _codes), sizeof(name ## _codes[0]) }
|
|
| 85 |
+ |
|
| 86 |
+av_cold void ff_aac_sbr_init(void) |
|
| 87 |
+{
|
|
| 88 |
+ int n, k; |
|
| 89 |
+ static const struct {
|
|
| 90 |
+ const void *sbr_codes, *sbr_bits; |
|
| 91 |
+ const unsigned int table_size, elem_size; |
|
| 92 |
+ } sbr_tmp[] = {
|
|
| 93 |
+ SBR_VLC_ROW(t_huffman_env_1_5dB), |
|
| 94 |
+ SBR_VLC_ROW(f_huffman_env_1_5dB), |
|
| 95 |
+ SBR_VLC_ROW(t_huffman_env_bal_1_5dB), |
|
| 96 |
+ SBR_VLC_ROW(f_huffman_env_bal_1_5dB), |
|
| 97 |
+ SBR_VLC_ROW(t_huffman_env_3_0dB), |
|
| 98 |
+ SBR_VLC_ROW(f_huffman_env_3_0dB), |
|
| 99 |
+ SBR_VLC_ROW(t_huffman_env_bal_3_0dB), |
|
| 100 |
+ SBR_VLC_ROW(f_huffman_env_bal_3_0dB), |
|
| 101 |
+ SBR_VLC_ROW(t_huffman_noise_3_0dB), |
|
| 102 |
+ SBR_VLC_ROW(t_huffman_noise_bal_3_0dB), |
|
| 103 |
+ }; |
|
| 104 |
+ |
|
| 105 |
+ // SBR VLC table initialization |
|
| 106 |
+ SBR_INIT_VLC_STATIC(0, 1098); |
|
| 107 |
+ SBR_INIT_VLC_STATIC(1, 1092); |
|
| 108 |
+ SBR_INIT_VLC_STATIC(2, 768); |
|
| 109 |
+ SBR_INIT_VLC_STATIC(3, 1026); |
|
| 110 |
+ SBR_INIT_VLC_STATIC(4, 1058); |
|
| 111 |
+ SBR_INIT_VLC_STATIC(5, 1052); |
|
| 112 |
+ SBR_INIT_VLC_STATIC(6, 544); |
|
| 113 |
+ SBR_INIT_VLC_STATIC(7, 544); |
|
| 114 |
+ SBR_INIT_VLC_STATIC(8, 592); |
|
| 115 |
+ SBR_INIT_VLC_STATIC(9, 512); |
|
| 116 |
+ |
|
| 117 |
+ for (n = 0; n < 64; n++) {
|
|
| 118 |
+ float pre = M_PI * n / 64; |
|
| 119 |
+ analysis_cos_pre[n] = cosf(pre); |
|
| 120 |
+ analysis_sin_pre[n] = sinf(pre); |
|
| 121 |
+ } |
|
| 122 |
+ for (k = 0; k < 32; k++) {
|
|
| 123 |
+ float post = M_PI * (k + 0.5) / 128; |
|
| 124 |
+ analysis_cossin_post[k][0] = 4.0 * cosf(post); |
|
| 125 |
+ analysis_cossin_post[k][1] = -4.0 * sinf(post); |
|
| 126 |
+ } |
|
| 127 |
+ for (n = 1; n < 320; n++) |
|
| 128 |
+ sbr_qmf_window_us[320 + n] = sbr_qmf_window_us[320 - n]; |
|
| 129 |
+ sbr_qmf_window_us[384] = -sbr_qmf_window_us[384]; |
|
| 130 |
+ sbr_qmf_window_us[512] = -sbr_qmf_window_us[512]; |
|
| 131 |
+ |
|
| 132 |
+ for (n = 0; n < 320; n++) |
|
| 133 |
+ sbr_qmf_window_ds[n] = sbr_qmf_window_us[2*n]; |
|
| 134 |
+} |
|
| 135 |
+ |
|
| 136 |
+av_cold void ff_aac_sbr_ctx_init(SpectralBandReplication *sbr) |
|
| 137 |
+{
|
|
| 138 |
+ sbr->kx[0] = sbr->kx[1] = 32; //Typo in spec, kx' inits to 32 |
|
| 139 |
+ sbr->data[0].synthesis_filterbank_samples_offset = SBR_SYNTHESIS_BUF_SIZE - (1280 - 128); |
|
| 140 |
+ sbr->data[1].synthesis_filterbank_samples_offset = SBR_SYNTHESIS_BUF_SIZE - (1280 - 128); |
|
| 141 |
+ ff_mdct_init(&sbr->mdct, 7, 1, 1.0/64); |
|
| 142 |
+ ff_rdft_init(&sbr->rdft, 6, IDFT_R2C); |
|
| 143 |
+} |
|
| 144 |
+ |
|
| 145 |
+av_cold void ff_aac_sbr_ctx_close(SpectralBandReplication *sbr) |
|
| 146 |
+{
|
|
| 147 |
+ ff_mdct_end(&sbr->mdct); |
|
| 148 |
+ ff_rdft_end(&sbr->rdft); |
|
| 149 |
+} |
|
| 150 |
+ |
|
| 151 |
+static int qsort_comparison_function_int16(const void *a, const void *b) |
|
| 152 |
+{
|
|
| 153 |
+ return *(const int16_t *)a - *(const int16_t *)b; |
|
| 154 |
+} |
|
| 155 |
+ |
|
| 156 |
+static inline int in_table_int16(const int16_t *table, int last_el, int16_t needle) |
|
| 157 |
+{
|
|
| 158 |
+ int i; |
|
| 159 |
+ for (i = 0; i <= last_el; i++) |
|
| 160 |
+ if (table[i] == needle) |
|
| 161 |
+ return 1; |
|
| 162 |
+ return 0; |
|
| 163 |
+} |
|
| 164 |
+ |
|
| 165 |
+/// Limiter Frequency Band Table (14496-3 sp04 p198) |
|
| 166 |
+static void sbr_make_f_tablelim(SpectralBandReplication *sbr) |
|
| 167 |
+{
|
|
| 168 |
+ int k; |
|
| 169 |
+ if (sbr->bs_limiter_bands > 0) {
|
|
| 170 |
+ static const float bands_warped[3] = { 1.32715174233856803909f, //2^(0.49/1.2)
|
|
| 171 |
+ 1.18509277094158210129f, //2^(0.49/2) |
|
| 172 |
+ 1.11987160404675912501f }; //2^(0.49/3) |
|
| 173 |
+ const float lim_bands_per_octave_warped = bands_warped[sbr->bs_limiter_bands - 1]; |
|
| 174 |
+ int16_t patch_borders[5]; |
|
| 175 |
+ uint16_t *in = sbr->f_tablelim + 1, *out = sbr->f_tablelim; |
|
| 176 |
+ |
|
| 177 |
+ patch_borders[0] = sbr->kx[1]; |
|
| 178 |
+ for (k = 1; k <= sbr->num_patches; k++) |
|
| 179 |
+ patch_borders[k] = patch_borders[k-1] + sbr->patch_num_subbands[k-1]; |
|
| 180 |
+ |
|
| 181 |
+ memcpy(sbr->f_tablelim, sbr->f_tablelow, |
|
| 182 |
+ (sbr->n[0] + 1) * sizeof(sbr->f_tablelow[0])); |
|
| 183 |
+ if (sbr->num_patches > 1) |
|
| 184 |
+ memcpy(sbr->f_tablelim + sbr->n[0] + 1, patch_borders + 1, |
|
| 185 |
+ (sbr->num_patches - 1) * sizeof(patch_borders[0])); |
|
| 186 |
+ |
|
| 187 |
+ qsort(sbr->f_tablelim, sbr->num_patches + sbr->n[0], |
|
| 188 |
+ sizeof(sbr->f_tablelim[0]), |
|
| 189 |
+ qsort_comparison_function_int16); |
|
| 190 |
+ |
|
| 191 |
+ sbr->n_lim = sbr->n[0] + sbr->num_patches - 1; |
|
| 192 |
+ while (out < sbr->f_tablelim + sbr->n_lim) {
|
|
| 193 |
+ if (*in >= *out * lim_bands_per_octave_warped) {
|
|
| 194 |
+ *++out = *in++; |
|
| 195 |
+ } else if (*in == *out || |
|
| 196 |
+ !in_table_int16(patch_borders, sbr->num_patches, *in)) {
|
|
| 197 |
+ in++; |
|
| 198 |
+ sbr->n_lim--; |
|
| 199 |
+ } else if (!in_table_int16(patch_borders, sbr->num_patches, *out)) {
|
|
| 200 |
+ *out = *in++; |
|
| 201 |
+ sbr->n_lim--; |
|
| 202 |
+ } else {
|
|
| 203 |
+ *++out = *in++; |
|
| 204 |
+ } |
|
| 205 |
+ } |
|
| 206 |
+ } else {
|
|
| 207 |
+ sbr->f_tablelim[0] = sbr->f_tablelow[0]; |
|
| 208 |
+ sbr->f_tablelim[1] = sbr->f_tablelow[sbr->n[0]]; |
|
| 209 |
+ sbr->n_lim = 1; |
|
| 210 |
+ } |
|
| 211 |
+} |
|
| 212 |
+ |
|
| 213 |
+static unsigned int read_sbr_header(SpectralBandReplication *sbr, GetBitContext *gb) |
|
| 214 |
+{
|
|
| 215 |
+ unsigned int cnt = get_bits_count(gb); |
|
| 216 |
+ uint8_t bs_header_extra_1; |
|
| 217 |
+ uint8_t bs_header_extra_2; |
|
| 218 |
+ int old_bs_limiter_bands = sbr->bs_limiter_bands; |
|
| 219 |
+ SpectrumParameters old_spectrum_params; |
|
| 220 |
+ |
|
| 221 |
+ sbr->start = 1; |
|
| 222 |
+ |
|
| 223 |
+ // Save last spectrum parameters variables to compare to new ones |
|
| 224 |
+ memcpy(&old_spectrum_params, &sbr->spectrum_params, sizeof(SpectrumParameters)); |
|
| 225 |
+ |
|
| 226 |
+ sbr->bs_amp_res_header = get_bits1(gb); |
|
| 227 |
+ sbr->spectrum_params.bs_start_freq = get_bits(gb, 4); |
|
| 228 |
+ sbr->spectrum_params.bs_stop_freq = get_bits(gb, 4); |
|
| 229 |
+ sbr->spectrum_params.bs_xover_band = get_bits(gb, 3); |
|
| 230 |
+ skip_bits(gb, 2); // bs_reserved |
|
| 231 |
+ |
|
| 232 |
+ bs_header_extra_1 = get_bits1(gb); |
|
| 233 |
+ bs_header_extra_2 = get_bits1(gb); |
|
| 234 |
+ |
|
| 235 |
+ if (bs_header_extra_1) {
|
|
| 236 |
+ sbr->spectrum_params.bs_freq_scale = get_bits(gb, 2); |
|
| 237 |
+ sbr->spectrum_params.bs_alter_scale = get_bits1(gb); |
|
| 238 |
+ sbr->spectrum_params.bs_noise_bands = get_bits(gb, 2); |
|
| 239 |
+ } else {
|
|
| 240 |
+ sbr->spectrum_params.bs_freq_scale = 2; |
|
| 241 |
+ sbr->spectrum_params.bs_alter_scale = 1; |
|
| 242 |
+ sbr->spectrum_params.bs_noise_bands = 2; |
|
| 243 |
+ } |
|
| 244 |
+ |
|
| 245 |
+ // Check if spectrum parameters changed |
|
| 246 |
+ if (memcmp(&old_spectrum_params, &sbr->spectrum_params, sizeof(SpectrumParameters))) |
|
| 247 |
+ sbr->reset = 1; |
|
| 248 |
+ |
|
| 249 |
+ if (bs_header_extra_2) {
|
|
| 250 |
+ sbr->bs_limiter_bands = get_bits(gb, 2); |
|
| 251 |
+ sbr->bs_limiter_gains = get_bits(gb, 2); |
|
| 252 |
+ sbr->bs_interpol_freq = get_bits1(gb); |
|
| 253 |
+ sbr->bs_smoothing_mode = get_bits1(gb); |
|
| 254 |
+ } else {
|
|
| 255 |
+ sbr->bs_limiter_bands = 2; |
|
| 256 |
+ sbr->bs_limiter_gains = 2; |
|
| 257 |
+ sbr->bs_interpol_freq = 1; |
|
| 258 |
+ sbr->bs_smoothing_mode = 1; |
|
| 259 |
+ } |
|
| 260 |
+ |
|
| 261 |
+ if (sbr->bs_limiter_bands != old_bs_limiter_bands && !sbr->reset) |
|
| 262 |
+ sbr_make_f_tablelim(sbr); |
|
| 263 |
+ |
|
| 264 |
+ return get_bits_count(gb) - cnt; |
|
| 265 |
+} |
|
| 266 |
+ |
|
| 267 |
+static int array_min_int16(const int16_t *array, int nel) |
|
| 268 |
+{
|
|
| 269 |
+ int i, min = array[0]; |
|
| 270 |
+ for (i = 1; i < nel; i++) |
|
| 271 |
+ min = FFMIN(array[i], min); |
|
| 272 |
+ return min; |
|
| 273 |
+} |
|
| 274 |
+ |
|
| 275 |
+static void make_bands(int16_t* bands, int start, int stop, int num_bands) |
|
| 276 |
+{
|
|
| 277 |
+ int k, previous, present; |
|
| 278 |
+ float base, prod; |
|
| 279 |
+ |
|
| 280 |
+ base = powf((float)stop / start, 1.0f / num_bands); |
|
| 281 |
+ prod = start; |
|
| 282 |
+ previous = start; |
|
| 283 |
+ |
|
| 284 |
+ for (k = 0; k < num_bands-1; k++) {
|
|
| 285 |
+ prod *= base; |
|
| 286 |
+ present = lrintf(prod); |
|
| 287 |
+ bands[k] = present - previous; |
|
| 288 |
+ previous = present; |
|
| 289 |
+ } |
|
| 290 |
+ bands[num_bands-1] = stop - previous; |
|
| 291 |
+} |
|
| 292 |
+ |
|
| 293 |
+static int check_n_master(AVCodecContext *avccontext, int n_master, int bs_xover_band) |
|
| 294 |
+{
|
|
| 295 |
+ // Requirements (14496-3 sp04 p205) |
|
| 296 |
+ if (n_master <= 0) {
|
|
| 297 |
+ av_log(avccontext, AV_LOG_ERROR, "Invalid n_master: %d\n", n_master); |
|
| 298 |
+ return -1; |
|
| 299 |
+ } |
|
| 300 |
+ if (bs_xover_band >= n_master) {
|
|
| 301 |
+ av_log(avccontext, AV_LOG_ERROR, |
|
| 302 |
+ "Invalid bitstream, crossover band index beyond array bounds: %d\n", |
|
| 303 |
+ bs_xover_band); |
|
| 304 |
+ return -1; |
|
| 305 |
+ } |
|
| 306 |
+ return 0; |
|
| 307 |
+} |
|
| 308 |
+ |
|
| 309 |
+/// Master Frequency Band Table (14496-3 sp04 p194) |
|
| 310 |
+static int sbr_make_f_master(AACContext *ac, SpectralBandReplication *sbr, |
|
| 311 |
+ SpectrumParameters *spectrum) |
|
| 312 |
+{
|
|
| 313 |
+ unsigned int temp, max_qmf_subbands; |
|
| 314 |
+ unsigned int start_min, stop_min; |
|
| 315 |
+ int k; |
|
| 316 |
+ const int8_t *sbr_offset_ptr; |
|
| 317 |
+ int16_t stop_dk[13]; |
|
| 318 |
+ |
|
| 319 |
+ if (sbr->sample_rate < 32000) {
|
|
| 320 |
+ temp = 3000; |
|
| 321 |
+ } else if (sbr->sample_rate < 64000) {
|
|
| 322 |
+ temp = 4000; |
|
| 323 |
+ } else |
|
| 324 |
+ temp = 5000; |
|
| 325 |
+ |
|
| 326 |
+ start_min = ((temp << 7) + (sbr->sample_rate >> 1)) / sbr->sample_rate; |
|
| 327 |
+ stop_min = ((temp << 8) + (sbr->sample_rate >> 1)) / sbr->sample_rate; |
|
| 328 |
+ |
|
| 329 |
+ switch (sbr->sample_rate) {
|
|
| 330 |
+ case 16000: |
|
| 331 |
+ sbr_offset_ptr = sbr_offset[0]; |
|
| 332 |
+ break; |
|
| 333 |
+ case 22050: |
|
| 334 |
+ sbr_offset_ptr = sbr_offset[1]; |
|
| 335 |
+ break; |
|
| 336 |
+ case 24000: |
|
| 337 |
+ sbr_offset_ptr = sbr_offset[2]; |
|
| 338 |
+ break; |
|
| 339 |
+ case 32000: |
|
| 340 |
+ sbr_offset_ptr = sbr_offset[3]; |
|
| 341 |
+ break; |
|
| 342 |
+ case 44100: case 48000: case 64000: |
|
| 343 |
+ sbr_offset_ptr = sbr_offset[4]; |
|
| 344 |
+ break; |
|
| 345 |
+ case 88200: case 96000: case 128000: case 176400: case 192000: |
|
| 346 |
+ sbr_offset_ptr = sbr_offset[5]; |
|
| 347 |
+ break; |
|
| 348 |
+ default: |
|
| 349 |
+ av_log(ac->avccontext, AV_LOG_ERROR, |
|
| 350 |
+ "Unsupported sample rate for SBR: %d\n", sbr->sample_rate); |
|
| 351 |
+ return -1; |
|
| 352 |
+ } |
|
| 353 |
+ |
|
| 354 |
+ sbr->k[0] = start_min + sbr_offset_ptr[spectrum->bs_start_freq]; |
|
| 355 |
+ |
|
| 356 |
+ if (spectrum->bs_stop_freq < 14) {
|
|
| 357 |
+ sbr->k[2] = stop_min; |
|
| 358 |
+ make_bands(stop_dk, stop_min, 64, 13); |
|
| 359 |
+ qsort(stop_dk, 13, sizeof(stop_dk[0]), qsort_comparison_function_int16); |
|
| 360 |
+ for (k = 0; k < spectrum->bs_stop_freq; k++) |
|
| 361 |
+ sbr->k[2] += stop_dk[k]; |
|
| 362 |
+ } else if (spectrum->bs_stop_freq == 14) {
|
|
| 363 |
+ sbr->k[2] = 2*sbr->k[0]; |
|
| 364 |
+ } else if (spectrum->bs_stop_freq == 15) {
|
|
| 365 |
+ sbr->k[2] = 3*sbr->k[0]; |
|
| 366 |
+ } else {
|
|
| 367 |
+ av_log(ac->avccontext, AV_LOG_ERROR, |
|
| 368 |
+ "Invalid bs_stop_freq: %d\n", spectrum->bs_stop_freq); |
|
| 369 |
+ return -1; |
|
| 370 |
+ } |
|
| 371 |
+ sbr->k[2] = FFMIN(64, sbr->k[2]); |
|
| 372 |
+ |
|
| 373 |
+ // Requirements (14496-3 sp04 p205) |
|
| 374 |
+ if (sbr->sample_rate <= 32000) {
|
|
| 375 |
+ max_qmf_subbands = 48; |
|
| 376 |
+ } else if (sbr->sample_rate == 44100) {
|
|
| 377 |
+ max_qmf_subbands = 35; |
|
| 378 |
+ } else if (sbr->sample_rate >= 48000) |
|
| 379 |
+ max_qmf_subbands = 32; |
|
| 380 |
+ |
|
| 381 |
+ if (sbr->k[2] - sbr->k[0] > max_qmf_subbands) {
|
|
| 382 |
+ av_log(ac->avccontext, AV_LOG_ERROR, |
|
| 383 |
+ "Invalid bitstream, too many QMF subbands: %d\n", sbr->k[2] - sbr->k[0]); |
|
| 384 |
+ return -1; |
|
| 385 |
+ } |
|
| 386 |
+ |
|
| 387 |
+ if (!spectrum->bs_freq_scale) {
|
|
| 388 |
+ unsigned int dk; |
|
| 389 |
+ int k2diff; |
|
| 390 |
+ |
|
| 391 |
+ dk = spectrum->bs_alter_scale + 1; |
|
| 392 |
+ sbr->n_master = ((sbr->k[2] - sbr->k[0] + (dk&2)) >> dk) << 1; |
|
| 393 |
+ if (check_n_master(ac->avccontext, sbr->n_master, sbr->spectrum_params.bs_xover_band)) |
|
| 394 |
+ return -1; |
|
| 395 |
+ |
|
| 396 |
+ for (k = 1; k <= sbr->n_master; k++) |
|
| 397 |
+ sbr->f_master[k] = dk; |
|
| 398 |
+ |
|
| 399 |
+ k2diff = sbr->k[2] - sbr->k[0] - sbr->n_master * dk; |
|
| 400 |
+ if (k2diff < 0) {
|
|
| 401 |
+ sbr->f_master[1]--; |
|
| 402 |
+ sbr->f_master[2]-= (k2diff < 1); |
|
| 403 |
+ } else if (k2diff) {
|
|
| 404 |
+ sbr->f_master[sbr->n_master]++; |
|
| 405 |
+ } |
|
| 406 |
+ |
|
| 407 |
+ sbr->f_master[0] = sbr->k[0]; |
|
| 408 |
+ for (k = 1; k <= sbr->n_master; k++) |
|
| 409 |
+ sbr->f_master[k] += sbr->f_master[k - 1]; |
|
| 410 |
+ |
|
| 411 |
+ } else {
|
|
| 412 |
+ int half_bands = 7 - spectrum->bs_freq_scale; // bs_freq_scale = {1,2,3}
|
|
| 413 |
+ int two_regions, num_bands_0; |
|
| 414 |
+ int vdk0_max, vdk1_min; |
|
| 415 |
+ int16_t vk0[49]; |
|
| 416 |
+ |
|
| 417 |
+ if (49 * sbr->k[2] > 110 * sbr->k[0]) {
|
|
| 418 |
+ two_regions = 1; |
|
| 419 |
+ sbr->k[1] = 2 * sbr->k[0]; |
|
| 420 |
+ } else {
|
|
| 421 |
+ two_regions = 0; |
|
| 422 |
+ sbr->k[1] = sbr->k[2]; |
|
| 423 |
+ } |
|
| 424 |
+ |
|
| 425 |
+ num_bands_0 = lrintf(half_bands * log2f(sbr->k[1] / (float)sbr->k[0])) * 2; |
|
| 426 |
+ |
|
| 427 |
+ if (num_bands_0 <= 0) { // Requirements (14496-3 sp04 p205)
|
|
| 428 |
+ av_log(ac->avccontext, AV_LOG_ERROR, "Invalid num_bands_0: %d\n", num_bands_0); |
|
| 429 |
+ return -1; |
|
| 430 |
+ } |
|
| 431 |
+ |
|
| 432 |
+ vk0[0] = 0; |
|
| 433 |
+ |
|
| 434 |
+ make_bands(vk0+1, sbr->k[0], sbr->k[1], num_bands_0); |
|
| 435 |
+ |
|
| 436 |
+ qsort(vk0 + 1, num_bands_0, sizeof(vk0[1]), qsort_comparison_function_int16); |
|
| 437 |
+ vdk0_max = vk0[num_bands_0]; |
|
| 438 |
+ |
|
| 439 |
+ vk0[0] = sbr->k[0]; |
|
| 440 |
+ for (k = 1; k <= num_bands_0; k++) {
|
|
| 441 |
+ if (vk0[k] <= 0) { // Requirements (14496-3 sp04 p205)
|
|
| 442 |
+ av_log(ac->avccontext, AV_LOG_ERROR, "Invalid vDk0[%d]: %d\n", k, vk0[k]); |
|
| 443 |
+ return -1; |
|
| 444 |
+ } |
|
| 445 |
+ vk0[k] += vk0[k-1]; |
|
| 446 |
+ } |
|
| 447 |
+ |
|
| 448 |
+ if (two_regions) {
|
|
| 449 |
+ int16_t vk1[49]; |
|
| 450 |
+ float invwarp = spectrum->bs_alter_scale ? 0.76923076923076923077f |
|
| 451 |
+ : 1.0f; // bs_alter_scale = {0,1}
|
|
| 452 |
+ int num_bands_1 = lrintf(half_bands * invwarp * |
|
| 453 |
+ log2f(sbr->k[2] / (float)sbr->k[1])) * 2; |
|
| 454 |
+ |
|
| 455 |
+ make_bands(vk1+1, sbr->k[1], sbr->k[2], num_bands_1); |
|
| 456 |
+ |
|
| 457 |
+ vdk1_min = array_min_int16(vk1 + 1, num_bands_1); |
|
| 458 |
+ |
|
| 459 |
+ if (vdk1_min < vdk0_max) {
|
|
| 460 |
+ int change; |
|
| 461 |
+ qsort(vk1 + 1, num_bands_1, sizeof(vk1[1]), qsort_comparison_function_int16); |
|
| 462 |
+ change = FFMIN(vdk0_max - vk1[1], (vk1[num_bands_1] - vk1[1]) >> 1); |
|
| 463 |
+ vk1[1] += change; |
|
| 464 |
+ vk1[num_bands_1] -= change; |
|
| 465 |
+ } |
|
| 466 |
+ |
|
| 467 |
+ qsort(vk1 + 1, num_bands_1, sizeof(vk1[1]), qsort_comparison_function_int16); |
|
| 468 |
+ |
|
| 469 |
+ vk1[0] = sbr->k[1]; |
|
| 470 |
+ for (k = 1; k <= num_bands_1; k++) {
|
|
| 471 |
+ if (vk1[k] <= 0) { // Requirements (14496-3 sp04 p205)
|
|
| 472 |
+ av_log(ac->avccontext, AV_LOG_ERROR, "Invalid vDk1[%d]: %d\n", k, vk1[k]); |
|
| 473 |
+ return -1; |
|
| 474 |
+ } |
|
| 475 |
+ vk1[k] += vk1[k-1]; |
|
| 476 |
+ } |
|
| 477 |
+ |
|
| 478 |
+ sbr->n_master = num_bands_0 + num_bands_1; |
|
| 479 |
+ if (check_n_master(ac->avccontext, sbr->n_master, sbr->spectrum_params.bs_xover_band)) |
|
| 480 |
+ return -1; |
|
| 481 |
+ memcpy(&sbr->f_master[0], vk0, |
|
| 482 |
+ (num_bands_0 + 1) * sizeof(sbr->f_master[0])); |
|
| 483 |
+ memcpy(&sbr->f_master[num_bands_0 + 1], vk1 + 1, |
|
| 484 |
+ num_bands_1 * sizeof(sbr->f_master[0])); |
|
| 485 |
+ |
|
| 486 |
+ } else {
|
|
| 487 |
+ sbr->n_master = num_bands_0; |
|
| 488 |
+ if (check_n_master(ac->avccontext, sbr->n_master, sbr->spectrum_params.bs_xover_band)) |
|
| 489 |
+ return -1; |
|
| 490 |
+ memcpy(sbr->f_master, vk0, (num_bands_0 + 1) * sizeof(sbr->f_master[0])); |
|
| 491 |
+ } |
|
| 492 |
+ } |
|
| 493 |
+ |
|
| 494 |
+ return 0; |
|
| 495 |
+} |
|
| 496 |
+ |
|
| 497 |
+/// High Frequency Generation - Patch Construction (14496-3 sp04 p216 fig. 4.46) |
|
| 498 |
+static int sbr_hf_calc_npatches(AACContext *ac, SpectralBandReplication *sbr) |
|
| 499 |
+{
|
|
| 500 |
+ int i, k, sb = 0; |
|
| 501 |
+ int msb = sbr->k[0]; |
|
| 502 |
+ int usb = sbr->kx[1]; |
|
| 503 |
+ int goal_sb = ((1000 << 11) + (sbr->sample_rate >> 1)) / sbr->sample_rate; |
|
| 504 |
+ |
|
| 505 |
+ sbr->num_patches = 0; |
|
| 506 |
+ |
|
| 507 |
+ if (goal_sb < sbr->kx[1] + sbr->m[1]) {
|
|
| 508 |
+ for (k = 0; sbr->f_master[k] < goal_sb; k++) ; |
|
| 509 |
+ } else |
|
| 510 |
+ k = sbr->n_master; |
|
| 511 |
+ |
|
| 512 |
+ do {
|
|
| 513 |
+ int odd = 0; |
|
| 514 |
+ for (i = k; i == k || sb > (sbr->k[0] - 1 + msb - odd); i--) {
|
|
| 515 |
+ sb = sbr->f_master[i]; |
|
| 516 |
+ odd = (sb + sbr->k[0]) & 1; |
|
| 517 |
+ } |
|
| 518 |
+ |
|
| 519 |
+ sbr->patch_num_subbands[sbr->num_patches] = FFMAX(sb - usb, 0); |
|
| 520 |
+ sbr->patch_start_subband[sbr->num_patches] = sbr->k[0] - odd - sbr->patch_num_subbands[sbr->num_patches]; |
|
| 521 |
+ |
|
| 522 |
+ if (sbr->patch_num_subbands[sbr->num_patches] > 0) {
|
|
| 523 |
+ usb = sb; |
|
| 524 |
+ msb = sb; |
|
| 525 |
+ sbr->num_patches++; |
|
| 526 |
+ } else |
|
| 527 |
+ msb = sbr->kx[1]; |
|
| 528 |
+ |
|
| 529 |
+ if (sbr->f_master[k] - sb < 3) |
|
| 530 |
+ k = sbr->n_master; |
|
| 531 |
+ } while (sb != sbr->kx[1] + sbr->m[1]); |
|
| 532 |
+ |
|
| 533 |
+ if (sbr->patch_num_subbands[sbr->num_patches-1] < 3 && sbr->num_patches > 1) |
|
| 534 |
+ sbr->num_patches--; |
|
| 535 |
+ |
|
| 536 |
+ // Requirements (14496-3 sp04 p205) sets the maximum number of patches to 5 |
|
| 537 |
+ // However the Coding Technologies decoder check uses 6 patches |
|
| 538 |
+ if (sbr->num_patches > 6) {
|
|
| 539 |
+ av_log(ac->avccontext, AV_LOG_ERROR, "Too many patches: %d\n", sbr->num_patches); |
|
| 540 |
+ return -1; |
|
| 541 |
+ } |
|
| 542 |
+ |
|
| 543 |
+ return 0; |
|
| 544 |
+} |
|
| 545 |
+ |
|
| 546 |
+/// Derived Frequency Band Tables (14496-3 sp04 p197) |
|
| 547 |
+static int sbr_make_f_derived(AACContext *ac, SpectralBandReplication *sbr) |
|
| 548 |
+{
|
|
| 549 |
+ int k, temp; |
|
| 550 |
+ |
|
| 551 |
+ sbr->n[1] = sbr->n_master - sbr->spectrum_params.bs_xover_band; |
|
| 552 |
+ sbr->n[0] = (sbr->n[1] + 1) >> 1; |
|
| 553 |
+ |
|
| 554 |
+ memcpy(sbr->f_tablehigh, &sbr->f_master[sbr->spectrum_params.bs_xover_band], |
|
| 555 |
+ (sbr->n[1] + 1) * sizeof(sbr->f_master[0])); |
|
| 556 |
+ sbr->m[1] = sbr->f_tablehigh[sbr->n[1]] - sbr->f_tablehigh[0]; |
|
| 557 |
+ sbr->kx[1] = sbr->f_tablehigh[0]; |
|
| 558 |
+ |
|
| 559 |
+ // Requirements (14496-3 sp04 p205) |
|
| 560 |
+ if (sbr->kx[1] + sbr->m[1] > 64) {
|
|
| 561 |
+ av_log(ac->avccontext, AV_LOG_ERROR, |
|
| 562 |
+ "Stop frequency border too high: %d\n", sbr->kx[1] + sbr->m[1]); |
|
| 563 |
+ return -1; |
|
| 564 |
+ } |
|
| 565 |
+ if (sbr->kx[1] > 32) {
|
|
| 566 |
+ av_log(ac->avccontext, AV_LOG_ERROR, "Start frequency border too high: %d\n", sbr->kx[1]); |
|
| 567 |
+ return -1; |
|
| 568 |
+ } |
|
| 569 |
+ |
|
| 570 |
+ sbr->f_tablelow[0] = sbr->f_tablehigh[0]; |
|
| 571 |
+ temp = sbr->n[1] & 1; |
|
| 572 |
+ for (k = 1; k <= sbr->n[0]; k++) |
|
| 573 |
+ sbr->f_tablelow[k] = sbr->f_tablehigh[2 * k - temp]; |
|
| 574 |
+ |
|
| 575 |
+ sbr->n_q = FFMAX(1, lrintf(sbr->spectrum_params.bs_noise_bands * |
|
| 576 |
+ log2f(sbr->k[2] / (float)sbr->kx[1]))); // 0 <= bs_noise_bands <= 3 |
|
| 577 |
+ if (sbr->n_q > 5) {
|
|
| 578 |
+ av_log(ac->avccontext, AV_LOG_ERROR, "Too many noise floor scale factors: %d\n", sbr->n_q); |
|
| 579 |
+ return -1; |
|
| 580 |
+ } |
|
| 581 |
+ |
|
| 582 |
+ sbr->f_tablenoise[0] = sbr->f_tablelow[0]; |
|
| 583 |
+ temp = 0; |
|
| 584 |
+ for (k = 1; k <= sbr->n_q; k++) {
|
|
| 585 |
+ temp += (sbr->n[0] - temp) / (sbr->n_q + 1 - k); |
|
| 586 |
+ sbr->f_tablenoise[k] = sbr->f_tablelow[temp]; |
|
| 587 |
+ } |
|
| 588 |
+ |
|
| 589 |
+ if (sbr_hf_calc_npatches(ac, sbr) < 0) |
|
| 590 |
+ return -1; |
|
| 591 |
+ |
|
| 592 |
+ sbr_make_f_tablelim(sbr); |
|
| 593 |
+ |
|
| 594 |
+ sbr->data[0].f_indexnoise = 0; |
|
| 595 |
+ sbr->data[1].f_indexnoise = 0; |
|
| 596 |
+ |
|
| 597 |
+ return 0; |
|
| 598 |
+} |
|
| 599 |
+ |
|
| 600 |
+static av_always_inline void get_bits1_vector(GetBitContext *gb, uint8_t *vec, |
|
| 601 |
+ int elements) |
|
| 602 |
+{
|
|
| 603 |
+ int i; |
|
| 604 |
+ for (i = 0; i < elements; i++) {
|
|
| 605 |
+ vec[i] = get_bits1(gb); |
|
| 606 |
+ } |
|
| 607 |
+} |
|
| 608 |
+ |
|
| 609 |
+/** ceil(log2(index+1)) */ |
|
| 610 |
+static const int8_t ceil_log2[] = {
|
|
| 611 |
+ 0, 1, 2, 2, 3, 3, |
|
| 612 |
+}; |
|
| 613 |
+ |
|
| 614 |
+static int read_sbr_grid(AACContext *ac, SpectralBandReplication *sbr, |
|
| 615 |
+ GetBitContext *gb, SBRData *ch_data) |
|
| 616 |
+{
|
|
| 617 |
+ int i; |
|
| 618 |
+ |
|
| 619 |
+ ch_data->bs_freq_res[0] = ch_data->bs_freq_res[ch_data->bs_num_env[1]]; |
|
| 620 |
+ ch_data->bs_num_env[0] = ch_data->bs_num_env[1]; |
|
| 621 |
+ ch_data->bs_amp_res = sbr->bs_amp_res_header; |
|
| 622 |
+ |
|
| 623 |
+ switch (ch_data->bs_frame_class = get_bits(gb, 2)) {
|
|
| 624 |
+ case FIXFIX: |
|
| 625 |
+ ch_data->bs_num_env[1] = 1 << get_bits(gb, 2); |
|
| 626 |
+ if (ch_data->bs_num_env[1] == 1) |
|
| 627 |
+ ch_data->bs_amp_res = 0; |
|
| 628 |
+ |
|
| 629 |
+ ch_data->bs_freq_res[1] = get_bits1(gb); |
|
| 630 |
+ for (i = 1; i < ch_data->bs_num_env[1]; i++) |
|
| 631 |
+ ch_data->bs_freq_res[i + 1] = ch_data->bs_freq_res[1]; |
|
| 632 |
+ break; |
|
| 633 |
+ case FIXVAR: |
|
| 634 |
+ ch_data->bs_var_bord[1] = get_bits(gb, 2); |
|
| 635 |
+ ch_data->bs_num_rel[1] = get_bits(gb, 2); |
|
| 636 |
+ ch_data->bs_num_env[1] = ch_data->bs_num_rel[1] + 1; |
|
| 637 |
+ |
|
| 638 |
+ for (i = 0; i < ch_data->bs_num_rel[1]; i++) |
|
| 639 |
+ ch_data->bs_rel_bord[1][i] = 2 * get_bits(gb, 2) + 2; |
|
| 640 |
+ |
|
| 641 |
+ ch_data->bs_pointer = get_bits(gb, ceil_log2[ch_data->bs_num_env[1]]); |
|
| 642 |
+ |
|
| 643 |
+ for (i = 0; i < ch_data->bs_num_env[1]; i++) |
|
| 644 |
+ ch_data->bs_freq_res[ch_data->bs_num_env[1] - i] = get_bits1(gb); |
|
| 645 |
+ break; |
|
| 646 |
+ case VARFIX: |
|
| 647 |
+ ch_data->bs_var_bord[0] = get_bits(gb, 2); |
|
| 648 |
+ ch_data->bs_num_rel[0] = get_bits(gb, 2); |
|
| 649 |
+ ch_data->bs_num_env[1] = ch_data->bs_num_rel[0] + 1; |
|
| 650 |
+ |
|
| 651 |
+ for (i = 0; i < ch_data->bs_num_rel[0]; i++) |
|
| 652 |
+ ch_data->bs_rel_bord[0][i] = 2 * get_bits(gb, 2) + 2; |
|
| 653 |
+ |
|
| 654 |
+ ch_data->bs_pointer = get_bits(gb, ceil_log2[ch_data->bs_num_env[1]]); |
|
| 655 |
+ |
|
| 656 |
+ get_bits1_vector(gb, ch_data->bs_freq_res + 1, ch_data->bs_num_env[1]); |
|
| 657 |
+ break; |
|
| 658 |
+ case VARVAR: |
|
| 659 |
+ ch_data->bs_var_bord[0] = get_bits(gb, 2); |
|
| 660 |
+ ch_data->bs_var_bord[1] = get_bits(gb, 2); |
|
| 661 |
+ ch_data->bs_num_rel[0] = get_bits(gb, 2); |
|
| 662 |
+ ch_data->bs_num_rel[1] = get_bits(gb, 2); |
|
| 663 |
+ ch_data->bs_num_env[1] = ch_data->bs_num_rel[0] + ch_data->bs_num_rel[1] + 1; |
|
| 664 |
+ |
|
| 665 |
+ for (i = 0; i < ch_data->bs_num_rel[0]; i++) |
|
| 666 |
+ ch_data->bs_rel_bord[0][i] = 2 * get_bits(gb, 2) + 2; |
|
| 667 |
+ for (i = 0; i < ch_data->bs_num_rel[1]; i++) |
|
| 668 |
+ ch_data->bs_rel_bord[1][i] = 2 * get_bits(gb, 2) + 2; |
|
| 669 |
+ |
|
| 670 |
+ ch_data->bs_pointer = get_bits(gb, ceil_log2[ch_data->bs_num_env[1]]); |
|
| 671 |
+ |
|
| 672 |
+ get_bits1_vector(gb, ch_data->bs_freq_res + 1, ch_data->bs_num_env[1]); |
|
| 673 |
+ break; |
|
| 674 |
+ } |
|
| 675 |
+ |
|
| 676 |
+ if (ch_data->bs_frame_class == FIXFIX && ch_data->bs_num_env[1] > 4) {
|
|
| 677 |
+ av_log(ac->avccontext, AV_LOG_ERROR, |
|
| 678 |
+ "Invalid bitstream, too many SBR envelopes in FIXFIX type SBR frame: %d\n", |
|
| 679 |
+ ch_data->bs_num_env[1]); |
|
| 680 |
+ return -1; |
|
| 681 |
+ } |
|
| 682 |
+ if (ch_data->bs_frame_class == VARVAR && ch_data->bs_num_env[1] > 5) {
|
|
| 683 |
+ av_log(ac->avccontext, AV_LOG_ERROR, |
|
| 684 |
+ "Invalid bitstream, too many SBR envelopes in VARVAR type SBR frame: %d\n", |
|
| 685 |
+ ch_data->bs_num_env[1]); |
|
| 686 |
+ return -1; |
|
| 687 |
+ } |
|
| 688 |
+ |
|
| 689 |
+ ch_data->bs_num_noise = (ch_data->bs_num_env[1] > 1) + 1; |
|
| 690 |
+ |
|
| 691 |
+ return 0; |
|
| 692 |
+} |
|
| 693 |
+ |
|
| 694 |
+static void copy_sbr_grid(SBRData *dst, const SBRData *src) {
|
|
| 695 |
+ //These variables are saved from the previous frame rather than copied |
|
| 696 |
+ dst->bs_freq_res[0] = dst->bs_freq_res[dst->bs_num_env[1]]; |
|
| 697 |
+ dst->bs_num_env[0] = dst->bs_num_env[1]; |
|
| 698 |
+ |
|
| 699 |
+ //These variables are read from the bitstream and therefore copied |
|
| 700 |
+ memcpy(dst->bs_freq_res+1, src->bs_freq_res+1, sizeof(dst->bs_freq_res)-sizeof(*dst->bs_freq_res)); |
|
| 701 |
+ memcpy(dst->bs_num_env+1, src->bs_num_env+1, sizeof(dst->bs_num_env)- sizeof(*dst->bs_num_env)); |
|
| 702 |
+ memcpy(dst->bs_var_bord, src->bs_var_bord, sizeof(dst->bs_var_bord)); |
|
| 703 |
+ memcpy(dst->bs_rel_bord, src->bs_rel_bord, sizeof(dst->bs_rel_bord)); |
|
| 704 |
+ memcpy(dst->bs_num_rel, src->bs_num_rel, sizeof(dst->bs_rel_bord)); |
|
| 705 |
+ dst->bs_amp_res = src->bs_amp_res; |
|
| 706 |
+ dst->bs_num_noise = src->bs_num_noise; |
|
| 707 |
+ dst->bs_pointer = src->bs_pointer; |
|
| 708 |
+ dst->bs_frame_class = src->bs_frame_class; |
|
| 709 |
+} |
|
| 710 |
+ |
|
| 711 |
+/// Read how the envelope and noise floor data is delta coded |
|
| 712 |
+static void read_sbr_dtdf(SpectralBandReplication *sbr, GetBitContext *gb, |
|
| 713 |
+ SBRData *ch_data) |
|
| 714 |
+{
|
|
| 715 |
+ get_bits1_vector(gb, ch_data->bs_df_env, ch_data->bs_num_env[1]); |
|
| 716 |
+ get_bits1_vector(gb, ch_data->bs_df_noise, ch_data->bs_num_noise); |
|
| 717 |
+} |
|
| 718 |
+ |
|
| 719 |
+/// Read inverse filtering data |
|
| 720 |
+static void read_sbr_invf(SpectralBandReplication *sbr, GetBitContext *gb, |
|
| 721 |
+ SBRData *ch_data) |
|
| 722 |
+{
|
|
| 723 |
+ int i; |
|
| 724 |
+ |
|
| 725 |
+ memcpy(ch_data->bs_invf_mode[1], ch_data->bs_invf_mode[0], 5 * sizeof(uint8_t)); |
|
| 726 |
+ for (i = 0; i < sbr->n_q; i++) |
|
| 727 |
+ ch_data->bs_invf_mode[0][i] = get_bits(gb, 2); |
|
| 728 |
+} |
|
| 729 |
+ |
|
| 730 |
+static void read_sbr_envelope(SpectralBandReplication *sbr, GetBitContext *gb, |
|
| 731 |
+ SBRData *ch_data, int ch) |
|
| 732 |
+{
|
|
| 733 |
+ int bits; |
|
| 734 |
+ int i, j, k; |
|
| 735 |
+ VLC_TYPE (*t_huff)[2], (*f_huff)[2]; |
|
| 736 |
+ int t_lav, f_lav; |
|
| 737 |
+ const int delta = (ch == 1 && sbr->bs_coupling == 1) + 1; |
|
| 738 |
+ const int odd = sbr->n[1] & 1; |
|
| 739 |
+ |
|
| 740 |
+ if (sbr->bs_coupling && ch) {
|
|
| 741 |
+ if (ch_data->bs_amp_res) {
|
|
| 742 |
+ bits = 5; |
|
| 743 |
+ t_huff = vlc_sbr[T_HUFFMAN_ENV_BAL_3_0DB].table; |
|
| 744 |
+ t_lav = vlc_sbr_lav[T_HUFFMAN_ENV_BAL_3_0DB]; |
|
| 745 |
+ f_huff = vlc_sbr[F_HUFFMAN_ENV_BAL_3_0DB].table; |
|
| 746 |
+ f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_BAL_3_0DB]; |
|
| 747 |
+ } else {
|
|
| 748 |
+ bits = 6; |
|
| 749 |
+ t_huff = vlc_sbr[T_HUFFMAN_ENV_BAL_1_5DB].table; |
|
| 750 |
+ t_lav = vlc_sbr_lav[T_HUFFMAN_ENV_BAL_1_5DB]; |
|
| 751 |
+ f_huff = vlc_sbr[F_HUFFMAN_ENV_BAL_1_5DB].table; |
|
| 752 |
+ f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_BAL_1_5DB]; |
|
| 753 |
+ } |
|
| 754 |
+ } else {
|
|
| 755 |
+ if (ch_data->bs_amp_res) {
|
|
| 756 |
+ bits = 6; |
|
| 757 |
+ t_huff = vlc_sbr[T_HUFFMAN_ENV_3_0DB].table; |
|
| 758 |
+ t_lav = vlc_sbr_lav[T_HUFFMAN_ENV_3_0DB]; |
|
| 759 |
+ f_huff = vlc_sbr[F_HUFFMAN_ENV_3_0DB].table; |
|
| 760 |
+ f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_3_0DB]; |
|
| 761 |
+ } else {
|
|
| 762 |
+ bits = 7; |
|
| 763 |
+ t_huff = vlc_sbr[T_HUFFMAN_ENV_1_5DB].table; |
|
| 764 |
+ t_lav = vlc_sbr_lav[T_HUFFMAN_ENV_1_5DB]; |
|
| 765 |
+ f_huff = vlc_sbr[F_HUFFMAN_ENV_1_5DB].table; |
|
| 766 |
+ f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_1_5DB]; |
|
| 767 |
+ } |
|
| 768 |
+ } |
|
| 769 |
+ |
|
| 770 |
+ for (i = 0; i < ch_data->bs_num_env[1]; i++) {
|
|
| 771 |
+ if (ch_data->bs_df_env[i]) {
|
|
| 772 |
+ // bs_freq_res[0] == bs_freq_res[bs_num_env[1]] from prev frame |
|
| 773 |
+ if (ch_data->bs_freq_res[i + 1] == ch_data->bs_freq_res[i]) {
|
|
| 774 |
+ for (j = 0; j < sbr->n[ch_data->bs_freq_res[i + 1]]; j++) |
|
| 775 |
+ ch_data->env_facs[i + 1][j] = ch_data->env_facs[i][j] + delta * (get_vlc2(gb, t_huff, 9, 3) - t_lav); |
|
| 776 |
+ } else if (ch_data->bs_freq_res[i + 1]) {
|
|
| 777 |
+ for (j = 0; j < sbr->n[ch_data->bs_freq_res[i + 1]]; j++) {
|
|
| 778 |
+ k = (j + odd) >> 1; // find k such that f_tablelow[k] <= f_tablehigh[j] < f_tablelow[k + 1] |
|
| 779 |
+ ch_data->env_facs[i + 1][j] = ch_data->env_facs[i][k] + delta * (get_vlc2(gb, t_huff, 9, 3) - t_lav); |
|
| 780 |
+ } |
|
| 781 |
+ } else {
|
|
| 782 |
+ for (j = 0; j < sbr->n[ch_data->bs_freq_res[i + 1]]; j++) {
|
|
| 783 |
+ k = j ? 2*j - odd : 0; // find k such that f_tablehigh[k] == f_tablelow[j] |
|
| 784 |
+ ch_data->env_facs[i + 1][j] = ch_data->env_facs[i][k] + delta * (get_vlc2(gb, t_huff, 9, 3) - t_lav); |
|
| 785 |
+ } |
|
| 786 |
+ } |
|
| 787 |
+ } else {
|
|
| 788 |
+ ch_data->env_facs[i + 1][0] = delta * get_bits(gb, bits); // bs_env_start_value_balance |
|
| 789 |
+ for (j = 1; j < sbr->n[ch_data->bs_freq_res[i + 1]]; j++) |
|
| 790 |
+ ch_data->env_facs[i + 1][j] = ch_data->env_facs[i + 1][j - 1] + delta * (get_vlc2(gb, f_huff, 9, 3) - f_lav); |
|
| 791 |
+ } |
|
| 792 |
+ } |
|
| 793 |
+ |
|
| 794 |
+ //assign 0th elements of env_facs from last elements |
|
| 795 |
+ memcpy(ch_data->env_facs[0], ch_data->env_facs[ch_data->bs_num_env[1]], |
|
| 796 |
+ sizeof(ch_data->env_facs[0])); |
|
| 797 |
+} |
|
| 798 |
+ |
|
| 799 |
+static void read_sbr_noise(SpectralBandReplication *sbr, GetBitContext *gb, |
|
| 800 |
+ SBRData *ch_data, int ch) |
|
| 801 |
+{
|
|
| 802 |
+ int i, j; |
|
| 803 |
+ VLC_TYPE (*t_huff)[2], (*f_huff)[2]; |
|
| 804 |
+ int t_lav, f_lav; |
|
| 805 |
+ int delta = (ch == 1 && sbr->bs_coupling == 1) + 1; |
|
| 806 |
+ |
|
| 807 |
+ if (sbr->bs_coupling && ch) {
|
|
| 808 |
+ t_huff = vlc_sbr[T_HUFFMAN_NOISE_BAL_3_0DB].table; |
|
| 809 |
+ t_lav = vlc_sbr_lav[T_HUFFMAN_NOISE_BAL_3_0DB]; |
|
| 810 |
+ f_huff = vlc_sbr[F_HUFFMAN_ENV_BAL_3_0DB].table; |
|
| 811 |
+ f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_BAL_3_0DB]; |
|
| 812 |
+ } else {
|
|
| 813 |
+ t_huff = vlc_sbr[T_HUFFMAN_NOISE_3_0DB].table; |
|
| 814 |
+ t_lav = vlc_sbr_lav[T_HUFFMAN_NOISE_3_0DB]; |
|
| 815 |
+ f_huff = vlc_sbr[F_HUFFMAN_ENV_3_0DB].table; |
|
| 816 |
+ f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_3_0DB]; |
|
| 817 |
+ } |
|
| 818 |
+ |
|
| 819 |
+ for (i = 0; i < ch_data->bs_num_noise; i++) {
|
|
| 820 |
+ if (ch_data->bs_df_noise[i]) {
|
|
| 821 |
+ for (j = 0; j < sbr->n_q; j++) |
|
| 822 |
+ ch_data->noise_facs[i + 1][j] = ch_data->noise_facs[i][j] + delta * (get_vlc2(gb, t_huff, 9, 2) - t_lav); |
|
| 823 |
+ } else {
|
|
| 824 |
+ ch_data->noise_facs[i + 1][0] = delta * get_bits(gb, 5); // bs_noise_start_value_balance or bs_noise_start_value_level |
|
| 825 |
+ for (j = 1; j < sbr->n_q; j++) |
|
| 826 |
+ ch_data->noise_facs[i + 1][j] = ch_data->noise_facs[i + 1][j - 1] + delta * (get_vlc2(gb, f_huff, 9, 3) - f_lav); |
|
| 827 |
+ } |
|
| 828 |
+ } |
|
| 829 |
+ |
|
| 830 |
+ //assign 0th elements of noise_facs from last elements |
|
| 831 |
+ memcpy(ch_data->noise_facs[0], ch_data->noise_facs[ch_data->bs_num_noise], |
|
| 832 |
+ sizeof(ch_data->noise_facs[0])); |
|
| 833 |
+} |
|
| 834 |
+ |
|
| 835 |
+static void read_sbr_extension(AACContext *ac, SpectralBandReplication *sbr, |
|
| 836 |
+ GetBitContext *gb, |
|
| 837 |
+ int bs_extension_id, int *num_bits_left) |
|
| 838 |
+{
|
|
| 839 |
+//TODO - implement ps_data for parametric stereo parsing |
|
| 840 |
+ switch (bs_extension_id) {
|
|
| 841 |
+ case EXTENSION_ID_PS: |
|
| 842 |
+#if 0 |
|
| 843 |
+ *num_bits_left -= ff_ps_data(gb, ps); |
|
| 844 |
+#else |
|
| 845 |
+ av_log_missing_feature(ac->avccontext, "Parametric Stereo is", 0); |
|
| 846 |
+ skip_bits_long(gb, *num_bits_left); // bs_fill_bits |
|
| 847 |
+ *num_bits_left = 0; |
|
| 848 |
+#endif |
|
| 849 |
+ break; |
|
| 850 |
+ default: |
|
| 851 |
+ av_log_missing_feature(ac->avccontext, "Reserved SBR extensions are", 1); |
|
| 852 |
+ skip_bits_long(gb, *num_bits_left); // bs_fill_bits |
|
| 853 |
+ *num_bits_left = 0; |
|
| 854 |
+ break; |
|
| 855 |
+ } |
|
| 856 |
+} |
|
| 857 |
+ |
|
| 858 |
+static void read_sbr_single_channel_element(AACContext *ac, |
|
| 859 |
+ SpectralBandReplication *sbr, |
|
| 860 |
+ GetBitContext *gb) |
|
| 861 |
+{
|
|
| 862 |
+ if (get_bits1(gb)) // bs_data_extra |
|
| 863 |
+ skip_bits(gb, 4); // bs_reserved |
|
| 864 |
+ |
|
| 865 |
+ read_sbr_grid(ac, sbr, gb, &sbr->data[0]); |
|
| 866 |
+ read_sbr_dtdf(sbr, gb, &sbr->data[0]); |
|
| 867 |
+ read_sbr_invf(sbr, gb, &sbr->data[0]); |
|
| 868 |
+ read_sbr_envelope(sbr, gb, &sbr->data[0], 0); |
|
| 869 |
+ read_sbr_noise(sbr, gb, &sbr->data[0], 0); |
|
| 870 |
+ |
|
| 871 |
+ if ((sbr->data[0].bs_add_harmonic_flag = get_bits1(gb))) |
|
| 872 |
+ get_bits1_vector(gb, sbr->data[0].bs_add_harmonic, sbr->n[1]); |
|
| 873 |
+} |
|
| 874 |
+ |
|
| 875 |
+static void read_sbr_channel_pair_element(AACContext *ac, |
|
| 876 |
+ SpectralBandReplication *sbr, |
|
| 877 |
+ GetBitContext *gb) |
|
| 878 |
+{
|
|
| 879 |
+ if (get_bits1(gb)) // bs_data_extra |
|
| 880 |
+ skip_bits(gb, 8); // bs_reserved |
|
| 881 |
+ |
|
| 882 |
+ if ((sbr->bs_coupling = get_bits1(gb))) {
|
|
| 883 |
+ read_sbr_grid(ac, sbr, gb, &sbr->data[0]); |
|
| 884 |
+ copy_sbr_grid(&sbr->data[1], &sbr->data[0]); |
|
| 885 |
+ read_sbr_dtdf(sbr, gb, &sbr->data[0]); |
|
| 886 |
+ read_sbr_dtdf(sbr, gb, &sbr->data[1]); |
|
| 887 |
+ read_sbr_invf(sbr, gb, &sbr->data[0]); |
|
| 888 |
+ memcpy(sbr->data[1].bs_invf_mode[1], sbr->data[1].bs_invf_mode[0], sizeof(sbr->data[1].bs_invf_mode[0])); |
|
| 889 |
+ memcpy(sbr->data[1].bs_invf_mode[0], sbr->data[0].bs_invf_mode[0], sizeof(sbr->data[1].bs_invf_mode[0])); |
|
| 890 |
+ read_sbr_envelope(sbr, gb, &sbr->data[0], 0); |
|
| 891 |
+ read_sbr_noise(sbr, gb, &sbr->data[0], 0); |
|
| 892 |
+ read_sbr_envelope(sbr, gb, &sbr->data[1], 1); |
|
| 893 |
+ read_sbr_noise(sbr, gb, &sbr->data[1], 1); |
|
| 894 |
+ } else {
|
|
| 895 |
+ read_sbr_grid(ac, sbr, gb, &sbr->data[0]); |
|
| 896 |
+ read_sbr_grid(ac, sbr, gb, &sbr->data[1]); |
|
| 897 |
+ read_sbr_dtdf(sbr, gb, &sbr->data[0]); |
|
| 898 |
+ read_sbr_dtdf(sbr, gb, &sbr->data[1]); |
|
| 899 |
+ read_sbr_invf(sbr, gb, &sbr->data[0]); |
|
| 900 |
+ read_sbr_invf(sbr, gb, &sbr->data[1]); |
|
| 901 |
+ read_sbr_envelope(sbr, gb, &sbr->data[0], 0); |
|
| 902 |
+ read_sbr_envelope(sbr, gb, &sbr->data[1], 1); |
|
| 903 |
+ read_sbr_noise(sbr, gb, &sbr->data[0], 0); |
|
| 904 |
+ read_sbr_noise(sbr, gb, &sbr->data[1], 1); |
|
| 905 |
+ } |
|
| 906 |
+ |
|
| 907 |
+ if ((sbr->data[0].bs_add_harmonic_flag = get_bits1(gb))) |
|
| 908 |
+ get_bits1_vector(gb, sbr->data[0].bs_add_harmonic, sbr->n[1]); |
|
| 909 |
+ if ((sbr->data[1].bs_add_harmonic_flag = get_bits1(gb))) |
|
| 910 |
+ get_bits1_vector(gb, sbr->data[1].bs_add_harmonic, sbr->n[1]); |
|
| 911 |
+} |
|
| 912 |
+ |
|
| 913 |
+static unsigned int read_sbr_data(AACContext *ac, SpectralBandReplication *sbr, |
|
| 914 |
+ GetBitContext *gb, int id_aac) |
|
| 915 |
+{
|
|
| 916 |
+ unsigned int cnt = get_bits_count(gb); |
|
| 917 |
+ |
|
| 918 |
+ if (id_aac == TYPE_SCE || id_aac == TYPE_CCE) {
|
|
| 919 |
+ read_sbr_single_channel_element(ac, sbr, gb); |
|
| 920 |
+ } else if (id_aac == TYPE_CPE) {
|
|
| 921 |
+ read_sbr_channel_pair_element(ac, sbr, gb); |
|
| 922 |
+ } else {
|
|
| 923 |
+ av_log(ac->avccontext, AV_LOG_ERROR, |
|
| 924 |
+ "Invalid bitstream - cannot apply SBR to element type %d\n", id_aac); |
|
| 925 |
+ sbr->start = 0; |
|
| 926 |
+ return get_bits_count(gb) - cnt; |
|
| 927 |
+ } |
|
| 928 |
+ if (get_bits1(gb)) { // bs_extended_data
|
|
| 929 |
+ int num_bits_left = get_bits(gb, 4); // bs_extension_size |
|
| 930 |
+ if (num_bits_left == 15) |
|
| 931 |
+ num_bits_left += get_bits(gb, 8); // bs_esc_count |
|
| 932 |
+ |
|
| 933 |
+ num_bits_left <<= 3; |
|
| 934 |
+ while (num_bits_left > 7) {
|
|
| 935 |
+ num_bits_left -= 2; |
|
| 936 |
+ read_sbr_extension(ac, sbr, gb, get_bits(gb, 2), &num_bits_left); // bs_extension_id |
|
| 937 |
+ } |
|
| 938 |
+ } |
|
| 939 |
+ |
|
| 940 |
+ return get_bits_count(gb) - cnt; |
|
| 941 |
+} |
|
| 942 |
+ |
|
| 943 |
+static void sbr_reset(AACContext *ac, SpectralBandReplication *sbr) |
|
| 944 |
+{
|
|
| 945 |
+ int err; |
|
| 946 |
+ err = sbr_make_f_master(ac, sbr, &sbr->spectrum_params); |
|
| 947 |
+ if (err >= 0) |
|
| 948 |
+ err = sbr_make_f_derived(ac, sbr); |
|
| 949 |
+ if (err < 0) {
|
|
| 950 |
+ av_log(ac->avccontext, AV_LOG_ERROR, |
|
| 951 |
+ "SBR reset failed. Switching SBR to pure upsampling mode.\n"); |
|
| 952 |
+ sbr->start = 0; |
|
| 953 |
+ } |
|
| 954 |
+} |
|
| 955 |
+ |
|
| 956 |
+/** |
|
| 957 |
+ * Decode Spectral Band Replication extension data; reference: table 4.55. |
|
| 958 |
+ * |
|
| 959 |
+ * @param crc flag indicating the presence of CRC checksum |
|
| 960 |
+ * @param cnt length of TYPE_FIL syntactic element in bytes |
|
| 961 |
+ * |
|
| 962 |
+ * @return Returns number of bytes consumed from the TYPE_FIL element. |
|
| 963 |
+ */ |
|
| 964 |
+int ff_decode_sbr_extension(AACContext *ac, SpectralBandReplication *sbr, |
|
| 965 |
+ GetBitContext *gb_host, int crc, int cnt, int id_aac) |
|
| 966 |
+{
|
|
| 967 |
+ unsigned int num_sbr_bits = 0, num_align_bits; |
|
| 968 |
+ unsigned bytes_read; |
|
| 969 |
+ GetBitContext gbc = *gb_host, *gb = &gbc; |
|
| 970 |
+ skip_bits_long(gb_host, cnt*8 - 4); |
|
| 971 |
+ |
|
| 972 |
+ sbr->reset = 0; |
|
| 973 |
+ |
|
| 974 |
+ if (!sbr->sample_rate) |
|
| 975 |
+ sbr->sample_rate = 2 * ac->m4ac.sample_rate; //TODO use the nominal sample rate for arbitrary sample rate support |
|
| 976 |
+ if (!ac->m4ac.ext_sample_rate) |
|
| 977 |
+ ac->m4ac.ext_sample_rate = 2 * ac->m4ac.sample_rate; |
|
| 978 |
+ |
|
| 979 |
+ if (crc) {
|
|
| 980 |
+ skip_bits(gb, 10); // bs_sbr_crc_bits; TODO - implement CRC check |
|
| 981 |
+ num_sbr_bits += 10; |
|
| 982 |
+ } |
|
| 983 |
+ |
|
| 984 |
+ //Save some state from the previous frame. |
|
| 985 |
+ sbr->kx[0] = sbr->kx[1]; |
|
| 986 |
+ sbr->m[0] = sbr->m[1]; |
|
| 987 |
+ |
|
| 988 |
+ num_sbr_bits++; |
|
| 989 |
+ if (get_bits1(gb)) // bs_header_flag |
|
| 990 |
+ num_sbr_bits += read_sbr_header(sbr, gb); |
|
| 991 |
+ |
|
| 992 |
+ if (sbr->reset) |
|
| 993 |
+ sbr_reset(ac, sbr); |
|
| 994 |
+ |
|
| 995 |
+ if (sbr->start) |
|
| 996 |
+ num_sbr_bits += read_sbr_data(ac, sbr, gb, id_aac); |
|
| 997 |
+ |
|
| 998 |
+ num_align_bits = ((cnt << 3) - 4 - num_sbr_bits) & 7; |
|
| 999 |
+ bytes_read = ((num_sbr_bits + num_align_bits + 4) >> 3); |
|
| 1000 |
+ |
|
| 1001 |
+ if (bytes_read > cnt) {
|
|
| 1002 |
+ av_log(ac->avccontext, AV_LOG_ERROR, |
|
| 1003 |
+ "Expected to read %d SBR bytes actually read %d.\n", cnt, bytes_read); |
|
| 1004 |
+ } |
|
| 1005 |
+ return cnt; |
|
| 1006 |
+} |
|
| 1007 |
+ |
|
| 1008 |
+/// Time/frequency Grid (14496-3 sp04 p200) |
|
| 1009 |
+static int sbr_time_freq_grid(AACContext *ac, SpectralBandReplication *sbr, |
|
| 1010 |
+ SBRData *ch_data, int ch) |
|
| 1011 |
+{
|
|
| 1012 |
+ int abs_bord_lead = ch_data->bs_frame_class >= 2 ? ch_data->bs_var_bord[0] : 0; |
|
| 1013 |
+ // frameLengthFlag ? 15 : 16; 960 sample length frames unsupported; this value is numTimeSlots |
|
| 1014 |
+ int abs_bord_trail = (ch_data->bs_frame_class & 1 ? ch_data->bs_var_bord[1] : 0) + 16; |
|
| 1015 |
+ int n_rel_lead; |
|
| 1016 |
+ int i; |
|
| 1017 |
+ |
|
| 1018 |
+ if (ch_data->bs_frame_class == FIXFIX) {
|
|
| 1019 |
+ n_rel_lead = ch_data->bs_num_env[1] - 1; |
|
| 1020 |
+ } else if (ch_data->bs_frame_class == FIXVAR) {
|
|
| 1021 |
+ n_rel_lead = 0; |
|
| 1022 |
+ } else if (ch_data->bs_frame_class < 4) { // VARFIX or VARVAR
|
|
| 1023 |
+ n_rel_lead = ch_data->bs_num_rel[0]; |
|
| 1024 |
+ } else {
|
|
| 1025 |
+ av_log(ac->avccontext, AV_LOG_ERROR, |
|
| 1026 |
+ "Invalid bs_frame_class for SBR: %d\n", ch_data->bs_frame_class); |
|
| 1027 |
+ return -1; |
|
| 1028 |
+ } |
|
| 1029 |
+ |
|
| 1030 |
+ ch_data->t_env_num_env_old = ch_data->t_env[ch_data->bs_num_env[0]]; |
|
| 1031 |
+ ch_data->t_env[0] = abs_bord_lead; |
|
| 1032 |
+ ch_data->t_env[ch_data->bs_num_env[1]] = abs_bord_trail; |
|
| 1033 |
+ |
|
| 1034 |
+ if (ch_data->bs_frame_class == FIXFIX) {
|
|
| 1035 |
+ int temp = (abs_bord_trail + (ch_data->bs_num_env[1] >> 1)) / |
|
| 1036 |
+ ch_data->bs_num_env[1]; |
|
| 1037 |
+ for (i = 0; i < n_rel_lead; i++) |
|
| 1038 |
+ ch_data->t_env[i + 1] = ch_data->t_env[i] + temp; |
|
| 1039 |
+ } else if (ch_data->bs_frame_class > 1) { // VARFIX or VARVAR
|
|
| 1040 |
+ for (i = 0; i < n_rel_lead; i++) |
|
| 1041 |
+ ch_data->t_env[i + 1] = ch_data->t_env[i] + ch_data->bs_rel_bord[0][i]; |
|
| 1042 |
+ } else { // FIXVAR
|
|
| 1043 |
+ for (i = 0; i < n_rel_lead; i++) |
|
| 1044 |
+ ch_data->t_env[i + 1] = abs_bord_lead; |
|
| 1045 |
+ } |
|
| 1046 |
+ |
|
| 1047 |
+ if (ch_data->bs_frame_class & 1) { // FIXVAR or VARVAR
|
|
| 1048 |
+ for (i = ch_data->bs_num_env[1] - 1; i > n_rel_lead; i--) |
|
| 1049 |
+ ch_data->t_env[i] = ch_data->t_env[i + 1] - |
|
| 1050 |
+ ch_data->bs_rel_bord[1][ch_data->bs_num_env[1] - 1 - i]; |
|
| 1051 |
+ } else { // FIXFIX or VARFIX
|
|
| 1052 |
+ for (i = n_rel_lead; i < ch_data->bs_num_env[1]; i++) |
|
| 1053 |
+ ch_data->t_env[i + 1] = abs_bord_trail; |
|
| 1054 |
+ } |
|
| 1055 |
+ |
|
| 1056 |
+ ch_data->t_q[0] = ch_data->t_env[0]; |
|
| 1057 |
+ if (ch_data->bs_num_noise > 1) { // typo in spec bases this on bs_num_env...
|
|
| 1058 |
+ unsigned int idx; |
|
| 1059 |
+ if (ch_data->bs_frame_class == FIXFIX) {
|
|
| 1060 |
+ idx = ch_data->bs_num_env[1] >> 1; |
|
| 1061 |
+ } else if (ch_data->bs_frame_class & 1) { // FIXVAR or VARVAR
|
|
| 1062 |
+ idx = ch_data->bs_num_env[1] - FFMAX(ch_data->bs_pointer - 1, 1); |
|
| 1063 |
+ } else { // VARFIX
|
|
| 1064 |
+ if (!ch_data->bs_pointer) |
|
| 1065 |
+ idx = 1; |
|
| 1066 |
+ else if (ch_data->bs_pointer == 1) |
|
| 1067 |
+ idx = ch_data->bs_num_env[1] - 1; |
|
| 1068 |
+ else // bs_pointer > 1 |
|
| 1069 |
+ idx = ch_data->bs_pointer - 1; |
|
| 1070 |
+ } |
|
| 1071 |
+ ch_data->t_q[1] = ch_data->t_env[idx]; |
|
| 1072 |
+ ch_data->t_q[2] = ch_data->t_env[ch_data->bs_num_env[1]]; |
|
| 1073 |
+ } else |
|
| 1074 |
+ ch_data->t_q[1] = ch_data->t_env[ch_data->bs_num_env[1]]; |
|
| 1075 |
+ |
|
| 1076 |
+ return 0; |
|
| 1077 |
+} |
|
| 1078 |
+ |
|
| 1079 |
+/// Dequantization and stereo decoding (14496-3 sp04 p203) |
|
| 1080 |
+static void sbr_dequant(SpectralBandReplication *sbr, int id_aac) |
|
| 1081 |
+{
|
|
| 1082 |
+ int k, e; |
|
| 1083 |
+ int ch; |
|
| 1084 |
+ |
|
| 1085 |
+ if (id_aac == TYPE_CPE && sbr->bs_coupling) {
|
|
| 1086 |
+ float alpha = sbr->data[0].bs_amp_res ? 1.0f : 0.5f; |
|
| 1087 |
+ float pan_offset = sbr->data[0].bs_amp_res ? 12.0f : 24.0f; |
|
| 1088 |
+ for (e = 1; e <= sbr->data[0].bs_num_env[1]; e++) {
|
|
| 1089 |
+ for (k = 0; k < sbr->n[sbr->data[0].bs_freq_res[e]]; k++) {
|
|
| 1090 |
+ float temp1 = exp2f(sbr->data[0].env_facs[e][k] * alpha + 7.0f); |
|
| 1091 |
+ float temp2 = exp2f((pan_offset - sbr->data[1].env_facs[e][k]) * alpha); |
|
| 1092 |
+ float fac = temp1 / (1.0f + temp2); |
|
| 1093 |
+ sbr->data[0].env_facs[e][k] = fac; |
|
| 1094 |
+ sbr->data[1].env_facs[e][k] = fac * temp2; |
|
| 1095 |
+ } |
|
| 1096 |
+ } |
|
| 1097 |
+ for (e = 1; e <= sbr->data[0].bs_num_noise; e++) {
|
|
| 1098 |
+ for (k = 0; k < sbr->n_q; k++) {
|
|
| 1099 |
+ float temp1 = exp2f(NOISE_FLOOR_OFFSET - sbr->data[0].noise_facs[e][k] + 1); |
|
| 1100 |
+ float temp2 = exp2f(12 - sbr->data[1].noise_facs[e][k]); |
|
| 1101 |
+ float fac = temp1 / (1.0f + temp2); |
|
| 1102 |
+ sbr->data[0].noise_facs[e][k] = fac; |
|
| 1103 |
+ sbr->data[1].noise_facs[e][k] = fac * temp2; |
|
| 1104 |
+ } |
|
| 1105 |
+ } |
|
| 1106 |
+ } else { // SCE or one non-coupled CPE
|
|
| 1107 |
+ for (ch = 0; ch < (id_aac == TYPE_CPE) + 1; ch++) {
|
|
| 1108 |
+ float alpha = sbr->data[ch].bs_amp_res ? 1.0f : 0.5f; |
|
| 1109 |
+ for (e = 1; e <= sbr->data[ch].bs_num_env[1]; e++) |
|
| 1110 |
+ for (k = 0; k < sbr->n[sbr->data[ch].bs_freq_res[e]]; k++) |
|
| 1111 |
+ sbr->data[ch].env_facs[e][k] = |
|
| 1112 |
+ exp2f(alpha * sbr->data[ch].env_facs[e][k] + 6.0f); |
|
| 1113 |
+ for (e = 1; e <= sbr->data[ch].bs_num_noise; e++) |
|
| 1114 |
+ for (k = 0; k < sbr->n_q; k++) |
|
| 1115 |
+ sbr->data[ch].noise_facs[e][k] = |
|
| 1116 |
+ exp2f(NOISE_FLOOR_OFFSET - sbr->data[ch].noise_facs[e][k]); |
|
| 1117 |
+ } |
|
| 1118 |
+ } |
|
| 1119 |
+} |
|
| 1120 |
+ |
|
| 1121 |
+/** |
|
| 1122 |
+ * Analysis QMF Bank (14496-3 sp04 p206) |
|
| 1123 |
+ * |
|
| 1124 |
+ * @param x pointer to the beginning of the first sample window |
|
| 1125 |
+ * @param W array of complex-valued samples split into subbands |
|
| 1126 |
+ */ |
|
| 1127 |
+static void sbr_qmf_analysis(DSPContext *dsp, RDFTContext *rdft, const float *in, float *x, |
|
| 1128 |
+ float z[320], float W[2][32][32][2], |
|
| 1129 |
+ float bias, float scale) |
|
| 1130 |
+{
|
|
| 1131 |
+ int i, k; |
|
| 1132 |
+ memcpy(W[0], W[1], sizeof(W[0])); |
|
| 1133 |
+ memcpy(x , x+1024, (320-32)*sizeof(x[0])); |
|
| 1134 |
+ if (scale != 1.0f || bias != 0.0f) |
|
| 1135 |
+ for (i = 0; i < 1024; i++) |
|
| 1136 |
+ x[288 + i] = (in[i] - bias) * scale; |
|
| 1137 |
+ else |
|
| 1138 |
+ memcpy(x+288, in, 1024*sizeof(*x)); |
|
| 1139 |
+ for (i = 0; i < 32; i++) { // numTimeSlots*RATE = 16*2 as 960 sample frames
|
|
| 1140 |
+ // are not supported |
|
| 1141 |
+ float re, im; |
|
| 1142 |
+ dsp->vector_fmul_reverse(z, sbr_qmf_window_ds, x, 320); |
|
| 1143 |
+ for (k = 0; k < 64; k++) {
|
|
| 1144 |
+ float f = z[k] + z[k + 64] + z[k + 128] + z[k + 192] + z[k + 256]; |
|
| 1145 |
+ z[k] = f * analysis_cos_pre[k]; |
|
| 1146 |
+ z[k+64] = f; |
|
| 1147 |
+ } |
|
| 1148 |
+ ff_rdft_calc(rdft, z); |
|
| 1149 |
+ re = z[0] * 0.5f; |
|
| 1150 |
+ im = 0.5f * dsp->scalarproduct_float(z+64, analysis_sin_pre, 64); |
|
| 1151 |
+ W[1][i][0][0] = re * analysis_cossin_post[0][0] - im * analysis_cossin_post[0][1]; |
|
| 1152 |
+ W[1][i][0][1] = re * analysis_cossin_post[0][1] + im * analysis_cossin_post[0][0]; |
|
| 1153 |
+ for (k = 1; k < 32; k++) {
|
|
| 1154 |
+ re = z[2*k ] - re; |
|
| 1155 |
+ im = z[2*k+1] - im; |
|
| 1156 |
+ W[1][i][k][0] = re * analysis_cossin_post[k][0] - im * analysis_cossin_post[k][1]; |
|
| 1157 |
+ W[1][i][k][1] = re * analysis_cossin_post[k][1] + im * analysis_cossin_post[k][0]; |
|
| 1158 |
+ } |
|
| 1159 |
+ x += 32; |
|
| 1160 |
+ } |
|
| 1161 |
+} |
|
| 1162 |
+ |
|
| 1163 |
+/** |
|
| 1164 |
+ * Synthesis QMF Bank (14496-3 sp04 p206) and Downsampled Synthesis QMF Bank |
|
| 1165 |
+ * (14496-3 sp04 p206) |
|
| 1166 |
+ */ |
|
| 1167 |
+static void sbr_qmf_synthesis(DSPContext *dsp, FFTContext *mdct, |
|
| 1168 |
+ float *out, float X[2][32][64], |
|
| 1169 |
+ float mdct_buf[2][64], |
|
| 1170 |
+ float *v0, int *v_off, const unsigned int div, |
|
| 1171 |
+ float bias, float scale) |
|
| 1172 |
+{
|
|
| 1173 |
+ int i, n; |
|
| 1174 |
+ const float *sbr_qmf_window = div ? sbr_qmf_window_ds : sbr_qmf_window_us; |
|
| 1175 |
+ int scale_and_bias = scale != 1.0f || bias != 0.0f; |
|
| 1176 |
+ float *v; |
|
| 1177 |
+ for (i = 0; i < 32; i++) {
|
|
| 1178 |
+ if (*v_off == 0) {
|
|
| 1179 |
+ int saved_samples = (1280 - 128) >> div; |
|
| 1180 |
+ memcpy(&v0[SBR_SYNTHESIS_BUF_SIZE - saved_samples], v0, saved_samples * sizeof(float)); |
|
| 1181 |
+ *v_off = SBR_SYNTHESIS_BUF_SIZE - saved_samples - (128 >> div); |
|
| 1182 |
+ } else {
|
|
| 1183 |
+ *v_off -= 128 >> div; |
|
| 1184 |
+ } |
|
| 1185 |
+ v = v0 + *v_off; |
|
| 1186 |
+ for (n = 1; n < 64 >> div; n+=2) {
|
|
| 1187 |
+ X[1][i][n] = -X[1][i][n]; |
|
| 1188 |
+ } |
|
| 1189 |
+ if (div) {
|
|
| 1190 |
+ memset(X[0][i]+32, 0, 32*sizeof(float)); |
|
| 1191 |
+ memset(X[1][i]+32, 0, 32*sizeof(float)); |
|
| 1192 |
+ } |
|
| 1193 |
+ ff_imdct_half(mdct, mdct_buf[0], X[0][i]); |
|
| 1194 |
+ ff_imdct_half(mdct, mdct_buf[1], X[1][i]); |
|
| 1195 |
+ if (div) {
|
|
| 1196 |
+ for (n = 0; n < 32; n++) {
|
|
| 1197 |
+ v[ n] = -mdct_buf[0][63 - 2*n] + mdct_buf[1][2*n ]; |
|
| 1198 |
+ v[ 63 - n] = mdct_buf[0][62 - 2*n] + mdct_buf[1][2*n + 1]; |
|
| 1199 |
+ } |
|
| 1200 |
+ } else {
|
|
| 1201 |
+ for (n = 0; n < 64; n++) {
|
|
| 1202 |
+ v[ n] = -mdct_buf[0][63 - n] + mdct_buf[1][ n ]; |
|
| 1203 |
+ v[127 - n] = mdct_buf[0][63 - n] + mdct_buf[1][ n ]; |
|
| 1204 |
+ } |
|
| 1205 |
+ } |
|
| 1206 |
+ dsp->vector_fmul_add(out, v , sbr_qmf_window , zero64, 64 >> div); |
|
| 1207 |
+ dsp->vector_fmul_add(out, v + ( 192 >> div), sbr_qmf_window + ( 64 >> div), out , 64 >> div); |
|
| 1208 |
+ dsp->vector_fmul_add(out, v + ( 256 >> div), sbr_qmf_window + (128 >> div), out , 64 >> div); |
|
| 1209 |
+ dsp->vector_fmul_add(out, v + ( 448 >> div), sbr_qmf_window + (192 >> div), out , 64 >> div); |
|
| 1210 |
+ dsp->vector_fmul_add(out, v + ( 512 >> div), sbr_qmf_window + (256 >> div), out , 64 >> div); |
|
| 1211 |
+ dsp->vector_fmul_add(out, v + ( 704 >> div), sbr_qmf_window + (320 >> div), out , 64 >> div); |
|
| 1212 |
+ dsp->vector_fmul_add(out, v + ( 768 >> div), sbr_qmf_window + (384 >> div), out , 64 >> div); |
|
| 1213 |
+ dsp->vector_fmul_add(out, v + ( 960 >> div), sbr_qmf_window + (448 >> div), out , 64 >> div); |
|
| 1214 |
+ dsp->vector_fmul_add(out, v + (1024 >> div), sbr_qmf_window + (512 >> div), out , 64 >> div); |
|
| 1215 |
+ dsp->vector_fmul_add(out, v + (1216 >> div), sbr_qmf_window + (576 >> div), out , 64 >> div); |
|
| 1216 |
+ if (scale_and_bias) |
|
| 1217 |
+ for (n = 0; n < 64 >> div; n++) |
|
| 1218 |
+ out[n] = out[n] * scale + bias; |
|
| 1219 |
+ out += 64 >> div; |
|
| 1220 |
+ } |
|
| 1221 |
+} |
|
| 1222 |
+ |
|
| 1223 |
+static void autocorrelate(const float x[40][2], float phi[3][2][2], int lag) |
|
| 1224 |
+{
|
|
| 1225 |
+ int i; |
|
| 1226 |
+ float real_sum = 0.0f; |
|
| 1227 |
+ float imag_sum = 0.0f; |
|
| 1228 |
+ if (lag) {
|
|
| 1229 |
+ for (i = 1; i < 38; i++) {
|
|
| 1230 |
+ real_sum += x[i][0] * x[i+lag][0] + x[i][1] * x[i+lag][1]; |
|
| 1231 |
+ imag_sum += x[i][0] * x[i+lag][1] - x[i][1] * x[i+lag][0]; |
|
| 1232 |
+ } |
|
| 1233 |
+ phi[2-lag][1][0] = real_sum + x[ 0][0] * x[lag][0] + x[ 0][1] * x[lag][1]; |
|
| 1234 |
+ phi[2-lag][1][1] = imag_sum + x[ 0][0] * x[lag][1] - x[ 0][1] * x[lag][0]; |
|
| 1235 |
+ if (lag == 1) {
|
|
| 1236 |
+ phi[0][0][0] = real_sum + x[38][0] * x[39][0] + x[38][1] * x[39][1]; |
|
| 1237 |
+ phi[0][0][1] = imag_sum + x[38][0] * x[39][1] - x[38][1] * x[39][0]; |
|
| 1238 |
+ } |
|
| 1239 |
+ } else {
|
|
| 1240 |
+ for (i = 1; i < 38; i++) {
|
|
| 1241 |
+ real_sum += x[i][0] * x[i][0] + x[i][1] * x[i][1]; |
|
| 1242 |
+ } |
|
| 1243 |
+ phi[2][1][0] = real_sum + x[ 0][0] * x[ 0][0] + x[ 0][1] * x[ 0][1]; |
|
| 1244 |
+ phi[1][0][0] = real_sum + x[38][0] * x[38][0] + x[38][1] * x[38][1]; |
|
| 1245 |
+ } |
|
| 1246 |
+} |
|
| 1247 |
+ |
|
| 1248 |
+/** High Frequency Generation (14496-3 sp04 p214+) and Inverse Filtering |
|
| 1249 |
+ * (14496-3 sp04 p214) |
|
| 1250 |
+ * Warning: This routine does not seem numerically stable. |
|
| 1251 |
+ */ |
|
| 1252 |
+static void sbr_hf_inverse_filter(float (*alpha0)[2], float (*alpha1)[2], |
|
| 1253 |
+ const float X_low[32][40][2], int k0) |
|
| 1254 |
+{
|
|
| 1255 |
+ int k; |
|
| 1256 |
+ for (k = 0; k < k0; k++) {
|
|
| 1257 |
+ float phi[3][2][2], dk; |
|
| 1258 |
+ |
|
| 1259 |
+ autocorrelate(X_low[k], phi, 0); |
|
| 1260 |
+ autocorrelate(X_low[k], phi, 1); |
|
| 1261 |
+ autocorrelate(X_low[k], phi, 2); |
|
| 1262 |
+ |
|
| 1263 |
+ dk = phi[2][1][0] * phi[1][0][0] - |
|
| 1264 |
+ (phi[1][1][0] * phi[1][1][0] + phi[1][1][1] * phi[1][1][1]) / 1.000001f; |
|
| 1265 |
+ |
|
| 1266 |
+ if (!dk) {
|
|
| 1267 |
+ alpha1[k][0] = 0; |
|
| 1268 |
+ alpha1[k][1] = 0; |
|
| 1269 |
+ } else {
|
|
| 1270 |
+ float temp_real, temp_im; |
|
| 1271 |
+ temp_real = phi[0][0][0] * phi[1][1][0] - |
|
| 1272 |
+ phi[0][0][1] * phi[1][1][1] - |
|
| 1273 |
+ phi[0][1][0] * phi[1][0][0]; |
|
| 1274 |
+ temp_im = phi[0][0][0] * phi[1][1][1] + |
|
| 1275 |
+ phi[0][0][1] * phi[1][1][0] - |
|
| 1276 |
+ phi[0][1][1] * phi[1][0][0]; |
|
| 1277 |
+ |
|
| 1278 |
+ alpha1[k][0] = temp_real / dk; |
|
| 1279 |
+ alpha1[k][1] = temp_im / dk; |
|
| 1280 |
+ } |
|
| 1281 |
+ |
|
| 1282 |
+ if (!phi[1][0][0]) {
|
|
| 1283 |
+ alpha0[k][0] = 0; |
|
| 1284 |
+ alpha0[k][1] = 0; |
|
| 1285 |
+ } else {
|
|
| 1286 |
+ float temp_real, temp_im; |
|
| 1287 |
+ temp_real = phi[0][0][0] + alpha1[k][0] * phi[1][1][0] + |
|
| 1288 |
+ alpha1[k][1] * phi[1][1][1]; |
|
| 1289 |
+ temp_im = phi[0][0][1] + alpha1[k][1] * phi[1][1][0] - |
|
| 1290 |
+ alpha1[k][0] * phi[1][1][1]; |
|
| 1291 |
+ |
|
| 1292 |
+ alpha0[k][0] = -temp_real / phi[1][0][0]; |
|
| 1293 |
+ alpha0[k][1] = -temp_im / phi[1][0][0]; |
|
| 1294 |
+ } |
|
| 1295 |
+ |
|
| 1296 |
+ if (alpha1[k][0] * alpha1[k][0] + alpha1[k][1] * alpha1[k][1] >= 16.0f || |
|
| 1297 |
+ alpha0[k][0] * alpha0[k][0] + alpha0[k][1] * alpha0[k][1] >= 16.0f) {
|
|
| 1298 |
+ alpha1[k][0] = 0; |
|
| 1299 |
+ alpha1[k][1] = 0; |
|
| 1300 |
+ alpha0[k][0] = 0; |
|
| 1301 |
+ alpha0[k][1] = 0; |
|
| 1302 |
+ } |
|
| 1303 |
+ } |
|
| 1304 |
+} |
|
| 1305 |
+ |
|
| 1306 |
+/// Chirp Factors (14496-3 sp04 p214) |
|
| 1307 |
+static void sbr_chirp(SpectralBandReplication *sbr, SBRData *ch_data) |
|
| 1308 |
+{
|
|
| 1309 |
+ int i; |
|
| 1310 |
+ float new_bw; |
|
| 1311 |
+ static const float bw_tab[] = { 0.0f, 0.75f, 0.9f, 0.98f };
|
|
| 1312 |
+ |
|
| 1313 |
+ for (i = 0; i < sbr->n_q; i++) {
|
|
| 1314 |
+ if (ch_data->bs_invf_mode[0][i] + ch_data->bs_invf_mode[1][i] == 1) {
|
|
| 1315 |
+ new_bw = 0.6f; |
|
| 1316 |
+ } else |
|
| 1317 |
+ new_bw = bw_tab[ch_data->bs_invf_mode[0][i]]; |
|
| 1318 |
+ |
|
| 1319 |
+ if (new_bw < ch_data->bw_array[i]) {
|
|
| 1320 |
+ new_bw = 0.75f * new_bw + 0.25f * ch_data->bw_array[i]; |
|
| 1321 |
+ } else |
|
| 1322 |
+ new_bw = 0.90625f * new_bw + 0.09375f * ch_data->bw_array[i]; |
|
| 1323 |
+ ch_data->bw_array[i] = new_bw < 0.015625f ? 0.0f : new_bw; |
|
| 1324 |
+ } |
|
| 1325 |
+} |
|
| 1326 |
+ |
|
| 1327 |
+/// Generate the subband filtered lowband |
|
| 1328 |
+static int sbr_lf_gen(AACContext *ac, SpectralBandReplication *sbr, |
|
| 1329 |
+ float X_low[32][40][2], const float W[2][32][32][2]) |
|
| 1330 |
+{
|
|
| 1331 |
+ int i, k; |
|
| 1332 |
+ const int t_HFGen = 8; |
|
| 1333 |
+ const int i_f = 32; |
|
| 1334 |
+ memset(X_low, 0, 32*sizeof(*X_low)); |
|
| 1335 |
+ for (k = 0; k < sbr->kx[1]; k++) {
|
|
| 1336 |
+ for (i = t_HFGen; i < i_f + t_HFGen; i++) {
|
|
| 1337 |
+ X_low[k][i][0] = W[1][i - t_HFGen][k][0]; |
|
| 1338 |
+ X_low[k][i][1] = W[1][i - t_HFGen][k][1]; |
|
| 1339 |
+ } |
|
| 1340 |
+ } |
|
| 1341 |
+ for (k = 0; k < sbr->kx[0]; k++) {
|
|
| 1342 |
+ for (i = 0; i < t_HFGen; i++) {
|
|
| 1343 |
+ X_low[k][i][0] = W[0][i + i_f - t_HFGen][k][0]; |
|
| 1344 |
+ X_low[k][i][1] = W[0][i + i_f - t_HFGen][k][1]; |
|
| 1345 |
+ } |
|
| 1346 |
+ } |
|
| 1347 |
+ return 0; |
|
| 1348 |
+} |
|
| 1349 |
+ |
|
| 1350 |
+/// High Frequency Generator (14496-3 sp04 p215) |
|
| 1351 |
+static int sbr_hf_gen(AACContext *ac, SpectralBandReplication *sbr, |
|
| 1352 |
+ float X_high[64][40][2], const float X_low[32][40][2], |
|
| 1353 |
+ const float (*alpha0)[2], const float (*alpha1)[2], |
|
| 1354 |
+ const float bw_array[5], const uint8_t *t_env, |
|
| 1355 |
+ int bs_num_env) |
|
| 1356 |
+{
|
|
| 1357 |
+ int i, j, x; |
|
| 1358 |
+ int g = 0; |
|
| 1359 |
+ int k = sbr->kx[1]; |
|
| 1360 |
+ for (j = 0; j < sbr->num_patches; j++) {
|
|
| 1361 |
+ for (x = 0; x < sbr->patch_num_subbands[j]; x++, k++) {
|
|
| 1362 |
+ float alpha[4]; |
|
| 1363 |
+ const int p = sbr->patch_start_subband[j] + x; |
|
| 1364 |
+ while (g <= sbr->n_q && k >= sbr->f_tablenoise[g]) |
|
| 1365 |
+ g++; |
|
| 1366 |
+ g--; |
|
| 1367 |
+ |
|
| 1368 |
+ if (g < 0) {
|
|
| 1369 |
+ av_log(ac->avccontext, AV_LOG_ERROR, |
|
| 1370 |
+ "ERROR : no subband found for frequency %d\n", k); |
|
| 1371 |
+ return -1; |
|
| 1372 |
+ } |
|
| 1373 |
+ |
|
| 1374 |
+ alpha[0] = alpha1[p][0] * bw_array[g] * bw_array[g]; |
|
| 1375 |
+ alpha[1] = alpha1[p][1] * bw_array[g] * bw_array[g]; |
|
| 1376 |
+ alpha[2] = alpha0[p][0] * bw_array[g]; |
|
| 1377 |
+ alpha[3] = alpha0[p][1] * bw_array[g]; |
|
| 1378 |
+ |
|
| 1379 |
+ for (i = 2 * t_env[0]; i < 2 * t_env[bs_num_env]; i++) {
|
|
| 1380 |
+ const int idx = i + ENVELOPE_ADJUSTMENT_OFFSET; |
|
| 1381 |
+ X_high[k][idx][0] = |
|
| 1382 |
+ X_low[p][idx - 2][0] * alpha[0] - |
|
| 1383 |
+ X_low[p][idx - 2][1] * alpha[1] + |
|
| 1384 |
+ X_low[p][idx - 1][0] * alpha[2] - |
|
| 1385 |
+ X_low[p][idx - 1][1] * alpha[3] + |
|
| 1386 |
+ X_low[p][idx][0]; |
|
| 1387 |
+ X_high[k][idx][1] = |
|
| 1388 |
+ X_low[p][idx - 2][1] * alpha[0] + |
|
| 1389 |
+ X_low[p][idx - 2][0] * alpha[1] + |
|
| 1390 |
+ X_low[p][idx - 1][1] * alpha[2] + |
|
| 1391 |
+ X_low[p][idx - 1][0] * alpha[3] + |
|
| 1392 |
+ X_low[p][idx][1]; |
|
| 1393 |
+ } |
|
| 1394 |
+ } |
|
| 1395 |
+ } |
|
| 1396 |
+ if (k < sbr->m[1] + sbr->kx[1]) |
|
| 1397 |
+ memset(X_high + k, 0, (sbr->m[1] + sbr->kx[1] - k) * sizeof(*X_high)); |
|
| 1398 |
+ |
|
| 1399 |
+ return 0; |
|
| 1400 |
+} |
|
| 1401 |
+ |
|
| 1402 |
+/// Generate the subband filtered lowband |
|
| 1403 |
+static int sbr_x_gen(SpectralBandReplication *sbr, float X[2][32][64], |
|
| 1404 |
+ const float X_low[32][40][2], const float Y[2][38][64][2], |
|
| 1405 |
+ int ch) |
|
| 1406 |
+{
|
|
| 1407 |
+ int k, i; |
|
| 1408 |
+ const int i_f = 32; |
|
| 1409 |
+ const int i_Temp = FFMAX(2*sbr->data[ch].t_env_num_env_old - i_f, 0); |
|
| 1410 |
+ memset(X, 0, 2*sizeof(*X)); |
|
| 1411 |
+ for (k = 0; k < sbr->kx[0]; k++) {
|
|
| 1412 |
+ for (i = 0; i < i_Temp; i++) {
|
|
| 1413 |
+ X[0][i][k] = X_low[k][i + ENVELOPE_ADJUSTMENT_OFFSET][0]; |
|
| 1414 |
+ X[1][i][k] = X_low[k][i + ENVELOPE_ADJUSTMENT_OFFSET][1]; |
|
| 1415 |
+ } |
|
| 1416 |
+ } |
|
| 1417 |
+ for (; k < sbr->kx[0] + sbr->m[0]; k++) {
|
|
| 1418 |
+ for (i = 0; i < i_Temp; i++) {
|
|
| 1419 |
+ X[0][i][k] = Y[0][i + i_f][k][0]; |
|
| 1420 |
+ X[1][i][k] = Y[0][i + i_f][k][1]; |
|
| 1421 |
+ } |
|
| 1422 |
+ } |
|
| 1423 |
+ |
|
| 1424 |
+ for (k = 0; k < sbr->kx[1]; k++) {
|
|
| 1425 |
+ for (i = i_Temp; i < i_f; i++) {
|
|
| 1426 |
+ X[0][i][k] = X_low[k][i + ENVELOPE_ADJUSTMENT_OFFSET][0]; |
|
| 1427 |
+ X[1][i][k] = X_low[k][i + ENVELOPE_ADJUSTMENT_OFFSET][1]; |
|
| 1428 |
+ } |
|
| 1429 |
+ } |
|
| 1430 |
+ for (; k < sbr->kx[1] + sbr->m[1]; k++) {
|
|
| 1431 |
+ for (i = i_Temp; i < i_f; i++) {
|
|
| 1432 |
+ X[0][i][k] = Y[1][i][k][0]; |
|
| 1433 |
+ X[1][i][k] = Y[1][i][k][1]; |
|
| 1434 |
+ } |
|
| 1435 |
+ } |
|
| 1436 |
+ return 0; |
|
| 1437 |
+} |
|
| 1438 |
+ |
|
| 1439 |
+/** High Frequency Adjustment (14496-3 sp04 p217) and Mapping |
|
| 1440 |
+ * (14496-3 sp04 p217) |
|
| 1441 |
+ */ |
|
| 1442 |
+static void sbr_mapping(AACContext *ac, SpectralBandReplication *sbr, |
|
| 1443 |
+ SBRData *ch_data, int e_a[2]) |
|
| 1444 |
+{
|
|
| 1445 |
+ int e, i, m; |
|
| 1446 |
+ |
|
| 1447 |
+ e_a[0] = -(e_a[1] != ch_data->bs_num_env[0]); // l_APrev |
|
| 1448 |
+ e_a[1] = -1; |
|
| 1449 |
+ if ((ch_data->bs_frame_class & 1) && ch_data->bs_pointer) { // FIXVAR or VARVAR and bs_pointer != 0
|
|
| 1450 |
+ e_a[1] = ch_data->bs_num_env[1] + 1 - ch_data->bs_pointer; |
|
| 1451 |
+ } else if ((ch_data->bs_frame_class == 2) && (ch_data->bs_pointer > 1)) // VARFIX and bs_pointer > 1 |
|
| 1452 |
+ e_a[1] = ch_data->bs_pointer - 1; |
|
| 1453 |
+ |
|
| 1454 |
+ memset(ch_data->s_indexmapped[1], 0, 7*sizeof(ch_data->s_indexmapped[1])); |
|
| 1455 |
+ for (e = 0; e < ch_data->bs_num_env[1]; e++) {
|
|
| 1456 |
+ const unsigned int ilim = sbr->n[ch_data->bs_freq_res[e + 1]]; |
|
| 1457 |
+ uint16_t *table = ch_data->bs_freq_res[e + 1] ? sbr->f_tablehigh : sbr->f_tablelow; |
|
| 1458 |
+ int k; |
|
| 1459 |
+ |
|
| 1460 |
+ for (i = 0; i < ilim; i++) |
|
| 1461 |
+ for (m = table[i]; m < table[i + 1]; m++) |
|
| 1462 |
+ sbr->e_origmapped[e][m - sbr->kx[1]] = ch_data->env_facs[e+1][i]; |
|
| 1463 |
+ |
|
| 1464 |
+ // ch_data->bs_num_noise > 1 => 2 noise floors |
|
| 1465 |
+ k = (ch_data->bs_num_noise > 1) && (ch_data->t_env[e] >= ch_data->t_q[1]); |
|
| 1466 |
+ for (i = 0; i < sbr->n_q; i++) |
|
| 1467 |
+ for (m = sbr->f_tablenoise[i]; m < sbr->f_tablenoise[i + 1]; m++) |
|
| 1468 |
+ sbr->q_mapped[e][m - sbr->kx[1]] = ch_data->noise_facs[k+1][i]; |
|
| 1469 |
+ |
|
| 1470 |
+ for (i = 0; i < sbr->n[1]; i++) {
|
|
| 1471 |
+ if (ch_data->bs_add_harmonic_flag) {
|
|
| 1472 |
+ const unsigned int m_midpoint = |
|
| 1473 |
+ (sbr->f_tablehigh[i] + sbr->f_tablehigh[i + 1]) >> 1; |
|
| 1474 |
+ |
|
| 1475 |
+ ch_data->s_indexmapped[e + 1][m_midpoint - sbr->kx[1]] = ch_data->bs_add_harmonic[i] * |
|
| 1476 |
+ (e >= e_a[1] || (ch_data->s_indexmapped[0][m_midpoint - sbr->kx[1]] == 1)); |
|
| 1477 |
+ } |
|
| 1478 |
+ } |
|
| 1479 |
+ |
|
| 1480 |
+ for (i = 0; i < ilim; i++) {
|
|
| 1481 |
+ int additional_sinusoid_present = 0; |
|
| 1482 |
+ for (m = table[i]; m < table[i + 1]; m++) {
|
|
| 1483 |
+ if (ch_data->s_indexmapped[e + 1][m - sbr->kx[1]]) {
|
|
| 1484 |
+ additional_sinusoid_present = 1; |
|
| 1485 |
+ break; |
|
| 1486 |
+ } |
|
| 1487 |
+ } |
|
| 1488 |
+ memset(&sbr->s_mapped[e][table[i] - sbr->kx[1]], additional_sinusoid_present, |
|
| 1489 |
+ (table[i + 1] - table[i]) * sizeof(sbr->s_mapped[e][0])); |
|
| 1490 |
+ } |
|
| 1491 |
+ } |
|
| 1492 |
+ |
|
| 1493 |
+ memcpy(ch_data->s_indexmapped[0], ch_data->s_indexmapped[ch_data->bs_num_env[1]], sizeof(ch_data->s_indexmapped[0])); |
|
| 1494 |
+} |
|
| 1495 |
+ |
|
| 1496 |
+/// Estimation of current envelope (14496-3 sp04 p218) |
|
| 1497 |
+static void sbr_env_estimate(float (*e_curr)[48], float X_high[64][40][2], |
|
| 1498 |
+ SpectralBandReplication *sbr, SBRData *ch_data) |
|
| 1499 |
+{
|
|
| 1500 |
+ int e, i, m; |
|
| 1501 |
+ |
|
| 1502 |
+ if (sbr->bs_interpol_freq) {
|
|
| 1503 |
+ for (e = 0; e < ch_data->bs_num_env[1]; e++) {
|
|
| 1504 |
+ const float recip_env_size = 0.5f / (ch_data->t_env[e + 1] - ch_data->t_env[e]); |
|
| 1505 |
+ int ilb = ch_data->t_env[e] * 2 + ENVELOPE_ADJUSTMENT_OFFSET; |
|
| 1506 |
+ int iub = ch_data->t_env[e + 1] * 2 + ENVELOPE_ADJUSTMENT_OFFSET; |
|
| 1507 |
+ |
|
| 1508 |
+ for (m = 0; m < sbr->m[1]; m++) {
|
|
| 1509 |
+ float sum = 0.0f; |
|
| 1510 |
+ |
|
| 1511 |
+ for (i = ilb; i < iub; i++) {
|
|
| 1512 |
+ sum += X_high[m + sbr->kx[1]][i][0] * X_high[m + sbr->kx[1]][i][0] + |
|
| 1513 |
+ X_high[m + sbr->kx[1]][i][1] * X_high[m + sbr->kx[1]][i][1]; |
|
| 1514 |
+ } |
|
| 1515 |
+ e_curr[e][m] = sum * recip_env_size; |
|
| 1516 |
+ } |
|
| 1517 |
+ } |
|
| 1518 |
+ } else {
|
|
| 1519 |
+ int k, p; |
|
| 1520 |
+ |
|
| 1521 |
+ for (e = 0; e < ch_data->bs_num_env[1]; e++) {
|
|
| 1522 |
+ const int env_size = 2 * (ch_data->t_env[e + 1] - ch_data->t_env[e]); |
|
| 1523 |
+ int ilb = ch_data->t_env[e] * 2 + ENVELOPE_ADJUSTMENT_OFFSET; |
|
| 1524 |
+ int iub = ch_data->t_env[e + 1] * 2 + ENVELOPE_ADJUSTMENT_OFFSET; |
|
| 1525 |
+ const uint16_t *table = ch_data->bs_freq_res[e + 1] ? sbr->f_tablehigh : sbr->f_tablelow; |
|
| 1526 |
+ |
|
| 1527 |
+ for (p = 0; p < sbr->n[ch_data->bs_freq_res[e + 1]]; p++) {
|
|
| 1528 |
+ float sum = 0.0f; |
|
| 1529 |
+ const int den = env_size * (table[p + 1] - table[p]); |
|
| 1530 |
+ |
|
| 1531 |
+ for (k = table[p]; k < table[p + 1]; k++) {
|
|
| 1532 |
+ for (i = ilb; i < iub; i++) {
|
|
| 1533 |
+ sum += X_high[k][i][0] * X_high[k][i][0] + |
|
| 1534 |
+ X_high[k][i][1] * X_high[k][i][1]; |
|
| 1535 |
+ } |
|
| 1536 |
+ } |
|
| 1537 |
+ sum /= den; |
|
| 1538 |
+ for (k = table[p]; k < table[p + 1]; k++) {
|
|
| 1539 |
+ e_curr[e][k - sbr->kx[1]] = sum; |
|
| 1540 |
+ } |
|
| 1541 |
+ } |
|
| 1542 |
+ } |
|
| 1543 |
+ } |
|
| 1544 |
+} |
|
| 1545 |
+ |
|
| 1546 |
+/** |
|
| 1547 |
+ * Calculation of levels of additional HF signal components (14496-3 sp04 p219) |
|
| 1548 |
+ * and Calculation of gain (14496-3 sp04 p219) |
|
| 1549 |
+ */ |
|
| 1550 |
+static void sbr_gain_calc(AACContext *ac, SpectralBandReplication *sbr, |
|
| 1551 |
+ SBRData *ch_data, const int e_a[2]) |
|
| 1552 |
+{
|
|
| 1553 |
+ int e, k, m; |
|
| 1554 |
+ // max gain limits : -3dB, 0dB, 3dB, inf dB (limiter off) |
|
| 1555 |
+ static const float limgain[4] = { 0.70795, 1.0, 1.41254, 10000000000 };
|
|
| 1556 |
+ |
|
| 1557 |
+ for (e = 0; e < ch_data->bs_num_env[1]; e++) {
|
|
| 1558 |
+ int delta = !((e == e_a[1]) || (e == e_a[0])); |
|
| 1559 |
+ for (k = 0; k < sbr->n_lim; k++) {
|
|
| 1560 |
+ float gain_boost, gain_max; |
|
| 1561 |
+ float sum[2] = { 0.0f, 0.0f };
|
|
| 1562 |
+ for (m = sbr->f_tablelim[k] - sbr->kx[1]; m < sbr->f_tablelim[k + 1] - sbr->kx[1]; m++) {
|
|
| 1563 |
+ const float temp = sbr->e_origmapped[e][m] / (1.0f + sbr->q_mapped[e][m]); |
|
| 1564 |
+ sbr->q_m[e][m] = sqrtf(temp * sbr->q_mapped[e][m]); |
|
| 1565 |
+ sbr->s_m[e][m] = sqrtf(temp * ch_data->s_indexmapped[e + 1][m]); |
|
| 1566 |
+ if (!sbr->s_mapped[e][m]) {
|
|
| 1567 |
+ sbr->gain[e][m] = sqrtf(sbr->e_origmapped[e][m] / |
|
| 1568 |
+ ((1.0f + sbr->e_curr[e][m]) * |
|
| 1569 |
+ (1.0f + sbr->q_mapped[e][m] * delta))); |
|
| 1570 |
+ } else {
|
|
| 1571 |
+ sbr->gain[e][m] = sqrtf(sbr->e_origmapped[e][m] * sbr->q_mapped[e][m] / |
|
| 1572 |
+ ((1.0f + sbr->e_curr[e][m]) * |
|
| 1573 |
+ (1.0f + sbr->q_mapped[e][m]))); |
|
| 1574 |
+ } |
|
| 1575 |
+ } |
|
| 1576 |
+ for (m = sbr->f_tablelim[k] - sbr->kx[1]; m < sbr->f_tablelim[k + 1] - sbr->kx[1]; m++) {
|
|
| 1577 |
+ sum[0] += sbr->e_origmapped[e][m]; |
|
| 1578 |
+ sum[1] += sbr->e_curr[e][m]; |
|
| 1579 |
+ } |
|
| 1580 |
+ gain_max = limgain[sbr->bs_limiter_gains] * sqrtf((FLT_EPSILON + sum[0]) / (FLT_EPSILON + sum[1])); |
|
| 1581 |
+ gain_max = FFMIN(100000, gain_max); |
|
| 1582 |
+ for (m = sbr->f_tablelim[k] - sbr->kx[1]; m < sbr->f_tablelim[k + 1] - sbr->kx[1]; m++) {
|
|
| 1583 |
+ float q_m_max = sbr->q_m[e][m] * gain_max / sbr->gain[e][m]; |
|
| 1584 |
+ sbr->q_m[e][m] = FFMIN(sbr->q_m[e][m], q_m_max); |
|
| 1585 |
+ sbr->gain[e][m] = FFMIN(sbr->gain[e][m], gain_max); |
|
| 1586 |
+ } |
|
| 1587 |
+ sum[0] = sum[1] = 0.0f; |
|
| 1588 |
+ for (m = sbr->f_tablelim[k] - sbr->kx[1]; m < sbr->f_tablelim[k + 1] - sbr->kx[1]; m++) {
|
|
| 1589 |
+ sum[0] += sbr->e_origmapped[e][m]; |
|
| 1590 |
+ sum[1] += sbr->e_curr[e][m] * sbr->gain[e][m] * sbr->gain[e][m] |
|
| 1591 |
+ + sbr->s_m[e][m] * sbr->s_m[e][m] |
|
| 1592 |
+ + (delta && !sbr->s_m[e][m]) * sbr->q_m[e][m] * sbr->q_m[e][m]; |
|
| 1593 |
+ } |
|
| 1594 |
+ gain_boost = sqrtf((FLT_EPSILON + sum[0]) / (FLT_EPSILON + sum[1])); |
|
| 1595 |
+ gain_boost = FFMIN(1.584893192, gain_boost); |
|
| 1596 |
+ for (m = sbr->f_tablelim[k] - sbr->kx[1]; m < sbr->f_tablelim[k + 1] - sbr->kx[1]; m++) {
|
|
| 1597 |
+ sbr->gain[e][m] *= gain_boost; |
|
| 1598 |
+ sbr->q_m[e][m] *= gain_boost; |
|
| 1599 |
+ sbr->s_m[e][m] *= gain_boost; |
|
| 1600 |
+ } |
|
| 1601 |
+ } |
|
| 1602 |
+ } |
|
| 1603 |
+} |
|
| 1604 |
+ |
|
| 1605 |
+/// Assembling HF Signals (14496-3 sp04 p220) |
|
| 1606 |
+static void sbr_hf_assemble(float Y[2][38][64][2], const float X_high[64][40][2], |
|
| 1607 |
+ SpectralBandReplication *sbr, SBRData *ch_data, |
|
| 1608 |
+ const int e_a[2]) |
|
| 1609 |
+{
|
|
| 1610 |
+ int e, i, j, m; |
|
| 1611 |
+ const int h_SL = 4 * !sbr->bs_smoothing_mode; |
|
| 1612 |
+ const int kx = sbr->kx[1]; |
|
| 1613 |
+ const int m_max = sbr->m[1]; |
|
| 1614 |
+ static const float h_smooth[5] = {
|
|
| 1615 |
+ 0.33333333333333, |
|
| 1616 |
+ 0.30150283239582, |
|
| 1617 |
+ 0.21816949906249, |
|
| 1618 |
+ 0.11516383427084, |
|
| 1619 |
+ 0.03183050093751, |
|
| 1620 |
+ }; |
|
| 1621 |
+ static const int8_t phi[2][4] = {
|
|
| 1622 |
+ { 1, 0, -1, 0}, // real
|
|
| 1623 |
+ { 0, 1, 0, -1}, // imaginary
|
|
| 1624 |
+ }; |
|
| 1625 |
+ float (*g_temp)[48] = ch_data->g_temp, (*q_temp)[48] = ch_data->q_temp; |
|
| 1626 |
+ int indexnoise = ch_data->f_indexnoise; |
|
| 1627 |
+ int indexsine = ch_data->f_indexsine; |
|
| 1628 |
+ memcpy(Y[0], Y[1], sizeof(Y[0])); |
|
| 1629 |
+ |
|
| 1630 |
+ if (sbr->reset) {
|
|
| 1631 |
+ for (i = 0; i < h_SL; i++) {
|
|
| 1632 |
+ memcpy(g_temp[i + 2*ch_data->t_env[0]], sbr->gain[0], m_max * sizeof(sbr->gain[0][0])); |
|
| 1633 |
+ memcpy(q_temp[i + 2*ch_data->t_env[0]], sbr->q_m[0], m_max * sizeof(sbr->q_m[0][0])); |
|
| 1634 |
+ } |
|
| 1635 |
+ } else if (h_SL) {
|
|
| 1636 |
+ memcpy(g_temp[2*ch_data->t_env[0]], g_temp[2*ch_data->t_env_num_env_old], 4*sizeof(g_temp[0])); |
|
| 1637 |
+ memcpy(q_temp[2*ch_data->t_env[0]], q_temp[2*ch_data->t_env_num_env_old], 4*sizeof(q_temp[0])); |
|
| 1638 |
+ } |
|
| 1639 |
+ |
|
| 1640 |
+ for (e = 0; e < ch_data->bs_num_env[1]; e++) {
|
|
| 1641 |
+ for (i = 2 * ch_data->t_env[e]; i < 2 * ch_data->t_env[e + 1]; i++) {
|
|
| 1642 |
+ memcpy(g_temp[h_SL + i], sbr->gain[e], m_max * sizeof(sbr->gain[0][0])); |
|
| 1643 |
+ memcpy(q_temp[h_SL + i], sbr->q_m[e], m_max * sizeof(sbr->q_m[0][0])); |
|
| 1644 |
+ } |
|
| 1645 |
+ } |
|
| 1646 |
+ |
|
| 1647 |
+ for (e = 0; e < ch_data->bs_num_env[1]; e++) {
|
|
| 1648 |
+ for (i = 2 * ch_data->t_env[e]; i < 2 * ch_data->t_env[e + 1]; i++) {
|
|
| 1649 |
+ int phi_sign = (1 - 2*(kx & 1)); |
|
| 1650 |
+ |
|
| 1651 |
+ if (h_SL && e != e_a[0] && e != e_a[1]) {
|
|
| 1652 |
+ for (m = 0; m < m_max; m++) {
|
|
| 1653 |
+ const int idx1 = i + h_SL; |
|
| 1654 |
+ float g_filt = 0.0f; |
|
| 1655 |
+ for (j = 0; j <= h_SL; j++) |
|
| 1656 |
+ g_filt += g_temp[idx1 - j][m] * h_smooth[j]; |
|
| 1657 |
+ Y[1][i][m + kx][0] = |
|
| 1658 |
+ X_high[m + kx][i + ENVELOPE_ADJUSTMENT_OFFSET][0] * g_filt; |
|
| 1659 |
+ Y[1][i][m + kx][1] = |
|
| 1660 |
+ X_high[m + kx][i + ENVELOPE_ADJUSTMENT_OFFSET][1] * g_filt; |
|
| 1661 |
+ } |
|
| 1662 |
+ } else {
|
|
| 1663 |
+ for (m = 0; m < m_max; m++) {
|
|
| 1664 |
+ const float g_filt = g_temp[i + h_SL][m]; |
|
| 1665 |
+ Y[1][i][m + kx][0] = |
|
| 1666 |
+ X_high[m + kx][i + ENVELOPE_ADJUSTMENT_OFFSET][0] * g_filt; |
|
| 1667 |
+ Y[1][i][m + kx][1] = |
|
| 1668 |
+ X_high[m + kx][i + ENVELOPE_ADJUSTMENT_OFFSET][1] * g_filt; |
|
| 1669 |
+ } |
|
| 1670 |
+ } |
|
| 1671 |
+ |
|
| 1672 |
+ if (e != e_a[0] && e != e_a[1]) {
|
|
| 1673 |
+ for (m = 0; m < m_max; m++) {
|
|
| 1674 |
+ indexnoise = (indexnoise + 1) & 0x1ff; |
|
| 1675 |
+ if (sbr->s_m[e][m]) {
|
|
| 1676 |
+ Y[1][i][m + kx][0] += |
|
| 1677 |
+ sbr->s_m[e][m] * phi[0][indexsine]; |
|
| 1678 |
+ Y[1][i][m + kx][1] += |
|
| 1679 |
+ sbr->s_m[e][m] * (phi[1][indexsine] * phi_sign); |
|
| 1680 |
+ } else {
|
|
| 1681 |
+ float q_filt; |
|
| 1682 |
+ if (h_SL) {
|
|
| 1683 |
+ const int idx1 = i + h_SL; |
|
| 1684 |
+ q_filt = 0.0f; |
|
| 1685 |
+ for (j = 0; j <= h_SL; j++) |
|
| 1686 |
+ q_filt += q_temp[idx1 - j][m] * h_smooth[j]; |
|
| 1687 |
+ } else {
|
|
| 1688 |
+ q_filt = q_temp[i][m]; |
|
| 1689 |
+ } |
|
| 1690 |
+ Y[1][i][m + kx][0] += |
|
| 1691 |
+ q_filt * sbr_noise_table[indexnoise][0]; |
|
| 1692 |
+ Y[1][i][m + kx][1] += |
|
| 1693 |
+ q_filt * sbr_noise_table[indexnoise][1]; |
|
| 1694 |
+ } |
|
| 1695 |
+ phi_sign = -phi_sign; |
|
| 1696 |
+ } |
|
| 1697 |
+ } else {
|
|
| 1698 |
+ indexnoise = (indexnoise + m_max) & 0x1ff; |
|
| 1699 |
+ for (m = 0; m < m_max; m++) {
|
|
| 1700 |
+ Y[1][i][m + kx][0] += |
|
| 1701 |
+ sbr->s_m[e][m] * phi[0][indexsine]; |
|
| 1702 |
+ Y[1][i][m + kx][1] += |
|
| 1703 |
+ sbr->s_m[e][m] * (phi[1][indexsine] * phi_sign); |
|
| 1704 |
+ phi_sign = -phi_sign; |
|
| 1705 |
+ } |
|
| 1706 |
+ } |
|
| 1707 |
+ indexsine = (indexsine + 1) & 3; |
|
| 1708 |
+ } |
|
| 1709 |
+ } |
|
| 1710 |
+ ch_data->f_indexnoise = indexnoise; |
|
| 1711 |
+ ch_data->f_indexsine = indexsine; |
|
| 1712 |
+} |
|
| 1713 |
+ |
|
| 1714 |
+void ff_sbr_dequant(AACContext *ac, SpectralBandReplication *sbr, int id_aac) |
|
| 1715 |
+{
|
|
| 1716 |
+ int ch; |
|
| 1717 |
+ |
|
| 1718 |
+ if (sbr->start) {
|
|
| 1719 |
+ for (ch = 0; ch < (id_aac == TYPE_CPE) + 1; ch++) {
|
|
| 1720 |
+ sbr_time_freq_grid(ac, sbr, &sbr->data[ch], ch); |
|
| 1721 |
+ } |
|
| 1722 |
+ sbr_dequant(sbr, id_aac); |
|
| 1723 |
+ } |
|
| 1724 |
+} |
|
| 1725 |
+ |
|
| 1726 |
+void ff_sbr_apply(AACContext *ac, SpectralBandReplication *sbr, int ch, |
|
| 1727 |
+ const float* in, float* out) |
|
| 1728 |
+{
|
|
| 1729 |
+ int downsampled = ac->m4ac.ext_sample_rate < sbr->sample_rate; |
|
| 1730 |
+ |
|
| 1731 |
+ /* decode channel */ |
|
| 1732 |
+ sbr_qmf_analysis(&ac->dsp, &sbr->rdft, in, sbr->data[ch].analysis_filterbank_samples, |
|
| 1733 |
+ (float*)sbr->qmf_filter_scratch, |
|
| 1734 |
+ sbr->data[ch].W, ac->add_bias, 1/(-1024 * ac->sf_scale)); |
|
| 1735 |
+ sbr_lf_gen(ac, sbr, sbr->X_low, sbr->data[ch].W); |
|
| 1736 |
+ if (sbr->start) {
|
|
| 1737 |
+ sbr_hf_inverse_filter(sbr->alpha0, sbr->alpha1, sbr->X_low, sbr->k[0]); |
|
| 1738 |
+ sbr_chirp(sbr, &sbr->data[ch]); |
|
| 1739 |
+ sbr_hf_gen(ac, sbr, sbr->X_high, sbr->X_low, sbr->alpha0, sbr->alpha1, |
|
| 1740 |
+ sbr->data[ch].bw_array, sbr->data[ch].t_env, |
|
| 1741 |
+ sbr->data[ch].bs_num_env[1]); |
|
| 1742 |
+ |
|
| 1743 |
+ // hf_adj |
|
| 1744 |
+ sbr_mapping(ac, sbr, &sbr->data[ch], sbr->data[ch].e_a); |
|
| 1745 |
+ sbr_env_estimate(sbr->e_curr, sbr->X_high, sbr, &sbr->data[ch]); |
|
| 1746 |
+ sbr_gain_calc(ac, sbr, &sbr->data[ch], sbr->data[ch].e_a); |
|
| 1747 |
+ sbr_hf_assemble(sbr->data[ch].Y, sbr->X_high, sbr, &sbr->data[ch], |
|
| 1748 |
+ sbr->data[ch].e_a); |
|
| 1749 |
+ } |
|
| 1750 |
+ |
|
| 1751 |
+ /* synthesis */ |
|
| 1752 |
+ sbr_x_gen(sbr, sbr->X, sbr->X_low, sbr->data[ch].Y, ch); |
|
| 1753 |
+ sbr_qmf_synthesis(&ac->dsp, &sbr->mdct, out, sbr->X, sbr->qmf_filter_scratch, |
|
| 1754 |
+ sbr->data[ch].synthesis_filterbank_samples, |
|
| 1755 |
+ &sbr->data[ch].synthesis_filterbank_samples_offset, |
|
| 1756 |
+ downsampled, |
|
| 1757 |
+ ac->add_bias, -1024 * ac->sf_scale); |
|
| 1758 |
+} |
| 0 | 1759 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,51 @@ |
| 0 |
+/* |
|
| 1 |
+ * AAC Spectral Band Replication function declarations |
|
| 2 |
+ * Copyright (c) 2008-2009 Robert Swain ( rob opendot cl ) |
|
| 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 |
+/** |
|
| 23 |
+ * @file libavcodec/aacsbr.h |
|
| 24 |
+ * AAC Spectral Band Replication function declarations |
|
| 25 |
+ * @author Robert Swain ( rob opendot cl ) |
|
| 26 |
+ */ |
|
| 27 |
+ |
|
| 28 |
+#ifndef AVCODEC_AACSBR_H |
|
| 29 |
+#define AVCODEC_AACSBR_H |
|
| 30 |
+ |
|
| 31 |
+#include "get_bits.h" |
|
| 32 |
+#include "aac.h" |
|
| 33 |
+#include "sbr.h" |
|
| 34 |
+ |
|
| 35 |
+/** Initialize SBR. */ |
|
| 36 |
+av_cold void ff_aac_sbr_init(void); |
|
| 37 |
+/** Initialize one SBR context. */ |
|
| 38 |
+av_cold void ff_aac_sbr_ctx_init(SpectralBandReplication *sbr); |
|
| 39 |
+/** Close one SBR context. */ |
|
| 40 |
+av_cold void ff_aac_sbr_ctx_close(SpectralBandReplication *sbr); |
|
| 41 |
+/** Decode one SBR element. */ |
|
| 42 |
+int ff_decode_sbr_extension(AACContext *ac, SpectralBandReplication *sbr, |
|
| 43 |
+ GetBitContext *gb, int crc, int cnt, int id_aac); |
|
| 44 |
+/** Dequantized all channels in one SBR element. */ |
|
| 45 |
+void ff_sbr_dequant(AACContext *ac, SpectralBandReplication *sbr, int id_aac); |
|
| 46 |
+/** Apply dequantized SBR to a single AAC channel. */ |
|
| 47 |
+void ff_sbr_apply(AACContext *ac, SpectralBandReplication *sbr, int ch, |
|
| 48 |
+ const float* in, float* out); |
|
| 49 |
+ |
|
| 50 |
+#endif /* AVCODEC_AACSBR_H */ |
| 0 | 51 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,613 @@ |
| 0 |
+/* |
|
| 1 |
+ * AAC Spectral Band Replication decoding data |
|
| 2 |
+ * Copyright (c) 2008-2009 Robert Swain ( rob opendot cl ) |
|
| 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 |
+/** |
|
| 22 |
+ * @file libavcodec/aacsbrdata.h |
|
| 23 |
+ * AAC Spectral Band Replication decoding data |
|
| 24 |
+ * @author Robert Swain ( rob opendot cl ) |
|
| 25 |
+ */ |
|
| 26 |
+ |
|
| 27 |
+#ifndef AVCODEC_AACSBRDATA_H |
|
| 28 |
+#define AVCODEC_AACSBRDATA_H |
|
| 29 |
+ |
|
| 30 |
+#include <stdint.h> |
|
| 31 |
+ |
|
| 32 |
+///< Huffman tables for SBR |
|
| 33 |
+ |
|
| 34 |
+static const uint8_t t_huffman_env_1_5dB_bits[121] = {
|
|
| 35 |
+ 18, 18, 18, 18, 18, 18, 19, 19, |
|
| 36 |
+ 19, 19, 19, 19, 19, 19, 19, 19, |
|
| 37 |
+ 19, 19, 19, 19, 19, 19, 19, 19, |
|
| 38 |
+ 19, 19, 19, 19, 19, 19, 19, 19, |
|
| 39 |
+ 19, 19, 17, 18, 16, 17, 18, 17, |
|
| 40 |
+ 16, 16, 16, 16, 15, 14, 14, 13, |
|
| 41 |
+ 13, 12, 11, 10, 9, 8, 7, 6, |
|
| 42 |
+ 5, 4, 3, 2, 2, 3, 4, 5, |
|
| 43 |
+ 6, 7, 8, 9, 10, 12, 13, 14, |
|
| 44 |
+ 14, 15, 16, 17, 16, 19, 19, 19, |
|
| 45 |
+ 19, 19, 19, 19, 19, 19, 19, 19, |
|
| 46 |
+ 19, 19, 19, 19, 19, 19, 19, 19, |
|
| 47 |
+ 19, 19, 19, 19, 19, 19, 19, 19, |
|
| 48 |
+ 19, 19, 19, 19, 19, 19, 19, 19, |
|
| 49 |
+ 19, 19, 19, 19, 19, 19, 19, 19, |
|
| 50 |
+ 19, |
|
| 51 |
+}; |
|
| 52 |
+ |
|
| 53 |
+static const uint32_t t_huffman_env_1_5dB_codes[121] = {
|
|
| 54 |
+ 0x3ffd6, 0x3ffd7, 0x3ffd8, 0x3ffd9, 0x3ffda, 0x3ffdb, 0x7ffb8, 0x7ffb9, |
|
| 55 |
+ 0x7ffba, 0x7ffbb, 0x7ffbc, 0x7ffbd, 0x7ffbe, 0x7ffbf, 0x7ffc0, 0x7ffc1, |
|
| 56 |
+ 0x7ffc2, 0x7ffc3, 0x7ffc4, 0x7ffc5, 0x7ffc6, 0x7ffc7, 0x7ffc8, 0x7ffc9, |
|
| 57 |
+ 0x7ffca, 0x7ffcb, 0x7ffcc, 0x7ffcd, 0x7ffce, 0x7ffcf, 0x7ffd0, 0x7ffd1, |
|
| 58 |
+ 0x7ffd2, 0x7ffd3, 0x1ffe6, 0x3ffd4, 0x0fff0, 0x1ffe9, 0x3ffd5, 0x1ffe7, |
|
| 59 |
+ 0x0fff1, 0x0ffec, 0x0ffed, 0x0ffee, 0x07ff4, 0x03ff9, 0x03ff7, 0x01ffa, |
|
| 60 |
+ 0x01ff9, 0x00ffb, 0x007fc, 0x003fc, 0x001fd, 0x000fd, 0x0007d, 0x0003d, |
|
| 61 |
+ 0x0001d, 0x0000d, 0x00005, 0x00001, 0x00000, 0x00004, 0x0000c, 0x0001c, |
|
| 62 |
+ 0x0003c, 0x0007c, 0x000fc, 0x001fc, 0x003fd, 0x00ffa, 0x01ff8, 0x03ff6, |
|
| 63 |
+ 0x03ff8, 0x07ff5, 0x0ffef, 0x1ffe8, 0x0fff2, 0x7ffd4, 0x7ffd5, 0x7ffd6, |
|
| 64 |
+ 0x7ffd7, 0x7ffd8, 0x7ffd9, 0x7ffda, 0x7ffdb, 0x7ffdc, 0x7ffdd, 0x7ffde, |
|
| 65 |
+ 0x7ffdf, 0x7ffe0, 0x7ffe1, 0x7ffe2, 0x7ffe3, 0x7ffe4, 0x7ffe5, 0x7ffe6, |
|
| 66 |
+ 0x7ffe7, 0x7ffe8, 0x7ffe9, 0x7ffea, 0x7ffeb, 0x7ffec, 0x7ffed, 0x7ffee, |
|
| 67 |
+ 0x7ffef, 0x7fff0, 0x7fff1, 0x7fff2, 0x7fff3, 0x7fff4, 0x7fff5, 0x7fff6, |
|
| 68 |
+ 0x7fff7, 0x7fff8, 0x7fff9, 0x7fffa, 0x7fffb, 0x7fffc, 0x7fffd, 0x7fffe, |
|
| 69 |
+ 0x7ffff, |
|
| 70 |
+}; |
|
| 71 |
+ |
|
| 72 |
+static const uint8_t f_huffman_env_1_5dB_bits[121] = {
|
|
| 73 |
+ 19, 19, 20, 20, 20, 20, 20, 20, |
|
| 74 |
+ 20, 19, 20, 20, 20, 20, 19, 20, |
|
| 75 |
+ 19, 19, 20, 18, 20, 20, 20, 19, |
|
| 76 |
+ 20, 20, 20, 19, 20, 19, 18, 19, |
|
| 77 |
+ 18, 18, 17, 18, 17, 17, 17, 16, |
|
| 78 |
+ 16, 16, 15, 15, 14, 13, 13, 12, |
|
| 79 |
+ 12, 11, 10, 9, 9, 8, 7, 6, |
|
| 80 |
+ 5, 4, 3, 2, 2, 3, 4, 5, |
|
| 81 |
+ 6, 8, 8, 9, 10, 11, 11, 11, |
|
| 82 |
+ 12, 12, 13, 13, 14, 14, 16, 16, |
|
| 83 |
+ 17, 17, 18, 18, 18, 18, 18, 18, |
|
| 84 |
+ 18, 20, 19, 20, 20, 20, 20, 20, |
|
| 85 |
+ 20, 19, 20, 20, 20, 20, 19, 20, |
|
| 86 |
+ 18, 20, 20, 19, 19, 20, 20, 20, |
|
| 87 |
+ 20, 20, 20, 20, 20, 20, 20, 20, |
|
| 88 |
+ 20, |
|
| 89 |
+}; |
|
| 90 |
+ |
|
| 91 |
+static const uint32_t f_huffman_env_1_5dB_codes[121] = {
|
|
| 92 |
+ 0x7ffe7, 0x7ffe8, 0xfffd2, 0xfffd3, 0xfffd4, 0xfffd5, 0xfffd6, 0xfffd7, |
|
| 93 |
+ 0xfffd8, 0x7ffda, 0xfffd9, 0xfffda, 0xfffdb, 0xfffdc, 0x7ffdb, 0xfffdd, |
|
| 94 |
+ 0x7ffdc, 0x7ffdd, 0xfffde, 0x3ffe4, 0xfffdf, 0xfffe0, 0xfffe1, 0x7ffde, |
|
| 95 |
+ 0xfffe2, 0xfffe3, 0xfffe4, 0x7ffdf, 0xfffe5, 0x7ffe0, 0x3ffe8, 0x7ffe1, |
|
| 96 |
+ 0x3ffe0, 0x3ffe9, 0x1ffef, 0x3ffe5, 0x1ffec, 0x1ffed, 0x1ffee, 0x0fff4, |
|
| 97 |
+ 0x0fff3, 0x0fff0, 0x07ff7, 0x07ff6, 0x03ffa, 0x01ffa, 0x01ff9, 0x00ffa, |
|
| 98 |
+ 0x00ff8, 0x007f9, 0x003fb, 0x001fc, 0x001fa, 0x000fb, 0x0007c, 0x0003c, |
|
| 99 |
+ 0x0001c, 0x0000c, 0x00005, 0x00001, 0x00000, 0x00004, 0x0000d, 0x0001d, |
|
| 100 |
+ 0x0003d, 0x000fa, 0x000fc, 0x001fb, 0x003fa, 0x007f8, 0x007fa, 0x007fb, |
|
| 101 |
+ 0x00ff9, 0x00ffb, 0x01ff8, 0x01ffb, 0x03ff8, 0x03ff9, 0x0fff1, 0x0fff2, |
|
| 102 |
+ 0x1ffea, 0x1ffeb, 0x3ffe1, 0x3ffe2, 0x3ffea, 0x3ffe3, 0x3ffe6, 0x3ffe7, |
|
| 103 |
+ 0x3ffeb, 0xfffe6, 0x7ffe2, 0xfffe7, 0xfffe8, 0xfffe9, 0xfffea, 0xfffeb, |
|
| 104 |
+ 0xfffec, 0x7ffe3, 0xfffed, 0xfffee, 0xfffef, 0xffff0, 0x7ffe4, 0xffff1, |
|
| 105 |
+ 0x3ffec, 0xffff2, 0xffff3, 0x7ffe5, 0x7ffe6, 0xffff4, 0xffff5, 0xffff6, |
|
| 106 |
+ 0xffff7, 0xffff8, 0xffff9, 0xffffa, 0xffffb, 0xffffc, 0xffffd, 0xffffe, |
|
| 107 |
+ 0xfffff, |
|
| 108 |
+}; |
|
| 109 |
+ |
|
| 110 |
+static const uint8_t t_huffman_env_bal_1_5dB_bits[49] = {
|
|
| 111 |
+ 16, 16, 16, 16, 16, 16, 16, 16, |
|
| 112 |
+ 16, 16, 16, 16, 16, 16, 16, 16, |
|
| 113 |
+ 16, 16, 12, 11, 9, 7, 5, 3, |
|
| 114 |
+ 1, 2, 4, 6, 8, 11, 12, 15, |
|
| 115 |
+ 16, 16, 16, 16, 16, 16, 16, 17, |
|
| 116 |
+ 17, 17, 17, 17, 17, 17, 17, 17, |
|
| 117 |
+ 17, |
|
| 118 |
+}; |
|
| 119 |
+ |
|
| 120 |
+static const uint32_t t_huffman_env_bal_1_5dB_codes[49] = {
|
|
| 121 |
+ 0x0ffe4, 0x0ffe5, 0x0ffe6, 0x0ffe7, 0x0ffe8, 0x0ffe9, 0x0ffea, 0x0ffeb, |
|
| 122 |
+ 0x0ffec, 0x0ffed, 0x0ffee, 0x0ffef, 0x0fff0, 0x0fff1, 0x0fff2, 0x0fff3, |
|
| 123 |
+ 0x0fff4, 0x0ffe2, 0x00ffc, 0x007fc, 0x001fe, 0x0007e, 0x0001e, 0x00006, |
|
| 124 |
+ 0x00000, 0x00002, 0x0000e, 0x0003e, 0x000fe, 0x007fd, 0x00ffd, 0x07ff0, |
|
| 125 |
+ 0x0ffe3, 0x0fff5, 0x0fff6, 0x0fff7, 0x0fff8, 0x0fff9, 0x0fffa, 0x1fff6, |
|
| 126 |
+ 0x1fff7, 0x1fff8, 0x1fff9, 0x1fffa, 0x1fffb, 0x1fffc, 0x1fffd, 0x1fffe, |
|
| 127 |
+ 0x1ffff, |
|
| 128 |
+}; |
|
| 129 |
+ |
|
| 130 |
+static const uint8_t f_huffman_env_bal_1_5dB_bits[49] = {
|
|
| 131 |
+ 18, 18, 18, 18, 18, 18, 18, 18, |
|
| 132 |
+ 18, 18, 18, 18, 18, 18, 18, 16, |
|
| 133 |
+ 17, 14, 11, 11, 8, 7, 4, 2, |
|
| 134 |
+ 1, 3, 5, 6, 9, 11, 12, 15, |
|
| 135 |
+ 16, 18, 18, 18, 18, 18, 18, 18, |
|
| 136 |
+ 18, 18, 18, 18, 18, 18, 18, 19, |
|
| 137 |
+ 19, |
|
| 138 |
+}; |
|
| 139 |
+ |
|
| 140 |
+static const uint32_t f_huffman_env_bal_1_5dB_codes[49] = {
|
|
| 141 |
+ 0x3ffe2, 0x3ffe3, 0x3ffe4, 0x3ffe5, 0x3ffe6, 0x3ffe7, 0x3ffe8, 0x3ffe9, |
|
| 142 |
+ 0x3ffea, 0x3ffeb, 0x3ffec, 0x3ffed, 0x3ffee, 0x3ffef, 0x3fff0, 0x0fff7, |
|
| 143 |
+ 0x1fff0, 0x03ffc, 0x007fe, 0x007fc, 0x000fe, 0x0007e, 0x0000e, 0x00002, |
|
| 144 |
+ 0x00000, 0x00006, 0x0001e, 0x0003e, 0x001fe, 0x007fd, 0x00ffe, 0x07ffa, |
|
| 145 |
+ 0x0fff6, 0x3fff1, 0x3fff2, 0x3fff3, 0x3fff4, 0x3fff5, 0x3fff6, 0x3fff7, |
|
| 146 |
+ 0x3fff8, 0x3fff9, 0x3fffa, 0x3fffb, 0x3fffc, 0x3fffd, 0x3fffe, 0x7fffe, |
|
| 147 |
+ 0x7ffff, |
|
| 148 |
+}; |
|
| 149 |
+ |
|
| 150 |
+static const uint8_t t_huffman_env_3_0dB_bits[63] = {
|
|
| 151 |
+ 18, 18, 19, 19, 19, 19, 19, 19, |
|
| 152 |
+ 19, 19, 19, 19, 19, 19, 19, 19, |
|
| 153 |
+ 19, 17, 16, 16, 16, 14, 14, 14, |
|
| 154 |
+ 13, 12, 11, 8, 6, 4, 2, 1, |
|
| 155 |
+ 3, 5, 7, 9, 11, 13, 14, 14, |
|
| 156 |
+ 15, 16, 17, 18, 19, 19, 19, 19, |
|
| 157 |
+ 19, 19, 19, 19, 19, 19, 19, 19, |
|
| 158 |
+ 19, 19, 19, 19, 19, 19, 19, |
|
| 159 |
+}; |
|
| 160 |
+ |
|
| 161 |
+static const uint32_t t_huffman_env_3_0dB_codes[63] = {
|
|
| 162 |
+ 0x3ffed, 0x3ffee, 0x7ffde, 0x7ffdf, 0x7ffe0, 0x7ffe1, 0x7ffe2, 0x7ffe3, |
|
| 163 |
+ 0x7ffe4, 0x7ffe5, 0x7ffe6, 0x7ffe7, 0x7ffe8, 0x7ffe9, 0x7ffea, 0x7ffeb, |
|
| 164 |
+ 0x7ffec, 0x1fff4, 0x0fff7, 0x0fff9, 0x0fff8, 0x03ffb, 0x03ffa, 0x03ff8, |
|
| 165 |
+ 0x01ffa, 0x00ffc, 0x007fc, 0x000fe, 0x0003e, 0x0000e, 0x00002, 0x00000, |
|
| 166 |
+ 0x00006, 0x0001e, 0x0007e, 0x001fe, 0x007fd, 0x01ffb, 0x03ff9, 0x03ffc, |
|
| 167 |
+ 0x07ffa, 0x0fff6, 0x1fff5, 0x3ffec, 0x7ffed, 0x7ffee, 0x7ffef, 0x7fff0, |
|
| 168 |
+ 0x7fff1, 0x7fff2, 0x7fff3, 0x7fff4, 0x7fff5, 0x7fff6, 0x7fff7, 0x7fff8, |
|
| 169 |
+ 0x7fff9, 0x7fffa, 0x7fffb, 0x7fffc, 0x7fffd, 0x7fffe, 0x7ffff, |
|
| 170 |
+}; |
|
| 171 |
+ |
|
| 172 |
+static const uint8_t f_huffman_env_3_0dB_bits[63] = {
|
|
| 173 |
+ 20, 20, 20, 20, 20, 20, 20, 18, |
|
| 174 |
+ 19, 19, 19, 19, 18, 18, 20, 19, |
|
| 175 |
+ 17, 18, 17, 16, 16, 15, 14, 12, |
|
| 176 |
+ 11, 10, 9, 8, 6, 4, 2, 1, |
|
| 177 |
+ 3, 5, 8, 9, 10, 11, 12, 13, |
|
| 178 |
+ 14, 15, 15, 16, 16, 17, 17, 18, |
|
| 179 |
+ 18, 18, 20, 19, 19, 19, 20, 19, |
|
| 180 |
+ 19, 20, 20, 20, 20, 20, 20, |
|
| 181 |
+}; |
|
| 182 |
+ |
|
| 183 |
+static const uint32_t f_huffman_env_3_0dB_codes[63] = {
|
|
| 184 |
+ 0xffff0, 0xffff1, 0xffff2, 0xffff3, 0xffff4, 0xffff5, 0xffff6, 0x3fff3, |
|
| 185 |
+ 0x7fff5, 0x7ffee, 0x7ffef, 0x7fff6, 0x3fff4, 0x3fff2, 0xffff7, 0x7fff0, |
|
| 186 |
+ 0x1fff5, 0x3fff0, 0x1fff4, 0x0fff7, 0x0fff6, 0x07ff8, 0x03ffb, 0x00ffd, |
|
| 187 |
+ 0x007fd, 0x003fd, 0x001fd, 0x000fd, 0x0003e, 0x0000e, 0x00002, 0x00000, |
|
| 188 |
+ 0x00006, 0x0001e, 0x000fc, 0x001fc, 0x003fc, 0x007fc, 0x00ffc, 0x01ffc, |
|
| 189 |
+ 0x03ffa, 0x07ff9, 0x07ffa, 0x0fff8, 0x0fff9, 0x1fff6, 0x1fff7, 0x3fff5, |
|
| 190 |
+ 0x3fff6, 0x3fff1, 0xffff8, 0x7fff1, 0x7fff2, 0x7fff3, 0xffff9, 0x7fff7, |
|
| 191 |
+ 0x7fff4, 0xffffa, 0xffffb, 0xffffc, 0xffffd, 0xffffe, 0xfffff, |
|
| 192 |
+}; |
|
| 193 |
+ |
|
| 194 |
+static const uint8_t t_huffman_env_bal_3_0dB_bits[25] = {
|
|
| 195 |
+ 13, 13, 13, 13, 13, 13, 13, 12, |
|
| 196 |
+ 8, 7, 4, 3, 1, 2, 5, 6, |
|
| 197 |
+ 9, 13, 13, 13, 13, 13, 13, 14, |
|
| 198 |
+ 14, |
|
| 199 |
+}; |
|
| 200 |
+ |
|
| 201 |
+static const uint16_t t_huffman_env_bal_3_0dB_codes[25] = {
|
|
| 202 |
+ 0x1ff2, 0x1ff3, 0x1ff4, 0x1ff5, 0x1ff6, 0x1ff7, 0x1ff8, 0x0ff8, |
|
| 203 |
+ 0x00fe, 0x007e, 0x000e, 0x0006, 0x0000, 0x0002, 0x001e, 0x003e, |
|
| 204 |
+ 0x01fe, 0x1ff9, 0x1ffa, 0x1ffb, 0x1ffc, 0x1ffd, 0x1ffe, 0x3ffe, |
|
| 205 |
+ 0x3fff, |
|
| 206 |
+}; |
|
| 207 |
+ |
|
| 208 |
+static const uint8_t f_huffman_env_bal_3_0dB_bits[25] = {
|
|
| 209 |
+ 13, 13, 13, 13, 13, 14, 14, 11, |
|
| 210 |
+ 8, 7, 4, 2, 1, 3, 5, 6, |
|
| 211 |
+ 9, 12, 13, 14, 14, 14, 14, 14, |
|
| 212 |
+ 14, |
|
| 213 |
+}; |
|
| 214 |
+ |
|
| 215 |
+static const uint16_t f_huffman_env_bal_3_0dB_codes[25] = {
|
|
| 216 |
+ 0x1ff7, 0x1ff8, 0x1ff9, 0x1ffa, 0x1ffb, 0x3ff8, 0x3ff9, 0x07fc, |
|
| 217 |
+ 0x00fe, 0x007e, 0x000e, 0x0002, 0x0000, 0x0006, 0x001e, 0x003e, |
|
| 218 |
+ 0x01fe, 0x0ffa, 0x1ff6, 0x3ffa, 0x3ffb, 0x3ffc, 0x3ffd, 0x3ffe, |
|
| 219 |
+ 0x3fff, |
|
| 220 |
+}; |
|
| 221 |
+ |
|
| 222 |
+static const uint8_t t_huffman_noise_3_0dB_bits[63] = {
|
|
| 223 |
+ 13, 13, 13, 13, 13, 13, 13, 13, |
|
| 224 |
+ 13, 13, 13, 13, 13, 13, 13, 13, |
|
| 225 |
+ 13, 13, 13, 13, 13, 13, 13, 13, |
|
| 226 |
+ 13, 13, 11, 8, 6, 4, 3, 1, |
|
| 227 |
+ 2, 5, 8, 10, 13, 13, 13, 13, |
|
| 228 |
+ 13, 13, 13, 13, 13, 13, 13, 13, |
|
| 229 |
+ 13, 13, 13, 13, 13, 13, 13, 13, |
|
| 230 |
+ 13, 13, 13, 13, 13, 14, 14, |
|
| 231 |
+}; |
|
| 232 |
+ |
|
| 233 |
+static const uint16_t t_huffman_noise_3_0dB_codes[63] = {
|
|
| 234 |
+ 0x1fce, 0x1fcf, 0x1fd0, 0x1fd1, 0x1fd2, 0x1fd3, 0x1fd4, 0x1fd5, |
|
| 235 |
+ 0x1fd6, 0x1fd7, 0x1fd8, 0x1fd9, 0x1fda, 0x1fdb, 0x1fdc, 0x1fdd, |
|
| 236 |
+ 0x1fde, 0x1fdf, 0x1fe0, 0x1fe1, 0x1fe2, 0x1fe3, 0x1fe4, 0x1fe5, |
|
| 237 |
+ 0x1fe6, 0x1fe7, 0x07f2, 0x00fd, 0x003e, 0x000e, 0x0006, 0x0000, |
|
| 238 |
+ 0x0002, 0x001e, 0x00fc, 0x03f8, 0x1fcc, 0x1fe8, 0x1fe9, 0x1fea, |
|
| 239 |
+ 0x1feb, 0x1fec, 0x1fcd, 0x1fed, 0x1fee, 0x1fef, 0x1ff0, 0x1ff1, |
|
| 240 |
+ 0x1ff2, 0x1ff3, 0x1ff4, 0x1ff5, 0x1ff6, 0x1ff7, 0x1ff8, 0x1ff9, |
|
| 241 |
+ 0x1ffa, 0x1ffb, 0x1ffc, 0x1ffd, 0x1ffe, 0x3ffe, 0x3fff, |
|
| 242 |
+}; |
|
| 243 |
+ |
|
| 244 |
+static const uint8_t t_huffman_noise_bal_3_0dB_bits[25] = {
|
|
| 245 |
+ 8, 8, 8, 8, 8, 8, 8, 8, |
|
| 246 |
+ 8, 8, 5, 2, 1, 3, 6, 8, |
|
| 247 |
+ 8, 8, 8, 8, 8, 8, 8, 8, |
|
| 248 |
+ 8, |
|
| 249 |
+}; |
|
| 250 |
+ |
|
| 251 |
+static const uint8_t t_huffman_noise_bal_3_0dB_codes[25] = {
|
|
| 252 |
+ 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, |
|
| 253 |
+ 0xf4, 0xf5, 0x1c, 0x02, 0x00, 0x06, 0x3a, 0xf6, |
|
| 254 |
+ 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, |
|
| 255 |
+ 0xff, |
|
| 256 |
+}; |
|
| 257 |
+ |
|
| 258 |
+static const int8_t sbr_offset[6][16] = {
|
|
| 259 |
+ {-8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7}, // fs_sbr = 16000 Hz
|
|
| 260 |
+ {-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13}, // fs_sbr = 22050 Hz
|
|
| 261 |
+ {-5, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16}, // fs_sbr = 24000 Hz
|
|
| 262 |
+ {-6, -4, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16}, // fs_sbr = 32000 Hz
|
|
| 263 |
+ {-4, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16, 20}, // 44100 Hz <= fs_sbr <= 64000 Hz
|
|
| 264 |
+ {-2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16, 20, 24}, // 64000 Hz < fs_sbr
|
|
| 265 |
+}; |
|
| 266 |
+ |
|
| 267 |
+///< window coefficients for analysis/synthesis QMF banks |
|
| 268 |
+static DECLARE_ALIGNED(16, float, sbr_qmf_window_ds)[320]; |
|
| 269 |
+static DECLARE_ALIGNED(16, float, sbr_qmf_window_us)[640] = {
|
|
| 270 |
+ 0.0000000000, -0.0005525286, -0.0005617692, -0.0004947518, |
|
| 271 |
+ -0.0004875227, -0.0004893791, -0.0005040714, -0.0005226564, |
|
| 272 |
+ -0.0005466565, -0.0005677802, -0.0005870930, -0.0006132747, |
|
| 273 |
+ -0.0006312493, -0.0006540333, -0.0006777690, -0.0006941614, |
|
| 274 |
+ -0.0007157736, -0.0007255043, -0.0007440941, -0.0007490598, |
|
| 275 |
+ -0.0007681371, -0.0007724848, -0.0007834332, -0.0007779869, |
|
| 276 |
+ -0.0007803664, -0.0007801449, -0.0007757977, -0.0007630793, |
|
| 277 |
+ -0.0007530001, -0.0007319357, -0.0007215391, -0.0006917937, |
|
| 278 |
+ -0.0006650415, -0.0006341594, -0.0005946118, -0.0005564576, |
|
| 279 |
+ -0.0005145572, -0.0004606325, -0.0004095121, -0.0003501175, |
|
| 280 |
+ -0.0002896981, -0.0002098337, -0.0001446380, -0.0000617334, |
|
| 281 |
+ 0.0000134949, 0.0001094383, 0.0002043017, 0.0002949531, |
|
| 282 |
+ 0.0004026540, 0.0005107388, 0.0006239376, 0.0007458025, |
|
| 283 |
+ 0.0008608443, 0.0009885988, 0.0011250155, 0.0012577884, |
|
| 284 |
+ 0.0013902494, 0.0015443219, 0.0016868083, 0.0018348265, |
|
| 285 |
+ 0.0019841140, 0.0021461583, 0.0023017254, 0.0024625616, |
|
| 286 |
+ 0.0026201758, 0.0027870464, 0.0029469447, 0.0031125420, |
|
| 287 |
+ 0.0032739613, 0.0034418874, 0.0036008268, 0.0037603922, |
|
| 288 |
+ 0.0039207432, 0.0040819753, 0.0042264269, 0.0043730719, |
|
| 289 |
+ 0.0045209852, 0.0046606460, 0.0047932560, 0.0049137603, |
|
| 290 |
+ 0.0050393022, 0.0051407353, 0.0052461166, 0.0053471681, |
|
| 291 |
+ 0.0054196775, 0.0054876040, 0.0055475714, 0.0055938023, |
|
| 292 |
+ 0.0056220643, 0.0056455196, 0.0056389199, 0.0056266114, |
|
| 293 |
+ 0.0055917128, 0.0055404363, 0.0054753783, 0.0053838975, |
|
| 294 |
+ 0.0052715758, 0.0051382275, 0.0049839687, 0.0048109469, |
|
| 295 |
+ 0.0046039530, 0.0043801861, 0.0041251642, 0.0038456408, |
|
| 296 |
+ 0.0035401246, 0.0032091885, 0.0028446757, 0.0024508540, |
|
| 297 |
+ 0.0020274176, 0.0015784682, 0.0010902329, 0.0005832264, |
|
| 298 |
+ 0.0000276045, -0.0005464280, -0.0011568135, -0.0018039472, |
|
| 299 |
+ -0.0024826723, -0.0031933778, -0.0039401124, -0.0047222596, |
|
| 300 |
+ -0.0055337211, -0.0063792293, -0.0072615816, -0.0081798233, |
|
| 301 |
+ -0.0091325329, -0.0101150215, -0.0111315548, -0.0121849995, |
|
| 302 |
+ 0.0132718220, 0.0143904666, 0.0155405553, 0.0167324712, |
|
| 303 |
+ 0.0179433381, 0.0191872431, 0.0204531793, 0.0217467550, |
|
| 304 |
+ 0.0230680169, 0.0244160992, 0.0257875847, 0.0271859429, |
|
| 305 |
+ 0.0286072173, 0.0300502657, 0.0315017608, 0.0329754081, |
|
| 306 |
+ 0.0344620948, 0.0359697560, 0.0374812850, 0.0390053679, |
|
| 307 |
+ 0.0405349170, 0.0420649094, 0.0436097542, 0.0451488405, |
|
| 308 |
+ 0.0466843027, 0.0482165720, 0.0497385755, 0.0512556155, |
|
| 309 |
+ 0.0527630746, 0.0542452768, 0.0557173648, 0.0571616450, |
|
| 310 |
+ 0.0585915683, 0.0599837480, 0.0613455171, 0.0626857808, |
|
| 311 |
+ 0.0639715898, 0.0652247106, 0.0664367512, 0.0676075985, |
|
| 312 |
+ 0.0687043828, 0.0697630244, 0.0707628710, 0.0717002673, |
|
| 313 |
+ 0.0725682583, 0.0733620255, 0.0741003642, 0.0747452558, |
|
| 314 |
+ 0.0753137336, 0.0758008358, 0.0761992479, 0.0764992170, |
|
| 315 |
+ 0.0767093490, 0.0768173975, 0.0768230011, 0.0767204924, |
|
| 316 |
+ 0.0765050718, 0.0761748321, 0.0757305756, 0.0751576255, |
|
| 317 |
+ 0.0744664394, 0.0736406005, 0.0726774642, 0.0715826364, |
|
| 318 |
+ 0.0703533073, 0.0689664013, 0.0674525021, 0.0657690668, |
|
| 319 |
+ 0.0639444805, 0.0619602779, 0.0598166570, 0.0575152691, |
|
| 320 |
+ 0.0550460034, 0.0524093821, 0.0495978676, 0.0466303305, |
|
| 321 |
+ 0.0434768782, 0.0401458278, 0.0366418116, 0.0329583930, |
|
| 322 |
+ 0.0290824006, 0.0250307561, 0.0207997072, 0.0163701258, |
|
| 323 |
+ 0.0117623832, 0.0069636862, 0.0019765601, -0.0032086896, |
|
| 324 |
+ -0.0085711749, -0.0141288827, -0.0198834129, -0.0258227288, |
|
| 325 |
+ -0.0319531274, -0.0382776572, -0.0447806821, -0.0514804176, |
|
| 326 |
+ -0.0583705326, -0.0654409853, -0.0726943300, -0.0801372934, |
|
| 327 |
+ -0.0877547536, -0.0955533352, -0.1035329531, -0.1116826931, |
|
| 328 |
+ -0.1200077984, -0.1285002850, -0.1371551761, -0.1459766491, |
|
| 329 |
+ -0.1549607071, -0.1640958855, -0.1733808172, -0.1828172548, |
|
| 330 |
+ -0.1923966745, -0.2021250176, -0.2119735853, -0.2219652696, |
|
| 331 |
+ -0.2320690870, -0.2423016884, -0.2526480309, -0.2631053299, |
|
| 332 |
+ -0.2736634040, -0.2843214189, -0.2950716717, -0.3059098575, |
|
| 333 |
+ -0.3168278913, -0.3278113727, -0.3388722693, -0.3499914122, |
|
| 334 |
+ 0.3611589903, 0.3723795546, 0.3836350013, 0.3949211761, |
|
| 335 |
+ 0.4062317676, 0.4175696896, 0.4289119920, 0.4402553754, |
|
| 336 |
+ 0.4515996535, 0.4629308085, 0.4742453214, 0.4855253091, |
|
| 337 |
+ 0.4967708254, 0.5079817500, 0.5191234970, 0.5302240895, |
|
| 338 |
+ 0.5412553448, 0.5522051258, 0.5630789140, 0.5738524131, |
|
| 339 |
+ 0.5845403235, 0.5951123086, 0.6055783538, 0.6159109932, |
|
| 340 |
+ 0.6261242695, 0.6361980107, 0.6461269695, 0.6559016302, |
|
| 341 |
+ 0.6655139880, 0.6749663190, 0.6842353293, 0.6933282376, |
|
| 342 |
+ 0.7022388719, 0.7109410426, 0.7194462634, 0.7277448900, |
|
| 343 |
+ 0.7358211758, 0.7436827863, 0.7513137456, 0.7587080760, |
|
| 344 |
+ 0.7658674865, 0.7727780881, 0.7794287519, 0.7858353120, |
|
| 345 |
+ 0.7919735841, 0.7978466413, 0.8034485751, 0.8087695004, |
|
| 346 |
+ 0.8138191270, 0.8185776004, 0.8230419890, 0.8272275347, |
|
| 347 |
+ 0.8311038457, 0.8346937361, 0.8379717337, 0.8409541392, |
|
| 348 |
+ 0.8436238281, 0.8459818469, 0.8480315777, 0.8497805198, |
|
| 349 |
+ 0.8511971524, 0.8523047035, 0.8531020949, 0.8535720573, |
|
| 350 |
+ 0.8537385600, |
|
| 351 |
+}; |
|
| 352 |
+ |
|
| 353 |
+static const float sbr_noise_table[512][2] = {
|
|
| 354 |
+{-0.99948153278296, -0.59483417516607}, { 0.97113454393991, -0.67528515225647},
|
|
| 355 |
+{ 0.14130051758487, -0.95090983575689}, {-0.47005496701697, -0.37340549728647},
|
|
| 356 |
+{ 0.80705063769351, 0.29653668284408}, {-0.38981478896926, 0.89572605717087},
|
|
| 357 |
+{-0.01053049862020, -0.66959058036166}, {-0.91266367957293, -0.11522938140034},
|
|
| 358 |
+{ 0.54840422910309, 0.75221367176302}, { 0.40009252867955, -0.98929400334421},
|
|
| 359 |
+{-0.99867974711855, -0.88147068645358}, {-0.95531076805040, 0.90908757154593},
|
|
| 360 |
+{-0.45725933317144, -0.56716323646760}, {-0.72929675029275, -0.98008272727324},
|
|
| 361 |
+{ 0.75622801399036, 0.20950329995549}, { 0.07069442601050, -0.78247898470706},
|
|
| 362 |
+{ 0.74496252926055, -0.91169004445807}, {-0.96440182703856, -0.94739918296622},
|
|
| 363 |
+{ 0.30424629369539, -0.49438267012479}, { 0.66565033746925, 0.64652935542491},
|
|
| 364 |
+{ 0.91697008020594, 0.17514097332009}, {-0.70774918760427, 0.52548653416543},
|
|
| 365 |
+{-0.70051415345560, -0.45340028808763}, {-0.99496513054797, -0.90071908066973},
|
|
| 366 |
+{ 0.98164490790123, -0.77463155528697}, {-0.54671580548181, -0.02570928536004},
|
|
| 367 |
+{-0.01689629065389, 0.00287506445732}, {-0.86110349531986, 0.42548583726477},
|
|
| 368 |
+{-0.98892980586032, -0.87881132267556}, { 0.51756627678691, 0.66926784710139},
|
|
| 369 |
+{-0.99635026409640, -0.58107730574765}, {-0.99969370862163, 0.98369989360250},
|
|
| 370 |
+{ 0.55266258627194, 0.59449057465591}, { 0.34581177741673, 0.94879421061866},
|
|
| 371 |
+{ 0.62664209577999, -0.74402970906471}, {-0.77149701404973, -0.33883658042801},
|
|
| 372 |
+{-0.91592244254432, 0.03687901376713}, {-0.76285492357887, -0.91371867919124},
|
|
| 373 |
+{ 0.79788337195331, -0.93180971199849}, { 0.54473080610200, -0.11919206037186},
|
|
| 374 |
+{-0.85639281671058, 0.42429854760451}, {-0.92882402971423, 0.27871809078609},
|
|
| 375 |
+{-0.11708371046774, -0.99800843444966}, { 0.21356749817493, -0.90716295627033},
|
|
| 376 |
+{-0.76191692573909, 0.99768118356265}, { 0.98111043100884, -0.95854459734407},
|
|
| 377 |
+{-0.85913269895572, 0.95766566168880}, {-0.93307242253692, 0.49431757696466},
|
|
| 378 |
+{ 0.30485754879632, -0.70540034357529}, { 0.85289650925190, 0.46766131791044},
|
|
| 379 |
+{ 0.91328082618125, -0.99839597361769}, {-0.05890199924154, 0.70741827819497},
|
|
| 380 |
+{ 0.28398686150148, 0.34633555702188}, { 0.95258164539612, -0.54893416026939},
|
|
| 381 |
+{-0.78566324168507, -0.75568541079691}, {-0.95789495447877, -0.20423194696966},
|
|
| 382 |
+{ 0.82411158711197, 0.96654618432562}, {-0.65185446735885, -0.88734990773289},
|
|
| 383 |
+{-0.93643603134666, 0.99870790442385}, { 0.91427159529618, -0.98290505544444},
|
|
| 384 |
+{-0.70395684036886, 0.58796798221039}, { 0.00563771969365, 0.61768196727244},
|
|
| 385 |
+{ 0.89065051931895, 0.52783352697585}, {-0.68683707712762, 0.80806944710339},
|
|
| 386 |
+{ 0.72165342518718, -0.69259857349564}, {-0.62928247730667, 0.13627037407335},
|
|
| 387 |
+{ 0.29938434065514, -0.46051329682246}, {-0.91781958879280, -0.74012716684186},
|
|
| 388 |
+{ 0.99298717043688, 0.40816610075661}, { 0.82368298622748, -0.74036047190173},
|
|
| 389 |
+{-0.98512833386833, -0.99972330709594}, {-0.95915368242257, -0.99237800466040},
|
|
| 390 |
+{-0.21411126572790, -0.93424819052545}, {-0.68821476106884, -0.26892306315457},
|
|
| 391 |
+{ 0.91851997982317, 0.09358228901785}, {-0.96062769559127, 0.36099095133739},
|
|
| 392 |
+{ 0.51646184922287, -0.71373332873917}, { 0.61130721139669, 0.46950141175917},
|
|
| 393 |
+{ 0.47336129371299, -0.27333178296162}, { 0.90998308703519, 0.96715662938132},
|
|
| 394 |
+{ 0.44844799194357, 0.99211574628306}, { 0.66614891079092, 0.96590176169121},
|
|
| 395 |
+{ 0.74922239129237, -0.89879858826087}, {-0.99571588506485, 0.52785521494349},
|
|
| 396 |
+{ 0.97401082477563, -0.16855870075190}, { 0.72683747733879, -0.48060774432251},
|
|
| 397 |
+{ 0.95432193457128, 0.68849603408441}, {-0.72962208425191, -0.76608443420917},
|
|
| 398 |
+{-0.85359479233537, 0.88738125901579}, {-0.81412430338535, -0.97480768049637},
|
|
| 399 |
+{-0.87930772356786, 0.74748307690436}, {-0.71573331064977, -0.98570608178923},
|
|
| 400 |
+{ 0.83524300028228, 0.83702537075163}, {-0.48086065601423, -0.98848504923531},
|
|
| 401 |
+{ 0.97139128574778, 0.80093621198236}, { 0.51992825347895, 0.80247631400510},
|
|
| 402 |
+{-0.00848591195325, -0.76670128000486}, {-0.70294374303036, 0.55359910445577},
|
|
| 403 |
+{-0.95894428168140, -0.43265504344783}, { 0.97079252950321, 0.09325857238682},
|
|
| 404 |
+{-0.92404293670797, 0.85507704027855}, {-0.69506469500450, 0.98633412625459},
|
|
| 405 |
+{ 0.26559203620024, 0.73314307966524}, { 0.28038443336943, 0.14537913654427},
|
|
| 406 |
+{-0.74138124825523, 0.99310339807762}, {-0.01752795995444, -0.82616635284178},
|
|
| 407 |
+{-0.55126773094930, -0.98898543862153}, { 0.97960898850996, -0.94021446752851},
|
|
| 408 |
+{-0.99196309146936, 0.67019017358456}, {-0.67684928085260, 0.12631491649378},
|
|
| 409 |
+{ 0.09140039465500, -0.20537731453108}, {-0.71658965751996, -0.97788200391224},
|
|
| 410 |
+{ 0.81014640078925, 0.53722648362443}, { 0.40616991671205, -0.26469008598449},
|
|
| 411 |
+{-0.67680188682972, 0.94502052337695}, { 0.86849774348749, -0.18333598647899},
|
|
| 412 |
+{-0.99500381284851, -0.02634122068550}, { 0.84329189340667, 0.10406957462213},
|
|
| 413 |
+{-0.09215968531446, 0.69540012101253}, { 0.99956173327206, -0.12358542001404},
|
|
| 414 |
+{-0.79732779473535, -0.91582524736159}, { 0.96349973642406, 0.96640458041000},
|
|
| 415 |
+{-0.79942778496547, 0.64323902822857}, {-0.11566039853896, 0.28587846253726},
|
|
| 416 |
+{-0.39922954514662, 0.94129601616966}, { 0.99089197565987, -0.92062625581587},
|
|
| 417 |
+{ 0.28631285179909, -0.91035047143603}, {-0.83302725605608, -0.67330410892084},
|
|
| 418 |
+{ 0.95404443402072, 0.49162765398743}, {-0.06449863579434, 0.03250560813135},
|
|
| 419 |
+{-0.99575054486311, 0.42389784469507}, {-0.65501142790847, 0.82546114655624},
|
|
| 420 |
+{-0.81254441908887, -0.51627234660629}, {-0.99646369485481, 0.84490533520752},
|
|
| 421 |
+{ 0.00287840603348, 0.64768261158166}, { 0.70176989408455, -0.20453028573322},
|
|
| 422 |
+{ 0.96361882270190, 0.40706967140989}, {-0.68883758192426, 0.91338958840772},
|
|
| 423 |
+{-0.34875585502238, 0.71472290693300}, { 0.91980081243087, 0.66507455644919},
|
|
| 424 |
+{-0.99009048343881, 0.85868021604848}, { 0.68865791458395, 0.55660316809678},
|
|
| 425 |
+{-0.99484402129368, -0.20052559254934}, { 0.94214511408023, -0.99696425367461},
|
|
| 426 |
+{-0.67414626793544, 0.49548221180078}, {-0.47339353684664, -0.85904328834047},
|
|
| 427 |
+{ 0.14323651387360, -0.94145598222488}, {-0.29268293575672, 0.05759224927952},
|
|
| 428 |
+{ 0.43793861458754, -0.78904969892724}, {-0.36345126374441, 0.64874435357162},
|
|
| 429 |
+{-0.08750604656825, 0.97686944362527}, {-0.96495267812511, -0.53960305946511},
|
|
| 430 |
+{ 0.55526940659947, 0.78891523734774}, { 0.73538215752630, 0.96452072373404},
|
|
| 431 |
+{-0.30889773919437, -0.80664389776860}, { 0.03574995626194, -0.97325616900959},
|
|
| 432 |
+{ 0.98720684660488, 0.48409133691962}, {-0.81689296271203, -0.90827703628298},
|
|
| 433 |
+{ 0.67866860118215, 0.81284503870856}, {-0.15808569732583, 0.85279555024382},
|
|
| 434 |
+{ 0.80723395114371, -0.24717418514605}, { 0.47788757329038, -0.46333147839295},
|
|
| 435 |
+{ 0.96367554763201, 0.38486749303242}, {-0.99143875716818, -0.24945277239809},
|
|
| 436 |
+{ 0.83081876925833, -0.94780851414763}, {-0.58753191905341, 0.01290772389163},
|
|
| 437 |
+{ 0.95538108220960, -0.85557052096538}, {-0.96490920476211, -0.64020970923102},
|
|
| 438 |
+{-0.97327101028521, 0.12378128133110}, { 0.91400366022124, 0.57972471346930},
|
|
| 439 |
+{-0.99925837363824, 0.71084847864067}, {-0.86875903507313, -0.20291699203564},
|
|
| 440 |
+{-0.26240034795124, -0.68264554369108}, {-0.24664412953388, -0.87642273115183},
|
|
| 441 |
+{ 0.02416275806869, 0.27192914288905}, { 0.82068619590515, -0.85087787994476},
|
|
| 442 |
+{ 0.88547373760759, -0.89636802901469}, {-0.18173078152226, -0.26152145156800},
|
|
| 443 |
+{ 0.09355476558534, 0.54845123045604}, {-0.54668414224090, 0.95980774020221},
|
|
| 444 |
+{ 0.37050990604091, -0.59910140383171}, {-0.70373594262891, 0.91227665827081},
|
|
| 445 |
+{-0.34600785879594, -0.99441426144200}, {-0.68774481731008, -0.30238837956299},
|
|
| 446 |
+{-0.26843291251234, 0.83115668004362}, { 0.49072334613242, -0.45359708737775},
|
|
| 447 |
+{ 0.38975993093975, 0.95515358099121}, {-0.97757125224150, 0.05305894580606},
|
|
| 448 |
+{-0.17325552859616, -0.92770672250494}, { 0.99948035025744, 0.58285545563426},
|
|
| 449 |
+{-0.64946246527458, 0.68645507104960}, {-0.12016920576437, -0.57147322153312},
|
|
| 450 |
+{-0.58947456517751, -0.34847132454388}, {-0.41815140454465, 0.16276422358861},
|
|
| 451 |
+{ 0.99885650204884, 0.11136095490444}, {-0.56649614128386, -0.90494866361587},
|
|
| 452 |
+{ 0.94138021032330, 0.35281916733018}, {-0.75725076534641, 0.53650549640587},
|
|
| 453 |
+{ 0.20541973692630, -0.94435144369918}, { 0.99980371023351, 0.79835913565599},
|
|
| 454 |
+{ 0.29078277605775, 0.35393777921520}, {-0.62858772103030, 0.38765693387102},
|
|
| 455 |
+{ 0.43440904467688, -0.98546330463232}, {-0.98298583762390, 0.21021524625209},
|
|
| 456 |
+{ 0.19513029146934, -0.94239832251867}, {-0.95476662400101, 0.98364554179143},
|
|
| 457 |
+{ 0.93379635304810, -0.70881994583682}, {-0.85235410573336, -0.08342347966410},
|
|
| 458 |
+{-0.86425093011245, -0.45795025029466}, { 0.38879779059045, 0.97274429344593},
|
|
| 459 |
+{ 0.92045124735495, -0.62433652524220}, { 0.89162532251878, 0.54950955570563},
|
|
| 460 |
+{-0.36834336949252, 0.96458298020975}, { 0.93891760988045, -0.89968353740388},
|
|
| 461 |
+{ 0.99267657565094, -0.03757034316958}, {-0.94063471614176, 0.41332338538963},
|
|
| 462 |
+{ 0.99740224117019, -0.16830494996370}, {-0.35899413170555, -0.46633226649613},
|
|
| 463 |
+{ 0.05237237274947, -0.25640361602661}, { 0.36703583957424, -0.38653265641875},
|
|
| 464 |
+{ 0.91653180367913, -0.30587628726597}, { 0.69000803499316, 0.90952171386132},
|
|
| 465 |
+{-0.38658751133527, 0.99501571208985}, {-0.29250814029851, 0.37444994344615},
|
|
| 466 |
+{-0.60182204677608, 0.86779651036123}, {-0.97418588163217, 0.96468523666475},
|
|
| 467 |
+{ 0.88461574003963, 0.57508405276414}, { 0.05198933055162, 0.21269661669964},
|
|
| 468 |
+{-0.53499621979720, 0.97241553731237}, {-0.49429560226497, 0.98183865291903},
|
|
| 469 |
+{-0.98935142339139, -0.40249159006933}, {-0.98081380091130, -0.72856895534041},
|
|
| 470 |
+{-0.27338148835532, 0.99950922447209}, { 0.06310802338302, -0.54539587529618},
|
|
| 471 |
+{-0.20461677199539, -0.14209977628489}, { 0.66223843141647, 0.72528579940326},
|
|
| 472 |
+{-0.84764345483665, 0.02372316801261}, {-0.89039863483811, 0.88866581484602},
|
|
| 473 |
+{ 0.95903308477986, 0.76744927173873}, { 0.73504123909879, -0.03747203173192},
|
|
| 474 |
+{-0.31744434966056, -0.36834111883652}, {-0.34110827591623, 0.40211222807691},
|
|
| 475 |
+{ 0.47803883714199, -0.39423219786288}, { 0.98299195879514, 0.01989791390047},
|
|
| 476 |
+{-0.30963073129751, -0.18076720599336}, { 0.99992588229018, -0.26281872094289},
|
|
| 477 |
+{-0.93149731080767, -0.98313162570490}, { 0.99923472302773, -0.80142993767554},
|
|
| 478 |
+{-0.26024169633417, -0.75999759855752}, {-0.35712514743563, 0.19298963768574},
|
|
| 479 |
+{-0.99899084509530, 0.74645156992493}, { 0.86557171579452, 0.55593866696299},
|
|
| 480 |
+{ 0.33408042438752, 0.86185953874709}, { 0.99010736374716, 0.04602397576623},
|
|
| 481 |
+{-0.66694269691195, -0.91643611810148}, { 0.64016792079480, 0.15649530836856},
|
|
| 482 |
+{ 0.99570534804836, 0.45844586038111}, {-0.63431466947340, 0.21079116459234},
|
|
| 483 |
+{-0.07706847005931, -0.89581437101329}, { 0.98590090577724, 0.88241721133981},
|
|
| 484 |
+{ 0.80099335254678, -0.36851896710853}, { 0.78368131392666, 0.45506999802597},
|
|
| 485 |
+{ 0.08707806671691, 0.80938994918745}, {-0.86811883080712, 0.39347308654705},
|
|
| 486 |
+{-0.39466529740375, -0.66809432114456}, { 0.97875325649683, -0.72467840967746},
|
|
| 487 |
+{-0.95038560288864, 0.89563219587625}, { 0.17005239424212, 0.54683053962658},
|
|
| 488 |
+{-0.76910792026848, -0.96226617549298}, { 0.99743281016846, 0.42697157037567},
|
|
| 489 |
+{ 0.95437383549973, 0.97002324109952}, { 0.99578905365569, -0.54106826257356},
|
|
| 490 |
+{ 0.28058259829990, -0.85361420634036}, { 0.85256524470573, -0.64567607735589},
|
|
| 491 |
+{-0.50608540105128, -0.65846015480300}, {-0.97210735183243, -0.23095213067791},
|
|
| 492 |
+{ 0.95424048234441, -0.99240147091219}, {-0.96926570524023, 0.73775654896574},
|
|
| 493 |
+{ 0.30872163214726, 0.41514960556126}, {-0.24523839572639, 0.63206633394807},
|
|
| 494 |
+{-0.33813265086024, -0.38661779441897}, {-0.05826828420146, -0.06940774188029},
|
|
| 495 |
+{-0.22898461455054, 0.97054853316316}, {-0.18509915019881, 0.47565762892084},
|
|
| 496 |
+{-0.10488238045009, -0.87769947402394}, {-0.71886586182037, 0.78030982480538},
|
|
| 497 |
+{ 0.99793873738654, 0.90041310491497}, { 0.57563307626120, -0.91034337352097},
|
|
| 498 |
+{ 0.28909646383717, 0.96307783970534}, { 0.42188998312520, 0.48148651230437},
|
|
| 499 |
+{ 0.93335049681047, -0.43537023883588}, {-0.97087374418267, 0.86636445711364},
|
|
| 500 |
+{ 0.36722871286923, 0.65291654172961}, {-0.81093025665696, 0.08778370229363},
|
|
| 501 |
+{-0.26240603062237, -0.92774095379098}, { 0.83996497984604, 0.55839849139647},
|
|
| 502 |
+{-0.99909615720225, -0.96024605713970}, { 0.74649464155061, 0.12144893606462},
|
|
| 503 |
+{-0.74774595569805, -0.26898062008959}, { 0.95781667469567, -0.79047927052628},
|
|
| 504 |
+{ 0.95472308713099, -0.08588776019550}, { 0.48708332746299, 0.99999041579432},
|
|
| 505 |
+{ 0.46332038247497, 0.10964126185063}, {-0.76497004940162, 0.89210929242238},
|
|
| 506 |
+{ 0.57397389364339, 0.35289703373760}, { 0.75374316974495, 0.96705214651335},
|
|
| 507 |
+{-0.59174397685714, -0.89405370422752}, { 0.75087906691890, -0.29612672982396},
|
|
| 508 |
+{-0.98607857336230, 0.25034911730023}, {-0.40761056640505, -0.90045573444695},
|
|
| 509 |
+{ 0.66929266740477, 0.98629493401748}, {-0.97463695257310, -0.00190223301301},
|
|
| 510 |
+{ 0.90145509409859, 0.99781390365446}, {-0.87259289048043, 0.99233587353666},
|
|
| 511 |
+{-0.91529461447692, -0.15698707534206}, {-0.03305738840705, -0.37205262859764},
|
|
| 512 |
+{ 0.07223051368337, -0.88805001733626}, { 0.99498012188353, 0.97094358113387},
|
|
| 513 |
+{-0.74904939500519, 0.99985483641521}, { 0.04585228574211, 0.99812337444082},
|
|
| 514 |
+{-0.89054954257993, -0.31791913188064}, {-0.83782144651251, 0.97637632547466},
|
|
| 515 |
+{ 0.33454804933804, -0.86231516800408}, {-0.99707579362824, 0.93237990079441},
|
|
| 516 |
+{-0.22827527843994, 0.18874759397997}, { 0.67248046289143, -0.03646211390569},
|
|
| 517 |
+{-0.05146538187944, -0.92599700120679}, { 0.99947295749905, 0.93625229707912},
|
|
| 518 |
+{ 0.66951124390363, 0.98905825623893}, {-0.99602956559179, -0.44654715757688},
|
|
| 519 |
+{ 0.82104905483590, 0.99540741724928}, { 0.99186510988782, 0.72023001312947},
|
|
| 520 |
+{-0.65284592392918, 0.52186723253637}, { 0.93885443798188, -0.74895312615259},
|
|
| 521 |
+{ 0.96735248738388, 0.90891816978629}, {-0.22225968841114, 0.57124029781228},
|
|
| 522 |
+{-0.44132783753414, -0.92688840659280}, {-0.85694974219574, 0.88844532719844},
|
|
| 523 |
+{ 0.91783042091762, -0.46356892383970}, { 0.72556974415690, -0.99899555770747},
|
|
| 524 |
+{-0.99711581834508, 0.58211560180426}, { 0.77638976371966, 0.94321834873819},
|
|
| 525 |
+{ 0.07717324253925, 0.58638399856595}, {-0.56049829194163, 0.82522301569036},
|
|
| 526 |
+{ 0.98398893639988, 0.39467440420569}, { 0.47546946844938, 0.68613044836811},
|
|
| 527 |
+{ 0.65675089314631, 0.18331637134880}, { 0.03273375457980, -0.74933109564108},
|
|
| 528 |
+{-0.38684144784738, 0.51337349030406}, {-0.97346267944545, -0.96549364384098},
|
|
| 529 |
+{-0.53282156061942, -0.91423265091354}, { 0.99817310731176, 0.61133572482148},
|
|
| 530 |
+{-0.50254500772635, -0.88829338134294}, { 0.01995873238855, 0.85223515096765},
|
|
| 531 |
+{ 0.99930381973804, 0.94578896296649}, { 0.82907767600783, -0.06323442598128},
|
|
| 532 |
+{-0.58660709669728, 0.96840773806582}, {-0.17573736667267, -0.48166920859485},
|
|
| 533 |
+{ 0.83434292401346, -0.13023450646997}, { 0.05946491307025, 0.20511047074866},
|
|
| 534 |
+{ 0.81505484574602, -0.94685947861369}, {-0.44976380954860, 0.40894572671545},
|
|
| 535 |
+{-0.89746474625671, 0.99846578838537}, { 0.39677256130792, -0.74854668609359},
|
|
| 536 |
+{-0.07588948563079, 0.74096214084170}, { 0.76343198951445, 0.41746629422634},
|
|
| 537 |
+{-0.74490104699626, 0.94725911744610}, { 0.64880119792759, 0.41336660830571},
|
|
| 538 |
+{ 0.62319537462542, -0.93098313552599}, { 0.42215817594807, -0.07712787385208},
|
|
| 539 |
+{ 0.02704554141885, -0.05417518053666}, { 0.80001773566818, 0.91542195141039},
|
|
| 540 |
+{-0.79351832348816, -0.36208897989136}, { 0.63872359151636, 0.08128252493444},
|
|
| 541 |
+{ 0.52890520960295, 0.60048872455592}, { 0.74238552914587, 0.04491915291044},
|
|
| 542 |
+{ 0.99096131449250, -0.19451182854402}, {-0.80412329643109, -0.88513818199457},
|
|
| 543 |
+{-0.64612616129736, 0.72198674804544}, { 0.11657770663191, -0.83662833815041},
|
|
| 544 |
+{-0.95053182488101, -0.96939905138082}, {-0.62228872928622, 0.82767262846661},
|
|
| 545 |
+{ 0.03004475787316, -0.99738896333384}, {-0.97987214341034, 0.36526129686425},
|
|
| 546 |
+{-0.99986980746200, -0.36021610299715}, { 0.89110648599879, -0.97894250343044},
|
|
| 547 |
+{ 0.10407960510582, 0.77357793811619}, { 0.95964737821728, -0.35435818285502},
|
|
| 548 |
+{ 0.50843233159162, 0.96107691266205}, { 0.17006334670615, -0.76854025314829},
|
|
| 549 |
+{ 0.25872675063360, 0.99893303933816}, {-0.01115998681937, 0.98496019742444},
|
|
| 550 |
+{-0.79598702973261, 0.97138411318894}, {-0.99264708948101, -0.99542822402536},
|
|
| 551 |
+{-0.99829663752818, 0.01877138824311}, {-0.70801016548184, 0.33680685948117},
|
|
| 552 |
+{-0.70467057786826, 0.93272777501857}, { 0.99846021905254, -0.98725746254433},
|
|
| 553 |
+{-0.63364968534650, -0.16473594423746}, {-0.16258217500792, -0.95939125400802},
|
|
| 554 |
+{-0.43645594360633, -0.94805030113284}, {-0.99848471702976, 0.96245166923809},
|
|
| 555 |
+{-0.16796458968998, -0.98987511890470}, {-0.87979225745213, -0.71725725041680},
|
|
| 556 |
+{ 0.44183099021786, -0.93568974498761}, { 0.93310180125532, -0.99913308068246},
|
|
| 557 |
+{-0.93941931782002, -0.56409379640356}, {-0.88590003188677, 0.47624600491382},
|
|
| 558 |
+{ 0.99971463703691, -0.83889954253462}, {-0.75376385639978, 0.00814643438625},
|
|
| 559 |
+{ 0.93887685615875, -0.11284528204636}, { 0.85126435782309, 0.52349251543547},
|
|
| 560 |
+{ 0.39701421446381, 0.81779634174316}, {-0.37024464187437, -0.87071656222959},
|
|
| 561 |
+{-0.36024828242896, 0.34655735648287}, {-0.93388812549209, -0.84476541096429},
|
|
| 562 |
+{-0.65298804552119, -0.18439575450921}, { 0.11960319006843, 0.99899346780168},
|
|
| 563 |
+{ 0.94292565553160, 0.83163906518293}, { 0.75081145286948, -0.35533223142265},
|
|
| 564 |
+{ 0.56721979748394, -0.24076836414499}, { 0.46857766746029, -0.30140233457198},
|
|
| 565 |
+{ 0.97312313923635, -0.99548191630031}, {-0.38299976567017, 0.98516909715427},
|
|
| 566 |
+{ 0.41025800019463, 0.02116736935734}, { 0.09638062008048, 0.04411984381457},
|
|
| 567 |
+{-0.85283249275397, 0.91475563922421}, { 0.88866808958124, -0.99735267083226},
|
|
| 568 |
+{-0.48202429536989, -0.96805608884164}, { 0.27572582416567, 0.58634753335832},
|
|
| 569 |
+{-0.65889129659168, 0.58835634138583}, { 0.98838086953732, 0.99994349600236},
|
|
| 570 |
+{-0.20651349620689, 0.54593044066355}, {-0.62126416356920, -0.59893681700392},
|
|
| 571 |
+{ 0.20320105410437, -0.86879180355289}, {-0.97790548600584, 0.96290806999242},
|
|
| 572 |
+{ 0.11112534735126, 0.21484763313301}, {-0.41368337314182, 0.28216837680365},
|
|
| 573 |
+{ 0.24133038992960, 0.51294362630238}, {-0.66393410674885, -0.08249679629081},
|
|
| 574 |
+{-0.53697829178752, -0.97649903936228}, {-0.97224737889348, 0.22081333579837},
|
|
| 575 |
+{ 0.87392477144549, -0.12796173740361}, { 0.19050361015753, 0.01602615387195},
|
|
| 576 |
+{-0.46353441212724, -0.95249041539006}, {-0.07064096339021, -0.94479803205886},
|
|
| 577 |
+{-0.92444085484466, -0.10457590187436}, {-0.83822593578728, -0.01695043208885},
|
|
| 578 |
+{ 0.75214681811150, -0.99955681042665}, {-0.42102998829339, 0.99720941999394},
|
|
| 579 |
+{-0.72094786237696, -0.35008961934255}, { 0.78843311019251, 0.52851398958271},
|
|
| 580 |
+{ 0.97394027897442, -0.26695944086561}, { 0.99206463477946, -0.57010120849429},
|
|
| 581 |
+{ 0.76789609461795, -0.76519356730966}, {-0.82002421836409, -0.73530179553767},
|
|
| 582 |
+{ 0.81924990025724, 0.99698425250579}, {-0.26719850873357, 0.68903369776193},
|
|
| 583 |
+{-0.43311260380975, 0.85321815947490}, { 0.99194979673836, 0.91876249766422},
|
|
| 584 |
+{-0.80692001248487, -0.32627540663214}, { 0.43080003649976, -0.21919095636638},
|
|
| 585 |
+{ 0.67709491937357, -0.95478075822906}, { 0.56151770568316, -0.70693811747778},
|
|
| 586 |
+{ 0.10831862810749, -0.08628837174592}, { 0.91229417540436, -0.65987351408410},
|
|
| 587 |
+{-0.48972893932274, 0.56289246362686}, {-0.89033658689697, -0.71656563987082},
|
|
| 588 |
+{ 0.65269447475094, 0.65916004833932}, { 0.67439478141121, -0.81684380846796},
|
|
| 589 |
+{-0.47770832416973, -0.16789556203025}, {-0.99715979260878, -0.93565784007648},
|
|
| 590 |
+{-0.90889593602546, 0.62034397054380}, {-0.06618622548177, -0.23812217221359},
|
|
| 591 |
+{ 0.99430266919728, 0.18812555317553}, { 0.97686402381843, -0.28664534366620},
|
|
| 592 |
+{ 0.94813650221268, -0.97506640027128}, {-0.95434497492853, -0.79607978501983},
|
|
| 593 |
+{-0.49104783137150, 0.32895214359663}, { 0.99881175120751, 0.88993983831354},
|
|
| 594 |
+{ 0.50449166760303, -0.85995072408434}, { 0.47162891065108, -0.18680204049569},
|
|
| 595 |
+{-0.62081581361840, 0.75000676218956}, {-0.43867015250812, 0.99998069244322},
|
|
| 596 |
+{ 0.98630563232075, -0.53578899600662}, {-0.61510362277374, -0.89515019899997},
|
|
| 597 |
+{-0.03841517601843, -0.69888815681179}, {-0.30102157304644, -0.07667808922205},
|
|
| 598 |
+{ 0.41881284182683, 0.02188098922282}, {-0.86135454941237, 0.98947480909359},
|
|
| 599 |
+{ 0.67226861393788, -0.13494389011014}, {-0.70737398842068, -0.76547349325992},
|
|
| 600 |
+{ 0.94044946687963, 0.09026201157416}, {-0.82386352534327, 0.08924768823676},
|
|
| 601 |
+{-0.32070666698656, 0.50143421908753}, { 0.57593163224487, -0.98966422921509},
|
|
| 602 |
+{-0.36326018419965, 0.07440243123228}, { 0.99979044674350, -0.14130287347405},
|
|
| 603 |
+{-0.92366023326932, -0.97979298068180}, {-0.44607178518598, -0.54233252016394},
|
|
| 604 |
+{ 0.44226800932956, 0.71326756742752}, { 0.03671907158312, 0.63606389366675},
|
|
| 605 |
+{ 0.52175424682195, -0.85396826735705}, {-0.94701139690956, -0.01826348194255},
|
|
| 606 |
+{-0.98759606946049, 0.82288714303073}, { 0.87434794743625, 0.89399495655433},
|
|
| 607 |
+{-0.93412041758744, 0.41374052024363}, { 0.96063943315511, 0.93116709541280},
|
|
| 608 |
+{ 0.97534253457837, 0.86150930812689}, { 0.99642466504163, 0.70190043427512},
|
|
| 609 |
+{-0.94705089665984, -0.29580042814306}, { 0.91599807087376, -0.98147830385781},
|
|
| 610 |
+}; |
|
| 611 |
+ |
|
| 612 |
+#endif /* AVCODEC_AACSBRDATA_H */ |
| ... | ... |
@@ -30,7 +30,7 @@ |
| 30 | 30 |
#include "libavutil/avutil.h" |
| 31 | 31 |
|
| 32 | 32 |
#define LIBAVCODEC_VERSION_MAJOR 52 |
| 33 |
-#define LIBAVCODEC_VERSION_MINOR 56 |
|
| 33 |
+#define LIBAVCODEC_VERSION_MINOR 57 |
|
| 34 | 34 |
#define LIBAVCODEC_VERSION_MICRO 0 |
| 35 | 35 |
|
| 36 | 36 |
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ |
| ... | ... |
@@ -57,7 +57,7 @@ enum AudioObjectType {
|
| 57 | 57 |
AOT_AAC_LC, ///< Y Low Complexity |
| 58 | 58 |
AOT_AAC_SSR, ///< N (code in SoC repo) Scalable Sample Rate |
| 59 | 59 |
AOT_AAC_LTP, ///< N (code in SoC repo) Long Term Prediction |
| 60 |
- AOT_SBR, ///< N (in progress) Spectral Band Replication |
|
| 60 |
+ AOT_SBR, ///< Y Spectral Band Replication |
|
| 61 | 61 |
AOT_AAC_SCALABLE, ///< N Scalable |
| 62 | 62 |
AOT_TWINVQ, ///< N Twin Vector Quantizer |
| 63 | 63 |
AOT_CELP, ///< N Code Excited Linear Prediction |
| 64 | 64 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,187 @@ |
| 0 |
+/* |
|
| 1 |
+ * Spectral Band Replication definitions and structures |
|
| 2 |
+ * Copyright (c) 2008-2009 Robert Swain ( rob opendot cl ) |
|
| 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 |
+/** |
|
| 23 |
+ * @file libavcodec/sbr.h |
|
| 24 |
+ * Spectral Band Replication definitions and structures |
|
| 25 |
+ * @author Robert Swain ( rob opendot cl ) |
|
| 26 |
+ */ |
|
| 27 |
+ |
|
| 28 |
+#ifndef AVCODEC_SBR_H |
|
| 29 |
+#define AVCODEC_SBR_H |
|
| 30 |
+ |
|
| 31 |
+#include <stdint.h> |
|
| 32 |
+#include "fft.h" |
|
| 33 |
+ |
|
| 34 |
+/** |
|
| 35 |
+ * Spectral Band Replication header - spectrum parameters that invoke a reset if they differ from the previous header. |
|
| 36 |
+ */ |
|
| 37 |
+typedef struct {
|
|
| 38 |
+ uint8_t bs_start_freq; |
|
| 39 |
+ uint8_t bs_stop_freq; |
|
| 40 |
+ uint8_t bs_xover_band; |
|
| 41 |
+ |
|
| 42 |
+ /** |
|
| 43 |
+ * @defgroup bs_header_extra_1 Variables associated with bs_header_extra_1 |
|
| 44 |
+ * @{
|
|
| 45 |
+ */ |
|
| 46 |
+ uint8_t bs_freq_scale; |
|
| 47 |
+ uint8_t bs_alter_scale; |
|
| 48 |
+ uint8_t bs_noise_bands; |
|
| 49 |
+ /** @} */ |
|
| 50 |
+} SpectrumParameters; |
|
| 51 |
+ |
|
| 52 |
+#define SBR_SYNTHESIS_BUF_SIZE ((1280-128)*2) |
|
| 53 |
+ |
|
| 54 |
+/** |
|
| 55 |
+ * Spectral Band Replication per channel data |
|
| 56 |
+ */ |
|
| 57 |
+typedef struct {
|
|
| 58 |
+ /** |
|
| 59 |
+ * @defgroup bitstream Main bitstream data variables |
|
| 60 |
+ * @{
|
|
| 61 |
+ */ |
|
| 62 |
+ unsigned bs_frame_class; |
|
| 63 |
+ unsigned bs_add_harmonic_flag; |
|
| 64 |
+ unsigned bs_num_env[2]; |
|
| 65 |
+ uint8_t bs_freq_res[7]; |
|
| 66 |
+ uint8_t bs_var_bord[2]; |
|
| 67 |
+ uint8_t bs_num_rel[2]; |
|
| 68 |
+ uint8_t bs_rel_bord[2][3]; |
|
| 69 |
+ unsigned bs_pointer; |
|
| 70 |
+ unsigned bs_num_noise; |
|
| 71 |
+ uint8_t bs_df_env[5]; |
|
| 72 |
+ uint8_t bs_df_noise[2]; |
|
| 73 |
+ uint8_t bs_invf_mode[2][5]; |
|
| 74 |
+ uint8_t bs_add_harmonic[48]; |
|
| 75 |
+ unsigned bs_amp_res; |
|
| 76 |
+ /** @} */ |
|
| 77 |
+ |
|
| 78 |
+ /** |
|
| 79 |
+ * @defgroup state State variables |
|
| 80 |
+ * @{
|
|
| 81 |
+ */ |
|
| 82 |
+ DECLARE_ALIGNED(16, float, synthesis_filterbank_samples)[SBR_SYNTHESIS_BUF_SIZE]; |
|
| 83 |
+ DECLARE_ALIGNED(16, float, analysis_filterbank_samples) [1312]; |
|
| 84 |
+ int synthesis_filterbank_samples_offset; |
|
| 85 |
+ ///l_APrev and l_A |
|
| 86 |
+ int e_a[2]; |
|
| 87 |
+ ///Chirp factors |
|
| 88 |
+ float bw_array[5]; |
|
| 89 |
+ ///QMF values of the original signal |
|
| 90 |
+ float W[2][32][32][2]; |
|
| 91 |
+ ///QMF output of the HF adjustor |
|
| 92 |
+ float Y[2][38][64][2]; |
|
| 93 |
+ float g_temp[42][48]; |
|
| 94 |
+ float q_temp[42][48]; |
|
| 95 |
+ uint8_t s_indexmapped[8][48]; |
|
| 96 |
+ ///Envelope scalefactors |
|
| 97 |
+ float env_facs[6][48]; |
|
| 98 |
+ ///Noise scalefactors |
|
| 99 |
+ float noise_facs[3][5]; |
|
| 100 |
+ ///Envelope time borders |
|
| 101 |
+ uint8_t t_env[8]; |
|
| 102 |
+ ///Envelope time border of the last envelope of the previous frame |
|
| 103 |
+ uint8_t t_env_num_env_old; |
|
| 104 |
+ ///Noise time borders |
|
| 105 |
+ uint8_t t_q[3]; |
|
| 106 |
+ unsigned f_indexnoise; |
|
| 107 |
+ unsigned f_indexsine; |
|
| 108 |
+ /** @} */ |
|
| 109 |
+} SBRData; |
|
| 110 |
+ |
|
| 111 |
+/** |
|
| 112 |
+ * Spectral Band Replication |
|
| 113 |
+ */ |
|
| 114 |
+typedef struct {
|
|
| 115 |
+ int sample_rate; |
|
| 116 |
+ int start; |
|
| 117 |
+ int reset; |
|
| 118 |
+ SpectrumParameters spectrum_params; |
|
| 119 |
+ int bs_amp_res_header; |
|
| 120 |
+ /** |
|
| 121 |
+ * @defgroup bs_header_extra_2 variables associated with bs_header_extra_2 |
|
| 122 |
+ * @{
|
|
| 123 |
+ */ |
|
| 124 |
+ unsigned bs_limiter_bands; |
|
| 125 |
+ unsigned bs_limiter_gains; |
|
| 126 |
+ unsigned bs_interpol_freq; |
|
| 127 |
+ unsigned bs_smoothing_mode; |
|
| 128 |
+ /** @} */ |
|
| 129 |
+ unsigned bs_coupling; |
|
| 130 |
+ unsigned k[5]; ///< k0, k1, k2 |
|
| 131 |
+ ///kx', and kx respectively, kx is the first QMF subband where SBR is used. |
|
| 132 |
+ ///kx' is its value from the previous frame |
|
| 133 |
+ unsigned kx[2]; |
|
| 134 |
+ ///M' and M respectively, M is the number of QMF subbands that use SBR. |
|
| 135 |
+ unsigned m[2]; |
|
| 136 |
+ ///The number of frequency bands in f_master |
|
| 137 |
+ unsigned n_master; |
|
| 138 |
+ SBRData data[2]; |
|
| 139 |
+ ///N_Low and N_High respectively, the number of frequency bands for low and high resolution |
|
| 140 |
+ unsigned n[2]; |
|
| 141 |
+ ///Number of noise floor bands |
|
| 142 |
+ unsigned n_q; |
|
| 143 |
+ ///Number of limiter bands |
|
| 144 |
+ unsigned n_lim; |
|
| 145 |
+ ///The master QMF frequency grouping |
|
| 146 |
+ uint16_t f_master[49]; |
|
| 147 |
+ ///Frequency borders for low resolution SBR |
|
| 148 |
+ uint16_t f_tablelow[25]; |
|
| 149 |
+ ///Frequency borders for high resolution SBR |
|
| 150 |
+ uint16_t f_tablehigh[49]; |
|
| 151 |
+ ///Frequency borders for noise floors |
|
| 152 |
+ uint16_t f_tablenoise[6]; |
|
| 153 |
+ ///Frequency borders for the limiter |
|
| 154 |
+ uint16_t f_tablelim[29]; |
|
| 155 |
+ unsigned num_patches; |
|
| 156 |
+ uint8_t patch_num_subbands[6]; |
|
| 157 |
+ uint8_t patch_start_subband[6]; |
|
| 158 |
+ ///QMF low frequency input to the HF generator |
|
| 159 |
+ float X_low[32][40][2]; |
|
| 160 |
+ ///QMF output of the HF generator |
|
| 161 |
+ float X_high[64][40][2]; |
|
| 162 |
+ ///QMF values of the reconstructed signal |
|
| 163 |
+ DECLARE_ALIGNED(16, float, X)[2][32][64]; |
|
| 164 |
+ ///Zeroth coefficient used to filter the subband signals |
|
| 165 |
+ float alpha0[64][2]; |
|
| 166 |
+ ///First coefficient used to filter the subband signals |
|
| 167 |
+ float alpha1[64][2]; |
|
| 168 |
+ ///Dequantized envelope scalefactors, remapped |
|
| 169 |
+ float e_origmapped[7][48]; |
|
| 170 |
+ ///Dequantized noise scalefactors, remapped |
|
| 171 |
+ float q_mapped[7][48]; |
|
| 172 |
+ ///Sinusoidal presence, remapped |
|
| 173 |
+ uint8_t s_mapped[7][48]; |
|
| 174 |
+ ///Estimated envelope |
|
| 175 |
+ float e_curr[7][48]; |
|
| 176 |
+ ///Amplitude adjusted noise scalefactors |
|
| 177 |
+ float q_m[7][48]; |
|
| 178 |
+ ///Sinusoidal levels |
|
| 179 |
+ float s_m[7][48]; |
|
| 180 |
+ float gain[7][48]; |
|
| 181 |
+ DECLARE_ALIGNED(16, float, qmf_filter_scratch)[5][64]; |
|
| 182 |
+ RDFTContext rdft; |
|
| 183 |
+ FFTContext mdct; |
|
| 184 |
+} SpectralBandReplication; |
|
| 185 |
+ |
|
| 186 |
+#endif /* AVCODEC_SBR_H */ |