diff options
author | Aleksoid <aleksoid@users.sourceforge.net> | 2012-03-13 03:22:01 +0400 |
---|---|---|
committer | Aleksoid <aleksoid@users.sourceforge.net> | 2012-03-13 03:22:01 +0400 |
commit | c756962c563dac093821cba13ed9475319c81cba (patch) | |
tree | 29ece63f3b4077830f6b203813df5922f8e34901 /src/filters | |
parent | 5dd4e7b45af6999bd8320bb2bea2eb7bd7bdc898 (diff) |
Fix : MPEGSplitter - fix crash H.264 parser on packet without Nalu start code;
Change : update libav - take aac's file from ffmpeg;
git-svn-id: https://mpc-hc.svn.sourceforge.net/svnroot/mpc-hc/trunk@4141 10f7b99b-c216-0410-bff0-8a66a9350fd8
Diffstat (limited to 'src/filters')
21 files changed, 8927 insertions, 8885 deletions
diff --git a/src/filters/parser/MpegSplitter/MpegSplitter.cpp b/src/filters/parser/MpegSplitter/MpegSplitter.cpp index b8b0b753e..c6efa7e2b 100644 --- a/src/filters/parser/MpegSplitter/MpegSplitter.cpp +++ b/src/filters/parser/MpegSplitter/MpegSplitter.cpp @@ -1794,6 +1794,11 @@ HRESULT CMpegSplitterOutputPin::DeliverPacket(CAutoPtr<Packet> p) p2->Append(*p3);
}
}
+ start = next;
+
+ if(!p2) {
+ continue;
+ }
p2->TrackNumber = m_p->TrackNumber;
p2->bDiscontinuity = m_p->bDiscontinuity;
@@ -1831,8 +1836,6 @@ HRESULT CMpegSplitterOutputPin::DeliverPacket(CAutoPtr<Packet> p) m_p->pmt = p->pmt;
p->pmt = NULL;
-
- start = next;
}
if (start > m_p->GetData()) {
m_p->RemoveAt(0, start - m_p->GetData());
diff --git a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aac.h b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aac.h index a45e758f6..3c8def61b 100644 --- a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aac.h +++ b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aac.h @@ -1,306 +1,306 @@ -/* - * AAC definitions and structures - * Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org ) - * Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com ) - * - * This file is part of FFmpeg. - * - * FFmpeg is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * FFmpeg is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/** - * @file - * AAC definitions and structures - * @author Oded Shimon ( ods15 ods15 dyndns org ) - * @author Maxim Gavrilov ( maxim.gavrilov gmail com ) - */ - -#ifndef AVCODEC_AAC_H -#define AVCODEC_AAC_H - -#include "avcodec.h" -#include "dsputil.h" -#include "fft.h" -#include "mpeg4audio.h" -#include "sbr.h" -#include "fmtconvert.h" - -#include <stdint.h> - -#define MAX_CHANNELS 64 -#define MAX_ELEM_ID 16 - -#define TNS_MAX_ORDER 20 -#define MAX_LTP_LONG_SFB 40 - -enum RawDataBlockType { - TYPE_SCE, - TYPE_CPE, - TYPE_CCE, - TYPE_LFE, - TYPE_DSE, - TYPE_PCE, - TYPE_FIL, - TYPE_END, -}; - -enum ExtensionPayloadID { - EXT_FILL, - EXT_FILL_DATA, - EXT_DATA_ELEMENT, - EXT_DYNAMIC_RANGE = 0xb, - EXT_SBR_DATA = 0xd, - EXT_SBR_DATA_CRC = 0xe, -}; - -enum WindowSequence { - ONLY_LONG_SEQUENCE, - LONG_START_SEQUENCE, - EIGHT_SHORT_SEQUENCE, - LONG_STOP_SEQUENCE, -}; - -enum BandType { - ZERO_BT = 0, ///< Scalefactors and spectral data are all zero. - FIRST_PAIR_BT = 5, ///< This and later band types encode two values (rather than four) with one code word. - ESC_BT = 11, ///< Spectral data are coded with an escape sequence. - NOISE_BT = 13, ///< Spectral data are scaled white noise not coded in the bitstream. - INTENSITY_BT2 = 14, ///< Scalefactor data are intensity stereo positions. - INTENSITY_BT = 15, ///< Scalefactor data are intensity stereo positions. -}; - -#define IS_CODEBOOK_UNSIGNED(x) ((x - 1) & 10) - -enum ChannelPosition { - AAC_CHANNEL_OFF = 0, - AAC_CHANNEL_FRONT = 1, - AAC_CHANNEL_SIDE = 2, - AAC_CHANNEL_BACK = 3, - AAC_CHANNEL_LFE = 4, - AAC_CHANNEL_CC = 5, -}; - -/** - * The point during decoding at which channel coupling is applied. - */ -enum CouplingPoint { - BEFORE_TNS, - BETWEEN_TNS_AND_IMDCT, - AFTER_IMDCT = 3, -}; - -/** - * Output configuration status - */ -enum OCStatus { - OC_NONE, ///< Output unconfigured - OC_TRIAL_PCE, ///< Output configuration under trial specified by an inband PCE - OC_TRIAL_FRAME, ///< Output configuration under trial specified by a frame header - OC_GLOBAL_HDR, ///< Output configuration set in a global header but not yet locked - OC_LOCKED, ///< Output configuration locked in place -}; - -/** - * Predictor State - */ -typedef struct { - float cor0; - float cor1; - float var0; - float var1; - float r0; - float r1; -} PredictorState; - -#define MAX_PREDICTORS 672 - -#define SCALE_DIV_512 36 ///< scalefactor difference that corresponds to scale difference in 512 times -#define SCALE_ONE_POS 140 ///< scalefactor index that corresponds to scale=1.0 -#define SCALE_MAX_POS 255 ///< scalefactor index maximum value -#define SCALE_MAX_DIFF 60 ///< maximum scalefactor difference allowed by standard -#define SCALE_DIFF_ZERO 60 ///< codebook index corresponding to zero scalefactor indices difference -#define POW_SF2_ZERO 200 ///< ff_aac_pow2sf_tab index corresponding to pow(2, 0); - -/** - * Long Term Prediction - */ -typedef struct { - int8_t present; - int16_t lag; - float coef; - int8_t used[MAX_LTP_LONG_SFB]; -} LongTermPrediction; - -/** - * Individual Channel Stream - */ -typedef struct { - uint8_t max_sfb; ///< number of scalefactor bands per group - enum WindowSequence window_sequence[2]; - uint8_t use_kb_window[2]; ///< If set, use Kaiser-Bessel window, otherwise use a sinus window. - int num_window_groups; - uint8_t group_len[8]; - LongTermPrediction ltp; - const uint16_t *swb_offset; ///< table of offsets to the lowest spectral coefficient of a scalefactor band, sfb, for a particular window - const uint8_t *swb_sizes; ///< table of scalefactor band sizes for a particular window - int num_swb; ///< number of scalefactor window bands - int num_windows; - int tns_max_bands; - int predictor_present; - int predictor_initialized; - int predictor_reset_group; - uint8_t prediction_used[41]; -} IndividualChannelStream; - -/** - * Temporal Noise Shaping - */ -typedef struct { - int present; - int n_filt[8]; - int length[8][4]; - int direction[8][4]; - int order[8][4]; - float coef[8][4][TNS_MAX_ORDER]; -} TemporalNoiseShaping; - -/** - * Dynamic Range Control - decoded from the bitstream but not processed further. - */ -typedef struct { - int pce_instance_tag; ///< Indicates with which program the DRC info is associated. - int dyn_rng_sgn[17]; ///< DRC sign information; 0 - positive, 1 - negative - int dyn_rng_ctl[17]; ///< DRC magnitude information - int exclude_mask[MAX_CHANNELS]; ///< Channels to be excluded from DRC processing. - int band_incr; ///< Number of DRC bands greater than 1 having DRC info. - int interpolation_scheme; ///< Indicates the interpolation scheme used in the SBR QMF domain. - int band_top[17]; ///< Indicates the top of the i-th DRC band in units of 4 spectral lines. - int prog_ref_level; /**< A reference level for the long-term program audio level for all - * channels combined. - */ -} DynamicRangeControl; - -typedef struct { - int num_pulse; - int start; - int pos[4]; - int amp[4]; -} Pulse; - -/** - * coupling parameters - */ -typedef struct { - enum CouplingPoint coupling_point; ///< The point during decoding at which coupling is applied. - int num_coupled; ///< number of target elements - enum RawDataBlockType type[8]; ///< Type of channel element to be coupled - SCE or CPE. - int id_select[8]; ///< element id - int ch_select[8]; /**< [0] shared list of gains; [1] list of gains for right channel; - * [2] list of gains for left channel; [3] lists of gains for both channels - */ - float gain[16][120]; -} ChannelCoupling; - -/** - * Single Channel Element - used for both SCE and LFE elements. - */ -typedef struct { - IndividualChannelStream ics; - TemporalNoiseShaping tns; - Pulse pulse; - enum BandType band_type[128]; ///< band types - int band_type_run_end[120]; ///< band type run end points - float sf[120]; ///< scalefactors - int sf_idx[128]; ///< scalefactor indices (used by encoder) - uint8_t zeroes[128]; ///< band is not coded (used by encoder) - DECLARE_ALIGNED(32, float, coeffs)[1024]; ///< coefficients for IMDCT - DECLARE_ALIGNED(32, float, saved)[1024]; ///< overlap - DECLARE_ALIGNED(32, float, ret)[2048]; ///< PCM output - DECLARE_ALIGNED(16, float, ltp_state)[3072]; ///< time signal for LTP - PredictorState predictor_state[MAX_PREDICTORS]; -} SingleChannelElement; - -/** - * channel element - generic struct for SCE/CPE/CCE/LFE - */ -typedef struct { - // CPE specific - int common_window; ///< Set if channels share a common 'IndividualChannelStream' in bitstream. - int ms_mode; ///< Signals mid/side stereo flags coding mode (used by encoder) - uint8_t ms_mask[128]; ///< Set if mid/side stereo is used for each scalefactor window band - // shared - SingleChannelElement ch[2]; - // CCE specific - ChannelCoupling coup; - SpectralBandReplication sbr; -} ChannelElement; - -/** - * main AAC context - */ -typedef struct { - AVCodecContext *avctx; - AVFrame frame; - - MPEG4AudioConfig m4ac; - - int is_saved; ///< Set if elements have stored overlap from previous frame. - DynamicRangeControl che_drc; - - /** - * @name Channel element related data - * @{ - */ - uint8_t layout_map[MAX_ELEM_ID*4][3]; - int layout_map_tags; - ChannelElement *che[4][MAX_ELEM_ID]; - ChannelElement *tag_che_map[4][MAX_ELEM_ID]; - int tags_mapped; - /** @} */ - - /** - * @name temporary aligned temporary buffers - * (We do not want to have these on the stack.) - * @{ - */ - DECLARE_ALIGNED(32, float, buf_mdct)[1024]; - /** @} */ - - /** - * @name Computed / set up during initialization - * @{ - */ - FFTContext mdct; - FFTContext mdct_small; - FFTContext mdct_ltp; - DSPContext dsp; - FmtConvertContext fmt_conv; - int random_state; - /** @} */ - - /** - * @name Members used for output interleaving - * @{ - */ - float *output_data[MAX_CHANNELS]; ///< Points to each element's 'ret' buffer (PCM output). - /** @} */ - - DECLARE_ALIGNED(32, float, temp)[128]; - - enum OCStatus output_configured; - int warned_num_aac_frames; -} AACContext; - -#endif /* AVCODEC_AAC_H */ +/*
+ * AAC definitions and structures
+ * Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org )
+ * Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com )
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * AAC definitions and structures
+ * @author Oded Shimon ( ods15 ods15 dyndns org )
+ * @author Maxim Gavrilov ( maxim.gavrilov gmail com )
+ */
+
+#ifndef AVCODEC_AAC_H
+#define AVCODEC_AAC_H
+
+#include "avcodec.h"
+#include "dsputil.h"
+#include "fft.h"
+#include "mpeg4audio.h"
+#include "sbr.h"
+#include "fmtconvert.h"
+
+#include <stdint.h>
+
+#define MAX_CHANNELS 64
+#define MAX_ELEM_ID 16
+
+#define TNS_MAX_ORDER 20
+#define MAX_LTP_LONG_SFB 40
+
+enum RawDataBlockType {
+ TYPE_SCE,
+ TYPE_CPE,
+ TYPE_CCE,
+ TYPE_LFE,
+ TYPE_DSE,
+ TYPE_PCE,
+ TYPE_FIL,
+ TYPE_END,
+};
+
+enum ExtensionPayloadID {
+ EXT_FILL,
+ EXT_FILL_DATA,
+ EXT_DATA_ELEMENT,
+ EXT_DYNAMIC_RANGE = 0xb,
+ EXT_SBR_DATA = 0xd,
+ EXT_SBR_DATA_CRC = 0xe,
+};
+
+enum WindowSequence {
+ ONLY_LONG_SEQUENCE,
+ LONG_START_SEQUENCE,
+ EIGHT_SHORT_SEQUENCE,
+ LONG_STOP_SEQUENCE,
+};
+
+enum BandType {
+ ZERO_BT = 0, ///< Scalefactors and spectral data are all zero.
+ FIRST_PAIR_BT = 5, ///< This and later band types encode two values (rather than four) with one code word.
+ ESC_BT = 11, ///< Spectral data are coded with an escape sequence.
+ NOISE_BT = 13, ///< Spectral data are scaled white noise not coded in the bitstream.
+ INTENSITY_BT2 = 14, ///< Scalefactor data are intensity stereo positions.
+ INTENSITY_BT = 15, ///< Scalefactor data are intensity stereo positions.
+};
+
+#define IS_CODEBOOK_UNSIGNED(x) ((x - 1) & 10)
+
+enum ChannelPosition {
+ AAC_CHANNEL_OFF = 0,
+ AAC_CHANNEL_FRONT = 1,
+ AAC_CHANNEL_SIDE = 2,
+ AAC_CHANNEL_BACK = 3,
+ AAC_CHANNEL_LFE = 4,
+ AAC_CHANNEL_CC = 5,
+};
+
+/**
+ * The point during decoding at which channel coupling is applied.
+ */
+enum CouplingPoint {
+ BEFORE_TNS,
+ BETWEEN_TNS_AND_IMDCT,
+ AFTER_IMDCT = 3,
+};
+
+/**
+ * Output configuration status
+ */
+enum OCStatus {
+ OC_NONE, ///< Output unconfigured
+ OC_TRIAL_PCE, ///< Output configuration under trial specified by an inband PCE
+ OC_TRIAL_FRAME, ///< Output configuration under trial specified by a frame header
+ OC_GLOBAL_HDR, ///< Output configuration set in a global header but not yet locked
+ OC_LOCKED, ///< Output configuration locked in place
+};
+
+/**
+ * Predictor State
+ */
+typedef struct {
+ float cor0;
+ float cor1;
+ float var0;
+ float var1;
+ float r0;
+ float r1;
+} PredictorState;
+
+#define MAX_PREDICTORS 672
+
+#define SCALE_DIV_512 36 ///< scalefactor difference that corresponds to scale difference in 512 times
+#define SCALE_ONE_POS 140 ///< scalefactor index that corresponds to scale=1.0
+#define SCALE_MAX_POS 255 ///< scalefactor index maximum value
+#define SCALE_MAX_DIFF 60 ///< maximum scalefactor difference allowed by standard
+#define SCALE_DIFF_ZERO 60 ///< codebook index corresponding to zero scalefactor indices difference
+#define POW_SF2_ZERO 200 ///< ff_aac_pow2sf_tab index corresponding to pow(2, 0);
+
+/**
+ * Long Term Prediction
+ */
+typedef struct {
+ int8_t present;
+ int16_t lag;
+ float coef;
+ int8_t used[MAX_LTP_LONG_SFB];
+} LongTermPrediction;
+
+/**
+ * Individual Channel Stream
+ */
+typedef struct {
+ uint8_t max_sfb; ///< number of scalefactor bands per group
+ enum WindowSequence window_sequence[2];
+ uint8_t use_kb_window[2]; ///< If set, use Kaiser-Bessel window, otherwise use a sinus window.
+ int num_window_groups;
+ uint8_t group_len[8];
+ LongTermPrediction ltp;
+ const uint16_t *swb_offset; ///< table of offsets to the lowest spectral coefficient of a scalefactor band, sfb, for a particular window
+ const uint8_t *swb_sizes; ///< table of scalefactor band sizes for a particular window
+ int num_swb; ///< number of scalefactor window bands
+ int num_windows;
+ int tns_max_bands;
+ int predictor_present;
+ int predictor_initialized;
+ int predictor_reset_group;
+ uint8_t prediction_used[41];
+} IndividualChannelStream;
+
+/**
+ * Temporal Noise Shaping
+ */
+typedef struct {
+ int present;
+ int n_filt[8];
+ int length[8][4];
+ int direction[8][4];
+ int order[8][4];
+ float coef[8][4][TNS_MAX_ORDER];
+} TemporalNoiseShaping;
+
+/**
+ * Dynamic Range Control - decoded from the bitstream but not processed further.
+ */
+typedef struct {
+ int pce_instance_tag; ///< Indicates with which program the DRC info is associated.
+ int dyn_rng_sgn[17]; ///< DRC sign information; 0 - positive, 1 - negative
+ int dyn_rng_ctl[17]; ///< DRC magnitude information
+ int exclude_mask[MAX_CHANNELS]; ///< Channels to be excluded from DRC processing.
+ int band_incr; ///< Number of DRC bands greater than 1 having DRC info.
+ int interpolation_scheme; ///< Indicates the interpolation scheme used in the SBR QMF domain.
+ int band_top[17]; ///< Indicates the top of the i-th DRC band in units of 4 spectral lines.
+ int prog_ref_level; /**< A reference level for the long-term program audio level for all
+ * channels combined.
+ */
+} DynamicRangeControl;
+
+typedef struct {
+ int num_pulse;
+ int start;
+ int pos[4];
+ int amp[4];
+} Pulse;
+
+/**
+ * coupling parameters
+ */
+typedef struct {
+ enum CouplingPoint coupling_point; ///< The point during decoding at which coupling is applied.
+ int num_coupled; ///< number of target elements
+ enum RawDataBlockType type[8]; ///< Type of channel element to be coupled - SCE or CPE.
+ int id_select[8]; ///< element id
+ int ch_select[8]; /**< [0] shared list of gains; [1] list of gains for right channel;
+ * [2] list of gains for left channel; [3] lists of gains for both channels
+ */
+ float gain[16][120];
+} ChannelCoupling;
+
+/**
+ * Single Channel Element - used for both SCE and LFE elements.
+ */
+typedef struct {
+ IndividualChannelStream ics;
+ TemporalNoiseShaping tns;
+ Pulse pulse;
+ enum BandType band_type[128]; ///< band types
+ int band_type_run_end[120]; ///< band type run end points
+ float sf[120]; ///< scalefactors
+ int sf_idx[128]; ///< scalefactor indices (used by encoder)
+ uint8_t zeroes[128]; ///< band is not coded (used by encoder)
+ DECLARE_ALIGNED(32, float, coeffs)[1024]; ///< coefficients for IMDCT
+ DECLARE_ALIGNED(32, float, saved)[1024]; ///< overlap
+ DECLARE_ALIGNED(32, float, ret)[2048]; ///< PCM output
+ DECLARE_ALIGNED(16, float, ltp_state)[3072]; ///< time signal for LTP
+ PredictorState predictor_state[MAX_PREDICTORS];
+} SingleChannelElement;
+
+/**
+ * channel element - generic struct for SCE/CPE/CCE/LFE
+ */
+typedef struct {
+ // CPE specific
+ int common_window; ///< Set if channels share a common 'IndividualChannelStream' in bitstream.
+ int ms_mode; ///< Signals mid/side stereo flags coding mode (used by encoder)
+ uint8_t ms_mask[128]; ///< Set if mid/side stereo is used for each scalefactor window band
+ // shared
+ SingleChannelElement ch[2];
+ // CCE specific
+ ChannelCoupling coup;
+ SpectralBandReplication sbr;
+} ChannelElement;
+
+/**
+ * main AAC context
+ */
+typedef struct {
+ AVCodecContext *avctx;
+ AVFrame frame;
+
+ MPEG4AudioConfig m4ac;
+
+ int is_saved; ///< Set if elements have stored overlap from previous frame.
+ DynamicRangeControl che_drc;
+
+ /**
+ * @name Channel element related data
+ * @{
+ */
+ uint8_t layout_map[MAX_ELEM_ID*4][3];
+ int layout_map_tags;
+ ChannelElement *che[4][MAX_ELEM_ID];
+ ChannelElement *tag_che_map[4][MAX_ELEM_ID];
+ int tags_mapped;
+ /** @} */
+
+ /**
+ * @name temporary aligned temporary buffers
+ * (We do not want to have these on the stack.)
+ * @{
+ */
+ DECLARE_ALIGNED(32, float, buf_mdct)[1024];
+ /** @} */
+
+ /**
+ * @name Computed / set up during initialization
+ * @{
+ */
+ FFTContext mdct;
+ FFTContext mdct_small;
+ FFTContext mdct_ltp;
+ DSPContext dsp;
+ FmtConvertContext fmt_conv;
+ int random_state;
+ /** @} */
+
+ /**
+ * @name Members used for output interleaving
+ * @{
+ */
+ float *output_data[MAX_CHANNELS]; ///< Points to each element's 'ret' buffer (PCM output).
+ /** @} */
+
+ DECLARE_ALIGNED(32, float, temp)[128];
+
+ enum OCStatus output_configured;
+ int warned_num_aac_frames;
+} AACContext;
+
+#endif /* AVCODEC_AAC_H */
diff --git a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aac_ac3_parser.c b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aac_ac3_parser.c index 8132ce899..f6be2ce75 100644 --- a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aac_ac3_parser.c +++ b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aac_ac3_parser.c @@ -1,103 +1,103 @@ -/* - * Common AAC and AC-3 parser - * Copyright (c) 2003 Fabrice Bellard - * Copyright (c) 2003 Michael Niedermayer - * - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "parser.h" -#include "aac_ac3_parser.h" - -int ff_aac_ac3_parse(AVCodecParserContext *s1, - AVCodecContext *avctx, - const uint8_t **poutbuf, int *poutbuf_size, - const uint8_t *buf, int buf_size) -{ - AACAC3ParseContext *s = s1->priv_data; - ParseContext *pc = &s->pc; - int len, i; - int new_frame_start; - -get_next: - i=END_NOT_FOUND; - if(s->remaining_size <= buf_size){ - if(s->remaining_size && !s->need_next_header){ - i= s->remaining_size; - s->remaining_size = 0; - }else{ //we need a header first - len=0; - for(i=s->remaining_size; i<buf_size; i++){ - s->state = (s->state<<8) + buf[i]; - if((len=s->sync(s->state, s, &s->need_next_header, &new_frame_start))) - break; - } - if(len<=0){ - i=END_NOT_FOUND; - }else{ - s->state=0; - i-= s->header_size -1; - s->remaining_size = len; - if(!new_frame_start || pc->index+i<=0){ - s->remaining_size += i; - goto get_next; - } - } - } - } - - if(ff_combine_frame(pc, i, &buf, &buf_size)<0){ - s->remaining_size -= FFMIN(s->remaining_size, buf_size); - *poutbuf = NULL; - *poutbuf_size = 0; - return buf_size; - } - - *poutbuf = buf; - *poutbuf_size = buf_size; - - /* update codec info */ - if(s->codec_id) - avctx->codec_id = s->codec_id; - - /* Due to backwards compatible HE-AAC the sample rate, channel count, - and total number of samples found in an AAC ADTS header are not - reliable. Bit rate is still accurate because the total frame duration in - seconds is still correct (as is the number of bits in the frame). */ - if (avctx->codec_id != CODEC_ID_AAC) { - avctx->sample_rate = s->sample_rate; - - /* allow downmixing to stereo (or mono for AC-3) */ - if(avctx->request_channels > 0 && - avctx->request_channels < s->channels && - (avctx->request_channels <= 2 || - (avctx->request_channels == 1 && - (avctx->codec_id == CODEC_ID_AC3 || - avctx->codec_id == CODEC_ID_EAC3)))) { - avctx->channels = avctx->request_channels; - } else { - avctx->channels = s->channels; - avctx->channel_layout = s->channel_layout; - } - s1->duration = s->samples; - avctx->audio_service_type = s->service_type; - } - - avctx->bit_rate = s->bit_rate; - - return i; -} +/*
+ * Common AAC and AC-3 parser
+ * Copyright (c) 2003 Fabrice Bellard
+ * Copyright (c) 2003 Michael Niedermayer
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "parser.h"
+#include "aac_ac3_parser.h"
+
+int ff_aac_ac3_parse(AVCodecParserContext *s1,
+ AVCodecContext *avctx,
+ const uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size)
+{
+ AACAC3ParseContext *s = s1->priv_data;
+ ParseContext *pc = &s->pc;
+ int len, i;
+ int new_frame_start;
+
+get_next:
+ i=END_NOT_FOUND;
+ if(s->remaining_size <= buf_size){
+ if(s->remaining_size && !s->need_next_header){
+ i= s->remaining_size;
+ s->remaining_size = 0;
+ }else{ //we need a header first
+ len=0;
+ for(i=s->remaining_size; i<buf_size; i++){
+ s->state = (s->state<<8) + buf[i];
+ if((len=s->sync(s->state, s, &s->need_next_header, &new_frame_start)))
+ break;
+ }
+ if(len<=0){
+ i=END_NOT_FOUND;
+ }else{
+ s->state=0;
+ i-= s->header_size -1;
+ s->remaining_size = len;
+ if(!new_frame_start || pc->index+i<=0){
+ s->remaining_size += i;
+ goto get_next;
+ }
+ }
+ }
+ }
+
+ if(ff_combine_frame(pc, i, &buf, &buf_size)<0){
+ s->remaining_size -= FFMIN(s->remaining_size, buf_size);
+ *poutbuf = NULL;
+ *poutbuf_size = 0;
+ return buf_size;
+ }
+
+ *poutbuf = buf;
+ *poutbuf_size = buf_size;
+
+ /* update codec info */
+ if(s->codec_id)
+ avctx->codec_id = s->codec_id;
+
+ /* Due to backwards compatible HE-AAC the sample rate, channel count,
+ and total number of samples found in an AAC ADTS header are not
+ reliable. Bit rate is still accurate because the total frame duration in
+ seconds is still correct (as is the number of bits in the frame). */
+ if (avctx->codec_id != CODEC_ID_AAC) {
+ avctx->sample_rate = s->sample_rate;
+
+ /* allow downmixing to stereo (or mono for AC-3) */
+ if(avctx->request_channels > 0 &&
+ avctx->request_channels < s->channels &&
+ (avctx->request_channels <= 2 ||
+ (avctx->request_channels == 1 &&
+ (avctx->codec_id == CODEC_ID_AC3 ||
+ avctx->codec_id == CODEC_ID_EAC3)))) {
+ avctx->channels = avctx->request_channels;
+ } else {
+ avctx->channels = s->channels;
+ avctx->channel_layout = s->channel_layout;
+ }
+ s1->duration = s->samples;
+ avctx->audio_service_type = s->service_type;
+ }
+
+ avctx->bit_rate = s->bit_rate;
+
+ return i;
+}
diff --git a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aac_ac3_parser.h b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aac_ac3_parser.h index 990a91d9d..e8d7584e7 100644 --- a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aac_ac3_parser.h +++ b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aac_ac3_parser.h @@ -3,20 +3,20 @@ * Copyright (c) 2003 Fabrice Bellard
* Copyright (c) 2003 Michael Niedermayer
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
diff --git a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aac_tablegen.h b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aac_tablegen.h index 8773d9b97..c2b847ee4 100644 --- a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aac_tablegen.h +++ b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aac_tablegen.h @@ -1,43 +1,43 @@ -/* - * Header file for hardcoded AAC tables - * - * Copyright (c) 2010 Alex Converse <alex.converse@gmail.com> - * - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef AVCODEC_AAC_TABLEGEN_H -#define AVCODEC_AAC_TABLEGEN_H - -#include "aac_tablegen_decl.h" - -#if CONFIG_HARDCODED_TABLES -#include "libavcodec/aac_tables.h" -#else -#include "libavutil/mathematics.h" -#include "aac.h" -float ff_aac_pow2sf_tab[428]; - -void ff_aac_tableinit(void) -{ - int i; - for (i = 0; i < 428; i++) - ff_aac_pow2sf_tab[i] = pow(2, (i - POW_SF2_ZERO) / 4.); -} -#endif /* CONFIG_HARDCODED_TABLES */ - -#endif /* AVCODEC_AAC_TABLEGEN_H */ +/*
+ * Header file for hardcoded AAC tables
+ *
+ * Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_AAC_TABLEGEN_H
+#define AVCODEC_AAC_TABLEGEN_H
+
+#include "aac_tablegen_decl.h"
+
+#if CONFIG_HARDCODED_TABLES
+#include "libavcodec/aac_tables.h"
+#else
+#include "libavutil/mathematics.h"
+#include "aac.h"
+float ff_aac_pow2sf_tab[428];
+
+void ff_aac_tableinit(void)
+{
+ int i;
+ for (i = 0; i < 428; i++)
+ ff_aac_pow2sf_tab[i] = pow(2, (i - POW_SF2_ZERO) / 4.);
+}
+#endif /* CONFIG_HARDCODED_TABLES */
+
+#endif /* AVCODEC_AAC_TABLEGEN_H */
diff --git a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aac_tablegen_decl.h b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aac_tablegen_decl.h index 496ca0c67..d6fc29c49 100644 --- a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aac_tablegen_decl.h +++ b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aac_tablegen_decl.h @@ -1,34 +1,34 @@ -/* - * Header file for hardcoded AAC tables - * - * Copyright (c) 2010 Alex Converse <alex.converse@gmail.com> - * - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef AVCODEC_AAC_TABLEGEN_DECL_H -#define AVCODEC_AAC_TABLEGEN_DECL_H - -#if CONFIG_HARDCODED_TABLES -#define ff_aac_tableinit() -extern const float ff_aac_pow2sf_tab[428]; -#else -void ff_aac_tableinit(void); -extern float ff_aac_pow2sf_tab[428]; -#endif /* CONFIG_HARDCODED_TABLES */ - -#endif /* AVCODEC_AAC_TABLEGEN_DECL_H */ +/*
+ * Header file for hardcoded AAC tables
+ *
+ * Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_AAC_TABLEGEN_DECL_H
+#define AVCODEC_AAC_TABLEGEN_DECL_H
+
+#if CONFIG_HARDCODED_TABLES
+#define ff_aac_tableinit()
+extern const float ff_aac_pow2sf_tab[428];
+#else
+void ff_aac_tableinit(void);
+extern float ff_aac_pow2sf_tab[428];
+#endif /* CONFIG_HARDCODED_TABLES */
+
+#endif /* AVCODEC_AAC_TABLEGEN_DECL_H */
diff --git a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacadtsdec.c b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacadtsdec.c index 30f92e0b1..4f0beba1a 100644 --- a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacadtsdec.c +++ b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacadtsdec.c @@ -1,70 +1,70 @@ -/* - * Audio and Video frame extraction - * Copyright (c) 2003 Fabrice Bellard - * Copyright (c) 2003 Michael Niedermayer - * Copyright (c) 2009 Alex Converse - * - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "aac_ac3_parser.h" -#include "aacadtsdec.h" -#include "get_bits.h" -#include "mpeg4audio.h" - -int avpriv_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr) -{ - int size, rdb, ch, sr; - int aot, crc_abs; - - if(get_bits(gbc, 12) != 0xfff) - return AAC_AC3_PARSE_ERROR_SYNC; - - skip_bits1(gbc); /* id */ - skip_bits(gbc, 2); /* layer */ - crc_abs = get_bits1(gbc); /* protection_absent */ - aot = get_bits(gbc, 2); /* profile_objecttype */ - sr = get_bits(gbc, 4); /* sample_frequency_index */ - if(!avpriv_mpeg4audio_sample_rates[sr]) - return AAC_AC3_PARSE_ERROR_SAMPLE_RATE; - skip_bits1(gbc); /* private_bit */ - ch = get_bits(gbc, 3); /* channel_configuration */ - - skip_bits1(gbc); /* original/copy */ - skip_bits1(gbc); /* home */ - - /* adts_variable_header */ - skip_bits1(gbc); /* copyright_identification_bit */ - skip_bits1(gbc); /* copyright_identification_start */ - size = get_bits(gbc, 13); /* aac_frame_length */ - if(size < AAC_ADTS_HEADER_SIZE) - return AAC_AC3_PARSE_ERROR_FRAME_SIZE; - - skip_bits(gbc, 11); /* adts_buffer_fullness */ - rdb = get_bits(gbc, 2); /* number_of_raw_data_blocks_in_frame */ - - hdr->object_type = aot + 1; - hdr->chan_config = ch; - hdr->crc_absent = crc_abs; - hdr->num_aac_frames = rdb + 1; - hdr->sampling_index = sr; - hdr->sample_rate = avpriv_mpeg4audio_sample_rates[sr]; - hdr->samples = (rdb + 1) * 1024; - hdr->bit_rate = size * 8 * hdr->sample_rate / hdr->samples; - - return size; -} +/*
+ * Audio and Video frame extraction
+ * Copyright (c) 2003 Fabrice Bellard
+ * Copyright (c) 2003 Michael Niedermayer
+ * Copyright (c) 2009 Alex Converse
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "aac_ac3_parser.h"
+#include "aacadtsdec.h"
+#include "get_bits.h"
+#include "mpeg4audio.h"
+
+int avpriv_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr)
+{
+ int size, rdb, ch, sr;
+ int aot, crc_abs;
+
+ if(get_bits(gbc, 12) != 0xfff)
+ return AAC_AC3_PARSE_ERROR_SYNC;
+
+ skip_bits1(gbc); /* id */
+ skip_bits(gbc, 2); /* layer */
+ crc_abs = get_bits1(gbc); /* protection_absent */
+ aot = get_bits(gbc, 2); /* profile_objecttype */
+ sr = get_bits(gbc, 4); /* sample_frequency_index */
+ if(!avpriv_mpeg4audio_sample_rates[sr])
+ return AAC_AC3_PARSE_ERROR_SAMPLE_RATE;
+ skip_bits1(gbc); /* private_bit */
+ ch = get_bits(gbc, 3); /* channel_configuration */
+
+ skip_bits1(gbc); /* original/copy */
+ skip_bits1(gbc); /* home */
+
+ /* adts_variable_header */
+ skip_bits1(gbc); /* copyright_identification_bit */
+ skip_bits1(gbc); /* copyright_identification_start */
+ size = get_bits(gbc, 13); /* aac_frame_length */
+ if(size < AAC_ADTS_HEADER_SIZE)
+ return AAC_AC3_PARSE_ERROR_FRAME_SIZE;
+
+ skip_bits(gbc, 11); /* adts_buffer_fullness */
+ rdb = get_bits(gbc, 2); /* number_of_raw_data_blocks_in_frame */
+
+ hdr->object_type = aot + 1;
+ hdr->chan_config = ch;
+ hdr->crc_absent = crc_abs;
+ hdr->num_aac_frames = rdb + 1;
+ hdr->sampling_index = sr;
+ hdr->sample_rate = avpriv_mpeg4audio_sample_rates[sr];
+ hdr->samples = (rdb + 1) * 1024;
+ hdr->bit_rate = size * 8 * hdr->sample_rate / hdr->samples;
+
+ return size;
+}
diff --git a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacadtsdec.h b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacadtsdec.h index 60fdd221a..3d8601892 100644 --- a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacadtsdec.h +++ b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacadtsdec.h @@ -1,54 +1,54 @@ -/* - * AAC ADTS header decoding prototypes and structures - * Copyright (c) 2003 Fabrice Bellard - * Copyright (c) 2003 Michael Niedermayer - * - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef AVCODEC_AACADTSDEC_H -#define AVCODEC_AACADTSDEC_H - -#include <stdint.h> -#include "get_bits.h" - -#define AAC_ADTS_HEADER_SIZE 7 - -typedef struct { - uint32_t sample_rate; - uint32_t samples; - uint32_t bit_rate; - uint8_t crc_absent; - uint8_t object_type; - uint8_t sampling_index; - uint8_t chan_config; - uint8_t num_aac_frames; -} AACADTSHeaderInfo; - -/** - * Parse AAC frame header. - * Parse the ADTS frame header to the end of the variable header, which is - * the first 54 bits. - * @param[in] gbc BitContext containing the first 54 bits of the frame. - * @param[out] hdr Pointer to struct where header info is written. - * @return Returns 0 on success, -1 if there is a sync word mismatch, - * -2 if the version element is invalid, -3 if the sample rate - * element is invalid, or -4 if the bit rate element is invalid. - */ -int avpriv_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr); - -#endif /* AVCODEC_AACADTSDEC_H */ +/*
+ * AAC ADTS header decoding prototypes and structures
+ * Copyright (c) 2003 Fabrice Bellard
+ * Copyright (c) 2003 Michael Niedermayer
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_AACADTSDEC_H
+#define AVCODEC_AACADTSDEC_H
+
+#include <stdint.h>
+#include "get_bits.h"
+
+#define AAC_ADTS_HEADER_SIZE 7
+
+typedef struct {
+ uint32_t sample_rate;
+ uint32_t samples;
+ uint32_t bit_rate;
+ uint8_t crc_absent;
+ uint8_t object_type;
+ uint8_t sampling_index;
+ uint8_t chan_config;
+ uint8_t num_aac_frames;
+} AACADTSHeaderInfo;
+
+/**
+ * Parse AAC frame header.
+ * Parse the ADTS frame header to the end of the variable header, which is
+ * the first 54 bits.
+ * @param[in] gbc BitContext containing the first 54 bits of the frame.
+ * @param[out] hdr Pointer to struct where header info is written.
+ * @return Returns 0 on success, -1 if there is a sync word mismatch,
+ * -2 if the version element is invalid, -3 if the sample rate
+ * element is invalid, or -4 if the bit rate element is invalid.
+ */
+int avpriv_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr);
+
+#endif /* AVCODEC_AACADTSDEC_H */
diff --git a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacdec.c b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacdec.c index 43afd1f09..0e64bbbd6 100644 --- a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacdec.c +++ b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacdec.c @@ -1,2843 +1,2847 @@ -/* - * AAC decoder - * Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org ) - * Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com ) - * - * AAC LATM decoder - * Copyright (c) 2008-2010 Paul Kendall <paul@kcbbs.gen.nz> - * Copyright (c) 2010 Janne Grunau <janne-ffmpeg@jannau.net> - * - * This file is part of FFmpeg. - * - * FFmpeg is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * FFmpeg is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/** - * @file - * AAC decoder - * @author Oded Shimon ( ods15 ods15 dyndns org ) - * @author Maxim Gavrilov ( maxim.gavrilov gmail com ) - */ - -/* - * supported tools - * - * Support? Name - * N (code in SoC repo) gain control - * Y block switching - * Y window shapes - standard - * N window shapes - Low Delay - * Y filterbank - standard - * N (code in SoC repo) filterbank - Scalable Sample Rate - * Y Temporal Noise Shaping - * Y Long Term Prediction - * Y intensity stereo - * Y channel coupling - * Y frequency domain prediction - * Y Perceptual Noise Substitution - * Y Mid/Side stereo - * N Scalable Inverse AAC Quantization - * N Frequency Selective Switch - * N upsampling filter - * Y quantization & coding - AAC - * N quantization & coding - TwinVQ - * N quantization & coding - BSAC - * N AAC Error Resilience tools - * N Error Resilience payload syntax - * N Error Protection tool - * N CELP - * N Silence Compression - * N HVXC - * N HVXC 4kbits/s VR - * N Structured Audio tools - * N Structured Audio Sample Bank Format - * N MIDI - * N Harmonic and Individual Lines plus Noise - * N Text-To-Speech Interface - * Y Spectral Band Replication - * Y (not in this code) Layer-1 - * Y (not in this code) Layer-2 - * Y (not in this code) Layer-3 - * N SinuSoidal Coding (Transient, Sinusoid, Noise) - * Y Parametric Stereo - * N Direct Stream Transfer - * - * Note: - HE AAC v1 comprises LC AAC with Spectral Band Replication. - * - HE AAC v2 comprises LC AAC with Spectral Band Replication and - Parametric Stereo. - */ - - -#include "avcodec.h" -#include "internal.h" -#include "get_bits.h" -#include "put_bits.h" -#include "dsputil.h" -#include "fft.h" -#include "fmtconvert.h" -#include "lpc.h" -#include "kbdwin.h" -#include "sinewin.h" - -#include "aac.h" -#include "aactab.h" -#include "aacdectab.h" -#include "cbrt_tablegen.h" -#include "sbr.h" -#include "aacsbr.h" -#include "mpeg4audio.h" -#include "aacadtsdec.h" -#include "libavutil/intfloat.h" - -#include <assert.h> -#include <errno.h> -#include <math.h> -#include <string.h> - -#if ARCH_ARM -# include "arm/aac.h" -#endif - -static VLC vlc_scalefactors; -static VLC vlc_spectral[11]; - -static const char overread_err[] = "Input buffer exhausted before END element found\n"; - -static int count_channels(uint8_t (*layout)[3], int tags) -{ - int i, sum = 0; - for (i = 0; i < tags; i++) { - int syn_ele = layout[i][0]; - int pos = layout[i][2]; - sum += (1 + (syn_ele == TYPE_CPE)) * - (pos != AAC_CHANNEL_OFF && pos != AAC_CHANNEL_CC); - } - return sum; -} - -/** - * Check for the channel element in the current channel position configuration. - * If it exists, make sure the appropriate element is allocated and map the - * channel order to match the internal FFmpeg channel layout. - * - * @param che_pos current channel position configuration - * @param type channel element type - * @param id channel element id - * @param channels count of the number of channels in the configuration - * - * @return Returns error status. 0 - OK, !0 - error - */ -static av_cold int che_configure(AACContext *ac, - enum ChannelPosition che_pos, - int type, int id, int *channels) -{ - if (che_pos) { - if (!ac->che[type][id]) { - if (!(ac->che[type][id] = av_mallocz(sizeof(ChannelElement)))) - return AVERROR(ENOMEM); - ff_aac_sbr_ctx_init(ac, &ac->che[type][id]->sbr); - } - if (type != TYPE_CCE) { - ac->output_data[(*channels)++] = ac->che[type][id]->ch[0].ret; - if (type == TYPE_CPE || - (type == TYPE_SCE && ac->m4ac.ps == 1)) { - ac->output_data[(*channels)++] = ac->che[type][id]->ch[1].ret; - } - } - } else { - if (ac->che[type][id]) - ff_aac_sbr_ctx_close(&ac->che[type][id]->sbr); - av_freep(&ac->che[type][id]); - } - return 0; -} - -struct elem_to_channel { - uint64_t av_position; - uint8_t syn_ele; - uint8_t elem_id; - uint8_t aac_position; -}; - -static int assign_pair(struct elem_to_channel e2c_vec[MAX_ELEM_ID], - uint8_t (*layout_map)[3], int offset, int tags, uint64_t left, - uint64_t right, int pos) -{ - if (layout_map[offset][0] == TYPE_CPE) { - e2c_vec[offset] = (struct elem_to_channel) { - .av_position = left | right, .syn_ele = TYPE_CPE, - .elem_id = layout_map[offset ][1], .aac_position = pos }; - return 1; - } else { - e2c_vec[offset] = (struct elem_to_channel) { - .av_position = left, .syn_ele = TYPE_SCE, - .elem_id = layout_map[offset ][1], .aac_position = pos }; - e2c_vec[offset + 1] = (struct elem_to_channel) { - .av_position = right, .syn_ele = TYPE_SCE, - .elem_id = layout_map[offset + 1][1], .aac_position = pos }; - return 2; - } -} - -static int count_paired_channels(uint8_t (*layout_map)[3], int tags, int pos, int *current) { - int num_pos_channels = 0; - int first_cpe = 0; - int sce_parity = 0; - int i; - for (i = *current; i < tags; i++) { - if (layout_map[i][2] != pos) - break; - if (layout_map[i][0] == TYPE_CPE) { - if (sce_parity) { - if (pos == AAC_CHANNEL_FRONT || !first_cpe) { - sce_parity = 0; - } else { - return -1; - } - } - num_pos_channels += 2; - first_cpe = 1; - } else { - num_pos_channels++; - sce_parity ^= 1; - } - } - if (sce_parity && - ((pos == AAC_CHANNEL_FRONT && first_cpe) || pos == AAC_CHANNEL_SIDE)) - return -1; - *current = i; - return num_pos_channels; -} - -static uint64_t sniff_channel_order(uint8_t (*layout_map)[3], int tags) -{ - int i, n, total_non_cc_elements; - struct elem_to_channel e2c_vec[MAX_ELEM_ID] = {{ 0 }}; - int num_front_channels, num_side_channels, num_back_channels; - uint64_t layout; - - i = 0; - num_front_channels = - count_paired_channels(layout_map, tags, AAC_CHANNEL_FRONT, &i); - if (num_front_channels < 0) - return 0; - num_side_channels = - count_paired_channels(layout_map, tags, AAC_CHANNEL_SIDE, &i); - if (num_side_channels < 0) - return 0; - num_back_channels = - count_paired_channels(layout_map, tags, AAC_CHANNEL_BACK, &i); - if (num_back_channels < 0) - return 0; - - i = 0; - if (num_front_channels & 1) { - e2c_vec[i] = (struct elem_to_channel) { - .av_position = AV_CH_FRONT_CENTER, .syn_ele = TYPE_SCE, - .elem_id = layout_map[i][1], .aac_position = AAC_CHANNEL_FRONT }; - i++; - num_front_channels--; - } - if (num_front_channels >= 4) { - i += assign_pair(e2c_vec, layout_map, i, tags, - AV_CH_FRONT_LEFT_OF_CENTER, - AV_CH_FRONT_RIGHT_OF_CENTER, - AAC_CHANNEL_FRONT); - num_front_channels -= 2; - } - if (num_front_channels >= 2) { - i += assign_pair(e2c_vec, layout_map, i, tags, - AV_CH_FRONT_LEFT, - AV_CH_FRONT_RIGHT, - AAC_CHANNEL_FRONT); - num_front_channels -= 2; - } - while (num_front_channels >= 2) { - i += assign_pair(e2c_vec, layout_map, i, tags, - UINT64_MAX, - UINT64_MAX, - AAC_CHANNEL_FRONT); - num_front_channels -= 2; - } - - if (num_side_channels >= 2) { - i += assign_pair(e2c_vec, layout_map, i, tags, - AV_CH_SIDE_LEFT, - AV_CH_SIDE_RIGHT, - AAC_CHANNEL_FRONT); - num_side_channels -= 2; - } - while (num_side_channels >= 2) { - i += assign_pair(e2c_vec, layout_map, i, tags, - UINT64_MAX, - UINT64_MAX, - AAC_CHANNEL_SIDE); - num_side_channels -= 2; - } - - while (num_back_channels >= 4) { - i += assign_pair(e2c_vec, layout_map, i, tags, - UINT64_MAX, - UINT64_MAX, - AAC_CHANNEL_BACK); - num_back_channels -= 2; - } - if (num_back_channels >= 2) { - i += assign_pair(e2c_vec, layout_map, i, tags, - AV_CH_BACK_LEFT, - AV_CH_BACK_RIGHT, - AAC_CHANNEL_BACK); - num_back_channels -= 2; - } - if (num_back_channels) { - e2c_vec[i] = (struct elem_to_channel) { - .av_position = AV_CH_BACK_CENTER, .syn_ele = TYPE_SCE, - .elem_id = layout_map[i][1], .aac_position = AAC_CHANNEL_BACK }; - i++; - num_back_channels--; - } - - if (i < tags && layout_map[i][2] == AAC_CHANNEL_LFE) { - e2c_vec[i] = (struct elem_to_channel) { - .av_position = AV_CH_LOW_FREQUENCY, .syn_ele = TYPE_LFE, - .elem_id = layout_map[i][1], .aac_position = AAC_CHANNEL_LFE }; - i++; - } - while (i < tags && layout_map[i][2] == AAC_CHANNEL_LFE) { - e2c_vec[i] = (struct elem_to_channel) { - .av_position = UINT64_MAX, .syn_ele = TYPE_LFE, - .elem_id = layout_map[i][1], .aac_position = AAC_CHANNEL_LFE }; - i++; - } - - // Must choose a stable sort - total_non_cc_elements = n = i; - do { - int next_n = 0; - for (i = 1; i < n; i++) { - if (e2c_vec[i-1].av_position > e2c_vec[i].av_position) { - FFSWAP(struct elem_to_channel, e2c_vec[i-1], e2c_vec[i]); - next_n = i; - } - } - n = next_n; - } while (n > 0); - - layout = 0; - for (i = 0; i < total_non_cc_elements; i++) { - layout_map[i][0] = e2c_vec[i].syn_ele; - layout_map[i][1] = e2c_vec[i].elem_id; - layout_map[i][2] = e2c_vec[i].aac_position; - if (e2c_vec[i].av_position != UINT64_MAX) { - layout |= e2c_vec[i].av_position; - } - } - - return layout; -} - -/** - * Configure output channel order based on the current program configuration element. - * - * @return Returns error status. 0 - OK, !0 - error - */ -static av_cold int output_configure(AACContext *ac, - uint8_t layout_map[MAX_ELEM_ID*4][3], int tags, - int channel_config, enum OCStatus oc_type) -{ - AVCodecContext *avctx = ac->avctx; - int i, channels = 0, ret; - uint64_t layout = 0; - - if (ac->layout_map != layout_map) { - memcpy(ac->layout_map, layout_map, tags * sizeof(layout_map[0])); - ac->layout_map_tags = tags; - } - - // Try to sniff a reasonable channel order, otherwise output the - // channels in the order the PCE declared them. - if (avctx->request_channel_layout != AV_CH_LAYOUT_NATIVE) - layout = sniff_channel_order(layout_map, tags); - for (i = 0; i < tags; i++) { - int type = layout_map[i][0]; - int id = layout_map[i][1]; - int position = layout_map[i][2]; - // Allocate or free elements depending on if they are in the - // current program configuration. - ret = che_configure(ac, position, type, id, &channels); - if (ret < 0) - return ret; - } - - memcpy(ac->tag_che_map, ac->che, 4 * MAX_ELEM_ID * sizeof(ac->che[0][0])); - if (layout) avctx->channel_layout = layout; - avctx->channels = channels; - ac->output_configured = oc_type; - - return 0; -} - -static void flush(AVCodecContext *avctx) -{ - AACContext *ac= avctx->priv_data; - int type, i, j; - - for (type = 3; type >= 0; type--) { - for (i = 0; i < MAX_ELEM_ID; i++) { - ChannelElement *che = ac->che[type][i]; - if (che) { - for (j = 0; j <= 1; j++) { - memset(che->ch[j].saved, 0, sizeof(che->ch[j].saved)); - } - } - } - } -} - -/** - * Set up channel positions based on a default channel configuration - * as specified in table 1.17. - * - * @return Returns error status. 0 - OK, !0 - error - */ -static av_cold int set_default_channel_config(AVCodecContext *avctx, - uint8_t (*layout_map)[3], - int *tags, - int channel_config) -{ - if (channel_config < 1 || channel_config > 7) { - av_log(avctx, AV_LOG_ERROR, "invalid default channel configuration (%d)\n", - channel_config); - return -1; - } - *tags = tags_per_config[channel_config]; - memcpy(layout_map, aac_channel_layout_map[channel_config-1], *tags * sizeof(*layout_map)); - return 0; -} - -static ChannelElement *get_che(AACContext *ac, int type, int elem_id) -{ - // For PCE based channel configurations map the channels solely based on tags. - if (!ac->m4ac.chan_config) { - return ac->tag_che_map[type][elem_id]; - } - // Allow single CPE stereo files to be signalled with mono configuration. - if (!ac->tags_mapped && type == TYPE_CPE && ac->m4ac.chan_config == 1) { - uint8_t layout_map[MAX_ELEM_ID*4][3]; - int layout_map_tags; - - if (set_default_channel_config(ac->avctx, layout_map, &layout_map_tags, - 2) < 0) - return NULL; - if (output_configure(ac, layout_map, layout_map_tags, - 2, OC_TRIAL_FRAME) < 0) - return NULL; - - ac->m4ac.chan_config = 2; - } - // For indexed channel configurations map the channels solely based on position. - switch (ac->m4ac.chan_config) { - case 7: - if (ac->tags_mapped == 3 && type == TYPE_CPE) { - ac->tags_mapped++; - return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][2]; - } - case 6: - /* Some streams incorrectly code 5.1 audio as SCE[0] CPE[0] CPE[1] SCE[1] - instead of SCE[0] CPE[0] CPE[1] LFE[0]. If we seem to have - encountered such a stream, transfer the LFE[0] element to the SCE[1]'s mapping */ - if (ac->tags_mapped == tags_per_config[ac->m4ac.chan_config] - 1 && (type == TYPE_LFE || type == TYPE_SCE)) { - ac->tags_mapped++; - return ac->tag_che_map[type][elem_id] = ac->che[TYPE_LFE][0]; - } - case 5: - if (ac->tags_mapped == 2 && type == TYPE_CPE) { - ac->tags_mapped++; - return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][1]; - } - case 4: - if (ac->tags_mapped == 2 && ac->m4ac.chan_config == 4 && type == TYPE_SCE) { - ac->tags_mapped++; - return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][1]; - } - case 3: - case 2: - if (ac->tags_mapped == (ac->m4ac.chan_config != 2) && type == TYPE_CPE) { - ac->tags_mapped++; - return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][0]; - } else if (ac->m4ac.chan_config == 2) { - return NULL; - } - case 1: - if (!ac->tags_mapped && type == TYPE_SCE) { - ac->tags_mapped++; - return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][0]; - } - default: - return NULL; - } -} - -/** - * Decode an array of 4 bit element IDs, optionally interleaved with a stereo/mono switching bit. - * - * @param type speaker type/position for these channels - */ -static void decode_channel_map(uint8_t layout_map[][3], - enum ChannelPosition type, - GetBitContext *gb, int n) -{ - while (n--) { - enum RawDataBlockType syn_ele; - switch (type) { - case AAC_CHANNEL_FRONT: - case AAC_CHANNEL_BACK: - case AAC_CHANNEL_SIDE: - syn_ele = get_bits1(gb); - break; - case AAC_CHANNEL_CC: - skip_bits1(gb); - syn_ele = TYPE_CCE; - break; - case AAC_CHANNEL_LFE: - syn_ele = TYPE_LFE; - break; - } - layout_map[0][0] = syn_ele; - layout_map[0][1] = get_bits(gb, 4); - layout_map[0][2] = type; - layout_map++; - } -} - -/** - * Decode program configuration element; reference: table 4.2. - * - * @return Returns error status. 0 - OK, !0 - error - */ -static int decode_pce(AVCodecContext *avctx, MPEG4AudioConfig *m4ac, - uint8_t (*layout_map)[3], - GetBitContext *gb) -{ - int num_front, num_side, num_back, num_lfe, num_assoc_data, num_cc, sampling_index; - int comment_len; - int tags; - - skip_bits(gb, 2); // object_type - - sampling_index = get_bits(gb, 4); - if (m4ac->sampling_index != sampling_index) - av_log(avctx, AV_LOG_WARNING, "Sample rate index in program config element does not match the sample rate index configured by the container.\n"); - - num_front = get_bits(gb, 4); - num_side = get_bits(gb, 4); - num_back = get_bits(gb, 4); - num_lfe = get_bits(gb, 2); - num_assoc_data = get_bits(gb, 3); - num_cc = get_bits(gb, 4); - - if (get_bits1(gb)) - skip_bits(gb, 4); // mono_mixdown_tag - if (get_bits1(gb)) - skip_bits(gb, 4); // stereo_mixdown_tag - - if (get_bits1(gb)) - skip_bits(gb, 3); // mixdown_coeff_index and pseudo_surround - - if (get_bits_left(gb) < 4 * (num_front + num_side + num_back + num_lfe + num_assoc_data + num_cc)) { - av_log(avctx, AV_LOG_ERROR, overread_err); - return -1; - } - decode_channel_map(layout_map , AAC_CHANNEL_FRONT, gb, num_front); - tags = num_front; - decode_channel_map(layout_map + tags, AAC_CHANNEL_SIDE, gb, num_side); - tags += num_side; - decode_channel_map(layout_map + tags, AAC_CHANNEL_BACK, gb, num_back); - tags += num_back; - decode_channel_map(layout_map + tags, AAC_CHANNEL_LFE, gb, num_lfe); - tags += num_lfe; - - skip_bits_long(gb, 4 * num_assoc_data); - - decode_channel_map(layout_map + tags, AAC_CHANNEL_CC, gb, num_cc); - tags += num_cc; - - align_get_bits(gb); - - /* comment field, first byte is length */ - comment_len = get_bits(gb, 8) * 8; - if (get_bits_left(gb) < comment_len) { - av_log(avctx, AV_LOG_ERROR, overread_err); - return -1; - } - skip_bits_long(gb, comment_len); - return tags; -} - -/** - * Decode GA "General Audio" specific configuration; reference: table 4.1. - * - * @param ac pointer to AACContext, may be null - * @param avctx pointer to AVCCodecContext, used for logging - * - * @return Returns error status. 0 - OK, !0 - error - */ -static int decode_ga_specific_config(AACContext *ac, AVCodecContext *avctx, - GetBitContext *gb, - MPEG4AudioConfig *m4ac, - int channel_config) -{ - int extension_flag, ret; - uint8_t layout_map[MAX_ELEM_ID*4][3]; - int tags = 0; - - if (get_bits1(gb)) { // frameLengthFlag - av_log_missing_feature(avctx, "960/120 MDCT window is", 1); - return -1; - } - - if (get_bits1(gb)) // dependsOnCoreCoder - skip_bits(gb, 14); // coreCoderDelay - extension_flag = get_bits1(gb); - - if (m4ac->object_type == AOT_AAC_SCALABLE || - m4ac->object_type == AOT_ER_AAC_SCALABLE) - skip_bits(gb, 3); // layerNr - - if (channel_config == 0) { - skip_bits(gb, 4); // element_instance_tag - tags = decode_pce(avctx, m4ac, layout_map, gb); - if (tags < 0) - return tags; - } else { - if ((ret = set_default_channel_config(avctx, layout_map, &tags, channel_config))) - return ret; - } - - if (count_channels(layout_map, tags) > 1) { - m4ac->ps = 0; - } else if (m4ac->sbr == 1 && m4ac->ps == -1) - m4ac->ps = 1; - - if (ac && (ret = output_configure(ac, layout_map, tags, - channel_config, OC_GLOBAL_HDR))) - return ret; - - if (extension_flag) { - switch (m4ac->object_type) { - case AOT_ER_BSAC: - skip_bits(gb, 5); // numOfSubFrame - skip_bits(gb, 11); // layer_length - break; - case AOT_ER_AAC_LC: - case AOT_ER_AAC_LTP: - case AOT_ER_AAC_SCALABLE: - case AOT_ER_AAC_LD: - skip_bits(gb, 3); /* aacSectionDataResilienceFlag - * aacScalefactorDataResilienceFlag - * aacSpectralDataResilienceFlag - */ - break; - } - skip_bits1(gb); // extensionFlag3 (TBD in version 3) - } - return 0; -} - -/** - * Decode audio specific configuration; reference: table 1.13. - * - * @param ac pointer to AACContext, may be null - * @param avctx pointer to AVCCodecContext, used for logging - * @param m4ac pointer to MPEG4AudioConfig, used for parsing - * @param data pointer to buffer holding an audio specific config - * @param bit_size size of audio specific config or data in bits - * @param sync_extension look for an appended sync extension - * - * @return Returns error status or number of consumed bits. <0 - error - */ -static int decode_audio_specific_config(AACContext *ac, - AVCodecContext *avctx, - MPEG4AudioConfig *m4ac, - const uint8_t *data, int bit_size, - int sync_extension) -{ - GetBitContext gb; - int i; - - av_dlog(avctx, "extradata size %d\n", avctx->extradata_size); - for (i = 0; i < avctx->extradata_size; i++) - av_dlog(avctx, "%02x ", avctx->extradata[i]); - av_dlog(avctx, "\n"); - - init_get_bits(&gb, data, bit_size); - - if ((i = avpriv_mpeg4audio_get_config(m4ac, data, bit_size, sync_extension)) < 0) - return -1; - if (m4ac->sampling_index > 12) { - av_log(avctx, AV_LOG_ERROR, "invalid sampling rate index %d\n", m4ac->sampling_index); - return -1; - } - - skip_bits_long(&gb, i); - - switch (m4ac->object_type) { - case AOT_AAC_MAIN: - case AOT_AAC_LC: - case AOT_AAC_LTP: - if (decode_ga_specific_config(ac, avctx, &gb, m4ac, m4ac->chan_config)) - return -1; - break; - default: - av_log(avctx, AV_LOG_ERROR, "Audio object type %s%d is not supported.\n", - m4ac->sbr == 1? "SBR+" : "", m4ac->object_type); - return -1; - } - - av_dlog(avctx, "AOT %d chan config %d sampling index %d (%d) SBR %d PS %d\n", - m4ac->object_type, m4ac->chan_config, m4ac->sampling_index, - m4ac->sample_rate, m4ac->sbr, m4ac->ps); - - return get_bits_count(&gb); -} - -/** - * linear congruential pseudorandom number generator - * - * @param previous_val pointer to the current state of the generator - * - * @return Returns a 32-bit pseudorandom integer - */ -static av_always_inline int lcg_random(int previous_val) -{ - return previous_val * 1664525 + 1013904223; -} - -static av_always_inline void reset_predict_state(PredictorState *ps) -{ - ps->r0 = 0.0f; - ps->r1 = 0.0f; - ps->cor0 = 0.0f; - ps->cor1 = 0.0f; - ps->var0 = 1.0f; - ps->var1 = 1.0f; -} - -static void reset_all_predictors(PredictorState *ps) -{ - int i; - for (i = 0; i < MAX_PREDICTORS; i++) - reset_predict_state(&ps[i]); -} - -static int sample_rate_idx (int rate) -{ - if (92017 <= rate) return 0; - else if (75132 <= rate) return 1; - else if (55426 <= rate) return 2; - else if (46009 <= rate) return 3; - else if (37566 <= rate) return 4; - else if (27713 <= rate) return 5; - else if (23004 <= rate) return 6; - else if (18783 <= rate) return 7; - else if (13856 <= rate) return 8; - else if (11502 <= rate) return 9; - else if (9391 <= rate) return 10; - else return 11; -} - -static void reset_predictor_group(PredictorState *ps, int group_num) -{ - int i; - for (i = group_num - 1; i < MAX_PREDICTORS; i += 30) - reset_predict_state(&ps[i]); -} - -#define AAC_INIT_VLC_STATIC(num, size) \ - INIT_VLC_STATIC(&vlc_spectral[num], 8, ff_aac_spectral_sizes[num], \ - ff_aac_spectral_bits[num], sizeof( ff_aac_spectral_bits[num][0]), sizeof( ff_aac_spectral_bits[num][0]), \ - ff_aac_spectral_codes[num], sizeof(ff_aac_spectral_codes[num][0]), sizeof(ff_aac_spectral_codes[num][0]), \ - size); - -static av_cold int aac_decode_init(AVCodecContext *avctx) -{ - AACContext *ac = avctx->priv_data; - float output_scale_factor; - - ac->avctx = avctx; - ac->m4ac.sample_rate = avctx->sample_rate; - - if (avctx->extradata_size > 0) { - if (decode_audio_specific_config(ac, ac->avctx, &ac->m4ac, - avctx->extradata, - avctx->extradata_size*8, 1) < 0) - return -1; - } else { - int sr, i; - uint8_t layout_map[MAX_ELEM_ID*4][3]; - int layout_map_tags; - - sr = sample_rate_idx(avctx->sample_rate); - ac->m4ac.sampling_index = sr; - ac->m4ac.channels = avctx->channels; - ac->m4ac.sbr = -1; - ac->m4ac.ps = -1; - - for (i = 0; i < FF_ARRAY_ELEMS(ff_mpeg4audio_channels); i++) - if (ff_mpeg4audio_channels[i] == avctx->channels) - break; - if (i == FF_ARRAY_ELEMS(ff_mpeg4audio_channels)) { - i = 0; - } - ac->m4ac.chan_config = i; - - if (ac->m4ac.chan_config) { - int ret = set_default_channel_config(avctx, layout_map, - &layout_map_tags, ac->m4ac.chan_config); - if (!ret) - output_configure(ac, layout_map, layout_map_tags, - ac->m4ac.chan_config, OC_GLOBAL_HDR); - else if (avctx->err_recognition & AV_EF_EXPLODE) - return AVERROR_INVALIDDATA; - } - } - - if (avctx->request_sample_fmt == AV_SAMPLE_FMT_FLT) { - avctx->sample_fmt = AV_SAMPLE_FMT_FLT; - output_scale_factor = 1.0; // / 32768.0; - } else { - avctx->sample_fmt = AV_SAMPLE_FMT_S16; - output_scale_factor = 1.0; - } - - AAC_INIT_VLC_STATIC( 0, 304); - AAC_INIT_VLC_STATIC( 1, 270); - AAC_INIT_VLC_STATIC( 2, 550); - AAC_INIT_VLC_STATIC( 3, 300); - AAC_INIT_VLC_STATIC( 4, 328); - AAC_INIT_VLC_STATIC( 5, 294); - AAC_INIT_VLC_STATIC( 6, 306); - AAC_INIT_VLC_STATIC( 7, 268); - AAC_INIT_VLC_STATIC( 8, 510); - AAC_INIT_VLC_STATIC( 9, 366); - AAC_INIT_VLC_STATIC(10, 462); - - ff_aac_sbr_init(); - - ff_dsputil_init(&ac->dsp, avctx); - ff_fmt_convert_init(&ac->fmt_conv, avctx); - - ac->random_state = 0x1f2e3d4c; - - ff_aac_tableinit(); - - INIT_VLC_STATIC(&vlc_scalefactors,7,FF_ARRAY_ELEMS(ff_aac_scalefactor_code), - ff_aac_scalefactor_bits, sizeof(ff_aac_scalefactor_bits[0]), sizeof(ff_aac_scalefactor_bits[0]), - ff_aac_scalefactor_code, sizeof(ff_aac_scalefactor_code[0]), sizeof(ff_aac_scalefactor_code[0]), - 352); - - ff_mdct_init(&ac->mdct, 11, 1, output_scale_factor/1024.0); - ff_mdct_init(&ac->mdct_small, 8, 1, output_scale_factor/128.0); - ff_mdct_init(&ac->mdct_ltp, 11, 0, -2.0/output_scale_factor); - // window initialization - ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024); - ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128); - ff_init_ff_sine_windows(10); - ff_init_ff_sine_windows( 7); - - cbrt_tableinit(); - - avcodec_get_frame_defaults(&ac->frame); - avctx->coded_frame = &ac->frame; - - return 0; -} - -/** - * Skip data_stream_element; reference: table 4.10. - */ -static int skip_data_stream_element(AACContext *ac, GetBitContext *gb) -{ - int byte_align = get_bits1(gb); - int count = get_bits(gb, 8); - if (count == 255) - count += get_bits(gb, 8); - if (byte_align) - align_get_bits(gb); - - if (get_bits_left(gb) < 8 * count) { - av_log(ac->avctx, AV_LOG_ERROR, overread_err); - return -1; - } - skip_bits_long(gb, 8 * count); - return 0; -} - -static int decode_prediction(AACContext *ac, IndividualChannelStream *ics, - GetBitContext *gb) -{ - int sfb; - if (get_bits1(gb)) { - ics->predictor_reset_group = get_bits(gb, 5); - if (ics->predictor_reset_group == 0 || ics->predictor_reset_group > 30) { - av_log(ac->avctx, AV_LOG_ERROR, "Invalid Predictor Reset Group.\n"); - return -1; - } - } - for (sfb = 0; sfb < FFMIN(ics->max_sfb, ff_aac_pred_sfb_max[ac->m4ac.sampling_index]); sfb++) { - ics->prediction_used[sfb] = get_bits1(gb); - } - return 0; -} - -/** - * Decode Long Term Prediction data; reference: table 4.xx. - */ -static void decode_ltp(AACContext *ac, LongTermPrediction *ltp, - GetBitContext *gb, uint8_t max_sfb) -{ - int sfb; - - ltp->lag = get_bits(gb, 11); - ltp->coef = ltp_coef[get_bits(gb, 3)]; - for (sfb = 0; sfb < FFMIN(max_sfb, MAX_LTP_LONG_SFB); sfb++) - ltp->used[sfb] = get_bits1(gb); -} - -/** - * Decode Individual Channel Stream info; reference: table 4.6. - */ -static int decode_ics_info(AACContext *ac, IndividualChannelStream *ics, - GetBitContext *gb) -{ - if (get_bits1(gb)) { - av_log(ac->avctx, AV_LOG_ERROR, "Reserved bit set.\n"); - return AVERROR_INVALIDDATA; - } - ics->window_sequence[1] = ics->window_sequence[0]; - ics->window_sequence[0] = get_bits(gb, 2); - ics->use_kb_window[1] = ics->use_kb_window[0]; - ics->use_kb_window[0] = get_bits1(gb); - ics->num_window_groups = 1; - ics->group_len[0] = 1; - if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { - int i; - ics->max_sfb = get_bits(gb, 4); - for (i = 0; i < 7; i++) { - if (get_bits1(gb)) { - ics->group_len[ics->num_window_groups - 1]++; - } else { - ics->num_window_groups++; - ics->group_len[ics->num_window_groups - 1] = 1; - } - } - ics->num_windows = 8; - ics->swb_offset = ff_swb_offset_128[ac->m4ac.sampling_index]; - ics->num_swb = ff_aac_num_swb_128[ac->m4ac.sampling_index]; - ics->tns_max_bands = ff_tns_max_bands_128[ac->m4ac.sampling_index]; - ics->predictor_present = 0; - } else { - ics->max_sfb = get_bits(gb, 6); - ics->num_windows = 1; - ics->swb_offset = ff_swb_offset_1024[ac->m4ac.sampling_index]; - ics->num_swb = ff_aac_num_swb_1024[ac->m4ac.sampling_index]; - ics->tns_max_bands = ff_tns_max_bands_1024[ac->m4ac.sampling_index]; - ics->predictor_present = get_bits1(gb); - ics->predictor_reset_group = 0; - if (ics->predictor_present) { - if (ac->m4ac.object_type == AOT_AAC_MAIN) { - if (decode_prediction(ac, ics, gb)) { - return AVERROR_INVALIDDATA; - } - } else if (ac->m4ac.object_type == AOT_AAC_LC) { - av_log(ac->avctx, AV_LOG_ERROR, "Prediction is not allowed in AAC-LC.\n"); - return AVERROR_INVALIDDATA; - } else { - if ((ics->ltp.present = get_bits(gb, 1))) - decode_ltp(ac, &ics->ltp, gb, ics->max_sfb); - } - } - } - - if (ics->max_sfb > ics->num_swb) { - av_log(ac->avctx, AV_LOG_ERROR, - "Number of scalefactor bands in group (%d) exceeds limit (%d).\n", - ics->max_sfb, ics->num_swb); - return AVERROR_INVALIDDATA; - } - - return 0; -} - -/** - * Decode band types (section_data payload); reference: table 4.46. - * - * @param band_type array of the used band type - * @param band_type_run_end array of the last scalefactor band of a band type run - * - * @return Returns error status. 0 - OK, !0 - error - */ -static int decode_band_types(AACContext *ac, enum BandType band_type[120], - int band_type_run_end[120], GetBitContext *gb, - IndividualChannelStream *ics) -{ - int g, idx = 0; - const int bits = (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) ? 3 : 5; - for (g = 0; g < ics->num_window_groups; g++) { - int k = 0; - while (k < ics->max_sfb) { - uint8_t sect_end = k; - int sect_len_incr; - int sect_band_type = get_bits(gb, 4); - if (sect_band_type == 12) { - av_log(ac->avctx, AV_LOG_ERROR, "invalid band type\n"); - return -1; - } - do { - sect_len_incr = get_bits(gb, bits); - sect_end += sect_len_incr; - if (get_bits_left(gb) < 0) { - av_log(ac->avctx, AV_LOG_ERROR, overread_err); - return -1; - } - if (sect_end > ics->max_sfb) { - av_log(ac->avctx, AV_LOG_ERROR, - "Number of bands (%d) exceeds limit (%d).\n", - sect_end, ics->max_sfb); - return -1; - } - } while (sect_len_incr == (1 << bits) - 1); - for (; k < sect_end; k++) { - band_type [idx] = sect_band_type; - band_type_run_end[idx++] = sect_end; - } - } - } - return 0; -} - -/** - * Decode scalefactors; reference: table 4.47. - * - * @param global_gain first scalefactor value as scalefactors are differentially coded - * @param band_type array of the used band type - * @param band_type_run_end array of the last scalefactor band of a band type run - * @param sf array of scalefactors or intensity stereo positions - * - * @return Returns error status. 0 - OK, !0 - error - */ -static int decode_scalefactors(AACContext *ac, float sf[120], GetBitContext *gb, - unsigned int global_gain, - IndividualChannelStream *ics, - enum BandType band_type[120], - int band_type_run_end[120]) -{ - int g, i, idx = 0; - int offset[3] = { global_gain, global_gain - 90, 0 }; - int clipped_offset; - int noise_flag = 1; - for (g = 0; g < ics->num_window_groups; g++) { - for (i = 0; i < ics->max_sfb;) { - int run_end = band_type_run_end[idx]; - if (band_type[idx] == ZERO_BT) { - for (; i < run_end; i++, idx++) - sf[idx] = 0.; - } else if ((band_type[idx] == INTENSITY_BT) || (band_type[idx] == INTENSITY_BT2)) { - for (; i < run_end; i++, idx++) { - offset[2] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60; - clipped_offset = av_clip(offset[2], -155, 100); - if (offset[2] != clipped_offset) { - av_log_ask_for_sample(ac->avctx, "Intensity stereo " - "position clipped (%d -> %d).\nIf you heard an " - "audible artifact, there may be a bug in the " - "decoder. ", offset[2], clipped_offset); - } - sf[idx] = ff_aac_pow2sf_tab[-clipped_offset + POW_SF2_ZERO]; - } - } else if (band_type[idx] == NOISE_BT) { - for (; i < run_end; i++, idx++) { - if (noise_flag-- > 0) - offset[1] += get_bits(gb, 9) - 256; - else - offset[1] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60; - clipped_offset = av_clip(offset[1], -100, 155); - if (offset[1] != clipped_offset) { - av_log_ask_for_sample(ac->avctx, "Noise gain clipped " - "(%d -> %d).\nIf you heard an audible " - "artifact, there may be a bug in the decoder. ", - offset[1], clipped_offset); - } - sf[idx] = -ff_aac_pow2sf_tab[clipped_offset + POW_SF2_ZERO]; - } - } else { - for (; i < run_end; i++, idx++) { - offset[0] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60; - if (offset[0] > 255U) { - av_log(ac->avctx, AV_LOG_ERROR, - "Scalefactor (%d) out of range.\n", offset[0]); - return -1; - } - sf[idx] = -ff_aac_pow2sf_tab[offset[0] - 100 + POW_SF2_ZERO]; - } - } - } - } - return 0; -} - -/** - * Decode pulse data; reference: table 4.7. - */ -static int decode_pulses(Pulse *pulse, GetBitContext *gb, - const uint16_t *swb_offset, int num_swb) -{ - int i, pulse_swb; - pulse->num_pulse = get_bits(gb, 2) + 1; - pulse_swb = get_bits(gb, 6); - if (pulse_swb >= num_swb) - return -1; - pulse->pos[0] = swb_offset[pulse_swb]; - pulse->pos[0] += get_bits(gb, 5); - if (pulse->pos[0] > 1023) - return -1; - pulse->amp[0] = get_bits(gb, 4); - for (i = 1; i < pulse->num_pulse; i++) { - pulse->pos[i] = get_bits(gb, 5) + pulse->pos[i - 1]; - if (pulse->pos[i] > 1023) - return -1; - pulse->amp[i] = get_bits(gb, 4); - } - return 0; -} - -/** - * Decode Temporal Noise Shaping data; reference: table 4.48. - * - * @return Returns error status. 0 - OK, !0 - error - */ -static int decode_tns(AACContext *ac, TemporalNoiseShaping *tns, - GetBitContext *gb, const IndividualChannelStream *ics) -{ - int w, filt, i, coef_len, coef_res, coef_compress; - const int is8 = ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE; - const int tns_max_order = is8 ? 7 : ac->m4ac.object_type == AOT_AAC_MAIN ? 20 : 12; - for (w = 0; w < ics->num_windows; w++) { - if ((tns->n_filt[w] = get_bits(gb, 2 - is8))) { - coef_res = get_bits1(gb); - - for (filt = 0; filt < tns->n_filt[w]; filt++) { - int tmp2_idx; - tns->length[w][filt] = get_bits(gb, 6 - 2 * is8); - - if ((tns->order[w][filt] = get_bits(gb, 5 - 2 * is8)) > tns_max_order) { - av_log(ac->avctx, AV_LOG_ERROR, "TNS filter order %d is greater than maximum %d.\n", - tns->order[w][filt], tns_max_order); - tns->order[w][filt] = 0; - return -1; - } - if (tns->order[w][filt]) { - tns->direction[w][filt] = get_bits1(gb); - coef_compress = get_bits1(gb); - coef_len = coef_res + 3 - coef_compress; - tmp2_idx = 2 * coef_compress + coef_res; - - for (i = 0; i < tns->order[w][filt]; i++) - tns->coef[w][filt][i] = tns_tmp2_map[tmp2_idx][get_bits(gb, coef_len)]; - } - } - } - } - return 0; -} - -/** - * Decode Mid/Side data; reference: table 4.54. - * - * @param ms_present Indicates mid/side stereo presence. [0] mask is all 0s; - * [1] mask is decoded from bitstream; [2] mask is all 1s; - * [3] reserved for scalable AAC - */ -static void decode_mid_side_stereo(ChannelElement *cpe, GetBitContext *gb, - int ms_present) -{ - int idx; - if (ms_present == 1) { - for (idx = 0; idx < cpe->ch[0].ics.num_window_groups * cpe->ch[0].ics.max_sfb; idx++) - cpe->ms_mask[idx] = get_bits1(gb); - } else if (ms_present == 2) { - memset(cpe->ms_mask, 1, cpe->ch[0].ics.num_window_groups * cpe->ch[0].ics.max_sfb * sizeof(cpe->ms_mask[0])); - } -} - -#ifndef VMUL2 -static inline float *VMUL2(float *dst, const float *v, unsigned idx, - const float *scale) -{ - float s = *scale; - *dst++ = v[idx & 15] * s; - *dst++ = v[idx>>4 & 15] * s; - return dst; -} -#endif - -#ifndef VMUL4 -static inline float *VMUL4(float *dst, const float *v, unsigned idx, - const float *scale) -{ - float s = *scale; - *dst++ = v[idx & 3] * s; - *dst++ = v[idx>>2 & 3] * s; - *dst++ = v[idx>>4 & 3] * s; - *dst++ = v[idx>>6 & 3] * s; - return dst; -} -#endif - -#ifndef VMUL2S -static inline float *VMUL2S(float *dst, const float *v, unsigned idx, - unsigned sign, const float *scale) -{ - union av_intfloat32 s0, s1; - - s0.f = s1.f = *scale; - s0.i ^= sign >> 1 << 31; - s1.i ^= sign << 31; - - *dst++ = v[idx & 15] * s0.f; - *dst++ = v[idx>>4 & 15] * s1.f; - - return dst; -} -#endif - -#ifndef VMUL4S -static inline float *VMUL4S(float *dst, const float *v, unsigned idx, - unsigned sign, const float *scale) -{ - unsigned nz = idx >> 12; - union av_intfloat32 s = { .f = *scale }; - union av_intfloat32 t; - - t.i = s.i ^ (sign & 1U<<31); - *dst++ = v[idx & 3] * t.f; - - sign <<= nz & 1; nz >>= 1; - t.i = s.i ^ (sign & 1U<<31); - *dst++ = v[idx>>2 & 3] * t.f; - - sign <<= nz & 1; nz >>= 1; - t.i = s.i ^ (sign & 1U<<31); - *dst++ = v[idx>>4 & 3] * t.f; - - sign <<= nz & 1; nz >>= 1; - t.i = s.i ^ (sign & 1U<<31); - *dst++ = v[idx>>6 & 3] * t.f; - - return dst; -} -#endif - -/** - * Decode spectral data; reference: table 4.50. - * Dequantize and scale spectral data; reference: 4.6.3.3. - * - * @param coef array of dequantized, scaled spectral data - * @param sf array of scalefactors or intensity stereo positions - * @param pulse_present set if pulses are present - * @param pulse pointer to pulse data struct - * @param band_type array of the used band type - * - * @return Returns error status. 0 - OK, !0 - error - */ -static int decode_spectrum_and_dequant(AACContext *ac, float coef[1024], - GetBitContext *gb, const float sf[120], - int pulse_present, const Pulse *pulse, - const IndividualChannelStream *ics, - enum BandType band_type[120]) -{ - int i, k, g, idx = 0; - const int c = 1024 / ics->num_windows; - const uint16_t *offsets = ics->swb_offset; - float *coef_base = coef; - - for (g = 0; g < ics->num_windows; g++) - memset(coef + g * 128 + offsets[ics->max_sfb], 0, sizeof(float) * (c - offsets[ics->max_sfb])); - - for (g = 0; g < ics->num_window_groups; g++) { - unsigned g_len = ics->group_len[g]; - - for (i = 0; i < ics->max_sfb; i++, idx++) { - const unsigned cbt_m1 = band_type[idx] - 1; - float *cfo = coef + offsets[i]; - int off_len = offsets[i + 1] - offsets[i]; - int group; - - if (cbt_m1 >= INTENSITY_BT2 - 1) { - for (group = 0; group < g_len; group++, cfo+=128) { - memset(cfo, 0, off_len * sizeof(float)); - } - } else if (cbt_m1 == NOISE_BT - 1) { - for (group = 0; group < g_len; group++, cfo+=128) { - float scale; - float band_energy; - - for (k = 0; k < off_len; k++) { - ac->random_state = lcg_random(ac->random_state); - cfo[k] = ac->random_state; - } - - band_energy = ac->dsp.scalarproduct_float(cfo, cfo, off_len); - scale = sf[idx] / sqrtf(band_energy); - ac->dsp.vector_fmul_scalar(cfo, cfo, scale, off_len); - } - } else { - const float *vq = ff_aac_codebook_vector_vals[cbt_m1]; - const uint16_t *cb_vector_idx = ff_aac_codebook_vector_idx[cbt_m1]; - VLC_TYPE (*vlc_tab)[2] = vlc_spectral[cbt_m1].table; - OPEN_READER(re, gb); - - switch (cbt_m1 >> 1) { - case 0: - for (group = 0; group < g_len; group++, cfo+=128) { - float *cf = cfo; - int len = off_len; - - do { - int code; - unsigned cb_idx; - - UPDATE_CACHE(re, gb); - GET_VLC(code, re, gb, vlc_tab, 8, 2); - cb_idx = cb_vector_idx[code]; - cf = VMUL4(cf, vq, cb_idx, sf + idx); - } while (len -= 4); - } - break; - - case 1: - for (group = 0; group < g_len; group++, cfo+=128) { - float *cf = cfo; - int len = off_len; - - do { - int code; - unsigned nnz; - unsigned cb_idx; - uint32_t bits; - - UPDATE_CACHE(re, gb); - GET_VLC(code, re, gb, vlc_tab, 8, 2); - cb_idx = cb_vector_idx[code]; - nnz = cb_idx >> 8 & 15; - bits = nnz ? GET_CACHE(re, gb) : 0; - LAST_SKIP_BITS(re, gb, nnz); - cf = VMUL4S(cf, vq, cb_idx, bits, sf + idx); - } while (len -= 4); - } - break; - - case 2: - for (group = 0; group < g_len; group++, cfo+=128) { - float *cf = cfo; - int len = off_len; - - do { - int code; - unsigned cb_idx; - - UPDATE_CACHE(re, gb); - GET_VLC(code, re, gb, vlc_tab, 8, 2); - cb_idx = cb_vector_idx[code]; - cf = VMUL2(cf, vq, cb_idx, sf + idx); - } while (len -= 2); - } - break; - - case 3: - case 4: - for (group = 0; group < g_len; group++, cfo+=128) { - float *cf = cfo; - int len = off_len; - - do { - int code; - unsigned nnz; - unsigned cb_idx; - unsigned sign; - - UPDATE_CACHE(re, gb); - GET_VLC(code, re, gb, vlc_tab, 8, 2); - cb_idx = cb_vector_idx[code]; - nnz = cb_idx >> 8 & 15; - sign = nnz ? SHOW_UBITS(re, gb, nnz) << (cb_idx >> 12) : 0; - LAST_SKIP_BITS(re, gb, nnz); - cf = VMUL2S(cf, vq, cb_idx, sign, sf + idx); - } while (len -= 2); - } - break; - - default: - for (group = 0; group < g_len; group++, cfo+=128) { - float *cf = cfo; - uint32_t *icf = (uint32_t *) cf; - int len = off_len; - - do { - int code; - unsigned nzt, nnz; - unsigned cb_idx; - uint32_t bits; - int j; - - UPDATE_CACHE(re, gb); - GET_VLC(code, re, gb, vlc_tab, 8, 2); - - if (!code) { - *icf++ = 0; - *icf++ = 0; - continue; - } - - cb_idx = cb_vector_idx[code]; - nnz = cb_idx >> 12; - nzt = cb_idx >> 8; - bits = SHOW_UBITS(re, gb, nnz) << (32-nnz); - LAST_SKIP_BITS(re, gb, nnz); - - for (j = 0; j < 2; j++) { - if (nzt & 1<<j) { - uint32_t b; - int n; - /* The total length of escape_sequence must be < 22 bits according - to the specification (i.e. max is 111111110xxxxxxxxxxxx). */ - UPDATE_CACHE(re, gb); - b = GET_CACHE(re, gb); - b = 31 - av_log2(~b); - - if (b > 8) { - av_log(ac->avctx, AV_LOG_ERROR, "error in spectral data, ESC overflow\n"); - return -1; - } - - SKIP_BITS(re, gb, b + 1); - b += 4; - n = (1 << b) + SHOW_UBITS(re, gb, b); - LAST_SKIP_BITS(re, gb, b); - *icf++ = cbrt_tab[n] | (bits & 1U<<31); - bits <<= 1; - } else { - unsigned v = ((const uint32_t*)vq)[cb_idx & 15]; - *icf++ = (bits & 1U<<31) | v; - bits <<= !!v; - } - cb_idx >>= 4; - } - } while (len -= 2); - - ac->dsp.vector_fmul_scalar(cfo, cfo, sf[idx], off_len); - } - } - - CLOSE_READER(re, gb); - } - } - coef += g_len << 7; - } - - if (pulse_present) { - idx = 0; - for (i = 0; i < pulse->num_pulse; i++) { - float co = coef_base[ pulse->pos[i] ]; - while (offsets[idx + 1] <= pulse->pos[i]) - idx++; - if (band_type[idx] != NOISE_BT && sf[idx]) { - float ico = -pulse->amp[i]; - if (co) { - co /= sf[idx]; - ico = co / sqrtf(sqrtf(fabsf(co))) + (co > 0 ? -ico : ico); - } - coef_base[ pulse->pos[i] ] = cbrtf(fabsf(ico)) * ico * sf[idx]; - } - } - } - return 0; -} - -static av_always_inline float flt16_round(float pf) -{ - union av_intfloat32 tmp; - tmp.f = pf; - tmp.i = (tmp.i + 0x00008000U) & 0xFFFF0000U; - return tmp.f; -} - -static av_always_inline float flt16_even(float pf) -{ - union av_intfloat32 tmp; - tmp.f = pf; - tmp.i = (tmp.i + 0x00007FFFU + (tmp.i & 0x00010000U >> 16)) & 0xFFFF0000U; - return tmp.f; -} - -static av_always_inline float flt16_trunc(float pf) -{ - union av_intfloat32 pun; - pun.f = pf; - pun.i &= 0xFFFF0000U; - return pun.f; -} - -static av_always_inline void predict(PredictorState *ps, float *coef, - int output_enable) -{ - const float a = 0.953125; // 61.0 / 64 - const float alpha = 0.90625; // 29.0 / 32 - float e0, e1; - float pv; - float k1, k2; - float r0 = ps->r0, r1 = ps->r1; - float cor0 = ps->cor0, cor1 = ps->cor1; - float var0 = ps->var0, var1 = ps->var1; - - k1 = var0 > 1 ? cor0 * flt16_even(a / var0) : 0; - k2 = var1 > 1 ? cor1 * flt16_even(a / var1) : 0; - - pv = flt16_round(k1 * r0 + k2 * r1); - if (output_enable) - *coef += pv; - - e0 = *coef; - e1 = e0 - k1 * r0; - - ps->cor1 = flt16_trunc(alpha * cor1 + r1 * e1); - ps->var1 = flt16_trunc(alpha * var1 + 0.5f * (r1 * r1 + e1 * e1)); - ps->cor0 = flt16_trunc(alpha * cor0 + r0 * e0); - ps->var0 = flt16_trunc(alpha * var0 + 0.5f * (r0 * r0 + e0 * e0)); - - ps->r1 = flt16_trunc(a * (r0 - k1 * e0)); - ps->r0 = flt16_trunc(a * e0); -} - -/** - * Apply AAC-Main style frequency domain prediction. - */ -static void apply_prediction(AACContext *ac, SingleChannelElement *sce) -{ - int sfb, k; - - if (!sce->ics.predictor_initialized) { - reset_all_predictors(sce->predictor_state); - sce->ics.predictor_initialized = 1; - } - - if (sce->ics.window_sequence[0] != EIGHT_SHORT_SEQUENCE) { - for (sfb = 0; sfb < ff_aac_pred_sfb_max[ac->m4ac.sampling_index]; sfb++) { - for (k = sce->ics.swb_offset[sfb]; k < sce->ics.swb_offset[sfb + 1]; k++) { - predict(&sce->predictor_state[k], &sce->coeffs[k], - sce->ics.predictor_present && sce->ics.prediction_used[sfb]); - } - } - if (sce->ics.predictor_reset_group) - reset_predictor_group(sce->predictor_state, sce->ics.predictor_reset_group); - } else - reset_all_predictors(sce->predictor_state); -} - -/** - * Decode an individual_channel_stream payload; reference: table 4.44. - * - * @param common_window Channels have independent [0], or shared [1], Individual Channel Stream information. - * @param scale_flag scalable [1] or non-scalable [0] AAC (Unused until scalable AAC is implemented.) - * - * @return Returns error status. 0 - OK, !0 - error - */ -static int decode_ics(AACContext *ac, SingleChannelElement *sce, - GetBitContext *gb, int common_window, int scale_flag) -{ - Pulse pulse; - TemporalNoiseShaping *tns = &sce->tns; - IndividualChannelStream *ics = &sce->ics; - float *out = sce->coeffs; - int global_gain, pulse_present = 0; - - /* This assignment is to silence a GCC warning about the variable being used - * uninitialized when in fact it always is. - */ - pulse.num_pulse = 0; - - global_gain = get_bits(gb, 8); - - if (!common_window && !scale_flag) { - if (decode_ics_info(ac, ics, gb) < 0) - return AVERROR_INVALIDDATA; - } - - if (decode_band_types(ac, sce->band_type, sce->band_type_run_end, gb, ics) < 0) - return -1; - if (decode_scalefactors(ac, sce->sf, gb, global_gain, ics, sce->band_type, sce->band_type_run_end) < 0) - return -1; - - pulse_present = 0; - if (!scale_flag) { - if ((pulse_present = get_bits1(gb))) { - if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { - av_log(ac->avctx, AV_LOG_ERROR, "Pulse tool not allowed in eight short sequence.\n"); - return -1; - } - if (decode_pulses(&pulse, gb, ics->swb_offset, ics->num_swb)) { - av_log(ac->avctx, AV_LOG_ERROR, "Pulse data corrupt or invalid.\n"); - return -1; - } - } - if ((tns->present = get_bits1(gb)) && decode_tns(ac, tns, gb, ics)) - return -1; - if (get_bits1(gb)) { - av_log_missing_feature(ac->avctx, "SSR", 1); - return -1; - } - } - - if (decode_spectrum_and_dequant(ac, out, gb, sce->sf, pulse_present, &pulse, ics, sce->band_type) < 0) - return -1; - - if (ac->m4ac.object_type == AOT_AAC_MAIN && !common_window) - apply_prediction(ac, sce); - - return 0; -} - -/** - * Mid/Side stereo decoding; reference: 4.6.8.1.3. - */ -static void apply_mid_side_stereo(AACContext *ac, ChannelElement *cpe) -{ - const IndividualChannelStream *ics = &cpe->ch[0].ics; - float *ch0 = cpe->ch[0].coeffs; - float *ch1 = cpe->ch[1].coeffs; - int g, i, group, idx = 0; - const uint16_t *offsets = ics->swb_offset; - for (g = 0; g < ics->num_window_groups; g++) { - for (i = 0; i < ics->max_sfb; i++, idx++) { - if (cpe->ms_mask[idx] && - cpe->ch[0].band_type[idx] < NOISE_BT && cpe->ch[1].band_type[idx] < NOISE_BT) { - for (group = 0; group < ics->group_len[g]; group++) { - ac->dsp.butterflies_float(ch0 + group * 128 + offsets[i], - ch1 + group * 128 + offsets[i], - offsets[i+1] - offsets[i]); - } - } - } - ch0 += ics->group_len[g] * 128; - ch1 += ics->group_len[g] * 128; - } -} - -/** - * intensity stereo decoding; reference: 4.6.8.2.3 - * - * @param ms_present Indicates mid/side stereo presence. [0] mask is all 0s; - * [1] mask is decoded from bitstream; [2] mask is all 1s; - * [3] reserved for scalable AAC - */ -static void apply_intensity_stereo(AACContext *ac, ChannelElement *cpe, int ms_present) -{ - const IndividualChannelStream *ics = &cpe->ch[1].ics; - SingleChannelElement *sce1 = &cpe->ch[1]; - float *coef0 = cpe->ch[0].coeffs, *coef1 = cpe->ch[1].coeffs; - const uint16_t *offsets = ics->swb_offset; - int g, group, i, idx = 0; - int c; - float scale; - for (g = 0; g < ics->num_window_groups; g++) { - for (i = 0; i < ics->max_sfb;) { - if (sce1->band_type[idx] == INTENSITY_BT || sce1->band_type[idx] == INTENSITY_BT2) { - const int bt_run_end = sce1->band_type_run_end[idx]; - for (; i < bt_run_end; i++, idx++) { - c = -1 + 2 * (sce1->band_type[idx] - 14); - if (ms_present) - c *= 1 - 2 * cpe->ms_mask[idx]; - scale = c * sce1->sf[idx]; - for (group = 0; group < ics->group_len[g]; group++) - ac->dsp.vector_fmul_scalar(coef1 + group * 128 + offsets[i], - coef0 + group * 128 + offsets[i], - scale, - offsets[i + 1] - offsets[i]); - } - } else { - int bt_run_end = sce1->band_type_run_end[idx]; - idx += bt_run_end - i; - i = bt_run_end; - } - } - coef0 += ics->group_len[g] * 128; - coef1 += ics->group_len[g] * 128; - } -} - -/** - * Decode a channel_pair_element; reference: table 4.4. - * - * @return Returns error status. 0 - OK, !0 - error - */ -static int decode_cpe(AACContext *ac, GetBitContext *gb, ChannelElement *cpe) -{ - int i, ret, common_window, ms_present = 0; - - common_window = get_bits1(gb); - if (common_window) { - if (decode_ics_info(ac, &cpe->ch[0].ics, gb)) - return AVERROR_INVALIDDATA; - i = cpe->ch[1].ics.use_kb_window[0]; - cpe->ch[1].ics = cpe->ch[0].ics; - cpe->ch[1].ics.use_kb_window[1] = i; - if (cpe->ch[1].ics.predictor_present && (ac->m4ac.object_type != AOT_AAC_MAIN)) - if ((cpe->ch[1].ics.ltp.present = get_bits(gb, 1))) - decode_ltp(ac, &cpe->ch[1].ics.ltp, gb, cpe->ch[1].ics.max_sfb); - ms_present = get_bits(gb, 2); - if (ms_present == 3) { - av_log(ac->avctx, AV_LOG_ERROR, "ms_present = 3 is reserved.\n"); - return -1; - } else if (ms_present) - decode_mid_side_stereo(cpe, gb, ms_present); - } - if ((ret = decode_ics(ac, &cpe->ch[0], gb, common_window, 0))) - return ret; - if ((ret = decode_ics(ac, &cpe->ch[1], gb, common_window, 0))) - return ret; - - if (common_window) { - if (ms_present) - apply_mid_side_stereo(ac, cpe); - if (ac->m4ac.object_type == AOT_AAC_MAIN) { - apply_prediction(ac, &cpe->ch[0]); - apply_prediction(ac, &cpe->ch[1]); - } - } - - apply_intensity_stereo(ac, cpe, ms_present); - return 0; -} - -static const float cce_scale[] = { - 1.09050773266525765921, //2^(1/8) - 1.18920711500272106672, //2^(1/4) - M_SQRT2, - 2, -}; - -/** - * Decode coupling_channel_element; reference: table 4.8. - * - * @return Returns error status. 0 - OK, !0 - error - */ -static int decode_cce(AACContext *ac, GetBitContext *gb, ChannelElement *che) -{ - int num_gain = 0; - int c, g, sfb, ret; - int sign; - float scale; - SingleChannelElement *sce = &che->ch[0]; - ChannelCoupling *coup = &che->coup; - - coup->coupling_point = 2 * get_bits1(gb); - coup->num_coupled = get_bits(gb, 3); - for (c = 0; c <= coup->num_coupled; c++) { - num_gain++; - coup->type[c] = get_bits1(gb) ? TYPE_CPE : TYPE_SCE; - coup->id_select[c] = get_bits(gb, 4); - if (coup->type[c] == TYPE_CPE) { - coup->ch_select[c] = get_bits(gb, 2); - if (coup->ch_select[c] == 3) - num_gain++; - } else - coup->ch_select[c] = 2; - } - coup->coupling_point += get_bits1(gb) || (coup->coupling_point >> 1); - - sign = get_bits(gb, 1); - scale = cce_scale[get_bits(gb, 2)]; - - if ((ret = decode_ics(ac, sce, gb, 0, 0))) - return ret; - - for (c = 0; c < num_gain; c++) { - int idx = 0; - int cge = 1; - int gain = 0; - float gain_cache = 1.; - if (c) { - cge = coup->coupling_point == AFTER_IMDCT ? 1 : get_bits1(gb); - gain = cge ? get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60: 0; - gain_cache = powf(scale, -gain); - } - if (coup->coupling_point == AFTER_IMDCT) { - coup->gain[c][0] = gain_cache; - } else { - for (g = 0; g < sce->ics.num_window_groups; g++) { - for (sfb = 0; sfb < sce->ics.max_sfb; sfb++, idx++) { - if (sce->band_type[idx] != ZERO_BT) { - if (!cge) { - int t = get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60; - if (t) { - int s = 1; - t = gain += t; - if (sign) { - s -= 2 * (t & 0x1); - t >>= 1; - } - gain_cache = powf(scale, -t) * s; - } - } - coup->gain[c][idx] = gain_cache; - } - } - } - } - } - return 0; -} - -/** - * Parse whether channels are to be excluded from Dynamic Range Compression; reference: table 4.53. - * - * @return Returns number of bytes consumed. - */ -static int decode_drc_channel_exclusions(DynamicRangeControl *che_drc, - GetBitContext *gb) -{ - int i; - int num_excl_chan = 0; - - do { - for (i = 0; i < 7; i++) - che_drc->exclude_mask[num_excl_chan++] = get_bits1(gb); - } while (num_excl_chan < MAX_CHANNELS - 7 && get_bits1(gb)); - - return num_excl_chan / 7; -} - -/** - * Decode dynamic range information; reference: table 4.52. - * - * @param cnt length of TYPE_FIL syntactic element in bytes - * - * @return Returns number of bytes consumed. - */ -static int decode_dynamic_range(DynamicRangeControl *che_drc, - GetBitContext *gb, int cnt) -{ - int n = 1; - int drc_num_bands = 1; - int i; - - /* pce_tag_present? */ - if (get_bits1(gb)) { - che_drc->pce_instance_tag = get_bits(gb, 4); - skip_bits(gb, 4); // tag_reserved_bits - n++; - } - - /* excluded_chns_present? */ - if (get_bits1(gb)) { - n += decode_drc_channel_exclusions(che_drc, gb); - } - - /* drc_bands_present? */ - if (get_bits1(gb)) { - che_drc->band_incr = get_bits(gb, 4); - che_drc->interpolation_scheme = get_bits(gb, 4); - n++; - drc_num_bands += che_drc->band_incr; - for (i = 0; i < drc_num_bands; i++) { - che_drc->band_top[i] = get_bits(gb, 8); - n++; - } - } - - /* prog_ref_level_present? */ - if (get_bits1(gb)) { - che_drc->prog_ref_level = get_bits(gb, 7); - skip_bits1(gb); // prog_ref_level_reserved_bits - n++; - } - - for (i = 0; i < drc_num_bands; i++) { - che_drc->dyn_rng_sgn[i] = get_bits1(gb); - che_drc->dyn_rng_ctl[i] = get_bits(gb, 7); - n++; - } - - return n; -} - -/** - * Decode extension data (incomplete); reference: table 4.51. - * - * @param cnt length of TYPE_FIL syntactic element in bytes - * - * @return Returns number of bytes consumed - */ -static int decode_extension_payload(AACContext *ac, GetBitContext *gb, int cnt, - ChannelElement *che, enum RawDataBlockType elem_type) -{ - int crc_flag = 0; - int res = cnt; - switch (get_bits(gb, 4)) { // extension type - case EXT_SBR_DATA_CRC: - crc_flag++; - case EXT_SBR_DATA: - if (!che) { - av_log(ac->avctx, AV_LOG_ERROR, "SBR was found before the first channel element.\n"); - return res; - } else if (!ac->m4ac.sbr) { - av_log(ac->avctx, AV_LOG_ERROR, "SBR signaled to be not-present but was found in the bitstream.\n"); - skip_bits_long(gb, 8 * cnt - 4); - return res; - } else if (ac->m4ac.sbr == -1 && ac->output_configured == OC_LOCKED) { - av_log(ac->avctx, AV_LOG_ERROR, "Implicit SBR was found with a first occurrence after the first frame.\n"); - skip_bits_long(gb, 8 * cnt - 4); - return res; - } else if (ac->m4ac.ps == -1 && ac->output_configured < OC_LOCKED && ac->avctx->channels == 1) { - ac->m4ac.sbr = 1; - ac->m4ac.ps = 1; - output_configure(ac, ac->layout_map, ac->layout_map_tags, - ac->m4ac.chan_config, ac->output_configured); - } else { - ac->m4ac.sbr = 1; - } - res = ff_decode_sbr_extension(ac, &che->sbr, gb, crc_flag, cnt, elem_type); - break; - case EXT_DYNAMIC_RANGE: - res = decode_dynamic_range(&ac->che_drc, gb, cnt); - break; - case EXT_FILL: - case EXT_FILL_DATA: - case EXT_DATA_ELEMENT: - default: - skip_bits_long(gb, 8 * cnt - 4); - break; - }; - return res; -} - -/** - * Decode Temporal Noise Shaping filter coefficients and apply all-pole filters; reference: 4.6.9.3. - * - * @param decode 1 if tool is used normally, 0 if tool is used in LTP. - * @param coef spectral coefficients - */ -static void apply_tns(float coef[1024], TemporalNoiseShaping *tns, - IndividualChannelStream *ics, int decode) -{ - const int mmm = FFMIN(ics->tns_max_bands, ics->max_sfb); - int w, filt, m, i; - int bottom, top, order, start, end, size, inc; - float lpc[TNS_MAX_ORDER]; - float tmp[TNS_MAX_ORDER]; - - for (w = 0; w < ics->num_windows; w++) { - bottom = ics->num_swb; - for (filt = 0; filt < tns->n_filt[w]; filt++) { - top = bottom; - bottom = FFMAX(0, top - tns->length[w][filt]); - order = tns->order[w][filt]; - if (order == 0) - continue; - - // tns_decode_coef - compute_lpc_coefs(tns->coef[w][filt], order, lpc, 0, 0, 0); - - start = ics->swb_offset[FFMIN(bottom, mmm)]; - end = ics->swb_offset[FFMIN( top, mmm)]; - if ((size = end - start) <= 0) - continue; - if (tns->direction[w][filt]) { - inc = -1; - start = end - 1; - } else { - inc = 1; - } - start += w * 128; - - if (decode) { - // ar filter - for (m = 0; m < size; m++, start += inc) - for (i = 1; i <= FFMIN(m, order); i++) - coef[start] -= coef[start - i * inc] * lpc[i - 1]; - } else { - // ma filter - for (m = 0; m < size; m++, start += inc) { - tmp[0] = coef[start]; - for (i = 1; i <= FFMIN(m, order); i++) - coef[start] += tmp[i] * lpc[i - 1]; - for (i = order; i > 0; i--) - tmp[i] = tmp[i - 1]; - } - } - } - } -} - -/** - * Apply windowing and MDCT to obtain the spectral - * coefficient from the predicted sample by LTP. - */ -static void windowing_and_mdct_ltp(AACContext *ac, float *out, - float *in, IndividualChannelStream *ics) -{ - const float *lwindow = ics->use_kb_window[0] ? ff_aac_kbd_long_1024 : ff_sine_1024; - const float *swindow = ics->use_kb_window[0] ? ff_aac_kbd_short_128 : ff_sine_128; - const float *lwindow_prev = ics->use_kb_window[1] ? ff_aac_kbd_long_1024 : ff_sine_1024; - const float *swindow_prev = ics->use_kb_window[1] ? ff_aac_kbd_short_128 : ff_sine_128; - - if (ics->window_sequence[0] != LONG_STOP_SEQUENCE) { - ac->dsp.vector_fmul(in, in, lwindow_prev, 1024); - } else { - memset(in, 0, 448 * sizeof(float)); - ac->dsp.vector_fmul(in + 448, in + 448, swindow_prev, 128); - } - if (ics->window_sequence[0] != LONG_START_SEQUENCE) { - ac->dsp.vector_fmul_reverse(in + 1024, in + 1024, lwindow, 1024); - } else { - ac->dsp.vector_fmul_reverse(in + 1024 + 448, in + 1024 + 448, swindow, 128); - memset(in + 1024 + 576, 0, 448 * sizeof(float)); - } - ac->mdct_ltp.mdct_calc(&ac->mdct_ltp, out, in); -} - -/** - * Apply the long term prediction - */ -static void apply_ltp(AACContext *ac, SingleChannelElement *sce) -{ - const LongTermPrediction *ltp = &sce->ics.ltp; - const uint16_t *offsets = sce->ics.swb_offset; - int i, sfb; - - if (sce->ics.window_sequence[0] != EIGHT_SHORT_SEQUENCE) { - float *predTime = sce->ret; - float *predFreq = ac->buf_mdct; - int16_t num_samples = 2048; - - if (ltp->lag < 1024) - num_samples = ltp->lag + 1024; - for (i = 0; i < num_samples; i++) - predTime[i] = sce->ltp_state[i + 2048 - ltp->lag] * ltp->coef; - memset(&predTime[i], 0, (2048 - i) * sizeof(float)); - - windowing_and_mdct_ltp(ac, predFreq, predTime, &sce->ics); - - if (sce->tns.present) - apply_tns(predFreq, &sce->tns, &sce->ics, 0); - - for (sfb = 0; sfb < FFMIN(sce->ics.max_sfb, MAX_LTP_LONG_SFB); sfb++) - if (ltp->used[sfb]) - for (i = offsets[sfb]; i < offsets[sfb + 1]; i++) - sce->coeffs[i] += predFreq[i]; - } -} - -/** - * Update the LTP buffer for next frame - */ -static void update_ltp(AACContext *ac, SingleChannelElement *sce) -{ - IndividualChannelStream *ics = &sce->ics; - float *saved = sce->saved; - float *saved_ltp = sce->coeffs; - const float *lwindow = ics->use_kb_window[0] ? ff_aac_kbd_long_1024 : ff_sine_1024; - const float *swindow = ics->use_kb_window[0] ? ff_aac_kbd_short_128 : ff_sine_128; - int i; - - if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { - memcpy(saved_ltp, saved, 512 * sizeof(float)); - memset(saved_ltp + 576, 0, 448 * sizeof(float)); - ac->dsp.vector_fmul_reverse(saved_ltp + 448, ac->buf_mdct + 960, &swindow[64], 64); - for (i = 0; i < 64; i++) - saved_ltp[i + 512] = ac->buf_mdct[1023 - i] * swindow[63 - i]; - } else if (ics->window_sequence[0] == LONG_START_SEQUENCE) { - memcpy(saved_ltp, ac->buf_mdct + 512, 448 * sizeof(float)); - memset(saved_ltp + 576, 0, 448 * sizeof(float)); - ac->dsp.vector_fmul_reverse(saved_ltp + 448, ac->buf_mdct + 960, &swindow[64], 64); - for (i = 0; i < 64; i++) - saved_ltp[i + 512] = ac->buf_mdct[1023 - i] * swindow[63 - i]; - } else { // LONG_STOP or ONLY_LONG - ac->dsp.vector_fmul_reverse(saved_ltp, ac->buf_mdct + 512, &lwindow[512], 512); - for (i = 0; i < 512; i++) - saved_ltp[i + 512] = ac->buf_mdct[1023 - i] * lwindow[511 - i]; - } - - memcpy(sce->ltp_state, sce->ltp_state+1024, 1024 * sizeof(*sce->ltp_state)); - memcpy(sce->ltp_state+1024, sce->ret, 1024 * sizeof(*sce->ltp_state)); - memcpy(sce->ltp_state+2048, saved_ltp, 1024 * sizeof(*sce->ltp_state)); -} - -/** - * Conduct IMDCT and windowing. - */ -static void imdct_and_windowing(AACContext *ac, SingleChannelElement *sce) -{ - IndividualChannelStream *ics = &sce->ics; - float *in = sce->coeffs; - float *out = sce->ret; - float *saved = sce->saved; - const float *swindow = ics->use_kb_window[0] ? ff_aac_kbd_short_128 : ff_sine_128; - const float *lwindow_prev = ics->use_kb_window[1] ? ff_aac_kbd_long_1024 : ff_sine_1024; - const float *swindow_prev = ics->use_kb_window[1] ? ff_aac_kbd_short_128 : ff_sine_128; - float *buf = ac->buf_mdct; - float *temp = ac->temp; - int i; - - // imdct - if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { - for (i = 0; i < 1024; i += 128) - ac->mdct_small.imdct_half(&ac->mdct_small, buf + i, in + i); - } else - ac->mdct.imdct_half(&ac->mdct, buf, in); - - /* window overlapping - * NOTE: To simplify the overlapping code, all 'meaningless' short to long - * and long to short transitions are considered to be short to short - * transitions. This leaves just two cases (long to long and short to short) - * with a little special sauce for EIGHT_SHORT_SEQUENCE. - */ - if ((ics->window_sequence[1] == ONLY_LONG_SEQUENCE || ics->window_sequence[1] == LONG_STOP_SEQUENCE) && - (ics->window_sequence[0] == ONLY_LONG_SEQUENCE || ics->window_sequence[0] == LONG_START_SEQUENCE)) { - ac->dsp.vector_fmul_window( out, saved, buf, lwindow_prev, 512); - } else { - memcpy( out, saved, 448 * sizeof(float)); - - if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { - ac->dsp.vector_fmul_window(out + 448 + 0*128, saved + 448, buf + 0*128, swindow_prev, 64); - ac->dsp.vector_fmul_window(out + 448 + 1*128, buf + 0*128 + 64, buf + 1*128, swindow, 64); - ac->dsp.vector_fmul_window(out + 448 + 2*128, buf + 1*128 + 64, buf + 2*128, swindow, 64); - ac->dsp.vector_fmul_window(out + 448 + 3*128, buf + 2*128 + 64, buf + 3*128, swindow, 64); - ac->dsp.vector_fmul_window(temp, buf + 3*128 + 64, buf + 4*128, swindow, 64); - memcpy( out + 448 + 4*128, temp, 64 * sizeof(float)); - } else { - ac->dsp.vector_fmul_window(out + 448, saved + 448, buf, swindow_prev, 64); - memcpy( out + 576, buf + 64, 448 * sizeof(float)); - } - } - - // buffer update - if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { - memcpy( saved, temp + 64, 64 * sizeof(float)); - ac->dsp.vector_fmul_window(saved + 64, buf + 4*128 + 64, buf + 5*128, swindow, 64); - ac->dsp.vector_fmul_window(saved + 192, buf + 5*128 + 64, buf + 6*128, swindow, 64); - ac->dsp.vector_fmul_window(saved + 320, buf + 6*128 + 64, buf + 7*128, swindow, 64); - memcpy( saved + 448, buf + 7*128 + 64, 64 * sizeof(float)); - } else if (ics->window_sequence[0] == LONG_START_SEQUENCE) { - memcpy( saved, buf + 512, 448 * sizeof(float)); - memcpy( saved + 448, buf + 7*128 + 64, 64 * sizeof(float)); - } else { // LONG_STOP or ONLY_LONG - memcpy( saved, buf + 512, 512 * sizeof(float)); - } -} - -/** - * Apply dependent channel coupling (applied before IMDCT). - * - * @param index index into coupling gain array - */ -static void apply_dependent_coupling(AACContext *ac, - SingleChannelElement *target, - ChannelElement *cce, int index) -{ - IndividualChannelStream *ics = &cce->ch[0].ics; - const uint16_t *offsets = ics->swb_offset; - float *dest = target->coeffs; - const float *src = cce->ch[0].coeffs; - int g, i, group, k, idx = 0; - if (ac->m4ac.object_type == AOT_AAC_LTP) { - av_log(ac->avctx, AV_LOG_ERROR, - "Dependent coupling is not supported together with LTP\n"); - return; - } - for (g = 0; g < ics->num_window_groups; g++) { - for (i = 0; i < ics->max_sfb; i++, idx++) { - if (cce->ch[0].band_type[idx] != ZERO_BT) { - const float gain = cce->coup.gain[index][idx]; - for (group = 0; group < ics->group_len[g]; group++) { - for (k = offsets[i]; k < offsets[i + 1]; k++) { - // XXX dsputil-ize - dest[group * 128 + k] += gain * src[group * 128 + k]; - } - } - } - } - dest += ics->group_len[g] * 128; - src += ics->group_len[g] * 128; - } -} - -/** - * Apply independent channel coupling (applied after IMDCT). - * - * @param index index into coupling gain array - */ -static void apply_independent_coupling(AACContext *ac, - SingleChannelElement *target, - ChannelElement *cce, int index) -{ - int i; - const float gain = cce->coup.gain[index][0]; - const float *src = cce->ch[0].ret; - float *dest = target->ret; - const int len = 1024 << (ac->m4ac.sbr == 1); - - for (i = 0; i < len; i++) - dest[i] += gain * src[i]; -} - -/** - * channel coupling transformation interface - * - * @param apply_coupling_method pointer to (in)dependent coupling function - */ -static void apply_channel_coupling(AACContext *ac, ChannelElement *cc, - enum RawDataBlockType type, int elem_id, - enum CouplingPoint coupling_point, - void (*apply_coupling_method)(AACContext *ac, SingleChannelElement *target, ChannelElement *cce, int index)) -{ - int i, c; - - for (i = 0; i < MAX_ELEM_ID; i++) { - ChannelElement *cce = ac->che[TYPE_CCE][i]; - int index = 0; - - if (cce && cce->coup.coupling_point == coupling_point) { - ChannelCoupling *coup = &cce->coup; - - for (c = 0; c <= coup->num_coupled; c++) { - if (coup->type[c] == type && coup->id_select[c] == elem_id) { - if (coup->ch_select[c] != 1) { - apply_coupling_method(ac, &cc->ch[0], cce, index); - if (coup->ch_select[c] != 0) - index++; - } - if (coup->ch_select[c] != 2) - apply_coupling_method(ac, &cc->ch[1], cce, index++); - } else - index += 1 + (coup->ch_select[c] == 3); - } - } - } -} - -/** - * Convert spectral data to float samples, applying all supported tools as appropriate. - */ -static void spectral_to_sample(AACContext *ac) -{ - int i, type; - for (type = 3; type >= 0; type--) { - for (i = 0; i < MAX_ELEM_ID; i++) { - ChannelElement *che = ac->che[type][i]; - if (che) { - if (type <= TYPE_CPE) - apply_channel_coupling(ac, che, type, i, BEFORE_TNS, apply_dependent_coupling); - if (ac->m4ac.object_type == AOT_AAC_LTP) { - if (che->ch[0].ics.predictor_present) { - if (che->ch[0].ics.ltp.present) - apply_ltp(ac, &che->ch[0]); - if (che->ch[1].ics.ltp.present && type == TYPE_CPE) - apply_ltp(ac, &che->ch[1]); - } - } - if (che->ch[0].tns.present) - apply_tns(che->ch[0].coeffs, &che->ch[0].tns, &che->ch[0].ics, 1); - if (che->ch[1].tns.present) - apply_tns(che->ch[1].coeffs, &che->ch[1].tns, &che->ch[1].ics, 1); - if (type <= TYPE_CPE) - apply_channel_coupling(ac, che, type, i, BETWEEN_TNS_AND_IMDCT, apply_dependent_coupling); - if (type != TYPE_CCE || che->coup.coupling_point == AFTER_IMDCT) { - imdct_and_windowing(ac, &che->ch[0]); - if (ac->m4ac.object_type == AOT_AAC_LTP) - update_ltp(ac, &che->ch[0]); - if (type == TYPE_CPE) { - imdct_and_windowing(ac, &che->ch[1]); - if (ac->m4ac.object_type == AOT_AAC_LTP) - update_ltp(ac, &che->ch[1]); - } - if (ac->m4ac.sbr > 0) { - ff_sbr_apply(ac, &che->sbr, type, che->ch[0].ret, che->ch[1].ret); - } - } - if (type <= TYPE_CCE) - apply_channel_coupling(ac, che, type, i, AFTER_IMDCT, apply_independent_coupling); - } - } - } -} - -static int parse_adts_frame_header(AACContext *ac, GetBitContext *gb) -{ - int size; - AACADTSHeaderInfo hdr_info; - uint8_t layout_map[MAX_ELEM_ID*4][3]; - int layout_map_tags; - - size = avpriv_aac_parse_header(gb, &hdr_info); - if (size > 0) { - if (hdr_info.chan_config) { - ac->m4ac.chan_config = hdr_info.chan_config; - if (set_default_channel_config(ac->avctx, layout_map, - &layout_map_tags, hdr_info.chan_config)) - return -7; - if (output_configure(ac, layout_map, layout_map_tags, - hdr_info.chan_config, - FFMAX(ac->output_configured, OC_TRIAL_FRAME))) - return -7; - } else if (ac->output_configured != OC_LOCKED) { - ac->m4ac.chan_config = 0; - ac->output_configured = OC_NONE; - } - if (ac->output_configured != OC_LOCKED) { - ac->m4ac.sbr = -1; - ac->m4ac.ps = -1; - ac->m4ac.sample_rate = hdr_info.sample_rate; - ac->m4ac.sampling_index = hdr_info.sampling_index; - ac->m4ac.object_type = hdr_info.object_type; - } - if (!ac->avctx->sample_rate) - ac->avctx->sample_rate = hdr_info.sample_rate; - if (!ac->warned_num_aac_frames && hdr_info.num_aac_frames != 1) { - // This is 2 for "VLB " audio in NSV files. - // See samples/nsv/vlb_audio. - av_log_missing_feature(ac->avctx, "More than one AAC RDB per ADTS frame is", 0); - ac->warned_num_aac_frames = 1; - } - if (!hdr_info.crc_absent) - skip_bits(gb, 16); - } - return size; -} - -/* ffdshow custom code */ -void float_interleave(float *dst, const float **src, long len, int channels) -{ - int i,j,c; - if(channels==2){ - for(i=0; i<len; i++){ - dst[2*i] = src[0][i] / 32768.0f; - dst[2*i+1] = src[1][i] / 32768.0f; - } - }else{ - for(c=0; c<channels; c++) - for(i=0, j=c; i<len; i++, j+=channels) - dst[j] = src[c][i] / 32768.0f; - } -} - -static int aac_decode_frame_int(AVCodecContext *avctx, void *data, - int *got_frame_ptr, GetBitContext *gb) -{ - AACContext *ac = avctx->priv_data; - ChannelElement *che = NULL, *che_prev = NULL; - enum RawDataBlockType elem_type, elem_type_prev = TYPE_END; - int err, elem_id; - int samples = 0, multiplier, audio_found = 0; - - if (show_bits(gb, 12) == 0xfff) { - if (parse_adts_frame_header(ac, gb) < 0) { - av_log(avctx, AV_LOG_ERROR, "Error decoding AAC frame header.\n"); - return -1; - } - if (ac->m4ac.sampling_index > 12) { - av_log(ac->avctx, AV_LOG_ERROR, "invalid sampling rate index %d\n", ac->m4ac.sampling_index); - return -1; - } - } - - ac->tags_mapped = 0; - // parse - while ((elem_type = get_bits(gb, 3)) != TYPE_END) { - elem_id = get_bits(gb, 4); - - if (elem_type < TYPE_DSE) { - if (!(che=get_che(ac, elem_type, elem_id))) { - av_log(ac->avctx, AV_LOG_ERROR, "channel element %d.%d is not allocated\n", - elem_type, elem_id); - return -1; - } - samples = 1024; - } - - switch (elem_type) { - - case TYPE_SCE: - err = decode_ics(ac, &che->ch[0], gb, 0, 0); - audio_found = 1; - break; - - case TYPE_CPE: - err = decode_cpe(ac, gb, che); - audio_found = 1; - break; - - case TYPE_CCE: - err = decode_cce(ac, gb, che); - break; - - case TYPE_LFE: - err = decode_ics(ac, &che->ch[0], gb, 0, 0); - audio_found = 1; - break; - - case TYPE_DSE: - err = skip_data_stream_element(ac, gb); - break; - - case TYPE_PCE: { - uint8_t layout_map[MAX_ELEM_ID*4][3]; - int tags; - tags = decode_pce(avctx, &ac->m4ac, layout_map, gb); - if (tags < 0) { - err = tags; - break; - } - if (ac->output_configured > OC_TRIAL_PCE) - av_log(avctx, AV_LOG_INFO, - "Evaluating a further program_config_element.\n"); - err = output_configure(ac, layout_map, tags, 0, OC_TRIAL_PCE); - if (!err) - ac->m4ac.chan_config = 0; - break; - } - - case TYPE_FIL: - if (elem_id == 15) - elem_id += get_bits(gb, 8) - 1; - if (get_bits_left(gb) < 8 * elem_id) { - av_log(avctx, AV_LOG_ERROR, overread_err); - return -1; - } - while (elem_id > 0) - elem_id -= decode_extension_payload(ac, gb, elem_id, che_prev, elem_type_prev); - err = 0; /* FIXME */ - break; - - default: - err = -1; /* should not happen, but keeps compiler happy */ - break; - } - - che_prev = che; - elem_type_prev = elem_type; - - if (err) - return err; - - if (get_bits_left(gb) < 3) { - av_log(avctx, AV_LOG_ERROR, overread_err); - return -1; - } - } - - spectral_to_sample(ac); - - multiplier = (ac->m4ac.sbr == 1) ? ac->m4ac.ext_sample_rate > ac->m4ac.sample_rate : 0; - samples <<= multiplier; - if (ac->output_configured < OC_LOCKED) { - avctx->sample_rate = ac->m4ac.sample_rate << multiplier; - avctx->frame_size = samples; - } - - if (samples) { - /* get output buffer */ - ac->frame.nb_samples = samples; - if ((err = avctx->get_buffer(avctx, &ac->frame)) < 0) { - av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return err; - } - - if (avctx->sample_fmt == AV_SAMPLE_FMT_FLT) - /*ac->fmt_conv.*/float_interleave((float *)ac->frame.data[0], - (const float **)ac->output_data, - samples, avctx->channels); - else - ac->fmt_conv.float_to_int16_interleave((int16_t *)ac->frame.data[0], - (const float **)ac->output_data, - samples, avctx->channels); - - *(AVFrame *)data = ac->frame; - } - *got_frame_ptr = !!samples; - - if (ac->output_configured && audio_found) - ac->output_configured = OC_LOCKED; - - return 0; -} - -static int aac_decode_frame(AVCodecContext *avctx, void *data, - int *got_frame_ptr, AVPacket *avpkt) -{ - const uint8_t *buf = avpkt->data; - int buf_size = avpkt->size; - GetBitContext gb; - int buf_consumed; - int buf_offset; - int err; - - init_get_bits(&gb, buf, buf_size * 8); - - if ((err = aac_decode_frame_int(avctx, data, got_frame_ptr, &gb)) < 0) - return err; - - buf_consumed = (get_bits_count(&gb) + 7) >> 3; - for (buf_offset = buf_consumed; buf_offset < buf_size; buf_offset++) - if (buf[buf_offset]) - break; - - return buf_size > buf_offset ? buf_consumed : buf_size; -} - -static av_cold int aac_decode_close(AVCodecContext *avctx) -{ - AACContext *ac = avctx->priv_data; - int i, type; - - if (!avctx->extradata_size && ac->m4ac.object_type) { - avctx->extradata = av_mallocz(2); - avctx->extradata_size = 2; - PutBitContext pb; - init_put_bits(&pb, avctx->extradata, avctx->extradata_size); - put_bits(&pb, 5, ac->m4ac.object_type); - put_bits(&pb, 4, ac->m4ac.sampling_index); - put_bits(&pb, 4, ac->m4ac.chan_config); - put_bits(&pb, 1, 0); //frame length - 1024 samples - put_bits(&pb, 1, 0); //does not depend on core coder - put_bits(&pb, 1, 0); //is not extension - flush_put_bits(&pb); - } - - for (i = 0; i < MAX_ELEM_ID; i++) { - for (type = 0; type < 4; type++) { - if (ac->che[type][i]) - ff_aac_sbr_ctx_close(&ac->che[type][i]->sbr); - av_freep(&ac->che[type][i]); - } - } - - ff_mdct_end(&ac->mdct); - ff_mdct_end(&ac->mdct_small); - ff_mdct_end(&ac->mdct_ltp); - return 0; -} - - -#define LOAS_SYNC_WORD 0x2b7 ///< 11 bits LOAS sync word - -struct LATMContext { - AACContext aac_ctx; ///< containing AACContext - int initialized; ///< initilized after a valid extradata was seen - - // parser data - int audio_mux_version_A; ///< LATM syntax version - int frame_length_type; ///< 0/1 variable/fixed frame length - int frame_length; ///< frame length for fixed frame length -}; - -static inline uint32_t latm_get_value(GetBitContext *b) -{ - int length = get_bits(b, 2); - - return get_bits_long(b, (length+1)*8); -} - -static int latm_decode_audio_specific_config(struct LATMContext *latmctx, - GetBitContext *gb, int asclen) -{ - AACContext *ac = &latmctx->aac_ctx; - AVCodecContext *avctx = ac->avctx; - MPEG4AudioConfig m4ac = {0}; - int config_start_bit = get_bits_count(gb); - int sync_extension = 0; - int bits_consumed, esize; - - if (asclen) { - sync_extension = 1; - asclen = FFMIN(asclen, get_bits_left(gb)); - } else - asclen = get_bits_left(gb); - - if (config_start_bit % 8) { - av_log_missing_feature(latmctx->aac_ctx.avctx, "audio specific " - "config not byte aligned.\n", 1); - return AVERROR_INVALIDDATA; - } - if (asclen <= 0) - return AVERROR_INVALIDDATA; - bits_consumed = decode_audio_specific_config(NULL, avctx, &m4ac, - gb->buffer + (config_start_bit / 8), - asclen, sync_extension); - - if (bits_consumed < 0) - return AVERROR_INVALIDDATA; - - if (ac->m4ac.sample_rate != m4ac.sample_rate || - ac->m4ac.chan_config != m4ac.chan_config) { - - av_log(avctx, AV_LOG_INFO, "audio config changed\n"); - latmctx->initialized = 0; - - esize = (bits_consumed+7) / 8; - - if (avctx->extradata_size < esize) { - av_free(avctx->extradata); - avctx->extradata = av_malloc(esize + FF_INPUT_BUFFER_PADDING_SIZE); - if (!avctx->extradata) - return AVERROR(ENOMEM); - } - - avctx->extradata_size = esize; - memcpy(avctx->extradata, gb->buffer + (config_start_bit/8), esize); - memset(avctx->extradata+esize, 0, FF_INPUT_BUFFER_PADDING_SIZE); - } - skip_bits_long(gb, bits_consumed); - - return bits_consumed; -} - -static int read_stream_mux_config(struct LATMContext *latmctx, - GetBitContext *gb) -{ - int ret, audio_mux_version = get_bits(gb, 1); - - latmctx->audio_mux_version_A = 0; - if (audio_mux_version) - latmctx->audio_mux_version_A = get_bits(gb, 1); - - if (!latmctx->audio_mux_version_A) { - - if (audio_mux_version) - latm_get_value(gb); // taraFullness - - skip_bits(gb, 1); // allStreamSameTimeFraming - skip_bits(gb, 6); // numSubFrames - // numPrograms - if (get_bits(gb, 4)) { // numPrograms - av_log_missing_feature(latmctx->aac_ctx.avctx, - "multiple programs are not supported\n", 1); - return AVERROR_PATCHWELCOME; - } - - // for each program (which there is only on in DVB) - - // for each layer (which there is only on in DVB) - if (get_bits(gb, 3)) { // numLayer - av_log_missing_feature(latmctx->aac_ctx.avctx, - "multiple layers are not supported\n", 1); - return AVERROR_PATCHWELCOME; - } - - // for all but first stream: use_same_config = get_bits(gb, 1); - if (!audio_mux_version) { - if ((ret = latm_decode_audio_specific_config(latmctx, gb, 0)) < 0) - return ret; - } else { - int ascLen = latm_get_value(gb); - if ((ret = latm_decode_audio_specific_config(latmctx, gb, ascLen)) < 0) - return ret; - ascLen -= ret; - skip_bits_long(gb, ascLen); - } - - latmctx->frame_length_type = get_bits(gb, 3); - switch (latmctx->frame_length_type) { - case 0: - skip_bits(gb, 8); // latmBufferFullness - break; - case 1: - latmctx->frame_length = get_bits(gb, 9); - break; - case 3: - case 4: - case 5: - skip_bits(gb, 6); // CELP frame length table index - break; - case 6: - case 7: - skip_bits(gb, 1); // HVXC frame length table index - break; - } - - if (get_bits(gb, 1)) { // other data - if (audio_mux_version) { - latm_get_value(gb); // other_data_bits - } else { - int esc; - do { - esc = get_bits(gb, 1); - skip_bits(gb, 8); - } while (esc); - } - } - - if (get_bits(gb, 1)) // crc present - skip_bits(gb, 8); // config_crc - } - - return 0; -} - -static int read_payload_length_info(struct LATMContext *ctx, GetBitContext *gb) -{ - uint8_t tmp; - - if (ctx->frame_length_type == 0) { - int mux_slot_length = 0; - do { - tmp = get_bits(gb, 8); - mux_slot_length += tmp; - } while (tmp == 255); - return mux_slot_length; - } else if (ctx->frame_length_type == 1) { - return ctx->frame_length; - } else if (ctx->frame_length_type == 3 || - ctx->frame_length_type == 5 || - ctx->frame_length_type == 7) { - skip_bits(gb, 2); // mux_slot_length_coded - } - return 0; -} - -static int read_audio_mux_element(struct LATMContext *latmctx, - GetBitContext *gb) -{ - int err; - uint8_t use_same_mux = get_bits(gb, 1); - if (!use_same_mux) { - if ((err = read_stream_mux_config(latmctx, gb)) < 0) - return err; - } else if (!latmctx->aac_ctx.avctx->extradata) { - av_log(latmctx->aac_ctx.avctx, AV_LOG_DEBUG, - "no decoder config found\n"); - return AVERROR(EAGAIN); - } - if (latmctx->audio_mux_version_A == 0) { - int mux_slot_length_bytes = read_payload_length_info(latmctx, gb); - if (mux_slot_length_bytes * 8 > get_bits_left(gb)) { - av_log(latmctx->aac_ctx.avctx, AV_LOG_ERROR, "incomplete frame\n"); - return AVERROR_INVALIDDATA; - } else if (mux_slot_length_bytes * 8 + 256 < get_bits_left(gb)) { - av_log(latmctx->aac_ctx.avctx, AV_LOG_ERROR, - "frame length mismatch %d << %d\n", - mux_slot_length_bytes * 8, get_bits_left(gb)); - return AVERROR_INVALIDDATA; - } - } - return 0; -} - - -static int latm_decode_frame(AVCodecContext *avctx, void *out, - int *got_frame_ptr, AVPacket *avpkt) -{ - struct LATMContext *latmctx = avctx->priv_data; - int muxlength, err; - GetBitContext gb; - - init_get_bits(&gb, avpkt->data, avpkt->size * 8); - - // check for LOAS sync word - if (get_bits(&gb, 11) != LOAS_SYNC_WORD) - return AVERROR_INVALIDDATA; - - muxlength = get_bits(&gb, 13) + 3; - // not enough data, the parser should have sorted this - if (muxlength > avpkt->size) - return AVERROR_INVALIDDATA; - - if ((err = read_audio_mux_element(latmctx, &gb)) < 0) - return err; - - if (!latmctx->initialized) { - if (!avctx->extradata) { - *got_frame_ptr = 0; - return avpkt->size; - } else { - if ((err = decode_audio_specific_config( - &latmctx->aac_ctx, avctx, &latmctx->aac_ctx.m4ac, - avctx->extradata, avctx->extradata_size*8, 1)) < 0) - return err; - latmctx->initialized = 1; - } - } - - if (show_bits(&gb, 12) == 0xfff) { - av_log(latmctx->aac_ctx.avctx, AV_LOG_ERROR, - "ADTS header detected, probably as result of configuration " - "misparsing\n"); - return AVERROR_INVALIDDATA; - } - - if ((err = aac_decode_frame_int(avctx, out, got_frame_ptr, &gb)) < 0) - return err; - - return muxlength; -} - -av_cold static int latm_decode_init(AVCodecContext *avctx) -{ - struct LATMContext *latmctx = avctx->priv_data; - int ret = aac_decode_init(avctx); - - if (avctx->extradata_size > 0) - latmctx->initialized = !ret; - - return ret; -} - - -AVCodec ff_aac_decoder = { - .name = "aac", - .type = AVMEDIA_TYPE_AUDIO, - .id = CODEC_ID_AAC, - .priv_data_size = sizeof(AACContext), - .init = aac_decode_init, - .close = aac_decode_close, - .decode = aac_decode_frame, - .long_name = NULL_IF_CONFIG_SMALL("Advanced Audio Coding"), - .sample_fmts = (const enum AVSampleFormat[]) { - AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE - }, - .capabilities = CODEC_CAP_CHANNEL_CONF | CODEC_CAP_DR1, - .channel_layouts = aac_channel_layout, -}; - -/* - Note: This decoder filter is intended to decode LATM streams transferred - in MPEG transport streams which only contain one program. - To do a more complex LATM demuxing a separate LATM demuxer should be used. -*/ -AVCodec ff_aac_latm_decoder = { - .name = "aac_latm", - .type = AVMEDIA_TYPE_AUDIO, - .id = CODEC_ID_AAC_LATM, - .priv_data_size = sizeof(struct LATMContext), - .init = latm_decode_init, - .close = aac_decode_close, - .decode = latm_decode_frame, - .long_name = NULL_IF_CONFIG_SMALL("AAC LATM (Advanced Audio Codec LATM syntax)"), - .sample_fmts = (const enum AVSampleFormat[]) { - AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE - }, - .capabilities = CODEC_CAP_CHANNEL_CONF | CODEC_CAP_DR1, - .channel_layouts = aac_channel_layout, - .flush = flush, -}; +/*
+ * AAC decoder
+ * Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org )
+ * Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com )
+ *
+ * AAC LATM decoder
+ * Copyright (c) 2008-2010 Paul Kendall <paul@kcbbs.gen.nz>
+ * Copyright (c) 2010 Janne Grunau <janne-ffmpeg@jannau.net>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * AAC decoder
+ * @author Oded Shimon ( ods15 ods15 dyndns org )
+ * @author Maxim Gavrilov ( maxim.gavrilov gmail com )
+ */
+
+/*
+ * supported tools
+ *
+ * Support? Name
+ * N (code in SoC repo) gain control
+ * Y block switching
+ * Y window shapes - standard
+ * N window shapes - Low Delay
+ * Y filterbank - standard
+ * N (code in SoC repo) filterbank - Scalable Sample Rate
+ * Y Temporal Noise Shaping
+ * Y Long Term Prediction
+ * Y intensity stereo
+ * Y channel coupling
+ * Y frequency domain prediction
+ * Y Perceptual Noise Substitution
+ * Y Mid/Side stereo
+ * N Scalable Inverse AAC Quantization
+ * N Frequency Selective Switch
+ * N upsampling filter
+ * Y quantization & coding - AAC
+ * N quantization & coding - TwinVQ
+ * N quantization & coding - BSAC
+ * N AAC Error Resilience tools
+ * N Error Resilience payload syntax
+ * N Error Protection tool
+ * N CELP
+ * N Silence Compression
+ * N HVXC
+ * N HVXC 4kbits/s VR
+ * N Structured Audio tools
+ * N Structured Audio Sample Bank Format
+ * N MIDI
+ * N Harmonic and Individual Lines plus Noise
+ * N Text-To-Speech Interface
+ * Y Spectral Band Replication
+ * Y (not in this code) Layer-1
+ * Y (not in this code) Layer-2
+ * Y (not in this code) Layer-3
+ * N SinuSoidal Coding (Transient, Sinusoid, Noise)
+ * Y Parametric Stereo
+ * N Direct Stream Transfer
+ *
+ * Note: - HE AAC v1 comprises LC AAC with Spectral Band Replication.
+ * - HE AAC v2 comprises LC AAC with Spectral Band Replication and
+ Parametric Stereo.
+ */
+
+
+#include "avcodec.h"
+#include "internal.h"
+#include "get_bits.h"
+#include "put_bits.h"
+#include "dsputil.h"
+#include "fft.h"
+#include "fmtconvert.h"
+#include "lpc.h"
+#include "kbdwin.h"
+#include "sinewin.h"
+
+#include "aac.h"
+#include "aactab.h"
+#include "aacdectab.h"
+#include "cbrt_tablegen.h"
+#include "sbr.h"
+#include "aacsbr.h"
+#include "mpeg4audio.h"
+#include "aacadtsdec.h"
+#include "libavutil/intfloat.h"
+
+#include <assert.h>
+#include <errno.h>
+#include <math.h>
+#include <string.h>
+
+#if ARCH_ARM
+# include "arm/aac.h"
+#endif
+
+static VLC vlc_scalefactors;
+static VLC vlc_spectral[11];
+
+static const char overread_err[] = "Input buffer exhausted before END element found\n";
+
+static int count_channels(uint8_t (*layout)[3], int tags)
+{
+ int i, sum = 0;
+ for (i = 0; i < tags; i++) {
+ int syn_ele = layout[i][0];
+ int pos = layout[i][2];
+ sum += (1 + (syn_ele == TYPE_CPE)) *
+ (pos != AAC_CHANNEL_OFF && pos != AAC_CHANNEL_CC);
+ }
+ return sum;
+}
+
+/**
+ * Check for the channel element in the current channel position configuration.
+ * If it exists, make sure the appropriate element is allocated and map the
+ * channel order to match the internal FFmpeg channel layout.
+ *
+ * @param che_pos current channel position configuration
+ * @param type channel element type
+ * @param id channel element id
+ * @param channels count of the number of channels in the configuration
+ *
+ * @return Returns error status. 0 - OK, !0 - error
+ */
+static av_cold int che_configure(AACContext *ac,
+ enum ChannelPosition che_pos,
+ int type, int id, int *channels)
+{
+ if (che_pos) {
+ if (!ac->che[type][id]) {
+ if (!(ac->che[type][id] = av_mallocz(sizeof(ChannelElement))))
+ return AVERROR(ENOMEM);
+ ff_aac_sbr_ctx_init(ac, &ac->che[type][id]->sbr);
+ }
+ if (type != TYPE_CCE) {
+ ac->output_data[(*channels)++] = ac->che[type][id]->ch[0].ret;
+ if (type == TYPE_CPE ||
+ (type == TYPE_SCE && ac->m4ac.ps == 1)) {
+ ac->output_data[(*channels)++] = ac->che[type][id]->ch[1].ret;
+ }
+ }
+ } else {
+ if (ac->che[type][id])
+ ff_aac_sbr_ctx_close(&ac->che[type][id]->sbr);
+ av_freep(&ac->che[type][id]);
+ }
+ return 0;
+}
+
+struct elem_to_channel {
+ uint64_t av_position;
+ uint8_t syn_ele;
+ uint8_t elem_id;
+ uint8_t aac_position;
+};
+
+static int assign_pair(struct elem_to_channel e2c_vec[MAX_ELEM_ID],
+ uint8_t (*layout_map)[3], int offset, int tags, uint64_t left,
+ uint64_t right, int pos)
+{
+ if (layout_map[offset][0] == TYPE_CPE) {
+ e2c_vec[offset] = (struct elem_to_channel) {
+ .av_position = left | right, .syn_ele = TYPE_CPE,
+ .elem_id = layout_map[offset ][1], .aac_position = pos };
+ return 1;
+ } else {
+ e2c_vec[offset] = (struct elem_to_channel) {
+ .av_position = left, .syn_ele = TYPE_SCE,
+ .elem_id = layout_map[offset ][1], .aac_position = pos };
+ e2c_vec[offset + 1] = (struct elem_to_channel) {
+ .av_position = right, .syn_ele = TYPE_SCE,
+ .elem_id = layout_map[offset + 1][1], .aac_position = pos };
+ return 2;
+ }
+}
+
+static int count_paired_channels(uint8_t (*layout_map)[3], int tags, int pos, int *current) {
+ int num_pos_channels = 0;
+ int first_cpe = 0;
+ int sce_parity = 0;
+ int i;
+ for (i = *current; i < tags; i++) {
+ if (layout_map[i][2] != pos)
+ break;
+ if (layout_map[i][0] == TYPE_CPE) {
+ if (sce_parity) {
+ if (pos == AAC_CHANNEL_FRONT || !first_cpe) {
+ sce_parity = 0;
+ } else {
+ return -1;
+ }
+ }
+ num_pos_channels += 2;
+ first_cpe = 1;
+ } else {
+ num_pos_channels++;
+ sce_parity ^= 1;
+ }
+ }
+ if (sce_parity &&
+ ((pos == AAC_CHANNEL_FRONT && first_cpe) || pos == AAC_CHANNEL_SIDE))
+ return -1;
+ *current = i;
+ return num_pos_channels;
+}
+
+static uint64_t sniff_channel_order(uint8_t (*layout_map)[3], int tags)
+{
+ int i, n, total_non_cc_elements;
+ struct elem_to_channel e2c_vec[MAX_ELEM_ID] = {{ 0 }};
+ int num_front_channels, num_side_channels, num_back_channels;
+ uint64_t layout;
+
+ i = 0;
+ num_front_channels =
+ count_paired_channels(layout_map, tags, AAC_CHANNEL_FRONT, &i);
+ if (num_front_channels < 0)
+ return 0;
+ num_side_channels =
+ count_paired_channels(layout_map, tags, AAC_CHANNEL_SIDE, &i);
+ if (num_side_channels < 0)
+ return 0;
+ num_back_channels =
+ count_paired_channels(layout_map, tags, AAC_CHANNEL_BACK, &i);
+ if (num_back_channels < 0)
+ return 0;
+
+ i = 0;
+ if (num_front_channels & 1) {
+ e2c_vec[i] = (struct elem_to_channel) {
+ .av_position = AV_CH_FRONT_CENTER, .syn_ele = TYPE_SCE,
+ .elem_id = layout_map[i][1], .aac_position = AAC_CHANNEL_FRONT };
+ i++;
+ num_front_channels--;
+ }
+ if (num_front_channels >= 4) {
+ i += assign_pair(e2c_vec, layout_map, i, tags,
+ AV_CH_FRONT_LEFT_OF_CENTER,
+ AV_CH_FRONT_RIGHT_OF_CENTER,
+ AAC_CHANNEL_FRONT);
+ num_front_channels -= 2;
+ }
+ if (num_front_channels >= 2) {
+ i += assign_pair(e2c_vec, layout_map, i, tags,
+ AV_CH_FRONT_LEFT,
+ AV_CH_FRONT_RIGHT,
+ AAC_CHANNEL_FRONT);
+ num_front_channels -= 2;
+ }
+ while (num_front_channels >= 2) {
+ i += assign_pair(e2c_vec, layout_map, i, tags,
+ UINT64_MAX,
+ UINT64_MAX,
+ AAC_CHANNEL_FRONT);
+ num_front_channels -= 2;
+ }
+
+ if (num_side_channels >= 2) {
+ i += assign_pair(e2c_vec, layout_map, i, tags,
+ AV_CH_SIDE_LEFT,
+ AV_CH_SIDE_RIGHT,
+ AAC_CHANNEL_FRONT);
+ num_side_channels -= 2;
+ }
+ while (num_side_channels >= 2) {
+ i += assign_pair(e2c_vec, layout_map, i, tags,
+ UINT64_MAX,
+ UINT64_MAX,
+ AAC_CHANNEL_SIDE);
+ num_side_channels -= 2;
+ }
+
+ while (num_back_channels >= 4) {
+ i += assign_pair(e2c_vec, layout_map, i, tags,
+ UINT64_MAX,
+ UINT64_MAX,
+ AAC_CHANNEL_BACK);
+ num_back_channels -= 2;
+ }
+ if (num_back_channels >= 2) {
+ i += assign_pair(e2c_vec, layout_map, i, tags,
+ AV_CH_BACK_LEFT,
+ AV_CH_BACK_RIGHT,
+ AAC_CHANNEL_BACK);
+ num_back_channels -= 2;
+ }
+ if (num_back_channels) {
+ e2c_vec[i] = (struct elem_to_channel) {
+ .av_position = AV_CH_BACK_CENTER, .syn_ele = TYPE_SCE,
+ .elem_id = layout_map[i][1], .aac_position = AAC_CHANNEL_BACK };
+ i++;
+ num_back_channels--;
+ }
+
+ if (i < tags && layout_map[i][2] == AAC_CHANNEL_LFE) {
+ e2c_vec[i] = (struct elem_to_channel) {
+ .av_position = AV_CH_LOW_FREQUENCY, .syn_ele = TYPE_LFE,
+ .elem_id = layout_map[i][1], .aac_position = AAC_CHANNEL_LFE };
+ i++;
+ }
+ while (i < tags && layout_map[i][2] == AAC_CHANNEL_LFE) {
+ e2c_vec[i] = (struct elem_to_channel) {
+ .av_position = UINT64_MAX, .syn_ele = TYPE_LFE,
+ .elem_id = layout_map[i][1], .aac_position = AAC_CHANNEL_LFE };
+ i++;
+ }
+
+ // Must choose a stable sort
+ total_non_cc_elements = n = i;
+ do {
+ int next_n = 0;
+ for (i = 1; i < n; i++) {
+ if (e2c_vec[i-1].av_position > e2c_vec[i].av_position) {
+ FFSWAP(struct elem_to_channel, e2c_vec[i-1], e2c_vec[i]);
+ next_n = i;
+ }
+ }
+ n = next_n;
+ } while (n > 0);
+
+ layout = 0;
+ for (i = 0; i < total_non_cc_elements; i++) {
+ layout_map[i][0] = e2c_vec[i].syn_ele;
+ layout_map[i][1] = e2c_vec[i].elem_id;
+ layout_map[i][2] = e2c_vec[i].aac_position;
+ if (e2c_vec[i].av_position != UINT64_MAX) {
+ layout |= e2c_vec[i].av_position;
+ }
+ }
+
+ return layout;
+}
+
+/**
+ * Configure output channel order based on the current program configuration element.
+ *
+ * @return Returns error status. 0 - OK, !0 - error
+ */
+static av_cold int output_configure(AACContext *ac,
+ uint8_t layout_map[MAX_ELEM_ID*4][3], int tags,
+ int channel_config, enum OCStatus oc_type)
+{
+ AVCodecContext *avctx = ac->avctx;
+ int i, channels = 0, ret;
+ uint64_t layout = 0;
+
+ if (ac->layout_map != layout_map) {
+ memcpy(ac->layout_map, layout_map, tags * sizeof(layout_map[0]));
+ ac->layout_map_tags = tags;
+ }
+
+ // Try to sniff a reasonable channel order, otherwise output the
+ // channels in the order the PCE declared them.
+ if (avctx->request_channel_layout != AV_CH_LAYOUT_NATIVE)
+ layout = sniff_channel_order(layout_map, tags);
+ for (i = 0; i < tags; i++) {
+ int type = layout_map[i][0];
+ int id = layout_map[i][1];
+ int position = layout_map[i][2];
+ // Allocate or free elements depending on if they are in the
+ // current program configuration.
+ ret = che_configure(ac, position, type, id, &channels);
+ if (ret < 0)
+ return ret;
+ }
+
+ memcpy(ac->tag_che_map, ac->che, 4 * MAX_ELEM_ID * sizeof(ac->che[0][0]));
+ if (layout) avctx->channel_layout = layout;
+ avctx->channels = channels;
+ ac->output_configured = oc_type;
+
+ return 0;
+}
+
+static void flush(AVCodecContext *avctx)
+{
+ AACContext *ac= avctx->priv_data;
+ int type, i, j;
+
+ for (type = 3; type >= 0; type--) {
+ for (i = 0; i < MAX_ELEM_ID; i++) {
+ ChannelElement *che = ac->che[type][i];
+ if (che) {
+ for (j = 0; j <= 1; j++) {
+ memset(che->ch[j].saved, 0, sizeof(che->ch[j].saved));
+ }
+ }
+ }
+ }
+}
+
+/**
+ * Set up channel positions based on a default channel configuration
+ * as specified in table 1.17.
+ *
+ * @return Returns error status. 0 - OK, !0 - error
+ */
+static av_cold int set_default_channel_config(AVCodecContext *avctx,
+ uint8_t (*layout_map)[3],
+ int *tags,
+ int channel_config)
+{
+ if (channel_config < 1 || channel_config > 7) {
+ av_log(avctx, AV_LOG_ERROR, "invalid default channel configuration (%d)\n",
+ channel_config);
+ return -1;
+ }
+ *tags = tags_per_config[channel_config];
+ memcpy(layout_map, aac_channel_layout_map[channel_config-1], *tags * sizeof(*layout_map));
+ return 0;
+}
+
+static ChannelElement *get_che(AACContext *ac, int type, int elem_id)
+{
+ // For PCE based channel configurations map the channels solely based on tags.
+ if (!ac->m4ac.chan_config) {
+ return ac->tag_che_map[type][elem_id];
+ }
+ // Allow single CPE stereo files to be signalled with mono configuration.
+ if (!ac->tags_mapped && type == TYPE_CPE && ac->m4ac.chan_config == 1) {
+ uint8_t layout_map[MAX_ELEM_ID*4][3];
+ int layout_map_tags;
+
+ if (set_default_channel_config(ac->avctx, layout_map, &layout_map_tags,
+ 2) < 0)
+ return NULL;
+ if (output_configure(ac, layout_map, layout_map_tags,
+ 2, OC_TRIAL_FRAME) < 0)
+ return NULL;
+
+ ac->m4ac.chan_config = 2;
+ }
+ // For indexed channel configurations map the channels solely based on position.
+ switch (ac->m4ac.chan_config) {
+ case 7:
+ if (ac->tags_mapped == 3 && type == TYPE_CPE) {
+ ac->tags_mapped++;
+ return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][2];
+ }
+ case 6:
+ /* Some streams incorrectly code 5.1 audio as SCE[0] CPE[0] CPE[1] SCE[1]
+ instead of SCE[0] CPE[0] CPE[1] LFE[0]. If we seem to have
+ encountered such a stream, transfer the LFE[0] element to the SCE[1]'s mapping */
+ if (ac->tags_mapped == tags_per_config[ac->m4ac.chan_config] - 1 && (type == TYPE_LFE || type == TYPE_SCE)) {
+ ac->tags_mapped++;
+ return ac->tag_che_map[type][elem_id] = ac->che[TYPE_LFE][0];
+ }
+ case 5:
+ if (ac->tags_mapped == 2 && type == TYPE_CPE) {
+ ac->tags_mapped++;
+ return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][1];
+ }
+ case 4:
+ if (ac->tags_mapped == 2 && ac->m4ac.chan_config == 4 && type == TYPE_SCE) {
+ ac->tags_mapped++;
+ return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][1];
+ }
+ case 3:
+ case 2:
+ if (ac->tags_mapped == (ac->m4ac.chan_config != 2) && type == TYPE_CPE) {
+ ac->tags_mapped++;
+ return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][0];
+ } else if (ac->m4ac.chan_config == 2) {
+ return NULL;
+ }
+ case 1:
+ if (!ac->tags_mapped && type == TYPE_SCE) {
+ ac->tags_mapped++;
+ return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][0];
+ }
+ default:
+ return NULL;
+ }
+}
+
+/**
+ * Decode an array of 4 bit element IDs, optionally interleaved with a stereo/mono switching bit.
+ *
+ * @param type speaker type/position for these channels
+ */
+static void decode_channel_map(uint8_t layout_map[][3],
+ enum ChannelPosition type,
+ GetBitContext *gb, int n)
+{
+ while (n--) {
+ enum RawDataBlockType syn_ele;
+ switch (type) {
+ case AAC_CHANNEL_FRONT:
+ case AAC_CHANNEL_BACK:
+ case AAC_CHANNEL_SIDE:
+ syn_ele = get_bits1(gb);
+ break;
+ case AAC_CHANNEL_CC:
+ skip_bits1(gb);
+ syn_ele = TYPE_CCE;
+ break;
+ case AAC_CHANNEL_LFE:
+ syn_ele = TYPE_LFE;
+ break;
+ }
+ layout_map[0][0] = syn_ele;
+ layout_map[0][1] = get_bits(gb, 4);
+ layout_map[0][2] = type;
+ layout_map++;
+ }
+}
+
+/**
+ * Decode program configuration element; reference: table 4.2.
+ *
+ * @return Returns error status. 0 - OK, !0 - error
+ */
+static int decode_pce(AVCodecContext *avctx, MPEG4AudioConfig *m4ac,
+ uint8_t (*layout_map)[3],
+ GetBitContext *gb)
+{
+ int num_front, num_side, num_back, num_lfe, num_assoc_data, num_cc, sampling_index;
+ int comment_len;
+ int tags;
+
+ skip_bits(gb, 2); // object_type
+
+ sampling_index = get_bits(gb, 4);
+ if (m4ac->sampling_index != sampling_index)
+ av_log(avctx, AV_LOG_WARNING, "Sample rate index in program config element does not match the sample rate index configured by the container.\n");
+
+ num_front = get_bits(gb, 4);
+ num_side = get_bits(gb, 4);
+ num_back = get_bits(gb, 4);
+ num_lfe = get_bits(gb, 2);
+ num_assoc_data = get_bits(gb, 3);
+ num_cc = get_bits(gb, 4);
+
+ if (get_bits1(gb))
+ skip_bits(gb, 4); // mono_mixdown_tag
+ if (get_bits1(gb))
+ skip_bits(gb, 4); // stereo_mixdown_tag
+
+ if (get_bits1(gb))
+ skip_bits(gb, 3); // mixdown_coeff_index and pseudo_surround
+
+ if (get_bits_left(gb) < 4 * (num_front + num_side + num_back + num_lfe + num_assoc_data + num_cc)) {
+ av_log(avctx, AV_LOG_ERROR, overread_err);
+ return -1;
+ }
+ decode_channel_map(layout_map , AAC_CHANNEL_FRONT, gb, num_front);
+ tags = num_front;
+ decode_channel_map(layout_map + tags, AAC_CHANNEL_SIDE, gb, num_side);
+ tags += num_side;
+ decode_channel_map(layout_map + tags, AAC_CHANNEL_BACK, gb, num_back);
+ tags += num_back;
+ decode_channel_map(layout_map + tags, AAC_CHANNEL_LFE, gb, num_lfe);
+ tags += num_lfe;
+
+ skip_bits_long(gb, 4 * num_assoc_data);
+
+ decode_channel_map(layout_map + tags, AAC_CHANNEL_CC, gb, num_cc);
+ tags += num_cc;
+
+ align_get_bits(gb);
+
+ /* comment field, first byte is length */
+ comment_len = get_bits(gb, 8) * 8;
+ if (get_bits_left(gb) < comment_len) {
+ av_log(avctx, AV_LOG_ERROR, overread_err);
+ return -1;
+ }
+ skip_bits_long(gb, comment_len);
+ return tags;
+}
+
+/**
+ * Decode GA "General Audio" specific configuration; reference: table 4.1.
+ *
+ * @param ac pointer to AACContext, may be null
+ * @param avctx pointer to AVCCodecContext, used for logging
+ *
+ * @return Returns error status. 0 - OK, !0 - error
+ */
+static int decode_ga_specific_config(AACContext *ac, AVCodecContext *avctx,
+ GetBitContext *gb,
+ MPEG4AudioConfig *m4ac,
+ int channel_config)
+{
+ int extension_flag, ret;
+ uint8_t layout_map[MAX_ELEM_ID*4][3];
+ int tags = 0;
+
+ if (get_bits1(gb)) { // frameLengthFlag
+ av_log_missing_feature(avctx, "960/120 MDCT window is", 1);
+ return -1;
+ }
+
+ if (get_bits1(gb)) // dependsOnCoreCoder
+ skip_bits(gb, 14); // coreCoderDelay
+ extension_flag = get_bits1(gb);
+
+ if (m4ac->object_type == AOT_AAC_SCALABLE ||
+ m4ac->object_type == AOT_ER_AAC_SCALABLE)
+ skip_bits(gb, 3); // layerNr
+
+ if (channel_config == 0) {
+ skip_bits(gb, 4); // element_instance_tag
+ tags = decode_pce(avctx, m4ac, layout_map, gb);
+ if (tags < 0)
+ return tags;
+ } else {
+ if ((ret = set_default_channel_config(avctx, layout_map, &tags, channel_config)))
+ return ret;
+ }
+
+ if (count_channels(layout_map, tags) > 1) {
+ m4ac->ps = 0;
+ } else if (m4ac->sbr == 1 && m4ac->ps == -1)
+ m4ac->ps = 1;
+
+ if (ac && (ret = output_configure(ac, layout_map, tags,
+ channel_config, OC_GLOBAL_HDR)))
+ return ret;
+
+ if (extension_flag) {
+ switch (m4ac->object_type) {
+ case AOT_ER_BSAC:
+ skip_bits(gb, 5); // numOfSubFrame
+ skip_bits(gb, 11); // layer_length
+ break;
+ case AOT_ER_AAC_LC:
+ case AOT_ER_AAC_LTP:
+ case AOT_ER_AAC_SCALABLE:
+ case AOT_ER_AAC_LD:
+ skip_bits(gb, 3); /* aacSectionDataResilienceFlag
+ * aacScalefactorDataResilienceFlag
+ * aacSpectralDataResilienceFlag
+ */
+ break;
+ }
+ skip_bits1(gb); // extensionFlag3 (TBD in version 3)
+ }
+ return 0;
+}
+
+/**
+ * Decode audio specific configuration; reference: table 1.13.
+ *
+ * @param ac pointer to AACContext, may be null
+ * @param avctx pointer to AVCCodecContext, used for logging
+ * @param m4ac pointer to MPEG4AudioConfig, used for parsing
+ * @param data pointer to buffer holding an audio specific config
+ * @param bit_size size of audio specific config or data in bits
+ * @param sync_extension look for an appended sync extension
+ *
+ * @return Returns error status or number of consumed bits. <0 - error
+ */
+static int decode_audio_specific_config(AACContext *ac,
+ AVCodecContext *avctx,
+ MPEG4AudioConfig *m4ac,
+ const uint8_t *data, int bit_size,
+ int sync_extension)
+{
+ GetBitContext gb;
+ int i;
+
+ av_dlog(avctx, "extradata size %d\n", avctx->extradata_size);
+ for (i = 0; i < avctx->extradata_size; i++)
+ av_dlog(avctx, "%02x ", avctx->extradata[i]);
+ av_dlog(avctx, "\n");
+
+ init_get_bits(&gb, data, bit_size);
+
+ if ((i = avpriv_mpeg4audio_get_config(m4ac, data, bit_size, sync_extension)) < 0)
+ return -1;
+ if (m4ac->sampling_index > 12) {
+ av_log(avctx, AV_LOG_ERROR, "invalid sampling rate index %d\n", m4ac->sampling_index);
+ return -1;
+ }
+
+ skip_bits_long(&gb, i);
+
+ switch (m4ac->object_type) {
+ case AOT_AAC_MAIN:
+ case AOT_AAC_LC:
+ case AOT_AAC_LTP:
+ if (decode_ga_specific_config(ac, avctx, &gb, m4ac, m4ac->chan_config))
+ return -1;
+ break;
+ default:
+ av_log(avctx, AV_LOG_ERROR, "Audio object type %s%d is not supported.\n",
+ m4ac->sbr == 1? "SBR+" : "", m4ac->object_type);
+ return -1;
+ }
+
+ av_dlog(avctx, "AOT %d chan config %d sampling index %d (%d) SBR %d PS %d\n",
+ m4ac->object_type, m4ac->chan_config, m4ac->sampling_index,
+ m4ac->sample_rate, m4ac->sbr, m4ac->ps);
+
+ return get_bits_count(&gb);
+}
+
+/**
+ * linear congruential pseudorandom number generator
+ *
+ * @param previous_val pointer to the current state of the generator
+ *
+ * @return Returns a 32-bit pseudorandom integer
+ */
+static av_always_inline int lcg_random(int previous_val)
+{
+ return previous_val * 1664525 + 1013904223;
+}
+
+static av_always_inline void reset_predict_state(PredictorState *ps)
+{
+ ps->r0 = 0.0f;
+ ps->r1 = 0.0f;
+ ps->cor0 = 0.0f;
+ ps->cor1 = 0.0f;
+ ps->var0 = 1.0f;
+ ps->var1 = 1.0f;
+}
+
+static void reset_all_predictors(PredictorState *ps)
+{
+ int i;
+ for (i = 0; i < MAX_PREDICTORS; i++)
+ reset_predict_state(&ps[i]);
+}
+
+static int sample_rate_idx (int rate)
+{
+ if (92017 <= rate) return 0;
+ else if (75132 <= rate) return 1;
+ else if (55426 <= rate) return 2;
+ else if (46009 <= rate) return 3;
+ else if (37566 <= rate) return 4;
+ else if (27713 <= rate) return 5;
+ else if (23004 <= rate) return 6;
+ else if (18783 <= rate) return 7;
+ else if (13856 <= rate) return 8;
+ else if (11502 <= rate) return 9;
+ else if (9391 <= rate) return 10;
+ else return 11;
+}
+
+static void reset_predictor_group(PredictorState *ps, int group_num)
+{
+ int i;
+ for (i = group_num - 1; i < MAX_PREDICTORS; i += 30)
+ reset_predict_state(&ps[i]);
+}
+
+#define AAC_INIT_VLC_STATIC(num, size) \
+ INIT_VLC_STATIC(&vlc_spectral[num], 8, ff_aac_spectral_sizes[num], \
+ ff_aac_spectral_bits[num], sizeof( ff_aac_spectral_bits[num][0]), sizeof( ff_aac_spectral_bits[num][0]), \
+ ff_aac_spectral_codes[num], sizeof(ff_aac_spectral_codes[num][0]), sizeof(ff_aac_spectral_codes[num][0]), \
+ size);
+
+static av_cold int aac_decode_init(AVCodecContext *avctx)
+{
+ AACContext *ac = avctx->priv_data;
+ float output_scale_factor;
+
+ ac->avctx = avctx;
+ ac->m4ac.sample_rate = avctx->sample_rate;
+
+ if (avctx->extradata_size > 0) {
+ if (decode_audio_specific_config(ac, ac->avctx, &ac->m4ac,
+ avctx->extradata,
+ avctx->extradata_size*8, 1) < 0)
+ return -1;
+ } else {
+ int sr, i;
+ uint8_t layout_map[MAX_ELEM_ID*4][3];
+ int layout_map_tags;
+
+ sr = sample_rate_idx(avctx->sample_rate);
+ ac->m4ac.sampling_index = sr;
+ ac->m4ac.channels = avctx->channels;
+ ac->m4ac.sbr = -1;
+ ac->m4ac.ps = -1;
+
+ for (i = 0; i < FF_ARRAY_ELEMS(ff_mpeg4audio_channels); i++)
+ if (ff_mpeg4audio_channels[i] == avctx->channels)
+ break;
+ if (i == FF_ARRAY_ELEMS(ff_mpeg4audio_channels)) {
+ i = 0;
+ }
+ ac->m4ac.chan_config = i;
+
+ if (ac->m4ac.chan_config) {
+ int ret = set_default_channel_config(avctx, layout_map,
+ &layout_map_tags, ac->m4ac.chan_config);
+ if (!ret)
+ output_configure(ac, layout_map, layout_map_tags,
+ ac->m4ac.chan_config, OC_GLOBAL_HDR);
+ else if (avctx->err_recognition & AV_EF_EXPLODE)
+ return AVERROR_INVALIDDATA;
+ }
+ }
+
+ if (avctx->request_sample_fmt == AV_SAMPLE_FMT_FLT) {
+ avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
+ output_scale_factor = 1.0; // / 32768.0;
+ } else {
+ avctx->sample_fmt = AV_SAMPLE_FMT_S16;
+ output_scale_factor = 1.0;
+ }
+
+ AAC_INIT_VLC_STATIC( 0, 304);
+ AAC_INIT_VLC_STATIC( 1, 270);
+ AAC_INIT_VLC_STATIC( 2, 550);
+ AAC_INIT_VLC_STATIC( 3, 300);
+ AAC_INIT_VLC_STATIC( 4, 328);
+ AAC_INIT_VLC_STATIC( 5, 294);
+ AAC_INIT_VLC_STATIC( 6, 306);
+ AAC_INIT_VLC_STATIC( 7, 268);
+ AAC_INIT_VLC_STATIC( 8, 510);
+ AAC_INIT_VLC_STATIC( 9, 366);
+ AAC_INIT_VLC_STATIC(10, 462);
+
+ ff_aac_sbr_init();
+
+ ff_dsputil_init(&ac->dsp, avctx);
+ ff_fmt_convert_init(&ac->fmt_conv, avctx);
+
+ ac->random_state = 0x1f2e3d4c;
+
+ ff_aac_tableinit();
+
+ INIT_VLC_STATIC(&vlc_scalefactors,7,FF_ARRAY_ELEMS(ff_aac_scalefactor_code),
+ ff_aac_scalefactor_bits, sizeof(ff_aac_scalefactor_bits[0]), sizeof(ff_aac_scalefactor_bits[0]),
+ ff_aac_scalefactor_code, sizeof(ff_aac_scalefactor_code[0]), sizeof(ff_aac_scalefactor_code[0]),
+ 352);
+
+ ff_mdct_init(&ac->mdct, 11, 1, output_scale_factor/1024.0);
+ ff_mdct_init(&ac->mdct_small, 8, 1, output_scale_factor/128.0);
+ ff_mdct_init(&ac->mdct_ltp, 11, 0, -2.0/output_scale_factor);
+ // window initialization
+ ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024);
+ ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128);
+ ff_init_ff_sine_windows(10);
+ ff_init_ff_sine_windows( 7);
+
+ cbrt_tableinit();
+
+ avcodec_get_frame_defaults(&ac->frame);
+ avctx->coded_frame = &ac->frame;
+
+ return 0;
+}
+
+/**
+ * Skip data_stream_element; reference: table 4.10.
+ */
+static int skip_data_stream_element(AACContext *ac, GetBitContext *gb)
+{
+ int byte_align = get_bits1(gb);
+ int count = get_bits(gb, 8);
+ if (count == 255)
+ count += get_bits(gb, 8);
+ if (byte_align)
+ align_get_bits(gb);
+
+ if (get_bits_left(gb) < 8 * count) {
+ av_log(ac->avctx, AV_LOG_ERROR, overread_err);
+ return -1;
+ }
+ skip_bits_long(gb, 8 * count);
+ return 0;
+}
+
+static int decode_prediction(AACContext *ac, IndividualChannelStream *ics,
+ GetBitContext *gb)
+{
+ int sfb;
+ if (get_bits1(gb)) {
+ ics->predictor_reset_group = get_bits(gb, 5);
+ if (ics->predictor_reset_group == 0 || ics->predictor_reset_group > 30) {
+ av_log(ac->avctx, AV_LOG_ERROR, "Invalid Predictor Reset Group.\n");
+ return -1;
+ }
+ }
+ for (sfb = 0; sfb < FFMIN(ics->max_sfb, ff_aac_pred_sfb_max[ac->m4ac.sampling_index]); sfb++) {
+ ics->prediction_used[sfb] = get_bits1(gb);
+ }
+ return 0;
+}
+
+/**
+ * Decode Long Term Prediction data; reference: table 4.xx.
+ */
+static void decode_ltp(AACContext *ac, LongTermPrediction *ltp,
+ GetBitContext *gb, uint8_t max_sfb)
+{
+ int sfb;
+
+ ltp->lag = get_bits(gb, 11);
+ ltp->coef = ltp_coef[get_bits(gb, 3)];
+ for (sfb = 0; sfb < FFMIN(max_sfb, MAX_LTP_LONG_SFB); sfb++)
+ ltp->used[sfb] = get_bits1(gb);
+}
+
+/**
+ * Decode Individual Channel Stream info; reference: table 4.6.
+ */
+static int decode_ics_info(AACContext *ac, IndividualChannelStream *ics,
+ GetBitContext *gb)
+{
+ if (get_bits1(gb)) {
+ av_log(ac->avctx, AV_LOG_ERROR, "Reserved bit set.\n");
+ return AVERROR_INVALIDDATA;
+ }
+ ics->window_sequence[1] = ics->window_sequence[0];
+ ics->window_sequence[0] = get_bits(gb, 2);
+ ics->use_kb_window[1] = ics->use_kb_window[0];
+ ics->use_kb_window[0] = get_bits1(gb);
+ ics->num_window_groups = 1;
+ ics->group_len[0] = 1;
+ if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
+ int i;
+ ics->max_sfb = get_bits(gb, 4);
+ for (i = 0; i < 7; i++) {
+ if (get_bits1(gb)) {
+ ics->group_len[ics->num_window_groups - 1]++;
+ } else {
+ ics->num_window_groups++;
+ ics->group_len[ics->num_window_groups - 1] = 1;
+ }
+ }
+ ics->num_windows = 8;
+ ics->swb_offset = ff_swb_offset_128[ac->m4ac.sampling_index];
+ ics->num_swb = ff_aac_num_swb_128[ac->m4ac.sampling_index];
+ ics->tns_max_bands = ff_tns_max_bands_128[ac->m4ac.sampling_index];
+ ics->predictor_present = 0;
+ } else {
+ ics->max_sfb = get_bits(gb, 6);
+ ics->num_windows = 1;
+ ics->swb_offset = ff_swb_offset_1024[ac->m4ac.sampling_index];
+ ics->num_swb = ff_aac_num_swb_1024[ac->m4ac.sampling_index];
+ ics->tns_max_bands = ff_tns_max_bands_1024[ac->m4ac.sampling_index];
+ ics->predictor_present = get_bits1(gb);
+ ics->predictor_reset_group = 0;
+ if (ics->predictor_present) {
+ if (ac->m4ac.object_type == AOT_AAC_MAIN) {
+ if (decode_prediction(ac, ics, gb)) {
+ return AVERROR_INVALIDDATA;
+ }
+ } else if (ac->m4ac.object_type == AOT_AAC_LC) {
+ av_log(ac->avctx, AV_LOG_ERROR, "Prediction is not allowed in AAC-LC.\n");
+ return AVERROR_INVALIDDATA;
+ } else {
+ if ((ics->ltp.present = get_bits(gb, 1)))
+ decode_ltp(ac, &ics->ltp, gb, ics->max_sfb);
+ }
+ }
+ }
+
+ if (ics->max_sfb > ics->num_swb) {
+ av_log(ac->avctx, AV_LOG_ERROR,
+ "Number of scalefactor bands in group (%d) exceeds limit (%d).\n",
+ ics->max_sfb, ics->num_swb);
+ return AVERROR_INVALIDDATA;
+ }
+
+ return 0;
+}
+
+/**
+ * Decode band types (section_data payload); reference: table 4.46.
+ *
+ * @param band_type array of the used band type
+ * @param band_type_run_end array of the last scalefactor band of a band type run
+ *
+ * @return Returns error status. 0 - OK, !0 - error
+ */
+static int decode_band_types(AACContext *ac, enum BandType band_type[120],
+ int band_type_run_end[120], GetBitContext *gb,
+ IndividualChannelStream *ics)
+{
+ int g, idx = 0;
+ const int bits = (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) ? 3 : 5;
+ for (g = 0; g < ics->num_window_groups; g++) {
+ int k = 0;
+ while (k < ics->max_sfb) {
+ uint8_t sect_end = k;
+ int sect_len_incr;
+ int sect_band_type = get_bits(gb, 4);
+ if (sect_band_type == 12) {
+ av_log(ac->avctx, AV_LOG_ERROR, "invalid band type\n");
+ return -1;
+ }
+ do {
+ sect_len_incr = get_bits(gb, bits);
+ sect_end += sect_len_incr;
+ if (get_bits_left(gb) < 0) {
+ av_log(ac->avctx, AV_LOG_ERROR, overread_err);
+ return -1;
+ }
+ if (sect_end > ics->max_sfb) {
+ av_log(ac->avctx, AV_LOG_ERROR,
+ "Number of bands (%d) exceeds limit (%d).\n",
+ sect_end, ics->max_sfb);
+ return -1;
+ }
+ } while (sect_len_incr == (1 << bits) - 1);
+ for (; k < sect_end; k++) {
+ band_type [idx] = sect_band_type;
+ band_type_run_end[idx++] = sect_end;
+ }
+ }
+ }
+ return 0;
+}
+
+/**
+ * Decode scalefactors; reference: table 4.47.
+ *
+ * @param global_gain first scalefactor value as scalefactors are differentially coded
+ * @param band_type array of the used band type
+ * @param band_type_run_end array of the last scalefactor band of a band type run
+ * @param sf array of scalefactors or intensity stereo positions
+ *
+ * @return Returns error status. 0 - OK, !0 - error
+ */
+static int decode_scalefactors(AACContext *ac, float sf[120], GetBitContext *gb,
+ unsigned int global_gain,
+ IndividualChannelStream *ics,
+ enum BandType band_type[120],
+ int band_type_run_end[120])
+{
+ int g, i, idx = 0;
+ int offset[3] = { global_gain, global_gain - 90, 0 };
+ int clipped_offset;
+ int noise_flag = 1;
+ for (g = 0; g < ics->num_window_groups; g++) {
+ for (i = 0; i < ics->max_sfb;) {
+ int run_end = band_type_run_end[idx];
+ if (band_type[idx] == ZERO_BT) {
+ for (; i < run_end; i++, idx++)
+ sf[idx] = 0.;
+ } else if ((band_type[idx] == INTENSITY_BT) || (band_type[idx] == INTENSITY_BT2)) {
+ for (; i < run_end; i++, idx++) {
+ offset[2] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60;
+ clipped_offset = av_clip(offset[2], -155, 100);
+ if (offset[2] != clipped_offset) {
+ av_log_ask_for_sample(ac->avctx, "Intensity stereo "
+ "position clipped (%d -> %d).\nIf you heard an "
+ "audible artifact, there may be a bug in the "
+ "decoder. ", offset[2], clipped_offset);
+ }
+ sf[idx] = ff_aac_pow2sf_tab[-clipped_offset + POW_SF2_ZERO];
+ }
+ } else if (band_type[idx] == NOISE_BT) {
+ for (; i < run_end; i++, idx++) {
+ if (noise_flag-- > 0)
+ offset[1] += get_bits(gb, 9) - 256;
+ else
+ offset[1] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60;
+ clipped_offset = av_clip(offset[1], -100, 155);
+ if (offset[1] != clipped_offset) {
+ av_log_ask_for_sample(ac->avctx, "Noise gain clipped "
+ "(%d -> %d).\nIf you heard an audible "
+ "artifact, there may be a bug in the decoder. ",
+ offset[1], clipped_offset);
+ }
+ sf[idx] = -ff_aac_pow2sf_tab[clipped_offset + POW_SF2_ZERO];
+ }
+ } else {
+ for (; i < run_end; i++, idx++) {
+ offset[0] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60;
+ if (offset[0] > 255U) {
+ av_log(ac->avctx, AV_LOG_ERROR,
+ "Scalefactor (%d) out of range.\n", offset[0]);
+ return -1;
+ }
+ sf[idx] = -ff_aac_pow2sf_tab[offset[0] - 100 + POW_SF2_ZERO];
+ }
+ }
+ }
+ }
+ return 0;
+}
+
+/**
+ * Decode pulse data; reference: table 4.7.
+ */
+static int decode_pulses(Pulse *pulse, GetBitContext *gb,
+ const uint16_t *swb_offset, int num_swb)
+{
+ int i, pulse_swb;
+ pulse->num_pulse = get_bits(gb, 2) + 1;
+ pulse_swb = get_bits(gb, 6);
+ if (pulse_swb >= num_swb)
+ return -1;
+ pulse->pos[0] = swb_offset[pulse_swb];
+ pulse->pos[0] += get_bits(gb, 5);
+ if (pulse->pos[0] > 1023)
+ return -1;
+ pulse->amp[0] = get_bits(gb, 4);
+ for (i = 1; i < pulse->num_pulse; i++) {
+ pulse->pos[i] = get_bits(gb, 5) + pulse->pos[i - 1];
+ if (pulse->pos[i] > 1023)
+ return -1;
+ pulse->amp[i] = get_bits(gb, 4);
+ }
+ return 0;
+}
+
+/**
+ * Decode Temporal Noise Shaping data; reference: table 4.48.
+ *
+ * @return Returns error status. 0 - OK, !0 - error
+ */
+static int decode_tns(AACContext *ac, TemporalNoiseShaping *tns,
+ GetBitContext *gb, const IndividualChannelStream *ics)
+{
+ int w, filt, i, coef_len, coef_res, coef_compress;
+ const int is8 = ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE;
+ const int tns_max_order = is8 ? 7 : ac->m4ac.object_type == AOT_AAC_MAIN ? 20 : 12;
+ for (w = 0; w < ics->num_windows; w++) {
+ if ((tns->n_filt[w] = get_bits(gb, 2 - is8))) {
+ coef_res = get_bits1(gb);
+
+ for (filt = 0; filt < tns->n_filt[w]; filt++) {
+ int tmp2_idx;
+ tns->length[w][filt] = get_bits(gb, 6 - 2 * is8);
+
+ if ((tns->order[w][filt] = get_bits(gb, 5 - 2 * is8)) > tns_max_order) {
+ av_log(ac->avctx, AV_LOG_ERROR, "TNS filter order %d is greater than maximum %d.\n",
+ tns->order[w][filt], tns_max_order);
+ tns->order[w][filt] = 0;
+ return -1;
+ }
+ if (tns->order[w][filt]) {
+ tns->direction[w][filt] = get_bits1(gb);
+ coef_compress = get_bits1(gb);
+ coef_len = coef_res + 3 - coef_compress;
+ tmp2_idx = 2 * coef_compress + coef_res;
+
+ for (i = 0; i < tns->order[w][filt]; i++)
+ tns->coef[w][filt][i] = tns_tmp2_map[tmp2_idx][get_bits(gb, coef_len)];
+ }
+ }
+ }
+ }
+ return 0;
+}
+
+/**
+ * Decode Mid/Side data; reference: table 4.54.
+ *
+ * @param ms_present Indicates mid/side stereo presence. [0] mask is all 0s;
+ * [1] mask is decoded from bitstream; [2] mask is all 1s;
+ * [3] reserved for scalable AAC
+ */
+static void decode_mid_side_stereo(ChannelElement *cpe, GetBitContext *gb,
+ int ms_present)
+{
+ int idx;
+ if (ms_present == 1) {
+ for (idx = 0; idx < cpe->ch[0].ics.num_window_groups * cpe->ch[0].ics.max_sfb; idx++)
+ cpe->ms_mask[idx] = get_bits1(gb);
+ } else if (ms_present == 2) {
+ memset(cpe->ms_mask, 1, cpe->ch[0].ics.num_window_groups * cpe->ch[0].ics.max_sfb * sizeof(cpe->ms_mask[0]));
+ }
+}
+
+#ifndef VMUL2
+static inline float *VMUL2(float *dst, const float *v, unsigned idx,
+ const float *scale)
+{
+ float s = *scale;
+ *dst++ = v[idx & 15] * s;
+ *dst++ = v[idx>>4 & 15] * s;
+ return dst;
+}
+#endif
+
+#ifndef VMUL4
+static inline float *VMUL4(float *dst, const float *v, unsigned idx,
+ const float *scale)
+{
+ float s = *scale;
+ *dst++ = v[idx & 3] * s;
+ *dst++ = v[idx>>2 & 3] * s;
+ *dst++ = v[idx>>4 & 3] * s;
+ *dst++ = v[idx>>6 & 3] * s;
+ return dst;
+}
+#endif
+
+#ifndef VMUL2S
+static inline float *VMUL2S(float *dst, const float *v, unsigned idx,
+ unsigned sign, const float *scale)
+{
+ union av_intfloat32 s0, s1;
+
+ s0.f = s1.f = *scale;
+ s0.i ^= sign >> 1 << 31;
+ s1.i ^= sign << 31;
+
+ *dst++ = v[idx & 15] * s0.f;
+ *dst++ = v[idx>>4 & 15] * s1.f;
+
+ return dst;
+}
+#endif
+
+#ifndef VMUL4S
+static inline float *VMUL4S(float *dst, const float *v, unsigned idx,
+ unsigned sign, const float *scale)
+{
+ unsigned nz = idx >> 12;
+ union av_intfloat32 s = { .f = *scale };
+ union av_intfloat32 t;
+
+ t.i = s.i ^ (sign & 1U<<31);
+ *dst++ = v[idx & 3] * t.f;
+
+ sign <<= nz & 1; nz >>= 1;
+ t.i = s.i ^ (sign & 1U<<31);
+ *dst++ = v[idx>>2 & 3] * t.f;
+
+ sign <<= nz & 1; nz >>= 1;
+ t.i = s.i ^ (sign & 1U<<31);
+ *dst++ = v[idx>>4 & 3] * t.f;
+
+ sign <<= nz & 1; nz >>= 1;
+ t.i = s.i ^ (sign & 1U<<31);
+ *dst++ = v[idx>>6 & 3] * t.f;
+
+ return dst;
+}
+#endif
+
+/**
+ * Decode spectral data; reference: table 4.50.
+ * Dequantize and scale spectral data; reference: 4.6.3.3.
+ *
+ * @param coef array of dequantized, scaled spectral data
+ * @param sf array of scalefactors or intensity stereo positions
+ * @param pulse_present set if pulses are present
+ * @param pulse pointer to pulse data struct
+ * @param band_type array of the used band type
+ *
+ * @return Returns error status. 0 - OK, !0 - error
+ */
+static int decode_spectrum_and_dequant(AACContext *ac, float coef[1024],
+ GetBitContext *gb, const float sf[120],
+ int pulse_present, const Pulse *pulse,
+ const IndividualChannelStream *ics,
+ enum BandType band_type[120])
+{
+ int i, k, g, idx = 0;
+ const int c = 1024 / ics->num_windows;
+ const uint16_t *offsets = ics->swb_offset;
+ float *coef_base = coef;
+
+ for (g = 0; g < ics->num_windows; g++)
+ memset(coef + g * 128 + offsets[ics->max_sfb], 0, sizeof(float) * (c - offsets[ics->max_sfb]));
+
+ for (g = 0; g < ics->num_window_groups; g++) {
+ unsigned g_len = ics->group_len[g];
+
+ for (i = 0; i < ics->max_sfb; i++, idx++) {
+ const unsigned cbt_m1 = band_type[idx] - 1;
+ float *cfo = coef + offsets[i];
+ int off_len = offsets[i + 1] - offsets[i];
+ int group;
+
+ if (cbt_m1 >= INTENSITY_BT2 - 1) {
+ for (group = 0; group < g_len; group++, cfo+=128) {
+ memset(cfo, 0, off_len * sizeof(float));
+ }
+ } else if (cbt_m1 == NOISE_BT - 1) {
+ for (group = 0; group < g_len; group++, cfo+=128) {
+ float scale;
+ float band_energy;
+
+ for (k = 0; k < off_len; k++) {
+ ac->random_state = lcg_random(ac->random_state);
+ cfo[k] = ac->random_state;
+ }
+
+ band_energy = ac->dsp.scalarproduct_float(cfo, cfo, off_len);
+ scale = sf[idx] / sqrtf(band_energy);
+ ac->dsp.vector_fmul_scalar(cfo, cfo, scale, off_len);
+ }
+ } else {
+ const float *vq = ff_aac_codebook_vector_vals[cbt_m1];
+ const uint16_t *cb_vector_idx = ff_aac_codebook_vector_idx[cbt_m1];
+ VLC_TYPE (*vlc_tab)[2] = vlc_spectral[cbt_m1].table;
+ OPEN_READER(re, gb);
+
+ switch (cbt_m1 >> 1) {
+ case 0:
+ for (group = 0; group < g_len; group++, cfo+=128) {
+ float *cf = cfo;
+ int len = off_len;
+
+ do {
+ int code;
+ unsigned cb_idx;
+
+ UPDATE_CACHE(re, gb);
+ GET_VLC(code, re, gb, vlc_tab, 8, 2);
+ cb_idx = cb_vector_idx[code];
+ cf = VMUL4(cf, vq, cb_idx, sf + idx);
+ } while (len -= 4);
+ }
+ break;
+
+ case 1:
+ for (group = 0; group < g_len; group++, cfo+=128) {
+ float *cf = cfo;
+ int len = off_len;
+
+ do {
+ int code;
+ unsigned nnz;
+ unsigned cb_idx;
+ uint32_t bits;
+
+ UPDATE_CACHE(re, gb);
+ GET_VLC(code, re, gb, vlc_tab, 8, 2);
+ cb_idx = cb_vector_idx[code];
+ nnz = cb_idx >> 8 & 15;
+ bits = nnz ? GET_CACHE(re, gb) : 0;
+ LAST_SKIP_BITS(re, gb, nnz);
+ cf = VMUL4S(cf, vq, cb_idx, bits, sf + idx);
+ } while (len -= 4);
+ }
+ break;
+
+ case 2:
+ for (group = 0; group < g_len; group++, cfo+=128) {
+ float *cf = cfo;
+ int len = off_len;
+
+ do {
+ int code;
+ unsigned cb_idx;
+
+ UPDATE_CACHE(re, gb);
+ GET_VLC(code, re, gb, vlc_tab, 8, 2);
+ cb_idx = cb_vector_idx[code];
+ cf = VMUL2(cf, vq, cb_idx, sf + idx);
+ } while (len -= 2);
+ }
+ break;
+
+ case 3:
+ case 4:
+ for (group = 0; group < g_len; group++, cfo+=128) {
+ float *cf = cfo;
+ int len = off_len;
+
+ do {
+ int code;
+ unsigned nnz;
+ unsigned cb_idx;
+ unsigned sign;
+
+ UPDATE_CACHE(re, gb);
+ GET_VLC(code, re, gb, vlc_tab, 8, 2);
+ cb_idx = cb_vector_idx[code];
+ nnz = cb_idx >> 8 & 15;
+ sign = nnz ? SHOW_UBITS(re, gb, nnz) << (cb_idx >> 12) : 0;
+ LAST_SKIP_BITS(re, gb, nnz);
+ cf = VMUL2S(cf, vq, cb_idx, sign, sf + idx);
+ } while (len -= 2);
+ }
+ break;
+
+ default:
+ for (group = 0; group < g_len; group++, cfo+=128) {
+ float *cf = cfo;
+ uint32_t *icf = (uint32_t *) cf;
+ int len = off_len;
+
+ do {
+ int code;
+ unsigned nzt, nnz;
+ unsigned cb_idx;
+ uint32_t bits;
+ int j;
+
+ UPDATE_CACHE(re, gb);
+ GET_VLC(code, re, gb, vlc_tab, 8, 2);
+
+ if (!code) {
+ *icf++ = 0;
+ *icf++ = 0;
+ continue;
+ }
+
+ cb_idx = cb_vector_idx[code];
+ nnz = cb_idx >> 12;
+ nzt = cb_idx >> 8;
+ bits = SHOW_UBITS(re, gb, nnz) << (32-nnz);
+ LAST_SKIP_BITS(re, gb, nnz);
+
+ for (j = 0; j < 2; j++) {
+ if (nzt & 1<<j) {
+ uint32_t b;
+ int n;
+ /* The total length of escape_sequence must be < 22 bits according
+ to the specification (i.e. max is 111111110xxxxxxxxxxxx). */
+ UPDATE_CACHE(re, gb);
+ b = GET_CACHE(re, gb);
+ b = 31 - av_log2(~b);
+
+ if (b > 8) {
+ av_log(ac->avctx, AV_LOG_ERROR, "error in spectral data, ESC overflow\n");
+ return -1;
+ }
+
+ SKIP_BITS(re, gb, b + 1);
+ b += 4;
+ n = (1 << b) + SHOW_UBITS(re, gb, b);
+ LAST_SKIP_BITS(re, gb, b);
+ *icf++ = cbrt_tab[n] | (bits & 1U<<31);
+ bits <<= 1;
+ } else {
+ unsigned v = ((const uint32_t*)vq)[cb_idx & 15];
+ *icf++ = (bits & 1U<<31) | v;
+ bits <<= !!v;
+ }
+ cb_idx >>= 4;
+ }
+ } while (len -= 2);
+
+ ac->dsp.vector_fmul_scalar(cfo, cfo, sf[idx], off_len);
+ }
+ }
+
+ CLOSE_READER(re, gb);
+ }
+ }
+ coef += g_len << 7;
+ }
+
+ if (pulse_present) {
+ idx = 0;
+ for (i = 0; i < pulse->num_pulse; i++) {
+ float co = coef_base[ pulse->pos[i] ];
+ while (offsets[idx + 1] <= pulse->pos[i])
+ idx++;
+ if (band_type[idx] != NOISE_BT && sf[idx]) {
+ float ico = -pulse->amp[i];
+ if (co) {
+ co /= sf[idx];
+ ico = co / sqrtf(sqrtf(fabsf(co))) + (co > 0 ? -ico : ico);
+ }
+ coef_base[ pulse->pos[i] ] = cbrtf(fabsf(ico)) * ico * sf[idx];
+ }
+ }
+ }
+ return 0;
+}
+
+static av_always_inline float flt16_round(float pf)
+{
+ union av_intfloat32 tmp;
+ tmp.f = pf;
+ tmp.i = (tmp.i + 0x00008000U) & 0xFFFF0000U;
+ return tmp.f;
+}
+
+static av_always_inline float flt16_even(float pf)
+{
+ union av_intfloat32 tmp;
+ tmp.f = pf;
+ tmp.i = (tmp.i + 0x00007FFFU + (tmp.i & 0x00010000U >> 16)) & 0xFFFF0000U;
+ return tmp.f;
+}
+
+static av_always_inline float flt16_trunc(float pf)
+{
+ union av_intfloat32 pun;
+ pun.f = pf;
+ pun.i &= 0xFFFF0000U;
+ return pun.f;
+}
+
+static av_always_inline void predict(PredictorState *ps, float *coef,
+ int output_enable)
+{
+ const float a = 0.953125; // 61.0 / 64
+ const float alpha = 0.90625; // 29.0 / 32
+ float e0, e1;
+ float pv;
+ float k1, k2;
+ float r0 = ps->r0, r1 = ps->r1;
+ float cor0 = ps->cor0, cor1 = ps->cor1;
+ float var0 = ps->var0, var1 = ps->var1;
+
+ k1 = var0 > 1 ? cor0 * flt16_even(a / var0) : 0;
+ k2 = var1 > 1 ? cor1 * flt16_even(a / var1) : 0;
+
+ pv = flt16_round(k1 * r0 + k2 * r1);
+ if (output_enable)
+ *coef += pv;
+
+ e0 = *coef;
+ e1 = e0 - k1 * r0;
+
+ ps->cor1 = flt16_trunc(alpha * cor1 + r1 * e1);
+ ps->var1 = flt16_trunc(alpha * var1 + 0.5f * (r1 * r1 + e1 * e1));
+ ps->cor0 = flt16_trunc(alpha * cor0 + r0 * e0);
+ ps->var0 = flt16_trunc(alpha * var0 + 0.5f * (r0 * r0 + e0 * e0));
+
+ ps->r1 = flt16_trunc(a * (r0 - k1 * e0));
+ ps->r0 = flt16_trunc(a * e0);
+}
+
+/**
+ * Apply AAC-Main style frequency domain prediction.
+ */
+static void apply_prediction(AACContext *ac, SingleChannelElement *sce)
+{
+ int sfb, k;
+
+ if (!sce->ics.predictor_initialized) {
+ reset_all_predictors(sce->predictor_state);
+ sce->ics.predictor_initialized = 1;
+ }
+
+ if (sce->ics.window_sequence[0] != EIGHT_SHORT_SEQUENCE) {
+ for (sfb = 0; sfb < ff_aac_pred_sfb_max[ac->m4ac.sampling_index]; sfb++) {
+ for (k = sce->ics.swb_offset[sfb]; k < sce->ics.swb_offset[sfb + 1]; k++) {
+ predict(&sce->predictor_state[k], &sce->coeffs[k],
+ sce->ics.predictor_present && sce->ics.prediction_used[sfb]);
+ }
+ }
+ if (sce->ics.predictor_reset_group)
+ reset_predictor_group(sce->predictor_state, sce->ics.predictor_reset_group);
+ } else
+ reset_all_predictors(sce->predictor_state);
+}
+
+/**
+ * Decode an individual_channel_stream payload; reference: table 4.44.
+ *
+ * @param common_window Channels have independent [0], or shared [1], Individual Channel Stream information.
+ * @param scale_flag scalable [1] or non-scalable [0] AAC (Unused until scalable AAC is implemented.)
+ *
+ * @return Returns error status. 0 - OK, !0 - error
+ */
+static int decode_ics(AACContext *ac, SingleChannelElement *sce,
+ GetBitContext *gb, int common_window, int scale_flag)
+{
+ Pulse pulse;
+ TemporalNoiseShaping *tns = &sce->tns;
+ IndividualChannelStream *ics = &sce->ics;
+ float *out = sce->coeffs;
+ int global_gain, pulse_present = 0;
+
+ /* This assignment is to silence a GCC warning about the variable being used
+ * uninitialized when in fact it always is.
+ */
+ pulse.num_pulse = 0;
+
+ global_gain = get_bits(gb, 8);
+
+ if (!common_window && !scale_flag) {
+ if (decode_ics_info(ac, ics, gb) < 0)
+ return AVERROR_INVALIDDATA;
+ }
+
+ if (decode_band_types(ac, sce->band_type, sce->band_type_run_end, gb, ics) < 0)
+ return -1;
+ if (decode_scalefactors(ac, sce->sf, gb, global_gain, ics, sce->band_type, sce->band_type_run_end) < 0)
+ return -1;
+
+ pulse_present = 0;
+ if (!scale_flag) {
+ if ((pulse_present = get_bits1(gb))) {
+ if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
+ av_log(ac->avctx, AV_LOG_ERROR, "Pulse tool not allowed in eight short sequence.\n");
+ return -1;
+ }
+ if (decode_pulses(&pulse, gb, ics->swb_offset, ics->num_swb)) {
+ av_log(ac->avctx, AV_LOG_ERROR, "Pulse data corrupt or invalid.\n");
+ return -1;
+ }
+ }
+ if ((tns->present = get_bits1(gb)) && decode_tns(ac, tns, gb, ics))
+ return -1;
+ if (get_bits1(gb)) {
+ av_log_missing_feature(ac->avctx, "SSR", 1);
+ return -1;
+ }
+ }
+
+ if (decode_spectrum_and_dequant(ac, out, gb, sce->sf, pulse_present, &pulse, ics, sce->band_type) < 0)
+ return -1;
+
+ if (ac->m4ac.object_type == AOT_AAC_MAIN && !common_window)
+ apply_prediction(ac, sce);
+
+ return 0;
+}
+
+/**
+ * Mid/Side stereo decoding; reference: 4.6.8.1.3.
+ */
+static void apply_mid_side_stereo(AACContext *ac, ChannelElement *cpe)
+{
+ const IndividualChannelStream *ics = &cpe->ch[0].ics;
+ float *ch0 = cpe->ch[0].coeffs;
+ float *ch1 = cpe->ch[1].coeffs;
+ int g, i, group, idx = 0;
+ const uint16_t *offsets = ics->swb_offset;
+ for (g = 0; g < ics->num_window_groups; g++) {
+ for (i = 0; i < ics->max_sfb; i++, idx++) {
+ if (cpe->ms_mask[idx] &&
+ cpe->ch[0].band_type[idx] < NOISE_BT && cpe->ch[1].band_type[idx] < NOISE_BT) {
+ for (group = 0; group < ics->group_len[g]; group++) {
+ ac->dsp.butterflies_float(ch0 + group * 128 + offsets[i],
+ ch1 + group * 128 + offsets[i],
+ offsets[i+1] - offsets[i]);
+ }
+ }
+ }
+ ch0 += ics->group_len[g] * 128;
+ ch1 += ics->group_len[g] * 128;
+ }
+}
+
+/**
+ * intensity stereo decoding; reference: 4.6.8.2.3
+ *
+ * @param ms_present Indicates mid/side stereo presence. [0] mask is all 0s;
+ * [1] mask is decoded from bitstream; [2] mask is all 1s;
+ * [3] reserved for scalable AAC
+ */
+static void apply_intensity_stereo(AACContext *ac, ChannelElement *cpe, int ms_present)
+{
+ const IndividualChannelStream *ics = &cpe->ch[1].ics;
+ SingleChannelElement *sce1 = &cpe->ch[1];
+ float *coef0 = cpe->ch[0].coeffs, *coef1 = cpe->ch[1].coeffs;
+ const uint16_t *offsets = ics->swb_offset;
+ int g, group, i, idx = 0;
+ int c;
+ float scale;
+ for (g = 0; g < ics->num_window_groups; g++) {
+ for (i = 0; i < ics->max_sfb;) {
+ if (sce1->band_type[idx] == INTENSITY_BT || sce1->band_type[idx] == INTENSITY_BT2) {
+ const int bt_run_end = sce1->band_type_run_end[idx];
+ for (; i < bt_run_end; i++, idx++) {
+ c = -1 + 2 * (sce1->band_type[idx] - 14);
+ if (ms_present)
+ c *= 1 - 2 * cpe->ms_mask[idx];
+ scale = c * sce1->sf[idx];
+ for (group = 0; group < ics->group_len[g]; group++)
+ ac->dsp.vector_fmul_scalar(coef1 + group * 128 + offsets[i],
+ coef0 + group * 128 + offsets[i],
+ scale,
+ offsets[i + 1] - offsets[i]);
+ }
+ } else {
+ int bt_run_end = sce1->band_type_run_end[idx];
+ idx += bt_run_end - i;
+ i = bt_run_end;
+ }
+ }
+ coef0 += ics->group_len[g] * 128;
+ coef1 += ics->group_len[g] * 128;
+ }
+}
+
+/**
+ * Decode a channel_pair_element; reference: table 4.4.
+ *
+ * @return Returns error status. 0 - OK, !0 - error
+ */
+static int decode_cpe(AACContext *ac, GetBitContext *gb, ChannelElement *cpe)
+{
+ int i, ret, common_window, ms_present = 0;
+
+ common_window = get_bits1(gb);
+ if (common_window) {
+ if (decode_ics_info(ac, &cpe->ch[0].ics, gb))
+ return AVERROR_INVALIDDATA;
+ i = cpe->ch[1].ics.use_kb_window[0];
+ cpe->ch[1].ics = cpe->ch[0].ics;
+ cpe->ch[1].ics.use_kb_window[1] = i;
+ if (cpe->ch[1].ics.predictor_present && (ac->m4ac.object_type != AOT_AAC_MAIN))
+ if ((cpe->ch[1].ics.ltp.present = get_bits(gb, 1)))
+ decode_ltp(ac, &cpe->ch[1].ics.ltp, gb, cpe->ch[1].ics.max_sfb);
+ ms_present = get_bits(gb, 2);
+ if (ms_present == 3) {
+ av_log(ac->avctx, AV_LOG_ERROR, "ms_present = 3 is reserved.\n");
+ return -1;
+ } else if (ms_present)
+ decode_mid_side_stereo(cpe, gb, ms_present);
+ }
+ if ((ret = decode_ics(ac, &cpe->ch[0], gb, common_window, 0)))
+ return ret;
+ if ((ret = decode_ics(ac, &cpe->ch[1], gb, common_window, 0)))
+ return ret;
+
+ if (common_window) {
+ if (ms_present)
+ apply_mid_side_stereo(ac, cpe);
+ if (ac->m4ac.object_type == AOT_AAC_MAIN) {
+ apply_prediction(ac, &cpe->ch[0]);
+ apply_prediction(ac, &cpe->ch[1]);
+ }
+ }
+
+ apply_intensity_stereo(ac, cpe, ms_present);
+ return 0;
+}
+
+static const float cce_scale[] = {
+ 1.09050773266525765921, //2^(1/8)
+ 1.18920711500272106672, //2^(1/4)
+ M_SQRT2,
+ 2,
+};
+
+/**
+ * Decode coupling_channel_element; reference: table 4.8.
+ *
+ * @return Returns error status. 0 - OK, !0 - error
+ */
+static int decode_cce(AACContext *ac, GetBitContext *gb, ChannelElement *che)
+{
+ int num_gain = 0;
+ int c, g, sfb, ret;
+ int sign;
+ float scale;
+ SingleChannelElement *sce = &che->ch[0];
+ ChannelCoupling *coup = &che->coup;
+
+ coup->coupling_point = 2 * get_bits1(gb);
+ coup->num_coupled = get_bits(gb, 3);
+ for (c = 0; c <= coup->num_coupled; c++) {
+ num_gain++;
+ coup->type[c] = get_bits1(gb) ? TYPE_CPE : TYPE_SCE;
+ coup->id_select[c] = get_bits(gb, 4);
+ if (coup->type[c] == TYPE_CPE) {
+ coup->ch_select[c] = get_bits(gb, 2);
+ if (coup->ch_select[c] == 3)
+ num_gain++;
+ } else
+ coup->ch_select[c] = 2;
+ }
+ coup->coupling_point += get_bits1(gb) || (coup->coupling_point >> 1);
+
+ sign = get_bits(gb, 1);
+ scale = cce_scale[get_bits(gb, 2)];
+
+ if ((ret = decode_ics(ac, sce, gb, 0, 0)))
+ return ret;
+
+ for (c = 0; c < num_gain; c++) {
+ int idx = 0;
+ int cge = 1;
+ int gain = 0;
+ float gain_cache = 1.;
+ if (c) {
+ cge = coup->coupling_point == AFTER_IMDCT ? 1 : get_bits1(gb);
+ gain = cge ? get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60: 0;
+ gain_cache = powf(scale, -gain);
+ }
+ if (coup->coupling_point == AFTER_IMDCT) {
+ coup->gain[c][0] = gain_cache;
+ } else {
+ for (g = 0; g < sce->ics.num_window_groups; g++) {
+ for (sfb = 0; sfb < sce->ics.max_sfb; sfb++, idx++) {
+ if (sce->band_type[idx] != ZERO_BT) {
+ if (!cge) {
+ int t = get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60;
+ if (t) {
+ int s = 1;
+ t = gain += t;
+ if (sign) {
+ s -= 2 * (t & 0x1);
+ t >>= 1;
+ }
+ gain_cache = powf(scale, -t) * s;
+ }
+ }
+ coup->gain[c][idx] = gain_cache;
+ }
+ }
+ }
+ }
+ }
+ return 0;
+}
+
+/**
+ * Parse whether channels are to be excluded from Dynamic Range Compression; reference: table 4.53.
+ *
+ * @return Returns number of bytes consumed.
+ */
+static int decode_drc_channel_exclusions(DynamicRangeControl *che_drc,
+ GetBitContext *gb)
+{
+ int i;
+ int num_excl_chan = 0;
+
+ do {
+ for (i = 0; i < 7; i++)
+ che_drc->exclude_mask[num_excl_chan++] = get_bits1(gb);
+ } while (num_excl_chan < MAX_CHANNELS - 7 && get_bits1(gb));
+
+ return num_excl_chan / 7;
+}
+
+/**
+ * Decode dynamic range information; reference: table 4.52.
+ *
+ * @param cnt length of TYPE_FIL syntactic element in bytes
+ *
+ * @return Returns number of bytes consumed.
+ */
+static int decode_dynamic_range(DynamicRangeControl *che_drc,
+ GetBitContext *gb, int cnt)
+{
+ int n = 1;
+ int drc_num_bands = 1;
+ int i;
+
+ /* pce_tag_present? */
+ if (get_bits1(gb)) {
+ che_drc->pce_instance_tag = get_bits(gb, 4);
+ skip_bits(gb, 4); // tag_reserved_bits
+ n++;
+ }
+
+ /* excluded_chns_present? */
+ if (get_bits1(gb)) {
+ n += decode_drc_channel_exclusions(che_drc, gb);
+ }
+
+ /* drc_bands_present? */
+ if (get_bits1(gb)) {
+ che_drc->band_incr = get_bits(gb, 4);
+ che_drc->interpolation_scheme = get_bits(gb, 4);
+ n++;
+ drc_num_bands += che_drc->band_incr;
+ for (i = 0; i < drc_num_bands; i++) {
+ che_drc->band_top[i] = get_bits(gb, 8);
+ n++;
+ }
+ }
+
+ /* prog_ref_level_present? */
+ if (get_bits1(gb)) {
+ che_drc->prog_ref_level = get_bits(gb, 7);
+ skip_bits1(gb); // prog_ref_level_reserved_bits
+ n++;
+ }
+
+ for (i = 0; i < drc_num_bands; i++) {
+ che_drc->dyn_rng_sgn[i] = get_bits1(gb);
+ che_drc->dyn_rng_ctl[i] = get_bits(gb, 7);
+ n++;
+ }
+
+ return n;
+}
+
+/**
+ * Decode extension data (incomplete); reference: table 4.51.
+ *
+ * @param cnt length of TYPE_FIL syntactic element in bytes
+ *
+ * @return Returns number of bytes consumed
+ */
+static int decode_extension_payload(AACContext *ac, GetBitContext *gb, int cnt,
+ ChannelElement *che, enum RawDataBlockType elem_type)
+{
+ int crc_flag = 0;
+ int res = cnt;
+ switch (get_bits(gb, 4)) { // extension type
+ case EXT_SBR_DATA_CRC:
+ crc_flag++;
+ case EXT_SBR_DATA:
+ if (!che) {
+ av_log(ac->avctx, AV_LOG_ERROR, "SBR was found before the first channel element.\n");
+ return res;
+ } else if (!ac->m4ac.sbr) {
+ av_log(ac->avctx, AV_LOG_ERROR, "SBR signaled to be not-present but was found in the bitstream.\n");
+ skip_bits_long(gb, 8 * cnt - 4);
+ return res;
+ } else if (ac->m4ac.sbr == -1 && ac->output_configured == OC_LOCKED) {
+ av_log(ac->avctx, AV_LOG_ERROR, "Implicit SBR was found with a first occurrence after the first frame.\n");
+ skip_bits_long(gb, 8 * cnt - 4);
+ return res;
+ } else if (ac->m4ac.ps == -1 && ac->output_configured < OC_LOCKED && ac->avctx->channels == 1) {
+ ac->m4ac.sbr = 1;
+ ac->m4ac.ps = 1;
+ output_configure(ac, ac->layout_map, ac->layout_map_tags,
+ ac->m4ac.chan_config, ac->output_configured);
+ } else {
+ ac->m4ac.sbr = 1;
+ }
+ res = ff_decode_sbr_extension(ac, &che->sbr, gb, crc_flag, cnt, elem_type);
+ break;
+ case EXT_DYNAMIC_RANGE:
+ res = decode_dynamic_range(&ac->che_drc, gb, cnt);
+ break;
+ case EXT_FILL:
+ case EXT_FILL_DATA:
+ case EXT_DATA_ELEMENT:
+ default:
+ skip_bits_long(gb, 8 * cnt - 4);
+ break;
+ };
+ return res;
+}
+
+/**
+ * Decode Temporal Noise Shaping filter coefficients and apply all-pole filters; reference: 4.6.9.3.
+ *
+ * @param decode 1 if tool is used normally, 0 if tool is used in LTP.
+ * @param coef spectral coefficients
+ */
+static void apply_tns(float coef[1024], TemporalNoiseShaping *tns,
+ IndividualChannelStream *ics, int decode)
+{
+ const int mmm = FFMIN(ics->tns_max_bands, ics->max_sfb);
+ int w, filt, m, i;
+ int bottom, top, order, start, end, size, inc;
+ float lpc[TNS_MAX_ORDER];
+ float tmp[TNS_MAX_ORDER];
+
+ for (w = 0; w < ics->num_windows; w++) {
+ bottom = ics->num_swb;
+ for (filt = 0; filt < tns->n_filt[w]; filt++) {
+ top = bottom;
+ bottom = FFMAX(0, top - tns->length[w][filt]);
+ order = tns->order[w][filt];
+ if (order == 0)
+ continue;
+
+ // tns_decode_coef
+ compute_lpc_coefs(tns->coef[w][filt], order, lpc, 0, 0, 0);
+
+ start = ics->swb_offset[FFMIN(bottom, mmm)];
+ end = ics->swb_offset[FFMIN( top, mmm)];
+ if ((size = end - start) <= 0)
+ continue;
+ if (tns->direction[w][filt]) {
+ inc = -1;
+ start = end - 1;
+ } else {
+ inc = 1;
+ }
+ start += w * 128;
+
+ if (decode) {
+ // ar filter
+ for (m = 0; m < size; m++, start += inc)
+ for (i = 1; i <= FFMIN(m, order); i++)
+ coef[start] -= coef[start - i * inc] * lpc[i - 1];
+ } else {
+ // ma filter
+ for (m = 0; m < size; m++, start += inc) {
+ tmp[0] = coef[start];
+ for (i = 1; i <= FFMIN(m, order); i++)
+ coef[start] += tmp[i] * lpc[i - 1];
+ for (i = order; i > 0; i--)
+ tmp[i] = tmp[i - 1];
+ }
+ }
+ }
+ }
+}
+
+/**
+ * Apply windowing and MDCT to obtain the spectral
+ * coefficient from the predicted sample by LTP.
+ */
+static void windowing_and_mdct_ltp(AACContext *ac, float *out,
+ float *in, IndividualChannelStream *ics)
+{
+ const float *lwindow = ics->use_kb_window[0] ? ff_aac_kbd_long_1024 : ff_sine_1024;
+ const float *swindow = ics->use_kb_window[0] ? ff_aac_kbd_short_128 : ff_sine_128;
+ const float *lwindow_prev = ics->use_kb_window[1] ? ff_aac_kbd_long_1024 : ff_sine_1024;
+ const float *swindow_prev = ics->use_kb_window[1] ? ff_aac_kbd_short_128 : ff_sine_128;
+
+ if (ics->window_sequence[0] != LONG_STOP_SEQUENCE) {
+ ac->dsp.vector_fmul(in, in, lwindow_prev, 1024);
+ } else {
+ memset(in, 0, 448 * sizeof(float));
+ ac->dsp.vector_fmul(in + 448, in + 448, swindow_prev, 128);
+ }
+ if (ics->window_sequence[0] != LONG_START_SEQUENCE) {
+ ac->dsp.vector_fmul_reverse(in + 1024, in + 1024, lwindow, 1024);
+ } else {
+ ac->dsp.vector_fmul_reverse(in + 1024 + 448, in + 1024 + 448, swindow, 128);
+ memset(in + 1024 + 576, 0, 448 * sizeof(float));
+ }
+ ac->mdct_ltp.mdct_calc(&ac->mdct_ltp, out, in);
+}
+
+/**
+ * Apply the long term prediction
+ */
+static void apply_ltp(AACContext *ac, SingleChannelElement *sce)
+{
+ const LongTermPrediction *ltp = &sce->ics.ltp;
+ const uint16_t *offsets = sce->ics.swb_offset;
+ int i, sfb;
+
+ if (sce->ics.window_sequence[0] != EIGHT_SHORT_SEQUENCE) {
+ float *predTime = sce->ret;
+ float *predFreq = ac->buf_mdct;
+ int16_t num_samples = 2048;
+
+ if (ltp->lag < 1024)
+ num_samples = ltp->lag + 1024;
+ for (i = 0; i < num_samples; i++)
+ predTime[i] = sce->ltp_state[i + 2048 - ltp->lag] * ltp->coef;
+ memset(&predTime[i], 0, (2048 - i) * sizeof(float));
+
+ windowing_and_mdct_ltp(ac, predFreq, predTime, &sce->ics);
+
+ if (sce->tns.present)
+ apply_tns(predFreq, &sce->tns, &sce->ics, 0);
+
+ for (sfb = 0; sfb < FFMIN(sce->ics.max_sfb, MAX_LTP_LONG_SFB); sfb++)
+ if (ltp->used[sfb])
+ for (i = offsets[sfb]; i < offsets[sfb + 1]; i++)
+ sce->coeffs[i] += predFreq[i];
+ }
+}
+
+/**
+ * Update the LTP buffer for next frame
+ */
+static void update_ltp(AACContext *ac, SingleChannelElement *sce)
+{
+ IndividualChannelStream *ics = &sce->ics;
+ float *saved = sce->saved;
+ float *saved_ltp = sce->coeffs;
+ const float *lwindow = ics->use_kb_window[0] ? ff_aac_kbd_long_1024 : ff_sine_1024;
+ const float *swindow = ics->use_kb_window[0] ? ff_aac_kbd_short_128 : ff_sine_128;
+ int i;
+
+ if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
+ memcpy(saved_ltp, saved, 512 * sizeof(float));
+ memset(saved_ltp + 576, 0, 448 * sizeof(float));
+ ac->dsp.vector_fmul_reverse(saved_ltp + 448, ac->buf_mdct + 960, &swindow[64], 64);
+ for (i = 0; i < 64; i++)
+ saved_ltp[i + 512] = ac->buf_mdct[1023 - i] * swindow[63 - i];
+ } else if (ics->window_sequence[0] == LONG_START_SEQUENCE) {
+ memcpy(saved_ltp, ac->buf_mdct + 512, 448 * sizeof(float));
+ memset(saved_ltp + 576, 0, 448 * sizeof(float));
+ ac->dsp.vector_fmul_reverse(saved_ltp + 448, ac->buf_mdct + 960, &swindow[64], 64);
+ for (i = 0; i < 64; i++)
+ saved_ltp[i + 512] = ac->buf_mdct[1023 - i] * swindow[63 - i];
+ } else { // LONG_STOP or ONLY_LONG
+ ac->dsp.vector_fmul_reverse(saved_ltp, ac->buf_mdct + 512, &lwindow[512], 512);
+ for (i = 0; i < 512; i++)
+ saved_ltp[i + 512] = ac->buf_mdct[1023 - i] * lwindow[511 - i];
+ }
+
+ memcpy(sce->ltp_state, sce->ltp_state+1024, 1024 * sizeof(*sce->ltp_state));
+ memcpy(sce->ltp_state+1024, sce->ret, 1024 * sizeof(*sce->ltp_state));
+ memcpy(sce->ltp_state+2048, saved_ltp, 1024 * sizeof(*sce->ltp_state));
+}
+
+/**
+ * Conduct IMDCT and windowing.
+ */
+static void imdct_and_windowing(AACContext *ac, SingleChannelElement *sce)
+{
+ IndividualChannelStream *ics = &sce->ics;
+ float *in = sce->coeffs;
+ float *out = sce->ret;
+ float *saved = sce->saved;
+ const float *swindow = ics->use_kb_window[0] ? ff_aac_kbd_short_128 : ff_sine_128;
+ const float *lwindow_prev = ics->use_kb_window[1] ? ff_aac_kbd_long_1024 : ff_sine_1024;
+ const float *swindow_prev = ics->use_kb_window[1] ? ff_aac_kbd_short_128 : ff_sine_128;
+ float *buf = ac->buf_mdct;
+ float *temp = ac->temp;
+ int i;
+
+ // imdct
+ if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
+ for (i = 0; i < 1024; i += 128)
+ ac->mdct_small.imdct_half(&ac->mdct_small, buf + i, in + i);
+ } else
+ ac->mdct.imdct_half(&ac->mdct, buf, in);
+
+ /* window overlapping
+ * NOTE: To simplify the overlapping code, all 'meaningless' short to long
+ * and long to short transitions are considered to be short to short
+ * transitions. This leaves just two cases (long to long and short to short)
+ * with a little special sauce for EIGHT_SHORT_SEQUENCE.
+ */
+ if ((ics->window_sequence[1] == ONLY_LONG_SEQUENCE || ics->window_sequence[1] == LONG_STOP_SEQUENCE) &&
+ (ics->window_sequence[0] == ONLY_LONG_SEQUENCE || ics->window_sequence[0] == LONG_START_SEQUENCE)) {
+ ac->dsp.vector_fmul_window( out, saved, buf, lwindow_prev, 512);
+ } else {
+ memcpy( out, saved, 448 * sizeof(float));
+
+ if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
+ ac->dsp.vector_fmul_window(out + 448 + 0*128, saved + 448, buf + 0*128, swindow_prev, 64);
+ ac->dsp.vector_fmul_window(out + 448 + 1*128, buf + 0*128 + 64, buf + 1*128, swindow, 64);
+ ac->dsp.vector_fmul_window(out + 448 + 2*128, buf + 1*128 + 64, buf + 2*128, swindow, 64);
+ ac->dsp.vector_fmul_window(out + 448 + 3*128, buf + 2*128 + 64, buf + 3*128, swindow, 64);
+ ac->dsp.vector_fmul_window(temp, buf + 3*128 + 64, buf + 4*128, swindow, 64);
+ memcpy( out + 448 + 4*128, temp, 64 * sizeof(float));
+ } else {
+ ac->dsp.vector_fmul_window(out + 448, saved + 448, buf, swindow_prev, 64);
+ memcpy( out + 576, buf + 64, 448 * sizeof(float));
+ }
+ }
+
+ // buffer update
+ if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
+ memcpy( saved, temp + 64, 64 * sizeof(float));
+ ac->dsp.vector_fmul_window(saved + 64, buf + 4*128 + 64, buf + 5*128, swindow, 64);
+ ac->dsp.vector_fmul_window(saved + 192, buf + 5*128 + 64, buf + 6*128, swindow, 64);
+ ac->dsp.vector_fmul_window(saved + 320, buf + 6*128 + 64, buf + 7*128, swindow, 64);
+ memcpy( saved + 448, buf + 7*128 + 64, 64 * sizeof(float));
+ } else if (ics->window_sequence[0] == LONG_START_SEQUENCE) {
+ memcpy( saved, buf + 512, 448 * sizeof(float));
+ memcpy( saved + 448, buf + 7*128 + 64, 64 * sizeof(float));
+ } else { // LONG_STOP or ONLY_LONG
+ memcpy( saved, buf + 512, 512 * sizeof(float));
+ }
+}
+
+/**
+ * Apply dependent channel coupling (applied before IMDCT).
+ *
+ * @param index index into coupling gain array
+ */
+static void apply_dependent_coupling(AACContext *ac,
+ SingleChannelElement *target,
+ ChannelElement *cce, int index)
+{
+ IndividualChannelStream *ics = &cce->ch[0].ics;
+ const uint16_t *offsets = ics->swb_offset;
+ float *dest = target->coeffs;
+ const float *src = cce->ch[0].coeffs;
+ int g, i, group, k, idx = 0;
+ if (ac->m4ac.object_type == AOT_AAC_LTP) {
+ av_log(ac->avctx, AV_LOG_ERROR,
+ "Dependent coupling is not supported together with LTP\n");
+ return;
+ }
+ for (g = 0; g < ics->num_window_groups; g++) {
+ for (i = 0; i < ics->max_sfb; i++, idx++) {
+ if (cce->ch[0].band_type[idx] != ZERO_BT) {
+ const float gain = cce->coup.gain[index][idx];
+ for (group = 0; group < ics->group_len[g]; group++) {
+ for (k = offsets[i]; k < offsets[i + 1]; k++) {
+ // XXX dsputil-ize
+ dest[group * 128 + k] += gain * src[group * 128 + k];
+ }
+ }
+ }
+ }
+ dest += ics->group_len[g] * 128;
+ src += ics->group_len[g] * 128;
+ }
+}
+
+/**
+ * Apply independent channel coupling (applied after IMDCT).
+ *
+ * @param index index into coupling gain array
+ */
+static void apply_independent_coupling(AACContext *ac,
+ SingleChannelElement *target,
+ ChannelElement *cce, int index)
+{
+ int i;
+ const float gain = cce->coup.gain[index][0];
+ const float *src = cce->ch[0].ret;
+ float *dest = target->ret;
+ const int len = 1024 << (ac->m4ac.sbr == 1);
+
+ for (i = 0; i < len; i++)
+ dest[i] += gain * src[i];
+}
+
+/**
+ * channel coupling transformation interface
+ *
+ * @param apply_coupling_method pointer to (in)dependent coupling function
+ */
+static void apply_channel_coupling(AACContext *ac, ChannelElement *cc,
+ enum RawDataBlockType type, int elem_id,
+ enum CouplingPoint coupling_point,
+ void (*apply_coupling_method)(AACContext *ac, SingleChannelElement *target, ChannelElement *cce, int index))
+{
+ int i, c;
+
+ for (i = 0; i < MAX_ELEM_ID; i++) {
+ ChannelElement *cce = ac->che[TYPE_CCE][i];
+ int index = 0;
+
+ if (cce && cce->coup.coupling_point == coupling_point) {
+ ChannelCoupling *coup = &cce->coup;
+
+ for (c = 0; c <= coup->num_coupled; c++) {
+ if (coup->type[c] == type && coup->id_select[c] == elem_id) {
+ if (coup->ch_select[c] != 1) {
+ apply_coupling_method(ac, &cc->ch[0], cce, index);
+ if (coup->ch_select[c] != 0)
+ index++;
+ }
+ if (coup->ch_select[c] != 2)
+ apply_coupling_method(ac, &cc->ch[1], cce, index++);
+ } else
+ index += 1 + (coup->ch_select[c] == 3);
+ }
+ }
+ }
+}
+
+/**
+ * Convert spectral data to float samples, applying all supported tools as appropriate.
+ */
+static void spectral_to_sample(AACContext *ac)
+{
+ int i, type;
+ for (type = 3; type >= 0; type--) {
+ for (i = 0; i < MAX_ELEM_ID; i++) {
+ ChannelElement *che = ac->che[type][i];
+ if (che) {
+ if (type <= TYPE_CPE)
+ apply_channel_coupling(ac, che, type, i, BEFORE_TNS, apply_dependent_coupling);
+ if (ac->m4ac.object_type == AOT_AAC_LTP) {
+ if (che->ch[0].ics.predictor_present) {
+ if (che->ch[0].ics.ltp.present)
+ apply_ltp(ac, &che->ch[0]);
+ if (che->ch[1].ics.ltp.present && type == TYPE_CPE)
+ apply_ltp(ac, &che->ch[1]);
+ }
+ }
+ if (che->ch[0].tns.present)
+ apply_tns(che->ch[0].coeffs, &che->ch[0].tns, &che->ch[0].ics, 1);
+ if (che->ch[1].tns.present)
+ apply_tns(che->ch[1].coeffs, &che->ch[1].tns, &che->ch[1].ics, 1);
+ if (type <= TYPE_CPE)
+ apply_channel_coupling(ac, che, type, i, BETWEEN_TNS_AND_IMDCT, apply_dependent_coupling);
+ if (type != TYPE_CCE || che->coup.coupling_point == AFTER_IMDCT) {
+ imdct_and_windowing(ac, &che->ch[0]);
+ if (ac->m4ac.object_type == AOT_AAC_LTP)
+ update_ltp(ac, &che->ch[0]);
+ if (type == TYPE_CPE) {
+ imdct_and_windowing(ac, &che->ch[1]);
+ if (ac->m4ac.object_type == AOT_AAC_LTP)
+ update_ltp(ac, &che->ch[1]);
+ }
+ if (ac->m4ac.sbr > 0) {
+ ff_sbr_apply(ac, &che->sbr, type, che->ch[0].ret, che->ch[1].ret);
+ }
+ }
+ if (type <= TYPE_CCE)
+ apply_channel_coupling(ac, che, type, i, AFTER_IMDCT, apply_independent_coupling);
+ }
+ }
+ }
+}
+
+static int parse_adts_frame_header(AACContext *ac, GetBitContext *gb)
+{
+ int size;
+ AACADTSHeaderInfo hdr_info;
+ uint8_t layout_map[MAX_ELEM_ID*4][3];
+ int layout_map_tags;
+
+ size = avpriv_aac_parse_header(gb, &hdr_info);
+ if (size > 0) {
+ if (hdr_info.chan_config) {
+ ac->m4ac.chan_config = hdr_info.chan_config;
+ if (set_default_channel_config(ac->avctx, layout_map,
+ &layout_map_tags, hdr_info.chan_config))
+ return -7;
+ if (output_configure(ac, layout_map, layout_map_tags,
+ hdr_info.chan_config,
+ FFMAX(ac->output_configured, OC_TRIAL_FRAME)))
+ return -7;
+ } else if (ac->output_configured != OC_LOCKED) {
+ ac->m4ac.chan_config = 0;
+ ac->output_configured = OC_NONE;
+ }
+ if (ac->output_configured != OC_LOCKED) {
+ ac->m4ac.sbr = -1;
+ ac->m4ac.ps = -1;
+ ac->m4ac.sample_rate = hdr_info.sample_rate;
+ ac->m4ac.sampling_index = hdr_info.sampling_index;
+ ac->m4ac.object_type = hdr_info.object_type;
+ }
+ if (!ac->avctx->sample_rate)
+ ac->avctx->sample_rate = hdr_info.sample_rate;
+ if (!ac->warned_num_aac_frames && hdr_info.num_aac_frames != 1) {
+ // This is 2 for "VLB " audio in NSV files.
+ // See samples/nsv/vlb_audio.
+ av_log_missing_feature(ac->avctx, "More than one AAC RDB per ADTS frame is", 0);
+ ac->warned_num_aac_frames = 1;
+ }
+ if (!hdr_info.crc_absent)
+ skip_bits(gb, 16);
+ }
+ return size;
+}
+
+static int aac_decode_frame_int(AVCodecContext *avctx, void *data,
+ int *got_frame_ptr, GetBitContext *gb)
+{
+ AACContext *ac = avctx->priv_data;
+ ChannelElement *che = NULL, *che_prev = NULL;
+ enum RawDataBlockType elem_type, elem_type_prev = TYPE_END;
+ int err, elem_id;
+ int samples = 0, multiplier, audio_found = 0;
+
+ if (show_bits(gb, 12) == 0xfff) {
+ if (parse_adts_frame_header(ac, gb) < 0) {
+ av_log(avctx, AV_LOG_ERROR, "Error decoding AAC frame header.\n");
+ return -1;
+ }
+ if (ac->m4ac.sampling_index > 12) {
+ av_log(ac->avctx, AV_LOG_ERROR, "invalid sampling rate index %d\n", ac->m4ac.sampling_index);
+ return -1;
+ }
+ }
+
+ ac->tags_mapped = 0;
+ // parse
+ while ((elem_type = get_bits(gb, 3)) != TYPE_END) {
+ elem_id = get_bits(gb, 4);
+
+ if (elem_type < TYPE_DSE) {
+ if (!(che=get_che(ac, elem_type, elem_id))) {
+ av_log(ac->avctx, AV_LOG_ERROR, "channel element %d.%d is not allocated\n",
+ elem_type, elem_id);
+ return -1;
+ }
+ samples = 1024;
+ }
+
+ switch (elem_type) {
+
+ case TYPE_SCE:
+ err = decode_ics(ac, &che->ch[0], gb, 0, 0);
+ audio_found = 1;
+ break;
+
+ case TYPE_CPE:
+ err = decode_cpe(ac, gb, che);
+ audio_found = 1;
+ break;
+
+ case TYPE_CCE:
+ err = decode_cce(ac, gb, che);
+ break;
+
+ case TYPE_LFE:
+ err = decode_ics(ac, &che->ch[0], gb, 0, 0);
+ audio_found = 1;
+ break;
+
+ case TYPE_DSE:
+ err = skip_data_stream_element(ac, gb);
+ break;
+
+ case TYPE_PCE: {
+ uint8_t layout_map[MAX_ELEM_ID*4][3];
+ int tags;
+ tags = decode_pce(avctx, &ac->m4ac, layout_map, gb);
+ if (tags < 0) {
+ err = tags;
+ break;
+ }
+ if (ac->output_configured > OC_TRIAL_PCE)
+ av_log(avctx, AV_LOG_INFO,
+ "Evaluating a further program_config_element.\n");
+ err = output_configure(ac, layout_map, tags, 0, OC_TRIAL_PCE);
+ if (!err)
+ ac->m4ac.chan_config = 0;
+ break;
+ }
+
+ case TYPE_FIL:
+ if (elem_id == 15)
+ elem_id += get_bits(gb, 8) - 1;
+ if (get_bits_left(gb) < 8 * elem_id) {
+ av_log(avctx, AV_LOG_ERROR, overread_err);
+ return -1;
+ }
+ while (elem_id > 0)
+ elem_id -= decode_extension_payload(ac, gb, elem_id, che_prev, elem_type_prev);
+ err = 0; /* FIXME */
+ break;
+
+ default:
+ err = -1; /* should not happen, but keeps compiler happy */
+ break;
+ }
+
+ che_prev = che;
+ elem_type_prev = elem_type;
+
+ if (err)
+ return err;
+
+ if (get_bits_left(gb) < 3) {
+ av_log(avctx, AV_LOG_ERROR, overread_err);
+ return -1;
+ }
+ }
+
+ spectral_to_sample(ac);
+
+ multiplier = (ac->m4ac.sbr == 1) ? ac->m4ac.ext_sample_rate > ac->m4ac.sample_rate : 0;
+ samples <<= multiplier;
+ if (ac->output_configured < OC_LOCKED) {
+ avctx->sample_rate = ac->m4ac.sample_rate << multiplier;
+ avctx->frame_size = samples;
+ }
+
+ if (samples) {
+ /* get output buffer */
+ ac->frame.nb_samples = samples;
+ if ((err = avctx->get_buffer(avctx, &ac->frame)) < 0) {
+ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+ return err;
+ }
+
+ if (avctx->sample_fmt == AV_SAMPLE_FMT_FLT)
+ float_interleave((float *)ac->frame.data[0], (const float **)ac->output_data,
+ samples, avctx->channels);
+ else
+ ac->fmt_conv.float_to_int16_interleave((int16_t *)ac->frame.data[0],
+ (const float **)ac->output_data,
+ samples, avctx->channels);
+
+ *(AVFrame *)data = ac->frame;
+ }
+ *got_frame_ptr = !!samples;
+
+ if (ac->output_configured && audio_found)
+ ac->output_configured = OC_LOCKED;
+
+ return 0;
+}
+
+static int aac_decode_frame(AVCodecContext *avctx, void *data,
+ int *got_frame_ptr, AVPacket *avpkt)
+{
+ AACContext *ac = avctx->priv_data;
+ const uint8_t *buf = avpkt->data;
+ int buf_size = avpkt->size;
+ GetBitContext gb;
+ int buf_consumed;
+ int buf_offset;
+ int err;
+ int new_extradata_size;
+ const uint8_t *new_extradata = av_packet_get_side_data(avpkt,
+ AV_PKT_DATA_NEW_EXTRADATA,
+ &new_extradata_size);
+
+ if (new_extradata) {
+ av_free(avctx->extradata);
+ avctx->extradata = av_mallocz(new_extradata_size +
+ FF_INPUT_BUFFER_PADDING_SIZE);
+ if (!avctx->extradata)
+ return AVERROR(ENOMEM);
+ avctx->extradata_size = new_extradata_size;
+ memcpy(avctx->extradata, new_extradata, new_extradata_size);
+ if (decode_audio_specific_config(ac, ac->avctx, &ac->m4ac,
+ avctx->extradata,
+ avctx->extradata_size*8, 1) < 0)
+ return AVERROR_INVALIDDATA;
+ }
+
+ init_get_bits(&gb, buf, buf_size * 8);
+
+ if ((err = aac_decode_frame_int(avctx, data, got_frame_ptr, &gb)) < 0)
+ return err;
+
+ buf_consumed = (get_bits_count(&gb) + 7) >> 3;
+ for (buf_offset = buf_consumed; buf_offset < buf_size; buf_offset++)
+ if (buf[buf_offset])
+ break;
+
+ return buf_size > buf_offset ? buf_consumed : buf_size;
+}
+
+static av_cold int aac_decode_close(AVCodecContext *avctx)
+{
+ AACContext *ac = avctx->priv_data;
+ int i, type;
+
+ if (!avctx->extradata_size && ac->m4ac.object_type) {
+ PutBitContext pb;
+
+ avctx->extradata = av_mallocz(2);
+ avctx->extradata_size = 2;
+ init_put_bits(&pb, avctx->extradata, avctx->extradata_size);
+ put_bits(&pb, 5, ac->m4ac.object_type);
+ put_bits(&pb, 4, ac->m4ac.sampling_index);
+ put_bits(&pb, 4, ac->m4ac.chan_config);
+ put_bits(&pb, 1, 0); //frame length - 1024 samples
+ put_bits(&pb, 1, 0); //does not depend on core coder
+ put_bits(&pb, 1, 0); //is not extension
+ flush_put_bits(&pb);
+ }
+
+ for (i = 0; i < MAX_ELEM_ID; i++) {
+ for (type = 0; type < 4; type++) {
+ if (ac->che[type][i])
+ ff_aac_sbr_ctx_close(&ac->che[type][i]->sbr);
+ av_freep(&ac->che[type][i]);
+ }
+ }
+
+ ff_mdct_end(&ac->mdct);
+ ff_mdct_end(&ac->mdct_small);
+ ff_mdct_end(&ac->mdct_ltp);
+ return 0;
+}
+
+
+#define LOAS_SYNC_WORD 0x2b7 ///< 11 bits LOAS sync word
+
+struct LATMContext {
+ AACContext aac_ctx; ///< containing AACContext
+ int initialized; ///< initilized after a valid extradata was seen
+
+ // parser data
+ int audio_mux_version_A; ///< LATM syntax version
+ int frame_length_type; ///< 0/1 variable/fixed frame length
+ int frame_length; ///< frame length for fixed frame length
+};
+
+static inline uint32_t latm_get_value(GetBitContext *b)
+{
+ int length = get_bits(b, 2);
+
+ return get_bits_long(b, (length+1)*8);
+}
+
+static int latm_decode_audio_specific_config(struct LATMContext *latmctx,
+ GetBitContext *gb, int asclen)
+{
+ AACContext *ac = &latmctx->aac_ctx;
+ AVCodecContext *avctx = ac->avctx;
+ MPEG4AudioConfig m4ac = {0};
+ int config_start_bit = get_bits_count(gb);
+ int sync_extension = 0;
+ int bits_consumed, esize;
+
+ if (asclen) {
+ sync_extension = 1;
+ asclen = FFMIN(asclen, get_bits_left(gb));
+ } else
+ asclen = get_bits_left(gb);
+
+ if (config_start_bit % 8) {
+ av_log_missing_feature(latmctx->aac_ctx.avctx, "audio specific "
+ "config not byte aligned.\n", 1);
+ return AVERROR_INVALIDDATA;
+ }
+ if (asclen <= 0)
+ return AVERROR_INVALIDDATA;
+ bits_consumed = decode_audio_specific_config(NULL, avctx, &m4ac,
+ gb->buffer + (config_start_bit / 8),
+ asclen, sync_extension);
+
+ if (bits_consumed < 0)
+ return AVERROR_INVALIDDATA;
+
+ if (!latmctx->initialized ||
+ ac->m4ac.sample_rate != m4ac.sample_rate ||
+ ac->m4ac.chan_config != m4ac.chan_config) {
+
+ av_log(avctx, AV_LOG_INFO, "audio config changed\n");
+ latmctx->initialized = 0;
+
+ esize = (bits_consumed+7) / 8;
+
+ if (avctx->extradata_size < esize) {
+ av_free(avctx->extradata);
+ avctx->extradata = av_malloc(esize + FF_INPUT_BUFFER_PADDING_SIZE);
+ if (!avctx->extradata)
+ return AVERROR(ENOMEM);
+ }
+
+ avctx->extradata_size = esize;
+ memcpy(avctx->extradata, gb->buffer + (config_start_bit/8), esize);
+ memset(avctx->extradata+esize, 0, FF_INPUT_BUFFER_PADDING_SIZE);
+ }
+ skip_bits_long(gb, bits_consumed);
+
+ return bits_consumed;
+}
+
+static int read_stream_mux_config(struct LATMContext *latmctx,
+ GetBitContext *gb)
+{
+ int ret, audio_mux_version = get_bits(gb, 1);
+
+ latmctx->audio_mux_version_A = 0;
+ if (audio_mux_version)
+ latmctx->audio_mux_version_A = get_bits(gb, 1);
+
+ if (!latmctx->audio_mux_version_A) {
+
+ if (audio_mux_version)
+ latm_get_value(gb); // taraFullness
+
+ skip_bits(gb, 1); // allStreamSameTimeFraming
+ skip_bits(gb, 6); // numSubFrames
+ // numPrograms
+ if (get_bits(gb, 4)) { // numPrograms
+ av_log_missing_feature(latmctx->aac_ctx.avctx,
+ "multiple programs are not supported\n", 1);
+ return AVERROR_PATCHWELCOME;
+ }
+
+ // for each program (which there is only on in DVB)
+
+ // for each layer (which there is only on in DVB)
+ if (get_bits(gb, 3)) { // numLayer
+ av_log_missing_feature(latmctx->aac_ctx.avctx,
+ "multiple layers are not supported\n", 1);
+ return AVERROR_PATCHWELCOME;
+ }
+
+ // for all but first stream: use_same_config = get_bits(gb, 1);
+ if (!audio_mux_version) {
+ if ((ret = latm_decode_audio_specific_config(latmctx, gb, 0)) < 0)
+ return ret;
+ } else {
+ int ascLen = latm_get_value(gb);
+ if ((ret = latm_decode_audio_specific_config(latmctx, gb, ascLen)) < 0)
+ return ret;
+ ascLen -= ret;
+ skip_bits_long(gb, ascLen);
+ }
+
+ latmctx->frame_length_type = get_bits(gb, 3);
+ switch (latmctx->frame_length_type) {
+ case 0:
+ skip_bits(gb, 8); // latmBufferFullness
+ break;
+ case 1:
+ latmctx->frame_length = get_bits(gb, 9);
+ break;
+ case 3:
+ case 4:
+ case 5:
+ skip_bits(gb, 6); // CELP frame length table index
+ break;
+ case 6:
+ case 7:
+ skip_bits(gb, 1); // HVXC frame length table index
+ break;
+ }
+
+ if (get_bits(gb, 1)) { // other data
+ if (audio_mux_version) {
+ latm_get_value(gb); // other_data_bits
+ } else {
+ int esc;
+ do {
+ esc = get_bits(gb, 1);
+ skip_bits(gb, 8);
+ } while (esc);
+ }
+ }
+
+ if (get_bits(gb, 1)) // crc present
+ skip_bits(gb, 8); // config_crc
+ }
+
+ return 0;
+}
+
+static int read_payload_length_info(struct LATMContext *ctx, GetBitContext *gb)
+{
+ uint8_t tmp;
+
+ if (ctx->frame_length_type == 0) {
+ int mux_slot_length = 0;
+ do {
+ tmp = get_bits(gb, 8);
+ mux_slot_length += tmp;
+ } while (tmp == 255);
+ return mux_slot_length;
+ } else if (ctx->frame_length_type == 1) {
+ return ctx->frame_length;
+ } else if (ctx->frame_length_type == 3 ||
+ ctx->frame_length_type == 5 ||
+ ctx->frame_length_type == 7) {
+ skip_bits(gb, 2); // mux_slot_length_coded
+ }
+ return 0;
+}
+
+static int read_audio_mux_element(struct LATMContext *latmctx,
+ GetBitContext *gb)
+{
+ int err;
+ uint8_t use_same_mux = get_bits(gb, 1);
+ if (!use_same_mux) {
+ if ((err = read_stream_mux_config(latmctx, gb)) < 0)
+ return err;
+ } else if (!latmctx->aac_ctx.avctx->extradata) {
+ av_log(latmctx->aac_ctx.avctx, AV_LOG_DEBUG,
+ "no decoder config found\n");
+ return AVERROR(EAGAIN);
+ }
+ if (latmctx->audio_mux_version_A == 0) {
+ int mux_slot_length_bytes = read_payload_length_info(latmctx, gb);
+ if (mux_slot_length_bytes * 8 > get_bits_left(gb)) {
+ av_log(latmctx->aac_ctx.avctx, AV_LOG_ERROR, "incomplete frame\n");
+ return AVERROR_INVALIDDATA;
+ } else if (mux_slot_length_bytes * 8 + 256 < get_bits_left(gb)) {
+ av_log(latmctx->aac_ctx.avctx, AV_LOG_ERROR,
+ "frame length mismatch %d << %d\n",
+ mux_slot_length_bytes * 8, get_bits_left(gb));
+ return AVERROR_INVALIDDATA;
+ }
+ }
+ return 0;
+}
+
+
+static int latm_decode_frame(AVCodecContext *avctx, void *out,
+ int *got_frame_ptr, AVPacket *avpkt)
+{
+ struct LATMContext *latmctx = avctx->priv_data;
+ int muxlength, err;
+ GetBitContext gb;
+
+ init_get_bits(&gb, avpkt->data, avpkt->size * 8);
+
+ // check for LOAS sync word
+ if (get_bits(&gb, 11) != LOAS_SYNC_WORD)
+ return AVERROR_INVALIDDATA;
+
+ muxlength = get_bits(&gb, 13) + 3;
+ // not enough data, the parser should have sorted this
+ if (muxlength > avpkt->size)
+ return AVERROR_INVALIDDATA;
+
+ if ((err = read_audio_mux_element(latmctx, &gb)) < 0)
+ return err;
+
+ if (!latmctx->initialized) {
+ if (!avctx->extradata) {
+ *got_frame_ptr = 0;
+ return avpkt->size;
+ } else {
+ if ((err = decode_audio_specific_config(
+ &latmctx->aac_ctx, avctx, &latmctx->aac_ctx.m4ac,
+ avctx->extradata, avctx->extradata_size*8, 1)) < 0)
+ return err;
+ latmctx->initialized = 1;
+ }
+ }
+
+ if (show_bits(&gb, 12) == 0xfff) {
+ av_log(latmctx->aac_ctx.avctx, AV_LOG_ERROR,
+ "ADTS header detected, probably as result of configuration "
+ "misparsing\n");
+ return AVERROR_INVALIDDATA;
+ }
+
+ if ((err = aac_decode_frame_int(avctx, out, got_frame_ptr, &gb)) < 0)
+ return err;
+
+ return muxlength;
+}
+
+av_cold static int latm_decode_init(AVCodecContext *avctx)
+{
+ struct LATMContext *latmctx = avctx->priv_data;
+ int ret = aac_decode_init(avctx);
+
+ if (avctx->extradata_size > 0)
+ latmctx->initialized = !ret;
+
+ return ret;
+}
+
+
+AVCodec ff_aac_decoder = {
+ .name = "aac",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_AAC,
+ .priv_data_size = sizeof(AACContext),
+ .init = aac_decode_init,
+ .close = aac_decode_close,
+ .decode = aac_decode_frame,
+ .long_name = NULL_IF_CONFIG_SMALL("Advanced Audio Coding"),
+ .sample_fmts = (const enum AVSampleFormat[]) {
+ AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE
+ },
+ .capabilities = CODEC_CAP_CHANNEL_CONF | CODEC_CAP_DR1,
+ .channel_layouts = aac_channel_layout,
+};
+
+/*
+ Note: This decoder filter is intended to decode LATM streams transferred
+ in MPEG transport streams which only contain one program.
+ To do a more complex LATM demuxing a separate LATM demuxer should be used.
+*/
+AVCodec ff_aac_latm_decoder = {
+ .name = "aac_latm",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .id = CODEC_ID_AAC_LATM,
+ .priv_data_size = sizeof(struct LATMContext),
+ .init = latm_decode_init,
+ .close = aac_decode_close,
+ .decode = latm_decode_frame,
+ .long_name = NULL_IF_CONFIG_SMALL("AAC LATM (Advanced Audio Codec LATM syntax)"),
+ .sample_fmts = (const enum AVSampleFormat[]) {
+ AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE
+ },
+ .capabilities = CODEC_CAP_CHANNEL_CONF | CODEC_CAP_DR1,
+ .channel_layouts = aac_channel_layout,
+ .flush = flush,
+};
diff --git a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacdectab.h b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacdectab.h index 008326089..728a239a8 100644 --- a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacdectab.h +++ b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacdectab.h @@ -1,104 +1,104 @@ -/* - * AAC decoder data - * Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org ) - * Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com ) - * - * This file is part of FFmpeg. - * - * FFmpeg is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * FFmpeg is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/** - * @file - * AAC decoder data - * @author Oded Shimon ( ods15 ods15 dyndns org ) - * @author Maxim Gavrilov ( maxim.gavrilov gmail com ) - */ - -#ifndef AVCODEC_AACDECTAB_H -#define AVCODEC_AACDECTAB_H - -#include "libavutil/audioconvert.h" -#include "aac.h" - -#include <stdint.h> - -/* @name ltp_coef - * Table of the LTP coefficients - */ -static const float ltp_coef[8] = { - 0.570829, 0.696616, 0.813004, 0.911304, - 0.984900, 1.067894, 1.194601, 1.369533, -}; - -/* @name tns_tmp2_map - * Tables of the tmp2[] arrays of LPC coefficients used for TNS. - * The suffix _M_N[] indicate the values of coef_compress and coef_res - * respectively. - * @{ - */ -static const float tns_tmp2_map_1_3[4] = { - 0.00000000, -0.43388373, 0.64278758, 0.34202015, -}; - -static const float tns_tmp2_map_0_3[8] = { - 0.00000000, -0.43388373, -0.78183150, -0.97492790, - 0.98480773, 0.86602539, 0.64278758, 0.34202015, -}; - -static const float tns_tmp2_map_1_4[8] = { - 0.00000000, -0.20791170, -0.40673664, -0.58778524, - 0.67369562, 0.52643216, 0.36124167, 0.18374951, -}; - -static const float tns_tmp2_map_0_4[16] = { - 0.00000000, -0.20791170, -0.40673664, -0.58778524, - -0.74314481, -0.86602539, -0.95105654, -0.99452192, - 0.99573416, 0.96182561, 0.89516330, 0.79801720, - 0.67369562, 0.52643216, 0.36124167, 0.18374951, -}; - -static const float * const tns_tmp2_map[4] = { - tns_tmp2_map_0_3, - tns_tmp2_map_0_4, - tns_tmp2_map_1_3, - tns_tmp2_map_1_4 -}; -// @} - -static const int8_t tags_per_config[16] = { 0, 1, 1, 2, 3, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0 }; - -static const uint8_t aac_channel_layout_map[7][5][3] = { - { { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, }, - { { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, }, - { { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, }, - { { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, { TYPE_SCE, 1, AAC_CHANNEL_BACK }, }, - { { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 1, AAC_CHANNEL_BACK }, }, - { { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 1, AAC_CHANNEL_BACK }, { TYPE_LFE, 0, AAC_CHANNEL_LFE }, }, - { { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 1, AAC_CHANNEL_FRONT }, { TYPE_CPE, 2, AAC_CHANNEL_BACK }, { TYPE_LFE, 0, AAC_CHANNEL_LFE }, }, -}; - -static const uint64_t aac_channel_layout[8] = { - AV_CH_LAYOUT_MONO, - AV_CH_LAYOUT_STEREO, - AV_CH_LAYOUT_SURROUND, - AV_CH_LAYOUT_4POINT0, - AV_CH_LAYOUT_5POINT0_BACK, - AV_CH_LAYOUT_5POINT1_BACK, - AV_CH_LAYOUT_7POINT1_WIDE_BACK, - 0, -}; - -#endif /* AVCODEC_AACDECTAB_H */ +/*
+ * AAC decoder data
+ * Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org )
+ * Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com )
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * AAC decoder data
+ * @author Oded Shimon ( ods15 ods15 dyndns org )
+ * @author Maxim Gavrilov ( maxim.gavrilov gmail com )
+ */
+
+#ifndef AVCODEC_AACDECTAB_H
+#define AVCODEC_AACDECTAB_H
+
+#include "libavutil/audioconvert.h"
+#include "aac.h"
+
+#include <stdint.h>
+
+/* @name ltp_coef
+ * Table of the LTP coefficients
+ */
+static const float ltp_coef[8] = {
+ 0.570829, 0.696616, 0.813004, 0.911304,
+ 0.984900, 1.067894, 1.194601, 1.369533,
+};
+
+/* @name tns_tmp2_map
+ * Tables of the tmp2[] arrays of LPC coefficients used for TNS.
+ * The suffix _M_N[] indicate the values of coef_compress and coef_res
+ * respectively.
+ * @{
+ */
+static const float tns_tmp2_map_1_3[4] = {
+ 0.00000000, -0.43388373, 0.64278758, 0.34202015,
+};
+
+static const float tns_tmp2_map_0_3[8] = {
+ 0.00000000, -0.43388373, -0.78183150, -0.97492790,
+ 0.98480773, 0.86602539, 0.64278758, 0.34202015,
+};
+
+static const float tns_tmp2_map_1_4[8] = {
+ 0.00000000, -0.20791170, -0.40673664, -0.58778524,
+ 0.67369562, 0.52643216, 0.36124167, 0.18374951,
+};
+
+static const float tns_tmp2_map_0_4[16] = {
+ 0.00000000, -0.20791170, -0.40673664, -0.58778524,
+ -0.74314481, -0.86602539, -0.95105654, -0.99452192,
+ 0.99573416, 0.96182561, 0.89516330, 0.79801720,
+ 0.67369562, 0.52643216, 0.36124167, 0.18374951,
+};
+
+static const float * const tns_tmp2_map[4] = {
+ tns_tmp2_map_0_3,
+ tns_tmp2_map_0_4,
+ tns_tmp2_map_1_3,
+ tns_tmp2_map_1_4
+};
+// @}
+
+static const int8_t tags_per_config[16] = { 0, 1, 1, 2, 3, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0 };
+
+static const uint8_t aac_channel_layout_map[7][5][3] = {
+ { { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, },
+ { { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, },
+ { { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, },
+ { { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, { TYPE_SCE, 1, AAC_CHANNEL_BACK }, },
+ { { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 1, AAC_CHANNEL_BACK }, },
+ { { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 1, AAC_CHANNEL_BACK }, { TYPE_LFE, 0, AAC_CHANNEL_LFE }, },
+ { { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 1, AAC_CHANNEL_FRONT }, { TYPE_CPE, 2, AAC_CHANNEL_BACK }, { TYPE_LFE, 0, AAC_CHANNEL_LFE }, },
+};
+
+static const uint64_t aac_channel_layout[8] = {
+ AV_CH_LAYOUT_MONO,
+ AV_CH_LAYOUT_STEREO,
+ AV_CH_LAYOUT_SURROUND,
+ AV_CH_LAYOUT_4POINT0,
+ AV_CH_LAYOUT_5POINT0_BACK,
+ AV_CH_LAYOUT_5POINT1_BACK,
+ AV_CH_LAYOUT_7POINT1_WIDE_BACK,
+ 0,
+};
+
+#endif /* AVCODEC_AACDECTAB_H */
diff --git a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacps.c b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacps.c index 3da912c6c..77237a743 100644 --- a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacps.c +++ b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacps.c @@ -1,1040 +1,1040 @@ -/* - * MPEG-4 Parametric Stereo decoding functions - * Copyright (c) 2010 Alex Converse <alex.converse@gmail.com> - * - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include <stdint.h> -#include "libavutil/common.h" -#include "libavutil/mathematics.h" -#include "avcodec.h" -#include "get_bits.h" -#include "aacps.h" -#include "aacps_tablegen.h" -#include "aacpsdata.c" - -#define PS_BASELINE 0 ///< Operate in Baseline PS mode - ///< Baseline implies 10 or 20 stereo bands, - ///< mixing mode A, and no ipd/opd - -#define numQMFSlots 32 //numTimeSlots * RATE - -static const int8_t num_env_tab[2][4] = { - { 0, 1, 2, 4, }, - { 1, 2, 3, 4, }, -}; - -static const int8_t nr_iidicc_par_tab[] = { - 10, 20, 34, 10, 20, 34, -}; - -static const int8_t nr_iidopd_par_tab[] = { - 5, 11, 17, 5, 11, 17, -}; - -enum { - huff_iid_df1, - huff_iid_dt1, - huff_iid_df0, - huff_iid_dt0, - huff_icc_df, - huff_icc_dt, - huff_ipd_df, - huff_ipd_dt, - huff_opd_df, - huff_opd_dt, -}; - -static const int huff_iid[] = { - huff_iid_df0, - huff_iid_df1, - huff_iid_dt0, - huff_iid_dt1, -}; - -static VLC vlc_ps[10]; - -#define READ_PAR_DATA(PAR, OFFSET, MASK, ERR_CONDITION) \ -/** \ - * Read Inter-channel Intensity Difference/Inter-Channel Coherence/ \ - * Inter-channel Phase Difference/Overall Phase Difference parameters from the \ - * bitstream. \ - * \ - * @param avctx contains the current codec context \ - * @param gb pointer to the input bitstream \ - * @param ps pointer to the Parametric Stereo context \ - * @param PAR pointer to the parameter to be read \ - * @param e envelope to decode \ - * @param dt 1: time delta-coded, 0: frequency delta-coded \ - */ \ -static int read_ ## PAR ## _data(AVCodecContext *avctx, GetBitContext *gb, PSContext *ps, \ - int8_t (*PAR)[PS_MAX_NR_IIDICC], int table_idx, int e, int dt) \ -{ \ - int b, num = ps->nr_ ## PAR ## _par; \ - VLC_TYPE (*vlc_table)[2] = vlc_ps[table_idx].table; \ - if (dt) { \ - int e_prev = e ? e - 1 : ps->num_env_old - 1; \ - e_prev = FFMAX(e_prev, 0); \ - for (b = 0; b < num; b++) { \ - int val = PAR[e_prev][b] + get_vlc2(gb, vlc_table, 9, 3) - OFFSET; \ - if (MASK) val &= MASK; \ - PAR[e][b] = val; \ - if (ERR_CONDITION) \ - goto err; \ - } \ - } else { \ - int val = 0; \ - for (b = 0; b < num; b++) { \ - val += get_vlc2(gb, vlc_table, 9, 3) - OFFSET; \ - if (MASK) val &= MASK; \ - PAR[e][b] = val; \ - if (ERR_CONDITION) \ - goto err; \ - } \ - } \ - return 0; \ -err: \ - av_log(avctx, AV_LOG_ERROR, "illegal "#PAR"\n"); \ - return -1; \ -} - -READ_PAR_DATA(iid, huff_offset[table_idx], 0, FFABS(ps->iid_par[e][b]) > 7 + 8 * ps->iid_quant) -READ_PAR_DATA(icc, huff_offset[table_idx], 0, ps->icc_par[e][b] > 7U) -READ_PAR_DATA(ipdopd, 0, 0x07, 0) - -static int ps_read_extension_data(GetBitContext *gb, PSContext *ps, int ps_extension_id) -{ - int e; - int count = get_bits_count(gb); - - if (ps_extension_id) - return 0; - - ps->enable_ipdopd = get_bits1(gb); - if (ps->enable_ipdopd) { - for (e = 0; e < ps->num_env; e++) { - int dt = get_bits1(gb); - read_ipdopd_data(NULL, gb, ps, ps->ipd_par, dt ? huff_ipd_dt : huff_ipd_df, e, dt); - dt = get_bits1(gb); - read_ipdopd_data(NULL, gb, ps, ps->opd_par, dt ? huff_opd_dt : huff_opd_df, e, dt); - } - } - skip_bits1(gb); //reserved_ps - return get_bits_count(gb) - count; -} - -static void ipdopd_reset(int8_t *opd_hist, int8_t *ipd_hist) -{ - int i; - for (i = 0; i < PS_MAX_NR_IPDOPD; i++) { - opd_hist[i] = 0; - ipd_hist[i] = 0; - } -} - -int ff_ps_read_data(AVCodecContext *avctx, GetBitContext *gb_host, PSContext *ps, int bits_left) -{ - int e; - int bit_count_start = get_bits_count(gb_host); - int header; - int bits_consumed; - GetBitContext gbc = *gb_host, *gb = &gbc; - - header = get_bits1(gb); - if (header) { //enable_ps_header - ps->enable_iid = get_bits1(gb); - if (ps->enable_iid) { - int iid_mode = get_bits(gb, 3); - if (iid_mode > 5) { - av_log(avctx, AV_LOG_ERROR, "iid_mode %d is reserved.\n", - iid_mode); - goto err; - } - ps->nr_iid_par = nr_iidicc_par_tab[iid_mode]; - ps->iid_quant = iid_mode > 2; - ps->nr_ipdopd_par = nr_iidopd_par_tab[iid_mode]; - } - ps->enable_icc = get_bits1(gb); - if (ps->enable_icc) { - ps->icc_mode = get_bits(gb, 3); - if (ps->icc_mode > 5) { - av_log(avctx, AV_LOG_ERROR, "icc_mode %d is reserved.\n", - ps->icc_mode); - goto err; - } - ps->nr_icc_par = nr_iidicc_par_tab[ps->icc_mode]; - } - ps->enable_ext = get_bits1(gb); - } - - ps->frame_class = get_bits1(gb); - ps->num_env_old = ps->num_env; - ps->num_env = num_env_tab[ps->frame_class][get_bits(gb, 2)]; - - ps->border_position[0] = -1; - if (ps->frame_class) { - for (e = 1; e <= ps->num_env; e++) - ps->border_position[e] = get_bits(gb, 5); - } else - for (e = 1; e <= ps->num_env; e++) - ps->border_position[e] = (e * numQMFSlots >> ff_log2_tab[ps->num_env]) - 1; - - if (ps->enable_iid) { - for (e = 0; e < ps->num_env; e++) { - int dt = get_bits1(gb); - if (read_iid_data(avctx, gb, ps, ps->iid_par, huff_iid[2*dt+ps->iid_quant], e, dt)) - goto err; - } - } else - memset(ps->iid_par, 0, sizeof(ps->iid_par)); - - if (ps->enable_icc) - for (e = 0; e < ps->num_env; e++) { - int dt = get_bits1(gb); - if (read_icc_data(avctx, gb, ps, ps->icc_par, dt ? huff_icc_dt : huff_icc_df, e, dt)) - goto err; - } - else - memset(ps->icc_par, 0, sizeof(ps->icc_par)); - - if (ps->enable_ext) { - int cnt = get_bits(gb, 4); - if (cnt == 15) { - cnt += get_bits(gb, 8); - } - cnt *= 8; - while (cnt > 7) { - int ps_extension_id = get_bits(gb, 2); - cnt -= 2 + ps_read_extension_data(gb, ps, ps_extension_id); - } - if (cnt < 0) { - av_log(avctx, AV_LOG_ERROR, "ps extension overflow %d\n", cnt); - goto err; - } - skip_bits(gb, cnt); - } - - ps->enable_ipdopd &= !PS_BASELINE; - - //Fix up envelopes - if (!ps->num_env || ps->border_position[ps->num_env] < numQMFSlots - 1) { - //Create a fake envelope - int source = ps->num_env ? ps->num_env - 1 : ps->num_env_old - 1; - if (source >= 0 && source != ps->num_env) { - if (ps->enable_iid) { - memcpy(ps->iid_par+ps->num_env, ps->iid_par+source, sizeof(ps->iid_par[0])); - } - if (ps->enable_icc) { - memcpy(ps->icc_par+ps->num_env, ps->icc_par+source, sizeof(ps->icc_par[0])); - } - if (ps->enable_ipdopd) { - memcpy(ps->ipd_par+ps->num_env, ps->ipd_par+source, sizeof(ps->ipd_par[0])); - memcpy(ps->opd_par+ps->num_env, ps->opd_par+source, sizeof(ps->opd_par[0])); - } - } - ps->num_env++; - ps->border_position[ps->num_env] = numQMFSlots - 1; - } - - - ps->is34bands_old = ps->is34bands; - if (!PS_BASELINE && (ps->enable_iid || ps->enable_icc)) - ps->is34bands = (ps->enable_iid && ps->nr_iid_par == 34) || - (ps->enable_icc && ps->nr_icc_par == 34); - - //Baseline - if (!ps->enable_ipdopd) { - memset(ps->ipd_par, 0, sizeof(ps->ipd_par)); - memset(ps->opd_par, 0, sizeof(ps->opd_par)); - } - - if (header) - ps->start = 1; - - bits_consumed = get_bits_count(gb) - bit_count_start; - if (bits_consumed <= bits_left) { - skip_bits_long(gb_host, bits_consumed); - return bits_consumed; - } - av_log(avctx, AV_LOG_ERROR, "Expected to read %d PS bits actually read %d.\n", bits_left, bits_consumed); -err: - ps->start = 0; - skip_bits_long(gb_host, bits_left); - return bits_left; -} - -/** Split one subband into 2 subsubbands with a symmetric real filter. - * The filter must have its non-center even coefficients equal to zero. */ -static void hybrid2_re(float (*in)[2], float (*out)[32][2], const float filter[7], int len, int reverse) -{ - int i, j; - for (i = 0; i < len; i++, in++) { - float re_in = filter[6] * in[6][0]; //real inphase - float re_op = 0.0f; //real out of phase - float im_in = filter[6] * in[6][1]; //imag inphase - float im_op = 0.0f; //imag out of phase - for (j = 0; j < 6; j += 2) { - re_op += filter[j+1] * (in[j+1][0] + in[12-j-1][0]); - im_op += filter[j+1] * (in[j+1][1] + in[12-j-1][1]); - } - out[ reverse][i][0] = re_in + re_op; - out[ reverse][i][1] = im_in + im_op; - out[!reverse][i][0] = re_in - re_op; - out[!reverse][i][1] = im_in - im_op; - } -} - -/** Split one subband into 6 subsubbands with a complex filter */ -static void hybrid6_cx(float (*in)[2], float (*out)[32][2], const float (*filter)[7][2], int len) -{ - int i, j, ssb; - int N = 8; - float temp[8][2]; - - for (i = 0; i < len; i++, in++) { - for (ssb = 0; ssb < N; ssb++) { - float sum_re = filter[ssb][6][0] * in[6][0], sum_im = filter[ssb][6][0] * in[6][1]; - for (j = 0; j < 6; j++) { - float in0_re = in[j][0]; - float in0_im = in[j][1]; - float in1_re = in[12-j][0]; - float in1_im = in[12-j][1]; - sum_re += filter[ssb][j][0] * (in0_re + in1_re) - filter[ssb][j][1] * (in0_im - in1_im); - sum_im += filter[ssb][j][0] * (in0_im + in1_im) + filter[ssb][j][1] * (in0_re - in1_re); - } - temp[ssb][0] = sum_re; - temp[ssb][1] = sum_im; - } - out[0][i][0] = temp[6][0]; - out[0][i][1] = temp[6][1]; - out[1][i][0] = temp[7][0]; - out[1][i][1] = temp[7][1]; - out[2][i][0] = temp[0][0]; - out[2][i][1] = temp[0][1]; - out[3][i][0] = temp[1][0]; - out[3][i][1] = temp[1][1]; - out[4][i][0] = temp[2][0] + temp[5][0]; - out[4][i][1] = temp[2][1] + temp[5][1]; - out[5][i][0] = temp[3][0] + temp[4][0]; - out[5][i][1] = temp[3][1] + temp[4][1]; - } -} - -static void hybrid4_8_12_cx(float (*in)[2], float (*out)[32][2], const float (*filter)[7][2], int N, int len) -{ - int i, j, ssb; - - for (i = 0; i < len; i++, in++) { - for (ssb = 0; ssb < N; ssb++) { - float sum_re = filter[ssb][6][0] * in[6][0], sum_im = filter[ssb][6][0] * in[6][1]; - for (j = 0; j < 6; j++) { - float in0_re = in[j][0]; - float in0_im = in[j][1]; - float in1_re = in[12-j][0]; - float in1_im = in[12-j][1]; - sum_re += filter[ssb][j][0] * (in0_re + in1_re) - filter[ssb][j][1] * (in0_im - in1_im); - sum_im += filter[ssb][j][0] * (in0_im + in1_im) + filter[ssb][j][1] * (in0_re - in1_re); - } - out[ssb][i][0] = sum_re; - out[ssb][i][1] = sum_im; - } - } -} - -static void hybrid_analysis(float out[91][32][2], float in[5][44][2], float L[2][38][64], int is34, int len) -{ - int i, j; - for (i = 0; i < 5; i++) { - for (j = 0; j < 38; j++) { - in[i][j+6][0] = L[0][j][i]; - in[i][j+6][1] = L[1][j][i]; - } - } - if (is34) { - hybrid4_8_12_cx(in[0], out, f34_0_12, 12, len); - hybrid4_8_12_cx(in[1], out+12, f34_1_8, 8, len); - hybrid4_8_12_cx(in[2], out+20, f34_2_4, 4, len); - hybrid4_8_12_cx(in[3], out+24, f34_2_4, 4, len); - hybrid4_8_12_cx(in[4], out+28, f34_2_4, 4, len); - for (i = 0; i < 59; i++) { - for (j = 0; j < len; j++) { - out[i+32][j][0] = L[0][j][i+5]; - out[i+32][j][1] = L[1][j][i+5]; - } - } - } else { - hybrid6_cx(in[0], out, f20_0_8, len); - hybrid2_re(in[1], out+6, g1_Q2, len, 1); - hybrid2_re(in[2], out+8, g1_Q2, len, 0); - for (i = 0; i < 61; i++) { - for (j = 0; j < len; j++) { - out[i+10][j][0] = L[0][j][i+3]; - out[i+10][j][1] = L[1][j][i+3]; - } - } - } - //update in_buf - for (i = 0; i < 5; i++) { - memcpy(in[i], in[i]+32, 6 * sizeof(in[i][0])); - } -} - -static void hybrid_synthesis(float out[2][38][64], float in[91][32][2], int is34, int len) -{ - int i, n; - if (is34) { - for (n = 0; n < len; n++) { - memset(out[0][n], 0, 5*sizeof(out[0][n][0])); - memset(out[1][n], 0, 5*sizeof(out[1][n][0])); - for (i = 0; i < 12; i++) { - out[0][n][0] += in[ i][n][0]; - out[1][n][0] += in[ i][n][1]; - } - for (i = 0; i < 8; i++) { - out[0][n][1] += in[12+i][n][0]; - out[1][n][1] += in[12+i][n][1]; - } - for (i = 0; i < 4; i++) { - out[0][n][2] += in[20+i][n][0]; - out[1][n][2] += in[20+i][n][1]; - out[0][n][3] += in[24+i][n][0]; - out[1][n][3] += in[24+i][n][1]; - out[0][n][4] += in[28+i][n][0]; - out[1][n][4] += in[28+i][n][1]; - } - } - for (i = 0; i < 59; i++) { - for (n = 0; n < len; n++) { - out[0][n][i+5] = in[i+32][n][0]; - out[1][n][i+5] = in[i+32][n][1]; - } - } - } else { - for (n = 0; n < len; n++) { - out[0][n][0] = in[0][n][0] + in[1][n][0] + in[2][n][0] + - in[3][n][0] + in[4][n][0] + in[5][n][0]; - out[1][n][0] = in[0][n][1] + in[1][n][1] + in[2][n][1] + - in[3][n][1] + in[4][n][1] + in[5][n][1]; - out[0][n][1] = in[6][n][0] + in[7][n][0]; - out[1][n][1] = in[6][n][1] + in[7][n][1]; - out[0][n][2] = in[8][n][0] + in[9][n][0]; - out[1][n][2] = in[8][n][1] + in[9][n][1]; - } - for (i = 0; i < 61; i++) { - for (n = 0; n < len; n++) { - out[0][n][i+3] = in[i+10][n][0]; - out[1][n][i+3] = in[i+10][n][1]; - } - } - } -} - -/// All-pass filter decay slope -#define DECAY_SLOPE 0.05f -/// Number of frequency bands that can be addressed by the parameter index, b(k) -static const int NR_PAR_BANDS[] = { 20, 34 }; -/// Number of frequency bands that can be addressed by the sub subband index, k -static const int NR_BANDS[] = { 71, 91 }; -/// Start frequency band for the all-pass filter decay slope -static const int DECAY_CUTOFF[] = { 10, 32 }; -/// Number of all-pass filer bands -static const int NR_ALLPASS_BANDS[] = { 30, 50 }; -/// First stereo band using the short one sample delay -static const int SHORT_DELAY_BAND[] = { 42, 62 }; - -/** Table 8.46 */ -static void map_idx_10_to_20(int8_t *par_mapped, const int8_t *par, int full) -{ - int b; - if (full) - b = 9; - else { - b = 4; - par_mapped[10] = 0; - } - for (; b >= 0; b--) { - par_mapped[2*b+1] = par_mapped[2*b] = par[b]; - } -} - -static void map_idx_34_to_20(int8_t *par_mapped, const int8_t *par, int full) -{ - par_mapped[ 0] = (2*par[ 0] + par[ 1]) / 3; - par_mapped[ 1] = ( par[ 1] + 2*par[ 2]) / 3; - par_mapped[ 2] = (2*par[ 3] + par[ 4]) / 3; - par_mapped[ 3] = ( par[ 4] + 2*par[ 5]) / 3; - par_mapped[ 4] = ( par[ 6] + par[ 7]) / 2; - par_mapped[ 5] = ( par[ 8] + par[ 9]) / 2; - par_mapped[ 6] = par[10]; - par_mapped[ 7] = par[11]; - par_mapped[ 8] = ( par[12] + par[13]) / 2; - par_mapped[ 9] = ( par[14] + par[15]) / 2; - par_mapped[10] = par[16]; - if (full) { - par_mapped[11] = par[17]; - par_mapped[12] = par[18]; - par_mapped[13] = par[19]; - par_mapped[14] = ( par[20] + par[21]) / 2; - par_mapped[15] = ( par[22] + par[23]) / 2; - par_mapped[16] = ( par[24] + par[25]) / 2; - par_mapped[17] = ( par[26] + par[27]) / 2; - par_mapped[18] = ( par[28] + par[29] + par[30] + par[31]) / 4; - par_mapped[19] = ( par[32] + par[33]) / 2; - } -} - -static void map_val_34_to_20(float par[PS_MAX_NR_IIDICC]) -{ - par[ 0] = (2*par[ 0] + par[ 1]) * 0.33333333f; - par[ 1] = ( par[ 1] + 2*par[ 2]) * 0.33333333f; - par[ 2] = (2*par[ 3] + par[ 4]) * 0.33333333f; - par[ 3] = ( par[ 4] + 2*par[ 5]) * 0.33333333f; - par[ 4] = ( par[ 6] + par[ 7]) * 0.5f; - par[ 5] = ( par[ 8] + par[ 9]) * 0.5f; - par[ 6] = par[10]; - par[ 7] = par[11]; - par[ 8] = ( par[12] + par[13]) * 0.5f; - par[ 9] = ( par[14] + par[15]) * 0.5f; - par[10] = par[16]; - par[11] = par[17]; - par[12] = par[18]; - par[13] = par[19]; - par[14] = ( par[20] + par[21]) * 0.5f; - par[15] = ( par[22] + par[23]) * 0.5f; - par[16] = ( par[24] + par[25]) * 0.5f; - par[17] = ( par[26] + par[27]) * 0.5f; - par[18] = ( par[28] + par[29] + par[30] + par[31]) * 0.25f; - par[19] = ( par[32] + par[33]) * 0.5f; -} - -static void map_idx_10_to_34(int8_t *par_mapped, const int8_t *par, int full) -{ - if (full) { - par_mapped[33] = par[9]; - par_mapped[32] = par[9]; - par_mapped[31] = par[9]; - par_mapped[30] = par[9]; - par_mapped[29] = par[9]; - par_mapped[28] = par[9]; - par_mapped[27] = par[8]; - par_mapped[26] = par[8]; - par_mapped[25] = par[8]; - par_mapped[24] = par[8]; - par_mapped[23] = par[7]; - par_mapped[22] = par[7]; - par_mapped[21] = par[7]; - par_mapped[20] = par[7]; - par_mapped[19] = par[6]; - par_mapped[18] = par[6]; - par_mapped[17] = par[5]; - par_mapped[16] = par[5]; - } else { - par_mapped[16] = 0; - } - par_mapped[15] = par[4]; - par_mapped[14] = par[4]; - par_mapped[13] = par[4]; - par_mapped[12] = par[4]; - par_mapped[11] = par[3]; - par_mapped[10] = par[3]; - par_mapped[ 9] = par[2]; - par_mapped[ 8] = par[2]; - par_mapped[ 7] = par[2]; - par_mapped[ 6] = par[2]; - par_mapped[ 5] = par[1]; - par_mapped[ 4] = par[1]; - par_mapped[ 3] = par[1]; - par_mapped[ 2] = par[0]; - par_mapped[ 1] = par[0]; - par_mapped[ 0] = par[0]; -} - -static void map_idx_20_to_34(int8_t *par_mapped, const int8_t *par, int full) -{ - if (full) { - par_mapped[33] = par[19]; - par_mapped[32] = par[19]; - par_mapped[31] = par[18]; - par_mapped[30] = par[18]; - par_mapped[29] = par[18]; - par_mapped[28] = par[18]; - par_mapped[27] = par[17]; - par_mapped[26] = par[17]; - par_mapped[25] = par[16]; - par_mapped[24] = par[16]; - par_mapped[23] = par[15]; - par_mapped[22] = par[15]; - par_mapped[21] = par[14]; - par_mapped[20] = par[14]; - par_mapped[19] = par[13]; - par_mapped[18] = par[12]; - par_mapped[17] = par[11]; - } - par_mapped[16] = par[10]; - par_mapped[15] = par[ 9]; - par_mapped[14] = par[ 9]; - par_mapped[13] = par[ 8]; - par_mapped[12] = par[ 8]; - par_mapped[11] = par[ 7]; - par_mapped[10] = par[ 6]; - par_mapped[ 9] = par[ 5]; - par_mapped[ 8] = par[ 5]; - par_mapped[ 7] = par[ 4]; - par_mapped[ 6] = par[ 4]; - par_mapped[ 5] = par[ 3]; - par_mapped[ 4] = (par[ 2] + par[ 3]) / 2; - par_mapped[ 3] = par[ 2]; - par_mapped[ 2] = par[ 1]; - par_mapped[ 1] = (par[ 0] + par[ 1]) / 2; - par_mapped[ 0] = par[ 0]; -} - -static void map_val_20_to_34(float par[PS_MAX_NR_IIDICC]) -{ - par[33] = par[19]; - par[32] = par[19]; - par[31] = par[18]; - par[30] = par[18]; - par[29] = par[18]; - par[28] = par[18]; - par[27] = par[17]; - par[26] = par[17]; - par[25] = par[16]; - par[24] = par[16]; - par[23] = par[15]; - par[22] = par[15]; - par[21] = par[14]; - par[20] = par[14]; - par[19] = par[13]; - par[18] = par[12]; - par[17] = par[11]; - par[16] = par[10]; - par[15] = par[ 9]; - par[14] = par[ 9]; - par[13] = par[ 8]; - par[12] = par[ 8]; - par[11] = par[ 7]; - par[10] = par[ 6]; - par[ 9] = par[ 5]; - par[ 8] = par[ 5]; - par[ 7] = par[ 4]; - par[ 6] = par[ 4]; - par[ 5] = par[ 3]; - par[ 4] = (par[ 2] + par[ 3]) * 0.5f; - par[ 3] = par[ 2]; - par[ 2] = par[ 1]; - par[ 1] = (par[ 0] + par[ 1]) * 0.5f; - par[ 0] = par[ 0]; -} - -static void decorrelation(PSContext *ps, float (*out)[32][2], const float (*s)[32][2], int is34) -{ - float power[34][PS_QMF_TIME_SLOTS] = {{0}}; - float transient_gain[34][PS_QMF_TIME_SLOTS]; - float *peak_decay_nrg = ps->peak_decay_nrg; - float *power_smooth = ps->power_smooth; - float *peak_decay_diff_smooth = ps->peak_decay_diff_smooth; - float (*delay)[PS_QMF_TIME_SLOTS + PS_MAX_DELAY][2] = ps->delay; - float (*ap_delay)[PS_AP_LINKS][PS_QMF_TIME_SLOTS + PS_MAX_AP_DELAY][2] = ps->ap_delay; - const int8_t *k_to_i = is34 ? k_to_i_34 : k_to_i_20; - const float peak_decay_factor = 0.76592833836465f; - const float transient_impact = 1.5f; - const float a_smooth = 0.25f; ///< Smoothing coefficient - int i, k, m, n; - int n0 = 0, nL = 32; - static const int link_delay[] = { 3, 4, 5 }; - static const float a[] = { 0.65143905753106f, - 0.56471812200776f, - 0.48954165955695f }; - - if (is34 != ps->is34bands_old) { - memset(ps->peak_decay_nrg, 0, sizeof(ps->peak_decay_nrg)); - memset(ps->power_smooth, 0, sizeof(ps->power_smooth)); - memset(ps->peak_decay_diff_smooth, 0, sizeof(ps->peak_decay_diff_smooth)); - memset(ps->delay, 0, sizeof(ps->delay)); - memset(ps->ap_delay, 0, sizeof(ps->ap_delay)); - } - - for (n = n0; n < nL; n++) { - for (k = 0; k < NR_BANDS[is34]; k++) { - int i = k_to_i[k]; - power[i][n] += s[k][n][0] * s[k][n][0] + s[k][n][1] * s[k][n][1]; - } - } - - //Transient detection - for (i = 0; i < NR_PAR_BANDS[is34]; i++) { - for (n = n0; n < nL; n++) { - float decayed_peak = peak_decay_factor * peak_decay_nrg[i]; - float denom; - peak_decay_nrg[i] = FFMAX(decayed_peak, power[i][n]); - power_smooth[i] += a_smooth * (power[i][n] - power_smooth[i]); - peak_decay_diff_smooth[i] += a_smooth * (peak_decay_nrg[i] - power[i][n] - peak_decay_diff_smooth[i]); - denom = transient_impact * peak_decay_diff_smooth[i]; - transient_gain[i][n] = (denom > power_smooth[i]) ? - power_smooth[i] / denom : 1.0f; - } - } - - //Decorrelation and transient reduction - // PS_AP_LINKS - 1 - // ----- - // | | Q_fract_allpass[k][m]*z^-link_delay[m] - a[m]*g_decay_slope[k] - //H[k][z] = z^-2 * phi_fract[k] * | | ---------------------------------------------------------------- - // | | 1 - a[m]*g_decay_slope[k]*Q_fract_allpass[k][m]*z^-link_delay[m] - // m = 0 - //d[k][z] (out) = transient_gain_mapped[k][z] * H[k][z] * s[k][z] - for (k = 0; k < NR_ALLPASS_BANDS[is34]; k++) { - int b = k_to_i[k]; - float g_decay_slope = 1.f - DECAY_SLOPE * (k - DECAY_CUTOFF[is34]); - float ag[PS_AP_LINKS]; - g_decay_slope = av_clipf(g_decay_slope, 0.f, 1.f); - memcpy(delay[k], delay[k]+nL, PS_MAX_DELAY*sizeof(delay[k][0])); - memcpy(delay[k]+PS_MAX_DELAY, s[k], numQMFSlots*sizeof(delay[k][0])); - for (m = 0; m < PS_AP_LINKS; m++) { - memcpy(ap_delay[k][m], ap_delay[k][m]+numQMFSlots, 5*sizeof(ap_delay[k][m][0])); - ag[m] = a[m] * g_decay_slope; - } - for (n = n0; n < nL; n++) { - float in_re = delay[k][n+PS_MAX_DELAY-2][0] * phi_fract[is34][k][0] - - delay[k][n+PS_MAX_DELAY-2][1] * phi_fract[is34][k][1]; - float in_im = delay[k][n+PS_MAX_DELAY-2][0] * phi_fract[is34][k][1] + - delay[k][n+PS_MAX_DELAY-2][1] * phi_fract[is34][k][0]; - for (m = 0; m < PS_AP_LINKS; m++) { - float a_re = ag[m] * in_re; - float a_im = ag[m] * in_im; - float link_delay_re = ap_delay[k][m][n+5-link_delay[m]][0]; - float link_delay_im = ap_delay[k][m][n+5-link_delay[m]][1]; - float fractional_delay_re = Q_fract_allpass[is34][k][m][0]; - float fractional_delay_im = Q_fract_allpass[is34][k][m][1]; - ap_delay[k][m][n+5][0] = in_re; - ap_delay[k][m][n+5][1] = in_im; - in_re = link_delay_re * fractional_delay_re - link_delay_im * fractional_delay_im - a_re; - in_im = link_delay_re * fractional_delay_im + link_delay_im * fractional_delay_re - a_im; - ap_delay[k][m][n+5][0] += ag[m] * in_re; - ap_delay[k][m][n+5][1] += ag[m] * in_im; - } - out[k][n][0] = transient_gain[b][n] * in_re; - out[k][n][1] = transient_gain[b][n] * in_im; - } - } - for (; k < SHORT_DELAY_BAND[is34]; k++) { - memcpy(delay[k], delay[k]+nL, PS_MAX_DELAY*sizeof(delay[k][0])); - memcpy(delay[k]+PS_MAX_DELAY, s[k], numQMFSlots*sizeof(delay[k][0])); - for (n = n0; n < nL; n++) { - //H = delay 14 - out[k][n][0] = transient_gain[k_to_i[k]][n] * delay[k][n+PS_MAX_DELAY-14][0]; - out[k][n][1] = transient_gain[k_to_i[k]][n] * delay[k][n+PS_MAX_DELAY-14][1]; - } - } - for (; k < NR_BANDS[is34]; k++) { - memcpy(delay[k], delay[k]+nL, PS_MAX_DELAY*sizeof(delay[k][0])); - memcpy(delay[k]+PS_MAX_DELAY, s[k], numQMFSlots*sizeof(delay[k][0])); - for (n = n0; n < nL; n++) { - //H = delay 1 - out[k][n][0] = transient_gain[k_to_i[k]][n] * delay[k][n+PS_MAX_DELAY-1][0]; - out[k][n][1] = transient_gain[k_to_i[k]][n] * delay[k][n+PS_MAX_DELAY-1][1]; - } - } -} - -static void remap34(int8_t (**p_par_mapped)[PS_MAX_NR_IIDICC], - int8_t (*par)[PS_MAX_NR_IIDICC], - int num_par, int num_env, int full) -{ - int8_t (*par_mapped)[PS_MAX_NR_IIDICC] = *p_par_mapped; - int e; - if (num_par == 20 || num_par == 11) { - for (e = 0; e < num_env; e++) { - map_idx_20_to_34(par_mapped[e], par[e], full); - } - } else if (num_par == 10 || num_par == 5) { - for (e = 0; e < num_env; e++) { - map_idx_10_to_34(par_mapped[e], par[e], full); - } - } else { - *p_par_mapped = par; - } -} - -static void remap20(int8_t (**p_par_mapped)[PS_MAX_NR_IIDICC], - int8_t (*par)[PS_MAX_NR_IIDICC], - int num_par, int num_env, int full) -{ - int8_t (*par_mapped)[PS_MAX_NR_IIDICC] = *p_par_mapped; - int e; - if (num_par == 34 || num_par == 17) { - for (e = 0; e < num_env; e++) { - map_idx_34_to_20(par_mapped[e], par[e], full); - } - } else if (num_par == 10 || num_par == 5) { - for (e = 0; e < num_env; e++) { - map_idx_10_to_20(par_mapped[e], par[e], full); - } - } else { - *p_par_mapped = par; - } -} - -static void stereo_processing(PSContext *ps, float (*l)[32][2], float (*r)[32][2], int is34) -{ - int e, b, k, n; - - float (*H11)[PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC] = ps->H11; - float (*H12)[PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC] = ps->H12; - float (*H21)[PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC] = ps->H21; - float (*H22)[PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC] = ps->H22; - int8_t *opd_hist = ps->opd_hist; - int8_t *ipd_hist = ps->ipd_hist; - int8_t iid_mapped_buf[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; - int8_t icc_mapped_buf[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; - int8_t ipd_mapped_buf[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; - int8_t opd_mapped_buf[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; - int8_t (*iid_mapped)[PS_MAX_NR_IIDICC] = iid_mapped_buf; - int8_t (*icc_mapped)[PS_MAX_NR_IIDICC] = icc_mapped_buf; - int8_t (*ipd_mapped)[PS_MAX_NR_IIDICC] = ipd_mapped_buf; - int8_t (*opd_mapped)[PS_MAX_NR_IIDICC] = opd_mapped_buf; - const int8_t *k_to_i = is34 ? k_to_i_34 : k_to_i_20; - const float (*H_LUT)[8][4] = (PS_BASELINE || ps->icc_mode < 3) ? HA : HB; - - //Remapping - if (ps->num_env_old) { - memcpy(H11[0][0], H11[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H11[0][0][0])); - memcpy(H11[1][0], H11[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H11[1][0][0])); - memcpy(H12[0][0], H12[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H12[0][0][0])); - memcpy(H12[1][0], H12[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H12[1][0][0])); - memcpy(H21[0][0], H21[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H21[0][0][0])); - memcpy(H21[1][0], H21[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H21[1][0][0])); - memcpy(H22[0][0], H22[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H22[0][0][0])); - memcpy(H22[1][0], H22[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H22[1][0][0])); - } - - if (is34) { - remap34(&iid_mapped, ps->iid_par, ps->nr_iid_par, ps->num_env, 1); - remap34(&icc_mapped, ps->icc_par, ps->nr_icc_par, ps->num_env, 1); - if (ps->enable_ipdopd) { - remap34(&ipd_mapped, ps->ipd_par, ps->nr_ipdopd_par, ps->num_env, 0); - remap34(&opd_mapped, ps->opd_par, ps->nr_ipdopd_par, ps->num_env, 0); - } - if (!ps->is34bands_old) { - map_val_20_to_34(H11[0][0]); - map_val_20_to_34(H11[1][0]); - map_val_20_to_34(H12[0][0]); - map_val_20_to_34(H12[1][0]); - map_val_20_to_34(H21[0][0]); - map_val_20_to_34(H21[1][0]); - map_val_20_to_34(H22[0][0]); - map_val_20_to_34(H22[1][0]); - ipdopd_reset(ipd_hist, opd_hist); - } - } else { - remap20(&iid_mapped, ps->iid_par, ps->nr_iid_par, ps->num_env, 1); - remap20(&icc_mapped, ps->icc_par, ps->nr_icc_par, ps->num_env, 1); - if (ps->enable_ipdopd) { - remap20(&ipd_mapped, ps->ipd_par, ps->nr_ipdopd_par, ps->num_env, 0); - remap20(&opd_mapped, ps->opd_par, ps->nr_ipdopd_par, ps->num_env, 0); - } - if (ps->is34bands_old) { - map_val_34_to_20(H11[0][0]); - map_val_34_to_20(H11[1][0]); - map_val_34_to_20(H12[0][0]); - map_val_34_to_20(H12[1][0]); - map_val_34_to_20(H21[0][0]); - map_val_34_to_20(H21[1][0]); - map_val_34_to_20(H22[0][0]); - map_val_34_to_20(H22[1][0]); - ipdopd_reset(ipd_hist, opd_hist); - } - } - - //Mixing - for (e = 0; e < ps->num_env; e++) { - for (b = 0; b < NR_PAR_BANDS[is34]; b++) { - float h11, h12, h21, h22; - h11 = H_LUT[iid_mapped[e][b] + 7 + 23 * ps->iid_quant][icc_mapped[e][b]][0]; - h12 = H_LUT[iid_mapped[e][b] + 7 + 23 * ps->iid_quant][icc_mapped[e][b]][1]; - h21 = H_LUT[iid_mapped[e][b] + 7 + 23 * ps->iid_quant][icc_mapped[e][b]][2]; - h22 = H_LUT[iid_mapped[e][b] + 7 + 23 * ps->iid_quant][icc_mapped[e][b]][3]; - if (!PS_BASELINE && ps->enable_ipdopd && b < ps->nr_ipdopd_par) { - //The spec say says to only run this smoother when enable_ipdopd - //is set but the reference decoder appears to run it constantly - float h11i, h12i, h21i, h22i; - float ipd_adj_re, ipd_adj_im; - int opd_idx = opd_hist[b] * 8 + opd_mapped[e][b]; - int ipd_idx = ipd_hist[b] * 8 + ipd_mapped[e][b]; - float opd_re = pd_re_smooth[opd_idx]; - float opd_im = pd_im_smooth[opd_idx]; - float ipd_re = pd_re_smooth[ipd_idx]; - float ipd_im = pd_im_smooth[ipd_idx]; - opd_hist[b] = opd_idx & 0x3F; - ipd_hist[b] = ipd_idx & 0x3F; - - ipd_adj_re = opd_re*ipd_re + opd_im*ipd_im; - ipd_adj_im = opd_im*ipd_re - opd_re*ipd_im; - h11i = h11 * opd_im; - h11 = h11 * opd_re; - h12i = h12 * ipd_adj_im; - h12 = h12 * ipd_adj_re; - h21i = h21 * opd_im; - h21 = h21 * opd_re; - h22i = h22 * ipd_adj_im; - h22 = h22 * ipd_adj_re; - H11[1][e+1][b] = h11i; - H12[1][e+1][b] = h12i; - H21[1][e+1][b] = h21i; - H22[1][e+1][b] = h22i; - } - H11[0][e+1][b] = h11; - H12[0][e+1][b] = h12; - H21[0][e+1][b] = h21; - H22[0][e+1][b] = h22; - } - for (k = 0; k < NR_BANDS[is34]; k++) { - float h11r, h12r, h21r, h22r; - float h11i, h12i, h21i, h22i; - float h11r_step, h12r_step, h21r_step, h22r_step; - float h11i_step, h12i_step, h21i_step, h22i_step; - int start = ps->border_position[e]; - int stop = ps->border_position[e+1]; - float width = 1.f / (stop - start); - b = k_to_i[k]; - h11r = H11[0][e][b]; - h12r = H12[0][e][b]; - h21r = H21[0][e][b]; - h22r = H22[0][e][b]; - if (!PS_BASELINE && ps->enable_ipdopd) { - //Is this necessary? ps_04_new seems unchanged - if ((is34 && k <= 13 && k >= 9) || (!is34 && k <= 1)) { - h11i = -H11[1][e][b]; - h12i = -H12[1][e][b]; - h21i = -H21[1][e][b]; - h22i = -H22[1][e][b]; - } else { - h11i = H11[1][e][b]; - h12i = H12[1][e][b]; - h21i = H21[1][e][b]; - h22i = H22[1][e][b]; - } - } - //Interpolation - h11r_step = (H11[0][e+1][b] - h11r) * width; - h12r_step = (H12[0][e+1][b] - h12r) * width; - h21r_step = (H21[0][e+1][b] - h21r) * width; - h22r_step = (H22[0][e+1][b] - h22r) * width; - if (!PS_BASELINE && ps->enable_ipdopd) { - h11i_step = (H11[1][e+1][b] - h11i) * width; - h12i_step = (H12[1][e+1][b] - h12i) * width; - h21i_step = (H21[1][e+1][b] - h21i) * width; - h22i_step = (H22[1][e+1][b] - h22i) * width; - } - for (n = start + 1; n <= stop; n++) { - //l is s, r is d - float l_re = l[k][n][0]; - float l_im = l[k][n][1]; - float r_re = r[k][n][0]; - float r_im = r[k][n][1]; - h11r += h11r_step; - h12r += h12r_step; - h21r += h21r_step; - h22r += h22r_step; - if (!PS_BASELINE && ps->enable_ipdopd) { - h11i += h11i_step; - h12i += h12i_step; - h21i += h21i_step; - h22i += h22i_step; - - l[k][n][0] = h11r*l_re + h21r*r_re - h11i*l_im - h21i*r_im; - l[k][n][1] = h11r*l_im + h21r*r_im + h11i*l_re + h21i*r_re; - r[k][n][0] = h12r*l_re + h22r*r_re - h12i*l_im - h22i*r_im; - r[k][n][1] = h12r*l_im + h22r*r_im + h12i*l_re + h22i*r_re; - } else { - l[k][n][0] = h11r*l_re + h21r*r_re; - l[k][n][1] = h11r*l_im + h21r*r_im; - r[k][n][0] = h12r*l_re + h22r*r_re; - r[k][n][1] = h12r*l_im + h22r*r_im; - } - } - } - } -} - -int ff_ps_apply(AVCodecContext *avctx, PSContext *ps, float L[2][38][64], float R[2][38][64], int top) -{ - float Lbuf[91][32][2]; - float Rbuf[91][32][2]; - const int len = 32; - int is34 = ps->is34bands; - - top += NR_BANDS[is34] - 64; - memset(ps->delay+top, 0, (NR_BANDS[is34] - top)*sizeof(ps->delay[0])); - if (top < NR_ALLPASS_BANDS[is34]) - memset(ps->ap_delay + top, 0, (NR_ALLPASS_BANDS[is34] - top)*sizeof(ps->ap_delay[0])); - - hybrid_analysis(Lbuf, ps->in_buf, L, is34, len); - decorrelation(ps, Rbuf, Lbuf, is34); - stereo_processing(ps, Lbuf, Rbuf, is34); - hybrid_synthesis(L, Lbuf, is34, len); - hybrid_synthesis(R, Rbuf, is34, len); - - return 0; -} - -#define PS_INIT_VLC_STATIC(num, size) \ - INIT_VLC_STATIC(&vlc_ps[num], 9, ps_tmp[num].table_size / ps_tmp[num].elem_size, \ - ps_tmp[num].ps_bits, 1, 1, \ - ps_tmp[num].ps_codes, ps_tmp[num].elem_size, ps_tmp[num].elem_size, \ - size); - -#define PS_VLC_ROW(name) \ - { name ## _codes, name ## _bits, sizeof(name ## _codes), sizeof(name ## _codes[0]) } - -av_cold void ff_ps_init(void) { - // Syntax initialization - static const struct { - const void *ps_codes, *ps_bits; - const unsigned int table_size, elem_size; - } ps_tmp[] = { - PS_VLC_ROW(huff_iid_df1), - PS_VLC_ROW(huff_iid_dt1), - PS_VLC_ROW(huff_iid_df0), - PS_VLC_ROW(huff_iid_dt0), - PS_VLC_ROW(huff_icc_df), - PS_VLC_ROW(huff_icc_dt), - PS_VLC_ROW(huff_ipd_df), - PS_VLC_ROW(huff_ipd_dt), - PS_VLC_ROW(huff_opd_df), - PS_VLC_ROW(huff_opd_dt), - }; - - PS_INIT_VLC_STATIC(0, 1544); - PS_INIT_VLC_STATIC(1, 832); - PS_INIT_VLC_STATIC(2, 1024); - PS_INIT_VLC_STATIC(3, 1036); - PS_INIT_VLC_STATIC(4, 544); - PS_INIT_VLC_STATIC(5, 544); - PS_INIT_VLC_STATIC(6, 512); - PS_INIT_VLC_STATIC(7, 512); - PS_INIT_VLC_STATIC(8, 512); - PS_INIT_VLC_STATIC(9, 512); - - ps_tableinit(); -} - -av_cold void ff_ps_ctx_init(PSContext *ps) -{ -} +/*
+ * MPEG-4 Parametric Stereo decoding functions
+ * Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdint.h>
+#include "libavutil/common.h"
+#include "libavutil/mathematics.h"
+#include "avcodec.h"
+#include "get_bits.h"
+#include "aacps.h"
+#include "aacps_tablegen.h"
+#include "aacpsdata.c"
+
+#define PS_BASELINE 0 ///< Operate in Baseline PS mode
+ ///< Baseline implies 10 or 20 stereo bands,
+ ///< mixing mode A, and no ipd/opd
+
+#define numQMFSlots 32 //numTimeSlots * RATE
+
+static const int8_t num_env_tab[2][4] = {
+ { 0, 1, 2, 4, },
+ { 1, 2, 3, 4, },
+};
+
+static const int8_t nr_iidicc_par_tab[] = {
+ 10, 20, 34, 10, 20, 34,
+};
+
+static const int8_t nr_iidopd_par_tab[] = {
+ 5, 11, 17, 5, 11, 17,
+};
+
+enum {
+ huff_iid_df1,
+ huff_iid_dt1,
+ huff_iid_df0,
+ huff_iid_dt0,
+ huff_icc_df,
+ huff_icc_dt,
+ huff_ipd_df,
+ huff_ipd_dt,
+ huff_opd_df,
+ huff_opd_dt,
+};
+
+static const int huff_iid[] = {
+ huff_iid_df0,
+ huff_iid_df1,
+ huff_iid_dt0,
+ huff_iid_dt1,
+};
+
+static VLC vlc_ps[10];
+
+#define READ_PAR_DATA(PAR, OFFSET, MASK, ERR_CONDITION) \
+/** \
+ * Read Inter-channel Intensity Difference/Inter-Channel Coherence/ \
+ * Inter-channel Phase Difference/Overall Phase Difference parameters from the \
+ * bitstream. \
+ * \
+ * @param avctx contains the current codec context \
+ * @param gb pointer to the input bitstream \
+ * @param ps pointer to the Parametric Stereo context \
+ * @param PAR pointer to the parameter to be read \
+ * @param e envelope to decode \
+ * @param dt 1: time delta-coded, 0: frequency delta-coded \
+ */ \
+static int read_ ## PAR ## _data(AVCodecContext *avctx, GetBitContext *gb, PSContext *ps, \
+ int8_t (*PAR)[PS_MAX_NR_IIDICC], int table_idx, int e, int dt) \
+{ \
+ int b, num = ps->nr_ ## PAR ## _par; \
+ VLC_TYPE (*vlc_table)[2] = vlc_ps[table_idx].table; \
+ if (dt) { \
+ int e_prev = e ? e - 1 : ps->num_env_old - 1; \
+ e_prev = FFMAX(e_prev, 0); \
+ for (b = 0; b < num; b++) { \
+ int val = PAR[e_prev][b] + get_vlc2(gb, vlc_table, 9, 3) - OFFSET; \
+ if (MASK) val &= MASK; \
+ PAR[e][b] = val; \
+ if (ERR_CONDITION) \
+ goto err; \
+ } \
+ } else { \
+ int val = 0; \
+ for (b = 0; b < num; b++) { \
+ val += get_vlc2(gb, vlc_table, 9, 3) - OFFSET; \
+ if (MASK) val &= MASK; \
+ PAR[e][b] = val; \
+ if (ERR_CONDITION) \
+ goto err; \
+ } \
+ } \
+ return 0; \
+err: \
+ av_log(avctx, AV_LOG_ERROR, "illegal "#PAR"\n"); \
+ return -1; \
+}
+
+READ_PAR_DATA(iid, huff_offset[table_idx], 0, FFABS(ps->iid_par[e][b]) > 7 + 8 * ps->iid_quant)
+READ_PAR_DATA(icc, huff_offset[table_idx], 0, ps->icc_par[e][b] > 7U)
+READ_PAR_DATA(ipdopd, 0, 0x07, 0)
+
+static int ps_read_extension_data(GetBitContext *gb, PSContext *ps, int ps_extension_id)
+{
+ int e;
+ int count = get_bits_count(gb);
+
+ if (ps_extension_id)
+ return 0;
+
+ ps->enable_ipdopd = get_bits1(gb);
+ if (ps->enable_ipdopd) {
+ for (e = 0; e < ps->num_env; e++) {
+ int dt = get_bits1(gb);
+ read_ipdopd_data(NULL, gb, ps, ps->ipd_par, dt ? huff_ipd_dt : huff_ipd_df, e, dt);
+ dt = get_bits1(gb);
+ read_ipdopd_data(NULL, gb, ps, ps->opd_par, dt ? huff_opd_dt : huff_opd_df, e, dt);
+ }
+ }
+ skip_bits1(gb); //reserved_ps
+ return get_bits_count(gb) - count;
+}
+
+static void ipdopd_reset(int8_t *opd_hist, int8_t *ipd_hist)
+{
+ int i;
+ for (i = 0; i < PS_MAX_NR_IPDOPD; i++) {
+ opd_hist[i] = 0;
+ ipd_hist[i] = 0;
+ }
+}
+
+int ff_ps_read_data(AVCodecContext *avctx, GetBitContext *gb_host, PSContext *ps, int bits_left)
+{
+ int e;
+ int bit_count_start = get_bits_count(gb_host);
+ int header;
+ int bits_consumed;
+ GetBitContext gbc = *gb_host, *gb = &gbc;
+
+ header = get_bits1(gb);
+ if (header) { //enable_ps_header
+ ps->enable_iid = get_bits1(gb);
+ if (ps->enable_iid) {
+ int iid_mode = get_bits(gb, 3);
+ if (iid_mode > 5) {
+ av_log(avctx, AV_LOG_ERROR, "iid_mode %d is reserved.\n",
+ iid_mode);
+ goto err;
+ }
+ ps->nr_iid_par = nr_iidicc_par_tab[iid_mode];
+ ps->iid_quant = iid_mode > 2;
+ ps->nr_ipdopd_par = nr_iidopd_par_tab[iid_mode];
+ }
+ ps->enable_icc = get_bits1(gb);
+ if (ps->enable_icc) {
+ ps->icc_mode = get_bits(gb, 3);
+ if (ps->icc_mode > 5) {
+ av_log(avctx, AV_LOG_ERROR, "icc_mode %d is reserved.\n",
+ ps->icc_mode);
+ goto err;
+ }
+ ps->nr_icc_par = nr_iidicc_par_tab[ps->icc_mode];
+ }
+ ps->enable_ext = get_bits1(gb);
+ }
+
+ ps->frame_class = get_bits1(gb);
+ ps->num_env_old = ps->num_env;
+ ps->num_env = num_env_tab[ps->frame_class][get_bits(gb, 2)];
+
+ ps->border_position[0] = -1;
+ if (ps->frame_class) {
+ for (e = 1; e <= ps->num_env; e++)
+ ps->border_position[e] = get_bits(gb, 5);
+ } else
+ for (e = 1; e <= ps->num_env; e++)
+ ps->border_position[e] = (e * numQMFSlots >> ff_log2_tab[ps->num_env]) - 1;
+
+ if (ps->enable_iid) {
+ for (e = 0; e < ps->num_env; e++) {
+ int dt = get_bits1(gb);
+ if (read_iid_data(avctx, gb, ps, ps->iid_par, huff_iid[2*dt+ps->iid_quant], e, dt))
+ goto err;
+ }
+ } else
+ memset(ps->iid_par, 0, sizeof(ps->iid_par));
+
+ if (ps->enable_icc)
+ for (e = 0; e < ps->num_env; e++) {
+ int dt = get_bits1(gb);
+ if (read_icc_data(avctx, gb, ps, ps->icc_par, dt ? huff_icc_dt : huff_icc_df, e, dt))
+ goto err;
+ }
+ else
+ memset(ps->icc_par, 0, sizeof(ps->icc_par));
+
+ if (ps->enable_ext) {
+ int cnt = get_bits(gb, 4);
+ if (cnt == 15) {
+ cnt += get_bits(gb, 8);
+ }
+ cnt *= 8;
+ while (cnt > 7) {
+ int ps_extension_id = get_bits(gb, 2);
+ cnt -= 2 + ps_read_extension_data(gb, ps, ps_extension_id);
+ }
+ if (cnt < 0) {
+ av_log(avctx, AV_LOG_ERROR, "ps extension overflow %d\n", cnt);
+ goto err;
+ }
+ skip_bits(gb, cnt);
+ }
+
+ ps->enable_ipdopd &= !PS_BASELINE;
+
+ //Fix up envelopes
+ if (!ps->num_env || ps->border_position[ps->num_env] < numQMFSlots - 1) {
+ //Create a fake envelope
+ int source = ps->num_env ? ps->num_env - 1 : ps->num_env_old - 1;
+ if (source >= 0 && source != ps->num_env) {
+ if (ps->enable_iid) {
+ memcpy(ps->iid_par+ps->num_env, ps->iid_par+source, sizeof(ps->iid_par[0]));
+ }
+ if (ps->enable_icc) {
+ memcpy(ps->icc_par+ps->num_env, ps->icc_par+source, sizeof(ps->icc_par[0]));
+ }
+ if (ps->enable_ipdopd) {
+ memcpy(ps->ipd_par+ps->num_env, ps->ipd_par+source, sizeof(ps->ipd_par[0]));
+ memcpy(ps->opd_par+ps->num_env, ps->opd_par+source, sizeof(ps->opd_par[0]));
+ }
+ }
+ ps->num_env++;
+ ps->border_position[ps->num_env] = numQMFSlots - 1;
+ }
+
+
+ ps->is34bands_old = ps->is34bands;
+ if (!PS_BASELINE && (ps->enable_iid || ps->enable_icc))
+ ps->is34bands = (ps->enable_iid && ps->nr_iid_par == 34) ||
+ (ps->enable_icc && ps->nr_icc_par == 34);
+
+ //Baseline
+ if (!ps->enable_ipdopd) {
+ memset(ps->ipd_par, 0, sizeof(ps->ipd_par));
+ memset(ps->opd_par, 0, sizeof(ps->opd_par));
+ }
+
+ if (header)
+ ps->start = 1;
+
+ bits_consumed = get_bits_count(gb) - bit_count_start;
+ if (bits_consumed <= bits_left) {
+ skip_bits_long(gb_host, bits_consumed);
+ return bits_consumed;
+ }
+ av_log(avctx, AV_LOG_ERROR, "Expected to read %d PS bits actually read %d.\n", bits_left, bits_consumed);
+err:
+ ps->start = 0;
+ skip_bits_long(gb_host, bits_left);
+ return bits_left;
+}
+
+/** Split one subband into 2 subsubbands with a symmetric real filter.
+ * The filter must have its non-center even coefficients equal to zero. */
+static void hybrid2_re(float (*in)[2], float (*out)[32][2], const float filter[7], int len, int reverse)
+{
+ int i, j;
+ for (i = 0; i < len; i++, in++) {
+ float re_in = filter[6] * in[6][0]; //real inphase
+ float re_op = 0.0f; //real out of phase
+ float im_in = filter[6] * in[6][1]; //imag inphase
+ float im_op = 0.0f; //imag out of phase
+ for (j = 0; j < 6; j += 2) {
+ re_op += filter[j+1] * (in[j+1][0] + in[12-j-1][0]);
+ im_op += filter[j+1] * (in[j+1][1] + in[12-j-1][1]);
+ }
+ out[ reverse][i][0] = re_in + re_op;
+ out[ reverse][i][1] = im_in + im_op;
+ out[!reverse][i][0] = re_in - re_op;
+ out[!reverse][i][1] = im_in - im_op;
+ }
+}
+
+/** Split one subband into 6 subsubbands with a complex filter */
+static void hybrid6_cx(float (*in)[2], float (*out)[32][2], const float (*filter)[7][2], int len)
+{
+ int i, j, ssb;
+ int N = 8;
+ float temp[8][2];
+
+ for (i = 0; i < len; i++, in++) {
+ for (ssb = 0; ssb < N; ssb++) {
+ float sum_re = filter[ssb][6][0] * in[6][0], sum_im = filter[ssb][6][0] * in[6][1];
+ for (j = 0; j < 6; j++) {
+ float in0_re = in[j][0];
+ float in0_im = in[j][1];
+ float in1_re = in[12-j][0];
+ float in1_im = in[12-j][1];
+ sum_re += filter[ssb][j][0] * (in0_re + in1_re) - filter[ssb][j][1] * (in0_im - in1_im);
+ sum_im += filter[ssb][j][0] * (in0_im + in1_im) + filter[ssb][j][1] * (in0_re - in1_re);
+ }
+ temp[ssb][0] = sum_re;
+ temp[ssb][1] = sum_im;
+ }
+ out[0][i][0] = temp[6][0];
+ out[0][i][1] = temp[6][1];
+ out[1][i][0] = temp[7][0];
+ out[1][i][1] = temp[7][1];
+ out[2][i][0] = temp[0][0];
+ out[2][i][1] = temp[0][1];
+ out[3][i][0] = temp[1][0];
+ out[3][i][1] = temp[1][1];
+ out[4][i][0] = temp[2][0] + temp[5][0];
+ out[4][i][1] = temp[2][1] + temp[5][1];
+ out[5][i][0] = temp[3][0] + temp[4][0];
+ out[5][i][1] = temp[3][1] + temp[4][1];
+ }
+}
+
+static void hybrid4_8_12_cx(float (*in)[2], float (*out)[32][2], const float (*filter)[7][2], int N, int len)
+{
+ int i, j, ssb;
+
+ for (i = 0; i < len; i++, in++) {
+ for (ssb = 0; ssb < N; ssb++) {
+ float sum_re = filter[ssb][6][0] * in[6][0], sum_im = filter[ssb][6][0] * in[6][1];
+ for (j = 0; j < 6; j++) {
+ float in0_re = in[j][0];
+ float in0_im = in[j][1];
+ float in1_re = in[12-j][0];
+ float in1_im = in[12-j][1];
+ sum_re += filter[ssb][j][0] * (in0_re + in1_re) - filter[ssb][j][1] * (in0_im - in1_im);
+ sum_im += filter[ssb][j][0] * (in0_im + in1_im) + filter[ssb][j][1] * (in0_re - in1_re);
+ }
+ out[ssb][i][0] = sum_re;
+ out[ssb][i][1] = sum_im;
+ }
+ }
+}
+
+static void hybrid_analysis(float out[91][32][2], float in[5][44][2], float L[2][38][64], int is34, int len)
+{
+ int i, j;
+ for (i = 0; i < 5; i++) {
+ for (j = 0; j < 38; j++) {
+ in[i][j+6][0] = L[0][j][i];
+ in[i][j+6][1] = L[1][j][i];
+ }
+ }
+ if (is34) {
+ hybrid4_8_12_cx(in[0], out, f34_0_12, 12, len);
+ hybrid4_8_12_cx(in[1], out+12, f34_1_8, 8, len);
+ hybrid4_8_12_cx(in[2], out+20, f34_2_4, 4, len);
+ hybrid4_8_12_cx(in[3], out+24, f34_2_4, 4, len);
+ hybrid4_8_12_cx(in[4], out+28, f34_2_4, 4, len);
+ for (i = 0; i < 59; i++) {
+ for (j = 0; j < len; j++) {
+ out[i+32][j][0] = L[0][j][i+5];
+ out[i+32][j][1] = L[1][j][i+5];
+ }
+ }
+ } else {
+ hybrid6_cx(in[0], out, f20_0_8, len);
+ hybrid2_re(in[1], out+6, g1_Q2, len, 1);
+ hybrid2_re(in[2], out+8, g1_Q2, len, 0);
+ for (i = 0; i < 61; i++) {
+ for (j = 0; j < len; j++) {
+ out[i+10][j][0] = L[0][j][i+3];
+ out[i+10][j][1] = L[1][j][i+3];
+ }
+ }
+ }
+ //update in_buf
+ for (i = 0; i < 5; i++) {
+ memcpy(in[i], in[i]+32, 6 * sizeof(in[i][0]));
+ }
+}
+
+static void hybrid_synthesis(float out[2][38][64], float in[91][32][2], int is34, int len)
+{
+ int i, n;
+ if (is34) {
+ for (n = 0; n < len; n++) {
+ memset(out[0][n], 0, 5*sizeof(out[0][n][0]));
+ memset(out[1][n], 0, 5*sizeof(out[1][n][0]));
+ for (i = 0; i < 12; i++) {
+ out[0][n][0] += in[ i][n][0];
+ out[1][n][0] += in[ i][n][1];
+ }
+ for (i = 0; i < 8; i++) {
+ out[0][n][1] += in[12+i][n][0];
+ out[1][n][1] += in[12+i][n][1];
+ }
+ for (i = 0; i < 4; i++) {
+ out[0][n][2] += in[20+i][n][0];
+ out[1][n][2] += in[20+i][n][1];
+ out[0][n][3] += in[24+i][n][0];
+ out[1][n][3] += in[24+i][n][1];
+ out[0][n][4] += in[28+i][n][0];
+ out[1][n][4] += in[28+i][n][1];
+ }
+ }
+ for (i = 0; i < 59; i++) {
+ for (n = 0; n < len; n++) {
+ out[0][n][i+5] = in[i+32][n][0];
+ out[1][n][i+5] = in[i+32][n][1];
+ }
+ }
+ } else {
+ for (n = 0; n < len; n++) {
+ out[0][n][0] = in[0][n][0] + in[1][n][0] + in[2][n][0] +
+ in[3][n][0] + in[4][n][0] + in[5][n][0];
+ out[1][n][0] = in[0][n][1] + in[1][n][1] + in[2][n][1] +
+ in[3][n][1] + in[4][n][1] + in[5][n][1];
+ out[0][n][1] = in[6][n][0] + in[7][n][0];
+ out[1][n][1] = in[6][n][1] + in[7][n][1];
+ out[0][n][2] = in[8][n][0] + in[9][n][0];
+ out[1][n][2] = in[8][n][1] + in[9][n][1];
+ }
+ for (i = 0; i < 61; i++) {
+ for (n = 0; n < len; n++) {
+ out[0][n][i+3] = in[i+10][n][0];
+ out[1][n][i+3] = in[i+10][n][1];
+ }
+ }
+ }
+}
+
+/// All-pass filter decay slope
+#define DECAY_SLOPE 0.05f
+/// Number of frequency bands that can be addressed by the parameter index, b(k)
+static const int NR_PAR_BANDS[] = { 20, 34 };
+/// Number of frequency bands that can be addressed by the sub subband index, k
+static const int NR_BANDS[] = { 71, 91 };
+/// Start frequency band for the all-pass filter decay slope
+static const int DECAY_CUTOFF[] = { 10, 32 };
+/// Number of all-pass filer bands
+static const int NR_ALLPASS_BANDS[] = { 30, 50 };
+/// First stereo band using the short one sample delay
+static const int SHORT_DELAY_BAND[] = { 42, 62 };
+
+/** Table 8.46 */
+static void map_idx_10_to_20(int8_t *par_mapped, const int8_t *par, int full)
+{
+ int b;
+ if (full)
+ b = 9;
+ else {
+ b = 4;
+ par_mapped[10] = 0;
+ }
+ for (; b >= 0; b--) {
+ par_mapped[2*b+1] = par_mapped[2*b] = par[b];
+ }
+}
+
+static void map_idx_34_to_20(int8_t *par_mapped, const int8_t *par, int full)
+{
+ par_mapped[ 0] = (2*par[ 0] + par[ 1]) / 3;
+ par_mapped[ 1] = ( par[ 1] + 2*par[ 2]) / 3;
+ par_mapped[ 2] = (2*par[ 3] + par[ 4]) / 3;
+ par_mapped[ 3] = ( par[ 4] + 2*par[ 5]) / 3;
+ par_mapped[ 4] = ( par[ 6] + par[ 7]) / 2;
+ par_mapped[ 5] = ( par[ 8] + par[ 9]) / 2;
+ par_mapped[ 6] = par[10];
+ par_mapped[ 7] = par[11];
+ par_mapped[ 8] = ( par[12] + par[13]) / 2;
+ par_mapped[ 9] = ( par[14] + par[15]) / 2;
+ par_mapped[10] = par[16];
+ if (full) {
+ par_mapped[11] = par[17];
+ par_mapped[12] = par[18];
+ par_mapped[13] = par[19];
+ par_mapped[14] = ( par[20] + par[21]) / 2;
+ par_mapped[15] = ( par[22] + par[23]) / 2;
+ par_mapped[16] = ( par[24] + par[25]) / 2;
+ par_mapped[17] = ( par[26] + par[27]) / 2;
+ par_mapped[18] = ( par[28] + par[29] + par[30] + par[31]) / 4;
+ par_mapped[19] = ( par[32] + par[33]) / 2;
+ }
+}
+
+static void map_val_34_to_20(float par[PS_MAX_NR_IIDICC])
+{
+ par[ 0] = (2*par[ 0] + par[ 1]) * 0.33333333f;
+ par[ 1] = ( par[ 1] + 2*par[ 2]) * 0.33333333f;
+ par[ 2] = (2*par[ 3] + par[ 4]) * 0.33333333f;
+ par[ 3] = ( par[ 4] + 2*par[ 5]) * 0.33333333f;
+ par[ 4] = ( par[ 6] + par[ 7]) * 0.5f;
+ par[ 5] = ( par[ 8] + par[ 9]) * 0.5f;
+ par[ 6] = par[10];
+ par[ 7] = par[11];
+ par[ 8] = ( par[12] + par[13]) * 0.5f;
+ par[ 9] = ( par[14] + par[15]) * 0.5f;
+ par[10] = par[16];
+ par[11] = par[17];
+ par[12] = par[18];
+ par[13] = par[19];
+ par[14] = ( par[20] + par[21]) * 0.5f;
+ par[15] = ( par[22] + par[23]) * 0.5f;
+ par[16] = ( par[24] + par[25]) * 0.5f;
+ par[17] = ( par[26] + par[27]) * 0.5f;
+ par[18] = ( par[28] + par[29] + par[30] + par[31]) * 0.25f;
+ par[19] = ( par[32] + par[33]) * 0.5f;
+}
+
+static void map_idx_10_to_34(int8_t *par_mapped, const int8_t *par, int full)
+{
+ if (full) {
+ par_mapped[33] = par[9];
+ par_mapped[32] = par[9];
+ par_mapped[31] = par[9];
+ par_mapped[30] = par[9];
+ par_mapped[29] = par[9];
+ par_mapped[28] = par[9];
+ par_mapped[27] = par[8];
+ par_mapped[26] = par[8];
+ par_mapped[25] = par[8];
+ par_mapped[24] = par[8];
+ par_mapped[23] = par[7];
+ par_mapped[22] = par[7];
+ par_mapped[21] = par[7];
+ par_mapped[20] = par[7];
+ par_mapped[19] = par[6];
+ par_mapped[18] = par[6];
+ par_mapped[17] = par[5];
+ par_mapped[16] = par[5];
+ } else {
+ par_mapped[16] = 0;
+ }
+ par_mapped[15] = par[4];
+ par_mapped[14] = par[4];
+ par_mapped[13] = par[4];
+ par_mapped[12] = par[4];
+ par_mapped[11] = par[3];
+ par_mapped[10] = par[3];
+ par_mapped[ 9] = par[2];
+ par_mapped[ 8] = par[2];
+ par_mapped[ 7] = par[2];
+ par_mapped[ 6] = par[2];
+ par_mapped[ 5] = par[1];
+ par_mapped[ 4] = par[1];
+ par_mapped[ 3] = par[1];
+ par_mapped[ 2] = par[0];
+ par_mapped[ 1] = par[0];
+ par_mapped[ 0] = par[0];
+}
+
+static void map_idx_20_to_34(int8_t *par_mapped, const int8_t *par, int full)
+{
+ if (full) {
+ par_mapped[33] = par[19];
+ par_mapped[32] = par[19];
+ par_mapped[31] = par[18];
+ par_mapped[30] = par[18];
+ par_mapped[29] = par[18];
+ par_mapped[28] = par[18];
+ par_mapped[27] = par[17];
+ par_mapped[26] = par[17];
+ par_mapped[25] = par[16];
+ par_mapped[24] = par[16];
+ par_mapped[23] = par[15];
+ par_mapped[22] = par[15];
+ par_mapped[21] = par[14];
+ par_mapped[20] = par[14];
+ par_mapped[19] = par[13];
+ par_mapped[18] = par[12];
+ par_mapped[17] = par[11];
+ }
+ par_mapped[16] = par[10];
+ par_mapped[15] = par[ 9];
+ par_mapped[14] = par[ 9];
+ par_mapped[13] = par[ 8];
+ par_mapped[12] = par[ 8];
+ par_mapped[11] = par[ 7];
+ par_mapped[10] = par[ 6];
+ par_mapped[ 9] = par[ 5];
+ par_mapped[ 8] = par[ 5];
+ par_mapped[ 7] = par[ 4];
+ par_mapped[ 6] = par[ 4];
+ par_mapped[ 5] = par[ 3];
+ par_mapped[ 4] = (par[ 2] + par[ 3]) / 2;
+ par_mapped[ 3] = par[ 2];
+ par_mapped[ 2] = par[ 1];
+ par_mapped[ 1] = (par[ 0] + par[ 1]) / 2;
+ par_mapped[ 0] = par[ 0];
+}
+
+static void map_val_20_to_34(float par[PS_MAX_NR_IIDICC])
+{
+ par[33] = par[19];
+ par[32] = par[19];
+ par[31] = par[18];
+ par[30] = par[18];
+ par[29] = par[18];
+ par[28] = par[18];
+ par[27] = par[17];
+ par[26] = par[17];
+ par[25] = par[16];
+ par[24] = par[16];
+ par[23] = par[15];
+ par[22] = par[15];
+ par[21] = par[14];
+ par[20] = par[14];
+ par[19] = par[13];
+ par[18] = par[12];
+ par[17] = par[11];
+ par[16] = par[10];
+ par[15] = par[ 9];
+ par[14] = par[ 9];
+ par[13] = par[ 8];
+ par[12] = par[ 8];
+ par[11] = par[ 7];
+ par[10] = par[ 6];
+ par[ 9] = par[ 5];
+ par[ 8] = par[ 5];
+ par[ 7] = par[ 4];
+ par[ 6] = par[ 4];
+ par[ 5] = par[ 3];
+ par[ 4] = (par[ 2] + par[ 3]) * 0.5f;
+ par[ 3] = par[ 2];
+ par[ 2] = par[ 1];
+ par[ 1] = (par[ 0] + par[ 1]) * 0.5f;
+ par[ 0] = par[ 0];
+}
+
+static void decorrelation(PSContext *ps, float (*out)[32][2], const float (*s)[32][2], int is34)
+{
+ float power[34][PS_QMF_TIME_SLOTS] = {{0}};
+ float transient_gain[34][PS_QMF_TIME_SLOTS];
+ float *peak_decay_nrg = ps->peak_decay_nrg;
+ float *power_smooth = ps->power_smooth;
+ float *peak_decay_diff_smooth = ps->peak_decay_diff_smooth;
+ float (*delay)[PS_QMF_TIME_SLOTS + PS_MAX_DELAY][2] = ps->delay;
+ float (*ap_delay)[PS_AP_LINKS][PS_QMF_TIME_SLOTS + PS_MAX_AP_DELAY][2] = ps->ap_delay;
+ const int8_t *k_to_i = is34 ? k_to_i_34 : k_to_i_20;
+ const float peak_decay_factor = 0.76592833836465f;
+ const float transient_impact = 1.5f;
+ const float a_smooth = 0.25f; ///< Smoothing coefficient
+ int i, k, m, n;
+ int n0 = 0, nL = 32;
+ static const int link_delay[] = { 3, 4, 5 };
+ static const float a[] = { 0.65143905753106f,
+ 0.56471812200776f,
+ 0.48954165955695f };
+
+ if (is34 != ps->is34bands_old) {
+ memset(ps->peak_decay_nrg, 0, sizeof(ps->peak_decay_nrg));
+ memset(ps->power_smooth, 0, sizeof(ps->power_smooth));
+ memset(ps->peak_decay_diff_smooth, 0, sizeof(ps->peak_decay_diff_smooth));
+ memset(ps->delay, 0, sizeof(ps->delay));
+ memset(ps->ap_delay, 0, sizeof(ps->ap_delay));
+ }
+
+ for (n = n0; n < nL; n++) {
+ for (k = 0; k < NR_BANDS[is34]; k++) {
+ int i = k_to_i[k];
+ power[i][n] += s[k][n][0] * s[k][n][0] + s[k][n][1] * s[k][n][1];
+ }
+ }
+
+ //Transient detection
+ for (i = 0; i < NR_PAR_BANDS[is34]; i++) {
+ for (n = n0; n < nL; n++) {
+ float decayed_peak = peak_decay_factor * peak_decay_nrg[i];
+ float denom;
+ peak_decay_nrg[i] = FFMAX(decayed_peak, power[i][n]);
+ power_smooth[i] += a_smooth * (power[i][n] - power_smooth[i]);
+ peak_decay_diff_smooth[i] += a_smooth * (peak_decay_nrg[i] - power[i][n] - peak_decay_diff_smooth[i]);
+ denom = transient_impact * peak_decay_diff_smooth[i];
+ transient_gain[i][n] = (denom > power_smooth[i]) ?
+ power_smooth[i] / denom : 1.0f;
+ }
+ }
+
+ //Decorrelation and transient reduction
+ // PS_AP_LINKS - 1
+ // -----
+ // | | Q_fract_allpass[k][m]*z^-link_delay[m] - a[m]*g_decay_slope[k]
+ //H[k][z] = z^-2 * phi_fract[k] * | | ----------------------------------------------------------------
+ // | | 1 - a[m]*g_decay_slope[k]*Q_fract_allpass[k][m]*z^-link_delay[m]
+ // m = 0
+ //d[k][z] (out) = transient_gain_mapped[k][z] * H[k][z] * s[k][z]
+ for (k = 0; k < NR_ALLPASS_BANDS[is34]; k++) {
+ int b = k_to_i[k];
+ float g_decay_slope = 1.f - DECAY_SLOPE * (k - DECAY_CUTOFF[is34]);
+ float ag[PS_AP_LINKS];
+ g_decay_slope = av_clipf(g_decay_slope, 0.f, 1.f);
+ memcpy(delay[k], delay[k]+nL, PS_MAX_DELAY*sizeof(delay[k][0]));
+ memcpy(delay[k]+PS_MAX_DELAY, s[k], numQMFSlots*sizeof(delay[k][0]));
+ for (m = 0; m < PS_AP_LINKS; m++) {
+ memcpy(ap_delay[k][m], ap_delay[k][m]+numQMFSlots, 5*sizeof(ap_delay[k][m][0]));
+ ag[m] = a[m] * g_decay_slope;
+ }
+ for (n = n0; n < nL; n++) {
+ float in_re = delay[k][n+PS_MAX_DELAY-2][0] * phi_fract[is34][k][0] -
+ delay[k][n+PS_MAX_DELAY-2][1] * phi_fract[is34][k][1];
+ float in_im = delay[k][n+PS_MAX_DELAY-2][0] * phi_fract[is34][k][1] +
+ delay[k][n+PS_MAX_DELAY-2][1] * phi_fract[is34][k][0];
+ for (m = 0; m < PS_AP_LINKS; m++) {
+ float a_re = ag[m] * in_re;
+ float a_im = ag[m] * in_im;
+ float link_delay_re = ap_delay[k][m][n+5-link_delay[m]][0];
+ float link_delay_im = ap_delay[k][m][n+5-link_delay[m]][1];
+ float fractional_delay_re = Q_fract_allpass[is34][k][m][0];
+ float fractional_delay_im = Q_fract_allpass[is34][k][m][1];
+ ap_delay[k][m][n+5][0] = in_re;
+ ap_delay[k][m][n+5][1] = in_im;
+ in_re = link_delay_re * fractional_delay_re - link_delay_im * fractional_delay_im - a_re;
+ in_im = link_delay_re * fractional_delay_im + link_delay_im * fractional_delay_re - a_im;
+ ap_delay[k][m][n+5][0] += ag[m] * in_re;
+ ap_delay[k][m][n+5][1] += ag[m] * in_im;
+ }
+ out[k][n][0] = transient_gain[b][n] * in_re;
+ out[k][n][1] = transient_gain[b][n] * in_im;
+ }
+ }
+ for (; k < SHORT_DELAY_BAND[is34]; k++) {
+ memcpy(delay[k], delay[k]+nL, PS_MAX_DELAY*sizeof(delay[k][0]));
+ memcpy(delay[k]+PS_MAX_DELAY, s[k], numQMFSlots*sizeof(delay[k][0]));
+ for (n = n0; n < nL; n++) {
+ //H = delay 14
+ out[k][n][0] = transient_gain[k_to_i[k]][n] * delay[k][n+PS_MAX_DELAY-14][0];
+ out[k][n][1] = transient_gain[k_to_i[k]][n] * delay[k][n+PS_MAX_DELAY-14][1];
+ }
+ }
+ for (; k < NR_BANDS[is34]; k++) {
+ memcpy(delay[k], delay[k]+nL, PS_MAX_DELAY*sizeof(delay[k][0]));
+ memcpy(delay[k]+PS_MAX_DELAY, s[k], numQMFSlots*sizeof(delay[k][0]));
+ for (n = n0; n < nL; n++) {
+ //H = delay 1
+ out[k][n][0] = transient_gain[k_to_i[k]][n] * delay[k][n+PS_MAX_DELAY-1][0];
+ out[k][n][1] = transient_gain[k_to_i[k]][n] * delay[k][n+PS_MAX_DELAY-1][1];
+ }
+ }
+}
+
+static void remap34(int8_t (**p_par_mapped)[PS_MAX_NR_IIDICC],
+ int8_t (*par)[PS_MAX_NR_IIDICC],
+ int num_par, int num_env, int full)
+{
+ int8_t (*par_mapped)[PS_MAX_NR_IIDICC] = *p_par_mapped;
+ int e;
+ if (num_par == 20 || num_par == 11) {
+ for (e = 0; e < num_env; e++) {
+ map_idx_20_to_34(par_mapped[e], par[e], full);
+ }
+ } else if (num_par == 10 || num_par == 5) {
+ for (e = 0; e < num_env; e++) {
+ map_idx_10_to_34(par_mapped[e], par[e], full);
+ }
+ } else {
+ *p_par_mapped = par;
+ }
+}
+
+static void remap20(int8_t (**p_par_mapped)[PS_MAX_NR_IIDICC],
+ int8_t (*par)[PS_MAX_NR_IIDICC],
+ int num_par, int num_env, int full)
+{
+ int8_t (*par_mapped)[PS_MAX_NR_IIDICC] = *p_par_mapped;
+ int e;
+ if (num_par == 34 || num_par == 17) {
+ for (e = 0; e < num_env; e++) {
+ map_idx_34_to_20(par_mapped[e], par[e], full);
+ }
+ } else if (num_par == 10 || num_par == 5) {
+ for (e = 0; e < num_env; e++) {
+ map_idx_10_to_20(par_mapped[e], par[e], full);
+ }
+ } else {
+ *p_par_mapped = par;
+ }
+}
+
+static void stereo_processing(PSContext *ps, float (*l)[32][2], float (*r)[32][2], int is34)
+{
+ int e, b, k, n;
+
+ float (*H11)[PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC] = ps->H11;
+ float (*H12)[PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC] = ps->H12;
+ float (*H21)[PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC] = ps->H21;
+ float (*H22)[PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC] = ps->H22;
+ int8_t *opd_hist = ps->opd_hist;
+ int8_t *ipd_hist = ps->ipd_hist;
+ int8_t iid_mapped_buf[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC];
+ int8_t icc_mapped_buf[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC];
+ int8_t ipd_mapped_buf[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC];
+ int8_t opd_mapped_buf[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC];
+ int8_t (*iid_mapped)[PS_MAX_NR_IIDICC] = iid_mapped_buf;
+ int8_t (*icc_mapped)[PS_MAX_NR_IIDICC] = icc_mapped_buf;
+ int8_t (*ipd_mapped)[PS_MAX_NR_IIDICC] = ipd_mapped_buf;
+ int8_t (*opd_mapped)[PS_MAX_NR_IIDICC] = opd_mapped_buf;
+ const int8_t *k_to_i = is34 ? k_to_i_34 : k_to_i_20;
+ const float (*H_LUT)[8][4] = (PS_BASELINE || ps->icc_mode < 3) ? HA : HB;
+
+ //Remapping
+ if (ps->num_env_old) {
+ memcpy(H11[0][0], H11[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H11[0][0][0]));
+ memcpy(H11[1][0], H11[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H11[1][0][0]));
+ memcpy(H12[0][0], H12[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H12[0][0][0]));
+ memcpy(H12[1][0], H12[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H12[1][0][0]));
+ memcpy(H21[0][0], H21[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H21[0][0][0]));
+ memcpy(H21[1][0], H21[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H21[1][0][0]));
+ memcpy(H22[0][0], H22[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H22[0][0][0]));
+ memcpy(H22[1][0], H22[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H22[1][0][0]));
+ }
+
+ if (is34) {
+ remap34(&iid_mapped, ps->iid_par, ps->nr_iid_par, ps->num_env, 1);
+ remap34(&icc_mapped, ps->icc_par, ps->nr_icc_par, ps->num_env, 1);
+ if (ps->enable_ipdopd) {
+ remap34(&ipd_mapped, ps->ipd_par, ps->nr_ipdopd_par, ps->num_env, 0);
+ remap34(&opd_mapped, ps->opd_par, ps->nr_ipdopd_par, ps->num_env, 0);
+ }
+ if (!ps->is34bands_old) {
+ map_val_20_to_34(H11[0][0]);
+ map_val_20_to_34(H11[1][0]);
+ map_val_20_to_34(H12[0][0]);
+ map_val_20_to_34(H12[1][0]);
+ map_val_20_to_34(H21[0][0]);
+ map_val_20_to_34(H21[1][0]);
+ map_val_20_to_34(H22[0][0]);
+ map_val_20_to_34(H22[1][0]);
+ ipdopd_reset(ipd_hist, opd_hist);
+ }
+ } else {
+ remap20(&iid_mapped, ps->iid_par, ps->nr_iid_par, ps->num_env, 1);
+ remap20(&icc_mapped, ps->icc_par, ps->nr_icc_par, ps->num_env, 1);
+ if (ps->enable_ipdopd) {
+ remap20(&ipd_mapped, ps->ipd_par, ps->nr_ipdopd_par, ps->num_env, 0);
+ remap20(&opd_mapped, ps->opd_par, ps->nr_ipdopd_par, ps->num_env, 0);
+ }
+ if (ps->is34bands_old) {
+ map_val_34_to_20(H11[0][0]);
+ map_val_34_to_20(H11[1][0]);
+ map_val_34_to_20(H12[0][0]);
+ map_val_34_to_20(H12[1][0]);
+ map_val_34_to_20(H21[0][0]);
+ map_val_34_to_20(H21[1][0]);
+ map_val_34_to_20(H22[0][0]);
+ map_val_34_to_20(H22[1][0]);
+ ipdopd_reset(ipd_hist, opd_hist);
+ }
+ }
+
+ //Mixing
+ for (e = 0; e < ps->num_env; e++) {
+ for (b = 0; b < NR_PAR_BANDS[is34]; b++) {
+ float h11, h12, h21, h22;
+ h11 = H_LUT[iid_mapped[e][b] + 7 + 23 * ps->iid_quant][icc_mapped[e][b]][0];
+ h12 = H_LUT[iid_mapped[e][b] + 7 + 23 * ps->iid_quant][icc_mapped[e][b]][1];
+ h21 = H_LUT[iid_mapped[e][b] + 7 + 23 * ps->iid_quant][icc_mapped[e][b]][2];
+ h22 = H_LUT[iid_mapped[e][b] + 7 + 23 * ps->iid_quant][icc_mapped[e][b]][3];
+ if (!PS_BASELINE && ps->enable_ipdopd && b < ps->nr_ipdopd_par) {
+ //The spec say says to only run this smoother when enable_ipdopd
+ //is set but the reference decoder appears to run it constantly
+ float h11i, h12i, h21i, h22i;
+ float ipd_adj_re, ipd_adj_im;
+ int opd_idx = opd_hist[b] * 8 + opd_mapped[e][b];
+ int ipd_idx = ipd_hist[b] * 8 + ipd_mapped[e][b];
+ float opd_re = pd_re_smooth[opd_idx];
+ float opd_im = pd_im_smooth[opd_idx];
+ float ipd_re = pd_re_smooth[ipd_idx];
+ float ipd_im = pd_im_smooth[ipd_idx];
+ opd_hist[b] = opd_idx & 0x3F;
+ ipd_hist[b] = ipd_idx & 0x3F;
+
+ ipd_adj_re = opd_re*ipd_re + opd_im*ipd_im;
+ ipd_adj_im = opd_im*ipd_re - opd_re*ipd_im;
+ h11i = h11 * opd_im;
+ h11 = h11 * opd_re;
+ h12i = h12 * ipd_adj_im;
+ h12 = h12 * ipd_adj_re;
+ h21i = h21 * opd_im;
+ h21 = h21 * opd_re;
+ h22i = h22 * ipd_adj_im;
+ h22 = h22 * ipd_adj_re;
+ H11[1][e+1][b] = h11i;
+ H12[1][e+1][b] = h12i;
+ H21[1][e+1][b] = h21i;
+ H22[1][e+1][b] = h22i;
+ }
+ H11[0][e+1][b] = h11;
+ H12[0][e+1][b] = h12;
+ H21[0][e+1][b] = h21;
+ H22[0][e+1][b] = h22;
+ }
+ for (k = 0; k < NR_BANDS[is34]; k++) {
+ float h11r, h12r, h21r, h22r;
+ float h11i, h12i, h21i, h22i;
+ float h11r_step, h12r_step, h21r_step, h22r_step;
+ float h11i_step, h12i_step, h21i_step, h22i_step;
+ int start = ps->border_position[e];
+ int stop = ps->border_position[e+1];
+ float width = 1.f / (stop - start);
+ b = k_to_i[k];
+ h11r = H11[0][e][b];
+ h12r = H12[0][e][b];
+ h21r = H21[0][e][b];
+ h22r = H22[0][e][b];
+ if (!PS_BASELINE && ps->enable_ipdopd) {
+ //Is this necessary? ps_04_new seems unchanged
+ if ((is34 && k <= 13 && k >= 9) || (!is34 && k <= 1)) {
+ h11i = -H11[1][e][b];
+ h12i = -H12[1][e][b];
+ h21i = -H21[1][e][b];
+ h22i = -H22[1][e][b];
+ } else {
+ h11i = H11[1][e][b];
+ h12i = H12[1][e][b];
+ h21i = H21[1][e][b];
+ h22i = H22[1][e][b];
+ }
+ }
+ //Interpolation
+ h11r_step = (H11[0][e+1][b] - h11r) * width;
+ h12r_step = (H12[0][e+1][b] - h12r) * width;
+ h21r_step = (H21[0][e+1][b] - h21r) * width;
+ h22r_step = (H22[0][e+1][b] - h22r) * width;
+ if (!PS_BASELINE && ps->enable_ipdopd) {
+ h11i_step = (H11[1][e+1][b] - h11i) * width;
+ h12i_step = (H12[1][e+1][b] - h12i) * width;
+ h21i_step = (H21[1][e+1][b] - h21i) * width;
+ h22i_step = (H22[1][e+1][b] - h22i) * width;
+ }
+ for (n = start + 1; n <= stop; n++) {
+ //l is s, r is d
+ float l_re = l[k][n][0];
+ float l_im = l[k][n][1];
+ float r_re = r[k][n][0];
+ float r_im = r[k][n][1];
+ h11r += h11r_step;
+ h12r += h12r_step;
+ h21r += h21r_step;
+ h22r += h22r_step;
+ if (!PS_BASELINE && ps->enable_ipdopd) {
+ h11i += h11i_step;
+ h12i += h12i_step;
+ h21i += h21i_step;
+ h22i += h22i_step;
+
+ l[k][n][0] = h11r*l_re + h21r*r_re - h11i*l_im - h21i*r_im;
+ l[k][n][1] = h11r*l_im + h21r*r_im + h11i*l_re + h21i*r_re;
+ r[k][n][0] = h12r*l_re + h22r*r_re - h12i*l_im - h22i*r_im;
+ r[k][n][1] = h12r*l_im + h22r*r_im + h12i*l_re + h22i*r_re;
+ } else {
+ l[k][n][0] = h11r*l_re + h21r*r_re;
+ l[k][n][1] = h11r*l_im + h21r*r_im;
+ r[k][n][0] = h12r*l_re + h22r*r_re;
+ r[k][n][1] = h12r*l_im + h22r*r_im;
+ }
+ }
+ }
+ }
+}
+
+int ff_ps_apply(AVCodecContext *avctx, PSContext *ps, float L[2][38][64], float R[2][38][64], int top)
+{
+ float Lbuf[91][32][2];
+ float Rbuf[91][32][2];
+ const int len = 32;
+ int is34 = ps->is34bands;
+
+ top += NR_BANDS[is34] - 64;
+ memset(ps->delay+top, 0, (NR_BANDS[is34] - top)*sizeof(ps->delay[0]));
+ if (top < NR_ALLPASS_BANDS[is34])
+ memset(ps->ap_delay + top, 0, (NR_ALLPASS_BANDS[is34] - top)*sizeof(ps->ap_delay[0]));
+
+ hybrid_analysis(Lbuf, ps->in_buf, L, is34, len);
+ decorrelation(ps, Rbuf, Lbuf, is34);
+ stereo_processing(ps, Lbuf, Rbuf, is34);
+ hybrid_synthesis(L, Lbuf, is34, len);
+ hybrid_synthesis(R, Rbuf, is34, len);
+
+ return 0;
+}
+
+#define PS_INIT_VLC_STATIC(num, size) \
+ INIT_VLC_STATIC(&vlc_ps[num], 9, ps_tmp[num].table_size / ps_tmp[num].elem_size, \
+ ps_tmp[num].ps_bits, 1, 1, \
+ ps_tmp[num].ps_codes, ps_tmp[num].elem_size, ps_tmp[num].elem_size, \
+ size);
+
+#define PS_VLC_ROW(name) \
+ { name ## _codes, name ## _bits, sizeof(name ## _codes), sizeof(name ## _codes[0]) }
+
+av_cold void ff_ps_init(void) {
+ // Syntax initialization
+ static const struct {
+ const void *ps_codes, *ps_bits;
+ const unsigned int table_size, elem_size;
+ } ps_tmp[] = {
+ PS_VLC_ROW(huff_iid_df1),
+ PS_VLC_ROW(huff_iid_dt1),
+ PS_VLC_ROW(huff_iid_df0),
+ PS_VLC_ROW(huff_iid_dt0),
+ PS_VLC_ROW(huff_icc_df),
+ PS_VLC_ROW(huff_icc_dt),
+ PS_VLC_ROW(huff_ipd_df),
+ PS_VLC_ROW(huff_ipd_dt),
+ PS_VLC_ROW(huff_opd_df),
+ PS_VLC_ROW(huff_opd_dt),
+ };
+
+ PS_INIT_VLC_STATIC(0, 1544);
+ PS_INIT_VLC_STATIC(1, 832);
+ PS_INIT_VLC_STATIC(2, 1024);
+ PS_INIT_VLC_STATIC(3, 1036);
+ PS_INIT_VLC_STATIC(4, 544);
+ PS_INIT_VLC_STATIC(5, 544);
+ PS_INIT_VLC_STATIC(6, 512);
+ PS_INIT_VLC_STATIC(7, 512);
+ PS_INIT_VLC_STATIC(8, 512);
+ PS_INIT_VLC_STATIC(9, 512);
+
+ ps_tableinit();
+}
+
+av_cold void ff_ps_ctx_init(PSContext *ps)
+{
+}
diff --git a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacps.h b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacps.h index 124fbee22..f031d8672 100644 --- a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacps.h +++ b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacps.h @@ -1,82 +1,82 @@ -/* - * MPEG-4 Parametric Stereo definitions and declarations - * Copyright (c) 2010 Alex Converse <alex.converse@gmail.com> - * - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef AVCODEC_PS_H -#define AVCODEC_PS_H - -#include <stdint.h> - -#include "avcodec.h" -#include "get_bits.h" - -#define PS_MAX_NUM_ENV 5 -#define PS_MAX_NR_IIDICC 34 -#define PS_MAX_NR_IPDOPD 17 -#define PS_MAX_SSB 91 -#define PS_MAX_AP_BANDS 50 -#define PS_QMF_TIME_SLOTS 32 -#define PS_MAX_DELAY 14 -#define PS_AP_LINKS 3 -#define PS_MAX_AP_DELAY 5 - -typedef struct { - int start; - int enable_iid; - int iid_quant; - int nr_iid_par; - int nr_ipdopd_par; - int enable_icc; - int icc_mode; - int nr_icc_par; - int enable_ext; - int frame_class; - int num_env_old; - int num_env; - int enable_ipdopd; - int border_position[PS_MAX_NUM_ENV+1]; - int8_t iid_par[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; ///< Inter-channel Intensity Difference Parameters - int8_t icc_par[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; ///< Inter-Channel Coherence Parameters - /* ipd/opd is iid/icc sized so that the same functions can handle both */ - int8_t ipd_par[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; ///< Inter-channel Phase Difference Parameters - int8_t opd_par[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; ///< Overall Phase Difference Parameters - int is34bands; - int is34bands_old; - - float in_buf[5][44][2]; - float delay[PS_MAX_SSB][PS_QMF_TIME_SLOTS + PS_MAX_DELAY][2]; - float ap_delay[PS_MAX_AP_BANDS][PS_AP_LINKS][PS_QMF_TIME_SLOTS + PS_MAX_AP_DELAY][2]; - float peak_decay_nrg[34]; - float power_smooth[34]; - float peak_decay_diff_smooth[34]; - float H11[2][PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC]; - float H12[2][PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC]; - float H21[2][PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC]; - float H22[2][PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC]; - int8_t opd_hist[PS_MAX_NR_IIDICC]; - int8_t ipd_hist[PS_MAX_NR_IIDICC]; -} PSContext; - -void ff_ps_init(void); -void ff_ps_ctx_init(PSContext *ps); -int ff_ps_read_data(AVCodecContext *avctx, GetBitContext *gb, PSContext *ps, int bits_left); -int ff_ps_apply(AVCodecContext *avctx, PSContext *ps, float L[2][38][64], float R[2][38][64], int top); - -#endif /* AVCODEC_PS_H */ +/*
+ * MPEG-4 Parametric Stereo definitions and declarations
+ * Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_PS_H
+#define AVCODEC_PS_H
+
+#include <stdint.h>
+
+#include "avcodec.h"
+#include "get_bits.h"
+
+#define PS_MAX_NUM_ENV 5
+#define PS_MAX_NR_IIDICC 34
+#define PS_MAX_NR_IPDOPD 17
+#define PS_MAX_SSB 91
+#define PS_MAX_AP_BANDS 50
+#define PS_QMF_TIME_SLOTS 32
+#define PS_MAX_DELAY 14
+#define PS_AP_LINKS 3
+#define PS_MAX_AP_DELAY 5
+
+typedef struct {
+ int start;
+ int enable_iid;
+ int iid_quant;
+ int nr_iid_par;
+ int nr_ipdopd_par;
+ int enable_icc;
+ int icc_mode;
+ int nr_icc_par;
+ int enable_ext;
+ int frame_class;
+ int num_env_old;
+ int num_env;
+ int enable_ipdopd;
+ int border_position[PS_MAX_NUM_ENV+1];
+ int8_t iid_par[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; ///< Inter-channel Intensity Difference Parameters
+ int8_t icc_par[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; ///< Inter-Channel Coherence Parameters
+ /* ipd/opd is iid/icc sized so that the same functions can handle both */
+ int8_t ipd_par[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; ///< Inter-channel Phase Difference Parameters
+ int8_t opd_par[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; ///< Overall Phase Difference Parameters
+ int is34bands;
+ int is34bands_old;
+
+ float in_buf[5][44][2];
+ float delay[PS_MAX_SSB][PS_QMF_TIME_SLOTS + PS_MAX_DELAY][2];
+ float ap_delay[PS_MAX_AP_BANDS][PS_AP_LINKS][PS_QMF_TIME_SLOTS + PS_MAX_AP_DELAY][2];
+ float peak_decay_nrg[34];
+ float power_smooth[34];
+ float peak_decay_diff_smooth[34];
+ float H11[2][PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC];
+ float H12[2][PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC];
+ float H21[2][PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC];
+ float H22[2][PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC];
+ int8_t opd_hist[PS_MAX_NR_IIDICC];
+ int8_t ipd_hist[PS_MAX_NR_IIDICC];
+} PSContext;
+
+void ff_ps_init(void);
+void ff_ps_ctx_init(PSContext *ps);
+int ff_ps_read_data(AVCodecContext *avctx, GetBitContext *gb, PSContext *ps, int bits_left);
+int ff_ps_apply(AVCodecContext *avctx, PSContext *ps, float L[2][38][64], float R[2][38][64], int top);
+
+#endif /* AVCODEC_PS_H */
diff --git a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacps_tablegen.h b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacps_tablegen.h index 5041f44d1..c5113cd09 100644 --- a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacps_tablegen.h +++ b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacps_tablegen.h @@ -1,212 +1,212 @@ -/* - * Header file for hardcoded Parametric Stereo tables - * - * Copyright (c) 2010 Alex Converse <alex.converse@gmail.com> - * - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef AACPS_TABLEGEN_H -#define AACPS_TABLEGEN_H - -#include <stdint.h> - -#if CONFIG_HARDCODED_TABLES -#define ps_tableinit() -#include "libavcodec/aacps_tables.h" -#else -#include "libavutil/common.h" -#include "libavutil/mathematics.h" -#define NR_ALLPASS_BANDS20 30 -#define NR_ALLPASS_BANDS34 50 -#define PS_AP_LINKS 3 -static float pd_re_smooth[8*8*8]; -static float pd_im_smooth[8*8*8]; -static float HA[46][8][4]; -static float HB[46][8][4]; -static float f20_0_8 [ 8][7][2]; -static float f34_0_12[12][7][2]; -static float f34_1_8 [ 8][7][2]; -static float f34_2_4 [ 4][7][2]; -static float Q_fract_allpass[2][50][3][2]; -static float phi_fract[2][50][2]; - -static const float g0_Q8[] = { - 0.00746082949812f, 0.02270420949825f, 0.04546865930473f, 0.07266113929591f, - 0.09885108575264f, 0.11793710567217f, 0.125f -}; - -static const float g0_Q12[] = { - 0.04081179924692f, 0.03812810994926f, 0.05144908135699f, 0.06399831151592f, - 0.07428313801106f, 0.08100347892914f, 0.08333333333333f -}; - -static const float g1_Q8[] = { - 0.01565675600122f, 0.03752716391991f, 0.05417891378782f, 0.08417044116767f, - 0.10307344158036f, 0.12222452249753f, 0.125f -}; - -static const float g2_Q4[] = { - -0.05908211155639f, -0.04871498374946f, 0.0f, 0.07778723915851f, - 0.16486303567403f, 0.23279856662996f, 0.25f -}; - -static void make_filters_from_proto(float (*filter)[7][2], const float *proto, int bands) -{ - int q, n; - for (q = 0; q < bands; q++) { - for (n = 0; n < 7; n++) { - double theta = 2 * M_PI * (q + 0.5) * (n - 6) / bands; - filter[q][n][0] = proto[n] * cos(theta); - filter[q][n][1] = proto[n] * -sin(theta); - } - } -} - -static void ps_tableinit(void) -{ - static const float ipdopd_sin[] = { 0, M_SQRT1_2, 1, M_SQRT1_2, 0, -M_SQRT1_2, -1, -M_SQRT1_2 }; - static const float ipdopd_cos[] = { 1, M_SQRT1_2, 0, -M_SQRT1_2, -1, -M_SQRT1_2, 0, M_SQRT1_2 }; - int pd0, pd1, pd2; - - static const float iid_par_dequant[] = { - //iid_par_dequant_default - 0.05623413251903, 0.12589254117942, 0.19952623149689, 0.31622776601684, - 0.44668359215096, 0.63095734448019, 0.79432823472428, 1, - 1.25892541179417, 1.58489319246111, 2.23872113856834, 3.16227766016838, - 5.01187233627272, 7.94328234724282, 17.7827941003892, - //iid_par_dequant_fine - 0.00316227766017, 0.00562341325190, 0.01, 0.01778279410039, - 0.03162277660168, 0.05623413251903, 0.07943282347243, 0.11220184543020, - 0.15848931924611, 0.22387211385683, 0.31622776601684, 0.39810717055350, - 0.50118723362727, 0.63095734448019, 0.79432823472428, 1, - 1.25892541179417, 1.58489319246111, 1.99526231496888, 2.51188643150958, - 3.16227766016838, 4.46683592150963, 6.30957344480193, 8.91250938133745, - 12.5892541179417, 17.7827941003892, 31.6227766016838, 56.2341325190349, - 100, 177.827941003892, 316.227766016837, - }; - static const float icc_invq[] = { - 1, 0.937, 0.84118, 0.60092, 0.36764, 0, -0.589, -1 - }; - static const float acos_icc_invq[] = { - 0, 0.35685527, 0.57133466, 0.92614472, 1.1943263, M_PI/2, 2.2006171, M_PI - }; - int iid, icc; - - int k, m; - static const int8_t f_center_20[] = { - -3, -1, 1, 3, 5, 7, 10, 14, 18, 22, - }; - static const int8_t f_center_34[] = { - 2, 6, 10, 14, 18, 22, 26, 30, - 34,-10, -6, -2, 51, 57, 15, 21, - 27, 33, 39, 45, 54, 66, 78, 42, - 102, 66, 78, 90,102,114,126, 90, - }; - static const float fractional_delay_links[] = { 0.43f, 0.75f, 0.347f }; - const float fractional_delay_gain = 0.39f; - - for (pd0 = 0; pd0 < 8; pd0++) { - float pd0_re = ipdopd_cos[pd0]; - float pd0_im = ipdopd_sin[pd0]; - for (pd1 = 0; pd1 < 8; pd1++) { - float pd1_re = ipdopd_cos[pd1]; - float pd1_im = ipdopd_sin[pd1]; - for (pd2 = 0; pd2 < 8; pd2++) { - float pd2_re = ipdopd_cos[pd2]; - float pd2_im = ipdopd_sin[pd2]; - float re_smooth = 0.25f * pd0_re + 0.5f * pd1_re + pd2_re; - float im_smooth = 0.25f * pd0_im + 0.5f * pd1_im + pd2_im; - float pd_mag = 1 / sqrt(im_smooth * im_smooth + re_smooth * re_smooth); - pd_re_smooth[pd0*64+pd1*8+pd2] = re_smooth * pd_mag; - pd_im_smooth[pd0*64+pd1*8+pd2] = im_smooth * pd_mag; - } - } - } - - for (iid = 0; iid < 46; iid++) { - float c = iid_par_dequant[iid]; ///< Linear Inter-channel Intensity Difference - float c1 = (float)M_SQRT2 / sqrtf(1.0f + c*c); - float c2 = c * c1; - for (icc = 0; icc < 8; icc++) { - /*if (PS_BASELINE || ps->icc_mode < 3)*/ { - float alpha = 0.5f * acos_icc_invq[icc]; - float beta = alpha * (c1 - c2) * (float)M_SQRT1_2; - HA[iid][icc][0] = c2 * cosf(beta + alpha); - HA[iid][icc][1] = c1 * cosf(beta - alpha); - HA[iid][icc][2] = c2 * sinf(beta + alpha); - HA[iid][icc][3] = c1 * sinf(beta - alpha); - } /* else */ { - float alpha, gamma, mu, rho; - float alpha_c, alpha_s, gamma_c, gamma_s; - rho = FFMAX(icc_invq[icc], 0.05f); - alpha = 0.5f * atan2f(2.0f * c * rho, c*c - 1.0f); - mu = c + 1.0f / c; - mu = sqrtf(1 + (4 * rho * rho - 4)/(mu * mu)); - gamma = atanf(sqrtf((1.0f - mu)/(1.0f + mu))); - if (alpha < 0) alpha += M_PI/2; - alpha_c = cosf(alpha); - alpha_s = sinf(alpha); - gamma_c = cosf(gamma); - gamma_s = sinf(gamma); - HB[iid][icc][0] = M_SQRT2 * alpha_c * gamma_c; - HB[iid][icc][1] = M_SQRT2 * alpha_s * gamma_c; - HB[iid][icc][2] = -M_SQRT2 * alpha_s * gamma_s; - HB[iid][icc][3] = M_SQRT2 * alpha_c * gamma_s; - } - } - } - - for (k = 0; k < NR_ALLPASS_BANDS20; k++) { - double f_center, theta; - if (k < FF_ARRAY_ELEMS(f_center_20)) - f_center = f_center_20[k] * 0.125; - else - f_center = k - 6.5f; - for (m = 0; m < PS_AP_LINKS; m++) { - theta = -M_PI * fractional_delay_links[m] * f_center; - Q_fract_allpass[0][k][m][0] = cos(theta); - Q_fract_allpass[0][k][m][1] = sin(theta); - } - theta = -M_PI*fractional_delay_gain*f_center; - phi_fract[0][k][0] = cos(theta); - phi_fract[0][k][1] = sin(theta); - } - for (k = 0; k < NR_ALLPASS_BANDS34; k++) { - double f_center, theta; - if (k < FF_ARRAY_ELEMS(f_center_34)) - f_center = f_center_34[k] / 24.; - else - f_center = k - 26.5f; - for (m = 0; m < PS_AP_LINKS; m++) { - theta = -M_PI * fractional_delay_links[m] * f_center; - Q_fract_allpass[1][k][m][0] = cos(theta); - Q_fract_allpass[1][k][m][1] = sin(theta); - } - theta = -M_PI*fractional_delay_gain*f_center; - phi_fract[1][k][0] = cos(theta); - phi_fract[1][k][1] = sin(theta); - } - - make_filters_from_proto(f20_0_8, g0_Q8, 8); - make_filters_from_proto(f34_0_12, g0_Q12, 12); - make_filters_from_proto(f34_1_8, g1_Q8, 8); - make_filters_from_proto(f34_2_4, g2_Q4, 4); -} -#endif /* CONFIG_HARDCODED_TABLES */ - -#endif /* AACPS_TABLEGEN_H */ +/*
+ * Header file for hardcoded Parametric Stereo tables
+ *
+ * Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AACPS_TABLEGEN_H
+#define AACPS_TABLEGEN_H
+
+#include <stdint.h>
+
+#if CONFIG_HARDCODED_TABLES
+#define ps_tableinit()
+#include "libavcodec/aacps_tables.h"
+#else
+#include "libavutil/common.h"
+#include "libavutil/mathematics.h"
+#define NR_ALLPASS_BANDS20 30
+#define NR_ALLPASS_BANDS34 50
+#define PS_AP_LINKS 3
+static float pd_re_smooth[8*8*8];
+static float pd_im_smooth[8*8*8];
+static float HA[46][8][4];
+static float HB[46][8][4];
+static float f20_0_8 [ 8][7][2];
+static float f34_0_12[12][7][2];
+static float f34_1_8 [ 8][7][2];
+static float f34_2_4 [ 4][7][2];
+static float Q_fract_allpass[2][50][3][2];
+static float phi_fract[2][50][2];
+
+static const float g0_Q8[] = {
+ 0.00746082949812f, 0.02270420949825f, 0.04546865930473f, 0.07266113929591f,
+ 0.09885108575264f, 0.11793710567217f, 0.125f
+};
+
+static const float g0_Q12[] = {
+ 0.04081179924692f, 0.03812810994926f, 0.05144908135699f, 0.06399831151592f,
+ 0.07428313801106f, 0.08100347892914f, 0.08333333333333f
+};
+
+static const float g1_Q8[] = {
+ 0.01565675600122f, 0.03752716391991f, 0.05417891378782f, 0.08417044116767f,
+ 0.10307344158036f, 0.12222452249753f, 0.125f
+};
+
+static const float g2_Q4[] = {
+ -0.05908211155639f, -0.04871498374946f, 0.0f, 0.07778723915851f,
+ 0.16486303567403f, 0.23279856662996f, 0.25f
+};
+
+static void make_filters_from_proto(float (*filter)[7][2], const float *proto, int bands)
+{
+ int q, n;
+ for (q = 0; q < bands; q++) {
+ for (n = 0; n < 7; n++) {
+ double theta = 2 * M_PI * (q + 0.5) * (n - 6) / bands;
+ filter[q][n][0] = proto[n] * cos(theta);
+ filter[q][n][1] = proto[n] * -sin(theta);
+ }
+ }
+}
+
+static void ps_tableinit(void)
+{
+ static const float ipdopd_sin[] = { 0, M_SQRT1_2, 1, M_SQRT1_2, 0, -M_SQRT1_2, -1, -M_SQRT1_2 };
+ static const float ipdopd_cos[] = { 1, M_SQRT1_2, 0, -M_SQRT1_2, -1, -M_SQRT1_2, 0, M_SQRT1_2 };
+ int pd0, pd1, pd2;
+
+ static const float iid_par_dequant[] = {
+ //iid_par_dequant_default
+ 0.05623413251903, 0.12589254117942, 0.19952623149689, 0.31622776601684,
+ 0.44668359215096, 0.63095734448019, 0.79432823472428, 1,
+ 1.25892541179417, 1.58489319246111, 2.23872113856834, 3.16227766016838,
+ 5.01187233627272, 7.94328234724282, 17.7827941003892,
+ //iid_par_dequant_fine
+ 0.00316227766017, 0.00562341325190, 0.01, 0.01778279410039,
+ 0.03162277660168, 0.05623413251903, 0.07943282347243, 0.11220184543020,
+ 0.15848931924611, 0.22387211385683, 0.31622776601684, 0.39810717055350,
+ 0.50118723362727, 0.63095734448019, 0.79432823472428, 1,
+ 1.25892541179417, 1.58489319246111, 1.99526231496888, 2.51188643150958,
+ 3.16227766016838, 4.46683592150963, 6.30957344480193, 8.91250938133745,
+ 12.5892541179417, 17.7827941003892, 31.6227766016838, 56.2341325190349,
+ 100, 177.827941003892, 316.227766016837,
+ };
+ static const float icc_invq[] = {
+ 1, 0.937, 0.84118, 0.60092, 0.36764, 0, -0.589, -1
+ };
+ static const float acos_icc_invq[] = {
+ 0, 0.35685527, 0.57133466, 0.92614472, 1.1943263, M_PI/2, 2.2006171, M_PI
+ };
+ int iid, icc;
+
+ int k, m;
+ static const int8_t f_center_20[] = {
+ -3, -1, 1, 3, 5, 7, 10, 14, 18, 22,
+ };
+ static const int8_t f_center_34[] = {
+ 2, 6, 10, 14, 18, 22, 26, 30,
+ 34,-10, -6, -2, 51, 57, 15, 21,
+ 27, 33, 39, 45, 54, 66, 78, 42,
+ 102, 66, 78, 90,102,114,126, 90,
+ };
+ static const float fractional_delay_links[] = { 0.43f, 0.75f, 0.347f };
+ const float fractional_delay_gain = 0.39f;
+
+ for (pd0 = 0; pd0 < 8; pd0++) {
+ float pd0_re = ipdopd_cos[pd0];
+ float pd0_im = ipdopd_sin[pd0];
+ for (pd1 = 0; pd1 < 8; pd1++) {
+ float pd1_re = ipdopd_cos[pd1];
+ float pd1_im = ipdopd_sin[pd1];
+ for (pd2 = 0; pd2 < 8; pd2++) {
+ float pd2_re = ipdopd_cos[pd2];
+ float pd2_im = ipdopd_sin[pd2];
+ float re_smooth = 0.25f * pd0_re + 0.5f * pd1_re + pd2_re;
+ float im_smooth = 0.25f * pd0_im + 0.5f * pd1_im + pd2_im;
+ float pd_mag = 1 / sqrt(im_smooth * im_smooth + re_smooth * re_smooth);
+ pd_re_smooth[pd0*64+pd1*8+pd2] = re_smooth * pd_mag;
+ pd_im_smooth[pd0*64+pd1*8+pd2] = im_smooth * pd_mag;
+ }
+ }
+ }
+
+ for (iid = 0; iid < 46; iid++) {
+ float c = iid_par_dequant[iid]; ///< Linear Inter-channel Intensity Difference
+ float c1 = (float)M_SQRT2 / sqrtf(1.0f + c*c);
+ float c2 = c * c1;
+ for (icc = 0; icc < 8; icc++) {
+ /*if (PS_BASELINE || ps->icc_mode < 3)*/ {
+ float alpha = 0.5f * acos_icc_invq[icc];
+ float beta = alpha * (c1 - c2) * (float)M_SQRT1_2;
+ HA[iid][icc][0] = c2 * cosf(beta + alpha);
+ HA[iid][icc][1] = c1 * cosf(beta - alpha);
+ HA[iid][icc][2] = c2 * sinf(beta + alpha);
+ HA[iid][icc][3] = c1 * sinf(beta - alpha);
+ } /* else */ {
+ float alpha, gamma, mu, rho;
+ float alpha_c, alpha_s, gamma_c, gamma_s;
+ rho = FFMAX(icc_invq[icc], 0.05f);
+ alpha = 0.5f * atan2f(2.0f * c * rho, c*c - 1.0f);
+ mu = c + 1.0f / c;
+ mu = sqrtf(1 + (4 * rho * rho - 4)/(mu * mu));
+ gamma = atanf(sqrtf((1.0f - mu)/(1.0f + mu)));
+ if (alpha < 0) alpha += M_PI/2;
+ alpha_c = cosf(alpha);
+ alpha_s = sinf(alpha);
+ gamma_c = cosf(gamma);
+ gamma_s = sinf(gamma);
+ HB[iid][icc][0] = M_SQRT2 * alpha_c * gamma_c;
+ HB[iid][icc][1] = M_SQRT2 * alpha_s * gamma_c;
+ HB[iid][icc][2] = -M_SQRT2 * alpha_s * gamma_s;
+ HB[iid][icc][3] = M_SQRT2 * alpha_c * gamma_s;
+ }
+ }
+ }
+
+ for (k = 0; k < NR_ALLPASS_BANDS20; k++) {
+ double f_center, theta;
+ if (k < FF_ARRAY_ELEMS(f_center_20))
+ f_center = f_center_20[k] * 0.125;
+ else
+ f_center = k - 6.5f;
+ for (m = 0; m < PS_AP_LINKS; m++) {
+ theta = -M_PI * fractional_delay_links[m] * f_center;
+ Q_fract_allpass[0][k][m][0] = cos(theta);
+ Q_fract_allpass[0][k][m][1] = sin(theta);
+ }
+ theta = -M_PI*fractional_delay_gain*f_center;
+ phi_fract[0][k][0] = cos(theta);
+ phi_fract[0][k][1] = sin(theta);
+ }
+ for (k = 0; k < NR_ALLPASS_BANDS34; k++) {
+ double f_center, theta;
+ if (k < FF_ARRAY_ELEMS(f_center_34))
+ f_center = f_center_34[k] / 24.;
+ else
+ f_center = k - 26.5f;
+ for (m = 0; m < PS_AP_LINKS; m++) {
+ theta = -M_PI * fractional_delay_links[m] * f_center;
+ Q_fract_allpass[1][k][m][0] = cos(theta);
+ Q_fract_allpass[1][k][m][1] = sin(theta);
+ }
+ theta = -M_PI*fractional_delay_gain*f_center;
+ phi_fract[1][k][0] = cos(theta);
+ phi_fract[1][k][1] = sin(theta);
+ }
+
+ make_filters_from_proto(f20_0_8, g0_Q8, 8);
+ make_filters_from_proto(f34_0_12, g0_Q12, 12);
+ make_filters_from_proto(f34_1_8, g1_Q8, 8);
+ make_filters_from_proto(f34_2_4, g2_Q4, 4);
+}
+#endif /* CONFIG_HARDCODED_TABLES */
+
+#endif /* AACPS_TABLEGEN_H */
diff --git a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacpsdata.c b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacpsdata.c index 675bd8e2b..238fd09ad 100644 --- a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacpsdata.c +++ b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacpsdata.c @@ -1,163 +1,163 @@ -/* - * MPEG-4 Parametric Stereo data tables - * Copyright (c) 2010 Alex Converse <alex.converse@gmail.com> - * - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -static const uint8_t huff_iid_df1_bits[] = { - 18, 18, 18, 18, 18, 18, 18, 18, 18, 17, 18, 17, 17, 16, 16, 15, 14, 14, - 13, 12, 12, 11, 10, 10, 8, 7, 6, 5, 4, 3, 1, 3, 4, 5, 6, 7, - 8, 9, 10, 11, 11, 12, 13, 14, 14, 15, 16, 16, 17, 17, 18, 17, 18, 18, - 18, 18, 18, 18, 18, 18, 18, -}; - -static const uint32_t huff_iid_df1_codes[] = { - 0x01FEB4, 0x01FEB5, 0x01FD76, 0x01FD77, 0x01FD74, 0x01FD75, 0x01FE8A, - 0x01FE8B, 0x01FE88, 0x00FE80, 0x01FEB6, 0x00FE82, 0x00FEB8, 0x007F42, - 0x007FAE, 0x003FAF, 0x001FD1, 0x001FE9, 0x000FE9, 0x0007EA, 0x0007FB, - 0x0003FB, 0x0001FB, 0x0001FF, 0x00007C, 0x00003C, 0x00001C, 0x00000C, - 0x000000, 0x000001, 0x000001, 0x000002, 0x000001, 0x00000D, 0x00001D, - 0x00003D, 0x00007D, 0x0000FC, 0x0001FC, 0x0003FC, 0x0003F4, 0x0007EB, - 0x000FEA, 0x001FEA, 0x001FD6, 0x003FD0, 0x007FAF, 0x007F43, 0x00FEB9, - 0x00FE83, 0x01FEB7, 0x00FE81, 0x01FE89, 0x01FE8E, 0x01FE8F, 0x01FE8C, - 0x01FE8D, 0x01FEB2, 0x01FEB3, 0x01FEB0, 0x01FEB1, -}; - -static const uint8_t huff_iid_dt1_bits[] = { - 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 14, 14, 13, - 13, 13, 12, 12, 11, 10, 9, 9, 7, 6, 5, 3, 1, 2, 5, 6, 7, 8, - 9, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, -}; - -static const uint16_t huff_iid_dt1_codes[] = { - 0x004ED4, 0x004ED5, 0x004ECE, 0x004ECF, 0x004ECC, 0x004ED6, 0x004ED8, - 0x004F46, 0x004F60, 0x002718, 0x002719, 0x002764, 0x002765, 0x00276D, - 0x0027B1, 0x0013B7, 0x0013D6, 0x0009C7, 0x0009E9, 0x0009ED, 0x0004EE, - 0x0004F7, 0x000278, 0x000139, 0x00009A, 0x00009F, 0x000020, 0x000011, - 0x00000A, 0x000003, 0x000001, 0x000000, 0x00000B, 0x000012, 0x000021, - 0x00004C, 0x00009B, 0x00013A, 0x000279, 0x000270, 0x0004EF, 0x0004E2, - 0x0009EA, 0x0009D8, 0x0013D7, 0x0013D0, 0x0027B2, 0x0027A2, 0x00271A, - 0x00271B, 0x004F66, 0x004F67, 0x004F61, 0x004F47, 0x004ED9, 0x004ED7, - 0x004ECD, 0x004ED2, 0x004ED3, 0x004ED0, 0x004ED1, -}; - -static const uint8_t huff_iid_df0_bits[] = { - 17, 17, 17, 17, 16, 15, 13, 10, 9, 7, 6, 5, 4, 3, 1, 3, 4, 5, - 6, 6, 8, 11, 13, 14, 14, 15, 17, 18, 18, -}; - -static const uint32_t huff_iid_df0_codes[] = { - 0x01FFFB, 0x01FFFC, 0x01FFFD, 0x01FFFA, 0x00FFFC, 0x007FFC, 0x001FFD, - 0x0003FE, 0x0001FE, 0x00007E, 0x00003C, 0x00001D, 0x00000D, 0x000005, - 0x000000, 0x000004, 0x00000C, 0x00001C, 0x00003D, 0x00003E, 0x0000FE, - 0x0007FE, 0x001FFC, 0x003FFC, 0x003FFD, 0x007FFD, 0x01FFFE, 0x03FFFE, - 0x03FFFF, -}; - -static const uint8_t huff_iid_dt0_bits[] = { - 19, 19, 19, 20, 20, 20, 17, 15, 12, 10, 8, 6, 4, 2, 1, 3, 5, 7, - 9, 11, 13, 14, 17, 19, 20, 20, 20, 20, 20, -}; - -static const uint32_t huff_iid_dt0_codes[] = { - 0x07FFF9, 0x07FFFA, 0x07FFFB, 0x0FFFF8, 0x0FFFF9, 0x0FFFFA, 0x01FFFD, - 0x007FFE, 0x000FFE, 0x0003FE, 0x0000FE, 0x00003E, 0x00000E, 0x000002, - 0x000000, 0x000006, 0x00001E, 0x00007E, 0x0001FE, 0x0007FE, 0x001FFE, - 0x003FFE, 0x01FFFC, 0x07FFF8, 0x0FFFFB, 0x0FFFFC, 0x0FFFFD, 0x0FFFFE, - 0x0FFFFF, -}; - -static const uint8_t huff_icc_df_bits[] = { - 14, 14, 12, 10, 7, 5, 3, 1, 2, 4, 6, 8, 9, 11, 13, -}; - -static const uint16_t huff_icc_df_codes[] = { - 0x3FFF, 0x3FFE, 0x0FFE, 0x03FE, 0x007E, 0x001E, 0x0006, 0x0000, - 0x0002, 0x000E, 0x003E, 0x00FE, 0x01FE, 0x07FE, 0x1FFE, -}; - -static const uint8_t huff_icc_dt_bits[] = { - 14, 13, 11, 9, 7, 5, 3, 1, 2, 4, 6, 8, 10, 12, 14, -}; - -static const uint16_t huff_icc_dt_codes[] = { - 0x3FFE, 0x1FFE, 0x07FE, 0x01FE, 0x007E, 0x001E, 0x0006, 0x0000, - 0x0002, 0x000E, 0x003E, 0x00FE, 0x03FE, 0x0FFE, 0x3FFF, -}; - -static const uint8_t huff_ipd_df_bits[] = { - 1, 3, 4, 4, 4, 4, 4, 4, -}; - -static const uint8_t huff_ipd_df_codes[] = { - 0x01, 0x00, 0x06, 0x04, 0x02, 0x03, 0x05, 0x07, -}; - -static const uint8_t huff_ipd_dt_bits[] = { - 1, 3, 4, 5, 5, 4, 4, 3, -}; - -static const uint8_t huff_ipd_dt_codes[] = { - 0x01, 0x02, 0x02, 0x03, 0x02, 0x00, 0x03, 0x03, -}; - -static const uint8_t huff_opd_df_bits[] = { - 1, 3, 4, 4, 5, 5, 4, 3, -}; - -static const uint8_t huff_opd_df_codes[] = { - 0x01, 0x01, 0x06, 0x04, 0x0F, 0x0E, 0x05, 0x00, -}; - -static const uint8_t huff_opd_dt_bits[] = { - 1, 3, 4, 5, 5, 4, 4, 3, -}; - -static const uint8_t huff_opd_dt_codes[] = { - 0x01, 0x02, 0x01, 0x07, 0x06, 0x00, 0x02, 0x03, -}; - -static const int8_t huff_offset[] = { - 30, 30, - 14, 14, - 7, 7, - 0, 0, - 0, 0, -}; - -///Table 8.48 -static const int8_t k_to_i_20[] = { - 1, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 14, 15, - 15, 15, 16, 16, 16, 16, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, - 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19 -}; -///Table 8.49 -static const int8_t k_to_i_34[] = { - 0, 1, 2, 3, 4, 5, 6, 6, 7, 2, 1, 0, 10, 10, 4, 5, 6, 7, 8, - 9, 10, 11, 12, 9, 14, 11, 12, 13, 14, 15, 16, 13, 16, 17, 18, 19, 20, 21, - 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 27, 28, 28, 28, 29, 29, 29, - 30, 30, 30, 31, 31, 31, 31, 32, 32, 32, 32, 33, 33, 33, 33, 33, 33, 33, 33, - 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33 -}; - -static const float g1_Q2[] = { - 0.0f, 0.01899487526049f, 0.0f, -0.07293139167538f, - 0.0f, 0.30596630545168f, 0.5f -}; +/*
+ * MPEG-4 Parametric Stereo data tables
+ * Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+static const uint8_t huff_iid_df1_bits[] = {
+ 18, 18, 18, 18, 18, 18, 18, 18, 18, 17, 18, 17, 17, 16, 16, 15, 14, 14,
+ 13, 12, 12, 11, 10, 10, 8, 7, 6, 5, 4, 3, 1, 3, 4, 5, 6, 7,
+ 8, 9, 10, 11, 11, 12, 13, 14, 14, 15, 16, 16, 17, 17, 18, 17, 18, 18,
+ 18, 18, 18, 18, 18, 18, 18,
+};
+
+static const uint32_t huff_iid_df1_codes[] = {
+ 0x01FEB4, 0x01FEB5, 0x01FD76, 0x01FD77, 0x01FD74, 0x01FD75, 0x01FE8A,
+ 0x01FE8B, 0x01FE88, 0x00FE80, 0x01FEB6, 0x00FE82, 0x00FEB8, 0x007F42,
+ 0x007FAE, 0x003FAF, 0x001FD1, 0x001FE9, 0x000FE9, 0x0007EA, 0x0007FB,
+ 0x0003FB, 0x0001FB, 0x0001FF, 0x00007C, 0x00003C, 0x00001C, 0x00000C,
+ 0x000000, 0x000001, 0x000001, 0x000002, 0x000001, 0x00000D, 0x00001D,
+ 0x00003D, 0x00007D, 0x0000FC, 0x0001FC, 0x0003FC, 0x0003F4, 0x0007EB,
+ 0x000FEA, 0x001FEA, 0x001FD6, 0x003FD0, 0x007FAF, 0x007F43, 0x00FEB9,
+ 0x00FE83, 0x01FEB7, 0x00FE81, 0x01FE89, 0x01FE8E, 0x01FE8F, 0x01FE8C,
+ 0x01FE8D, 0x01FEB2, 0x01FEB3, 0x01FEB0, 0x01FEB1,
+};
+
+static const uint8_t huff_iid_dt1_bits[] = {
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 14, 14, 13,
+ 13, 13, 12, 12, 11, 10, 9, 9, 7, 6, 5, 3, 1, 2, 5, 6, 7, 8,
+ 9, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16,
+};
+
+static const uint16_t huff_iid_dt1_codes[] = {
+ 0x004ED4, 0x004ED5, 0x004ECE, 0x004ECF, 0x004ECC, 0x004ED6, 0x004ED8,
+ 0x004F46, 0x004F60, 0x002718, 0x002719, 0x002764, 0x002765, 0x00276D,
+ 0x0027B1, 0x0013B7, 0x0013D6, 0x0009C7, 0x0009E9, 0x0009ED, 0x0004EE,
+ 0x0004F7, 0x000278, 0x000139, 0x00009A, 0x00009F, 0x000020, 0x000011,
+ 0x00000A, 0x000003, 0x000001, 0x000000, 0x00000B, 0x000012, 0x000021,
+ 0x00004C, 0x00009B, 0x00013A, 0x000279, 0x000270, 0x0004EF, 0x0004E2,
+ 0x0009EA, 0x0009D8, 0x0013D7, 0x0013D0, 0x0027B2, 0x0027A2, 0x00271A,
+ 0x00271B, 0x004F66, 0x004F67, 0x004F61, 0x004F47, 0x004ED9, 0x004ED7,
+ 0x004ECD, 0x004ED2, 0x004ED3, 0x004ED0, 0x004ED1,
+};
+
+static const uint8_t huff_iid_df0_bits[] = {
+ 17, 17, 17, 17, 16, 15, 13, 10, 9, 7, 6, 5, 4, 3, 1, 3, 4, 5,
+ 6, 6, 8, 11, 13, 14, 14, 15, 17, 18, 18,
+};
+
+static const uint32_t huff_iid_df0_codes[] = {
+ 0x01FFFB, 0x01FFFC, 0x01FFFD, 0x01FFFA, 0x00FFFC, 0x007FFC, 0x001FFD,
+ 0x0003FE, 0x0001FE, 0x00007E, 0x00003C, 0x00001D, 0x00000D, 0x000005,
+ 0x000000, 0x000004, 0x00000C, 0x00001C, 0x00003D, 0x00003E, 0x0000FE,
+ 0x0007FE, 0x001FFC, 0x003FFC, 0x003FFD, 0x007FFD, 0x01FFFE, 0x03FFFE,
+ 0x03FFFF,
+};
+
+static const uint8_t huff_iid_dt0_bits[] = {
+ 19, 19, 19, 20, 20, 20, 17, 15, 12, 10, 8, 6, 4, 2, 1, 3, 5, 7,
+ 9, 11, 13, 14, 17, 19, 20, 20, 20, 20, 20,
+};
+
+static const uint32_t huff_iid_dt0_codes[] = {
+ 0x07FFF9, 0x07FFFA, 0x07FFFB, 0x0FFFF8, 0x0FFFF9, 0x0FFFFA, 0x01FFFD,
+ 0x007FFE, 0x000FFE, 0x0003FE, 0x0000FE, 0x00003E, 0x00000E, 0x000002,
+ 0x000000, 0x000006, 0x00001E, 0x00007E, 0x0001FE, 0x0007FE, 0x001FFE,
+ 0x003FFE, 0x01FFFC, 0x07FFF8, 0x0FFFFB, 0x0FFFFC, 0x0FFFFD, 0x0FFFFE,
+ 0x0FFFFF,
+};
+
+static const uint8_t huff_icc_df_bits[] = {
+ 14, 14, 12, 10, 7, 5, 3, 1, 2, 4, 6, 8, 9, 11, 13,
+};
+
+static const uint16_t huff_icc_df_codes[] = {
+ 0x3FFF, 0x3FFE, 0x0FFE, 0x03FE, 0x007E, 0x001E, 0x0006, 0x0000,
+ 0x0002, 0x000E, 0x003E, 0x00FE, 0x01FE, 0x07FE, 0x1FFE,
+};
+
+static const uint8_t huff_icc_dt_bits[] = {
+ 14, 13, 11, 9, 7, 5, 3, 1, 2, 4, 6, 8, 10, 12, 14,
+};
+
+static const uint16_t huff_icc_dt_codes[] = {
+ 0x3FFE, 0x1FFE, 0x07FE, 0x01FE, 0x007E, 0x001E, 0x0006, 0x0000,
+ 0x0002, 0x000E, 0x003E, 0x00FE, 0x03FE, 0x0FFE, 0x3FFF,
+};
+
+static const uint8_t huff_ipd_df_bits[] = {
+ 1, 3, 4, 4, 4, 4, 4, 4,
+};
+
+static const uint8_t huff_ipd_df_codes[] = {
+ 0x01, 0x00, 0x06, 0x04, 0x02, 0x03, 0x05, 0x07,
+};
+
+static const uint8_t huff_ipd_dt_bits[] = {
+ 1, 3, 4, 5, 5, 4, 4, 3,
+};
+
+static const uint8_t huff_ipd_dt_codes[] = {
+ 0x01, 0x02, 0x02, 0x03, 0x02, 0x00, 0x03, 0x03,
+};
+
+static const uint8_t huff_opd_df_bits[] = {
+ 1, 3, 4, 4, 5, 5, 4, 3,
+};
+
+static const uint8_t huff_opd_df_codes[] = {
+ 0x01, 0x01, 0x06, 0x04, 0x0F, 0x0E, 0x05, 0x00,
+};
+
+static const uint8_t huff_opd_dt_bits[] = {
+ 1, 3, 4, 5, 5, 4, 4, 3,
+};
+
+static const uint8_t huff_opd_dt_codes[] = {
+ 0x01, 0x02, 0x01, 0x07, 0x06, 0x00, 0x02, 0x03,
+};
+
+static const int8_t huff_offset[] = {
+ 30, 30,
+ 14, 14,
+ 7, 7,
+ 0, 0,
+ 0, 0,
+};
+
+///Table 8.48
+static const int8_t k_to_i_20[] = {
+ 1, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 14, 15,
+ 15, 15, 16, 16, 16, 16, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18,
+ 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19
+};
+///Table 8.49
+static const int8_t k_to_i_34[] = {
+ 0, 1, 2, 3, 4, 5, 6, 6, 7, 2, 1, 0, 10, 10, 4, 5, 6, 7, 8,
+ 9, 10, 11, 12, 9, 14, 11, 12, 13, 14, 15, 16, 13, 16, 17, 18, 19, 20, 21,
+ 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 27, 28, 28, 28, 29, 29, 29,
+ 30, 30, 30, 31, 31, 31, 31, 32, 32, 32, 32, 33, 33, 33, 33, 33, 33, 33, 33,
+ 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33
+};
+
+static const float g1_Q2[] = {
+ 0.0f, 0.01899487526049f, 0.0f, -0.07293139167538f,
+ 0.0f, 0.30596630545168f, 0.5f
+};
diff --git a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacsbr.c b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacsbr.c index fc87d3dbc..a41cca87f 100644 --- a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacsbr.c +++ b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacsbr.c @@ -1,1692 +1,1692 @@ -/* - * AAC Spectral Band Replication decoding functions - * Copyright (c) 2008-2009 Robert Swain ( rob opendot cl ) - * Copyright (c) 2009-2010 Alex Converse <alex.converse@gmail.com> - * - * This file is part of FFmpeg. - * - * FFmpeg is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * FFmpeg is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/** - * @file - * AAC Spectral Band Replication decoding functions - * @author Robert Swain ( rob opendot cl ) - */ - -#include "aac.h" -#include "sbr.h" -#include "aacsbr.h" -#include "aacsbrdata.h" -#include "fft.h" -#include "aacps.h" -#include "sbrdsp.h" -#include "libavutil/libm.h" -#include "libavutil/avassert.h" - -#include <stdint.h> -#include <float.h> -#include <math.h> - -#define ENVELOPE_ADJUSTMENT_OFFSET 2 -#define NOISE_FLOOR_OFFSET 6.0f - -/** - * SBR VLC tables - */ -enum { - T_HUFFMAN_ENV_1_5DB, - F_HUFFMAN_ENV_1_5DB, - T_HUFFMAN_ENV_BAL_1_5DB, - F_HUFFMAN_ENV_BAL_1_5DB, - T_HUFFMAN_ENV_3_0DB, - F_HUFFMAN_ENV_3_0DB, - T_HUFFMAN_ENV_BAL_3_0DB, - F_HUFFMAN_ENV_BAL_3_0DB, - T_HUFFMAN_NOISE_3_0DB, - T_HUFFMAN_NOISE_BAL_3_0DB, -}; - -/** - * bs_frame_class - frame class of current SBR frame (14496-3 sp04 p98) - */ -enum { - FIXFIX, - FIXVAR, - VARFIX, - VARVAR, -}; - -enum { - EXTENSION_ID_PS = 2, -}; - -static VLC vlc_sbr[10]; -static const int8_t vlc_sbr_lav[10] = - { 60, 60, 24, 24, 31, 31, 12, 12, 31, 12 }; -static const DECLARE_ALIGNED(16, float, zero64)[64]; - -#define SBR_INIT_VLC_STATIC(num, size) \ - INIT_VLC_STATIC(&vlc_sbr[num], 9, sbr_tmp[num].table_size / sbr_tmp[num].elem_size, \ - sbr_tmp[num].sbr_bits , 1, 1, \ - sbr_tmp[num].sbr_codes, sbr_tmp[num].elem_size, sbr_tmp[num].elem_size, \ - size) - -#define SBR_VLC_ROW(name) \ - { name ## _codes, name ## _bits, sizeof(name ## _codes), sizeof(name ## _codes[0]) } - -av_cold void ff_aac_sbr_init(void) -{ - int n; - static const struct { - const void *sbr_codes, *sbr_bits; - const unsigned int table_size, elem_size; - } sbr_tmp[] = { - SBR_VLC_ROW(t_huffman_env_1_5dB), - SBR_VLC_ROW(f_huffman_env_1_5dB), - SBR_VLC_ROW(t_huffman_env_bal_1_5dB), - SBR_VLC_ROW(f_huffman_env_bal_1_5dB), - SBR_VLC_ROW(t_huffman_env_3_0dB), - SBR_VLC_ROW(f_huffman_env_3_0dB), - SBR_VLC_ROW(t_huffman_env_bal_3_0dB), - SBR_VLC_ROW(f_huffman_env_bal_3_0dB), - SBR_VLC_ROW(t_huffman_noise_3_0dB), - SBR_VLC_ROW(t_huffman_noise_bal_3_0dB), - }; - - // SBR VLC table initialization - SBR_INIT_VLC_STATIC(0, 1098); - SBR_INIT_VLC_STATIC(1, 1092); - SBR_INIT_VLC_STATIC(2, 768); - SBR_INIT_VLC_STATIC(3, 1026); - SBR_INIT_VLC_STATIC(4, 1058); - SBR_INIT_VLC_STATIC(5, 1052); - SBR_INIT_VLC_STATIC(6, 544); - SBR_INIT_VLC_STATIC(7, 544); - SBR_INIT_VLC_STATIC(8, 592); - SBR_INIT_VLC_STATIC(9, 512); - - for (n = 1; n < 320; n++) - sbr_qmf_window_us[320 + n] = sbr_qmf_window_us[320 - n]; - sbr_qmf_window_us[384] = -sbr_qmf_window_us[384]; - sbr_qmf_window_us[512] = -sbr_qmf_window_us[512]; - - for (n = 0; n < 320; n++) - sbr_qmf_window_ds[n] = sbr_qmf_window_us[2*n]; - - ff_ps_init(); -} - -av_cold void ff_aac_sbr_ctx_init(AACContext *ac, SpectralBandReplication *sbr) -{ - float mdct_scale; - if(sbr->mdct.mdct_bits) - return; - sbr->kx[0] = sbr->kx[1] = 32; //Typo in spec, kx' inits to 32 - sbr->data[0].e_a[1] = sbr->data[1].e_a[1] = -1; - sbr->data[0].synthesis_filterbank_samples_offset = SBR_SYNTHESIS_BUF_SIZE - (1280 - 128); - sbr->data[1].synthesis_filterbank_samples_offset = SBR_SYNTHESIS_BUF_SIZE - (1280 - 128); - /* SBR requires samples to be scaled to +/-32768.0 to work correctly. - * mdct scale factors are adjusted to scale up from +/-1.0 at analysis - * and scale back down at synthesis. */ - mdct_scale = ac->avctx->sample_fmt == AV_SAMPLE_FMT_FLT ? 32768.0f : 1.0f; - ff_mdct_init(&sbr->mdct, 7, 1, 1.0 / (64 * mdct_scale)); - ff_mdct_init(&sbr->mdct_ana, 7, 1, -2.0 * mdct_scale); - ff_ps_ctx_init(&sbr->ps); - ff_sbrdsp_init(&sbr->dsp); -} - -av_cold void ff_aac_sbr_ctx_close(SpectralBandReplication *sbr) -{ - ff_mdct_end(&sbr->mdct); - ff_mdct_end(&sbr->mdct_ana); -} - -static int qsort_comparison_function_int16(const void *a, const void *b) -{ - return *(const int16_t *)a - *(const int16_t *)b; -} - -static inline int in_table_int16(const int16_t *table, int last_el, int16_t needle) -{ - int i; - for (i = 0; i <= last_el; i++) - if (table[i] == needle) - return 1; - return 0; -} - -/// Limiter Frequency Band Table (14496-3 sp04 p198) -static void sbr_make_f_tablelim(SpectralBandReplication *sbr) -{ - int k; - if (sbr->bs_limiter_bands > 0) { - static const float bands_warped[3] = { 1.32715174233856803909f, //2^(0.49/1.2) - 1.18509277094158210129f, //2^(0.49/2) - 1.11987160404675912501f }; //2^(0.49/3) - const float lim_bands_per_octave_warped = bands_warped[sbr->bs_limiter_bands - 1]; - int16_t patch_borders[7]; - uint16_t *in = sbr->f_tablelim + 1, *out = sbr->f_tablelim; - - patch_borders[0] = sbr->kx[1]; - for (k = 1; k <= sbr->num_patches; k++) - patch_borders[k] = patch_borders[k-1] + sbr->patch_num_subbands[k-1]; - - memcpy(sbr->f_tablelim, sbr->f_tablelow, - (sbr->n[0] + 1) * sizeof(sbr->f_tablelow[0])); - if (sbr->num_patches > 1) - memcpy(sbr->f_tablelim + sbr->n[0] + 1, patch_borders + 1, - (sbr->num_patches - 1) * sizeof(patch_borders[0])); - - qsort(sbr->f_tablelim, sbr->num_patches + sbr->n[0], - sizeof(sbr->f_tablelim[0]), - qsort_comparison_function_int16); - - sbr->n_lim = sbr->n[0] + sbr->num_patches - 1; - while (out < sbr->f_tablelim + sbr->n_lim) { - if (*in >= *out * lim_bands_per_octave_warped) { - *++out = *in++; - } else if (*in == *out || - !in_table_int16(patch_borders, sbr->num_patches, *in)) { - in++; - sbr->n_lim--; - } else if (!in_table_int16(patch_borders, sbr->num_patches, *out)) { - *out = *in++; - sbr->n_lim--; - } else { - *++out = *in++; - } - } - } else { - sbr->f_tablelim[0] = sbr->f_tablelow[0]; - sbr->f_tablelim[1] = sbr->f_tablelow[sbr->n[0]]; - sbr->n_lim = 1; - } -} - -static unsigned int read_sbr_header(SpectralBandReplication *sbr, GetBitContext *gb) -{ - unsigned int cnt = get_bits_count(gb); - uint8_t bs_header_extra_1; - uint8_t bs_header_extra_2; - int old_bs_limiter_bands = sbr->bs_limiter_bands; - SpectrumParameters old_spectrum_params; - - sbr->start = 1; - - // Save last spectrum parameters variables to compare to new ones - memcpy(&old_spectrum_params, &sbr->spectrum_params, sizeof(SpectrumParameters)); - - sbr->bs_amp_res_header = get_bits1(gb); - sbr->spectrum_params.bs_start_freq = get_bits(gb, 4); - sbr->spectrum_params.bs_stop_freq = get_bits(gb, 4); - sbr->spectrum_params.bs_xover_band = get_bits(gb, 3); - skip_bits(gb, 2); // bs_reserved - - bs_header_extra_1 = get_bits1(gb); - bs_header_extra_2 = get_bits1(gb); - - if (bs_header_extra_1) { - sbr->spectrum_params.bs_freq_scale = get_bits(gb, 2); - sbr->spectrum_params.bs_alter_scale = get_bits1(gb); - sbr->spectrum_params.bs_noise_bands = get_bits(gb, 2); - } else { - sbr->spectrum_params.bs_freq_scale = 2; - sbr->spectrum_params.bs_alter_scale = 1; - sbr->spectrum_params.bs_noise_bands = 2; - } - - // Check if spectrum parameters changed - if (memcmp(&old_spectrum_params, &sbr->spectrum_params, sizeof(SpectrumParameters))) - sbr->reset = 1; - - if (bs_header_extra_2) { - sbr->bs_limiter_bands = get_bits(gb, 2); - sbr->bs_limiter_gains = get_bits(gb, 2); - sbr->bs_interpol_freq = get_bits1(gb); - sbr->bs_smoothing_mode = get_bits1(gb); - } else { - sbr->bs_limiter_bands = 2; - sbr->bs_limiter_gains = 2; - sbr->bs_interpol_freq = 1; - sbr->bs_smoothing_mode = 1; - } - - if (sbr->bs_limiter_bands != old_bs_limiter_bands && !sbr->reset) - sbr_make_f_tablelim(sbr); - - return get_bits_count(gb) - cnt; -} - -static int array_min_int16(const int16_t *array, int nel) -{ - int i, min = array[0]; - for (i = 1; i < nel; i++) - min = FFMIN(array[i], min); - return min; -} - -static void make_bands(int16_t* bands, int start, int stop, int num_bands) -{ - int k, previous, present; - float base, prod; - - base = powf((float)stop / start, 1.0f / num_bands); - prod = start; - previous = start; - - for (k = 0; k < num_bands-1; k++) { - prod *= base; - present = lrintf(prod); - bands[k] = present - previous; - previous = present; - } - bands[num_bands-1] = stop - previous; -} - -static int check_n_master(AVCodecContext *avctx, int n_master, int bs_xover_band) -{ - // Requirements (14496-3 sp04 p205) - if (n_master <= 0) { - av_log(avctx, AV_LOG_ERROR, "Invalid n_master: %d\n", n_master); - return -1; - } - if (bs_xover_band >= n_master) { - av_log(avctx, AV_LOG_ERROR, - "Invalid bitstream, crossover band index beyond array bounds: %d\n", - bs_xover_band); - return -1; - } - return 0; -} - -/// Master Frequency Band Table (14496-3 sp04 p194) -static int sbr_make_f_master(AACContext *ac, SpectralBandReplication *sbr, - SpectrumParameters *spectrum) -{ - unsigned int temp, max_qmf_subbands; - unsigned int start_min, stop_min; - int k; - const int8_t *sbr_offset_ptr; - int16_t stop_dk[13]; - - if (sbr->sample_rate < 32000) { - temp = 3000; - } else if (sbr->sample_rate < 64000) { - temp = 4000; - } else - temp = 5000; - - start_min = ((temp << 7) + (sbr->sample_rate >> 1)) / sbr->sample_rate; - stop_min = ((temp << 8) + (sbr->sample_rate >> 1)) / sbr->sample_rate; - - switch (sbr->sample_rate) { - case 16000: - sbr_offset_ptr = sbr_offset[0]; - break; - case 22050: - sbr_offset_ptr = sbr_offset[1]; - break; - case 24000: - sbr_offset_ptr = sbr_offset[2]; - break; - case 32000: - sbr_offset_ptr = sbr_offset[3]; - break; - case 44100: case 48000: case 64000: - sbr_offset_ptr = sbr_offset[4]; - break; - case 88200: case 96000: case 128000: case 176400: case 192000: - sbr_offset_ptr = sbr_offset[5]; - break; - default: - av_log(ac->avctx, AV_LOG_ERROR, - "Unsupported sample rate for SBR: %d\n", sbr->sample_rate); - return -1; - } - - sbr->k[0] = start_min + sbr_offset_ptr[spectrum->bs_start_freq]; - - if (spectrum->bs_stop_freq < 14) { - sbr->k[2] = stop_min; - make_bands(stop_dk, stop_min, 64, 13); - qsort(stop_dk, 13, sizeof(stop_dk[0]), qsort_comparison_function_int16); - for (k = 0; k < spectrum->bs_stop_freq; k++) - sbr->k[2] += stop_dk[k]; - } else if (spectrum->bs_stop_freq == 14) { - sbr->k[2] = 2*sbr->k[0]; - } else if (spectrum->bs_stop_freq == 15) { - sbr->k[2] = 3*sbr->k[0]; - } else { - av_log(ac->avctx, AV_LOG_ERROR, - "Invalid bs_stop_freq: %d\n", spectrum->bs_stop_freq); - return -1; - } - sbr->k[2] = FFMIN(64, sbr->k[2]); - - // Requirements (14496-3 sp04 p205) - if (sbr->sample_rate <= 32000) { - max_qmf_subbands = 48; - } else if (sbr->sample_rate == 44100) { - max_qmf_subbands = 35; - } else if (sbr->sample_rate >= 48000) - max_qmf_subbands = 32; - - if (sbr->k[2] - sbr->k[0] > max_qmf_subbands) { - av_log(ac->avctx, AV_LOG_ERROR, - "Invalid bitstream, too many QMF subbands: %d\n", sbr->k[2] - sbr->k[0]); - return -1; - } - - if (!spectrum->bs_freq_scale) { - int dk, k2diff; - - dk = spectrum->bs_alter_scale + 1; - sbr->n_master = ((sbr->k[2] - sbr->k[0] + (dk&2)) >> dk) << 1; - if (check_n_master(ac->avctx, sbr->n_master, sbr->spectrum_params.bs_xover_band)) - return -1; - - for (k = 1; k <= sbr->n_master; k++) - sbr->f_master[k] = dk; - - k2diff = sbr->k[2] - sbr->k[0] - sbr->n_master * dk; - if (k2diff < 0) { - sbr->f_master[1]--; - sbr->f_master[2]-= (k2diff < -1); - } else if (k2diff) { - sbr->f_master[sbr->n_master]++; - } - - sbr->f_master[0] = sbr->k[0]; - for (k = 1; k <= sbr->n_master; k++) - sbr->f_master[k] += sbr->f_master[k - 1]; - - } else { - int half_bands = 7 - spectrum->bs_freq_scale; // bs_freq_scale = {1,2,3} - int two_regions, num_bands_0; - int vdk0_max, vdk1_min; - int16_t vk0[49]; - - if (49 * sbr->k[2] > 110 * sbr->k[0]) { - two_regions = 1; - sbr->k[1] = 2 * sbr->k[0]; - } else { - two_regions = 0; - sbr->k[1] = sbr->k[2]; - } - - num_bands_0 = lrintf(half_bands * log2f(sbr->k[1] / (float)sbr->k[0])) * 2; - - if (num_bands_0 <= 0) { // Requirements (14496-3 sp04 p205) - av_log(ac->avctx, AV_LOG_ERROR, "Invalid num_bands_0: %d\n", num_bands_0); - return -1; - } - - vk0[0] = 0; - - make_bands(vk0+1, sbr->k[0], sbr->k[1], num_bands_0); - - qsort(vk0 + 1, num_bands_0, sizeof(vk0[1]), qsort_comparison_function_int16); - vdk0_max = vk0[num_bands_0]; - - vk0[0] = sbr->k[0]; - for (k = 1; k <= num_bands_0; k++) { - if (vk0[k] <= 0) { // Requirements (14496-3 sp04 p205) - av_log(ac->avctx, AV_LOG_ERROR, "Invalid vDk0[%d]: %d\n", k, vk0[k]); - return -1; - } - vk0[k] += vk0[k-1]; - } - - if (two_regions) { - int16_t vk1[49]; - float invwarp = spectrum->bs_alter_scale ? 0.76923076923076923077f - : 1.0f; // bs_alter_scale = {0,1} - int num_bands_1 = lrintf(half_bands * invwarp * - log2f(sbr->k[2] / (float)sbr->k[1])) * 2; - - make_bands(vk1+1, sbr->k[1], sbr->k[2], num_bands_1); - - vdk1_min = array_min_int16(vk1 + 1, num_bands_1); - - if (vdk1_min < vdk0_max) { - int change; - qsort(vk1 + 1, num_bands_1, sizeof(vk1[1]), qsort_comparison_function_int16); - change = FFMIN(vdk0_max - vk1[1], (vk1[num_bands_1] - vk1[1]) >> 1); - vk1[1] += change; - vk1[num_bands_1] -= change; - } - - qsort(vk1 + 1, num_bands_1, sizeof(vk1[1]), qsort_comparison_function_int16); - - vk1[0] = sbr->k[1]; - for (k = 1; k <= num_bands_1; k++) { - if (vk1[k] <= 0) { // Requirements (14496-3 sp04 p205) - av_log(ac->avctx, AV_LOG_ERROR, "Invalid vDk1[%d]: %d\n", k, vk1[k]); - return -1; - } - vk1[k] += vk1[k-1]; - } - - sbr->n_master = num_bands_0 + num_bands_1; - if (check_n_master(ac->avctx, sbr->n_master, sbr->spectrum_params.bs_xover_band)) - return -1; - memcpy(&sbr->f_master[0], vk0, - (num_bands_0 + 1) * sizeof(sbr->f_master[0])); - memcpy(&sbr->f_master[num_bands_0 + 1], vk1 + 1, - num_bands_1 * sizeof(sbr->f_master[0])); - - } else { - sbr->n_master = num_bands_0; - if (check_n_master(ac->avctx, sbr->n_master, sbr->spectrum_params.bs_xover_band)) - return -1; - memcpy(sbr->f_master, vk0, (num_bands_0 + 1) * sizeof(sbr->f_master[0])); - } - } - - return 0; -} - -/// High Frequency Generation - Patch Construction (14496-3 sp04 p216 fig. 4.46) -static int sbr_hf_calc_npatches(AACContext *ac, SpectralBandReplication *sbr) -{ - int i, k, sb = 0; - int msb = sbr->k[0]; - int usb = sbr->kx[1]; - int goal_sb = ((1000 << 11) + (sbr->sample_rate >> 1)) / sbr->sample_rate; - - sbr->num_patches = 0; - - if (goal_sb < sbr->kx[1] + sbr->m[1]) { - for (k = 0; sbr->f_master[k] < goal_sb; k++) ; - } else - k = sbr->n_master; - - do { - int odd = 0; - for (i = k; i == k || sb > (sbr->k[0] - 1 + msb - odd); i--) { - sb = sbr->f_master[i]; - odd = (sb + sbr->k[0]) & 1; - } - - // Requirements (14496-3 sp04 p205) sets the maximum number of patches to 5. - // After this check the final number of patches can still be six which is - // illegal however the Coding Technologies decoder check stream has a final - // count of 6 patches - if (sbr->num_patches > 5) { - av_log(ac->avctx, AV_LOG_ERROR, "Too many patches: %d\n", sbr->num_patches); - return -1; - } - - sbr->patch_num_subbands[sbr->num_patches] = FFMAX(sb - usb, 0); - sbr->patch_start_subband[sbr->num_patches] = sbr->k[0] - odd - sbr->patch_num_subbands[sbr->num_patches]; - - if (sbr->patch_num_subbands[sbr->num_patches] > 0) { - usb = sb; - msb = sb; - sbr->num_patches++; - } else - msb = sbr->kx[1]; - - if (sbr->f_master[k] - sb < 3) - k = sbr->n_master; - } while (sb != sbr->kx[1] + sbr->m[1]); - - if (sbr->patch_num_subbands[sbr->num_patches-1] < 3 && sbr->num_patches > 1) - sbr->num_patches--; - - return 0; -} - -/// Derived Frequency Band Tables (14496-3 sp04 p197) -static int sbr_make_f_derived(AACContext *ac, SpectralBandReplication *sbr) -{ - int k, temp; - - sbr->n[1] = sbr->n_master - sbr->spectrum_params.bs_xover_band; - sbr->n[0] = (sbr->n[1] + 1) >> 1; - - memcpy(sbr->f_tablehigh, &sbr->f_master[sbr->spectrum_params.bs_xover_band], - (sbr->n[1] + 1) * sizeof(sbr->f_master[0])); - sbr->m[1] = sbr->f_tablehigh[sbr->n[1]] - sbr->f_tablehigh[0]; - sbr->kx[1] = sbr->f_tablehigh[0]; - - // Requirements (14496-3 sp04 p205) - if (sbr->kx[1] + sbr->m[1] > 64) { - av_log(ac->avctx, AV_LOG_ERROR, - "Stop frequency border too high: %d\n", sbr->kx[1] + sbr->m[1]); - return -1; - } - if (sbr->kx[1] > 32) { - av_log(ac->avctx, AV_LOG_ERROR, "Start frequency border too high: %d\n", sbr->kx[1]); - return -1; - } - - sbr->f_tablelow[0] = sbr->f_tablehigh[0]; - temp = sbr->n[1] & 1; - for (k = 1; k <= sbr->n[0]; k++) - sbr->f_tablelow[k] = sbr->f_tablehigh[2 * k - temp]; - - sbr->n_q = FFMAX(1, lrintf(sbr->spectrum_params.bs_noise_bands * - log2f(sbr->k[2] / (float)sbr->kx[1]))); // 0 <= bs_noise_bands <= 3 - if (sbr->n_q > 5) { - av_log(ac->avctx, AV_LOG_ERROR, "Too many noise floor scale factors: %d\n", sbr->n_q); - return -1; - } - - sbr->f_tablenoise[0] = sbr->f_tablelow[0]; - temp = 0; - for (k = 1; k <= sbr->n_q; k++) { - temp += (sbr->n[0] - temp) / (sbr->n_q + 1 - k); - sbr->f_tablenoise[k] = sbr->f_tablelow[temp]; - } - - if (sbr_hf_calc_npatches(ac, sbr) < 0) - return -1; - - sbr_make_f_tablelim(sbr); - - sbr->data[0].f_indexnoise = 0; - sbr->data[1].f_indexnoise = 0; - - return 0; -} - -static av_always_inline void get_bits1_vector(GetBitContext *gb, uint8_t *vec, - int elements) -{ - int i; - for (i = 0; i < elements; i++) { - vec[i] = get_bits1(gb); - } -} - -/** ceil(log2(index+1)) */ -static const int8_t ceil_log2[] = { - 0, 1, 2, 2, 3, 3, -}; - -static int read_sbr_grid(AACContext *ac, SpectralBandReplication *sbr, - GetBitContext *gb, SBRData *ch_data) -{ - int i; - unsigned bs_pointer = 0; - // frameLengthFlag ? 15 : 16; 960 sample length frames unsupported; this value is numTimeSlots - int abs_bord_trail = 16; - int num_rel_lead, num_rel_trail; - unsigned bs_num_env_old = ch_data->bs_num_env; - - ch_data->bs_freq_res[0] = ch_data->bs_freq_res[ch_data->bs_num_env]; - ch_data->bs_amp_res = sbr->bs_amp_res_header; - ch_data->t_env_num_env_old = ch_data->t_env[bs_num_env_old]; - - switch (ch_data->bs_frame_class = get_bits(gb, 2)) { - case FIXFIX: - ch_data->bs_num_env = 1 << get_bits(gb, 2); - num_rel_lead = ch_data->bs_num_env - 1; - if (ch_data->bs_num_env == 1) - ch_data->bs_amp_res = 0; - - if (ch_data->bs_num_env > 4) { - av_log(ac->avctx, AV_LOG_ERROR, - "Invalid bitstream, too many SBR envelopes in FIXFIX type SBR frame: %d\n", - ch_data->bs_num_env); - return -1; - } - - ch_data->t_env[0] = 0; - ch_data->t_env[ch_data->bs_num_env] = abs_bord_trail; - - abs_bord_trail = (abs_bord_trail + (ch_data->bs_num_env >> 1)) / - ch_data->bs_num_env; - for (i = 0; i < num_rel_lead; i++) - ch_data->t_env[i + 1] = ch_data->t_env[i] + abs_bord_trail; - - ch_data->bs_freq_res[1] = get_bits1(gb); - for (i = 1; i < ch_data->bs_num_env; i++) - ch_data->bs_freq_res[i + 1] = ch_data->bs_freq_res[1]; - break; - case FIXVAR: - abs_bord_trail += get_bits(gb, 2); - num_rel_trail = get_bits(gb, 2); - ch_data->bs_num_env = num_rel_trail + 1; - ch_data->t_env[0] = 0; - ch_data->t_env[ch_data->bs_num_env] = abs_bord_trail; - - for (i = 0; i < num_rel_trail; i++) - ch_data->t_env[ch_data->bs_num_env - 1 - i] = - ch_data->t_env[ch_data->bs_num_env - i] - 2 * get_bits(gb, 2) - 2; - - bs_pointer = get_bits(gb, ceil_log2[ch_data->bs_num_env]); - - for (i = 0; i < ch_data->bs_num_env; i++) - ch_data->bs_freq_res[ch_data->bs_num_env - i] = get_bits1(gb); - break; - case VARFIX: - ch_data->t_env[0] = get_bits(gb, 2); - num_rel_lead = get_bits(gb, 2); - ch_data->bs_num_env = num_rel_lead + 1; - ch_data->t_env[ch_data->bs_num_env] = abs_bord_trail; - - for (i = 0; i < num_rel_lead; i++) - ch_data->t_env[i + 1] = ch_data->t_env[i] + 2 * get_bits(gb, 2) + 2; - - bs_pointer = get_bits(gb, ceil_log2[ch_data->bs_num_env]); - - get_bits1_vector(gb, ch_data->bs_freq_res + 1, ch_data->bs_num_env); - break; - case VARVAR: - ch_data->t_env[0] = get_bits(gb, 2); - abs_bord_trail += get_bits(gb, 2); - num_rel_lead = get_bits(gb, 2); - num_rel_trail = get_bits(gb, 2); - ch_data->bs_num_env = num_rel_lead + num_rel_trail + 1; - - if (ch_data->bs_num_env > 5) { - av_log(ac->avctx, AV_LOG_ERROR, - "Invalid bitstream, too many SBR envelopes in VARVAR type SBR frame: %d\n", - ch_data->bs_num_env); - return -1; - } - - ch_data->t_env[ch_data->bs_num_env] = abs_bord_trail; - - for (i = 0; i < num_rel_lead; i++) - ch_data->t_env[i + 1] = ch_data->t_env[i] + 2 * get_bits(gb, 2) + 2; - for (i = 0; i < num_rel_trail; i++) - ch_data->t_env[ch_data->bs_num_env - 1 - i] = - ch_data->t_env[ch_data->bs_num_env - i] - 2 * get_bits(gb, 2) - 2; - - bs_pointer = get_bits(gb, ceil_log2[ch_data->bs_num_env]); - - get_bits1_vector(gb, ch_data->bs_freq_res + 1, ch_data->bs_num_env); - break; - } - - if (bs_pointer > ch_data->bs_num_env + 1) { - av_log(ac->avctx, AV_LOG_ERROR, - "Invalid bitstream, bs_pointer points to a middle noise border outside the time borders table: %d\n", - bs_pointer); - return -1; - } - - for (i = 1; i <= ch_data->bs_num_env; i++) { - if (ch_data->t_env[i-1] > ch_data->t_env[i]) { - av_log(ac->avctx, AV_LOG_ERROR, "Non monotone time borders\n"); - return -1; - } - } - - ch_data->bs_num_noise = (ch_data->bs_num_env > 1) + 1; - - ch_data->t_q[0] = ch_data->t_env[0]; - ch_data->t_q[ch_data->bs_num_noise] = ch_data->t_env[ch_data->bs_num_env]; - if (ch_data->bs_num_noise > 1) { - unsigned int idx; - if (ch_data->bs_frame_class == FIXFIX) { - idx = ch_data->bs_num_env >> 1; - } else if (ch_data->bs_frame_class & 1) { // FIXVAR or VARVAR - idx = ch_data->bs_num_env - FFMAX(bs_pointer - 1, 1); - } else { // VARFIX - if (!bs_pointer) - idx = 1; - else if (bs_pointer == 1) - idx = ch_data->bs_num_env - 1; - else // bs_pointer > 1 - idx = bs_pointer - 1; - } - ch_data->t_q[1] = ch_data->t_env[idx]; - } - - ch_data->e_a[0] = -(ch_data->e_a[1] != bs_num_env_old); // l_APrev - ch_data->e_a[1] = -1; - if ((ch_data->bs_frame_class & 1) && bs_pointer) { // FIXVAR or VARVAR and bs_pointer != 0 - ch_data->e_a[1] = ch_data->bs_num_env + 1 - bs_pointer; - } else if ((ch_data->bs_frame_class == 2) && (bs_pointer > 1)) // VARFIX and bs_pointer > 1 - ch_data->e_a[1] = bs_pointer - 1; - - return 0; -} - -static void copy_sbr_grid(SBRData *dst, const SBRData *src) { - //These variables are saved from the previous frame rather than copied - dst->bs_freq_res[0] = dst->bs_freq_res[dst->bs_num_env]; - dst->t_env_num_env_old = dst->t_env[dst->bs_num_env]; - dst->e_a[0] = -(dst->e_a[1] != dst->bs_num_env); - - //These variables are read from the bitstream and therefore copied - memcpy(dst->bs_freq_res+1, src->bs_freq_res+1, sizeof(dst->bs_freq_res)-sizeof(*dst->bs_freq_res)); - memcpy(dst->t_env, src->t_env, sizeof(dst->t_env)); - memcpy(dst->t_q, src->t_q, sizeof(dst->t_q)); - dst->bs_num_env = src->bs_num_env; - dst->bs_amp_res = src->bs_amp_res; - dst->bs_num_noise = src->bs_num_noise; - dst->bs_frame_class = src->bs_frame_class; - dst->e_a[1] = src->e_a[1]; -} - -/// Read how the envelope and noise floor data is delta coded -static void read_sbr_dtdf(SpectralBandReplication *sbr, GetBitContext *gb, - SBRData *ch_data) -{ - get_bits1_vector(gb, ch_data->bs_df_env, ch_data->bs_num_env); - get_bits1_vector(gb, ch_data->bs_df_noise, ch_data->bs_num_noise); -} - -/// Read inverse filtering data -static void read_sbr_invf(SpectralBandReplication *sbr, GetBitContext *gb, - SBRData *ch_data) -{ - int i; - - memcpy(ch_data->bs_invf_mode[1], ch_data->bs_invf_mode[0], 5 * sizeof(uint8_t)); - for (i = 0; i < sbr->n_q; i++) - ch_data->bs_invf_mode[0][i] = get_bits(gb, 2); -} - -static void read_sbr_envelope(SpectralBandReplication *sbr, GetBitContext *gb, - SBRData *ch_data, int ch) -{ - int bits; - int i, j, k; - VLC_TYPE (*t_huff)[2], (*f_huff)[2]; - int t_lav, f_lav; - const int delta = (ch == 1 && sbr->bs_coupling == 1) + 1; - const int odd = sbr->n[1] & 1; - - if (sbr->bs_coupling && ch) { - if (ch_data->bs_amp_res) { - bits = 5; - t_huff = vlc_sbr[T_HUFFMAN_ENV_BAL_3_0DB].table; - t_lav = vlc_sbr_lav[T_HUFFMAN_ENV_BAL_3_0DB]; - f_huff = vlc_sbr[F_HUFFMAN_ENV_BAL_3_0DB].table; - f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_BAL_3_0DB]; - } else { - bits = 6; - t_huff = vlc_sbr[T_HUFFMAN_ENV_BAL_1_5DB].table; - t_lav = vlc_sbr_lav[T_HUFFMAN_ENV_BAL_1_5DB]; - f_huff = vlc_sbr[F_HUFFMAN_ENV_BAL_1_5DB].table; - f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_BAL_1_5DB]; - } - } else { - if (ch_data->bs_amp_res) { - bits = 6; - t_huff = vlc_sbr[T_HUFFMAN_ENV_3_0DB].table; - t_lav = vlc_sbr_lav[T_HUFFMAN_ENV_3_0DB]; - f_huff = vlc_sbr[F_HUFFMAN_ENV_3_0DB].table; - f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_3_0DB]; - } else { - bits = 7; - t_huff = vlc_sbr[T_HUFFMAN_ENV_1_5DB].table; - t_lav = vlc_sbr_lav[T_HUFFMAN_ENV_1_5DB]; - f_huff = vlc_sbr[F_HUFFMAN_ENV_1_5DB].table; - f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_1_5DB]; - } - } - - for (i = 0; i < ch_data->bs_num_env; i++) { - if (ch_data->bs_df_env[i]) { - // bs_freq_res[0] == bs_freq_res[bs_num_env] from prev frame - if (ch_data->bs_freq_res[i + 1] == ch_data->bs_freq_res[i]) { - for (j = 0; j < sbr->n[ch_data->bs_freq_res[i + 1]]; j++) - ch_data->env_facs[i + 1][j] = ch_data->env_facs[i][j] + delta * (get_vlc2(gb, t_huff, 9, 3) - t_lav); - } else if (ch_data->bs_freq_res[i + 1]) { - for (j = 0; j < sbr->n[ch_data->bs_freq_res[i + 1]]; j++) { - k = (j + odd) >> 1; // find k such that f_tablelow[k] <= f_tablehigh[j] < f_tablelow[k + 1] - ch_data->env_facs[i + 1][j] = ch_data->env_facs[i][k] + delta * (get_vlc2(gb, t_huff, 9, 3) - t_lav); - } - } else { - for (j = 0; j < sbr->n[ch_data->bs_freq_res[i + 1]]; j++) { - k = j ? 2*j - odd : 0; // find k such that f_tablehigh[k] == f_tablelow[j] - ch_data->env_facs[i + 1][j] = ch_data->env_facs[i][k] + delta * (get_vlc2(gb, t_huff, 9, 3) - t_lav); - } - } - } else { - ch_data->env_facs[i + 1][0] = delta * get_bits(gb, bits); // bs_env_start_value_balance - for (j = 1; j < sbr->n[ch_data->bs_freq_res[i + 1]]; j++) - 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); - } - } - - //assign 0th elements of env_facs from last elements - memcpy(ch_data->env_facs[0], ch_data->env_facs[ch_data->bs_num_env], - sizeof(ch_data->env_facs[0])); -} - -static void read_sbr_noise(SpectralBandReplication *sbr, GetBitContext *gb, - SBRData *ch_data, int ch) -{ - int i, j; - VLC_TYPE (*t_huff)[2], (*f_huff)[2]; - int t_lav, f_lav; - int delta = (ch == 1 && sbr->bs_coupling == 1) + 1; - - if (sbr->bs_coupling && ch) { - t_huff = vlc_sbr[T_HUFFMAN_NOISE_BAL_3_0DB].table; - t_lav = vlc_sbr_lav[T_HUFFMAN_NOISE_BAL_3_0DB]; - f_huff = vlc_sbr[F_HUFFMAN_ENV_BAL_3_0DB].table; - f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_BAL_3_0DB]; - } else { - t_huff = vlc_sbr[T_HUFFMAN_NOISE_3_0DB].table; - t_lav = vlc_sbr_lav[T_HUFFMAN_NOISE_3_0DB]; - f_huff = vlc_sbr[F_HUFFMAN_ENV_3_0DB].table; - f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_3_0DB]; - } - - for (i = 0; i < ch_data->bs_num_noise; i++) { - if (ch_data->bs_df_noise[i]) { - for (j = 0; j < sbr->n_q; j++) - ch_data->noise_facs[i + 1][j] = ch_data->noise_facs[i][j] + delta * (get_vlc2(gb, t_huff, 9, 2) - t_lav); - } else { - ch_data->noise_facs[i + 1][0] = delta * get_bits(gb, 5); // bs_noise_start_value_balance or bs_noise_start_value_level - for (j = 1; j < sbr->n_q; j++) - 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); - } - } - - //assign 0th elements of noise_facs from last elements - memcpy(ch_data->noise_facs[0], ch_data->noise_facs[ch_data->bs_num_noise], - sizeof(ch_data->noise_facs[0])); -} - -static void read_sbr_extension(AACContext *ac, SpectralBandReplication *sbr, - GetBitContext *gb, - int bs_extension_id, int *num_bits_left) -{ - switch (bs_extension_id) { - case EXTENSION_ID_PS: - if (!ac->m4ac.ps) { - av_log(ac->avctx, AV_LOG_ERROR, "Parametric Stereo signaled to be not-present but was found in the bitstream.\n"); - skip_bits_long(gb, *num_bits_left); // bs_fill_bits - *num_bits_left = 0; - } else { -#if 1 - *num_bits_left -= ff_ps_read_data(ac->avctx, gb, &sbr->ps, *num_bits_left); -#else - av_log_missing_feature(ac->avctx, "Parametric Stereo is", 0); - skip_bits_long(gb, *num_bits_left); // bs_fill_bits - *num_bits_left = 0; -#endif - } - break; - default: - av_log_missing_feature(ac->avctx, "Reserved SBR extensions are", 1); - skip_bits_long(gb, *num_bits_left); // bs_fill_bits - *num_bits_left = 0; - break; - } -} - -static int read_sbr_single_channel_element(AACContext *ac, - SpectralBandReplication *sbr, - GetBitContext *gb) -{ - if (get_bits1(gb)) // bs_data_extra - skip_bits(gb, 4); // bs_reserved - - if (read_sbr_grid(ac, sbr, gb, &sbr->data[0])) - return -1; - read_sbr_dtdf(sbr, gb, &sbr->data[0]); - read_sbr_invf(sbr, gb, &sbr->data[0]); - read_sbr_envelope(sbr, gb, &sbr->data[0], 0); - read_sbr_noise(sbr, gb, &sbr->data[0], 0); - - if ((sbr->data[0].bs_add_harmonic_flag = get_bits1(gb))) - get_bits1_vector(gb, sbr->data[0].bs_add_harmonic, sbr->n[1]); - - return 0; -} - -static int read_sbr_channel_pair_element(AACContext *ac, - SpectralBandReplication *sbr, - GetBitContext *gb) -{ - if (get_bits1(gb)) // bs_data_extra - skip_bits(gb, 8); // bs_reserved - - if ((sbr->bs_coupling = get_bits1(gb))) { - if (read_sbr_grid(ac, sbr, gb, &sbr->data[0])) - return -1; - copy_sbr_grid(&sbr->data[1], &sbr->data[0]); - read_sbr_dtdf(sbr, gb, &sbr->data[0]); - read_sbr_dtdf(sbr, gb, &sbr->data[1]); - read_sbr_invf(sbr, gb, &sbr->data[0]); - memcpy(sbr->data[1].bs_invf_mode[1], sbr->data[1].bs_invf_mode[0], sizeof(sbr->data[1].bs_invf_mode[0])); - memcpy(sbr->data[1].bs_invf_mode[0], sbr->data[0].bs_invf_mode[0], sizeof(sbr->data[1].bs_invf_mode[0])); - read_sbr_envelope(sbr, gb, &sbr->data[0], 0); - read_sbr_noise(sbr, gb, &sbr->data[0], 0); - read_sbr_envelope(sbr, gb, &sbr->data[1], 1); - read_sbr_noise(sbr, gb, &sbr->data[1], 1); - } else { - if (read_sbr_grid(ac, sbr, gb, &sbr->data[0]) || - read_sbr_grid(ac, sbr, gb, &sbr->data[1])) - return -1; - read_sbr_dtdf(sbr, gb, &sbr->data[0]); - read_sbr_dtdf(sbr, gb, &sbr->data[1]); - read_sbr_invf(sbr, gb, &sbr->data[0]); - read_sbr_invf(sbr, gb, &sbr->data[1]); - read_sbr_envelope(sbr, gb, &sbr->data[0], 0); - read_sbr_envelope(sbr, gb, &sbr->data[1], 1); - read_sbr_noise(sbr, gb, &sbr->data[0], 0); - read_sbr_noise(sbr, gb, &sbr->data[1], 1); - } - - if ((sbr->data[0].bs_add_harmonic_flag = get_bits1(gb))) - get_bits1_vector(gb, sbr->data[0].bs_add_harmonic, sbr->n[1]); - if ((sbr->data[1].bs_add_harmonic_flag = get_bits1(gb))) - get_bits1_vector(gb, sbr->data[1].bs_add_harmonic, sbr->n[1]); - - return 0; -} - -static unsigned int read_sbr_data(AACContext *ac, SpectralBandReplication *sbr, - GetBitContext *gb, int id_aac) -{ - unsigned int cnt = get_bits_count(gb); - - if (id_aac == TYPE_SCE || id_aac == TYPE_CCE) { - if (read_sbr_single_channel_element(ac, sbr, gb)) { - sbr->start = 0; - return get_bits_count(gb) - cnt; - } - } else if (id_aac == TYPE_CPE) { - if (read_sbr_channel_pair_element(ac, sbr, gb)) { - sbr->start = 0; - return get_bits_count(gb) - cnt; - } - } else { - av_log(ac->avctx, AV_LOG_ERROR, - "Invalid bitstream - cannot apply SBR to element type %d\n", id_aac); - sbr->start = 0; - return get_bits_count(gb) - cnt; - } - if (get_bits1(gb)) { // bs_extended_data - int num_bits_left = get_bits(gb, 4); // bs_extension_size - if (num_bits_left == 15) - num_bits_left += get_bits(gb, 8); // bs_esc_count - - num_bits_left <<= 3; - while (num_bits_left > 7) { - num_bits_left -= 2; - read_sbr_extension(ac, sbr, gb, get_bits(gb, 2), &num_bits_left); // bs_extension_id - } - if (num_bits_left < 0) { - av_log(ac->avctx, AV_LOG_ERROR, "SBR Extension over read.\n"); - } - if (num_bits_left > 0) - skip_bits(gb, num_bits_left); - } - - return get_bits_count(gb) - cnt; -} - -static void sbr_reset(AACContext *ac, SpectralBandReplication *sbr) -{ - int err; - err = sbr_make_f_master(ac, sbr, &sbr->spectrum_params); - if (err >= 0) - err = sbr_make_f_derived(ac, sbr); - if (err < 0) { - av_log(ac->avctx, AV_LOG_ERROR, - "SBR reset failed. Switching SBR to pure upsampling mode.\n"); - sbr->start = 0; - } -} - -/** - * Decode Spectral Band Replication extension data; reference: table 4.55. - * - * @param crc flag indicating the presence of CRC checksum - * @param cnt length of TYPE_FIL syntactic element in bytes - * - * @return Returns number of bytes consumed from the TYPE_FIL element. - */ -int ff_decode_sbr_extension(AACContext *ac, SpectralBandReplication *sbr, - GetBitContext *gb_host, int crc, int cnt, int id_aac) -{ - unsigned int num_sbr_bits = 0, num_align_bits; - unsigned bytes_read; - GetBitContext gbc = *gb_host, *gb = &gbc; - skip_bits_long(gb_host, cnt*8 - 4); - - sbr->reset = 0; - - if (!sbr->sample_rate) - sbr->sample_rate = 2 * ac->m4ac.sample_rate; //TODO use the nominal sample rate for arbitrary sample rate support - if (!ac->m4ac.ext_sample_rate) - ac->m4ac.ext_sample_rate = 2 * ac->m4ac.sample_rate; - - if (crc) { - skip_bits(gb, 10); // bs_sbr_crc_bits; TODO - implement CRC check - num_sbr_bits += 10; - } - - //Save some state from the previous frame. - sbr->kx[0] = sbr->kx[1]; - sbr->m[0] = sbr->m[1]; - - num_sbr_bits++; - if (get_bits1(gb)) // bs_header_flag - num_sbr_bits += read_sbr_header(sbr, gb); - - if (sbr->reset) - sbr_reset(ac, sbr); - - if (sbr->start) - num_sbr_bits += read_sbr_data(ac, sbr, gb, id_aac); - - num_align_bits = ((cnt << 3) - 4 - num_sbr_bits) & 7; - bytes_read = ((num_sbr_bits + num_align_bits + 4) >> 3); - - if (bytes_read > cnt) { - av_log(ac->avctx, AV_LOG_ERROR, - "Expected to read %d SBR bytes actually read %d.\n", cnt, bytes_read); - } - return cnt; -} - -/// Dequantization and stereo decoding (14496-3 sp04 p203) -static void sbr_dequant(SpectralBandReplication *sbr, int id_aac) -{ - int k, e; - int ch; - - if (id_aac == TYPE_CPE && sbr->bs_coupling) { - float alpha = sbr->data[0].bs_amp_res ? 1.0f : 0.5f; - float pan_offset = sbr->data[0].bs_amp_res ? 12.0f : 24.0f; - for (e = 1; e <= sbr->data[0].bs_num_env; e++) { - for (k = 0; k < sbr->n[sbr->data[0].bs_freq_res[e]]; k++) { - float temp1 = exp2f(sbr->data[0].env_facs[e][k] * alpha + 7.0f); - float temp2 = exp2f((pan_offset - sbr->data[1].env_facs[e][k]) * alpha); - float fac = temp1 / (1.0f + temp2); - sbr->data[0].env_facs[e][k] = fac; - sbr->data[1].env_facs[e][k] = fac * temp2; - } - } - for (e = 1; e <= sbr->data[0].bs_num_noise; e++) { - for (k = 0; k < sbr->n_q; k++) { - float temp1 = exp2f(NOISE_FLOOR_OFFSET - sbr->data[0].noise_facs[e][k] + 1); - float temp2 = exp2f(12 - sbr->data[1].noise_facs[e][k]); - float fac = temp1 / (1.0f + temp2); - sbr->data[0].noise_facs[e][k] = fac; - sbr->data[1].noise_facs[e][k] = fac * temp2; - } - } - } else { // SCE or one non-coupled CPE - for (ch = 0; ch < (id_aac == TYPE_CPE) + 1; ch++) { - float alpha = sbr->data[ch].bs_amp_res ? 1.0f : 0.5f; - for (e = 1; e <= sbr->data[ch].bs_num_env; e++) - for (k = 0; k < sbr->n[sbr->data[ch].bs_freq_res[e]]; k++) - sbr->data[ch].env_facs[e][k] = - exp2f(alpha * sbr->data[ch].env_facs[e][k] + 6.0f); - for (e = 1; e <= sbr->data[ch].bs_num_noise; e++) - for (k = 0; k < sbr->n_q; k++) - sbr->data[ch].noise_facs[e][k] = - exp2f(NOISE_FLOOR_OFFSET - sbr->data[ch].noise_facs[e][k]); - } - } -} - -/** - * Analysis QMF Bank (14496-3 sp04 p206) - * - * @param x pointer to the beginning of the first sample window - * @param W array of complex-valued samples split into subbands - */ -static void sbr_qmf_analysis(DSPContext *dsp, FFTContext *mdct, - SBRDSPContext *sbrdsp, const float *in, float *x, - float z[320], float W[2][32][32][2]) -{ - int i; - memcpy(W[0], W[1], sizeof(W[0])); - memcpy(x , x+1024, (320-32)*sizeof(x[0])); - memcpy(x+288, in, 1024*sizeof(x[0])); - for (i = 0; i < 32; i++) { // numTimeSlots*RATE = 16*2 as 960 sample frames - // are not supported - dsp->vector_fmul_reverse(z, sbr_qmf_window_ds, x, 320); - sbrdsp->sum64x5(z); - sbrdsp->qmf_pre_shuffle(z); - mdct->imdct_half(mdct, z, z+64); - sbrdsp->qmf_post_shuffle(W[1][i], z); - x += 32; - } -} - -/** - * Synthesis QMF Bank (14496-3 sp04 p206) and Downsampled Synthesis QMF Bank - * (14496-3 sp04 p206) - */ -static void sbr_qmf_synthesis(DSPContext *dsp, FFTContext *mdct, - SBRDSPContext *sbrdsp, - float *out, float X[2][38][64], - float mdct_buf[2][64], - float *v0, int *v_off, const unsigned int div) -{ - int i, n; - const float *sbr_qmf_window = div ? sbr_qmf_window_ds : sbr_qmf_window_us; - const int step = 128 >> div; - float *v; - for (i = 0; i < 32; i++) { - if (*v_off < step) { - int saved_samples = (1280 - 128) >> div; - memcpy(&v0[SBR_SYNTHESIS_BUF_SIZE - saved_samples], v0, saved_samples * sizeof(float)); - *v_off = SBR_SYNTHESIS_BUF_SIZE - saved_samples - step; - } else { - *v_off -= step; - } - v = v0 + *v_off; - if (div) { - for (n = 0; n < 32; n++) { - X[0][i][ n] = -X[0][i][n]; - X[0][i][32+n] = X[1][i][31-n]; - } - mdct->imdct_half(mdct, mdct_buf[0], X[0][i]); - sbrdsp->qmf_deint_neg(v, mdct_buf[0]); - } else { - sbrdsp->neg_odd_64(X[1][i]); - mdct->imdct_half(mdct, mdct_buf[0], X[0][i]); - mdct->imdct_half(mdct, mdct_buf[1], X[1][i]); - sbrdsp->qmf_deint_bfly(v, mdct_buf[1], mdct_buf[0]); - } - dsp->vector_fmul_add(out, v , sbr_qmf_window , zero64, 64 >> div); - dsp->vector_fmul_add(out, v + ( 192 >> div), sbr_qmf_window + ( 64 >> div), out , 64 >> div); - dsp->vector_fmul_add(out, v + ( 256 >> div), sbr_qmf_window + (128 >> div), out , 64 >> div); - dsp->vector_fmul_add(out, v + ( 448 >> div), sbr_qmf_window + (192 >> div), out , 64 >> div); - dsp->vector_fmul_add(out, v + ( 512 >> div), sbr_qmf_window + (256 >> div), out , 64 >> div); - dsp->vector_fmul_add(out, v + ( 704 >> div), sbr_qmf_window + (320 >> div), out , 64 >> div); - dsp->vector_fmul_add(out, v + ( 768 >> div), sbr_qmf_window + (384 >> div), out , 64 >> div); - dsp->vector_fmul_add(out, v + ( 960 >> div), sbr_qmf_window + (448 >> div), out , 64 >> div); - dsp->vector_fmul_add(out, v + (1024 >> div), sbr_qmf_window + (512 >> div), out , 64 >> div); - dsp->vector_fmul_add(out, v + (1216 >> div), sbr_qmf_window + (576 >> div), out , 64 >> div); - out += 64 >> div; - } -} - -/** High Frequency Generation (14496-3 sp04 p214+) and Inverse Filtering - * (14496-3 sp04 p214) - * Warning: This routine does not seem numerically stable. - */ -static void sbr_hf_inverse_filter(SBRDSPContext *dsp, - float (*alpha0)[2], float (*alpha1)[2], - const float X_low[32][40][2], int k0) -{ - int k; - for (k = 0; k < k0; k++) { - LOCAL_ALIGNED_16(float, phi, [3], [2][2]); - float dk; - - dsp->autocorrelate(X_low[k], phi); - - dk = phi[2][1][0] * phi[1][0][0] - - (phi[1][1][0] * phi[1][1][0] + phi[1][1][1] * phi[1][1][1]) / 1.000001f; - - if (!dk) { - alpha1[k][0] = 0; - alpha1[k][1] = 0; - } else { - float temp_real, temp_im; - temp_real = phi[0][0][0] * phi[1][1][0] - - phi[0][0][1] * phi[1][1][1] - - phi[0][1][0] * phi[1][0][0]; - temp_im = phi[0][0][0] * phi[1][1][1] + - phi[0][0][1] * phi[1][1][0] - - phi[0][1][1] * phi[1][0][0]; - - alpha1[k][0] = temp_real / dk; - alpha1[k][1] = temp_im / dk; - } - - if (!phi[1][0][0]) { - alpha0[k][0] = 0; - alpha0[k][1] = 0; - } else { - float temp_real, temp_im; - temp_real = phi[0][0][0] + alpha1[k][0] * phi[1][1][0] + - alpha1[k][1] * phi[1][1][1]; - temp_im = phi[0][0][1] + alpha1[k][1] * phi[1][1][0] - - alpha1[k][0] * phi[1][1][1]; - - alpha0[k][0] = -temp_real / phi[1][0][0]; - alpha0[k][1] = -temp_im / phi[1][0][0]; - } - - if (alpha1[k][0] * alpha1[k][0] + alpha1[k][1] * alpha1[k][1] >= 16.0f || - alpha0[k][0] * alpha0[k][0] + alpha0[k][1] * alpha0[k][1] >= 16.0f) { - alpha1[k][0] = 0; - alpha1[k][1] = 0; - alpha0[k][0] = 0; - alpha0[k][1] = 0; - } - } -} - -/// Chirp Factors (14496-3 sp04 p214) -static void sbr_chirp(SpectralBandReplication *sbr, SBRData *ch_data) -{ - int i; - float new_bw; - static const float bw_tab[] = { 0.0f, 0.75f, 0.9f, 0.98f }; - - for (i = 0; i < sbr->n_q; i++) { - if (ch_data->bs_invf_mode[0][i] + ch_data->bs_invf_mode[1][i] == 1) { - new_bw = 0.6f; - } else - new_bw = bw_tab[ch_data->bs_invf_mode[0][i]]; - - if (new_bw < ch_data->bw_array[i]) { - new_bw = 0.75f * new_bw + 0.25f * ch_data->bw_array[i]; - } else - new_bw = 0.90625f * new_bw + 0.09375f * ch_data->bw_array[i]; - ch_data->bw_array[i] = new_bw < 0.015625f ? 0.0f : new_bw; - } -} - -/// Generate the subband filtered lowband -static int sbr_lf_gen(AACContext *ac, SpectralBandReplication *sbr, - float X_low[32][40][2], const float W[2][32][32][2]) -{ - int i, k; - const int t_HFGen = 8; - const int i_f = 32; - memset(X_low, 0, 32*sizeof(*X_low)); - for (k = 0; k < sbr->kx[1]; k++) { - for (i = t_HFGen; i < i_f + t_HFGen; i++) { - X_low[k][i][0] = W[1][i - t_HFGen][k][0]; - X_low[k][i][1] = W[1][i - t_HFGen][k][1]; - } - } - for (k = 0; k < sbr->kx[0]; k++) { - for (i = 0; i < t_HFGen; i++) { - X_low[k][i][0] = W[0][i + i_f - t_HFGen][k][0]; - X_low[k][i][1] = W[0][i + i_f - t_HFGen][k][1]; - } - } - return 0; -} - -/// High Frequency Generator (14496-3 sp04 p215) -static int sbr_hf_gen(AACContext *ac, SpectralBandReplication *sbr, - float X_high[64][40][2], const float X_low[32][40][2], - const float (*alpha0)[2], const float (*alpha1)[2], - const float bw_array[5], const uint8_t *t_env, - int bs_num_env) -{ - int j, x; - int g = 0; - int k = sbr->kx[1]; - for (j = 0; j < sbr->num_patches; j++) { - for (x = 0; x < sbr->patch_num_subbands[j]; x++, k++) { - const int p = sbr->patch_start_subband[j] + x; - while (g <= sbr->n_q && k >= sbr->f_tablenoise[g]) - g++; - g--; - - if (g < 0) { - av_log(ac->avctx, AV_LOG_ERROR, - "ERROR : no subband found for frequency %d\n", k); - return -1; - } - - sbr->dsp.hf_gen(X_high[k] + ENVELOPE_ADJUSTMENT_OFFSET, - X_low[p] + ENVELOPE_ADJUSTMENT_OFFSET, - alpha0[p], alpha1[p], bw_array[g], - 2 * t_env[0], 2 * t_env[bs_num_env]); - } - } - if (k < sbr->m[1] + sbr->kx[1]) - memset(X_high + k, 0, (sbr->m[1] + sbr->kx[1] - k) * sizeof(*X_high)); - - return 0; -} - -/// Generate the subband filtered lowband -static int sbr_x_gen(SpectralBandReplication *sbr, float X[2][38][64], - const float Y0[38][64][2], const float Y1[38][64][2], - const float X_low[32][40][2], int ch) -{ - int k, i; - const int i_f = 32; - const int i_Temp = FFMAX(2*sbr->data[ch].t_env_num_env_old - i_f, 0); - memset(X, 0, 2*sizeof(*X)); - for (k = 0; k < sbr->kx[0]; k++) { - for (i = 0; i < i_Temp; i++) { - X[0][i][k] = X_low[k][i + ENVELOPE_ADJUSTMENT_OFFSET][0]; - X[1][i][k] = X_low[k][i + ENVELOPE_ADJUSTMENT_OFFSET][1]; - } - } - for (; k < sbr->kx[0] + sbr->m[0]; k++) { - for (i = 0; i < i_Temp; i++) { - X[0][i][k] = Y0[i + i_f][k][0]; - X[1][i][k] = Y0[i + i_f][k][1]; - } - } - - for (k = 0; k < sbr->kx[1]; k++) { - for (i = i_Temp; i < 38; i++) { - X[0][i][k] = X_low[k][i + ENVELOPE_ADJUSTMENT_OFFSET][0]; - X[1][i][k] = X_low[k][i + ENVELOPE_ADJUSTMENT_OFFSET][1]; - } - } - for (; k < sbr->kx[1] + sbr->m[1]; k++) { - for (i = i_Temp; i < i_f; i++) { - X[0][i][k] = Y1[i][k][0]; - X[1][i][k] = Y1[i][k][1]; - } - } - return 0; -} - -/** High Frequency Adjustment (14496-3 sp04 p217) and Mapping - * (14496-3 sp04 p217) - */ -static void sbr_mapping(AACContext *ac, SpectralBandReplication *sbr, - SBRData *ch_data, int e_a[2]) -{ - int e, i, m; - - memset(ch_data->s_indexmapped[1], 0, 7*sizeof(ch_data->s_indexmapped[1])); - for (e = 0; e < ch_data->bs_num_env; e++) { - const unsigned int ilim = sbr->n[ch_data->bs_freq_res[e + 1]]; - uint16_t *table = ch_data->bs_freq_res[e + 1] ? sbr->f_tablehigh : sbr->f_tablelow; - int k; - - av_assert0(sbr->kx[1] <= table[0]); - for (i = 0; i < ilim; i++) - for (m = table[i]; m < table[i + 1]; m++) - sbr->e_origmapped[e][m - sbr->kx[1]] = ch_data->env_facs[e+1][i]; - - // ch_data->bs_num_noise > 1 => 2 noise floors - k = (ch_data->bs_num_noise > 1) && (ch_data->t_env[e] >= ch_data->t_q[1]); - for (i = 0; i < sbr->n_q; i++) - for (m = sbr->f_tablenoise[i]; m < sbr->f_tablenoise[i + 1]; m++) - sbr->q_mapped[e][m - sbr->kx[1]] = ch_data->noise_facs[k+1][i]; - - for (i = 0; i < sbr->n[1]; i++) { - if (ch_data->bs_add_harmonic_flag) { - const unsigned int m_midpoint = - (sbr->f_tablehigh[i] + sbr->f_tablehigh[i + 1]) >> 1; - - ch_data->s_indexmapped[e + 1][m_midpoint - sbr->kx[1]] = ch_data->bs_add_harmonic[i] * - (e >= e_a[1] || (ch_data->s_indexmapped[0][m_midpoint - sbr->kx[1]] == 1)); - } - } - - for (i = 0; i < ilim; i++) { - int additional_sinusoid_present = 0; - for (m = table[i]; m < table[i + 1]; m++) { - if (ch_data->s_indexmapped[e + 1][m - sbr->kx[1]]) { - additional_sinusoid_present = 1; - break; - } - } - memset(&sbr->s_mapped[e][table[i] - sbr->kx[1]], additional_sinusoid_present, - (table[i + 1] - table[i]) * sizeof(sbr->s_mapped[e][0])); - } - } - - memcpy(ch_data->s_indexmapped[0], ch_data->s_indexmapped[ch_data->bs_num_env], sizeof(ch_data->s_indexmapped[0])); -} - -/// Estimation of current envelope (14496-3 sp04 p218) -static void sbr_env_estimate(float (*e_curr)[48], float X_high[64][40][2], - SpectralBandReplication *sbr, SBRData *ch_data) -{ - int e, m; - int kx1 = sbr->kx[1]; - - if (sbr->bs_interpol_freq) { - for (e = 0; e < ch_data->bs_num_env; e++) { - const float recip_env_size = 0.5f / (ch_data->t_env[e + 1] - ch_data->t_env[e]); - int ilb = ch_data->t_env[e] * 2 + ENVELOPE_ADJUSTMENT_OFFSET; - int iub = ch_data->t_env[e + 1] * 2 + ENVELOPE_ADJUSTMENT_OFFSET; - - for (m = 0; m < sbr->m[1]; m++) { - float sum = sbr->dsp.sum_square(X_high[m+kx1] + ilb, iub - ilb); - e_curr[e][m] = sum * recip_env_size; - } - } - } else { - int k, p; - - for (e = 0; e < ch_data->bs_num_env; e++) { - const int env_size = 2 * (ch_data->t_env[e + 1] - ch_data->t_env[e]); - int ilb = ch_data->t_env[e] * 2 + ENVELOPE_ADJUSTMENT_OFFSET; - int iub = ch_data->t_env[e + 1] * 2 + ENVELOPE_ADJUSTMENT_OFFSET; - const uint16_t *table = ch_data->bs_freq_res[e + 1] ? sbr->f_tablehigh : sbr->f_tablelow; - - for (p = 0; p < sbr->n[ch_data->bs_freq_res[e + 1]]; p++) { - float sum = 0.0f; - const int den = env_size * (table[p + 1] - table[p]); - - for (k = table[p]; k < table[p + 1]; k++) { - sum += sbr->dsp.sum_square(X_high[k] + ilb, iub - ilb); - } - sum /= den; - for (k = table[p]; k < table[p + 1]; k++) { - e_curr[e][k - kx1] = sum; - } - } - } - } -} - -/** - * Calculation of levels of additional HF signal components (14496-3 sp04 p219) - * and Calculation of gain (14496-3 sp04 p219) - */ -static void sbr_gain_calc(AACContext *ac, SpectralBandReplication *sbr, - SBRData *ch_data, const int e_a[2]) -{ - int e, k, m; - // max gain limits : -3dB, 0dB, 3dB, inf dB (limiter off) - static const float limgain[4] = { 0.70795, 1.0, 1.41254, 10000000000 }; - - for (e = 0; e < ch_data->bs_num_env; e++) { - int delta = !((e == e_a[1]) || (e == e_a[0])); - for (k = 0; k < sbr->n_lim; k++) { - float gain_boost, gain_max; - float sum[2] = { 0.0f, 0.0f }; - for (m = sbr->f_tablelim[k] - sbr->kx[1]; m < sbr->f_tablelim[k + 1] - sbr->kx[1]; m++) { - const float temp = sbr->e_origmapped[e][m] / (1.0f + sbr->q_mapped[e][m]); - sbr->q_m[e][m] = sqrtf(temp * sbr->q_mapped[e][m]); - sbr->s_m[e][m] = sqrtf(temp * ch_data->s_indexmapped[e + 1][m]); - if (!sbr->s_mapped[e][m]) { - sbr->gain[e][m] = sqrtf(sbr->e_origmapped[e][m] / - ((1.0f + sbr->e_curr[e][m]) * - (1.0f + sbr->q_mapped[e][m] * delta))); - } else { - sbr->gain[e][m] = sqrtf(sbr->e_origmapped[e][m] * sbr->q_mapped[e][m] / - ((1.0f + sbr->e_curr[e][m]) * - (1.0f + sbr->q_mapped[e][m]))); - } - } - for (m = sbr->f_tablelim[k] - sbr->kx[1]; m < sbr->f_tablelim[k + 1] - sbr->kx[1]; m++) { - sum[0] += sbr->e_origmapped[e][m]; - sum[1] += sbr->e_curr[e][m]; - } - gain_max = limgain[sbr->bs_limiter_gains] * sqrtf((FLT_EPSILON + sum[0]) / (FLT_EPSILON + sum[1])); - gain_max = FFMIN(100000.f, gain_max); - for (m = sbr->f_tablelim[k] - sbr->kx[1]; m < sbr->f_tablelim[k + 1] - sbr->kx[1]; m++) { - float q_m_max = sbr->q_m[e][m] * gain_max / sbr->gain[e][m]; - sbr->q_m[e][m] = FFMIN(sbr->q_m[e][m], q_m_max); - sbr->gain[e][m] = FFMIN(sbr->gain[e][m], gain_max); - } - sum[0] = sum[1] = 0.0f; - for (m = sbr->f_tablelim[k] - sbr->kx[1]; m < sbr->f_tablelim[k + 1] - sbr->kx[1]; m++) { - sum[0] += sbr->e_origmapped[e][m]; - sum[1] += sbr->e_curr[e][m] * sbr->gain[e][m] * sbr->gain[e][m] - + sbr->s_m[e][m] * sbr->s_m[e][m] - + (delta && !sbr->s_m[e][m]) * sbr->q_m[e][m] * sbr->q_m[e][m]; - } - gain_boost = sqrtf((FLT_EPSILON + sum[0]) / (FLT_EPSILON + sum[1])); - gain_boost = FFMIN(1.584893192f, gain_boost); - for (m = sbr->f_tablelim[k] - sbr->kx[1]; m < sbr->f_tablelim[k + 1] - sbr->kx[1]; m++) { - sbr->gain[e][m] *= gain_boost; - sbr->q_m[e][m] *= gain_boost; - sbr->s_m[e][m] *= gain_boost; - } - } - } -} - -/// Assembling HF Signals (14496-3 sp04 p220) -static void sbr_hf_assemble(float Y1[38][64][2], - const float X_high[64][40][2], - SpectralBandReplication *sbr, SBRData *ch_data, - const int e_a[2]) -{ - int e, i, j, m; - const int h_SL = 4 * !sbr->bs_smoothing_mode; - const int kx = sbr->kx[1]; - const int m_max = sbr->m[1]; - static const float h_smooth[5] = { - 0.33333333333333, - 0.30150283239582, - 0.21816949906249, - 0.11516383427084, - 0.03183050093751, - }; - static const int8_t phi[2][4] = { - { 1, 0, -1, 0}, // real - { 0, 1, 0, -1}, // imaginary - }; - float (*g_temp)[48] = ch_data->g_temp, (*q_temp)[48] = ch_data->q_temp; - int indexnoise = ch_data->f_indexnoise; - int indexsine = ch_data->f_indexsine; - - if (sbr->reset) { - for (i = 0; i < h_SL; i++) { - memcpy(g_temp[i + 2*ch_data->t_env[0]], sbr->gain[0], m_max * sizeof(sbr->gain[0][0])); - memcpy(q_temp[i + 2*ch_data->t_env[0]], sbr->q_m[0], m_max * sizeof(sbr->q_m[0][0])); - } - } else if (h_SL) { - memcpy(g_temp[2*ch_data->t_env[0]], g_temp[2*ch_data->t_env_num_env_old], 4*sizeof(g_temp[0])); - memcpy(q_temp[2*ch_data->t_env[0]], q_temp[2*ch_data->t_env_num_env_old], 4*sizeof(q_temp[0])); - } - - for (e = 0; e < ch_data->bs_num_env; e++) { - for (i = 2 * ch_data->t_env[e]; i < 2 * ch_data->t_env[e + 1]; i++) { - memcpy(g_temp[h_SL + i], sbr->gain[e], m_max * sizeof(sbr->gain[0][0])); - memcpy(q_temp[h_SL + i], sbr->q_m[e], m_max * sizeof(sbr->q_m[0][0])); - } - } - - for (e = 0; e < ch_data->bs_num_env; e++) { - for (i = 2 * ch_data->t_env[e]; i < 2 * ch_data->t_env[e + 1]; i++) { - int phi_sign = (1 - 2*(kx & 1)); - LOCAL_ALIGNED_16(float, g_filt_tab, [48]); - LOCAL_ALIGNED_16(float, q_filt_tab, [48]); - float *g_filt, *q_filt; - - if (h_SL && e != e_a[0] && e != e_a[1]) { - g_filt = g_filt_tab; - q_filt = q_filt_tab; - for (m = 0; m < m_max; m++) { - const int idx1 = i + h_SL; - g_filt[m] = 0.0f; - q_filt[m] = 0.0f; - for (j = 0; j <= h_SL; j++) { - g_filt[m] += g_temp[idx1 - j][m] * h_smooth[j]; - q_filt[m] += q_temp[idx1 - j][m] * h_smooth[j]; - } - } - } else { - g_filt = g_temp[i + h_SL]; - q_filt = q_temp[i]; - } - - sbr->dsp.hf_g_filt(Y1[i] + kx, X_high + kx, g_filt, m_max, - i + ENVELOPE_ADJUSTMENT_OFFSET); - - if (e != e_a[0] && e != e_a[1]) { - sbr->dsp.hf_apply_noise[indexsine](Y1[i] + kx, sbr->s_m[e], - q_filt, indexnoise, - kx, m_max); - } else { - for (m = 0; m < m_max; m++) { - Y1[i][m + kx][0] += - sbr->s_m[e][m] * phi[0][indexsine]; - Y1[i][m + kx][1] += - sbr->s_m[e][m] * (phi[1][indexsine] * phi_sign); - phi_sign = -phi_sign; - } - } - indexnoise = (indexnoise + m_max) & 0x1ff; - indexsine = (indexsine + 1) & 3; - } - } - ch_data->f_indexnoise = indexnoise; - ch_data->f_indexsine = indexsine; -} - -void ff_sbr_apply(AACContext *ac, SpectralBandReplication *sbr, int id_aac, - float* L, float* R) -{ - int downsampled = ac->m4ac.ext_sample_rate < sbr->sample_rate; - int ch; - int nch = (id_aac == TYPE_CPE) ? 2 : 1; - - if (sbr->start) { - sbr_dequant(sbr, id_aac); - } - for (ch = 0; ch < nch; ch++) { - /* decode channel */ - sbr_qmf_analysis(&ac->dsp, &sbr->mdct_ana, &sbr->dsp, ch ? R : L, sbr->data[ch].analysis_filterbank_samples, - (float*)sbr->qmf_filter_scratch, - sbr->data[ch].W); - sbr_lf_gen(ac, sbr, sbr->X_low, sbr->data[ch].W); - if (sbr->start) { - sbr_hf_inverse_filter(&sbr->dsp, sbr->alpha0, sbr->alpha1, sbr->X_low, sbr->k[0]); - sbr_chirp(sbr, &sbr->data[ch]); - sbr_hf_gen(ac, sbr, sbr->X_high, sbr->X_low, sbr->alpha0, sbr->alpha1, - sbr->data[ch].bw_array, sbr->data[ch].t_env, - sbr->data[ch].bs_num_env); - - // hf_adj - sbr_mapping(ac, sbr, &sbr->data[ch], sbr->data[ch].e_a); - sbr_env_estimate(sbr->e_curr, sbr->X_high, sbr, &sbr->data[ch]); - sbr_gain_calc(ac, sbr, &sbr->data[ch], sbr->data[ch].e_a); - sbr->data[ch].Ypos ^= 1; - sbr_hf_assemble(sbr->data[ch].Y[sbr->data[ch].Ypos], - sbr->X_high, sbr, &sbr->data[ch], - sbr->data[ch].e_a); - } - - /* synthesis */ - sbr_x_gen(sbr, sbr->X[ch], - sbr->data[ch].Y[1-sbr->data[ch].Ypos], - sbr->data[ch].Y[ sbr->data[ch].Ypos], - sbr->X_low, ch); - } - - if (ac->m4ac.ps == 1) { - if (sbr->ps.start) { - ff_ps_apply(ac->avctx, &sbr->ps, sbr->X[0], sbr->X[1], sbr->kx[1] + sbr->m[1]); - } else { - memcpy(sbr->X[1], sbr->X[0], sizeof(sbr->X[0])); - } - nch = 2; - } - - sbr_qmf_synthesis(&ac->dsp, &sbr->mdct, &sbr->dsp, L, sbr->X[0], sbr->qmf_filter_scratch, - sbr->data[0].synthesis_filterbank_samples, - &sbr->data[0].synthesis_filterbank_samples_offset, - downsampled); - if (nch == 2) - sbr_qmf_synthesis(&ac->dsp, &sbr->mdct, &sbr->dsp, R, sbr->X[1], sbr->qmf_filter_scratch, - sbr->data[1].synthesis_filterbank_samples, - &sbr->data[1].synthesis_filterbank_samples_offset, - downsampled); -} +/*
+ * AAC Spectral Band Replication decoding functions
+ * Copyright (c) 2008-2009 Robert Swain ( rob opendot cl )
+ * Copyright (c) 2009-2010 Alex Converse <alex.converse@gmail.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * AAC Spectral Band Replication decoding functions
+ * @author Robert Swain ( rob opendot cl )
+ */
+
+#include "aac.h"
+#include "sbr.h"
+#include "aacsbr.h"
+#include "aacsbrdata.h"
+#include "fft.h"
+#include "aacps.h"
+#include "sbrdsp.h"
+#include "libavutil/libm.h"
+#include "libavutil/avassert.h"
+
+#include <stdint.h>
+#include <float.h>
+#include <math.h>
+
+#define ENVELOPE_ADJUSTMENT_OFFSET 2
+#define NOISE_FLOOR_OFFSET 6.0f
+
+/**
+ * SBR VLC tables
+ */
+enum {
+ T_HUFFMAN_ENV_1_5DB,
+ F_HUFFMAN_ENV_1_5DB,
+ T_HUFFMAN_ENV_BAL_1_5DB,
+ F_HUFFMAN_ENV_BAL_1_5DB,
+ T_HUFFMAN_ENV_3_0DB,
+ F_HUFFMAN_ENV_3_0DB,
+ T_HUFFMAN_ENV_BAL_3_0DB,
+ F_HUFFMAN_ENV_BAL_3_0DB,
+ T_HUFFMAN_NOISE_3_0DB,
+ T_HUFFMAN_NOISE_BAL_3_0DB,
+};
+
+/**
+ * bs_frame_class - frame class of current SBR frame (14496-3 sp04 p98)
+ */
+enum {
+ FIXFIX,
+ FIXVAR,
+ VARFIX,
+ VARVAR,
+};
+
+enum {
+ EXTENSION_ID_PS = 2,
+};
+
+static VLC vlc_sbr[10];
+static const int8_t vlc_sbr_lav[10] =
+ { 60, 60, 24, 24, 31, 31, 12, 12, 31, 12 };
+static const DECLARE_ALIGNED(16, float, zero64)[64];
+
+#define SBR_INIT_VLC_STATIC(num, size) \
+ INIT_VLC_STATIC(&vlc_sbr[num], 9, sbr_tmp[num].table_size / sbr_tmp[num].elem_size, \
+ sbr_tmp[num].sbr_bits , 1, 1, \
+ sbr_tmp[num].sbr_codes, sbr_tmp[num].elem_size, sbr_tmp[num].elem_size, \
+ size)
+
+#define SBR_VLC_ROW(name) \
+ { name ## _codes, name ## _bits, sizeof(name ## _codes), sizeof(name ## _codes[0]) }
+
+av_cold void ff_aac_sbr_init(void)
+{
+ int n;
+ static const struct {
+ const void *sbr_codes, *sbr_bits;
+ const unsigned int table_size, elem_size;
+ } sbr_tmp[] = {
+ SBR_VLC_ROW(t_huffman_env_1_5dB),
+ SBR_VLC_ROW(f_huffman_env_1_5dB),
+ SBR_VLC_ROW(t_huffman_env_bal_1_5dB),
+ SBR_VLC_ROW(f_huffman_env_bal_1_5dB),
+ SBR_VLC_ROW(t_huffman_env_3_0dB),
+ SBR_VLC_ROW(f_huffman_env_3_0dB),
+ SBR_VLC_ROW(t_huffman_env_bal_3_0dB),
+ SBR_VLC_ROW(f_huffman_env_bal_3_0dB),
+ SBR_VLC_ROW(t_huffman_noise_3_0dB),
+ SBR_VLC_ROW(t_huffman_noise_bal_3_0dB),
+ };
+
+ // SBR VLC table initialization
+ SBR_INIT_VLC_STATIC(0, 1098);
+ SBR_INIT_VLC_STATIC(1, 1092);
+ SBR_INIT_VLC_STATIC(2, 768);
+ SBR_INIT_VLC_STATIC(3, 1026);
+ SBR_INIT_VLC_STATIC(4, 1058);
+ SBR_INIT_VLC_STATIC(5, 1052);
+ SBR_INIT_VLC_STATIC(6, 544);
+ SBR_INIT_VLC_STATIC(7, 544);
+ SBR_INIT_VLC_STATIC(8, 592);
+ SBR_INIT_VLC_STATIC(9, 512);
+
+ for (n = 1; n < 320; n++)
+ sbr_qmf_window_us[320 + n] = sbr_qmf_window_us[320 - n];
+ sbr_qmf_window_us[384] = -sbr_qmf_window_us[384];
+ sbr_qmf_window_us[512] = -sbr_qmf_window_us[512];
+
+ for (n = 0; n < 320; n++)
+ sbr_qmf_window_ds[n] = sbr_qmf_window_us[2*n];
+
+ ff_ps_init();
+}
+
+av_cold void ff_aac_sbr_ctx_init(AACContext *ac, SpectralBandReplication *sbr)
+{
+ float mdct_scale;
+ if(sbr->mdct.mdct_bits)
+ return;
+ sbr->kx[0] = sbr->kx[1] = 32; //Typo in spec, kx' inits to 32
+ sbr->data[0].e_a[1] = sbr->data[1].e_a[1] = -1;
+ sbr->data[0].synthesis_filterbank_samples_offset = SBR_SYNTHESIS_BUF_SIZE - (1280 - 128);
+ sbr->data[1].synthesis_filterbank_samples_offset = SBR_SYNTHESIS_BUF_SIZE - (1280 - 128);
+ /* SBR requires samples to be scaled to +/-32768.0 to work correctly.
+ * mdct scale factors are adjusted to scale up from +/-1.0 at analysis
+ * and scale back down at synthesis. */
+ mdct_scale = 1.0; //ac->avctx->sample_fmt == AV_SAMPLE_FMT_FLT ? 32768.0f : 1.0f;
+ ff_mdct_init(&sbr->mdct, 7, 1, 1.0 / (64 * mdct_scale));
+ ff_mdct_init(&sbr->mdct_ana, 7, 1, -2.0 * mdct_scale);
+ ff_ps_ctx_init(&sbr->ps);
+ ff_sbrdsp_init(&sbr->dsp);
+}
+
+av_cold void ff_aac_sbr_ctx_close(SpectralBandReplication *sbr)
+{
+ ff_mdct_end(&sbr->mdct);
+ ff_mdct_end(&sbr->mdct_ana);
+}
+
+static int qsort_comparison_function_int16(const void *a, const void *b)
+{
+ return *(const int16_t *)a - *(const int16_t *)b;
+}
+
+static inline int in_table_int16(const int16_t *table, int last_el, int16_t needle)
+{
+ int i;
+ for (i = 0; i <= last_el; i++)
+ if (table[i] == needle)
+ return 1;
+ return 0;
+}
+
+/// Limiter Frequency Band Table (14496-3 sp04 p198)
+static void sbr_make_f_tablelim(SpectralBandReplication *sbr)
+{
+ int k;
+ if (sbr->bs_limiter_bands > 0) {
+ static const float bands_warped[3] = { 1.32715174233856803909f, //2^(0.49/1.2)
+ 1.18509277094158210129f, //2^(0.49/2)
+ 1.11987160404675912501f }; //2^(0.49/3)
+ const float lim_bands_per_octave_warped = bands_warped[sbr->bs_limiter_bands - 1];
+ int16_t patch_borders[7];
+ uint16_t *in = sbr->f_tablelim + 1, *out = sbr->f_tablelim;
+
+ patch_borders[0] = sbr->kx[1];
+ for (k = 1; k <= sbr->num_patches; k++)
+ patch_borders[k] = patch_borders[k-1] + sbr->patch_num_subbands[k-1];
+
+ memcpy(sbr->f_tablelim, sbr->f_tablelow,
+ (sbr->n[0] + 1) * sizeof(sbr->f_tablelow[0]));
+ if (sbr->num_patches > 1)
+ memcpy(sbr->f_tablelim + sbr->n[0] + 1, patch_borders + 1,
+ (sbr->num_patches - 1) * sizeof(patch_borders[0]));
+
+ qsort(sbr->f_tablelim, sbr->num_patches + sbr->n[0],
+ sizeof(sbr->f_tablelim[0]),
+ qsort_comparison_function_int16);
+
+ sbr->n_lim = sbr->n[0] + sbr->num_patches - 1;
+ while (out < sbr->f_tablelim + sbr->n_lim) {
+ if (*in >= *out * lim_bands_per_octave_warped) {
+ *++out = *in++;
+ } else if (*in == *out ||
+ !in_table_int16(patch_borders, sbr->num_patches, *in)) {
+ in++;
+ sbr->n_lim--;
+ } else if (!in_table_int16(patch_borders, sbr->num_patches, *out)) {
+ *out = *in++;
+ sbr->n_lim--;
+ } else {
+ *++out = *in++;
+ }
+ }
+ } else {
+ sbr->f_tablelim[0] = sbr->f_tablelow[0];
+ sbr->f_tablelim[1] = sbr->f_tablelow[sbr->n[0]];
+ sbr->n_lim = 1;
+ }
+}
+
+static unsigned int read_sbr_header(SpectralBandReplication *sbr, GetBitContext *gb)
+{
+ unsigned int cnt = get_bits_count(gb);
+ uint8_t bs_header_extra_1;
+ uint8_t bs_header_extra_2;
+ int old_bs_limiter_bands = sbr->bs_limiter_bands;
+ SpectrumParameters old_spectrum_params;
+
+ sbr->start = 1;
+
+ // Save last spectrum parameters variables to compare to new ones
+ memcpy(&old_spectrum_params, &sbr->spectrum_params, sizeof(SpectrumParameters));
+
+ sbr->bs_amp_res_header = get_bits1(gb);
+ sbr->spectrum_params.bs_start_freq = get_bits(gb, 4);
+ sbr->spectrum_params.bs_stop_freq = get_bits(gb, 4);
+ sbr->spectrum_params.bs_xover_band = get_bits(gb, 3);
+ skip_bits(gb, 2); // bs_reserved
+
+ bs_header_extra_1 = get_bits1(gb);
+ bs_header_extra_2 = get_bits1(gb);
+
+ if (bs_header_extra_1) {
+ sbr->spectrum_params.bs_freq_scale = get_bits(gb, 2);
+ sbr->spectrum_params.bs_alter_scale = get_bits1(gb);
+ sbr->spectrum_params.bs_noise_bands = get_bits(gb, 2);
+ } else {
+ sbr->spectrum_params.bs_freq_scale = 2;
+ sbr->spectrum_params.bs_alter_scale = 1;
+ sbr->spectrum_params.bs_noise_bands = 2;
+ }
+
+ // Check if spectrum parameters changed
+ if (memcmp(&old_spectrum_params, &sbr->spectrum_params, sizeof(SpectrumParameters)))
+ sbr->reset = 1;
+
+ if (bs_header_extra_2) {
+ sbr->bs_limiter_bands = get_bits(gb, 2);
+ sbr->bs_limiter_gains = get_bits(gb, 2);
+ sbr->bs_interpol_freq = get_bits1(gb);
+ sbr->bs_smoothing_mode = get_bits1(gb);
+ } else {
+ sbr->bs_limiter_bands = 2;
+ sbr->bs_limiter_gains = 2;
+ sbr->bs_interpol_freq = 1;
+ sbr->bs_smoothing_mode = 1;
+ }
+
+ if (sbr->bs_limiter_bands != old_bs_limiter_bands && !sbr->reset)
+ sbr_make_f_tablelim(sbr);
+
+ return get_bits_count(gb) - cnt;
+}
+
+static int array_min_int16(const int16_t *array, int nel)
+{
+ int i, min = array[0];
+ for (i = 1; i < nel; i++)
+ min = FFMIN(array[i], min);
+ return min;
+}
+
+static void make_bands(int16_t* bands, int start, int stop, int num_bands)
+{
+ int k, previous, present;
+ float base, prod;
+
+ base = powf((float)stop / start, 1.0f / num_bands);
+ prod = start;
+ previous = start;
+
+ for (k = 0; k < num_bands-1; k++) {
+ prod *= base;
+ present = lrintf(prod);
+ bands[k] = present - previous;
+ previous = present;
+ }
+ bands[num_bands-1] = stop - previous;
+}
+
+static int check_n_master(AVCodecContext *avctx, int n_master, int bs_xover_band)
+{
+ // Requirements (14496-3 sp04 p205)
+ if (n_master <= 0) {
+ av_log(avctx, AV_LOG_ERROR, "Invalid n_master: %d\n", n_master);
+ return -1;
+ }
+ if (bs_xover_band >= n_master) {
+ av_log(avctx, AV_LOG_ERROR,
+ "Invalid bitstream, crossover band index beyond array bounds: %d\n",
+ bs_xover_band);
+ return -1;
+ }
+ return 0;
+}
+
+/// Master Frequency Band Table (14496-3 sp04 p194)
+static int sbr_make_f_master(AACContext *ac, SpectralBandReplication *sbr,
+ SpectrumParameters *spectrum)
+{
+ unsigned int temp, max_qmf_subbands;
+ unsigned int start_min, stop_min;
+ int k;
+ const int8_t *sbr_offset_ptr;
+ int16_t stop_dk[13];
+
+ if (sbr->sample_rate < 32000) {
+ temp = 3000;
+ } else if (sbr->sample_rate < 64000) {
+ temp = 4000;
+ } else
+ temp = 5000;
+
+ start_min = ((temp << 7) + (sbr->sample_rate >> 1)) / sbr->sample_rate;
+ stop_min = ((temp << 8) + (sbr->sample_rate >> 1)) / sbr->sample_rate;
+
+ switch (sbr->sample_rate) {
+ case 16000:
+ sbr_offset_ptr = sbr_offset[0];
+ break;
+ case 22050:
+ sbr_offset_ptr = sbr_offset[1];
+ break;
+ case 24000:
+ sbr_offset_ptr = sbr_offset[2];
+ break;
+ case 32000:
+ sbr_offset_ptr = sbr_offset[3];
+ break;
+ case 44100: case 48000: case 64000:
+ sbr_offset_ptr = sbr_offset[4];
+ break;
+ case 88200: case 96000: case 128000: case 176400: case 192000:
+ sbr_offset_ptr = sbr_offset[5];
+ break;
+ default:
+ av_log(ac->avctx, AV_LOG_ERROR,
+ "Unsupported sample rate for SBR: %d\n", sbr->sample_rate);
+ return -1;
+ }
+
+ sbr->k[0] = start_min + sbr_offset_ptr[spectrum->bs_start_freq];
+
+ if (spectrum->bs_stop_freq < 14) {
+ sbr->k[2] = stop_min;
+ make_bands(stop_dk, stop_min, 64, 13);
+ qsort(stop_dk, 13, sizeof(stop_dk[0]), qsort_comparison_function_int16);
+ for (k = 0; k < spectrum->bs_stop_freq; k++)
+ sbr->k[2] += stop_dk[k];
+ } else if (spectrum->bs_stop_freq == 14) {
+ sbr->k[2] = 2*sbr->k[0];
+ } else if (spectrum->bs_stop_freq == 15) {
+ sbr->k[2] = 3*sbr->k[0];
+ } else {
+ av_log(ac->avctx, AV_LOG_ERROR,
+ "Invalid bs_stop_freq: %d\n", spectrum->bs_stop_freq);
+ return -1;
+ }
+ sbr->k[2] = FFMIN(64, sbr->k[2]);
+
+ // Requirements (14496-3 sp04 p205)
+ if (sbr->sample_rate <= 32000) {
+ max_qmf_subbands = 48;
+ } else if (sbr->sample_rate == 44100) {
+ max_qmf_subbands = 35;
+ } else if (sbr->sample_rate >= 48000)
+ max_qmf_subbands = 32;
+
+ if (sbr->k[2] - sbr->k[0] > max_qmf_subbands) {
+ av_log(ac->avctx, AV_LOG_ERROR,
+ "Invalid bitstream, too many QMF subbands: %d\n", sbr->k[2] - sbr->k[0]);
+ return -1;
+ }
+
+ if (!spectrum->bs_freq_scale) {
+ int dk, k2diff;
+
+ dk = spectrum->bs_alter_scale + 1;
+ sbr->n_master = ((sbr->k[2] - sbr->k[0] + (dk&2)) >> dk) << 1;
+ if (check_n_master(ac->avctx, sbr->n_master, sbr->spectrum_params.bs_xover_band))
+ return -1;
+
+ for (k = 1; k <= sbr->n_master; k++)
+ sbr->f_master[k] = dk;
+
+ k2diff = sbr->k[2] - sbr->k[0] - sbr->n_master * dk;
+ if (k2diff < 0) {
+ sbr->f_master[1]--;
+ sbr->f_master[2]-= (k2diff < -1);
+ } else if (k2diff) {
+ sbr->f_master[sbr->n_master]++;
+ }
+
+ sbr->f_master[0] = sbr->k[0];
+ for (k = 1; k <= sbr->n_master; k++)
+ sbr->f_master[k] += sbr->f_master[k - 1];
+
+ } else {
+ int half_bands = 7 - spectrum->bs_freq_scale; // bs_freq_scale = {1,2,3}
+ int two_regions, num_bands_0;
+ int vdk0_max, vdk1_min;
+ int16_t vk0[49];
+
+ if (49 * sbr->k[2] > 110 * sbr->k[0]) {
+ two_regions = 1;
+ sbr->k[1] = 2 * sbr->k[0];
+ } else {
+ two_regions = 0;
+ sbr->k[1] = sbr->k[2];
+ }
+
+ num_bands_0 = lrintf(half_bands * log2f(sbr->k[1] / (float)sbr->k[0])) * 2;
+
+ if (num_bands_0 <= 0) { // Requirements (14496-3 sp04 p205)
+ av_log(ac->avctx, AV_LOG_ERROR, "Invalid num_bands_0: %d\n", num_bands_0);
+ return -1;
+ }
+
+ vk0[0] = 0;
+
+ make_bands(vk0+1, sbr->k[0], sbr->k[1], num_bands_0);
+
+ qsort(vk0 + 1, num_bands_0, sizeof(vk0[1]), qsort_comparison_function_int16);
+ vdk0_max = vk0[num_bands_0];
+
+ vk0[0] = sbr->k[0];
+ for (k = 1; k <= num_bands_0; k++) {
+ if (vk0[k] <= 0) { // Requirements (14496-3 sp04 p205)
+ av_log(ac->avctx, AV_LOG_ERROR, "Invalid vDk0[%d]: %d\n", k, vk0[k]);
+ return -1;
+ }
+ vk0[k] += vk0[k-1];
+ }
+
+ if (two_regions) {
+ int16_t vk1[49];
+ float invwarp = spectrum->bs_alter_scale ? 0.76923076923076923077f
+ : 1.0f; // bs_alter_scale = {0,1}
+ int num_bands_1 = lrintf(half_bands * invwarp *
+ log2f(sbr->k[2] / (float)sbr->k[1])) * 2;
+
+ make_bands(vk1+1, sbr->k[1], sbr->k[2], num_bands_1);
+
+ vdk1_min = array_min_int16(vk1 + 1, num_bands_1);
+
+ if (vdk1_min < vdk0_max) {
+ int change;
+ qsort(vk1 + 1, num_bands_1, sizeof(vk1[1]), qsort_comparison_function_int16);
+ change = FFMIN(vdk0_max - vk1[1], (vk1[num_bands_1] - vk1[1]) >> 1);
+ vk1[1] += change;
+ vk1[num_bands_1] -= change;
+ }
+
+ qsort(vk1 + 1, num_bands_1, sizeof(vk1[1]), qsort_comparison_function_int16);
+
+ vk1[0] = sbr->k[1];
+ for (k = 1; k <= num_bands_1; k++) {
+ if (vk1[k] <= 0) { // Requirements (14496-3 sp04 p205)
+ av_log(ac->avctx, AV_LOG_ERROR, "Invalid vDk1[%d]: %d\n", k, vk1[k]);
+ return -1;
+ }
+ vk1[k] += vk1[k-1];
+ }
+
+ sbr->n_master = num_bands_0 + num_bands_1;
+ if (check_n_master(ac->avctx, sbr->n_master, sbr->spectrum_params.bs_xover_band))
+ return -1;
+ memcpy(&sbr->f_master[0], vk0,
+ (num_bands_0 + 1) * sizeof(sbr->f_master[0]));
+ memcpy(&sbr->f_master[num_bands_0 + 1], vk1 + 1,
+ num_bands_1 * sizeof(sbr->f_master[0]));
+
+ } else {
+ sbr->n_master = num_bands_0;
+ if (check_n_master(ac->avctx, sbr->n_master, sbr->spectrum_params.bs_xover_band))
+ return -1;
+ memcpy(sbr->f_master, vk0, (num_bands_0 + 1) * sizeof(sbr->f_master[0]));
+ }
+ }
+
+ return 0;
+}
+
+/// High Frequency Generation - Patch Construction (14496-3 sp04 p216 fig. 4.46)
+static int sbr_hf_calc_npatches(AACContext *ac, SpectralBandReplication *sbr)
+{
+ int i, k, sb = 0;
+ int msb = sbr->k[0];
+ int usb = sbr->kx[1];
+ int goal_sb = ((1000 << 11) + (sbr->sample_rate >> 1)) / sbr->sample_rate;
+
+ sbr->num_patches = 0;
+
+ if (goal_sb < sbr->kx[1] + sbr->m[1]) {
+ for (k = 0; sbr->f_master[k] < goal_sb; k++) ;
+ } else
+ k = sbr->n_master;
+
+ do {
+ int odd = 0;
+ for (i = k; i == k || sb > (sbr->k[0] - 1 + msb - odd); i--) {
+ sb = sbr->f_master[i];
+ odd = (sb + sbr->k[0]) & 1;
+ }
+
+ // Requirements (14496-3 sp04 p205) sets the maximum number of patches to 5.
+ // After this check the final number of patches can still be six which is
+ // illegal however the Coding Technologies decoder check stream has a final
+ // count of 6 patches
+ if (sbr->num_patches > 5) {
+ av_log(ac->avctx, AV_LOG_ERROR, "Too many patches: %d\n", sbr->num_patches);
+ return -1;
+ }
+
+ sbr->patch_num_subbands[sbr->num_patches] = FFMAX(sb - usb, 0);
+ sbr->patch_start_subband[sbr->num_patches] = sbr->k[0] - odd - sbr->patch_num_subbands[sbr->num_patches];
+
+ if (sbr->patch_num_subbands[sbr->num_patches] > 0) {
+ usb = sb;
+ msb = sb;
+ sbr->num_patches++;
+ } else
+ msb = sbr->kx[1];
+
+ if (sbr->f_master[k] - sb < 3)
+ k = sbr->n_master;
+ } while (sb != sbr->kx[1] + sbr->m[1]);
+
+ if (sbr->patch_num_subbands[sbr->num_patches-1] < 3 && sbr->num_patches > 1)
+ sbr->num_patches--;
+
+ return 0;
+}
+
+/// Derived Frequency Band Tables (14496-3 sp04 p197)
+static int sbr_make_f_derived(AACContext *ac, SpectralBandReplication *sbr)
+{
+ int k, temp;
+
+ sbr->n[1] = sbr->n_master - sbr->spectrum_params.bs_xover_band;
+ sbr->n[0] = (sbr->n[1] + 1) >> 1;
+
+ memcpy(sbr->f_tablehigh, &sbr->f_master[sbr->spectrum_params.bs_xover_band],
+ (sbr->n[1] + 1) * sizeof(sbr->f_master[0]));
+ sbr->m[1] = sbr->f_tablehigh[sbr->n[1]] - sbr->f_tablehigh[0];
+ sbr->kx[1] = sbr->f_tablehigh[0];
+
+ // Requirements (14496-3 sp04 p205)
+ if (sbr->kx[1] + sbr->m[1] > 64) {
+ av_log(ac->avctx, AV_LOG_ERROR,
+ "Stop frequency border too high: %d\n", sbr->kx[1] + sbr->m[1]);
+ return -1;
+ }
+ if (sbr->kx[1] > 32) {
+ av_log(ac->avctx, AV_LOG_ERROR, "Start frequency border too high: %d\n", sbr->kx[1]);
+ return -1;
+ }
+
+ sbr->f_tablelow[0] = sbr->f_tablehigh[0];
+ temp = sbr->n[1] & 1;
+ for (k = 1; k <= sbr->n[0]; k++)
+ sbr->f_tablelow[k] = sbr->f_tablehigh[2 * k - temp];
+
+ sbr->n_q = FFMAX(1, lrintf(sbr->spectrum_params.bs_noise_bands *
+ log2f(sbr->k[2] / (float)sbr->kx[1]))); // 0 <= bs_noise_bands <= 3
+ if (sbr->n_q > 5) {
+ av_log(ac->avctx, AV_LOG_ERROR, "Too many noise floor scale factors: %d\n", sbr->n_q);
+ return -1;
+ }
+
+ sbr->f_tablenoise[0] = sbr->f_tablelow[0];
+ temp = 0;
+ for (k = 1; k <= sbr->n_q; k++) {
+ temp += (sbr->n[0] - temp) / (sbr->n_q + 1 - k);
+ sbr->f_tablenoise[k] = sbr->f_tablelow[temp];
+ }
+
+ if (sbr_hf_calc_npatches(ac, sbr) < 0)
+ return -1;
+
+ sbr_make_f_tablelim(sbr);
+
+ sbr->data[0].f_indexnoise = 0;
+ sbr->data[1].f_indexnoise = 0;
+
+ return 0;
+}
+
+static av_always_inline void get_bits1_vector(GetBitContext *gb, uint8_t *vec,
+ int elements)
+{
+ int i;
+ for (i = 0; i < elements; i++) {
+ vec[i] = get_bits1(gb);
+ }
+}
+
+/** ceil(log2(index+1)) */
+static const int8_t ceil_log2[] = {
+ 0, 1, 2, 2, 3, 3,
+};
+
+static int read_sbr_grid(AACContext *ac, SpectralBandReplication *sbr,
+ GetBitContext *gb, SBRData *ch_data)
+{
+ int i;
+ unsigned bs_pointer = 0;
+ // frameLengthFlag ? 15 : 16; 960 sample length frames unsupported; this value is numTimeSlots
+ int abs_bord_trail = 16;
+ int num_rel_lead, num_rel_trail;
+ unsigned bs_num_env_old = ch_data->bs_num_env;
+
+ ch_data->bs_freq_res[0] = ch_data->bs_freq_res[ch_data->bs_num_env];
+ ch_data->bs_amp_res = sbr->bs_amp_res_header;
+ ch_data->t_env_num_env_old = ch_data->t_env[bs_num_env_old];
+
+ switch (ch_data->bs_frame_class = get_bits(gb, 2)) {
+ case FIXFIX:
+ ch_data->bs_num_env = 1 << get_bits(gb, 2);
+ num_rel_lead = ch_data->bs_num_env - 1;
+ if (ch_data->bs_num_env == 1)
+ ch_data->bs_amp_res = 0;
+
+ if (ch_data->bs_num_env > 4) {
+ av_log(ac->avctx, AV_LOG_ERROR,
+ "Invalid bitstream, too many SBR envelopes in FIXFIX type SBR frame: %d\n",
+ ch_data->bs_num_env);
+ return -1;
+ }
+
+ ch_data->t_env[0] = 0;
+ ch_data->t_env[ch_data->bs_num_env] = abs_bord_trail;
+
+ abs_bord_trail = (abs_bord_trail + (ch_data->bs_num_env >> 1)) /
+ ch_data->bs_num_env;
+ for (i = 0; i < num_rel_lead; i++)
+ ch_data->t_env[i + 1] = ch_data->t_env[i] + abs_bord_trail;
+
+ ch_data->bs_freq_res[1] = get_bits1(gb);
+ for (i = 1; i < ch_data->bs_num_env; i++)
+ ch_data->bs_freq_res[i + 1] = ch_data->bs_freq_res[1];
+ break;
+ case FIXVAR:
+ abs_bord_trail += get_bits(gb, 2);
+ num_rel_trail = get_bits(gb, 2);
+ ch_data->bs_num_env = num_rel_trail + 1;
+ ch_data->t_env[0] = 0;
+ ch_data->t_env[ch_data->bs_num_env] = abs_bord_trail;
+
+ for (i = 0; i < num_rel_trail; i++)
+ ch_data->t_env[ch_data->bs_num_env - 1 - i] =
+ ch_data->t_env[ch_data->bs_num_env - i] - 2 * get_bits(gb, 2) - 2;
+
+ bs_pointer = get_bits(gb, ceil_log2[ch_data->bs_num_env]);
+
+ for (i = 0; i < ch_data->bs_num_env; i++)
+ ch_data->bs_freq_res[ch_data->bs_num_env - i] = get_bits1(gb);
+ break;
+ case VARFIX:
+ ch_data->t_env[0] = get_bits(gb, 2);
+ num_rel_lead = get_bits(gb, 2);
+ ch_data->bs_num_env = num_rel_lead + 1;
+ ch_data->t_env[ch_data->bs_num_env] = abs_bord_trail;
+
+ for (i = 0; i < num_rel_lead; i++)
+ ch_data->t_env[i + 1] = ch_data->t_env[i] + 2 * get_bits(gb, 2) + 2;
+
+ bs_pointer = get_bits(gb, ceil_log2[ch_data->bs_num_env]);
+
+ get_bits1_vector(gb, ch_data->bs_freq_res + 1, ch_data->bs_num_env);
+ break;
+ case VARVAR:
+ ch_data->t_env[0] = get_bits(gb, 2);
+ abs_bord_trail += get_bits(gb, 2);
+ num_rel_lead = get_bits(gb, 2);
+ num_rel_trail = get_bits(gb, 2);
+ ch_data->bs_num_env = num_rel_lead + num_rel_trail + 1;
+
+ if (ch_data->bs_num_env > 5) {
+ av_log(ac->avctx, AV_LOG_ERROR,
+ "Invalid bitstream, too many SBR envelopes in VARVAR type SBR frame: %d\n",
+ ch_data->bs_num_env);
+ return -1;
+ }
+
+ ch_data->t_env[ch_data->bs_num_env] = abs_bord_trail;
+
+ for (i = 0; i < num_rel_lead; i++)
+ ch_data->t_env[i + 1] = ch_data->t_env[i] + 2 * get_bits(gb, 2) + 2;
+ for (i = 0; i < num_rel_trail; i++)
+ ch_data->t_env[ch_data->bs_num_env - 1 - i] =
+ ch_data->t_env[ch_data->bs_num_env - i] - 2 * get_bits(gb, 2) - 2;
+
+ bs_pointer = get_bits(gb, ceil_log2[ch_data->bs_num_env]);
+
+ get_bits1_vector(gb, ch_data->bs_freq_res + 1, ch_data->bs_num_env);
+ break;
+ }
+
+ if (bs_pointer > ch_data->bs_num_env + 1) {
+ av_log(ac->avctx, AV_LOG_ERROR,
+ "Invalid bitstream, bs_pointer points to a middle noise border outside the time borders table: %d\n",
+ bs_pointer);
+ return -1;
+ }
+
+ for (i = 1; i <= ch_data->bs_num_env; i++) {
+ if (ch_data->t_env[i-1] > ch_data->t_env[i]) {
+ av_log(ac->avctx, AV_LOG_ERROR, "Non monotone time borders\n");
+ return -1;
+ }
+ }
+
+ ch_data->bs_num_noise = (ch_data->bs_num_env > 1) + 1;
+
+ ch_data->t_q[0] = ch_data->t_env[0];
+ ch_data->t_q[ch_data->bs_num_noise] = ch_data->t_env[ch_data->bs_num_env];
+ if (ch_data->bs_num_noise > 1) {
+ unsigned int idx;
+ if (ch_data->bs_frame_class == FIXFIX) {
+ idx = ch_data->bs_num_env >> 1;
+ } else if (ch_data->bs_frame_class & 1) { // FIXVAR or VARVAR
+ idx = ch_data->bs_num_env - FFMAX(bs_pointer - 1, 1);
+ } else { // VARFIX
+ if (!bs_pointer)
+ idx = 1;
+ else if (bs_pointer == 1)
+ idx = ch_data->bs_num_env - 1;
+ else // bs_pointer > 1
+ idx = bs_pointer - 1;
+ }
+ ch_data->t_q[1] = ch_data->t_env[idx];
+ }
+
+ ch_data->e_a[0] = -(ch_data->e_a[1] != bs_num_env_old); // l_APrev
+ ch_data->e_a[1] = -1;
+ if ((ch_data->bs_frame_class & 1) && bs_pointer) { // FIXVAR or VARVAR and bs_pointer != 0
+ ch_data->e_a[1] = ch_data->bs_num_env + 1 - bs_pointer;
+ } else if ((ch_data->bs_frame_class == 2) && (bs_pointer > 1)) // VARFIX and bs_pointer > 1
+ ch_data->e_a[1] = bs_pointer - 1;
+
+ return 0;
+}
+
+static void copy_sbr_grid(SBRData *dst, const SBRData *src) {
+ //These variables are saved from the previous frame rather than copied
+ dst->bs_freq_res[0] = dst->bs_freq_res[dst->bs_num_env];
+ dst->t_env_num_env_old = dst->t_env[dst->bs_num_env];
+ dst->e_a[0] = -(dst->e_a[1] != dst->bs_num_env);
+
+ //These variables are read from the bitstream and therefore copied
+ memcpy(dst->bs_freq_res+1, src->bs_freq_res+1, sizeof(dst->bs_freq_res)-sizeof(*dst->bs_freq_res));
+ memcpy(dst->t_env, src->t_env, sizeof(dst->t_env));
+ memcpy(dst->t_q, src->t_q, sizeof(dst->t_q));
+ dst->bs_num_env = src->bs_num_env;
+ dst->bs_amp_res = src->bs_amp_res;
+ dst->bs_num_noise = src->bs_num_noise;
+ dst->bs_frame_class = src->bs_frame_class;
+ dst->e_a[1] = src->e_a[1];
+}
+
+/// Read how the envelope and noise floor data is delta coded
+static void read_sbr_dtdf(SpectralBandReplication *sbr, GetBitContext *gb,
+ SBRData *ch_data)
+{
+ get_bits1_vector(gb, ch_data->bs_df_env, ch_data->bs_num_env);
+ get_bits1_vector(gb, ch_data->bs_df_noise, ch_data->bs_num_noise);
+}
+
+/// Read inverse filtering data
+static void read_sbr_invf(SpectralBandReplication *sbr, GetBitContext *gb,
+ SBRData *ch_data)
+{
+ int i;
+
+ memcpy(ch_data->bs_invf_mode[1], ch_data->bs_invf_mode[0], 5 * sizeof(uint8_t));
+ for (i = 0; i < sbr->n_q; i++)
+ ch_data->bs_invf_mode[0][i] = get_bits(gb, 2);
+}
+
+static void read_sbr_envelope(SpectralBandReplication *sbr, GetBitContext *gb,
+ SBRData *ch_data, int ch)
+{
+ int bits;
+ int i, j, k;
+ VLC_TYPE (*t_huff)[2], (*f_huff)[2];
+ int t_lav, f_lav;
+ const int delta = (ch == 1 && sbr->bs_coupling == 1) + 1;
+ const int odd = sbr->n[1] & 1;
+
+ if (sbr->bs_coupling && ch) {
+ if (ch_data->bs_amp_res) {
+ bits = 5;
+ t_huff = vlc_sbr[T_HUFFMAN_ENV_BAL_3_0DB].table;
+ t_lav = vlc_sbr_lav[T_HUFFMAN_ENV_BAL_3_0DB];
+ f_huff = vlc_sbr[F_HUFFMAN_ENV_BAL_3_0DB].table;
+ f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_BAL_3_0DB];
+ } else {
+ bits = 6;
+ t_huff = vlc_sbr[T_HUFFMAN_ENV_BAL_1_5DB].table;
+ t_lav = vlc_sbr_lav[T_HUFFMAN_ENV_BAL_1_5DB];
+ f_huff = vlc_sbr[F_HUFFMAN_ENV_BAL_1_5DB].table;
+ f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_BAL_1_5DB];
+ }
+ } else {
+ if (ch_data->bs_amp_res) {
+ bits = 6;
+ t_huff = vlc_sbr[T_HUFFMAN_ENV_3_0DB].table;
+ t_lav = vlc_sbr_lav[T_HUFFMAN_ENV_3_0DB];
+ f_huff = vlc_sbr[F_HUFFMAN_ENV_3_0DB].table;
+ f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_3_0DB];
+ } else {
+ bits = 7;
+ t_huff = vlc_sbr[T_HUFFMAN_ENV_1_5DB].table;
+ t_lav = vlc_sbr_lav[T_HUFFMAN_ENV_1_5DB];
+ f_huff = vlc_sbr[F_HUFFMAN_ENV_1_5DB].table;
+ f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_1_5DB];
+ }
+ }
+
+ for (i = 0; i < ch_data->bs_num_env; i++) {
+ if (ch_data->bs_df_env[i]) {
+ // bs_freq_res[0] == bs_freq_res[bs_num_env] from prev frame
+ if (ch_data->bs_freq_res[i + 1] == ch_data->bs_freq_res[i]) {
+ for (j = 0; j < sbr->n[ch_data->bs_freq_res[i + 1]]; j++)
+ ch_data->env_facs[i + 1][j] = ch_data->env_facs[i][j] + delta * (get_vlc2(gb, t_huff, 9, 3) - t_lav);
+ } else if (ch_data->bs_freq_res[i + 1]) {
+ for (j = 0; j < sbr->n[ch_data->bs_freq_res[i + 1]]; j++) {
+ k = (j + odd) >> 1; // find k such that f_tablelow[k] <= f_tablehigh[j] < f_tablelow[k + 1]
+ ch_data->env_facs[i + 1][j] = ch_data->env_facs[i][k] + delta * (get_vlc2(gb, t_huff, 9, 3) - t_lav);
+ }
+ } else {
+ for (j = 0; j < sbr->n[ch_data->bs_freq_res[i + 1]]; j++) {
+ k = j ? 2*j - odd : 0; // find k such that f_tablehigh[k] == f_tablelow[j]
+ ch_data->env_facs[i + 1][j] = ch_data->env_facs[i][k] + delta * (get_vlc2(gb, t_huff, 9, 3) - t_lav);
+ }
+ }
+ } else {
+ ch_data->env_facs[i + 1][0] = delta * get_bits(gb, bits); // bs_env_start_value_balance
+ for (j = 1; j < sbr->n[ch_data->bs_freq_res[i + 1]]; j++)
+ 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);
+ }
+ }
+
+ //assign 0th elements of env_facs from last elements
+ memcpy(ch_data->env_facs[0], ch_data->env_facs[ch_data->bs_num_env],
+ sizeof(ch_data->env_facs[0]));
+}
+
+static void read_sbr_noise(SpectralBandReplication *sbr, GetBitContext *gb,
+ SBRData *ch_data, int ch)
+{
+ int i, j;
+ VLC_TYPE (*t_huff)[2], (*f_huff)[2];
+ int t_lav, f_lav;
+ int delta = (ch == 1 && sbr->bs_coupling == 1) + 1;
+
+ if (sbr->bs_coupling && ch) {
+ t_huff = vlc_sbr[T_HUFFMAN_NOISE_BAL_3_0DB].table;
+ t_lav = vlc_sbr_lav[T_HUFFMAN_NOISE_BAL_3_0DB];
+ f_huff = vlc_sbr[F_HUFFMAN_ENV_BAL_3_0DB].table;
+ f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_BAL_3_0DB];
+ } else {
+ t_huff = vlc_sbr[T_HUFFMAN_NOISE_3_0DB].table;
+ t_lav = vlc_sbr_lav[T_HUFFMAN_NOISE_3_0DB];
+ f_huff = vlc_sbr[F_HUFFMAN_ENV_3_0DB].table;
+ f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_3_0DB];
+ }
+
+ for (i = 0; i < ch_data->bs_num_noise; i++) {
+ if (ch_data->bs_df_noise[i]) {
+ for (j = 0; j < sbr->n_q; j++)
+ ch_data->noise_facs[i + 1][j] = ch_data->noise_facs[i][j] + delta * (get_vlc2(gb, t_huff, 9, 2) - t_lav);
+ } else {
+ ch_data->noise_facs[i + 1][0] = delta * get_bits(gb, 5); // bs_noise_start_value_balance or bs_noise_start_value_level
+ for (j = 1; j < sbr->n_q; j++)
+ 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);
+ }
+ }
+
+ //assign 0th elements of noise_facs from last elements
+ memcpy(ch_data->noise_facs[0], ch_data->noise_facs[ch_data->bs_num_noise],
+ sizeof(ch_data->noise_facs[0]));
+}
+
+static void read_sbr_extension(AACContext *ac, SpectralBandReplication *sbr,
+ GetBitContext *gb,
+ int bs_extension_id, int *num_bits_left)
+{
+ switch (bs_extension_id) {
+ case EXTENSION_ID_PS:
+ if (!ac->m4ac.ps) {
+ av_log(ac->avctx, AV_LOG_ERROR, "Parametric Stereo signaled to be not-present but was found in the bitstream.\n");
+ skip_bits_long(gb, *num_bits_left); // bs_fill_bits
+ *num_bits_left = 0;
+ } else {
+#if 1
+ *num_bits_left -= ff_ps_read_data(ac->avctx, gb, &sbr->ps, *num_bits_left);
+#else
+ av_log_missing_feature(ac->avctx, "Parametric Stereo is", 0);
+ skip_bits_long(gb, *num_bits_left); // bs_fill_bits
+ *num_bits_left = 0;
+#endif
+ }
+ break;
+ default:
+ av_log_missing_feature(ac->avctx, "Reserved SBR extensions are", 1);
+ skip_bits_long(gb, *num_bits_left); // bs_fill_bits
+ *num_bits_left = 0;
+ break;
+ }
+}
+
+static int read_sbr_single_channel_element(AACContext *ac,
+ SpectralBandReplication *sbr,
+ GetBitContext *gb)
+{
+ if (get_bits1(gb)) // bs_data_extra
+ skip_bits(gb, 4); // bs_reserved
+
+ if (read_sbr_grid(ac, sbr, gb, &sbr->data[0]))
+ return -1;
+ read_sbr_dtdf(sbr, gb, &sbr->data[0]);
+ read_sbr_invf(sbr, gb, &sbr->data[0]);
+ read_sbr_envelope(sbr, gb, &sbr->data[0], 0);
+ read_sbr_noise(sbr, gb, &sbr->data[0], 0);
+
+ if ((sbr->data[0].bs_add_harmonic_flag = get_bits1(gb)))
+ get_bits1_vector(gb, sbr->data[0].bs_add_harmonic, sbr->n[1]);
+
+ return 0;
+}
+
+static int read_sbr_channel_pair_element(AACContext *ac,
+ SpectralBandReplication *sbr,
+ GetBitContext *gb)
+{
+ if (get_bits1(gb)) // bs_data_extra
+ skip_bits(gb, 8); // bs_reserved
+
+ if ((sbr->bs_coupling = get_bits1(gb))) {
+ if (read_sbr_grid(ac, sbr, gb, &sbr->data[0]))
+ return -1;
+ copy_sbr_grid(&sbr->data[1], &sbr->data[0]);
+ read_sbr_dtdf(sbr, gb, &sbr->data[0]);
+ read_sbr_dtdf(sbr, gb, &sbr->data[1]);
+ read_sbr_invf(sbr, gb, &sbr->data[0]);
+ memcpy(sbr->data[1].bs_invf_mode[1], sbr->data[1].bs_invf_mode[0], sizeof(sbr->data[1].bs_invf_mode[0]));
+ memcpy(sbr->data[1].bs_invf_mode[0], sbr->data[0].bs_invf_mode[0], sizeof(sbr->data[1].bs_invf_mode[0]));
+ read_sbr_envelope(sbr, gb, &sbr->data[0], 0);
+ read_sbr_noise(sbr, gb, &sbr->data[0], 0);
+ read_sbr_envelope(sbr, gb, &sbr->data[1], 1);
+ read_sbr_noise(sbr, gb, &sbr->data[1], 1);
+ } else {
+ if (read_sbr_grid(ac, sbr, gb, &sbr->data[0]) ||
+ read_sbr_grid(ac, sbr, gb, &sbr->data[1]))
+ return -1;
+ read_sbr_dtdf(sbr, gb, &sbr->data[0]);
+ read_sbr_dtdf(sbr, gb, &sbr->data[1]);
+ read_sbr_invf(sbr, gb, &sbr->data[0]);
+ read_sbr_invf(sbr, gb, &sbr->data[1]);
+ read_sbr_envelope(sbr, gb, &sbr->data[0], 0);
+ read_sbr_envelope(sbr, gb, &sbr->data[1], 1);
+ read_sbr_noise(sbr, gb, &sbr->data[0], 0);
+ read_sbr_noise(sbr, gb, &sbr->data[1], 1);
+ }
+
+ if ((sbr->data[0].bs_add_harmonic_flag = get_bits1(gb)))
+ get_bits1_vector(gb, sbr->data[0].bs_add_harmonic, sbr->n[1]);
+ if ((sbr->data[1].bs_add_harmonic_flag = get_bits1(gb)))
+ get_bits1_vector(gb, sbr->data[1].bs_add_harmonic, sbr->n[1]);
+
+ return 0;
+}
+
+static unsigned int read_sbr_data(AACContext *ac, SpectralBandReplication *sbr,
+ GetBitContext *gb, int id_aac)
+{
+ unsigned int cnt = get_bits_count(gb);
+
+ if (id_aac == TYPE_SCE || id_aac == TYPE_CCE) {
+ if (read_sbr_single_channel_element(ac, sbr, gb)) {
+ sbr->start = 0;
+ return get_bits_count(gb) - cnt;
+ }
+ } else if (id_aac == TYPE_CPE) {
+ if (read_sbr_channel_pair_element(ac, sbr, gb)) {
+ sbr->start = 0;
+ return get_bits_count(gb) - cnt;
+ }
+ } else {
+ av_log(ac->avctx, AV_LOG_ERROR,
+ "Invalid bitstream - cannot apply SBR to element type %d\n", id_aac);
+ sbr->start = 0;
+ return get_bits_count(gb) - cnt;
+ }
+ if (get_bits1(gb)) { // bs_extended_data
+ int num_bits_left = get_bits(gb, 4); // bs_extension_size
+ if (num_bits_left == 15)
+ num_bits_left += get_bits(gb, 8); // bs_esc_count
+
+ num_bits_left <<= 3;
+ while (num_bits_left > 7) {
+ num_bits_left -= 2;
+ read_sbr_extension(ac, sbr, gb, get_bits(gb, 2), &num_bits_left); // bs_extension_id
+ }
+ if (num_bits_left < 0) {
+ av_log(ac->avctx, AV_LOG_ERROR, "SBR Extension over read.\n");
+ }
+ if (num_bits_left > 0)
+ skip_bits(gb, num_bits_left);
+ }
+
+ return get_bits_count(gb) - cnt;
+}
+
+static void sbr_reset(AACContext *ac, SpectralBandReplication *sbr)
+{
+ int err;
+ err = sbr_make_f_master(ac, sbr, &sbr->spectrum_params);
+ if (err >= 0)
+ err = sbr_make_f_derived(ac, sbr);
+ if (err < 0) {
+ av_log(ac->avctx, AV_LOG_ERROR,
+ "SBR reset failed. Switching SBR to pure upsampling mode.\n");
+ sbr->start = 0;
+ }
+}
+
+/**
+ * Decode Spectral Band Replication extension data; reference: table 4.55.
+ *
+ * @param crc flag indicating the presence of CRC checksum
+ * @param cnt length of TYPE_FIL syntactic element in bytes
+ *
+ * @return Returns number of bytes consumed from the TYPE_FIL element.
+ */
+int ff_decode_sbr_extension(AACContext *ac, SpectralBandReplication *sbr,
+ GetBitContext *gb_host, int crc, int cnt, int id_aac)
+{
+ unsigned int num_sbr_bits = 0, num_align_bits;
+ unsigned bytes_read;
+ GetBitContext gbc = *gb_host, *gb = &gbc;
+ skip_bits_long(gb_host, cnt*8 - 4);
+
+ sbr->reset = 0;
+
+ if (!sbr->sample_rate)
+ sbr->sample_rate = 2 * ac->m4ac.sample_rate; //TODO use the nominal sample rate for arbitrary sample rate support
+ if (!ac->m4ac.ext_sample_rate)
+ ac->m4ac.ext_sample_rate = 2 * ac->m4ac.sample_rate;
+
+ if (crc) {
+ skip_bits(gb, 10); // bs_sbr_crc_bits; TODO - implement CRC check
+ num_sbr_bits += 10;
+ }
+
+ //Save some state from the previous frame.
+ sbr->kx[0] = sbr->kx[1];
+ sbr->m[0] = sbr->m[1];
+
+ num_sbr_bits++;
+ if (get_bits1(gb)) // bs_header_flag
+ num_sbr_bits += read_sbr_header(sbr, gb);
+
+ if (sbr->reset)
+ sbr_reset(ac, sbr);
+
+ if (sbr->start)
+ num_sbr_bits += read_sbr_data(ac, sbr, gb, id_aac);
+
+ num_align_bits = ((cnt << 3) - 4 - num_sbr_bits) & 7;
+ bytes_read = ((num_sbr_bits + num_align_bits + 4) >> 3);
+
+ if (bytes_read > cnt) {
+ av_log(ac->avctx, AV_LOG_ERROR,
+ "Expected to read %d SBR bytes actually read %d.\n", cnt, bytes_read);
+ }
+ return cnt;
+}
+
+/// Dequantization and stereo decoding (14496-3 sp04 p203)
+static void sbr_dequant(SpectralBandReplication *sbr, int id_aac)
+{
+ int k, e;
+ int ch;
+
+ if (id_aac == TYPE_CPE && sbr->bs_coupling) {
+ float alpha = sbr->data[0].bs_amp_res ? 1.0f : 0.5f;
+ float pan_offset = sbr->data[0].bs_amp_res ? 12.0f : 24.0f;
+ for (e = 1; e <= sbr->data[0].bs_num_env; e++) {
+ for (k = 0; k < sbr->n[sbr->data[0].bs_freq_res[e]]; k++) {
+ float temp1 = exp2f(sbr->data[0].env_facs[e][k] * alpha + 7.0f);
+ float temp2 = exp2f((pan_offset - sbr->data[1].env_facs[e][k]) * alpha);
+ float fac = temp1 / (1.0f + temp2);
+ sbr->data[0].env_facs[e][k] = fac;
+ sbr->data[1].env_facs[e][k] = fac * temp2;
+ }
+ }
+ for (e = 1; e <= sbr->data[0].bs_num_noise; e++) {
+ for (k = 0; k < sbr->n_q; k++) {
+ float temp1 = exp2f(NOISE_FLOOR_OFFSET - sbr->data[0].noise_facs[e][k] + 1);
+ float temp2 = exp2f(12 - sbr->data[1].noise_facs[e][k]);
+ float fac = temp1 / (1.0f + temp2);
+ sbr->data[0].noise_facs[e][k] = fac;
+ sbr->data[1].noise_facs[e][k] = fac * temp2;
+ }
+ }
+ } else { // SCE or one non-coupled CPE
+ for (ch = 0; ch < (id_aac == TYPE_CPE) + 1; ch++) {
+ float alpha = sbr->data[ch].bs_amp_res ? 1.0f : 0.5f;
+ for (e = 1; e <= sbr->data[ch].bs_num_env; e++)
+ for (k = 0; k < sbr->n[sbr->data[ch].bs_freq_res[e]]; k++)
+ sbr->data[ch].env_facs[e][k] =
+ exp2f(alpha * sbr->data[ch].env_facs[e][k] + 6.0f);
+ for (e = 1; e <= sbr->data[ch].bs_num_noise; e++)
+ for (k = 0; k < sbr->n_q; k++)
+ sbr->data[ch].noise_facs[e][k] =
+ exp2f(NOISE_FLOOR_OFFSET - sbr->data[ch].noise_facs[e][k]);
+ }
+ }
+}
+
+/**
+ * Analysis QMF Bank (14496-3 sp04 p206)
+ *
+ * @param x pointer to the beginning of the first sample window
+ * @param W array of complex-valued samples split into subbands
+ */
+static void sbr_qmf_analysis(DSPContext *dsp, FFTContext *mdct,
+ SBRDSPContext *sbrdsp, const float *in, float *x,
+ float z[320], float W[2][32][32][2])
+{
+ int i;
+ memcpy(W[0], W[1], sizeof(W[0]));
+ memcpy(x , x+1024, (320-32)*sizeof(x[0]));
+ memcpy(x+288, in, 1024*sizeof(x[0]));
+ for (i = 0; i < 32; i++) { // numTimeSlots*RATE = 16*2 as 960 sample frames
+ // are not supported
+ dsp->vector_fmul_reverse(z, sbr_qmf_window_ds, x, 320);
+ sbrdsp->sum64x5(z);
+ sbrdsp->qmf_pre_shuffle(z);
+ mdct->imdct_half(mdct, z, z+64);
+ sbrdsp->qmf_post_shuffle(W[1][i], z);
+ x += 32;
+ }
+}
+
+/**
+ * Synthesis QMF Bank (14496-3 sp04 p206) and Downsampled Synthesis QMF Bank
+ * (14496-3 sp04 p206)
+ */
+static void sbr_qmf_synthesis(DSPContext *dsp, FFTContext *mdct,
+ SBRDSPContext *sbrdsp,
+ float *out, float X[2][38][64],
+ float mdct_buf[2][64],
+ float *v0, int *v_off, const unsigned int div)
+{
+ int i, n;
+ const float *sbr_qmf_window = div ? sbr_qmf_window_ds : sbr_qmf_window_us;
+ const int step = 128 >> div;
+ float *v;
+ for (i = 0; i < 32; i++) {
+ if (*v_off < step) {
+ int saved_samples = (1280 - 128) >> div;
+ memcpy(&v0[SBR_SYNTHESIS_BUF_SIZE - saved_samples], v0, saved_samples * sizeof(float));
+ *v_off = SBR_SYNTHESIS_BUF_SIZE - saved_samples - step;
+ } else {
+ *v_off -= step;
+ }
+ v = v0 + *v_off;
+ if (div) {
+ for (n = 0; n < 32; n++) {
+ X[0][i][ n] = -X[0][i][n];
+ X[0][i][32+n] = X[1][i][31-n];
+ }
+ mdct->imdct_half(mdct, mdct_buf[0], X[0][i]);
+ sbrdsp->qmf_deint_neg(v, mdct_buf[0]);
+ } else {
+ sbrdsp->neg_odd_64(X[1][i]);
+ mdct->imdct_half(mdct, mdct_buf[0], X[0][i]);
+ mdct->imdct_half(mdct, mdct_buf[1], X[1][i]);
+ sbrdsp->qmf_deint_bfly(v, mdct_buf[1], mdct_buf[0]);
+ }
+ dsp->vector_fmul_add(out, v , sbr_qmf_window , zero64, 64 >> div);
+ dsp->vector_fmul_add(out, v + ( 192 >> div), sbr_qmf_window + ( 64 >> div), out , 64 >> div);
+ dsp->vector_fmul_add(out, v + ( 256 >> div), sbr_qmf_window + (128 >> div), out , 64 >> div);
+ dsp->vector_fmul_add(out, v + ( 448 >> div), sbr_qmf_window + (192 >> div), out , 64 >> div);
+ dsp->vector_fmul_add(out, v + ( 512 >> div), sbr_qmf_window + (256 >> div), out , 64 >> div);
+ dsp->vector_fmul_add(out, v + ( 704 >> div), sbr_qmf_window + (320 >> div), out , 64 >> div);
+ dsp->vector_fmul_add(out, v + ( 768 >> div), sbr_qmf_window + (384 >> div), out , 64 >> div);
+ dsp->vector_fmul_add(out, v + ( 960 >> div), sbr_qmf_window + (448 >> div), out , 64 >> div);
+ dsp->vector_fmul_add(out, v + (1024 >> div), sbr_qmf_window + (512 >> div), out , 64 >> div);
+ dsp->vector_fmul_add(out, v + (1216 >> div), sbr_qmf_window + (576 >> div), out , 64 >> div);
+ out += 64 >> div;
+ }
+}
+
+/** High Frequency Generation (14496-3 sp04 p214+) and Inverse Filtering
+ * (14496-3 sp04 p214)
+ * Warning: This routine does not seem numerically stable.
+ */
+static void sbr_hf_inverse_filter(SBRDSPContext *dsp,
+ float (*alpha0)[2], float (*alpha1)[2],
+ const float X_low[32][40][2], int k0)
+{
+ int k;
+ for (k = 0; k < k0; k++) {
+ LOCAL_ALIGNED_16(float, phi, [3], [2][2]);
+ float dk;
+
+ dsp->autocorrelate(X_low[k], phi);
+
+ dk = phi[2][1][0] * phi[1][0][0] -
+ (phi[1][1][0] * phi[1][1][0] + phi[1][1][1] * phi[1][1][1]) / 1.000001f;
+
+ if (!dk) {
+ alpha1[k][0] = 0;
+ alpha1[k][1] = 0;
+ } else {
+ float temp_real, temp_im;
+ temp_real = phi[0][0][0] * phi[1][1][0] -
+ phi[0][0][1] * phi[1][1][1] -
+ phi[0][1][0] * phi[1][0][0];
+ temp_im = phi[0][0][0] * phi[1][1][1] +
+ phi[0][0][1] * phi[1][1][0] -
+ phi[0][1][1] * phi[1][0][0];
+
+ alpha1[k][0] = temp_real / dk;
+ alpha1[k][1] = temp_im / dk;
+ }
+
+ if (!phi[1][0][0]) {
+ alpha0[k][0] = 0;
+ alpha0[k][1] = 0;
+ } else {
+ float temp_real, temp_im;
+ temp_real = phi[0][0][0] + alpha1[k][0] * phi[1][1][0] +
+ alpha1[k][1] * phi[1][1][1];
+ temp_im = phi[0][0][1] + alpha1[k][1] * phi[1][1][0] -
+ alpha1[k][0] * phi[1][1][1];
+
+ alpha0[k][0] = -temp_real / phi[1][0][0];
+ alpha0[k][1] = -temp_im / phi[1][0][0];
+ }
+
+ if (alpha1[k][0] * alpha1[k][0] + alpha1[k][1] * alpha1[k][1] >= 16.0f ||
+ alpha0[k][0] * alpha0[k][0] + alpha0[k][1] * alpha0[k][1] >= 16.0f) {
+ alpha1[k][0] = 0;
+ alpha1[k][1] = 0;
+ alpha0[k][0] = 0;
+ alpha0[k][1] = 0;
+ }
+ }
+}
+
+/// Chirp Factors (14496-3 sp04 p214)
+static void sbr_chirp(SpectralBandReplication *sbr, SBRData *ch_data)
+{
+ int i;
+ float new_bw;
+ static const float bw_tab[] = { 0.0f, 0.75f, 0.9f, 0.98f };
+
+ for (i = 0; i < sbr->n_q; i++) {
+ if (ch_data->bs_invf_mode[0][i] + ch_data->bs_invf_mode[1][i] == 1) {
+ new_bw = 0.6f;
+ } else
+ new_bw = bw_tab[ch_data->bs_invf_mode[0][i]];
+
+ if (new_bw < ch_data->bw_array[i]) {
+ new_bw = 0.75f * new_bw + 0.25f * ch_data->bw_array[i];
+ } else
+ new_bw = 0.90625f * new_bw + 0.09375f * ch_data->bw_array[i];
+ ch_data->bw_array[i] = new_bw < 0.015625f ? 0.0f : new_bw;
+ }
+}
+
+/// Generate the subband filtered lowband
+static int sbr_lf_gen(AACContext *ac, SpectralBandReplication *sbr,
+ float X_low[32][40][2], const float W[2][32][32][2])
+{
+ int i, k;
+ const int t_HFGen = 8;
+ const int i_f = 32;
+ memset(X_low, 0, 32*sizeof(*X_low));
+ for (k = 0; k < sbr->kx[1]; k++) {
+ for (i = t_HFGen; i < i_f + t_HFGen; i++) {
+ X_low[k][i][0] = W[1][i - t_HFGen][k][0];
+ X_low[k][i][1] = W[1][i - t_HFGen][k][1];
+ }
+ }
+ for (k = 0; k < sbr->kx[0]; k++) {
+ for (i = 0; i < t_HFGen; i++) {
+ X_low[k][i][0] = W[0][i + i_f - t_HFGen][k][0];
+ X_low[k][i][1] = W[0][i + i_f - t_HFGen][k][1];
+ }
+ }
+ return 0;
+}
+
+/// High Frequency Generator (14496-3 sp04 p215)
+static int sbr_hf_gen(AACContext *ac, SpectralBandReplication *sbr,
+ float X_high[64][40][2], const float X_low[32][40][2],
+ const float (*alpha0)[2], const float (*alpha1)[2],
+ const float bw_array[5], const uint8_t *t_env,
+ int bs_num_env)
+{
+ int j, x;
+ int g = 0;
+ int k = sbr->kx[1];
+ for (j = 0; j < sbr->num_patches; j++) {
+ for (x = 0; x < sbr->patch_num_subbands[j]; x++, k++) {
+ const int p = sbr->patch_start_subband[j] + x;
+ while (g <= sbr->n_q && k >= sbr->f_tablenoise[g])
+ g++;
+ g--;
+
+ if (g < 0) {
+ av_log(ac->avctx, AV_LOG_ERROR,
+ "ERROR : no subband found for frequency %d\n", k);
+ return -1;
+ }
+
+ sbr->dsp.hf_gen(X_high[k] + ENVELOPE_ADJUSTMENT_OFFSET,
+ X_low[p] + ENVELOPE_ADJUSTMENT_OFFSET,
+ alpha0[p], alpha1[p], bw_array[g],
+ 2 * t_env[0], 2 * t_env[bs_num_env]);
+ }
+ }
+ if (k < sbr->m[1] + sbr->kx[1])
+ memset(X_high + k, 0, (sbr->m[1] + sbr->kx[1] - k) * sizeof(*X_high));
+
+ return 0;
+}
+
+/// Generate the subband filtered lowband
+static int sbr_x_gen(SpectralBandReplication *sbr, float X[2][38][64],
+ const float Y0[38][64][2], const float Y1[38][64][2],
+ const float X_low[32][40][2], int ch)
+{
+ int k, i;
+ const int i_f = 32;
+ const int i_Temp = FFMAX(2*sbr->data[ch].t_env_num_env_old - i_f, 0);
+ memset(X, 0, 2*sizeof(*X));
+ for (k = 0; k < sbr->kx[0]; k++) {
+ for (i = 0; i < i_Temp; i++) {
+ X[0][i][k] = X_low[k][i + ENVELOPE_ADJUSTMENT_OFFSET][0];
+ X[1][i][k] = X_low[k][i + ENVELOPE_ADJUSTMENT_OFFSET][1];
+ }
+ }
+ for (; k < sbr->kx[0] + sbr->m[0]; k++) {
+ for (i = 0; i < i_Temp; i++) {
+ X[0][i][k] = Y0[i + i_f][k][0];
+ X[1][i][k] = Y0[i + i_f][k][1];
+ }
+ }
+
+ for (k = 0; k < sbr->kx[1]; k++) {
+ for (i = i_Temp; i < 38; i++) {
+ X[0][i][k] = X_low[k][i + ENVELOPE_ADJUSTMENT_OFFSET][0];
+ X[1][i][k] = X_low[k][i + ENVELOPE_ADJUSTMENT_OFFSET][1];
+ }
+ }
+ for (; k < sbr->kx[1] + sbr->m[1]; k++) {
+ for (i = i_Temp; i < i_f; i++) {
+ X[0][i][k] = Y1[i][k][0];
+ X[1][i][k] = Y1[i][k][1];
+ }
+ }
+ return 0;
+}
+
+/** High Frequency Adjustment (14496-3 sp04 p217) and Mapping
+ * (14496-3 sp04 p217)
+ */
+static void sbr_mapping(AACContext *ac, SpectralBandReplication *sbr,
+ SBRData *ch_data, int e_a[2])
+{
+ int e, i, m;
+
+ memset(ch_data->s_indexmapped[1], 0, 7*sizeof(ch_data->s_indexmapped[1]));
+ for (e = 0; e < ch_data->bs_num_env; e++) {
+ const unsigned int ilim = sbr->n[ch_data->bs_freq_res[e + 1]];
+ uint16_t *table = ch_data->bs_freq_res[e + 1] ? sbr->f_tablehigh : sbr->f_tablelow;
+ int k;
+
+ av_assert0(sbr->kx[1] <= table[0]);
+ for (i = 0; i < ilim; i++)
+ for (m = table[i]; m < table[i + 1]; m++)
+ sbr->e_origmapped[e][m - sbr->kx[1]] = ch_data->env_facs[e+1][i];
+
+ // ch_data->bs_num_noise > 1 => 2 noise floors
+ k = (ch_data->bs_num_noise > 1) && (ch_data->t_env[e] >= ch_data->t_q[1]);
+ for (i = 0; i < sbr->n_q; i++)
+ for (m = sbr->f_tablenoise[i]; m < sbr->f_tablenoise[i + 1]; m++)
+ sbr->q_mapped[e][m - sbr->kx[1]] = ch_data->noise_facs[k+1][i];
+
+ for (i = 0; i < sbr->n[1]; i++) {
+ if (ch_data->bs_add_harmonic_flag) {
+ const unsigned int m_midpoint =
+ (sbr->f_tablehigh[i] + sbr->f_tablehigh[i + 1]) >> 1;
+
+ ch_data->s_indexmapped[e + 1][m_midpoint - sbr->kx[1]] = ch_data->bs_add_harmonic[i] *
+ (e >= e_a[1] || (ch_data->s_indexmapped[0][m_midpoint - sbr->kx[1]] == 1));
+ }
+ }
+
+ for (i = 0; i < ilim; i++) {
+ int additional_sinusoid_present = 0;
+ for (m = table[i]; m < table[i + 1]; m++) {
+ if (ch_data->s_indexmapped[e + 1][m - sbr->kx[1]]) {
+ additional_sinusoid_present = 1;
+ break;
+ }
+ }
+ memset(&sbr->s_mapped[e][table[i] - sbr->kx[1]], additional_sinusoid_present,
+ (table[i + 1] - table[i]) * sizeof(sbr->s_mapped[e][0]));
+ }
+ }
+
+ memcpy(ch_data->s_indexmapped[0], ch_data->s_indexmapped[ch_data->bs_num_env], sizeof(ch_data->s_indexmapped[0]));
+}
+
+/// Estimation of current envelope (14496-3 sp04 p218)
+static void sbr_env_estimate(float (*e_curr)[48], float X_high[64][40][2],
+ SpectralBandReplication *sbr, SBRData *ch_data)
+{
+ int e, m;
+ int kx1 = sbr->kx[1];
+
+ if (sbr->bs_interpol_freq) {
+ for (e = 0; e < ch_data->bs_num_env; e++) {
+ const float recip_env_size = 0.5f / (ch_data->t_env[e + 1] - ch_data->t_env[e]);
+ int ilb = ch_data->t_env[e] * 2 + ENVELOPE_ADJUSTMENT_OFFSET;
+ int iub = ch_data->t_env[e + 1] * 2 + ENVELOPE_ADJUSTMENT_OFFSET;
+
+ for (m = 0; m < sbr->m[1]; m++) {
+ float sum = sbr->dsp.sum_square(X_high[m+kx1] + ilb, iub - ilb);
+ e_curr[e][m] = sum * recip_env_size;
+ }
+ }
+ } else {
+ int k, p;
+
+ for (e = 0; e < ch_data->bs_num_env; e++) {
+ const int env_size = 2 * (ch_data->t_env[e + 1] - ch_data->t_env[e]);
+ int ilb = ch_data->t_env[e] * 2 + ENVELOPE_ADJUSTMENT_OFFSET;
+ int iub = ch_data->t_env[e + 1] * 2 + ENVELOPE_ADJUSTMENT_OFFSET;
+ const uint16_t *table = ch_data->bs_freq_res[e + 1] ? sbr->f_tablehigh : sbr->f_tablelow;
+
+ for (p = 0; p < sbr->n[ch_data->bs_freq_res[e + 1]]; p++) {
+ float sum = 0.0f;
+ const int den = env_size * (table[p + 1] - table[p]);
+
+ for (k = table[p]; k < table[p + 1]; k++) {
+ sum += sbr->dsp.sum_square(X_high[k] + ilb, iub - ilb);
+ }
+ sum /= den;
+ for (k = table[p]; k < table[p + 1]; k++) {
+ e_curr[e][k - kx1] = sum;
+ }
+ }
+ }
+ }
+}
+
+/**
+ * Calculation of levels of additional HF signal components (14496-3 sp04 p219)
+ * and Calculation of gain (14496-3 sp04 p219)
+ */
+static void sbr_gain_calc(AACContext *ac, SpectralBandReplication *sbr,
+ SBRData *ch_data, const int e_a[2])
+{
+ int e, k, m;
+ // max gain limits : -3dB, 0dB, 3dB, inf dB (limiter off)
+ static const float limgain[4] = { 0.70795, 1.0, 1.41254, 10000000000 };
+
+ for (e = 0; e < ch_data->bs_num_env; e++) {
+ int delta = !((e == e_a[1]) || (e == e_a[0]));
+ for (k = 0; k < sbr->n_lim; k++) {
+ float gain_boost, gain_max;
+ float sum[2] = { 0.0f, 0.0f };
+ for (m = sbr->f_tablelim[k] - sbr->kx[1]; m < sbr->f_tablelim[k + 1] - sbr->kx[1]; m++) {
+ const float temp = sbr->e_origmapped[e][m] / (1.0f + sbr->q_mapped[e][m]);
+ sbr->q_m[e][m] = sqrtf(temp * sbr->q_mapped[e][m]);
+ sbr->s_m[e][m] = sqrtf(temp * ch_data->s_indexmapped[e + 1][m]);
+ if (!sbr->s_mapped[e][m]) {
+ sbr->gain[e][m] = sqrtf(sbr->e_origmapped[e][m] /
+ ((1.0f + sbr->e_curr[e][m]) *
+ (1.0f + sbr->q_mapped[e][m] * delta)));
+ } else {
+ sbr->gain[e][m] = sqrtf(sbr->e_origmapped[e][m] * sbr->q_mapped[e][m] /
+ ((1.0f + sbr->e_curr[e][m]) *
+ (1.0f + sbr->q_mapped[e][m])));
+ }
+ }
+ for (m = sbr->f_tablelim[k] - sbr->kx[1]; m < sbr->f_tablelim[k + 1] - sbr->kx[1]; m++) {
+ sum[0] += sbr->e_origmapped[e][m];
+ sum[1] += sbr->e_curr[e][m];
+ }
+ gain_max = limgain[sbr->bs_limiter_gains] * sqrtf((FLT_EPSILON + sum[0]) / (FLT_EPSILON + sum[1]));
+ gain_max = FFMIN(100000.f, gain_max);
+ for (m = sbr->f_tablelim[k] - sbr->kx[1]; m < sbr->f_tablelim[k + 1] - sbr->kx[1]; m++) {
+ float q_m_max = sbr->q_m[e][m] * gain_max / sbr->gain[e][m];
+ sbr->q_m[e][m] = FFMIN(sbr->q_m[e][m], q_m_max);
+ sbr->gain[e][m] = FFMIN(sbr->gain[e][m], gain_max);
+ }
+ sum[0] = sum[1] = 0.0f;
+ for (m = sbr->f_tablelim[k] - sbr->kx[1]; m < sbr->f_tablelim[k + 1] - sbr->kx[1]; m++) {
+ sum[0] += sbr->e_origmapped[e][m];
+ sum[1] += sbr->e_curr[e][m] * sbr->gain[e][m] * sbr->gain[e][m]
+ + sbr->s_m[e][m] * sbr->s_m[e][m]
+ + (delta && !sbr->s_m[e][m]) * sbr->q_m[e][m] * sbr->q_m[e][m];
+ }
+ gain_boost = sqrtf((FLT_EPSILON + sum[0]) / (FLT_EPSILON + sum[1]));
+ gain_boost = FFMIN(1.584893192f, gain_boost);
+ for (m = sbr->f_tablelim[k] - sbr->kx[1]; m < sbr->f_tablelim[k + 1] - sbr->kx[1]; m++) {
+ sbr->gain[e][m] *= gain_boost;
+ sbr->q_m[e][m] *= gain_boost;
+ sbr->s_m[e][m] *= gain_boost;
+ }
+ }
+ }
+}
+
+/// Assembling HF Signals (14496-3 sp04 p220)
+static void sbr_hf_assemble(float Y1[38][64][2],
+ const float X_high[64][40][2],
+ SpectralBandReplication *sbr, SBRData *ch_data,
+ const int e_a[2])
+{
+ int e, i, j, m;
+ const int h_SL = 4 * !sbr->bs_smoothing_mode;
+ const int kx = sbr->kx[1];
+ const int m_max = sbr->m[1];
+ static const float h_smooth[5] = {
+ 0.33333333333333,
+ 0.30150283239582,
+ 0.21816949906249,
+ 0.11516383427084,
+ 0.03183050093751,
+ };
+ static const int8_t phi[2][4] = {
+ { 1, 0, -1, 0}, // real
+ { 0, 1, 0, -1}, // imaginary
+ };
+ float (*g_temp)[48] = ch_data->g_temp, (*q_temp)[48] = ch_data->q_temp;
+ int indexnoise = ch_data->f_indexnoise;
+ int indexsine = ch_data->f_indexsine;
+
+ if (sbr->reset) {
+ for (i = 0; i < h_SL; i++) {
+ memcpy(g_temp[i + 2*ch_data->t_env[0]], sbr->gain[0], m_max * sizeof(sbr->gain[0][0]));
+ memcpy(q_temp[i + 2*ch_data->t_env[0]], sbr->q_m[0], m_max * sizeof(sbr->q_m[0][0]));
+ }
+ } else if (h_SL) {
+ memcpy(g_temp[2*ch_data->t_env[0]], g_temp[2*ch_data->t_env_num_env_old], 4*sizeof(g_temp[0]));
+ memcpy(q_temp[2*ch_data->t_env[0]], q_temp[2*ch_data->t_env_num_env_old], 4*sizeof(q_temp[0]));
+ }
+
+ for (e = 0; e < ch_data->bs_num_env; e++) {
+ for (i = 2 * ch_data->t_env[e]; i < 2 * ch_data->t_env[e + 1]; i++) {
+ memcpy(g_temp[h_SL + i], sbr->gain[e], m_max * sizeof(sbr->gain[0][0]));
+ memcpy(q_temp[h_SL + i], sbr->q_m[e], m_max * sizeof(sbr->q_m[0][0]));
+ }
+ }
+
+ for (e = 0; e < ch_data->bs_num_env; e++) {
+ for (i = 2 * ch_data->t_env[e]; i < 2 * ch_data->t_env[e + 1]; i++) {
+ int phi_sign = (1 - 2*(kx & 1));
+ LOCAL_ALIGNED_16(float, g_filt_tab, [48]);
+ LOCAL_ALIGNED_16(float, q_filt_tab, [48]);
+ float *g_filt, *q_filt;
+
+ if (h_SL && e != e_a[0] && e != e_a[1]) {
+ g_filt = g_filt_tab;
+ q_filt = q_filt_tab;
+ for (m = 0; m < m_max; m++) {
+ const int idx1 = i + h_SL;
+ g_filt[m] = 0.0f;
+ q_filt[m] = 0.0f;
+ for (j = 0; j <= h_SL; j++) {
+ g_filt[m] += g_temp[idx1 - j][m] * h_smooth[j];
+ q_filt[m] += q_temp[idx1 - j][m] * h_smooth[j];
+ }
+ }
+ } else {
+ g_filt = g_temp[i + h_SL];
+ q_filt = q_temp[i];
+ }
+
+ sbr->dsp.hf_g_filt(Y1[i] + kx, X_high + kx, g_filt, m_max,
+ i + ENVELOPE_ADJUSTMENT_OFFSET);
+
+ if (e != e_a[0] && e != e_a[1]) {
+ sbr->dsp.hf_apply_noise[indexsine](Y1[i] + kx, sbr->s_m[e],
+ q_filt, indexnoise,
+ kx, m_max);
+ } else {
+ for (m = 0; m < m_max; m++) {
+ Y1[i][m + kx][0] +=
+ sbr->s_m[e][m] * phi[0][indexsine];
+ Y1[i][m + kx][1] +=
+ sbr->s_m[e][m] * (phi[1][indexsine] * phi_sign);
+ phi_sign = -phi_sign;
+ }
+ }
+ indexnoise = (indexnoise + m_max) & 0x1ff;
+ indexsine = (indexsine + 1) & 3;
+ }
+ }
+ ch_data->f_indexnoise = indexnoise;
+ ch_data->f_indexsine = indexsine;
+}
+
+void ff_sbr_apply(AACContext *ac, SpectralBandReplication *sbr, int id_aac,
+ float* L, float* R)
+{
+ int downsampled = ac->m4ac.ext_sample_rate < sbr->sample_rate;
+ int ch;
+ int nch = (id_aac == TYPE_CPE) ? 2 : 1;
+
+ if (sbr->start) {
+ sbr_dequant(sbr, id_aac);
+ }
+ for (ch = 0; ch < nch; ch++) {
+ /* decode channel */
+ sbr_qmf_analysis(&ac->dsp, &sbr->mdct_ana, &sbr->dsp, ch ? R : L, sbr->data[ch].analysis_filterbank_samples,
+ (float*)sbr->qmf_filter_scratch,
+ sbr->data[ch].W);
+ sbr_lf_gen(ac, sbr, sbr->X_low, sbr->data[ch].W);
+ if (sbr->start) {
+ sbr_hf_inverse_filter(&sbr->dsp, sbr->alpha0, sbr->alpha1, sbr->X_low, sbr->k[0]);
+ sbr_chirp(sbr, &sbr->data[ch]);
+ sbr_hf_gen(ac, sbr, sbr->X_high, sbr->X_low, sbr->alpha0, sbr->alpha1,
+ sbr->data[ch].bw_array, sbr->data[ch].t_env,
+ sbr->data[ch].bs_num_env);
+
+ // hf_adj
+ sbr_mapping(ac, sbr, &sbr->data[ch], sbr->data[ch].e_a);
+ sbr_env_estimate(sbr->e_curr, sbr->X_high, sbr, &sbr->data[ch]);
+ sbr_gain_calc(ac, sbr, &sbr->data[ch], sbr->data[ch].e_a);
+ sbr->data[ch].Ypos ^= 1;
+ sbr_hf_assemble(sbr->data[ch].Y[sbr->data[ch].Ypos],
+ sbr->X_high, sbr, &sbr->data[ch],
+ sbr->data[ch].e_a);
+ }
+
+ /* synthesis */
+ sbr_x_gen(sbr, sbr->X[ch],
+ sbr->data[ch].Y[1-sbr->data[ch].Ypos],
+ sbr->data[ch].Y[ sbr->data[ch].Ypos],
+ sbr->X_low, ch);
+ }
+
+ if (ac->m4ac.ps == 1) {
+ if (sbr->ps.start) {
+ ff_ps_apply(ac->avctx, &sbr->ps, sbr->X[0], sbr->X[1], sbr->kx[1] + sbr->m[1]);
+ } else {
+ memcpy(sbr->X[1], sbr->X[0], sizeof(sbr->X[0]));
+ }
+ nch = 2;
+ }
+
+ sbr_qmf_synthesis(&ac->dsp, &sbr->mdct, &sbr->dsp, L, sbr->X[0], sbr->qmf_filter_scratch,
+ sbr->data[0].synthesis_filterbank_samples,
+ &sbr->data[0].synthesis_filterbank_samples_offset,
+ downsampled);
+ if (nch == 2)
+ sbr_qmf_synthesis(&ac->dsp, &sbr->mdct, &sbr->dsp, R, sbr->X[1], sbr->qmf_filter_scratch,
+ sbr->data[1].synthesis_filterbank_samples,
+ &sbr->data[1].synthesis_filterbank_samples_offset,
+ downsampled);
+}
diff --git a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacsbr.h b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacsbr.h index 153070d3f..32d026f83 100644 --- a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacsbr.h +++ b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacsbr.h @@ -1,49 +1,49 @@ -/* - * AAC Spectral Band Replication function declarations - * Copyright (c) 2008-2009 Robert Swain ( rob opendot cl ) - * Copyright (c) 2010 Alex Converse <alex.converse@gmail.com> - * - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/** - * @file - * AAC Spectral Band Replication function declarations - * @author Robert Swain ( rob opendot cl ) - */ - -#ifndef AVCODEC_AACSBR_H -#define AVCODEC_AACSBR_H - -#include "get_bits.h" -#include "aac.h" -#include "sbr.h" - -/** Initialize SBR. */ -av_cold void ff_aac_sbr_init(void); -/** Initialize one SBR context. */ -av_cold void ff_aac_sbr_ctx_init(AACContext *ac, SpectralBandReplication *sbr); -/** Close one SBR context. */ -av_cold void ff_aac_sbr_ctx_close(SpectralBandReplication *sbr); -/** Decode one SBR element. */ -int ff_decode_sbr_extension(AACContext *ac, SpectralBandReplication *sbr, - GetBitContext *gb, int crc, int cnt, int id_aac); -/** Apply one SBR element to one AAC element. */ -void ff_sbr_apply(AACContext *ac, SpectralBandReplication *sbr, int id_aac, - float* L, float *R); - -#endif /* AVCODEC_AACSBR_H */ +/*
+ * AAC Spectral Band Replication function declarations
+ * Copyright (c) 2008-2009 Robert Swain ( rob opendot cl )
+ * Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * AAC Spectral Band Replication function declarations
+ * @author Robert Swain ( rob opendot cl )
+ */
+
+#ifndef AVCODEC_AACSBR_H
+#define AVCODEC_AACSBR_H
+
+#include "get_bits.h"
+#include "aac.h"
+#include "sbr.h"
+
+/** Initialize SBR. */
+av_cold void ff_aac_sbr_init(void);
+/** Initialize one SBR context. */
+av_cold void ff_aac_sbr_ctx_init(AACContext *ac, SpectralBandReplication *sbr);
+/** Close one SBR context. */
+av_cold void ff_aac_sbr_ctx_close(SpectralBandReplication *sbr);
+/** Decode one SBR element. */
+int ff_decode_sbr_extension(AACContext *ac, SpectralBandReplication *sbr,
+ GetBitContext *gb, int crc, int cnt, int id_aac);
+/** Apply one SBR element to one AAC element. */
+void ff_sbr_apply(AACContext *ac, SpectralBandReplication *sbr, int id_aac,
+ float* L, float *R);
+
+#endif /* AVCODEC_AACSBR_H */
diff --git a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacsbrdata.h b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacsbrdata.h index a796e9deb..b36200817 100644 --- a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacsbrdata.h +++ b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aacsbrdata.h @@ -1,616 +1,616 @@ -/* - * AAC Spectral Band Replication decoding data - * Copyright (c) 2008-2009 Robert Swain ( rob opendot cl ) - * - * This file is part of FFmpeg. - * - * FFmpeg is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * FFmpeg is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/** - * @file - * AAC Spectral Band Replication decoding data - * @author Robert Swain ( rob opendot cl ) - */ - -#ifndef AVCODEC_AACSBRDATA_H -#define AVCODEC_AACSBRDATA_H - -#include <stdint.h> -#include "libavutil/mem.h" - -///< Huffman tables for SBR - -static const uint8_t t_huffman_env_1_5dB_bits[121] = { - 18, 18, 18, 18, 18, 18, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 17, 18, 16, 17, 18, 17, - 16, 16, 16, 16, 15, 14, 14, 13, - 13, 12, 11, 10, 9, 8, 7, 6, - 5, 4, 3, 2, 2, 3, 4, 5, - 6, 7, 8, 9, 10, 12, 13, 14, - 14, 15, 16, 17, 16, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, - 19, -}; - -static const uint32_t t_huffman_env_1_5dB_codes[121] = { - 0x3ffd6, 0x3ffd7, 0x3ffd8, 0x3ffd9, 0x3ffda, 0x3ffdb, 0x7ffb8, 0x7ffb9, - 0x7ffba, 0x7ffbb, 0x7ffbc, 0x7ffbd, 0x7ffbe, 0x7ffbf, 0x7ffc0, 0x7ffc1, - 0x7ffc2, 0x7ffc3, 0x7ffc4, 0x7ffc5, 0x7ffc6, 0x7ffc7, 0x7ffc8, 0x7ffc9, - 0x7ffca, 0x7ffcb, 0x7ffcc, 0x7ffcd, 0x7ffce, 0x7ffcf, 0x7ffd0, 0x7ffd1, - 0x7ffd2, 0x7ffd3, 0x1ffe6, 0x3ffd4, 0x0fff0, 0x1ffe9, 0x3ffd5, 0x1ffe7, - 0x0fff1, 0x0ffec, 0x0ffed, 0x0ffee, 0x07ff4, 0x03ff9, 0x03ff7, 0x01ffa, - 0x01ff9, 0x00ffb, 0x007fc, 0x003fc, 0x001fd, 0x000fd, 0x0007d, 0x0003d, - 0x0001d, 0x0000d, 0x00005, 0x00001, 0x00000, 0x00004, 0x0000c, 0x0001c, - 0x0003c, 0x0007c, 0x000fc, 0x001fc, 0x003fd, 0x00ffa, 0x01ff8, 0x03ff6, - 0x03ff8, 0x07ff5, 0x0ffef, 0x1ffe8, 0x0fff2, 0x7ffd4, 0x7ffd5, 0x7ffd6, - 0x7ffd7, 0x7ffd8, 0x7ffd9, 0x7ffda, 0x7ffdb, 0x7ffdc, 0x7ffdd, 0x7ffde, - 0x7ffdf, 0x7ffe0, 0x7ffe1, 0x7ffe2, 0x7ffe3, 0x7ffe4, 0x7ffe5, 0x7ffe6, - 0x7ffe7, 0x7ffe8, 0x7ffe9, 0x7ffea, 0x7ffeb, 0x7ffec, 0x7ffed, 0x7ffee, - 0x7ffef, 0x7fff0, 0x7fff1, 0x7fff2, 0x7fff3, 0x7fff4, 0x7fff5, 0x7fff6, - 0x7fff7, 0x7fff8, 0x7fff9, 0x7fffa, 0x7fffb, 0x7fffc, 0x7fffd, 0x7fffe, - 0x7ffff, -}; - -static const uint8_t f_huffman_env_1_5dB_bits[121] = { - 19, 19, 20, 20, 20, 20, 20, 20, - 20, 19, 20, 20, 20, 20, 19, 20, - 19, 19, 20, 18, 20, 20, 20, 19, - 20, 20, 20, 19, 20, 19, 18, 19, - 18, 18, 17, 18, 17, 17, 17, 16, - 16, 16, 15, 15, 14, 13, 13, 12, - 12, 11, 10, 9, 9, 8, 7, 6, - 5, 4, 3, 2, 2, 3, 4, 5, - 6, 8, 8, 9, 10, 11, 11, 11, - 12, 12, 13, 13, 14, 14, 16, 16, - 17, 17, 18, 18, 18, 18, 18, 18, - 18, 20, 19, 20, 20, 20, 20, 20, - 20, 19, 20, 20, 20, 20, 19, 20, - 18, 20, 20, 19, 19, 20, 20, 20, - 20, 20, 20, 20, 20, 20, 20, 20, - 20, -}; - -static const uint32_t f_huffman_env_1_5dB_codes[121] = { - 0x7ffe7, 0x7ffe8, 0xfffd2, 0xfffd3, 0xfffd4, 0xfffd5, 0xfffd6, 0xfffd7, - 0xfffd8, 0x7ffda, 0xfffd9, 0xfffda, 0xfffdb, 0xfffdc, 0x7ffdb, 0xfffdd, - 0x7ffdc, 0x7ffdd, 0xfffde, 0x3ffe4, 0xfffdf, 0xfffe0, 0xfffe1, 0x7ffde, - 0xfffe2, 0xfffe3, 0xfffe4, 0x7ffdf, 0xfffe5, 0x7ffe0, 0x3ffe8, 0x7ffe1, - 0x3ffe0, 0x3ffe9, 0x1ffef, 0x3ffe5, 0x1ffec, 0x1ffed, 0x1ffee, 0x0fff4, - 0x0fff3, 0x0fff0, 0x07ff7, 0x07ff6, 0x03ffa, 0x01ffa, 0x01ff9, 0x00ffa, - 0x00ff8, 0x007f9, 0x003fb, 0x001fc, 0x001fa, 0x000fb, 0x0007c, 0x0003c, - 0x0001c, 0x0000c, 0x00005, 0x00001, 0x00000, 0x00004, 0x0000d, 0x0001d, - 0x0003d, 0x000fa, 0x000fc, 0x001fb, 0x003fa, 0x007f8, 0x007fa, 0x007fb, - 0x00ff9, 0x00ffb, 0x01ff8, 0x01ffb, 0x03ff8, 0x03ff9, 0x0fff1, 0x0fff2, - 0x1ffea, 0x1ffeb, 0x3ffe1, 0x3ffe2, 0x3ffea, 0x3ffe3, 0x3ffe6, 0x3ffe7, - 0x3ffeb, 0xfffe6, 0x7ffe2, 0xfffe7, 0xfffe8, 0xfffe9, 0xfffea, 0xfffeb, - 0xfffec, 0x7ffe3, 0xfffed, 0xfffee, 0xfffef, 0xffff0, 0x7ffe4, 0xffff1, - 0x3ffec, 0xffff2, 0xffff3, 0x7ffe5, 0x7ffe6, 0xffff4, 0xffff5, 0xffff6, - 0xffff7, 0xffff8, 0xffff9, 0xffffa, 0xffffb, 0xffffc, 0xffffd, 0xffffe, - 0xfffff, -}; - -static const uint8_t t_huffman_env_bal_1_5dB_bits[49] = { - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 12, 11, 9, 7, 5, 3, - 1, 2, 4, 6, 8, 11, 12, 15, - 16, 16, 16, 16, 16, 16, 16, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, -}; - -static const uint32_t t_huffman_env_bal_1_5dB_codes[49] = { - 0x0ffe4, 0x0ffe5, 0x0ffe6, 0x0ffe7, 0x0ffe8, 0x0ffe9, 0x0ffea, 0x0ffeb, - 0x0ffec, 0x0ffed, 0x0ffee, 0x0ffef, 0x0fff0, 0x0fff1, 0x0fff2, 0x0fff3, - 0x0fff4, 0x0ffe2, 0x00ffc, 0x007fc, 0x001fe, 0x0007e, 0x0001e, 0x00006, - 0x00000, 0x00002, 0x0000e, 0x0003e, 0x000fe, 0x007fd, 0x00ffd, 0x07ff0, - 0x0ffe3, 0x0fff5, 0x0fff6, 0x0fff7, 0x0fff8, 0x0fff9, 0x0fffa, 0x1fff6, - 0x1fff7, 0x1fff8, 0x1fff9, 0x1fffa, 0x1fffb, 0x1fffc, 0x1fffd, 0x1fffe, - 0x1ffff, -}; - -static const uint8_t f_huffman_env_bal_1_5dB_bits[49] = { - 18, 18, 18, 18, 18, 18, 18, 18, - 18, 18, 18, 18, 18, 18, 18, 16, - 17, 14, 11, 11, 8, 7, 4, 2, - 1, 3, 5, 6, 9, 11, 12, 15, - 16, 18, 18, 18, 18, 18, 18, 18, - 18, 18, 18, 18, 18, 18, 18, 19, - 19, -}; - -static const uint32_t f_huffman_env_bal_1_5dB_codes[49] = { - 0x3ffe2, 0x3ffe3, 0x3ffe4, 0x3ffe5, 0x3ffe6, 0x3ffe7, 0x3ffe8, 0x3ffe9, - 0x3ffea, 0x3ffeb, 0x3ffec, 0x3ffed, 0x3ffee, 0x3ffef, 0x3fff0, 0x0fff7, - 0x1fff0, 0x03ffc, 0x007fe, 0x007fc, 0x000fe, 0x0007e, 0x0000e, 0x00002, - 0x00000, 0x00006, 0x0001e, 0x0003e, 0x001fe, 0x007fd, 0x00ffe, 0x07ffa, - 0x0fff6, 0x3fff1, 0x3fff2, 0x3fff3, 0x3fff4, 0x3fff5, 0x3fff6, 0x3fff7, - 0x3fff8, 0x3fff9, 0x3fffa, 0x3fffb, 0x3fffc, 0x3fffd, 0x3fffe, 0x7fffe, - 0x7ffff, -}; - -static const uint8_t t_huffman_env_3_0dB_bits[63] = { - 18, 18, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, - 19, 17, 16, 16, 16, 14, 14, 14, - 13, 12, 11, 8, 6, 4, 2, 1, - 3, 5, 7, 9, 11, 13, 14, 14, - 15, 16, 17, 18, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, -}; - -static const uint32_t t_huffman_env_3_0dB_codes[63] = { - 0x3ffed, 0x3ffee, 0x7ffde, 0x7ffdf, 0x7ffe0, 0x7ffe1, 0x7ffe2, 0x7ffe3, - 0x7ffe4, 0x7ffe5, 0x7ffe6, 0x7ffe7, 0x7ffe8, 0x7ffe9, 0x7ffea, 0x7ffeb, - 0x7ffec, 0x1fff4, 0x0fff7, 0x0fff9, 0x0fff8, 0x03ffb, 0x03ffa, 0x03ff8, - 0x01ffa, 0x00ffc, 0x007fc, 0x000fe, 0x0003e, 0x0000e, 0x00002, 0x00000, - 0x00006, 0x0001e, 0x0007e, 0x001fe, 0x007fd, 0x01ffb, 0x03ff9, 0x03ffc, - 0x07ffa, 0x0fff6, 0x1fff5, 0x3ffec, 0x7ffed, 0x7ffee, 0x7ffef, 0x7fff0, - 0x7fff1, 0x7fff2, 0x7fff3, 0x7fff4, 0x7fff5, 0x7fff6, 0x7fff7, 0x7fff8, - 0x7fff9, 0x7fffa, 0x7fffb, 0x7fffc, 0x7fffd, 0x7fffe, 0x7ffff, -}; - -static const uint8_t f_huffman_env_3_0dB_bits[63] = { - 20, 20, 20, 20, 20, 20, 20, 18, - 19, 19, 19, 19, 18, 18, 20, 19, - 17, 18, 17, 16, 16, 15, 14, 12, - 11, 10, 9, 8, 6, 4, 2, 1, - 3, 5, 8, 9, 10, 11, 12, 13, - 14, 15, 15, 16, 16, 17, 17, 18, - 18, 18, 20, 19, 19, 19, 20, 19, - 19, 20, 20, 20, 20, 20, 20, -}; - -static const uint32_t f_huffman_env_3_0dB_codes[63] = { - 0xffff0, 0xffff1, 0xffff2, 0xffff3, 0xffff4, 0xffff5, 0xffff6, 0x3fff3, - 0x7fff5, 0x7ffee, 0x7ffef, 0x7fff6, 0x3fff4, 0x3fff2, 0xffff7, 0x7fff0, - 0x1fff5, 0x3fff0, 0x1fff4, 0x0fff7, 0x0fff6, 0x07ff8, 0x03ffb, 0x00ffd, - 0x007fd, 0x003fd, 0x001fd, 0x000fd, 0x0003e, 0x0000e, 0x00002, 0x00000, - 0x00006, 0x0001e, 0x000fc, 0x001fc, 0x003fc, 0x007fc, 0x00ffc, 0x01ffc, - 0x03ffa, 0x07ff9, 0x07ffa, 0x0fff8, 0x0fff9, 0x1fff6, 0x1fff7, 0x3fff5, - 0x3fff6, 0x3fff1, 0xffff8, 0x7fff1, 0x7fff2, 0x7fff3, 0xffff9, 0x7fff7, - 0x7fff4, 0xffffa, 0xffffb, 0xffffc, 0xffffd, 0xffffe, 0xfffff, -}; - -static const uint8_t t_huffman_env_bal_3_0dB_bits[25] = { - 13, 13, 13, 13, 13, 13, 13, 12, - 8, 7, 4, 3, 1, 2, 5, 6, - 9, 13, 13, 13, 13, 13, 13, 14, - 14, -}; - -static const uint16_t t_huffman_env_bal_3_0dB_codes[25] = { - 0x1ff2, 0x1ff3, 0x1ff4, 0x1ff5, 0x1ff6, 0x1ff7, 0x1ff8, 0x0ff8, - 0x00fe, 0x007e, 0x000e, 0x0006, 0x0000, 0x0002, 0x001e, 0x003e, - 0x01fe, 0x1ff9, 0x1ffa, 0x1ffb, 0x1ffc, 0x1ffd, 0x1ffe, 0x3ffe, - 0x3fff, -}; - -static const uint8_t f_huffman_env_bal_3_0dB_bits[25] = { - 13, 13, 13, 13, 13, 14, 14, 11, - 8, 7, 4, 2, 1, 3, 5, 6, - 9, 12, 13, 14, 14, 14, 14, 14, - 14, -}; - -static const uint16_t f_huffman_env_bal_3_0dB_codes[25] = { - 0x1ff7, 0x1ff8, 0x1ff9, 0x1ffa, 0x1ffb, 0x3ff8, 0x3ff9, 0x07fc, - 0x00fe, 0x007e, 0x000e, 0x0002, 0x0000, 0x0006, 0x001e, 0x003e, - 0x01fe, 0x0ffa, 0x1ff6, 0x3ffa, 0x3ffb, 0x3ffc, 0x3ffd, 0x3ffe, - 0x3fff, -}; - -static const uint8_t t_huffman_noise_3_0dB_bits[63] = { - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 11, 8, 6, 4, 3, 1, - 2, 5, 8, 10, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 14, 14, -}; - -static const uint16_t t_huffman_noise_3_0dB_codes[63] = { - 0x1fce, 0x1fcf, 0x1fd0, 0x1fd1, 0x1fd2, 0x1fd3, 0x1fd4, 0x1fd5, - 0x1fd6, 0x1fd7, 0x1fd8, 0x1fd9, 0x1fda, 0x1fdb, 0x1fdc, 0x1fdd, - 0x1fde, 0x1fdf, 0x1fe0, 0x1fe1, 0x1fe2, 0x1fe3, 0x1fe4, 0x1fe5, - 0x1fe6, 0x1fe7, 0x07f2, 0x00fd, 0x003e, 0x000e, 0x0006, 0x0000, - 0x0002, 0x001e, 0x00fc, 0x03f8, 0x1fcc, 0x1fe8, 0x1fe9, 0x1fea, - 0x1feb, 0x1fec, 0x1fcd, 0x1fed, 0x1fee, 0x1fef, 0x1ff0, 0x1ff1, - 0x1ff2, 0x1ff3, 0x1ff4, 0x1ff5, 0x1ff6, 0x1ff7, 0x1ff8, 0x1ff9, - 0x1ffa, 0x1ffb, 0x1ffc, 0x1ffd, 0x1ffe, 0x3ffe, 0x3fff, -}; - -static const uint8_t t_huffman_noise_bal_3_0dB_bits[25] = { - 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 5, 2, 1, 3, 6, 8, - 8, 8, 8, 8, 8, 8, 8, 8, - 8, -}; - -static const uint8_t t_huffman_noise_bal_3_0dB_codes[25] = { - 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, - 0xf4, 0xf5, 0x1c, 0x02, 0x00, 0x06, 0x3a, 0xf6, - 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, - 0xff, -}; - -static const int8_t sbr_offset[6][16] = { - {-8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7}, // fs_sbr = 16000 Hz - {-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13}, // fs_sbr = 22050 Hz - {-5, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16}, // fs_sbr = 24000 Hz - {-6, -4, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16}, // fs_sbr = 32000 Hz - {-4, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16, 20}, // 44100 Hz <= fs_sbr <= 64000 Hz - {-2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16, 20, 24}, // 64000 Hz < fs_sbr -}; - -///< window coefficients for analysis/synthesis QMF banks -static DECLARE_ALIGNED(16, float, sbr_qmf_window_ds)[320]; -static DECLARE_ALIGNED(16, float, sbr_qmf_window_us)[640] = { - 0.0000000000, -0.0005525286, -0.0005617692, -0.0004947518, - -0.0004875227, -0.0004893791, -0.0005040714, -0.0005226564, - -0.0005466565, -0.0005677802, -0.0005870930, -0.0006132747, - -0.0006312493, -0.0006540333, -0.0006777690, -0.0006941614, - -0.0007157736, -0.0007255043, -0.0007440941, -0.0007490598, - -0.0007681371, -0.0007724848, -0.0007834332, -0.0007779869, - -0.0007803664, -0.0007801449, -0.0007757977, -0.0007630793, - -0.0007530001, -0.0007319357, -0.0007215391, -0.0006917937, - -0.0006650415, -0.0006341594, -0.0005946118, -0.0005564576, - -0.0005145572, -0.0004606325, -0.0004095121, -0.0003501175, - -0.0002896981, -0.0002098337, -0.0001446380, -0.0000617334, - 0.0000134949, 0.0001094383, 0.0002043017, 0.0002949531, - 0.0004026540, 0.0005107388, 0.0006239376, 0.0007458025, - 0.0008608443, 0.0009885988, 0.0011250155, 0.0012577884, - 0.0013902494, 0.0015443219, 0.0016868083, 0.0018348265, - 0.0019841140, 0.0021461583, 0.0023017254, 0.0024625616, - 0.0026201758, 0.0027870464, 0.0029469447, 0.0031125420, - 0.0032739613, 0.0034418874, 0.0036008268, 0.0037603922, - 0.0039207432, 0.0040819753, 0.0042264269, 0.0043730719, - 0.0045209852, 0.0046606460, 0.0047932560, 0.0049137603, - 0.0050393022, 0.0051407353, 0.0052461166, 0.0053471681, - 0.0054196775, 0.0054876040, 0.0055475714, 0.0055938023, - 0.0056220643, 0.0056455196, 0.0056389199, 0.0056266114, - 0.0055917128, 0.0055404363, 0.0054753783, 0.0053838975, - 0.0052715758, 0.0051382275, 0.0049839687, 0.0048109469, - 0.0046039530, 0.0043801861, 0.0041251642, 0.0038456408, - 0.0035401246, 0.0032091885, 0.0028446757, 0.0024508540, - 0.0020274176, 0.0015784682, 0.0010902329, 0.0005832264, - 0.0000276045, -0.0005464280, -0.0011568135, -0.0018039472, - -0.0024826723, -0.0031933778, -0.0039401124, -0.0047222596, - -0.0055337211, -0.0063792293, -0.0072615816, -0.0081798233, - -0.0091325329, -0.0101150215, -0.0111315548, -0.0121849995, - 0.0132718220, 0.0143904666, 0.0155405553, 0.0167324712, - 0.0179433381, 0.0191872431, 0.0204531793, 0.0217467550, - 0.0230680169, 0.0244160992, 0.0257875847, 0.0271859429, - 0.0286072173, 0.0300502657, 0.0315017608, 0.0329754081, - 0.0344620948, 0.0359697560, 0.0374812850, 0.0390053679, - 0.0405349170, 0.0420649094, 0.0436097542, 0.0451488405, - 0.0466843027, 0.0482165720, 0.0497385755, 0.0512556155, - 0.0527630746, 0.0542452768, 0.0557173648, 0.0571616450, - 0.0585915683, 0.0599837480, 0.0613455171, 0.0626857808, - 0.0639715898, 0.0652247106, 0.0664367512, 0.0676075985, - 0.0687043828, 0.0697630244, 0.0707628710, 0.0717002673, - 0.0725682583, 0.0733620255, 0.0741003642, 0.0747452558, - 0.0753137336, 0.0758008358, 0.0761992479, 0.0764992170, - 0.0767093490, 0.0768173975, 0.0768230011, 0.0767204924, - 0.0765050718, 0.0761748321, 0.0757305756, 0.0751576255, - 0.0744664394, 0.0736406005, 0.0726774642, 0.0715826364, - 0.0703533073, 0.0689664013, 0.0674525021, 0.0657690668, - 0.0639444805, 0.0619602779, 0.0598166570, 0.0575152691, - 0.0550460034, 0.0524093821, 0.0495978676, 0.0466303305, - 0.0434768782, 0.0401458278, 0.0366418116, 0.0329583930, - 0.0290824006, 0.0250307561, 0.0207997072, 0.0163701258, - 0.0117623832, 0.0069636862, 0.0019765601, -0.0032086896, - -0.0085711749, -0.0141288827, -0.0198834129, -0.0258227288, - -0.0319531274, -0.0382776572, -0.0447806821, -0.0514804176, - -0.0583705326, -0.0654409853, -0.0726943300, -0.0801372934, - -0.0877547536, -0.0955533352, -0.1035329531, -0.1116826931, - -0.1200077984, -0.1285002850, -0.1371551761, -0.1459766491, - -0.1549607071, -0.1640958855, -0.1733808172, -0.1828172548, - -0.1923966745, -0.2021250176, -0.2119735853, -0.2219652696, - -0.2320690870, -0.2423016884, -0.2526480309, -0.2631053299, - -0.2736634040, -0.2843214189, -0.2950716717, -0.3059098575, - -0.3168278913, -0.3278113727, -0.3388722693, -0.3499914122, - 0.3611589903, 0.3723795546, 0.3836350013, 0.3949211761, - 0.4062317676, 0.4175696896, 0.4289119920, 0.4402553754, - 0.4515996535, 0.4629308085, 0.4742453214, 0.4855253091, - 0.4967708254, 0.5079817500, 0.5191234970, 0.5302240895, - 0.5412553448, 0.5522051258, 0.5630789140, 0.5738524131, - 0.5845403235, 0.5951123086, 0.6055783538, 0.6159109932, - 0.6261242695, 0.6361980107, 0.6461269695, 0.6559016302, - 0.6655139880, 0.6749663190, 0.6842353293, 0.6933282376, - 0.7022388719, 0.7109410426, 0.7194462634, 0.7277448900, - 0.7358211758, 0.7436827863, 0.7513137456, 0.7587080760, - 0.7658674865, 0.7727780881, 0.7794287519, 0.7858353120, - 0.7919735841, 0.7978466413, 0.8034485751, 0.8087695004, - 0.8138191270, 0.8185776004, 0.8230419890, 0.8272275347, - 0.8311038457, 0.8346937361, 0.8379717337, 0.8409541392, - 0.8436238281, 0.8459818469, 0.8480315777, 0.8497805198, - 0.8511971524, 0.8523047035, 0.8531020949, 0.8535720573, - 0.8537385600, -}; - -/* First two entries repeated at end to simplify SIMD implementations. */ -const DECLARE_ALIGNED(16, float, ff_sbr_noise_table)[][2] = { -{-0.99948153278296, -0.59483417516607}, { 0.97113454393991, -0.67528515225647}, -{ 0.14130051758487, -0.95090983575689}, {-0.47005496701697, -0.37340549728647}, -{ 0.80705063769351, 0.29653668284408}, {-0.38981478896926, 0.89572605717087}, -{-0.01053049862020, -0.66959058036166}, {-0.91266367957293, -0.11522938140034}, -{ 0.54840422910309, 0.75221367176302}, { 0.40009252867955, -0.98929400334421}, -{-0.99867974711855, -0.88147068645358}, {-0.95531076805040, 0.90908757154593}, -{-0.45725933317144, -0.56716323646760}, {-0.72929675029275, -0.98008272727324}, -{ 0.75622801399036, 0.20950329995549}, { 0.07069442601050, -0.78247898470706}, -{ 0.74496252926055, -0.91169004445807}, {-0.96440182703856, -0.94739918296622}, -{ 0.30424629369539, -0.49438267012479}, { 0.66565033746925, 0.64652935542491}, -{ 0.91697008020594, 0.17514097332009}, {-0.70774918760427, 0.52548653416543}, -{-0.70051415345560, -0.45340028808763}, {-0.99496513054797, -0.90071908066973}, -{ 0.98164490790123, -0.77463155528697}, {-0.54671580548181, -0.02570928536004}, -{-0.01689629065389, 0.00287506445732}, {-0.86110349531986, 0.42548583726477}, -{-0.98892980586032, -0.87881132267556}, { 0.51756627678691, 0.66926784710139}, -{-0.99635026409640, -0.58107730574765}, {-0.99969370862163, 0.98369989360250}, -{ 0.55266258627194, 0.59449057465591}, { 0.34581177741673, 0.94879421061866}, -{ 0.62664209577999, -0.74402970906471}, {-0.77149701404973, -0.33883658042801}, -{-0.91592244254432, 0.03687901376713}, {-0.76285492357887, -0.91371867919124}, -{ 0.79788337195331, -0.93180971199849}, { 0.54473080610200, -0.11919206037186}, -{-0.85639281671058, 0.42429854760451}, {-0.92882402971423, 0.27871809078609}, -{-0.11708371046774, -0.99800843444966}, { 0.21356749817493, -0.90716295627033}, -{-0.76191692573909, 0.99768118356265}, { 0.98111043100884, -0.95854459734407}, -{-0.85913269895572, 0.95766566168880}, {-0.93307242253692, 0.49431757696466}, -{ 0.30485754879632, -0.70540034357529}, { 0.85289650925190, 0.46766131791044}, -{ 0.91328082618125, -0.99839597361769}, {-0.05890199924154, 0.70741827819497}, -{ 0.28398686150148, 0.34633555702188}, { 0.95258164539612, -0.54893416026939}, -{-0.78566324168507, -0.75568541079691}, {-0.95789495447877, -0.20423194696966}, -{ 0.82411158711197, 0.96654618432562}, {-0.65185446735885, -0.88734990773289}, -{-0.93643603134666, 0.99870790442385}, { 0.91427159529618, -0.98290505544444}, -{-0.70395684036886, 0.58796798221039}, { 0.00563771969365, 0.61768196727244}, -{ 0.89065051931895, 0.52783352697585}, {-0.68683707712762, 0.80806944710339}, -{ 0.72165342518718, -0.69259857349564}, {-0.62928247730667, 0.13627037407335}, -{ 0.29938434065514, -0.46051329682246}, {-0.91781958879280, -0.74012716684186}, -{ 0.99298717043688, 0.40816610075661}, { 0.82368298622748, -0.74036047190173}, -{-0.98512833386833, -0.99972330709594}, {-0.95915368242257, -0.99237800466040}, -{-0.21411126572790, -0.93424819052545}, {-0.68821476106884, -0.26892306315457}, -{ 0.91851997982317, 0.09358228901785}, {-0.96062769559127, 0.36099095133739}, -{ 0.51646184922287, -0.71373332873917}, { 0.61130721139669, 0.46950141175917}, -{ 0.47336129371299, -0.27333178296162}, { 0.90998308703519, 0.96715662938132}, -{ 0.44844799194357, 0.99211574628306}, { 0.66614891079092, 0.96590176169121}, -{ 0.74922239129237, -0.89879858826087}, {-0.99571588506485, 0.52785521494349}, -{ 0.97401082477563, -0.16855870075190}, { 0.72683747733879, -0.48060774432251}, -{ 0.95432193457128, 0.68849603408441}, {-0.72962208425191, -0.76608443420917}, -{-0.85359479233537, 0.88738125901579}, {-0.81412430338535, -0.97480768049637}, -{-0.87930772356786, 0.74748307690436}, {-0.71573331064977, -0.98570608178923}, -{ 0.83524300028228, 0.83702537075163}, {-0.48086065601423, -0.98848504923531}, -{ 0.97139128574778, 0.80093621198236}, { 0.51992825347895, 0.80247631400510}, -{-0.00848591195325, -0.76670128000486}, {-0.70294374303036, 0.55359910445577}, -{-0.95894428168140, -0.43265504344783}, { 0.97079252950321, 0.09325857238682}, -{-0.92404293670797, 0.85507704027855}, {-0.69506469500450, 0.98633412625459}, -{ 0.26559203620024, 0.73314307966524}, { 0.28038443336943, 0.14537913654427}, -{-0.74138124825523, 0.99310339807762}, {-0.01752795995444, -0.82616635284178}, -{-0.55126773094930, -0.98898543862153}, { 0.97960898850996, -0.94021446752851}, -{-0.99196309146936, 0.67019017358456}, {-0.67684928085260, 0.12631491649378}, -{ 0.09140039465500, -0.20537731453108}, {-0.71658965751996, -0.97788200391224}, -{ 0.81014640078925, 0.53722648362443}, { 0.40616991671205, -0.26469008598449}, -{-0.67680188682972, 0.94502052337695}, { 0.86849774348749, -0.18333598647899}, -{-0.99500381284851, -0.02634122068550}, { 0.84329189340667, 0.10406957462213}, -{-0.09215968531446, 0.69540012101253}, { 0.99956173327206, -0.12358542001404}, -{-0.79732779473535, -0.91582524736159}, { 0.96349973642406, 0.96640458041000}, -{-0.79942778496547, 0.64323902822857}, {-0.11566039853896, 0.28587846253726}, -{-0.39922954514662, 0.94129601616966}, { 0.99089197565987, -0.92062625581587}, -{ 0.28631285179909, -0.91035047143603}, {-0.83302725605608, -0.67330410892084}, -{ 0.95404443402072, 0.49162765398743}, {-0.06449863579434, 0.03250560813135}, -{-0.99575054486311, 0.42389784469507}, {-0.65501142790847, 0.82546114655624}, -{-0.81254441908887, -0.51627234660629}, {-0.99646369485481, 0.84490533520752}, -{ 0.00287840603348, 0.64768261158166}, { 0.70176989408455, -0.20453028573322}, -{ 0.96361882270190, 0.40706967140989}, {-0.68883758192426, 0.91338958840772}, -{-0.34875585502238, 0.71472290693300}, { 0.91980081243087, 0.66507455644919}, -{-0.99009048343881, 0.85868021604848}, { 0.68865791458395, 0.55660316809678}, -{-0.99484402129368, -0.20052559254934}, { 0.94214511408023, -0.99696425367461}, -{-0.67414626793544, 0.49548221180078}, {-0.47339353684664, -0.85904328834047}, -{ 0.14323651387360, -0.94145598222488}, {-0.29268293575672, 0.05759224927952}, -{ 0.43793861458754, -0.78904969892724}, {-0.36345126374441, 0.64874435357162}, -{-0.08750604656825, 0.97686944362527}, {-0.96495267812511, -0.53960305946511}, -{ 0.55526940659947, 0.78891523734774}, { 0.73538215752630, 0.96452072373404}, -{-0.30889773919437, -0.80664389776860}, { 0.03574995626194, -0.97325616900959}, -{ 0.98720684660488, 0.48409133691962}, {-0.81689296271203, -0.90827703628298}, -{ 0.67866860118215, 0.81284503870856}, {-0.15808569732583, 0.85279555024382}, -{ 0.80723395114371, -0.24717418514605}, { 0.47788757329038, -0.46333147839295}, -{ 0.96367554763201, 0.38486749303242}, {-0.99143875716818, -0.24945277239809}, -{ 0.83081876925833, -0.94780851414763}, {-0.58753191905341, 0.01290772389163}, -{ 0.95538108220960, -0.85557052096538}, {-0.96490920476211, -0.64020970923102}, -{-0.97327101028521, 0.12378128133110}, { 0.91400366022124, 0.57972471346930}, -{-0.99925837363824, 0.71084847864067}, {-0.86875903507313, -0.20291699203564}, -{-0.26240034795124, -0.68264554369108}, {-0.24664412953388, -0.87642273115183}, -{ 0.02416275806869, 0.27192914288905}, { 0.82068619590515, -0.85087787994476}, -{ 0.88547373760759, -0.89636802901469}, {-0.18173078152226, -0.26152145156800}, -{ 0.09355476558534, 0.54845123045604}, {-0.54668414224090, 0.95980774020221}, -{ 0.37050990604091, -0.59910140383171}, {-0.70373594262891, 0.91227665827081}, -{-0.34600785879594, -0.99441426144200}, {-0.68774481731008, -0.30238837956299}, -{-0.26843291251234, 0.83115668004362}, { 0.49072334613242, -0.45359708737775}, -{ 0.38975993093975, 0.95515358099121}, {-0.97757125224150, 0.05305894580606}, -{-0.17325552859616, -0.92770672250494}, { 0.99948035025744, 0.58285545563426}, -{-0.64946246527458, 0.68645507104960}, {-0.12016920576437, -0.57147322153312}, -{-0.58947456517751, -0.34847132454388}, {-0.41815140454465, 0.16276422358861}, -{ 0.99885650204884, 0.11136095490444}, {-0.56649614128386, -0.90494866361587}, -{ 0.94138021032330, 0.35281916733018}, {-0.75725076534641, 0.53650549640587}, -{ 0.20541973692630, -0.94435144369918}, { 0.99980371023351, 0.79835913565599}, -{ 0.29078277605775, 0.35393777921520}, {-0.62858772103030, 0.38765693387102}, -{ 0.43440904467688, -0.98546330463232}, {-0.98298583762390, 0.21021524625209}, -{ 0.19513029146934, -0.94239832251867}, {-0.95476662400101, 0.98364554179143}, -{ 0.93379635304810, -0.70881994583682}, {-0.85235410573336, -0.08342347966410}, -{-0.86425093011245, -0.45795025029466}, { 0.38879779059045, 0.97274429344593}, -{ 0.92045124735495, -0.62433652524220}, { 0.89162532251878, 0.54950955570563}, -{-0.36834336949252, 0.96458298020975}, { 0.93891760988045, -0.89968353740388}, -{ 0.99267657565094, -0.03757034316958}, {-0.94063471614176, 0.41332338538963}, -{ 0.99740224117019, -0.16830494996370}, {-0.35899413170555, -0.46633226649613}, -{ 0.05237237274947, -0.25640361602661}, { 0.36703583957424, -0.38653265641875}, -{ 0.91653180367913, -0.30587628726597}, { 0.69000803499316, 0.90952171386132}, -{-0.38658751133527, 0.99501571208985}, {-0.29250814029851, 0.37444994344615}, -{-0.60182204677608, 0.86779651036123}, {-0.97418588163217, 0.96468523666475}, -{ 0.88461574003963, 0.57508405276414}, { 0.05198933055162, 0.21269661669964}, -{-0.53499621979720, 0.97241553731237}, {-0.49429560226497, 0.98183865291903}, -{-0.98935142339139, -0.40249159006933}, {-0.98081380091130, -0.72856895534041}, -{-0.27338148835532, 0.99950922447209}, { 0.06310802338302, -0.54539587529618}, -{-0.20461677199539, -0.14209977628489}, { 0.66223843141647, 0.72528579940326}, -{-0.84764345483665, 0.02372316801261}, {-0.89039863483811, 0.88866581484602}, -{ 0.95903308477986, 0.76744927173873}, { 0.73504123909879, -0.03747203173192}, -{-0.31744434966056, -0.36834111883652}, {-0.34110827591623, 0.40211222807691}, -{ 0.47803883714199, -0.39423219786288}, { 0.98299195879514, 0.01989791390047}, -{-0.30963073129751, -0.18076720599336}, { 0.99992588229018, -0.26281872094289}, -{-0.93149731080767, -0.98313162570490}, { 0.99923472302773, -0.80142993767554}, -{-0.26024169633417, -0.75999759855752}, {-0.35712514743563, 0.19298963768574}, -{-0.99899084509530, 0.74645156992493}, { 0.86557171579452, 0.55593866696299}, -{ 0.33408042438752, 0.86185953874709}, { 0.99010736374716, 0.04602397576623}, -{-0.66694269691195, -0.91643611810148}, { 0.64016792079480, 0.15649530836856}, -{ 0.99570534804836, 0.45844586038111}, {-0.63431466947340, 0.21079116459234}, -{-0.07706847005931, -0.89581437101329}, { 0.98590090577724, 0.88241721133981}, -{ 0.80099335254678, -0.36851896710853}, { 0.78368131392666, 0.45506999802597}, -{ 0.08707806671691, 0.80938994918745}, {-0.86811883080712, 0.39347308654705}, -{-0.39466529740375, -0.66809432114456}, { 0.97875325649683, -0.72467840967746}, -{-0.95038560288864, 0.89563219587625}, { 0.17005239424212, 0.54683053962658}, -{-0.76910792026848, -0.96226617549298}, { 0.99743281016846, 0.42697157037567}, -{ 0.95437383549973, 0.97002324109952}, { 0.99578905365569, -0.54106826257356}, -{ 0.28058259829990, -0.85361420634036}, { 0.85256524470573, -0.64567607735589}, -{-0.50608540105128, -0.65846015480300}, {-0.97210735183243, -0.23095213067791}, -{ 0.95424048234441, -0.99240147091219}, {-0.96926570524023, 0.73775654896574}, -{ 0.30872163214726, 0.41514960556126}, {-0.24523839572639, 0.63206633394807}, -{-0.33813265086024, -0.38661779441897}, {-0.05826828420146, -0.06940774188029}, -{-0.22898461455054, 0.97054853316316}, {-0.18509915019881, 0.47565762892084}, -{-0.10488238045009, -0.87769947402394}, {-0.71886586182037, 0.78030982480538}, -{ 0.99793873738654, 0.90041310491497}, { 0.57563307626120, -0.91034337352097}, -{ 0.28909646383717, 0.96307783970534}, { 0.42188998312520, 0.48148651230437}, -{ 0.93335049681047, -0.43537023883588}, {-0.97087374418267, 0.86636445711364}, -{ 0.36722871286923, 0.65291654172961}, {-0.81093025665696, 0.08778370229363}, -{-0.26240603062237, -0.92774095379098}, { 0.83996497984604, 0.55839849139647}, -{-0.99909615720225, -0.96024605713970}, { 0.74649464155061, 0.12144893606462}, -{-0.74774595569805, -0.26898062008959}, { 0.95781667469567, -0.79047927052628}, -{ 0.95472308713099, -0.08588776019550}, { 0.48708332746299, 0.99999041579432}, -{ 0.46332038247497, 0.10964126185063}, {-0.76497004940162, 0.89210929242238}, -{ 0.57397389364339, 0.35289703373760}, { 0.75374316974495, 0.96705214651335}, -{-0.59174397685714, -0.89405370422752}, { 0.75087906691890, -0.29612672982396}, -{-0.98607857336230, 0.25034911730023}, {-0.40761056640505, -0.90045573444695}, -{ 0.66929266740477, 0.98629493401748}, {-0.97463695257310, -0.00190223301301}, -{ 0.90145509409859, 0.99781390365446}, {-0.87259289048043, 0.99233587353666}, -{-0.91529461447692, -0.15698707534206}, {-0.03305738840705, -0.37205262859764}, -{ 0.07223051368337, -0.88805001733626}, { 0.99498012188353, 0.97094358113387}, -{-0.74904939500519, 0.99985483641521}, { 0.04585228574211, 0.99812337444082}, -{-0.89054954257993, -0.31791913188064}, {-0.83782144651251, 0.97637632547466}, -{ 0.33454804933804, -0.86231516800408}, {-0.99707579362824, 0.93237990079441}, -{-0.22827527843994, 0.18874759397997}, { 0.67248046289143, -0.03646211390569}, -{-0.05146538187944, -0.92599700120679}, { 0.99947295749905, 0.93625229707912}, -{ 0.66951124390363, 0.98905825623893}, {-0.99602956559179, -0.44654715757688}, -{ 0.82104905483590, 0.99540741724928}, { 0.99186510988782, 0.72023001312947}, -{-0.65284592392918, 0.52186723253637}, { 0.93885443798188, -0.74895312615259}, -{ 0.96735248738388, 0.90891816978629}, {-0.22225968841114, 0.57124029781228}, -{-0.44132783753414, -0.92688840659280}, {-0.85694974219574, 0.88844532719844}, -{ 0.91783042091762, -0.46356892383970}, { 0.72556974415690, -0.99899555770747}, -{-0.99711581834508, 0.58211560180426}, { 0.77638976371966, 0.94321834873819}, -{ 0.07717324253925, 0.58638399856595}, {-0.56049829194163, 0.82522301569036}, -{ 0.98398893639988, 0.39467440420569}, { 0.47546946844938, 0.68613044836811}, -{ 0.65675089314631, 0.18331637134880}, { 0.03273375457980, -0.74933109564108}, -{-0.38684144784738, 0.51337349030406}, {-0.97346267944545, -0.96549364384098}, -{-0.53282156061942, -0.91423265091354}, { 0.99817310731176, 0.61133572482148}, -{-0.50254500772635, -0.88829338134294}, { 0.01995873238855, 0.85223515096765}, -{ 0.99930381973804, 0.94578896296649}, { 0.82907767600783, -0.06323442598128}, -{-0.58660709669728, 0.96840773806582}, {-0.17573736667267, -0.48166920859485}, -{ 0.83434292401346, -0.13023450646997}, { 0.05946491307025, 0.20511047074866}, -{ 0.81505484574602, -0.94685947861369}, {-0.44976380954860, 0.40894572671545}, -{-0.89746474625671, 0.99846578838537}, { 0.39677256130792, -0.74854668609359}, -{-0.07588948563079, 0.74096214084170}, { 0.76343198951445, 0.41746629422634}, -{-0.74490104699626, 0.94725911744610}, { 0.64880119792759, 0.41336660830571}, -{ 0.62319537462542, -0.93098313552599}, { 0.42215817594807, -0.07712787385208}, -{ 0.02704554141885, -0.05417518053666}, { 0.80001773566818, 0.91542195141039}, -{-0.79351832348816, -0.36208897989136}, { 0.63872359151636, 0.08128252493444}, -{ 0.52890520960295, 0.60048872455592}, { 0.74238552914587, 0.04491915291044}, -{ 0.99096131449250, -0.19451182854402}, {-0.80412329643109, -0.88513818199457}, -{-0.64612616129736, 0.72198674804544}, { 0.11657770663191, -0.83662833815041}, -{-0.95053182488101, -0.96939905138082}, {-0.62228872928622, 0.82767262846661}, -{ 0.03004475787316, -0.99738896333384}, {-0.97987214341034, 0.36526129686425}, -{-0.99986980746200, -0.36021610299715}, { 0.89110648599879, -0.97894250343044}, -{ 0.10407960510582, 0.77357793811619}, { 0.95964737821728, -0.35435818285502}, -{ 0.50843233159162, 0.96107691266205}, { 0.17006334670615, -0.76854025314829}, -{ 0.25872675063360, 0.99893303933816}, {-0.01115998681937, 0.98496019742444}, -{-0.79598702973261, 0.97138411318894}, {-0.99264708948101, -0.99542822402536}, -{-0.99829663752818, 0.01877138824311}, {-0.70801016548184, 0.33680685948117}, -{-0.70467057786826, 0.93272777501857}, { 0.99846021905254, -0.98725746254433}, -{-0.63364968534650, -0.16473594423746}, {-0.16258217500792, -0.95939125400802}, -{-0.43645594360633, -0.94805030113284}, {-0.99848471702976, 0.96245166923809}, -{-0.16796458968998, -0.98987511890470}, {-0.87979225745213, -0.71725725041680}, -{ 0.44183099021786, -0.93568974498761}, { 0.93310180125532, -0.99913308068246}, -{-0.93941931782002, -0.56409379640356}, {-0.88590003188677, 0.47624600491382}, -{ 0.99971463703691, -0.83889954253462}, {-0.75376385639978, 0.00814643438625}, -{ 0.93887685615875, -0.11284528204636}, { 0.85126435782309, 0.52349251543547}, -{ 0.39701421446381, 0.81779634174316}, {-0.37024464187437, -0.87071656222959}, -{-0.36024828242896, 0.34655735648287}, {-0.93388812549209, -0.84476541096429}, -{-0.65298804552119, -0.18439575450921}, { 0.11960319006843, 0.99899346780168}, -{ 0.94292565553160, 0.83163906518293}, { 0.75081145286948, -0.35533223142265}, -{ 0.56721979748394, -0.24076836414499}, { 0.46857766746029, -0.30140233457198}, -{ 0.97312313923635, -0.99548191630031}, {-0.38299976567017, 0.98516909715427}, -{ 0.41025800019463, 0.02116736935734}, { 0.09638062008048, 0.04411984381457}, -{-0.85283249275397, 0.91475563922421}, { 0.88866808958124, -0.99735267083226}, -{-0.48202429536989, -0.96805608884164}, { 0.27572582416567, 0.58634753335832}, -{-0.65889129659168, 0.58835634138583}, { 0.98838086953732, 0.99994349600236}, -{-0.20651349620689, 0.54593044066355}, {-0.62126416356920, -0.59893681700392}, -{ 0.20320105410437, -0.86879180355289}, {-0.97790548600584, 0.96290806999242}, -{ 0.11112534735126, 0.21484763313301}, {-0.41368337314182, 0.28216837680365}, -{ 0.24133038992960, 0.51294362630238}, {-0.66393410674885, -0.08249679629081}, -{-0.53697829178752, -0.97649903936228}, {-0.97224737889348, 0.22081333579837}, -{ 0.87392477144549, -0.12796173740361}, { 0.19050361015753, 0.01602615387195}, -{-0.46353441212724, -0.95249041539006}, {-0.07064096339021, -0.94479803205886}, -{-0.92444085484466, -0.10457590187436}, {-0.83822593578728, -0.01695043208885}, -{ 0.75214681811150, -0.99955681042665}, {-0.42102998829339, 0.99720941999394}, -{-0.72094786237696, -0.35008961934255}, { 0.78843311019251, 0.52851398958271}, -{ 0.97394027897442, -0.26695944086561}, { 0.99206463477946, -0.57010120849429}, -{ 0.76789609461795, -0.76519356730966}, {-0.82002421836409, -0.73530179553767}, -{ 0.81924990025724, 0.99698425250579}, {-0.26719850873357, 0.68903369776193}, -{-0.43311260380975, 0.85321815947490}, { 0.99194979673836, 0.91876249766422}, -{-0.80692001248487, -0.32627540663214}, { 0.43080003649976, -0.21919095636638}, -{ 0.67709491937357, -0.95478075822906}, { 0.56151770568316, -0.70693811747778}, -{ 0.10831862810749, -0.08628837174592}, { 0.91229417540436, -0.65987351408410}, -{-0.48972893932274, 0.56289246362686}, {-0.89033658689697, -0.71656563987082}, -{ 0.65269447475094, 0.65916004833932}, { 0.67439478141121, -0.81684380846796}, -{-0.47770832416973, -0.16789556203025}, {-0.99715979260878, -0.93565784007648}, -{-0.90889593602546, 0.62034397054380}, {-0.06618622548177, -0.23812217221359}, -{ 0.99430266919728, 0.18812555317553}, { 0.97686402381843, -0.28664534366620}, -{ 0.94813650221268, -0.97506640027128}, {-0.95434497492853, -0.79607978501983}, -{-0.49104783137150, 0.32895214359663}, { 0.99881175120751, 0.88993983831354}, -{ 0.50449166760303, -0.85995072408434}, { 0.47162891065108, -0.18680204049569}, -{-0.62081581361840, 0.75000676218956}, {-0.43867015250812, 0.99998069244322}, -{ 0.98630563232075, -0.53578899600662}, {-0.61510362277374, -0.89515019899997}, -{-0.03841517601843, -0.69888815681179}, {-0.30102157304644, -0.07667808922205}, -{ 0.41881284182683, 0.02188098922282}, {-0.86135454941237, 0.98947480909359}, -{ 0.67226861393788, -0.13494389011014}, {-0.70737398842068, -0.76547349325992}, -{ 0.94044946687963, 0.09026201157416}, {-0.82386352534327, 0.08924768823676}, -{-0.32070666698656, 0.50143421908753}, { 0.57593163224487, -0.98966422921509}, -{-0.36326018419965, 0.07440243123228}, { 0.99979044674350, -0.14130287347405}, -{-0.92366023326932, -0.97979298068180}, {-0.44607178518598, -0.54233252016394}, -{ 0.44226800932956, 0.71326756742752}, { 0.03671907158312, 0.63606389366675}, -{ 0.52175424682195, -0.85396826735705}, {-0.94701139690956, -0.01826348194255}, -{-0.98759606946049, 0.82288714303073}, { 0.87434794743625, 0.89399495655433}, -{-0.93412041758744, 0.41374052024363}, { 0.96063943315511, 0.93116709541280}, -{ 0.97534253457837, 0.86150930812689}, { 0.99642466504163, 0.70190043427512}, -{-0.94705089665984, -0.29580042814306}, { 0.91599807087376, -0.98147830385781}, -{-0.99948153278296, -0.59483417516607}, { 0.97113454393991, -0.67528515225647}, -}; - -#endif /* AVCODEC_AACSBRDATA_H */ +/*
+ * AAC Spectral Band Replication decoding data
+ * Copyright (c) 2008-2009 Robert Swain ( rob opendot cl )
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * AAC Spectral Band Replication decoding data
+ * @author Robert Swain ( rob opendot cl )
+ */
+
+#ifndef AVCODEC_AACSBRDATA_H
+#define AVCODEC_AACSBRDATA_H
+
+#include <stdint.h>
+#include "libavutil/mem.h"
+
+///< Huffman tables for SBR
+
+static const uint8_t t_huffman_env_1_5dB_bits[121] = {
+ 18, 18, 18, 18, 18, 18, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 17, 18, 16, 17, 18, 17,
+ 16, 16, 16, 16, 15, 14, 14, 13,
+ 13, 12, 11, 10, 9, 8, 7, 6,
+ 5, 4, 3, 2, 2, 3, 4, 5,
+ 6, 7, 8, 9, 10, 12, 13, 14,
+ 14, 15, 16, 17, 16, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19,
+ 19,
+};
+
+static const uint32_t t_huffman_env_1_5dB_codes[121] = {
+ 0x3ffd6, 0x3ffd7, 0x3ffd8, 0x3ffd9, 0x3ffda, 0x3ffdb, 0x7ffb8, 0x7ffb9,
+ 0x7ffba, 0x7ffbb, 0x7ffbc, 0x7ffbd, 0x7ffbe, 0x7ffbf, 0x7ffc0, 0x7ffc1,
+ 0x7ffc2, 0x7ffc3, 0x7ffc4, 0x7ffc5, 0x7ffc6, 0x7ffc7, 0x7ffc8, 0x7ffc9,
+ 0x7ffca, 0x7ffcb, 0x7ffcc, 0x7ffcd, 0x7ffce, 0x7ffcf, 0x7ffd0, 0x7ffd1,
+ 0x7ffd2, 0x7ffd3, 0x1ffe6, 0x3ffd4, 0x0fff0, 0x1ffe9, 0x3ffd5, 0x1ffe7,
+ 0x0fff1, 0x0ffec, 0x0ffed, 0x0ffee, 0x07ff4, 0x03ff9, 0x03ff7, 0x01ffa,
+ 0x01ff9, 0x00ffb, 0x007fc, 0x003fc, 0x001fd, 0x000fd, 0x0007d, 0x0003d,
+ 0x0001d, 0x0000d, 0x00005, 0x00001, 0x00000, 0x00004, 0x0000c, 0x0001c,
+ 0x0003c, 0x0007c, 0x000fc, 0x001fc, 0x003fd, 0x00ffa, 0x01ff8, 0x03ff6,
+ 0x03ff8, 0x07ff5, 0x0ffef, 0x1ffe8, 0x0fff2, 0x7ffd4, 0x7ffd5, 0x7ffd6,
+ 0x7ffd7, 0x7ffd8, 0x7ffd9, 0x7ffda, 0x7ffdb, 0x7ffdc, 0x7ffdd, 0x7ffde,
+ 0x7ffdf, 0x7ffe0, 0x7ffe1, 0x7ffe2, 0x7ffe3, 0x7ffe4, 0x7ffe5, 0x7ffe6,
+ 0x7ffe7, 0x7ffe8, 0x7ffe9, 0x7ffea, 0x7ffeb, 0x7ffec, 0x7ffed, 0x7ffee,
+ 0x7ffef, 0x7fff0, 0x7fff1, 0x7fff2, 0x7fff3, 0x7fff4, 0x7fff5, 0x7fff6,
+ 0x7fff7, 0x7fff8, 0x7fff9, 0x7fffa, 0x7fffb, 0x7fffc, 0x7fffd, 0x7fffe,
+ 0x7ffff,
+};
+
+static const uint8_t f_huffman_env_1_5dB_bits[121] = {
+ 19, 19, 20, 20, 20, 20, 20, 20,
+ 20, 19, 20, 20, 20, 20, 19, 20,
+ 19, 19, 20, 18, 20, 20, 20, 19,
+ 20, 20, 20, 19, 20, 19, 18, 19,
+ 18, 18, 17, 18, 17, 17, 17, 16,
+ 16, 16, 15, 15, 14, 13, 13, 12,
+ 12, 11, 10, 9, 9, 8, 7, 6,
+ 5, 4, 3, 2, 2, 3, 4, 5,
+ 6, 8, 8, 9, 10, 11, 11, 11,
+ 12, 12, 13, 13, 14, 14, 16, 16,
+ 17, 17, 18, 18, 18, 18, 18, 18,
+ 18, 20, 19, 20, 20, 20, 20, 20,
+ 20, 19, 20, 20, 20, 20, 19, 20,
+ 18, 20, 20, 19, 19, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20,
+ 20,
+};
+
+static const uint32_t f_huffman_env_1_5dB_codes[121] = {
+ 0x7ffe7, 0x7ffe8, 0xfffd2, 0xfffd3, 0xfffd4, 0xfffd5, 0xfffd6, 0xfffd7,
+ 0xfffd8, 0x7ffda, 0xfffd9, 0xfffda, 0xfffdb, 0xfffdc, 0x7ffdb, 0xfffdd,
+ 0x7ffdc, 0x7ffdd, 0xfffde, 0x3ffe4, 0xfffdf, 0xfffe0, 0xfffe1, 0x7ffde,
+ 0xfffe2, 0xfffe3, 0xfffe4, 0x7ffdf, 0xfffe5, 0x7ffe0, 0x3ffe8, 0x7ffe1,
+ 0x3ffe0, 0x3ffe9, 0x1ffef, 0x3ffe5, 0x1ffec, 0x1ffed, 0x1ffee, 0x0fff4,
+ 0x0fff3, 0x0fff0, 0x07ff7, 0x07ff6, 0x03ffa, 0x01ffa, 0x01ff9, 0x00ffa,
+ 0x00ff8, 0x007f9, 0x003fb, 0x001fc, 0x001fa, 0x000fb, 0x0007c, 0x0003c,
+ 0x0001c, 0x0000c, 0x00005, 0x00001, 0x00000, 0x00004, 0x0000d, 0x0001d,
+ 0x0003d, 0x000fa, 0x000fc, 0x001fb, 0x003fa, 0x007f8, 0x007fa, 0x007fb,
+ 0x00ff9, 0x00ffb, 0x01ff8, 0x01ffb, 0x03ff8, 0x03ff9, 0x0fff1, 0x0fff2,
+ 0x1ffea, 0x1ffeb, 0x3ffe1, 0x3ffe2, 0x3ffea, 0x3ffe3, 0x3ffe6, 0x3ffe7,
+ 0x3ffeb, 0xfffe6, 0x7ffe2, 0xfffe7, 0xfffe8, 0xfffe9, 0xfffea, 0xfffeb,
+ 0xfffec, 0x7ffe3, 0xfffed, 0xfffee, 0xfffef, 0xffff0, 0x7ffe4, 0xffff1,
+ 0x3ffec, 0xffff2, 0xffff3, 0x7ffe5, 0x7ffe6, 0xffff4, 0xffff5, 0xffff6,
+ 0xffff7, 0xffff8, 0xffff9, 0xffffa, 0xffffb, 0xffffc, 0xffffd, 0xffffe,
+ 0xfffff,
+};
+
+static const uint8_t t_huffman_env_bal_1_5dB_bits[49] = {
+ 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 12, 11, 9, 7, 5, 3,
+ 1, 2, 4, 6, 8, 11, 12, 15,
+ 16, 16, 16, 16, 16, 16, 16, 17,
+ 17, 17, 17, 17, 17, 17, 17, 17,
+ 17,
+};
+
+static const uint32_t t_huffman_env_bal_1_5dB_codes[49] = {
+ 0x0ffe4, 0x0ffe5, 0x0ffe6, 0x0ffe7, 0x0ffe8, 0x0ffe9, 0x0ffea, 0x0ffeb,
+ 0x0ffec, 0x0ffed, 0x0ffee, 0x0ffef, 0x0fff0, 0x0fff1, 0x0fff2, 0x0fff3,
+ 0x0fff4, 0x0ffe2, 0x00ffc, 0x007fc, 0x001fe, 0x0007e, 0x0001e, 0x00006,
+ 0x00000, 0x00002, 0x0000e, 0x0003e, 0x000fe, 0x007fd, 0x00ffd, 0x07ff0,
+ 0x0ffe3, 0x0fff5, 0x0fff6, 0x0fff7, 0x0fff8, 0x0fff9, 0x0fffa, 0x1fff6,
+ 0x1fff7, 0x1fff8, 0x1fff9, 0x1fffa, 0x1fffb, 0x1fffc, 0x1fffd, 0x1fffe,
+ 0x1ffff,
+};
+
+static const uint8_t f_huffman_env_bal_1_5dB_bits[49] = {
+ 18, 18, 18, 18, 18, 18, 18, 18,
+ 18, 18, 18, 18, 18, 18, 18, 16,
+ 17, 14, 11, 11, 8, 7, 4, 2,
+ 1, 3, 5, 6, 9, 11, 12, 15,
+ 16, 18, 18, 18, 18, 18, 18, 18,
+ 18, 18, 18, 18, 18, 18, 18, 19,
+ 19,
+};
+
+static const uint32_t f_huffman_env_bal_1_5dB_codes[49] = {
+ 0x3ffe2, 0x3ffe3, 0x3ffe4, 0x3ffe5, 0x3ffe6, 0x3ffe7, 0x3ffe8, 0x3ffe9,
+ 0x3ffea, 0x3ffeb, 0x3ffec, 0x3ffed, 0x3ffee, 0x3ffef, 0x3fff0, 0x0fff7,
+ 0x1fff0, 0x03ffc, 0x007fe, 0x007fc, 0x000fe, 0x0007e, 0x0000e, 0x00002,
+ 0x00000, 0x00006, 0x0001e, 0x0003e, 0x001fe, 0x007fd, 0x00ffe, 0x07ffa,
+ 0x0fff6, 0x3fff1, 0x3fff2, 0x3fff3, 0x3fff4, 0x3fff5, 0x3fff6, 0x3fff7,
+ 0x3fff8, 0x3fff9, 0x3fffa, 0x3fffb, 0x3fffc, 0x3fffd, 0x3fffe, 0x7fffe,
+ 0x7ffff,
+};
+
+static const uint8_t t_huffman_env_3_0dB_bits[63] = {
+ 18, 18, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 17, 16, 16, 16, 14, 14, 14,
+ 13, 12, 11, 8, 6, 4, 2, 1,
+ 3, 5, 7, 9, 11, 13, 14, 14,
+ 15, 16, 17, 18, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19,
+};
+
+static const uint32_t t_huffman_env_3_0dB_codes[63] = {
+ 0x3ffed, 0x3ffee, 0x7ffde, 0x7ffdf, 0x7ffe0, 0x7ffe1, 0x7ffe2, 0x7ffe3,
+ 0x7ffe4, 0x7ffe5, 0x7ffe6, 0x7ffe7, 0x7ffe8, 0x7ffe9, 0x7ffea, 0x7ffeb,
+ 0x7ffec, 0x1fff4, 0x0fff7, 0x0fff9, 0x0fff8, 0x03ffb, 0x03ffa, 0x03ff8,
+ 0x01ffa, 0x00ffc, 0x007fc, 0x000fe, 0x0003e, 0x0000e, 0x00002, 0x00000,
+ 0x00006, 0x0001e, 0x0007e, 0x001fe, 0x007fd, 0x01ffb, 0x03ff9, 0x03ffc,
+ 0x07ffa, 0x0fff6, 0x1fff5, 0x3ffec, 0x7ffed, 0x7ffee, 0x7ffef, 0x7fff0,
+ 0x7fff1, 0x7fff2, 0x7fff3, 0x7fff4, 0x7fff5, 0x7fff6, 0x7fff7, 0x7fff8,
+ 0x7fff9, 0x7fffa, 0x7fffb, 0x7fffc, 0x7fffd, 0x7fffe, 0x7ffff,
+};
+
+static const uint8_t f_huffman_env_3_0dB_bits[63] = {
+ 20, 20, 20, 20, 20, 20, 20, 18,
+ 19, 19, 19, 19, 18, 18, 20, 19,
+ 17, 18, 17, 16, 16, 15, 14, 12,
+ 11, 10, 9, 8, 6, 4, 2, 1,
+ 3, 5, 8, 9, 10, 11, 12, 13,
+ 14, 15, 15, 16, 16, 17, 17, 18,
+ 18, 18, 20, 19, 19, 19, 20, 19,
+ 19, 20, 20, 20, 20, 20, 20,
+};
+
+static const uint32_t f_huffman_env_3_0dB_codes[63] = {
+ 0xffff0, 0xffff1, 0xffff2, 0xffff3, 0xffff4, 0xffff5, 0xffff6, 0x3fff3,
+ 0x7fff5, 0x7ffee, 0x7ffef, 0x7fff6, 0x3fff4, 0x3fff2, 0xffff7, 0x7fff0,
+ 0x1fff5, 0x3fff0, 0x1fff4, 0x0fff7, 0x0fff6, 0x07ff8, 0x03ffb, 0x00ffd,
+ 0x007fd, 0x003fd, 0x001fd, 0x000fd, 0x0003e, 0x0000e, 0x00002, 0x00000,
+ 0x00006, 0x0001e, 0x000fc, 0x001fc, 0x003fc, 0x007fc, 0x00ffc, 0x01ffc,
+ 0x03ffa, 0x07ff9, 0x07ffa, 0x0fff8, 0x0fff9, 0x1fff6, 0x1fff7, 0x3fff5,
+ 0x3fff6, 0x3fff1, 0xffff8, 0x7fff1, 0x7fff2, 0x7fff3, 0xffff9, 0x7fff7,
+ 0x7fff4, 0xffffa, 0xffffb, 0xffffc, 0xffffd, 0xffffe, 0xfffff,
+};
+
+static const uint8_t t_huffman_env_bal_3_0dB_bits[25] = {
+ 13, 13, 13, 13, 13, 13, 13, 12,
+ 8, 7, 4, 3, 1, 2, 5, 6,
+ 9, 13, 13, 13, 13, 13, 13, 14,
+ 14,
+};
+
+static const uint16_t t_huffman_env_bal_3_0dB_codes[25] = {
+ 0x1ff2, 0x1ff3, 0x1ff4, 0x1ff5, 0x1ff6, 0x1ff7, 0x1ff8, 0x0ff8,
+ 0x00fe, 0x007e, 0x000e, 0x0006, 0x0000, 0x0002, 0x001e, 0x003e,
+ 0x01fe, 0x1ff9, 0x1ffa, 0x1ffb, 0x1ffc, 0x1ffd, 0x1ffe, 0x3ffe,
+ 0x3fff,
+};
+
+static const uint8_t f_huffman_env_bal_3_0dB_bits[25] = {
+ 13, 13, 13, 13, 13, 14, 14, 11,
+ 8, 7, 4, 2, 1, 3, 5, 6,
+ 9, 12, 13, 14, 14, 14, 14, 14,
+ 14,
+};
+
+static const uint16_t f_huffman_env_bal_3_0dB_codes[25] = {
+ 0x1ff7, 0x1ff8, 0x1ff9, 0x1ffa, 0x1ffb, 0x3ff8, 0x3ff9, 0x07fc,
+ 0x00fe, 0x007e, 0x000e, 0x0002, 0x0000, 0x0006, 0x001e, 0x003e,
+ 0x01fe, 0x0ffa, 0x1ff6, 0x3ffa, 0x3ffb, 0x3ffc, 0x3ffd, 0x3ffe,
+ 0x3fff,
+};
+
+static const uint8_t t_huffman_noise_3_0dB_bits[63] = {
+ 13, 13, 13, 13, 13, 13, 13, 13,
+ 13, 13, 13, 13, 13, 13, 13, 13,
+ 13, 13, 13, 13, 13, 13, 13, 13,
+ 13, 13, 11, 8, 6, 4, 3, 1,
+ 2, 5, 8, 10, 13, 13, 13, 13,
+ 13, 13, 13, 13, 13, 13, 13, 13,
+ 13, 13, 13, 13, 13, 13, 13, 13,
+ 13, 13, 13, 13, 13, 14, 14,
+};
+
+static const uint16_t t_huffman_noise_3_0dB_codes[63] = {
+ 0x1fce, 0x1fcf, 0x1fd0, 0x1fd1, 0x1fd2, 0x1fd3, 0x1fd4, 0x1fd5,
+ 0x1fd6, 0x1fd7, 0x1fd8, 0x1fd9, 0x1fda, 0x1fdb, 0x1fdc, 0x1fdd,
+ 0x1fde, 0x1fdf, 0x1fe0, 0x1fe1, 0x1fe2, 0x1fe3, 0x1fe4, 0x1fe5,
+ 0x1fe6, 0x1fe7, 0x07f2, 0x00fd, 0x003e, 0x000e, 0x0006, 0x0000,
+ 0x0002, 0x001e, 0x00fc, 0x03f8, 0x1fcc, 0x1fe8, 0x1fe9, 0x1fea,
+ 0x1feb, 0x1fec, 0x1fcd, 0x1fed, 0x1fee, 0x1fef, 0x1ff0, 0x1ff1,
+ 0x1ff2, 0x1ff3, 0x1ff4, 0x1ff5, 0x1ff6, 0x1ff7, 0x1ff8, 0x1ff9,
+ 0x1ffa, 0x1ffb, 0x1ffc, 0x1ffd, 0x1ffe, 0x3ffe, 0x3fff,
+};
+
+static const uint8_t t_huffman_noise_bal_3_0dB_bits[25] = {
+ 8, 8, 8, 8, 8, 8, 8, 8,
+ 8, 8, 5, 2, 1, 3, 6, 8,
+ 8, 8, 8, 8, 8, 8, 8, 8,
+ 8,
+};
+
+static const uint8_t t_huffman_noise_bal_3_0dB_codes[25] = {
+ 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3,
+ 0xf4, 0xf5, 0x1c, 0x02, 0x00, 0x06, 0x3a, 0xf6,
+ 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe,
+ 0xff,
+};
+
+static const int8_t sbr_offset[6][16] = {
+ {-8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7}, // fs_sbr = 16000 Hz
+ {-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13}, // fs_sbr = 22050 Hz
+ {-5, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16}, // fs_sbr = 24000 Hz
+ {-6, -4, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16}, // fs_sbr = 32000 Hz
+ {-4, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16, 20}, // 44100 Hz <= fs_sbr <= 64000 Hz
+ {-2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16, 20, 24}, // 64000 Hz < fs_sbr
+};
+
+///< window coefficients for analysis/synthesis QMF banks
+static DECLARE_ALIGNED(16, float, sbr_qmf_window_ds)[320];
+static DECLARE_ALIGNED(16, float, sbr_qmf_window_us)[640] = {
+ 0.0000000000, -0.0005525286, -0.0005617692, -0.0004947518,
+ -0.0004875227, -0.0004893791, -0.0005040714, -0.0005226564,
+ -0.0005466565, -0.0005677802, -0.0005870930, -0.0006132747,
+ -0.0006312493, -0.0006540333, -0.0006777690, -0.0006941614,
+ -0.0007157736, -0.0007255043, -0.0007440941, -0.0007490598,
+ -0.0007681371, -0.0007724848, -0.0007834332, -0.0007779869,
+ -0.0007803664, -0.0007801449, -0.0007757977, -0.0007630793,
+ -0.0007530001, -0.0007319357, -0.0007215391, -0.0006917937,
+ -0.0006650415, -0.0006341594, -0.0005946118, -0.0005564576,
+ -0.0005145572, -0.0004606325, -0.0004095121, -0.0003501175,
+ -0.0002896981, -0.0002098337, -0.0001446380, -0.0000617334,
+ 0.0000134949, 0.0001094383, 0.0002043017, 0.0002949531,
+ 0.0004026540, 0.0005107388, 0.0006239376, 0.0007458025,
+ 0.0008608443, 0.0009885988, 0.0011250155, 0.0012577884,
+ 0.0013902494, 0.0015443219, 0.0016868083, 0.0018348265,
+ 0.0019841140, 0.0021461583, 0.0023017254, 0.0024625616,
+ 0.0026201758, 0.0027870464, 0.0029469447, 0.0031125420,
+ 0.0032739613, 0.0034418874, 0.0036008268, 0.0037603922,
+ 0.0039207432, 0.0040819753, 0.0042264269, 0.0043730719,
+ 0.0045209852, 0.0046606460, 0.0047932560, 0.0049137603,
+ 0.0050393022, 0.0051407353, 0.0052461166, 0.0053471681,
+ 0.0054196775, 0.0054876040, 0.0055475714, 0.0055938023,
+ 0.0056220643, 0.0056455196, 0.0056389199, 0.0056266114,
+ 0.0055917128, 0.0055404363, 0.0054753783, 0.0053838975,
+ 0.0052715758, 0.0051382275, 0.0049839687, 0.0048109469,
+ 0.0046039530, 0.0043801861, 0.0041251642, 0.0038456408,
+ 0.0035401246, 0.0032091885, 0.0028446757, 0.0024508540,
+ 0.0020274176, 0.0015784682, 0.0010902329, 0.0005832264,
+ 0.0000276045, -0.0005464280, -0.0011568135, -0.0018039472,
+ -0.0024826723, -0.0031933778, -0.0039401124, -0.0047222596,
+ -0.0055337211, -0.0063792293, -0.0072615816, -0.0081798233,
+ -0.0091325329, -0.0101150215, -0.0111315548, -0.0121849995,
+ 0.0132718220, 0.0143904666, 0.0155405553, 0.0167324712,
+ 0.0179433381, 0.0191872431, 0.0204531793, 0.0217467550,
+ 0.0230680169, 0.0244160992, 0.0257875847, 0.0271859429,
+ 0.0286072173, 0.0300502657, 0.0315017608, 0.0329754081,
+ 0.0344620948, 0.0359697560, 0.0374812850, 0.0390053679,
+ 0.0405349170, 0.0420649094, 0.0436097542, 0.0451488405,
+ 0.0466843027, 0.0482165720, 0.0497385755, 0.0512556155,
+ 0.0527630746, 0.0542452768, 0.0557173648, 0.0571616450,
+ 0.0585915683, 0.0599837480, 0.0613455171, 0.0626857808,
+ 0.0639715898, 0.0652247106, 0.0664367512, 0.0676075985,
+ 0.0687043828, 0.0697630244, 0.0707628710, 0.0717002673,
+ 0.0725682583, 0.0733620255, 0.0741003642, 0.0747452558,
+ 0.0753137336, 0.0758008358, 0.0761992479, 0.0764992170,
+ 0.0767093490, 0.0768173975, 0.0768230011, 0.0767204924,
+ 0.0765050718, 0.0761748321, 0.0757305756, 0.0751576255,
+ 0.0744664394, 0.0736406005, 0.0726774642, 0.0715826364,
+ 0.0703533073, 0.0689664013, 0.0674525021, 0.0657690668,
+ 0.0639444805, 0.0619602779, 0.0598166570, 0.0575152691,
+ 0.0550460034, 0.0524093821, 0.0495978676, 0.0466303305,
+ 0.0434768782, 0.0401458278, 0.0366418116, 0.0329583930,
+ 0.0290824006, 0.0250307561, 0.0207997072, 0.0163701258,
+ 0.0117623832, 0.0069636862, 0.0019765601, -0.0032086896,
+ -0.0085711749, -0.0141288827, -0.0198834129, -0.0258227288,
+ -0.0319531274, -0.0382776572, -0.0447806821, -0.0514804176,
+ -0.0583705326, -0.0654409853, -0.0726943300, -0.0801372934,
+ -0.0877547536, -0.0955533352, -0.1035329531, -0.1116826931,
+ -0.1200077984, -0.1285002850, -0.1371551761, -0.1459766491,
+ -0.1549607071, -0.1640958855, -0.1733808172, -0.1828172548,
+ -0.1923966745, -0.2021250176, -0.2119735853, -0.2219652696,
+ -0.2320690870, -0.2423016884, -0.2526480309, -0.2631053299,
+ -0.2736634040, -0.2843214189, -0.2950716717, -0.3059098575,
+ -0.3168278913, -0.3278113727, -0.3388722693, -0.3499914122,
+ 0.3611589903, 0.3723795546, 0.3836350013, 0.3949211761,
+ 0.4062317676, 0.4175696896, 0.4289119920, 0.4402553754,
+ 0.4515996535, 0.4629308085, 0.4742453214, 0.4855253091,
+ 0.4967708254, 0.5079817500, 0.5191234970, 0.5302240895,
+ 0.5412553448, 0.5522051258, 0.5630789140, 0.5738524131,
+ 0.5845403235, 0.5951123086, 0.6055783538, 0.6159109932,
+ 0.6261242695, 0.6361980107, 0.6461269695, 0.6559016302,
+ 0.6655139880, 0.6749663190, 0.6842353293, 0.6933282376,
+ 0.7022388719, 0.7109410426, 0.7194462634, 0.7277448900,
+ 0.7358211758, 0.7436827863, 0.7513137456, 0.7587080760,
+ 0.7658674865, 0.7727780881, 0.7794287519, 0.7858353120,
+ 0.7919735841, 0.7978466413, 0.8034485751, 0.8087695004,
+ 0.8138191270, 0.8185776004, 0.8230419890, 0.8272275347,
+ 0.8311038457, 0.8346937361, 0.8379717337, 0.8409541392,
+ 0.8436238281, 0.8459818469, 0.8480315777, 0.8497805198,
+ 0.8511971524, 0.8523047035, 0.8531020949, 0.8535720573,
+ 0.8537385600,
+};
+
+/* First two entries repeated at end to simplify SIMD implementations. */
+const DECLARE_ALIGNED(16, float, ff_sbr_noise_table)[][2] = {
+{-0.99948153278296, -0.59483417516607}, { 0.97113454393991, -0.67528515225647},
+{ 0.14130051758487, -0.95090983575689}, {-0.47005496701697, -0.37340549728647},
+{ 0.80705063769351, 0.29653668284408}, {-0.38981478896926, 0.89572605717087},
+{-0.01053049862020, -0.66959058036166}, {-0.91266367957293, -0.11522938140034},
+{ 0.54840422910309, 0.75221367176302}, { 0.40009252867955, -0.98929400334421},
+{-0.99867974711855, -0.88147068645358}, {-0.95531076805040, 0.90908757154593},
+{-0.45725933317144, -0.56716323646760}, {-0.72929675029275, -0.98008272727324},
+{ 0.75622801399036, 0.20950329995549}, { 0.07069442601050, -0.78247898470706},
+{ 0.74496252926055, -0.91169004445807}, {-0.96440182703856, -0.94739918296622},
+{ 0.30424629369539, -0.49438267012479}, { 0.66565033746925, 0.64652935542491},
+{ 0.91697008020594, 0.17514097332009}, {-0.70774918760427, 0.52548653416543},
+{-0.70051415345560, -0.45340028808763}, {-0.99496513054797, -0.90071908066973},
+{ 0.98164490790123, -0.77463155528697}, {-0.54671580548181, -0.02570928536004},
+{-0.01689629065389, 0.00287506445732}, {-0.86110349531986, 0.42548583726477},
+{-0.98892980586032, -0.87881132267556}, { 0.51756627678691, 0.66926784710139},
+{-0.99635026409640, -0.58107730574765}, {-0.99969370862163, 0.98369989360250},
+{ 0.55266258627194, 0.59449057465591}, { 0.34581177741673, 0.94879421061866},
+{ 0.62664209577999, -0.74402970906471}, {-0.77149701404973, -0.33883658042801},
+{-0.91592244254432, 0.03687901376713}, {-0.76285492357887, -0.91371867919124},
+{ 0.79788337195331, -0.93180971199849}, { 0.54473080610200, -0.11919206037186},
+{-0.85639281671058, 0.42429854760451}, {-0.92882402971423, 0.27871809078609},
+{-0.11708371046774, -0.99800843444966}, { 0.21356749817493, -0.90716295627033},
+{-0.76191692573909, 0.99768118356265}, { 0.98111043100884, -0.95854459734407},
+{-0.85913269895572, 0.95766566168880}, {-0.93307242253692, 0.49431757696466},
+{ 0.30485754879632, -0.70540034357529}, { 0.85289650925190, 0.46766131791044},
+{ 0.91328082618125, -0.99839597361769}, {-0.05890199924154, 0.70741827819497},
+{ 0.28398686150148, 0.34633555702188}, { 0.95258164539612, -0.54893416026939},
+{-0.78566324168507, -0.75568541079691}, {-0.95789495447877, -0.20423194696966},
+{ 0.82411158711197, 0.96654618432562}, {-0.65185446735885, -0.88734990773289},
+{-0.93643603134666, 0.99870790442385}, { 0.91427159529618, -0.98290505544444},
+{-0.70395684036886, 0.58796798221039}, { 0.00563771969365, 0.61768196727244},
+{ 0.89065051931895, 0.52783352697585}, {-0.68683707712762, 0.80806944710339},
+{ 0.72165342518718, -0.69259857349564}, {-0.62928247730667, 0.13627037407335},
+{ 0.29938434065514, -0.46051329682246}, {-0.91781958879280, -0.74012716684186},
+{ 0.99298717043688, 0.40816610075661}, { 0.82368298622748, -0.74036047190173},
+{-0.98512833386833, -0.99972330709594}, {-0.95915368242257, -0.99237800466040},
+{-0.21411126572790, -0.93424819052545}, {-0.68821476106884, -0.26892306315457},
+{ 0.91851997982317, 0.09358228901785}, {-0.96062769559127, 0.36099095133739},
+{ 0.51646184922287, -0.71373332873917}, { 0.61130721139669, 0.46950141175917},
+{ 0.47336129371299, -0.27333178296162}, { 0.90998308703519, 0.96715662938132},
+{ 0.44844799194357, 0.99211574628306}, { 0.66614891079092, 0.96590176169121},
+{ 0.74922239129237, -0.89879858826087}, {-0.99571588506485, 0.52785521494349},
+{ 0.97401082477563, -0.16855870075190}, { 0.72683747733879, -0.48060774432251},
+{ 0.95432193457128, 0.68849603408441}, {-0.72962208425191, -0.76608443420917},
+{-0.85359479233537, 0.88738125901579}, {-0.81412430338535, -0.97480768049637},
+{-0.87930772356786, 0.74748307690436}, {-0.71573331064977, -0.98570608178923},
+{ 0.83524300028228, 0.83702537075163}, {-0.48086065601423, -0.98848504923531},
+{ 0.97139128574778, 0.80093621198236}, { 0.51992825347895, 0.80247631400510},
+{-0.00848591195325, -0.76670128000486}, {-0.70294374303036, 0.55359910445577},
+{-0.95894428168140, -0.43265504344783}, { 0.97079252950321, 0.09325857238682},
+{-0.92404293670797, 0.85507704027855}, {-0.69506469500450, 0.98633412625459},
+{ 0.26559203620024, 0.73314307966524}, { 0.28038443336943, 0.14537913654427},
+{-0.74138124825523, 0.99310339807762}, {-0.01752795995444, -0.82616635284178},
+{-0.55126773094930, -0.98898543862153}, { 0.97960898850996, -0.94021446752851},
+{-0.99196309146936, 0.67019017358456}, {-0.67684928085260, 0.12631491649378},
+{ 0.09140039465500, -0.20537731453108}, {-0.71658965751996, -0.97788200391224},
+{ 0.81014640078925, 0.53722648362443}, { 0.40616991671205, -0.26469008598449},
+{-0.67680188682972, 0.94502052337695}, { 0.86849774348749, -0.18333598647899},
+{-0.99500381284851, -0.02634122068550}, { 0.84329189340667, 0.10406957462213},
+{-0.09215968531446, 0.69540012101253}, { 0.99956173327206, -0.12358542001404},
+{-0.79732779473535, -0.91582524736159}, { 0.96349973642406, 0.96640458041000},
+{-0.79942778496547, 0.64323902822857}, {-0.11566039853896, 0.28587846253726},
+{-0.39922954514662, 0.94129601616966}, { 0.99089197565987, -0.92062625581587},
+{ 0.28631285179909, -0.91035047143603}, {-0.83302725605608, -0.67330410892084},
+{ 0.95404443402072, 0.49162765398743}, {-0.06449863579434, 0.03250560813135},
+{-0.99575054486311, 0.42389784469507}, {-0.65501142790847, 0.82546114655624},
+{-0.81254441908887, -0.51627234660629}, {-0.99646369485481, 0.84490533520752},
+{ 0.00287840603348, 0.64768261158166}, { 0.70176989408455, -0.20453028573322},
+{ 0.96361882270190, 0.40706967140989}, {-0.68883758192426, 0.91338958840772},
+{-0.34875585502238, 0.71472290693300}, { 0.91980081243087, 0.66507455644919},
+{-0.99009048343881, 0.85868021604848}, { 0.68865791458395, 0.55660316809678},
+{-0.99484402129368, -0.20052559254934}, { 0.94214511408023, -0.99696425367461},
+{-0.67414626793544, 0.49548221180078}, {-0.47339353684664, -0.85904328834047},
+{ 0.14323651387360, -0.94145598222488}, {-0.29268293575672, 0.05759224927952},
+{ 0.43793861458754, -0.78904969892724}, {-0.36345126374441, 0.64874435357162},
+{-0.08750604656825, 0.97686944362527}, {-0.96495267812511, -0.53960305946511},
+{ 0.55526940659947, 0.78891523734774}, { 0.73538215752630, 0.96452072373404},
+{-0.30889773919437, -0.80664389776860}, { 0.03574995626194, -0.97325616900959},
+{ 0.98720684660488, 0.48409133691962}, {-0.81689296271203, -0.90827703628298},
+{ 0.67866860118215, 0.81284503870856}, {-0.15808569732583, 0.85279555024382},
+{ 0.80723395114371, -0.24717418514605}, { 0.47788757329038, -0.46333147839295},
+{ 0.96367554763201, 0.38486749303242}, {-0.99143875716818, -0.24945277239809},
+{ 0.83081876925833, -0.94780851414763}, {-0.58753191905341, 0.01290772389163},
+{ 0.95538108220960, -0.85557052096538}, {-0.96490920476211, -0.64020970923102},
+{-0.97327101028521, 0.12378128133110}, { 0.91400366022124, 0.57972471346930},
+{-0.99925837363824, 0.71084847864067}, {-0.86875903507313, -0.20291699203564},
+{-0.26240034795124, -0.68264554369108}, {-0.24664412953388, -0.87642273115183},
+{ 0.02416275806869, 0.27192914288905}, { 0.82068619590515, -0.85087787994476},
+{ 0.88547373760759, -0.89636802901469}, {-0.18173078152226, -0.26152145156800},
+{ 0.09355476558534, 0.54845123045604}, {-0.54668414224090, 0.95980774020221},
+{ 0.37050990604091, -0.59910140383171}, {-0.70373594262891, 0.91227665827081},
+{-0.34600785879594, -0.99441426144200}, {-0.68774481731008, -0.30238837956299},
+{-0.26843291251234, 0.83115668004362}, { 0.49072334613242, -0.45359708737775},
+{ 0.38975993093975, 0.95515358099121}, {-0.97757125224150, 0.05305894580606},
+{-0.17325552859616, -0.92770672250494}, { 0.99948035025744, 0.58285545563426},
+{-0.64946246527458, 0.68645507104960}, {-0.12016920576437, -0.57147322153312},
+{-0.58947456517751, -0.34847132454388}, {-0.41815140454465, 0.16276422358861},
+{ 0.99885650204884, 0.11136095490444}, {-0.56649614128386, -0.90494866361587},
+{ 0.94138021032330, 0.35281916733018}, {-0.75725076534641, 0.53650549640587},
+{ 0.20541973692630, -0.94435144369918}, { 0.99980371023351, 0.79835913565599},
+{ 0.29078277605775, 0.35393777921520}, {-0.62858772103030, 0.38765693387102},
+{ 0.43440904467688, -0.98546330463232}, {-0.98298583762390, 0.21021524625209},
+{ 0.19513029146934, -0.94239832251867}, {-0.95476662400101, 0.98364554179143},
+{ 0.93379635304810, -0.70881994583682}, {-0.85235410573336, -0.08342347966410},
+{-0.86425093011245, -0.45795025029466}, { 0.38879779059045, 0.97274429344593},
+{ 0.92045124735495, -0.62433652524220}, { 0.89162532251878, 0.54950955570563},
+{-0.36834336949252, 0.96458298020975}, { 0.93891760988045, -0.89968353740388},
+{ 0.99267657565094, -0.03757034316958}, {-0.94063471614176, 0.41332338538963},
+{ 0.99740224117019, -0.16830494996370}, {-0.35899413170555, -0.46633226649613},
+{ 0.05237237274947, -0.25640361602661}, { 0.36703583957424, -0.38653265641875},
+{ 0.91653180367913, -0.30587628726597}, { 0.69000803499316, 0.90952171386132},
+{-0.38658751133527, 0.99501571208985}, {-0.29250814029851, 0.37444994344615},
+{-0.60182204677608, 0.86779651036123}, {-0.97418588163217, 0.96468523666475},
+{ 0.88461574003963, 0.57508405276414}, { 0.05198933055162, 0.21269661669964},
+{-0.53499621979720, 0.97241553731237}, {-0.49429560226497, 0.98183865291903},
+{-0.98935142339139, -0.40249159006933}, {-0.98081380091130, -0.72856895534041},
+{-0.27338148835532, 0.99950922447209}, { 0.06310802338302, -0.54539587529618},
+{-0.20461677199539, -0.14209977628489}, { 0.66223843141647, 0.72528579940326},
+{-0.84764345483665, 0.02372316801261}, {-0.89039863483811, 0.88866581484602},
+{ 0.95903308477986, 0.76744927173873}, { 0.73504123909879, -0.03747203173192},
+{-0.31744434966056, -0.36834111883652}, {-0.34110827591623, 0.40211222807691},
+{ 0.47803883714199, -0.39423219786288}, { 0.98299195879514, 0.01989791390047},
+{-0.30963073129751, -0.18076720599336}, { 0.99992588229018, -0.26281872094289},
+{-0.93149731080767, -0.98313162570490}, { 0.99923472302773, -0.80142993767554},
+{-0.26024169633417, -0.75999759855752}, {-0.35712514743563, 0.19298963768574},
+{-0.99899084509530, 0.74645156992493}, { 0.86557171579452, 0.55593866696299},
+{ 0.33408042438752, 0.86185953874709}, { 0.99010736374716, 0.04602397576623},
+{-0.66694269691195, -0.91643611810148}, { 0.64016792079480, 0.15649530836856},
+{ 0.99570534804836, 0.45844586038111}, {-0.63431466947340, 0.21079116459234},
+{-0.07706847005931, -0.89581437101329}, { 0.98590090577724, 0.88241721133981},
+{ 0.80099335254678, -0.36851896710853}, { 0.78368131392666, 0.45506999802597},
+{ 0.08707806671691, 0.80938994918745}, {-0.86811883080712, 0.39347308654705},
+{-0.39466529740375, -0.66809432114456}, { 0.97875325649683, -0.72467840967746},
+{-0.95038560288864, 0.89563219587625}, { 0.17005239424212, 0.54683053962658},
+{-0.76910792026848, -0.96226617549298}, { 0.99743281016846, 0.42697157037567},
+{ 0.95437383549973, 0.97002324109952}, { 0.99578905365569, -0.54106826257356},
+{ 0.28058259829990, -0.85361420634036}, { 0.85256524470573, -0.64567607735589},
+{-0.50608540105128, -0.65846015480300}, {-0.97210735183243, -0.23095213067791},
+{ 0.95424048234441, -0.99240147091219}, {-0.96926570524023, 0.73775654896574},
+{ 0.30872163214726, 0.41514960556126}, {-0.24523839572639, 0.63206633394807},
+{-0.33813265086024, -0.38661779441897}, {-0.05826828420146, -0.06940774188029},
+{-0.22898461455054, 0.97054853316316}, {-0.18509915019881, 0.47565762892084},
+{-0.10488238045009, -0.87769947402394}, {-0.71886586182037, 0.78030982480538},
+{ 0.99793873738654, 0.90041310491497}, { 0.57563307626120, -0.91034337352097},
+{ 0.28909646383717, 0.96307783970534}, { 0.42188998312520, 0.48148651230437},
+{ 0.93335049681047, -0.43537023883588}, {-0.97087374418267, 0.86636445711364},
+{ 0.36722871286923, 0.65291654172961}, {-0.81093025665696, 0.08778370229363},
+{-0.26240603062237, -0.92774095379098}, { 0.83996497984604, 0.55839849139647},
+{-0.99909615720225, -0.96024605713970}, { 0.74649464155061, 0.12144893606462},
+{-0.74774595569805, -0.26898062008959}, { 0.95781667469567, -0.79047927052628},
+{ 0.95472308713099, -0.08588776019550}, { 0.48708332746299, 0.99999041579432},
+{ 0.46332038247497, 0.10964126185063}, {-0.76497004940162, 0.89210929242238},
+{ 0.57397389364339, 0.35289703373760}, { 0.75374316974495, 0.96705214651335},
+{-0.59174397685714, -0.89405370422752}, { 0.75087906691890, -0.29612672982396},
+{-0.98607857336230, 0.25034911730023}, {-0.40761056640505, -0.90045573444695},
+{ 0.66929266740477, 0.98629493401748}, {-0.97463695257310, -0.00190223301301},
+{ 0.90145509409859, 0.99781390365446}, {-0.87259289048043, 0.99233587353666},
+{-0.91529461447692, -0.15698707534206}, {-0.03305738840705, -0.37205262859764},
+{ 0.07223051368337, -0.88805001733626}, { 0.99498012188353, 0.97094358113387},
+{-0.74904939500519, 0.99985483641521}, { 0.04585228574211, 0.99812337444082},
+{-0.89054954257993, -0.31791913188064}, {-0.83782144651251, 0.97637632547466},
+{ 0.33454804933804, -0.86231516800408}, {-0.99707579362824, 0.93237990079441},
+{-0.22827527843994, 0.18874759397997}, { 0.67248046289143, -0.03646211390569},
+{-0.05146538187944, -0.92599700120679}, { 0.99947295749905, 0.93625229707912},
+{ 0.66951124390363, 0.98905825623893}, {-0.99602956559179, -0.44654715757688},
+{ 0.82104905483590, 0.99540741724928}, { 0.99186510988782, 0.72023001312947},
+{-0.65284592392918, 0.52186723253637}, { 0.93885443798188, -0.74895312615259},
+{ 0.96735248738388, 0.90891816978629}, {-0.22225968841114, 0.57124029781228},
+{-0.44132783753414, -0.92688840659280}, {-0.85694974219574, 0.88844532719844},
+{ 0.91783042091762, -0.46356892383970}, { 0.72556974415690, -0.99899555770747},
+{-0.99711581834508, 0.58211560180426}, { 0.77638976371966, 0.94321834873819},
+{ 0.07717324253925, 0.58638399856595}, {-0.56049829194163, 0.82522301569036},
+{ 0.98398893639988, 0.39467440420569}, { 0.47546946844938, 0.68613044836811},
+{ 0.65675089314631, 0.18331637134880}, { 0.03273375457980, -0.74933109564108},
+{-0.38684144784738, 0.51337349030406}, {-0.97346267944545, -0.96549364384098},
+{-0.53282156061942, -0.91423265091354}, { 0.99817310731176, 0.61133572482148},
+{-0.50254500772635, -0.88829338134294}, { 0.01995873238855, 0.85223515096765},
+{ 0.99930381973804, 0.94578896296649}, { 0.82907767600783, -0.06323442598128},
+{-0.58660709669728, 0.96840773806582}, {-0.17573736667267, -0.48166920859485},
+{ 0.83434292401346, -0.13023450646997}, { 0.05946491307025, 0.20511047074866},
+{ 0.81505484574602, -0.94685947861369}, {-0.44976380954860, 0.40894572671545},
+{-0.89746474625671, 0.99846578838537}, { 0.39677256130792, -0.74854668609359},
+{-0.07588948563079, 0.74096214084170}, { 0.76343198951445, 0.41746629422634},
+{-0.74490104699626, 0.94725911744610}, { 0.64880119792759, 0.41336660830571},
+{ 0.62319537462542, -0.93098313552599}, { 0.42215817594807, -0.07712787385208},
+{ 0.02704554141885, -0.05417518053666}, { 0.80001773566818, 0.91542195141039},
+{-0.79351832348816, -0.36208897989136}, { 0.63872359151636, 0.08128252493444},
+{ 0.52890520960295, 0.60048872455592}, { 0.74238552914587, 0.04491915291044},
+{ 0.99096131449250, -0.19451182854402}, {-0.80412329643109, -0.88513818199457},
+{-0.64612616129736, 0.72198674804544}, { 0.11657770663191, -0.83662833815041},
+{-0.95053182488101, -0.96939905138082}, {-0.62228872928622, 0.82767262846661},
+{ 0.03004475787316, -0.99738896333384}, {-0.97987214341034, 0.36526129686425},
+{-0.99986980746200, -0.36021610299715}, { 0.89110648599879, -0.97894250343044},
+{ 0.10407960510582, 0.77357793811619}, { 0.95964737821728, -0.35435818285502},
+{ 0.50843233159162, 0.96107691266205}, { 0.17006334670615, -0.76854025314829},
+{ 0.25872675063360, 0.99893303933816}, {-0.01115998681937, 0.98496019742444},
+{-0.79598702973261, 0.97138411318894}, {-0.99264708948101, -0.99542822402536},
+{-0.99829663752818, 0.01877138824311}, {-0.70801016548184, 0.33680685948117},
+{-0.70467057786826, 0.93272777501857}, { 0.99846021905254, -0.98725746254433},
+{-0.63364968534650, -0.16473594423746}, {-0.16258217500792, -0.95939125400802},
+{-0.43645594360633, -0.94805030113284}, {-0.99848471702976, 0.96245166923809},
+{-0.16796458968998, -0.98987511890470}, {-0.87979225745213, -0.71725725041680},
+{ 0.44183099021786, -0.93568974498761}, { 0.93310180125532, -0.99913308068246},
+{-0.93941931782002, -0.56409379640356}, {-0.88590003188677, 0.47624600491382},
+{ 0.99971463703691, -0.83889954253462}, {-0.75376385639978, 0.00814643438625},
+{ 0.93887685615875, -0.11284528204636}, { 0.85126435782309, 0.52349251543547},
+{ 0.39701421446381, 0.81779634174316}, {-0.37024464187437, -0.87071656222959},
+{-0.36024828242896, 0.34655735648287}, {-0.93388812549209, -0.84476541096429},
+{-0.65298804552119, -0.18439575450921}, { 0.11960319006843, 0.99899346780168},
+{ 0.94292565553160, 0.83163906518293}, { 0.75081145286948, -0.35533223142265},
+{ 0.56721979748394, -0.24076836414499}, { 0.46857766746029, -0.30140233457198},
+{ 0.97312313923635, -0.99548191630031}, {-0.38299976567017, 0.98516909715427},
+{ 0.41025800019463, 0.02116736935734}, { 0.09638062008048, 0.04411984381457},
+{-0.85283249275397, 0.91475563922421}, { 0.88866808958124, -0.99735267083226},
+{-0.48202429536989, -0.96805608884164}, { 0.27572582416567, 0.58634753335832},
+{-0.65889129659168, 0.58835634138583}, { 0.98838086953732, 0.99994349600236},
+{-0.20651349620689, 0.54593044066355}, {-0.62126416356920, -0.59893681700392},
+{ 0.20320105410437, -0.86879180355289}, {-0.97790548600584, 0.96290806999242},
+{ 0.11112534735126, 0.21484763313301}, {-0.41368337314182, 0.28216837680365},
+{ 0.24133038992960, 0.51294362630238}, {-0.66393410674885, -0.08249679629081},
+{-0.53697829178752, -0.97649903936228}, {-0.97224737889348, 0.22081333579837},
+{ 0.87392477144549, -0.12796173740361}, { 0.19050361015753, 0.01602615387195},
+{-0.46353441212724, -0.95249041539006}, {-0.07064096339021, -0.94479803205886},
+{-0.92444085484466, -0.10457590187436}, {-0.83822593578728, -0.01695043208885},
+{ 0.75214681811150, -0.99955681042665}, {-0.42102998829339, 0.99720941999394},
+{-0.72094786237696, -0.35008961934255}, { 0.78843311019251, 0.52851398958271},
+{ 0.97394027897442, -0.26695944086561}, { 0.99206463477946, -0.57010120849429},
+{ 0.76789609461795, -0.76519356730966}, {-0.82002421836409, -0.73530179553767},
+{ 0.81924990025724, 0.99698425250579}, {-0.26719850873357, 0.68903369776193},
+{-0.43311260380975, 0.85321815947490}, { 0.99194979673836, 0.91876249766422},
+{-0.80692001248487, -0.32627540663214}, { 0.43080003649976, -0.21919095636638},
+{ 0.67709491937357, -0.95478075822906}, { 0.56151770568316, -0.70693811747778},
+{ 0.10831862810749, -0.08628837174592}, { 0.91229417540436, -0.65987351408410},
+{-0.48972893932274, 0.56289246362686}, {-0.89033658689697, -0.71656563987082},
+{ 0.65269447475094, 0.65916004833932}, { 0.67439478141121, -0.81684380846796},
+{-0.47770832416973, -0.16789556203025}, {-0.99715979260878, -0.93565784007648},
+{-0.90889593602546, 0.62034397054380}, {-0.06618622548177, -0.23812217221359},
+{ 0.99430266919728, 0.18812555317553}, { 0.97686402381843, -0.28664534366620},
+{ 0.94813650221268, -0.97506640027128}, {-0.95434497492853, -0.79607978501983},
+{-0.49104783137150, 0.32895214359663}, { 0.99881175120751, 0.88993983831354},
+{ 0.50449166760303, -0.85995072408434}, { 0.47162891065108, -0.18680204049569},
+{-0.62081581361840, 0.75000676218956}, {-0.43867015250812, 0.99998069244322},
+{ 0.98630563232075, -0.53578899600662}, {-0.61510362277374, -0.89515019899997},
+{-0.03841517601843, -0.69888815681179}, {-0.30102157304644, -0.07667808922205},
+{ 0.41881284182683, 0.02188098922282}, {-0.86135454941237, 0.98947480909359},
+{ 0.67226861393788, -0.13494389011014}, {-0.70737398842068, -0.76547349325992},
+{ 0.94044946687963, 0.09026201157416}, {-0.82386352534327, 0.08924768823676},
+{-0.32070666698656, 0.50143421908753}, { 0.57593163224487, -0.98966422921509},
+{-0.36326018419965, 0.07440243123228}, { 0.99979044674350, -0.14130287347405},
+{-0.92366023326932, -0.97979298068180}, {-0.44607178518598, -0.54233252016394},
+{ 0.44226800932956, 0.71326756742752}, { 0.03671907158312, 0.63606389366675},
+{ 0.52175424682195, -0.85396826735705}, {-0.94701139690956, -0.01826348194255},
+{-0.98759606946049, 0.82288714303073}, { 0.87434794743625, 0.89399495655433},
+{-0.93412041758744, 0.41374052024363}, { 0.96063943315511, 0.93116709541280},
+{ 0.97534253457837, 0.86150930812689}, { 0.99642466504163, 0.70190043427512},
+{-0.94705089665984, -0.29580042814306}, { 0.91599807087376, -0.98147830385781},
+{-0.99948153278296, -0.59483417516607}, { 0.97113454393991, -0.67528515225647},
+};
+
+#endif /* AVCODEC_AACSBRDATA_H */
diff --git a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aactab.c b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aactab.c index 46886b12d..2b2be8118 100644 --- a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aactab.c +++ b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aactab.c @@ -1,1207 +1,1207 @@ -/* - * AAC data - * Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org ) - * Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com ) - * - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/** - * @file - * AAC data - * @author Oded Shimon ( ods15 ods15 dyndns org ) - * @author Maxim Gavrilov ( maxim.gavrilov gmail com ) - */ - -#include "libavutil/mem.h" -#include "aac.h" -#include "aac_tablegen.h" - -#include <stdint.h> - -DECLARE_ALIGNED(16, float, ff_aac_kbd_long_1024)[1024]; -DECLARE_ALIGNED(16, float, ff_aac_kbd_short_128)[128]; - -const uint8_t ff_aac_num_swb_1024[] = { - 41, 41, 47, 49, 49, 51, 47, 47, 43, 43, 43, 40, 40 -}; - -const uint8_t ff_aac_num_swb_128[] = { - 12, 12, 12, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15 -}; - -const uint8_t ff_aac_pred_sfb_max[] = { - 33, 33, 38, 40, 40, 40, 41, 41, 37, 37, 37, 34, 34 -}; - -const uint32_t ff_aac_scalefactor_code[121] = { - 0x3ffe8, 0x3ffe6, 0x3ffe7, 0x3ffe5, 0x7fff5, 0x7fff1, 0x7ffed, 0x7fff6, - 0x7ffee, 0x7ffef, 0x7fff0, 0x7fffc, 0x7fffd, 0x7ffff, 0x7fffe, 0x7fff7, - 0x7fff8, 0x7fffb, 0x7fff9, 0x3ffe4, 0x7fffa, 0x3ffe3, 0x1ffef, 0x1fff0, - 0x0fff5, 0x1ffee, 0x0fff2, 0x0fff3, 0x0fff4, 0x0fff1, 0x07ff6, 0x07ff7, - 0x03ff9, 0x03ff5, 0x03ff7, 0x03ff3, 0x03ff6, 0x03ff2, 0x01ff7, 0x01ff5, - 0x00ff9, 0x00ff7, 0x00ff6, 0x007f9, 0x00ff4, 0x007f8, 0x003f9, 0x003f7, - 0x003f5, 0x001f8, 0x001f7, 0x000fa, 0x000f8, 0x000f6, 0x00079, 0x0003a, - 0x00038, 0x0001a, 0x0000b, 0x00004, 0x00000, 0x0000a, 0x0000c, 0x0001b, - 0x00039, 0x0003b, 0x00078, 0x0007a, 0x000f7, 0x000f9, 0x001f6, 0x001f9, - 0x003f4, 0x003f6, 0x003f8, 0x007f5, 0x007f4, 0x007f6, 0x007f7, 0x00ff5, - 0x00ff8, 0x01ff4, 0x01ff6, 0x01ff8, 0x03ff8, 0x03ff4, 0x0fff0, 0x07ff4, - 0x0fff6, 0x07ff5, 0x3ffe2, 0x7ffd9, 0x7ffda, 0x7ffdb, 0x7ffdc, 0x7ffdd, - 0x7ffde, 0x7ffd8, 0x7ffd2, 0x7ffd3, 0x7ffd4, 0x7ffd5, 0x7ffd6, 0x7fff2, - 0x7ffdf, 0x7ffe7, 0x7ffe8, 0x7ffe9, 0x7ffea, 0x7ffeb, 0x7ffe6, 0x7ffe0, - 0x7ffe1, 0x7ffe2, 0x7ffe3, 0x7ffe4, 0x7ffe5, 0x7ffd7, 0x7ffec, 0x7fff4, - 0x7fff3, -}; - -const uint8_t ff_aac_scalefactor_bits[121] = { - 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 18, 19, 18, 17, 17, 16, 17, 16, 16, 16, 16, 15, 15, - 14, 14, 14, 14, 14, 14, 13, 13, 12, 12, 12, 11, 12, 11, 10, 10, - 10, 9, 9, 8, 8, 8, 7, 6, 6, 5, 4, 3, 1, 4, 4, 5, - 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 11, 12, - 12, 13, 13, 13, 14, 14, 16, 15, 16, 15, 18, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, -}; - -static const uint16_t codes1[81] = { - 0x7f8, 0x1f1, 0x7fd, 0x3f5, 0x068, 0x3f0, 0x7f7, 0x1ec, - 0x7f5, 0x3f1, 0x072, 0x3f4, 0x074, 0x011, 0x076, 0x1eb, - 0x06c, 0x3f6, 0x7fc, 0x1e1, 0x7f1, 0x1f0, 0x061, 0x1f6, - 0x7f2, 0x1ea, 0x7fb, 0x1f2, 0x069, 0x1ed, 0x077, 0x017, - 0x06f, 0x1e6, 0x064, 0x1e5, 0x067, 0x015, 0x062, 0x012, - 0x000, 0x014, 0x065, 0x016, 0x06d, 0x1e9, 0x063, 0x1e4, - 0x06b, 0x013, 0x071, 0x1e3, 0x070, 0x1f3, 0x7fe, 0x1e7, - 0x7f3, 0x1ef, 0x060, 0x1ee, 0x7f0, 0x1e2, 0x7fa, 0x3f3, - 0x06a, 0x1e8, 0x075, 0x010, 0x073, 0x1f4, 0x06e, 0x3f7, - 0x7f6, 0x1e0, 0x7f9, 0x3f2, 0x066, 0x1f5, 0x7ff, 0x1f7, - 0x7f4, -}; - -static const uint8_t bits1[81] = { - 11, 9, 11, 10, 7, 10, 11, 9, 11, 10, 7, 10, 7, 5, 7, 9, - 7, 10, 11, 9, 11, 9, 7, 9, 11, 9, 11, 9, 7, 9, 7, 5, - 7, 9, 7, 9, 7, 5, 7, 5, 1, 5, 7, 5, 7, 9, 7, 9, - 7, 5, 7, 9, 7, 9, 11, 9, 11, 9, 7, 9, 11, 9, 11, 10, - 7, 9, 7, 5, 7, 9, 7, 10, 11, 9, 11, 10, 7, 9, 11, 9, - 11, -}; - -static const uint16_t codes2[81] = { - 0x1f3, 0x06f, 0x1fd, 0x0eb, 0x023, 0x0ea, 0x1f7, 0x0e8, - 0x1fa, 0x0f2, 0x02d, 0x070, 0x020, 0x006, 0x02b, 0x06e, - 0x028, 0x0e9, 0x1f9, 0x066, 0x0f8, 0x0e7, 0x01b, 0x0f1, - 0x1f4, 0x06b, 0x1f5, 0x0ec, 0x02a, 0x06c, 0x02c, 0x00a, - 0x027, 0x067, 0x01a, 0x0f5, 0x024, 0x008, 0x01f, 0x009, - 0x000, 0x007, 0x01d, 0x00b, 0x030, 0x0ef, 0x01c, 0x064, - 0x01e, 0x00c, 0x029, 0x0f3, 0x02f, 0x0f0, 0x1fc, 0x071, - 0x1f2, 0x0f4, 0x021, 0x0e6, 0x0f7, 0x068, 0x1f8, 0x0ee, - 0x022, 0x065, 0x031, 0x002, 0x026, 0x0ed, 0x025, 0x06a, - 0x1fb, 0x072, 0x1fe, 0x069, 0x02e, 0x0f6, 0x1ff, 0x06d, - 0x1f6, -}; - -static const uint8_t bits2[81] = { - 9, 7, 9, 8, 6, 8, 9, 8, 9, 8, 6, 7, 6, 5, 6, 7, - 6, 8, 9, 7, 8, 8, 6, 8, 9, 7, 9, 8, 6, 7, 6, 5, - 6, 7, 6, 8, 6, 5, 6, 5, 3, 5, 6, 5, 6, 8, 6, 7, - 6, 5, 6, 8, 6, 8, 9, 7, 9, 8, 6, 8, 8, 7, 9, 8, - 6, 7, 6, 4, 6, 8, 6, 7, 9, 7, 9, 7, 6, 8, 9, 7, - 9, -}; - -static const uint16_t codes3[81] = { - 0x0000, 0x0009, 0x00ef, 0x000b, 0x0019, 0x00f0, 0x01eb, 0x01e6, - 0x03f2, 0x000a, 0x0035, 0x01ef, 0x0034, 0x0037, 0x01e9, 0x01ed, - 0x01e7, 0x03f3, 0x01ee, 0x03ed, 0x1ffa, 0x01ec, 0x01f2, 0x07f9, - 0x07f8, 0x03f8, 0x0ff8, 0x0008, 0x0038, 0x03f6, 0x0036, 0x0075, - 0x03f1, 0x03eb, 0x03ec, 0x0ff4, 0x0018, 0x0076, 0x07f4, 0x0039, - 0x0074, 0x03ef, 0x01f3, 0x01f4, 0x07f6, 0x01e8, 0x03ea, 0x1ffc, - 0x00f2, 0x01f1, 0x0ffb, 0x03f5, 0x07f3, 0x0ffc, 0x00ee, 0x03f7, - 0x7ffe, 0x01f0, 0x07f5, 0x7ffd, 0x1ffb, 0x3ffa, 0xffff, 0x00f1, - 0x03f0, 0x3ffc, 0x01ea, 0x03ee, 0x3ffb, 0x0ff6, 0x0ffa, 0x7ffc, - 0x07f2, 0x0ff5, 0xfffe, 0x03f4, 0x07f7, 0x7ffb, 0x0ff7, 0x0ff9, - 0x7ffa, -}; - -static const uint8_t bits3[81] = { - 1, 4, 8, 4, 5, 8, 9, 9, 10, 4, 6, 9, 6, 6, 9, 9, - 9, 10, 9, 10, 13, 9, 9, 11, 11, 10, 12, 4, 6, 10, 6, 7, - 10, 10, 10, 12, 5, 7, 11, 6, 7, 10, 9, 9, 11, 9, 10, 13, - 8, 9, 12, 10, 11, 12, 8, 10, 15, 9, 11, 15, 13, 14, 16, 8, - 10, 14, 9, 10, 14, 12, 12, 15, 11, 12, 16, 10, 11, 15, 12, 12, - 15, -}; - -static const uint16_t codes4[81] = { - 0x007, 0x016, 0x0f6, 0x018, 0x008, 0x0ef, 0x1ef, 0x0f3, - 0x7f8, 0x019, 0x017, 0x0ed, 0x015, 0x001, 0x0e2, 0x0f0, - 0x070, 0x3f0, 0x1ee, 0x0f1, 0x7fa, 0x0ee, 0x0e4, 0x3f2, - 0x7f6, 0x3ef, 0x7fd, 0x005, 0x014, 0x0f2, 0x009, 0x004, - 0x0e5, 0x0f4, 0x0e8, 0x3f4, 0x006, 0x002, 0x0e7, 0x003, - 0x000, 0x06b, 0x0e3, 0x069, 0x1f3, 0x0eb, 0x0e6, 0x3f6, - 0x06e, 0x06a, 0x1f4, 0x3ec, 0x1f0, 0x3f9, 0x0f5, 0x0ec, - 0x7fb, 0x0ea, 0x06f, 0x3f7, 0x7f9, 0x3f3, 0xfff, 0x0e9, - 0x06d, 0x3f8, 0x06c, 0x068, 0x1f5, 0x3ee, 0x1f2, 0x7f4, - 0x7f7, 0x3f1, 0xffe, 0x3ed, 0x1f1, 0x7f5, 0x7fe, 0x3f5, - 0x7fc, -}; - -static const uint8_t bits4[81] = { - 4, 5, 8, 5, 4, 8, 9, 8, 11, 5, 5, 8, 5, 4, 8, 8, - 7, 10, 9, 8, 11, 8, 8, 10, 11, 10, 11, 4, 5, 8, 4, 4, - 8, 8, 8, 10, 4, 4, 8, 4, 4, 7, 8, 7, 9, 8, 8, 10, - 7, 7, 9, 10, 9, 10, 8, 8, 11, 8, 7, 10, 11, 10, 12, 8, - 7, 10, 7, 7, 9, 10, 9, 11, 11, 10, 12, 10, 9, 11, 11, 10, - 11, -}; - -static const uint16_t codes5[81] = { - 0x1fff, 0x0ff7, 0x07f4, 0x07e8, 0x03f1, 0x07ee, 0x07f9, 0x0ff8, - 0x1ffd, 0x0ffd, 0x07f1, 0x03e8, 0x01e8, 0x00f0, 0x01ec, 0x03ee, - 0x07f2, 0x0ffa, 0x0ff4, 0x03ef, 0x01f2, 0x00e8, 0x0070, 0x00ec, - 0x01f0, 0x03ea, 0x07f3, 0x07eb, 0x01eb, 0x00ea, 0x001a, 0x0008, - 0x0019, 0x00ee, 0x01ef, 0x07ed, 0x03f0, 0x00f2, 0x0073, 0x000b, - 0x0000, 0x000a, 0x0071, 0x00f3, 0x07e9, 0x07ef, 0x01ee, 0x00ef, - 0x0018, 0x0009, 0x001b, 0x00eb, 0x01e9, 0x07ec, 0x07f6, 0x03eb, - 0x01f3, 0x00ed, 0x0072, 0x00e9, 0x01f1, 0x03ed, 0x07f7, 0x0ff6, - 0x07f0, 0x03e9, 0x01ed, 0x00f1, 0x01ea, 0x03ec, 0x07f8, 0x0ff9, - 0x1ffc, 0x0ffc, 0x0ff5, 0x07ea, 0x03f3, 0x03f2, 0x07f5, 0x0ffb, - 0x1ffe, -}; - -static const uint8_t bits5[81] = { - 13, 12, 11, 11, 10, 11, 11, 12, 13, 12, 11, 10, 9, 8, 9, 10, - 11, 12, 12, 10, 9, 8, 7, 8, 9, 10, 11, 11, 9, 8, 5, 4, - 5, 8, 9, 11, 10, 8, 7, 4, 1, 4, 7, 8, 11, 11, 9, 8, - 5, 4, 5, 8, 9, 11, 11, 10, 9, 8, 7, 8, 9, 10, 11, 12, - 11, 10, 9, 8, 9, 10, 11, 12, 13, 12, 12, 11, 10, 10, 11, 12, - 13, -}; - -static const uint16_t codes6[81] = { - 0x7fe, 0x3fd, 0x1f1, 0x1eb, 0x1f4, 0x1ea, 0x1f0, 0x3fc, - 0x7fd, 0x3f6, 0x1e5, 0x0ea, 0x06c, 0x071, 0x068, 0x0f0, - 0x1e6, 0x3f7, 0x1f3, 0x0ef, 0x032, 0x027, 0x028, 0x026, - 0x031, 0x0eb, 0x1f7, 0x1e8, 0x06f, 0x02e, 0x008, 0x004, - 0x006, 0x029, 0x06b, 0x1ee, 0x1ef, 0x072, 0x02d, 0x002, - 0x000, 0x003, 0x02f, 0x073, 0x1fa, 0x1e7, 0x06e, 0x02b, - 0x007, 0x001, 0x005, 0x02c, 0x06d, 0x1ec, 0x1f9, 0x0ee, - 0x030, 0x024, 0x02a, 0x025, 0x033, 0x0ec, 0x1f2, 0x3f8, - 0x1e4, 0x0ed, 0x06a, 0x070, 0x069, 0x074, 0x0f1, 0x3fa, - 0x7ff, 0x3f9, 0x1f6, 0x1ed, 0x1f8, 0x1e9, 0x1f5, 0x3fb, - 0x7fc, -}; - -static const uint8_t bits6[81] = { - 11, 10, 9, 9, 9, 9, 9, 10, 11, 10, 9, 8, 7, 7, 7, 8, - 9, 10, 9, 8, 6, 6, 6, 6, 6, 8, 9, 9, 7, 6, 4, 4, - 4, 6, 7, 9, 9, 7, 6, 4, 4, 4, 6, 7, 9, 9, 7, 6, - 4, 4, 4, 6, 7, 9, 9, 8, 6, 6, 6, 6, 6, 8, 9, 10, - 9, 8, 7, 7, 7, 7, 8, 10, 11, 10, 9, 9, 9, 9, 9, 10, - 11, -}; - -static const uint16_t codes7[64] = { - 0x000, 0x005, 0x037, 0x074, 0x0f2, 0x1eb, 0x3ed, 0x7f7, - 0x004, 0x00c, 0x035, 0x071, 0x0ec, 0x0ee, 0x1ee, 0x1f5, - 0x036, 0x034, 0x072, 0x0ea, 0x0f1, 0x1e9, 0x1f3, 0x3f5, - 0x073, 0x070, 0x0eb, 0x0f0, 0x1f1, 0x1f0, 0x3ec, 0x3fa, - 0x0f3, 0x0ed, 0x1e8, 0x1ef, 0x3ef, 0x3f1, 0x3f9, 0x7fb, - 0x1ed, 0x0ef, 0x1ea, 0x1f2, 0x3f3, 0x3f8, 0x7f9, 0x7fc, - 0x3ee, 0x1ec, 0x1f4, 0x3f4, 0x3f7, 0x7f8, 0xffd, 0xffe, - 0x7f6, 0x3f0, 0x3f2, 0x3f6, 0x7fa, 0x7fd, 0xffc, 0xfff, -}; - -static const uint8_t bits7[64] = { - 1, 3, 6, 7, 8, 9, 10, 11, 3, 4, 6, 7, 8, 8, 9, 9, - 6, 6, 7, 8, 8, 9, 9, 10, 7, 7, 8, 8, 9, 9, 10, 10, - 8, 8, 9, 9, 10, 10, 10, 11, 9, 8, 9, 9, 10, 10, 11, 11, - 10, 9, 9, 10, 10, 11, 12, 12, 11, 10, 10, 10, 11, 11, 12, 12, -}; - -static const uint16_t codes8[64] = { - 0x00e, 0x005, 0x010, 0x030, 0x06f, 0x0f1, 0x1fa, 0x3fe, - 0x003, 0x000, 0x004, 0x012, 0x02c, 0x06a, 0x075, 0x0f8, - 0x00f, 0x002, 0x006, 0x014, 0x02e, 0x069, 0x072, 0x0f5, - 0x02f, 0x011, 0x013, 0x02a, 0x032, 0x06c, 0x0ec, 0x0fa, - 0x071, 0x02b, 0x02d, 0x031, 0x06d, 0x070, 0x0f2, 0x1f9, - 0x0ef, 0x068, 0x033, 0x06b, 0x06e, 0x0ee, 0x0f9, 0x3fc, - 0x1f8, 0x074, 0x073, 0x0ed, 0x0f0, 0x0f6, 0x1f6, 0x1fd, - 0x3fd, 0x0f3, 0x0f4, 0x0f7, 0x1f7, 0x1fb, 0x1fc, 0x3ff, -}; - -static const uint8_t bits8[64] = { - 5, 4, 5, 6, 7, 8, 9, 10, 4, 3, 4, 5, 6, 7, 7, 8, - 5, 4, 4, 5, 6, 7, 7, 8, 6, 5, 5, 6, 6, 7, 8, 8, - 7, 6, 6, 6, 7, 7, 8, 9, 8, 7, 6, 7, 7, 8, 8, 10, - 9, 7, 7, 8, 8, 8, 9, 9, 10, 8, 8, 8, 9, 9, 9, 10, -}; - -static const uint16_t codes9[169] = { - 0x0000, 0x0005, 0x0037, 0x00e7, 0x01de, 0x03ce, 0x03d9, 0x07c8, - 0x07cd, 0x0fc8, 0x0fdd, 0x1fe4, 0x1fec, 0x0004, 0x000c, 0x0035, - 0x0072, 0x00ea, 0x00ed, 0x01e2, 0x03d1, 0x03d3, 0x03e0, 0x07d8, - 0x0fcf, 0x0fd5, 0x0036, 0x0034, 0x0071, 0x00e8, 0x00ec, 0x01e1, - 0x03cf, 0x03dd, 0x03db, 0x07d0, 0x0fc7, 0x0fd4, 0x0fe4, 0x00e6, - 0x0070, 0x00e9, 0x01dd, 0x01e3, 0x03d2, 0x03dc, 0x07cc, 0x07ca, - 0x07de, 0x0fd8, 0x0fea, 0x1fdb, 0x01df, 0x00eb, 0x01dc, 0x01e6, - 0x03d5, 0x03de, 0x07cb, 0x07dd, 0x07dc, 0x0fcd, 0x0fe2, 0x0fe7, - 0x1fe1, 0x03d0, 0x01e0, 0x01e4, 0x03d6, 0x07c5, 0x07d1, 0x07db, - 0x0fd2, 0x07e0, 0x0fd9, 0x0feb, 0x1fe3, 0x1fe9, 0x07c4, 0x01e5, - 0x03d7, 0x07c6, 0x07cf, 0x07da, 0x0fcb, 0x0fda, 0x0fe3, 0x0fe9, - 0x1fe6, 0x1ff3, 0x1ff7, 0x07d3, 0x03d8, 0x03e1, 0x07d4, 0x07d9, - 0x0fd3, 0x0fde, 0x1fdd, 0x1fd9, 0x1fe2, 0x1fea, 0x1ff1, 0x1ff6, - 0x07d2, 0x03d4, 0x03da, 0x07c7, 0x07d7, 0x07e2, 0x0fce, 0x0fdb, - 0x1fd8, 0x1fee, 0x3ff0, 0x1ff4, 0x3ff2, 0x07e1, 0x03df, 0x07c9, - 0x07d6, 0x0fca, 0x0fd0, 0x0fe5, 0x0fe6, 0x1feb, 0x1fef, 0x3ff3, - 0x3ff4, 0x3ff5, 0x0fe0, 0x07ce, 0x07d5, 0x0fc6, 0x0fd1, 0x0fe1, - 0x1fe0, 0x1fe8, 0x1ff0, 0x3ff1, 0x3ff8, 0x3ff6, 0x7ffc, 0x0fe8, - 0x07df, 0x0fc9, 0x0fd7, 0x0fdc, 0x1fdc, 0x1fdf, 0x1fed, 0x1ff5, - 0x3ff9, 0x3ffb, 0x7ffd, 0x7ffe, 0x1fe7, 0x0fcc, 0x0fd6, 0x0fdf, - 0x1fde, 0x1fda, 0x1fe5, 0x1ff2, 0x3ffa, 0x3ff7, 0x3ffc, 0x3ffd, - 0x7fff, -}; - -static const uint8_t bits9[169] = { - 1, 3, 6, 8, 9, 10, 10, 11, 11, 12, 12, 13, 13, 3, 4, 6, - 7, 8, 8, 9, 10, 10, 10, 11, 12, 12, 6, 6, 7, 8, 8, 9, - 10, 10, 10, 11, 12, 12, 12, 8, 7, 8, 9, 9, 10, 10, 11, 11, - 11, 12, 12, 13, 9, 8, 9, 9, 10, 10, 11, 11, 11, 12, 12, 12, - 13, 10, 9, 9, 10, 11, 11, 11, 12, 11, 12, 12, 13, 13, 11, 9, - 10, 11, 11, 11, 12, 12, 12, 12, 13, 13, 13, 11, 10, 10, 11, 11, - 12, 12, 13, 13, 13, 13, 13, 13, 11, 10, 10, 11, 11, 11, 12, 12, - 13, 13, 14, 13, 14, 11, 10, 11, 11, 12, 12, 12, 12, 13, 13, 14, - 14, 14, 12, 11, 11, 12, 12, 12, 13, 13, 13, 14, 14, 14, 15, 12, - 11, 12, 12, 12, 13, 13, 13, 13, 14, 14, 15, 15, 13, 12, 12, 12, - 13, 13, 13, 13, 14, 14, 14, 14, 15, -}; - -static const uint16_t codes10[169] = { - 0x022, 0x008, 0x01d, 0x026, 0x05f, 0x0d3, 0x1cf, 0x3d0, - 0x3d7, 0x3ed, 0x7f0, 0x7f6, 0xffd, 0x007, 0x000, 0x001, - 0x009, 0x020, 0x054, 0x060, 0x0d5, 0x0dc, 0x1d4, 0x3cd, - 0x3de, 0x7e7, 0x01c, 0x002, 0x006, 0x00c, 0x01e, 0x028, - 0x05b, 0x0cd, 0x0d9, 0x1ce, 0x1dc, 0x3d9, 0x3f1, 0x025, - 0x00b, 0x00a, 0x00d, 0x024, 0x057, 0x061, 0x0cc, 0x0dd, - 0x1cc, 0x1de, 0x3d3, 0x3e7, 0x05d, 0x021, 0x01f, 0x023, - 0x027, 0x059, 0x064, 0x0d8, 0x0df, 0x1d2, 0x1e2, 0x3dd, - 0x3ee, 0x0d1, 0x055, 0x029, 0x056, 0x058, 0x062, 0x0ce, - 0x0e0, 0x0e2, 0x1da, 0x3d4, 0x3e3, 0x7eb, 0x1c9, 0x05e, - 0x05a, 0x05c, 0x063, 0x0ca, 0x0da, 0x1c7, 0x1ca, 0x1e0, - 0x3db, 0x3e8, 0x7ec, 0x1e3, 0x0d2, 0x0cb, 0x0d0, 0x0d7, - 0x0db, 0x1c6, 0x1d5, 0x1d8, 0x3ca, 0x3da, 0x7ea, 0x7f1, - 0x1e1, 0x0d4, 0x0cf, 0x0d6, 0x0de, 0x0e1, 0x1d0, 0x1d6, - 0x3d1, 0x3d5, 0x3f2, 0x7ee, 0x7fb, 0x3e9, 0x1cd, 0x1c8, - 0x1cb, 0x1d1, 0x1d7, 0x1df, 0x3cf, 0x3e0, 0x3ef, 0x7e6, - 0x7f8, 0xffa, 0x3eb, 0x1dd, 0x1d3, 0x1d9, 0x1db, 0x3d2, - 0x3cc, 0x3dc, 0x3ea, 0x7ed, 0x7f3, 0x7f9, 0xff9, 0x7f2, - 0x3ce, 0x1e4, 0x3cb, 0x3d8, 0x3d6, 0x3e2, 0x3e5, 0x7e8, - 0x7f4, 0x7f5, 0x7f7, 0xffb, 0x7fa, 0x3ec, 0x3df, 0x3e1, - 0x3e4, 0x3e6, 0x3f0, 0x7e9, 0x7ef, 0xff8, 0xffe, 0xffc, - 0xfff, -}; - -static const uint8_t bits10[169] = { - 6, 5, 6, 6, 7, 8, 9, 10, 10, 10, 11, 11, 12, 5, 4, 4, - 5, 6, 7, 7, 8, 8, 9, 10, 10, 11, 6, 4, 5, 5, 6, 6, - 7, 8, 8, 9, 9, 10, 10, 6, 5, 5, 5, 6, 7, 7, 8, 8, - 9, 9, 10, 10, 7, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 10, - 10, 8, 7, 6, 7, 7, 7, 8, 8, 8, 9, 10, 10, 11, 9, 7, - 7, 7, 7, 8, 8, 9, 9, 9, 10, 10, 11, 9, 8, 8, 8, 8, - 8, 9, 9, 9, 10, 10, 11, 11, 9, 8, 8, 8, 8, 8, 9, 9, - 10, 10, 10, 11, 11, 10, 9, 9, 9, 9, 9, 9, 10, 10, 10, 11, - 11, 12, 10, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 12, 11, - 10, 9, 10, 10, 10, 10, 10, 11, 11, 11, 11, 12, 11, 10, 10, 10, - 10, 10, 10, 11, 11, 12, 12, 12, 12, -}; - -static const uint16_t codes11[289] = { - 0x000, 0x006, 0x019, 0x03d, 0x09c, 0x0c6, 0x1a7, 0x390, - 0x3c2, 0x3df, 0x7e6, 0x7f3, 0xffb, 0x7ec, 0xffa, 0xffe, - 0x38e, 0x005, 0x001, 0x008, 0x014, 0x037, 0x042, 0x092, - 0x0af, 0x191, 0x1a5, 0x1b5, 0x39e, 0x3c0, 0x3a2, 0x3cd, - 0x7d6, 0x0ae, 0x017, 0x007, 0x009, 0x018, 0x039, 0x040, - 0x08e, 0x0a3, 0x0b8, 0x199, 0x1ac, 0x1c1, 0x3b1, 0x396, - 0x3be, 0x3ca, 0x09d, 0x03c, 0x015, 0x016, 0x01a, 0x03b, - 0x044, 0x091, 0x0a5, 0x0be, 0x196, 0x1ae, 0x1b9, 0x3a1, - 0x391, 0x3a5, 0x3d5, 0x094, 0x09a, 0x036, 0x038, 0x03a, - 0x041, 0x08c, 0x09b, 0x0b0, 0x0c3, 0x19e, 0x1ab, 0x1bc, - 0x39f, 0x38f, 0x3a9, 0x3cf, 0x093, 0x0bf, 0x03e, 0x03f, - 0x043, 0x045, 0x09e, 0x0a7, 0x0b9, 0x194, 0x1a2, 0x1ba, - 0x1c3, 0x3a6, 0x3a7, 0x3bb, 0x3d4, 0x09f, 0x1a0, 0x08f, - 0x08d, 0x090, 0x098, 0x0a6, 0x0b6, 0x0c4, 0x19f, 0x1af, - 0x1bf, 0x399, 0x3bf, 0x3b4, 0x3c9, 0x3e7, 0x0a8, 0x1b6, - 0x0ab, 0x0a4, 0x0aa, 0x0b2, 0x0c2, 0x0c5, 0x198, 0x1a4, - 0x1b8, 0x38c, 0x3a4, 0x3c4, 0x3c6, 0x3dd, 0x3e8, 0x0ad, - 0x3af, 0x192, 0x0bd, 0x0bc, 0x18e, 0x197, 0x19a, 0x1a3, - 0x1b1, 0x38d, 0x398, 0x3b7, 0x3d3, 0x3d1, 0x3db, 0x7dd, - 0x0b4, 0x3de, 0x1a9, 0x19b, 0x19c, 0x1a1, 0x1aa, 0x1ad, - 0x1b3, 0x38b, 0x3b2, 0x3b8, 0x3ce, 0x3e1, 0x3e0, 0x7d2, - 0x7e5, 0x0b7, 0x7e3, 0x1bb, 0x1a8, 0x1a6, 0x1b0, 0x1b2, - 0x1b7, 0x39b, 0x39a, 0x3ba, 0x3b5, 0x3d6, 0x7d7, 0x3e4, - 0x7d8, 0x7ea, 0x0ba, 0x7e8, 0x3a0, 0x1bd, 0x1b4, 0x38a, - 0x1c4, 0x392, 0x3aa, 0x3b0, 0x3bc, 0x3d7, 0x7d4, 0x7dc, - 0x7db, 0x7d5, 0x7f0, 0x0c1, 0x7fb, 0x3c8, 0x3a3, 0x395, - 0x39d, 0x3ac, 0x3ae, 0x3c5, 0x3d8, 0x3e2, 0x3e6, 0x7e4, - 0x7e7, 0x7e0, 0x7e9, 0x7f7, 0x190, 0x7f2, 0x393, 0x1be, - 0x1c0, 0x394, 0x397, 0x3ad, 0x3c3, 0x3c1, 0x3d2, 0x7da, - 0x7d9, 0x7df, 0x7eb, 0x7f4, 0x7fa, 0x195, 0x7f8, 0x3bd, - 0x39c, 0x3ab, 0x3a8, 0x3b3, 0x3b9, 0x3d0, 0x3e3, 0x3e5, - 0x7e2, 0x7de, 0x7ed, 0x7f1, 0x7f9, 0x7fc, 0x193, 0xffd, - 0x3dc, 0x3b6, 0x3c7, 0x3cc, 0x3cb, 0x3d9, 0x3da, 0x7d3, - 0x7e1, 0x7ee, 0x7ef, 0x7f5, 0x7f6, 0xffc, 0xfff, 0x19d, - 0x1c2, 0x0b5, 0x0a1, 0x096, 0x097, 0x095, 0x099, 0x0a0, - 0x0a2, 0x0ac, 0x0a9, 0x0b1, 0x0b3, 0x0bb, 0x0c0, 0x18f, - 0x004, -}; - -static const uint8_t bits11[289] = { - 4, 5, 6, 7, 8, 8, 9, 10, 10, 10, 11, 11, 12, 11, 12, 12, - 10, 5, 4, 5, 6, 7, 7, 8, 8, 9, 9, 9, 10, 10, 10, 10, - 11, 8, 6, 5, 5, 6, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, - 10, 10, 8, 7, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 10, - 10, 10, 10, 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, - 10, 10, 10, 10, 8, 8, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, - 9, 10, 10, 10, 10, 8, 9, 8, 8, 8, 8, 8, 8, 8, 9, 9, - 9, 10, 10, 10, 10, 10, 8, 9, 8, 8, 8, 8, 8, 8, 9, 9, - 9, 10, 10, 10, 10, 10, 10, 8, 10, 9, 8, 8, 9, 9, 9, 9, - 9, 10, 10, 10, 10, 10, 10, 11, 8, 10, 9, 9, 9, 9, 9, 9, - 9, 10, 10, 10, 10, 10, 10, 11, 11, 8, 11, 9, 9, 9, 9, 9, - 9, 10, 10, 10, 10, 10, 11, 10, 11, 11, 8, 11, 10, 9, 9, 10, - 9, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 8, 11, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 9, 11, 10, 9, - 9, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 9, 11, 10, - 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 9, 12, - 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 12, 12, 9, - 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, - 5, -}; - -const uint16_t * const ff_aac_spectral_codes[11] = { - codes1, codes2, codes3, codes4, codes5, codes6, codes7, codes8, - codes9, codes10, codes11, -}; - -const uint8_t * const ff_aac_spectral_bits[11] = { - bits1, bits2, bits3, bits4, bits5, bits6, bits7, bits8, - bits9, bits10, bits11, -}; - -const uint16_t ff_aac_spectral_sizes[11] = { - 81, 81, 81, 81, 81, 81, 64, 64, 169, 169, 289, -}; - -/* NOTE: - * 64.0f is a special value indicating the existence of an escape code in the - * bitstream. - */ -static const DECLARE_ALIGNED(16, float, codebook_vector0)[324] = { - -1.0000000, -1.0000000, -1.0000000, -1.0000000, - -1.0000000, -1.0000000, -1.0000000, 0.0000000, - -1.0000000, -1.0000000, -1.0000000, 1.0000000, - -1.0000000, -1.0000000, 0.0000000, -1.0000000, - -1.0000000, -1.0000000, 0.0000000, 0.0000000, - -1.0000000, -1.0000000, 0.0000000, 1.0000000, - -1.0000000, -1.0000000, 1.0000000, -1.0000000, - -1.0000000, -1.0000000, 1.0000000, 0.0000000, - -1.0000000, -1.0000000, 1.0000000, 1.0000000, - -1.0000000, 0.0000000, -1.0000000, -1.0000000, - -1.0000000, 0.0000000, -1.0000000, 0.0000000, - -1.0000000, 0.0000000, -1.0000000, 1.0000000, - -1.0000000, 0.0000000, 0.0000000, -1.0000000, - -1.0000000, 0.0000000, 0.0000000, 0.0000000, - -1.0000000, 0.0000000, 0.0000000, 1.0000000, - -1.0000000, 0.0000000, 1.0000000, -1.0000000, - -1.0000000, 0.0000000, 1.0000000, 0.0000000, - -1.0000000, 0.0000000, 1.0000000, 1.0000000, - -1.0000000, 1.0000000, -1.0000000, -1.0000000, - -1.0000000, 1.0000000, -1.0000000, 0.0000000, - -1.0000000, 1.0000000, -1.0000000, 1.0000000, - -1.0000000, 1.0000000, 0.0000000, -1.0000000, - -1.0000000, 1.0000000, 0.0000000, 0.0000000, - -1.0000000, 1.0000000, 0.0000000, 1.0000000, - -1.0000000, 1.0000000, 1.0000000, -1.0000000, - -1.0000000, 1.0000000, 1.0000000, 0.0000000, - -1.0000000, 1.0000000, 1.0000000, 1.0000000, - 0.0000000, -1.0000000, -1.0000000, -1.0000000, - 0.0000000, -1.0000000, -1.0000000, 0.0000000, - 0.0000000, -1.0000000, -1.0000000, 1.0000000, - 0.0000000, -1.0000000, 0.0000000, -1.0000000, - 0.0000000, -1.0000000, 0.0000000, 0.0000000, - 0.0000000, -1.0000000, 0.0000000, 1.0000000, - 0.0000000, -1.0000000, 1.0000000, -1.0000000, - 0.0000000, -1.0000000, 1.0000000, 0.0000000, - 0.0000000, -1.0000000, 1.0000000, 1.0000000, - 0.0000000, 0.0000000, -1.0000000, -1.0000000, - 0.0000000, 0.0000000, -1.0000000, 0.0000000, - 0.0000000, 0.0000000, -1.0000000, 1.0000000, - 0.0000000, 0.0000000, 0.0000000, -1.0000000, - 0.0000000, 0.0000000, 0.0000000, 0.0000000, - 0.0000000, 0.0000000, 0.0000000, 1.0000000, - 0.0000000, 0.0000000, 1.0000000, -1.0000000, - 0.0000000, 0.0000000, 1.0000000, 0.0000000, - 0.0000000, 0.0000000, 1.0000000, 1.0000000, - 0.0000000, 1.0000000, -1.0000000, -1.0000000, - 0.0000000, 1.0000000, -1.0000000, 0.0000000, - 0.0000000, 1.0000000, -1.0000000, 1.0000000, - 0.0000000, 1.0000000, 0.0000000, -1.0000000, - 0.0000000, 1.0000000, 0.0000000, 0.0000000, - 0.0000000, 1.0000000, 0.0000000, 1.0000000, - 0.0000000, 1.0000000, 1.0000000, -1.0000000, - 0.0000000, 1.0000000, 1.0000000, 0.0000000, - 0.0000000, 1.0000000, 1.0000000, 1.0000000, - 1.0000000, -1.0000000, -1.0000000, -1.0000000, - 1.0000000, -1.0000000, -1.0000000, 0.0000000, - 1.0000000, -1.0000000, -1.0000000, 1.0000000, - 1.0000000, -1.0000000, 0.0000000, -1.0000000, - 1.0000000, -1.0000000, 0.0000000, 0.0000000, - 1.0000000, -1.0000000, 0.0000000, 1.0000000, - 1.0000000, -1.0000000, 1.0000000, -1.0000000, - 1.0000000, -1.0000000, 1.0000000, 0.0000000, - 1.0000000, -1.0000000, 1.0000000, 1.0000000, - 1.0000000, 0.0000000, -1.0000000, -1.0000000, - 1.0000000, 0.0000000, -1.0000000, 0.0000000, - 1.0000000, 0.0000000, -1.0000000, 1.0000000, - 1.0000000, 0.0000000, 0.0000000, -1.0000000, - 1.0000000, 0.0000000, 0.0000000, 0.0000000, - 1.0000000, 0.0000000, 0.0000000, 1.0000000, - 1.0000000, 0.0000000, 1.0000000, -1.0000000, - 1.0000000, 0.0000000, 1.0000000, 0.0000000, - 1.0000000, 0.0000000, 1.0000000, 1.0000000, - 1.0000000, 1.0000000, -1.0000000, -1.0000000, - 1.0000000, 1.0000000, -1.0000000, 0.0000000, - 1.0000000, 1.0000000, -1.0000000, 1.0000000, - 1.0000000, 1.0000000, 0.0000000, -1.0000000, - 1.0000000, 1.0000000, 0.0000000, 0.0000000, - 1.0000000, 1.0000000, 0.0000000, 1.0000000, - 1.0000000, 1.0000000, 1.0000000, -1.0000000, - 1.0000000, 1.0000000, 1.0000000, 0.0000000, - 1.0000000, 1.0000000, 1.0000000, 1.0000000, -}; - -static const DECLARE_ALIGNED(16, float, codebook_vector2)[324] = { - 0.0000000, 0.0000000, 0.0000000, 0.0000000, - 0.0000000, 0.0000000, 0.0000000, 1.0000000, - 0.0000000, 0.0000000, 0.0000000, 2.5198421, - 0.0000000, 0.0000000, 1.0000000, 0.0000000, - 0.0000000, 0.0000000, 1.0000000, 1.0000000, - 0.0000000, 0.0000000, 1.0000000, 2.5198421, - 0.0000000, 0.0000000, 2.5198421, 0.0000000, - 0.0000000, 0.0000000, 2.5198421, 1.0000000, - 0.0000000, 0.0000000, 2.5198421, 2.5198421, - 0.0000000, 1.0000000, 0.0000000, 0.0000000, - 0.0000000, 1.0000000, 0.0000000, 1.0000000, - 0.0000000, 1.0000000, 0.0000000, 2.5198421, - 0.0000000, 1.0000000, 1.0000000, 0.0000000, - 0.0000000, 1.0000000, 1.0000000, 1.0000000, - 0.0000000, 1.0000000, 1.0000000, 2.5198421, - 0.0000000, 1.0000000, 2.5198421, 0.0000000, - 0.0000000, 1.0000000, 2.5198421, 1.0000000, - 0.0000000, 1.0000000, 2.5198421, 2.5198421, - 0.0000000, 2.5198421, 0.0000000, 0.0000000, - 0.0000000, 2.5198421, 0.0000000, 1.0000000, - 0.0000000, 2.5198421, 0.0000000, 2.5198421, - 0.0000000, 2.5198421, 1.0000000, 0.0000000, - 0.0000000, 2.5198421, 1.0000000, 1.0000000, - 0.0000000, 2.5198421, 1.0000000, 2.5198421, - 0.0000000, 2.5198421, 2.5198421, 0.0000000, - 0.0000000, 2.5198421, 2.5198421, 1.0000000, - 0.0000000, 2.5198421, 2.5198421, 2.5198421, - 1.0000000, 0.0000000, 0.0000000, 0.0000000, - 1.0000000, 0.0000000, 0.0000000, 1.0000000, - 1.0000000, 0.0000000, 0.0000000, 2.5198421, - 1.0000000, 0.0000000, 1.0000000, 0.0000000, - 1.0000000, 0.0000000, 1.0000000, 1.0000000, - 1.0000000, 0.0000000, 1.0000000, 2.5198421, - 1.0000000, 0.0000000, 2.5198421, 0.0000000, - 1.0000000, 0.0000000, 2.5198421, 1.0000000, - 1.0000000, 0.0000000, 2.5198421, 2.5198421, - 1.0000000, 1.0000000, 0.0000000, 0.0000000, - 1.0000000, 1.0000000, 0.0000000, 1.0000000, - 1.0000000, 1.0000000, 0.0000000, 2.5198421, - 1.0000000, 1.0000000, 1.0000000, 0.0000000, - 1.0000000, 1.0000000, 1.0000000, 1.0000000, - 1.0000000, 1.0000000, 1.0000000, 2.5198421, - 1.0000000, 1.0000000, 2.5198421, 0.0000000, - 1.0000000, 1.0000000, 2.5198421, 1.0000000, - 1.0000000, 1.0000000, 2.5198421, 2.5198421, - 1.0000000, 2.5198421, 0.0000000, 0.0000000, - 1.0000000, 2.5198421, 0.0000000, 1.0000000, - 1.0000000, 2.5198421, 0.0000000, 2.5198421, - 1.0000000, 2.5198421, 1.0000000, 0.0000000, - 1.0000000, 2.5198421, 1.0000000, 1.0000000, - 1.0000000, 2.5198421, 1.0000000, 2.5198421, - 1.0000000, 2.5198421, 2.5198421, 0.0000000, - 1.0000000, 2.5198421, 2.5198421, 1.0000000, - 1.0000000, 2.5198421, 2.5198421, 2.5198421, - 2.5198421, 0.0000000, 0.0000000, 0.0000000, - 2.5198421, 0.0000000, 0.0000000, 1.0000000, - 2.5198421, 0.0000000, 0.0000000, 2.5198421, - 2.5198421, 0.0000000, 1.0000000, 0.0000000, - 2.5198421, 0.0000000, 1.0000000, 1.0000000, - 2.5198421, 0.0000000, 1.0000000, 2.5198421, - 2.5198421, 0.0000000, 2.5198421, 0.0000000, - 2.5198421, 0.0000000, 2.5198421, 1.0000000, - 2.5198421, 0.0000000, 2.5198421, 2.5198421, - 2.5198421, 1.0000000, 0.0000000, 0.0000000, - 2.5198421, 1.0000000, 0.0000000, 1.0000000, - 2.5198421, 1.0000000, 0.0000000, 2.5198421, - 2.5198421, 1.0000000, 1.0000000, 0.0000000, - 2.5198421, 1.0000000, 1.0000000, 1.0000000, - 2.5198421, 1.0000000, 1.0000000, 2.5198421, - 2.5198421, 1.0000000, 2.5198421, 0.0000000, - 2.5198421, 1.0000000, 2.5198421, 1.0000000, - 2.5198421, 1.0000000, 2.5198421, 2.5198421, - 2.5198421, 2.5198421, 0.0000000, 0.0000000, - 2.5198421, 2.5198421, 0.0000000, 1.0000000, - 2.5198421, 2.5198421, 0.0000000, 2.5198421, - 2.5198421, 2.5198421, 1.0000000, 0.0000000, - 2.5198421, 2.5198421, 1.0000000, 1.0000000, - 2.5198421, 2.5198421, 1.0000000, 2.5198421, - 2.5198421, 2.5198421, 2.5198421, 0.0000000, - 2.5198421, 2.5198421, 2.5198421, 1.0000000, - 2.5198421, 2.5198421, 2.5198421, 2.5198421, -}; - -static const DECLARE_ALIGNED(16, float, codebook_vector4)[162] = { - -6.3496042, -6.3496042, -6.3496042, -4.3267487, - -6.3496042, -2.5198421, -6.3496042, -1.0000000, - -6.3496042, 0.0000000, -6.3496042, 1.0000000, - -6.3496042, 2.5198421, -6.3496042, 4.3267487, - -6.3496042, 6.3496042, -4.3267487, -6.3496042, - -4.3267487, -4.3267487, -4.3267487, -2.5198421, - -4.3267487, -1.0000000, -4.3267487, 0.0000000, - -4.3267487, 1.0000000, -4.3267487, 2.5198421, - -4.3267487, 4.3267487, -4.3267487, 6.3496042, - -2.5198421, -6.3496042, -2.5198421, -4.3267487, - -2.5198421, -2.5198421, -2.5198421, -1.0000000, - -2.5198421, 0.0000000, -2.5198421, 1.0000000, - -2.5198421, 2.5198421, -2.5198421, 4.3267487, - -2.5198421, 6.3496042, -1.0000000, -6.3496042, - -1.0000000, -4.3267487, -1.0000000, -2.5198421, - -1.0000000, -1.0000000, -1.0000000, 0.0000000, - -1.0000000, 1.0000000, -1.0000000, 2.5198421, - -1.0000000, 4.3267487, -1.0000000, 6.3496042, - 0.0000000, -6.3496042, 0.0000000, -4.3267487, - 0.0000000, -2.5198421, 0.0000000, -1.0000000, - 0.0000000, 0.0000000, 0.0000000, 1.0000000, - 0.0000000, 2.5198421, 0.0000000, 4.3267487, - 0.0000000, 6.3496042, 1.0000000, -6.3496042, - 1.0000000, -4.3267487, 1.0000000, -2.5198421, - 1.0000000, -1.0000000, 1.0000000, 0.0000000, - 1.0000000, 1.0000000, 1.0000000, 2.5198421, - 1.0000000, 4.3267487, 1.0000000, 6.3496042, - 2.5198421, -6.3496042, 2.5198421, -4.3267487, - 2.5198421, -2.5198421, 2.5198421, -1.0000000, - 2.5198421, 0.0000000, 2.5198421, 1.0000000, - 2.5198421, 2.5198421, 2.5198421, 4.3267487, - 2.5198421, 6.3496042, 4.3267487, -6.3496042, - 4.3267487, -4.3267487, 4.3267487, -2.5198421, - 4.3267487, -1.0000000, 4.3267487, 0.0000000, - 4.3267487, 1.0000000, 4.3267487, 2.5198421, - 4.3267487, 4.3267487, 4.3267487, 6.3496042, - 6.3496042, -6.3496042, 6.3496042, -4.3267487, - 6.3496042, -2.5198421, 6.3496042, -1.0000000, - 6.3496042, 0.0000000, 6.3496042, 1.0000000, - 6.3496042, 2.5198421, 6.3496042, 4.3267487, - 6.3496042, 6.3496042, -}; - -static const DECLARE_ALIGNED(16, float, codebook_vector6)[128] = { - 0.0000000, 0.0000000, 0.0000000, 1.0000000, - 0.0000000, 2.5198421, 0.0000000, 4.3267487, - 0.0000000, 6.3496042, 0.0000000, 8.5498797, - 0.0000000, 10.9027236, 0.0000000, 13.3905183, - 1.0000000, 0.0000000, 1.0000000, 1.0000000, - 1.0000000, 2.5198421, 1.0000000, 4.3267487, - 1.0000000, 6.3496042, 1.0000000, 8.5498797, - 1.0000000, 10.9027236, 1.0000000, 13.3905183, - 2.5198421, 0.0000000, 2.5198421, 1.0000000, - 2.5198421, 2.5198421, 2.5198421, 4.3267487, - 2.5198421, 6.3496042, 2.5198421, 8.5498797, - 2.5198421, 10.9027236, 2.5198421, 13.3905183, - 4.3267487, 0.0000000, 4.3267487, 1.0000000, - 4.3267487, 2.5198421, 4.3267487, 4.3267487, - 4.3267487, 6.3496042, 4.3267487, 8.5498797, - 4.3267487, 10.9027236, 4.3267487, 13.3905183, - 6.3496042, 0.0000000, 6.3496042, 1.0000000, - 6.3496042, 2.5198421, 6.3496042, 4.3267487, - 6.3496042, 6.3496042, 6.3496042, 8.5498797, - 6.3496042, 10.9027236, 6.3496042, 13.3905183, - 8.5498797, 0.0000000, 8.5498797, 1.0000000, - 8.5498797, 2.5198421, 8.5498797, 4.3267487, - 8.5498797, 6.3496042, 8.5498797, 8.5498797, - 8.5498797, 10.9027236, 8.5498797, 13.3905183, - 10.9027236, 0.0000000, 10.9027236, 1.0000000, - 10.9027236, 2.5198421, 10.9027236, 4.3267487, - 10.9027236, 6.3496042, 10.9027236, 8.5498797, - 10.9027236, 10.9027236, 10.9027236, 13.3905183, - 13.3905183, 0.0000000, 13.3905183, 1.0000000, - 13.3905183, 2.5198421, 13.3905183, 4.3267487, - 13.3905183, 6.3496042, 13.3905183, 8.5498797, - 13.3905183, 10.9027236, 13.3905183, 13.3905183, -}; - -static const DECLARE_ALIGNED(16, float, codebook_vector8)[338] = { - 0.0000000, 0.0000000, 0.0000000, 1.0000000, - 0.0000000, 2.5198421, 0.0000000, 4.3267487, - 0.0000000, 6.3496042, 0.0000000, 8.5498797, - 0.0000000, 10.9027236, 0.0000000, 13.3905183, - 0.0000000, 16.0000000, 0.0000000, 18.7207544, - 0.0000000, 21.5443469, 0.0000000, 24.4637810, - 0.0000000, 27.4731418, 1.0000000, 0.0000000, - 1.0000000, 1.0000000, 1.0000000, 2.5198421, - 1.0000000, 4.3267487, 1.0000000, 6.3496042, - 1.0000000, 8.5498797, 1.0000000, 10.9027236, - 1.0000000, 13.3905183, 1.0000000, 16.0000000, - 1.0000000, 18.7207544, 1.0000000, 21.5443469, - 1.0000000, 24.4637810, 1.0000000, 27.4731418, - 2.5198421, 0.0000000, 2.5198421, 1.0000000, - 2.5198421, 2.5198421, 2.5198421, 4.3267487, - 2.5198421, 6.3496042, 2.5198421, 8.5498797, - 2.5198421, 10.9027236, 2.5198421, 13.3905183, - 2.5198421, 16.0000000, 2.5198421, 18.7207544, - 2.5198421, 21.5443469, 2.5198421, 24.4637810, - 2.5198421, 27.4731418, 4.3267487, 0.0000000, - 4.3267487, 1.0000000, 4.3267487, 2.5198421, - 4.3267487, 4.3267487, 4.3267487, 6.3496042, - 4.3267487, 8.5498797, 4.3267487, 10.9027236, - 4.3267487, 13.3905183, 4.3267487, 16.0000000, - 4.3267487, 18.7207544, 4.3267487, 21.5443469, - 4.3267487, 24.4637810, 4.3267487, 27.4731418, - 6.3496042, 0.0000000, 6.3496042, 1.0000000, - 6.3496042, 2.5198421, 6.3496042, 4.3267487, - 6.3496042, 6.3496042, 6.3496042, 8.5498797, - 6.3496042, 10.9027236, 6.3496042, 13.3905183, - 6.3496042, 16.0000000, 6.3496042, 18.7207544, - 6.3496042, 21.5443469, 6.3496042, 24.4637810, - 6.3496042, 27.4731418, 8.5498797, 0.0000000, - 8.5498797, 1.0000000, 8.5498797, 2.5198421, - 8.5498797, 4.3267487, 8.5498797, 6.3496042, - 8.5498797, 8.5498797, 8.5498797, 10.9027236, - 8.5498797, 13.3905183, 8.5498797, 16.0000000, - 8.5498797, 18.7207544, 8.5498797, 21.5443469, - 8.5498797, 24.4637810, 8.5498797, 27.4731418, - 10.9027236, 0.0000000, 10.9027236, 1.0000000, - 10.9027236, 2.5198421, 10.9027236, 4.3267487, - 10.9027236, 6.3496042, 10.9027236, 8.5498797, - 10.9027236, 10.9027236, 10.9027236, 13.3905183, - 10.9027236, 16.0000000, 10.9027236, 18.7207544, - 10.9027236, 21.5443469, 10.9027236, 24.4637810, - 10.9027236, 27.4731418, 13.3905183, 0.0000000, - 13.3905183, 1.0000000, 13.3905183, 2.5198421, - 13.3905183, 4.3267487, 13.3905183, 6.3496042, - 13.3905183, 8.5498797, 13.3905183, 10.9027236, - 13.3905183, 13.3905183, 13.3905183, 16.0000000, - 13.3905183, 18.7207544, 13.3905183, 21.5443469, - 13.3905183, 24.4637810, 13.3905183, 27.4731418, - 16.0000000, 0.0000000, 16.0000000, 1.0000000, - 16.0000000, 2.5198421, 16.0000000, 4.3267487, - 16.0000000, 6.3496042, 16.0000000, 8.5498797, - 16.0000000, 10.9027236, 16.0000000, 13.3905183, - 16.0000000, 16.0000000, 16.0000000, 18.7207544, - 16.0000000, 21.5443469, 16.0000000, 24.4637810, - 16.0000000, 27.4731418, 18.7207544, 0.0000000, - 18.7207544, 1.0000000, 18.7207544, 2.5198421, - 18.7207544, 4.3267487, 18.7207544, 6.3496042, - 18.7207544, 8.5498797, 18.7207544, 10.9027236, - 18.7207544, 13.3905183, 18.7207544, 16.0000000, - 18.7207544, 18.7207544, 18.7207544, 21.5443469, - 18.7207544, 24.4637810, 18.7207544, 27.4731418, - 21.5443469, 0.0000000, 21.5443469, 1.0000000, - 21.5443469, 2.5198421, 21.5443469, 4.3267487, - 21.5443469, 6.3496042, 21.5443469, 8.5498797, - 21.5443469, 10.9027236, 21.5443469, 13.3905183, - 21.5443469, 16.0000000, 21.5443469, 18.7207544, - 21.5443469, 21.5443469, 21.5443469, 24.4637810, - 21.5443469, 27.4731418, 24.4637810, 0.0000000, - 24.4637810, 1.0000000, 24.4637810, 2.5198421, - 24.4637810, 4.3267487, 24.4637810, 6.3496042, - 24.4637810, 8.5498797, 24.4637810, 10.9027236, - 24.4637810, 13.3905183, 24.4637810, 16.0000000, - 24.4637810, 18.7207544, 24.4637810, 21.5443469, - 24.4637810, 24.4637810, 24.4637810, 27.4731418, - 27.4731418, 0.0000000, 27.4731418, 1.0000000, - 27.4731418, 2.5198421, 27.4731418, 4.3267487, - 27.4731418, 6.3496042, 27.4731418, 8.5498797, - 27.4731418, 10.9027236, 27.4731418, 13.3905183, - 27.4731418, 16.0000000, 27.4731418, 18.7207544, - 27.4731418, 21.5443469, 27.4731418, 24.4637810, - 27.4731418, 27.4731418, -}; - -static const DECLARE_ALIGNED(16, float, codebook_vector10)[578] = { - 0.0000000, 0.0000000, 0.0000000, 1.0000000, - 0.0000000, 2.5198421, 0.0000000, 4.3267487, - 0.0000000, 6.3496042, 0.0000000, 8.5498797, - 0.0000000, 10.9027236, 0.0000000, 13.3905183, - 0.0000000, 16.0000000, 0.0000000, 18.7207544, - 0.0000000, 21.5443469, 0.0000000, 24.4637810, - 0.0000000, 27.4731418, 0.0000000, 30.5673509, - 0.0000000, 33.7419917, 0.0000000, 36.9931811, - 0.0000000, 64.0f, 1.0000000, 0.0000000, - 1.0000000, 1.0000000, 1.0000000, 2.5198421, - 1.0000000, 4.3267487, 1.0000000, 6.3496042, - 1.0000000, 8.5498797, 1.0000000, 10.9027236, - 1.0000000, 13.3905183, 1.0000000, 16.0000000, - 1.0000000, 18.7207544, 1.0000000, 21.5443469, - 1.0000000, 24.4637810, 1.0000000, 27.4731418, - 1.0000000, 30.5673509, 1.0000000, 33.7419917, - 1.0000000, 36.9931811, 1.0000000, 64.0f, - 2.5198421, 0.0000000, 2.5198421, 1.0000000, - 2.5198421, 2.5198421, 2.5198421, 4.3267487, - 2.5198421, 6.3496042, 2.5198421, 8.5498797, - 2.5198421, 10.9027236, 2.5198421, 13.3905183, - 2.5198421, 16.0000000, 2.5198421, 18.7207544, - 2.5198421, 21.5443469, 2.5198421, 24.4637810, - 2.5198421, 27.4731418, 2.5198421, 30.5673509, - 2.5198421, 33.7419917, 2.5198421, 36.9931811, - 2.5198421, 64.0f, 4.3267487, 0.0000000, - 4.3267487, 1.0000000, 4.3267487, 2.5198421, - 4.3267487, 4.3267487, 4.3267487, 6.3496042, - 4.3267487, 8.5498797, 4.3267487, 10.9027236, - 4.3267487, 13.3905183, 4.3267487, 16.0000000, - 4.3267487, 18.7207544, 4.3267487, 21.5443469, - 4.3267487, 24.4637810, 4.3267487, 27.4731418, - 4.3267487, 30.5673509, 4.3267487, 33.7419917, - 4.3267487, 36.9931811, 4.3267487, 64.0f, - 6.3496042, 0.0000000, 6.3496042, 1.0000000, - 6.3496042, 2.5198421, 6.3496042, 4.3267487, - 6.3496042, 6.3496042, 6.3496042, 8.5498797, - 6.3496042, 10.9027236, 6.3496042, 13.3905183, - 6.3496042, 16.0000000, 6.3496042, 18.7207544, - 6.3496042, 21.5443469, 6.3496042, 24.4637810, - 6.3496042, 27.4731418, 6.3496042, 30.5673509, - 6.3496042, 33.7419917, 6.3496042, 36.9931811, - 6.3496042, 64.0f, 8.5498797, 0.0000000, - 8.5498797, 1.0000000, 8.5498797, 2.5198421, - 8.5498797, 4.3267487, 8.5498797, 6.3496042, - 8.5498797, 8.5498797, 8.5498797, 10.9027236, - 8.5498797, 13.3905183, 8.5498797, 16.0000000, - 8.5498797, 18.7207544, 8.5498797, 21.5443469, - 8.5498797, 24.4637810, 8.5498797, 27.4731418, - 8.5498797, 30.5673509, 8.5498797, 33.7419917, - 8.5498797, 36.9931811, 8.5498797, 64.0f, - 10.9027236, 0.0000000, 10.9027236, 1.0000000, - 10.9027236, 2.5198421, 10.9027236, 4.3267487, - 10.9027236, 6.3496042, 10.9027236, 8.5498797, - 10.9027236, 10.9027236, 10.9027236, 13.3905183, - 10.9027236, 16.0000000, 10.9027236, 18.7207544, - 10.9027236, 21.5443469, 10.9027236, 24.4637810, - 10.9027236, 27.4731418, 10.9027236, 30.5673509, - 10.9027236, 33.7419917, 10.9027236, 36.9931811, - 10.9027236, 64.0f, 13.3905183, 0.0000000, - 13.3905183, 1.0000000, 13.3905183, 2.5198421, - 13.3905183, 4.3267487, 13.3905183, 6.3496042, - 13.3905183, 8.5498797, 13.3905183, 10.9027236, - 13.3905183, 13.3905183, 13.3905183, 16.0000000, - 13.3905183, 18.7207544, 13.3905183, 21.5443469, - 13.3905183, 24.4637810, 13.3905183, 27.4731418, - 13.3905183, 30.5673509, 13.3905183, 33.7419917, - 13.3905183, 36.9931811, 13.3905183, 64.0f, - 16.0000000, 0.0000000, 16.0000000, 1.0000000, - 16.0000000, 2.5198421, 16.0000000, 4.3267487, - 16.0000000, 6.3496042, 16.0000000, 8.5498797, - 16.0000000, 10.9027236, 16.0000000, 13.3905183, - 16.0000000, 16.0000000, 16.0000000, 18.7207544, - 16.0000000, 21.5443469, 16.0000000, 24.4637810, - 16.0000000, 27.4731418, 16.0000000, 30.5673509, - 16.0000000, 33.7419917, 16.0000000, 36.9931811, - 16.0000000, 64.0f, 18.7207544, 0.0000000, - 18.7207544, 1.0000000, 18.7207544, 2.5198421, - 18.7207544, 4.3267487, 18.7207544, 6.3496042, - 18.7207544, 8.5498797, 18.7207544, 10.9027236, - 18.7207544, 13.3905183, 18.7207544, 16.0000000, - 18.7207544, 18.7207544, 18.7207544, 21.5443469, - 18.7207544, 24.4637810, 18.7207544, 27.4731418, - 18.7207544, 30.5673509, 18.7207544, 33.7419917, - 18.7207544, 36.9931811, 18.7207544, 64.0f, - 21.5443469, 0.0000000, 21.5443469, 1.0000000, - 21.5443469, 2.5198421, 21.5443469, 4.3267487, - 21.5443469, 6.3496042, 21.5443469, 8.5498797, - 21.5443469, 10.9027236, 21.5443469, 13.3905183, - 21.5443469, 16.0000000, 21.5443469, 18.7207544, - 21.5443469, 21.5443469, 21.5443469, 24.4637810, - 21.5443469, 27.4731418, 21.5443469, 30.5673509, - 21.5443469, 33.7419917, 21.5443469, 36.9931811, - 21.5443469, 64.0f, 24.4637810, 0.0000000, - 24.4637810, 1.0000000, 24.4637810, 2.5198421, - 24.4637810, 4.3267487, 24.4637810, 6.3496042, - 24.4637810, 8.5498797, 24.4637810, 10.9027236, - 24.4637810, 13.3905183, 24.4637810, 16.0000000, - 24.4637810, 18.7207544, 24.4637810, 21.5443469, - 24.4637810, 24.4637810, 24.4637810, 27.4731418, - 24.4637810, 30.5673509, 24.4637810, 33.7419917, - 24.4637810, 36.9931811, 24.4637810, 64.0f, - 27.4731418, 0.0000000, 27.4731418, 1.0000000, - 27.4731418, 2.5198421, 27.4731418, 4.3267487, - 27.4731418, 6.3496042, 27.4731418, 8.5498797, - 27.4731418, 10.9027236, 27.4731418, 13.3905183, - 27.4731418, 16.0000000, 27.4731418, 18.7207544, - 27.4731418, 21.5443469, 27.4731418, 24.4637810, - 27.4731418, 27.4731418, 27.4731418, 30.5673509, - 27.4731418, 33.7419917, 27.4731418, 36.9931811, - 27.4731418, 64.0f, 30.5673509, 0.0000000, - 30.5673509, 1.0000000, 30.5673509, 2.5198421, - 30.5673509, 4.3267487, 30.5673509, 6.3496042, - 30.5673509, 8.5498797, 30.5673509, 10.9027236, - 30.5673509, 13.3905183, 30.5673509, 16.0000000, - 30.5673509, 18.7207544, 30.5673509, 21.5443469, - 30.5673509, 24.4637810, 30.5673509, 27.4731418, - 30.5673509, 30.5673509, 30.5673509, 33.7419917, - 30.5673509, 36.9931811, 30.5673509, 64.0f, - 33.7419917, 0.0000000, 33.7419917, 1.0000000, - 33.7419917, 2.5198421, 33.7419917, 4.3267487, - 33.7419917, 6.3496042, 33.7419917, 8.5498797, - 33.7419917, 10.9027236, 33.7419917, 13.3905183, - 33.7419917, 16.0000000, 33.7419917, 18.7207544, - 33.7419917, 21.5443469, 33.7419917, 24.4637810, - 33.7419917, 27.4731418, 33.7419917, 30.5673509, - 33.7419917, 33.7419917, 33.7419917, 36.9931811, - 33.7419917, 64.0f, 36.9931811, 0.0000000, - 36.9931811, 1.0000000, 36.9931811, 2.5198421, - 36.9931811, 4.3267487, 36.9931811, 6.3496042, - 36.9931811, 8.5498797, 36.9931811, 10.9027236, - 36.9931811, 13.3905183, 36.9931811, 16.0000000, - 36.9931811, 18.7207544, 36.9931811, 21.5443469, - 36.9931811, 24.4637810, 36.9931811, 27.4731418, - 36.9931811, 30.5673509, 36.9931811, 33.7419917, - 36.9931811, 36.9931811, 36.9931811, 64.0f, - 64.0f, 0.0000000, 64.0f, 1.0000000, - 64.0f, 2.5198421, 64.0f, 4.3267487, - 64.0f, 6.3496042, 64.0f, 8.5498797, - 64.0f, 10.9027236, 64.0f, 13.3905183, - 64.0f, 16.0000000, 64.0f, 18.7207544, - 64.0f, 21.5443469, 64.0f, 24.4637810, - 64.0f, 27.4731418, 64.0f, 30.5673509, - 64.0f, 33.7419917, 64.0f, 36.9931811, - 64.0f, 64.0f, -}; - -const float * const ff_aac_codebook_vectors[] = { - codebook_vector0, codebook_vector0, codebook_vector2, - codebook_vector2, codebook_vector4, codebook_vector4, - codebook_vector6, codebook_vector6, codebook_vector8, - codebook_vector8, codebook_vector10, -}; - -static const float codebook_vector0_vals[] = { - -1.0000000, 0.0000000, 1.0000000 -}; - -/* - * bits 0:1, 2:3, 4:5, 6:7 index into _vals array - * 8:11 number of non-zero values - * 12:15 bit mask of non-zero values - */ -static const uint16_t codebook_vector02_idx[] = { - 0x0000, 0x8140, 0x8180, 0x4110, 0xc250, 0xc290, 0x4120, 0xc260, 0xc2a0, - 0x2104, 0xa244, 0xa284, 0x6214, 0xe354, 0xe394, 0x6224, 0xe364, 0xe3a4, - 0x2108, 0xa248, 0xa288, 0x6218, 0xe358, 0xe398, 0x6228, 0xe368, 0xe3a8, - 0x1101, 0x9241, 0x9281, 0x5211, 0xd351, 0xd391, 0x5221, 0xd361, 0xd3a1, - 0x3205, 0xb345, 0xb385, 0x7315, 0xf455, 0xf495, 0x7325, 0xf465, 0xf4a5, - 0x3209, 0xb349, 0xb389, 0x7319, 0xf459, 0xf499, 0x7329, 0xf469, 0xf4a9, - 0x1102, 0x9242, 0x9282, 0x5212, 0xd352, 0xd392, 0x5222, 0xd362, 0xd3a2, - 0x3206, 0xb346, 0xb386, 0x7316, 0xf456, 0xf496, 0x7326, 0xf466, 0xf4a6, - 0x320a, 0xb34a, 0xb38a, 0x731a, 0xf45a, 0xf49a, 0x732a, 0xf46a, 0xf4aa, -}; - -static const float codebook_vector4_vals[] = { - -6.3496042, -4.3267487, - -2.5198421, -1.0000000, - 0.0000000, 1.0000000, - 2.5198421, 4.3267487, - 6.3496042, -}; - -/* - * bits 0:3, 4:7 index into _vals array - */ -static const uint16_t codebook_vector4_idx[] = { - 0x0000, 0x0010, 0x0020, 0x0030, 0x0040, 0x0050, 0x0060, 0x0070, 0x0080, - 0x0001, 0x0011, 0x0021, 0x0031, 0x0041, 0x0051, 0x0061, 0x0071, 0x0081, - 0x0002, 0x0012, 0x0022, 0x0032, 0x0042, 0x0052, 0x0062, 0x0072, 0x0082, - 0x0003, 0x0013, 0x0023, 0x0033, 0x0043, 0x0053, 0x0063, 0x0073, 0x0083, - 0x0004, 0x0014, 0x0024, 0x0034, 0x0044, 0x0054, 0x0064, 0x0074, 0x0084, - 0x0005, 0x0015, 0x0025, 0x0035, 0x0045, 0x0055, 0x0065, 0x0075, 0x0085, - 0x0006, 0x0016, 0x0026, 0x0036, 0x0046, 0x0056, 0x0066, 0x0076, 0x0086, - 0x0007, 0x0017, 0x0027, 0x0037, 0x0047, 0x0057, 0x0067, 0x0077, 0x0087, - 0x0008, 0x0018, 0x0028, 0x0038, 0x0048, 0x0058, 0x0068, 0x0078, 0x0088, -}; - -/* - * bits 0:3, 4:7 index into _vals array - * 8:11 number of non-zero values - * 12:15 1: only second value non-zero - * 0: other cases - */ -static const uint16_t codebook_vector6_idx[] = { - 0x0000, 0x0110, 0x0120, 0x0130, 0x0140, 0x0150, 0x0160, 0x0170, - 0x1101, 0x0211, 0x0221, 0x0231, 0x0241, 0x0251, 0x0261, 0x0271, - 0x1102, 0x0212, 0x0222, 0x0232, 0x0242, 0x0252, 0x0262, 0x0272, - 0x1103, 0x0213, 0x0223, 0x0233, 0x0243, 0x0253, 0x0263, 0x0273, - 0x1104, 0x0214, 0x0224, 0x0234, 0x0244, 0x0254, 0x0264, 0x0274, - 0x1105, 0x0215, 0x0225, 0x0235, 0x0245, 0x0255, 0x0265, 0x0275, - 0x1106, 0x0216, 0x0226, 0x0236, 0x0246, 0x0256, 0x0266, 0x0276, - 0x1107, 0x0217, 0x0227, 0x0237, 0x0247, 0x0257, 0x0267, 0x0277, -}; - -/* - * bits 0:3, 4:7 index into _vals array - * 8:11 number of non-zero values - * 12:15 1: only second value non-zero - * 0: other cases - */ -static const uint16_t codebook_vector8_idx[] = { - 0x0000, 0x0110, 0x0120, 0x0130, 0x0140, 0x0150, 0x0160, - 0x0170, 0x0180, 0x0190, 0x01a0, 0x01b0, 0x01c0, - 0x1101, 0x0211, 0x0221, 0x0231, 0x0241, 0x0251, 0x0261, - 0x0271, 0x0281, 0x0291, 0x02a1, 0x02b1, 0x02c1, - 0x1102, 0x0212, 0x0222, 0x0232, 0x0242, 0x0252, 0x0262, - 0x0272, 0x0282, 0x0292, 0x02a2, 0x02b2, 0x02c2, - 0x1103, 0x0213, 0x0223, 0x0233, 0x0243, 0x0253, 0x0263, - 0x0273, 0x0283, 0x0293, 0x02a3, 0x02b3, 0x02c3, - 0x1104, 0x0214, 0x0224, 0x0234, 0x0244, 0x0254, 0x0264, - 0x0274, 0x0284, 0x0294, 0x02a4, 0x02b4, 0x02c4, - 0x1105, 0x0215, 0x0225, 0x0235, 0x0245, 0x0255, 0x0265, - 0x0275, 0x0285, 0x0295, 0x02a5, 0x02b5, 0x02c5, - 0x1106, 0x0216, 0x0226, 0x0236, 0x0246, 0x0256, 0x0266, - 0x0276, 0x0286, 0x0296, 0x02a6, 0x02b6, 0x02c6, - 0x1107, 0x0217, 0x0227, 0x0237, 0x0247, 0x0257, 0x0267, - 0x0277, 0x0287, 0x0297, 0x02a7, 0x02b7, 0x02c7, - 0x1108, 0x0218, 0x0228, 0x0238, 0x0248, 0x0258, 0x0268, - 0x0278, 0x0288, 0x0298, 0x02a8, 0x02b8, 0x02c8, - 0x1109, 0x0219, 0x0229, 0x0239, 0x0249, 0x0259, 0x0269, - 0x0279, 0x0289, 0x0299, 0x02a9, 0x02b9, 0x02c9, - 0x110a, 0x021a, 0x022a, 0x023a, 0x024a, 0x025a, 0x026a, - 0x027a, 0x028a, 0x029a, 0x02aa, 0x02ba, 0x02ca, - 0x110b, 0x021b, 0x022b, 0x023b, 0x024b, 0x025b, 0x026b, - 0x027b, 0x028b, 0x029b, 0x02ab, 0x02bb, 0x02cb, - 0x110c, 0x021c, 0x022c, 0x023c, 0x024c, 0x025c, 0x026c, - 0x027c, 0x028c, 0x029c, 0x02ac, 0x02bc, 0x02cc, -}; - -static const float codebook_vector10_vals[] = { - 0.0000000, 1.0000000, - 2.5198421, 4.3267487, - 6.3496042, 8.5498797, - 10.9027236, 13.3905183, - 16.0000000, 18.7207544, - 21.5443469, 24.4637810, - 27.4731418, 30.5673509, - 33.7419917, 36.9931811, -}; - -/* - * bits 0:3, 4:7 index into _vals array - * 8:9 bit mask of escape-coded entries - * 12:15 number of non-zero values - */ -static const uint16_t codebook_vector10_idx[] = { - 0x0000, 0x1010, 0x1020, 0x1030, 0x1040, 0x1050, 0x1060, 0x1070, - 0x1080, 0x1090, 0x10a0, 0x10b0, 0x10c0, 0x10d0, 0x10e0, 0x10f0, 0x1200, - 0x1001, 0x2011, 0x2021, 0x2031, 0x2041, 0x2051, 0x2061, 0x2071, - 0x2081, 0x2091, 0x20a1, 0x20b1, 0x20c1, 0x20d1, 0x20e1, 0x20f1, 0x2201, - 0x1002, 0x2012, 0x2022, 0x2032, 0x2042, 0x2052, 0x2062, 0x2072, - 0x2082, 0x2092, 0x20a2, 0x20b2, 0x20c2, 0x20d2, 0x20e2, 0x20f2, 0x2202, - 0x1003, 0x2013, 0x2023, 0x2033, 0x2043, 0x2053, 0x2063, 0x2073, - 0x2083, 0x2093, 0x20a3, 0x20b3, 0x20c3, 0x20d3, 0x20e3, 0x20f3, 0x2203, - 0x1004, 0x2014, 0x2024, 0x2034, 0x2044, 0x2054, 0x2064, 0x2074, - 0x2084, 0x2094, 0x20a4, 0x20b4, 0x20c4, 0x20d4, 0x20e4, 0x20f4, 0x2204, - 0x1005, 0x2015, 0x2025, 0x2035, 0x2045, 0x2055, 0x2065, 0x2075, - 0x2085, 0x2095, 0x20a5, 0x20b5, 0x20c5, 0x20d5, 0x20e5, 0x20f5, 0x2205, - 0x1006, 0x2016, 0x2026, 0x2036, 0x2046, 0x2056, 0x2066, 0x2076, - 0x2086, 0x2096, 0x20a6, 0x20b6, 0x20c6, 0x20d6, 0x20e6, 0x20f6, 0x2206, - 0x1007, 0x2017, 0x2027, 0x2037, 0x2047, 0x2057, 0x2067, 0x2077, - 0x2087, 0x2097, 0x20a7, 0x20b7, 0x20c7, 0x20d7, 0x20e7, 0x20f7, 0x2207, - 0x1008, 0x2018, 0x2028, 0x2038, 0x2048, 0x2058, 0x2068, 0x2078, - 0x2088, 0x2098, 0x20a8, 0x20b8, 0x20c8, 0x20d8, 0x20e8, 0x20f8, 0x2208, - 0x1009, 0x2019, 0x2029, 0x2039, 0x2049, 0x2059, 0x2069, 0x2079, - 0x2089, 0x2099, 0x20a9, 0x20b9, 0x20c9, 0x20d9, 0x20e9, 0x20f9, 0x2209, - 0x100a, 0x201a, 0x202a, 0x203a, 0x204a, 0x205a, 0x206a, 0x207a, - 0x208a, 0x209a, 0x20aa, 0x20ba, 0x20ca, 0x20da, 0x20ea, 0x20fa, 0x220a, - 0x100b, 0x201b, 0x202b, 0x203b, 0x204b, 0x205b, 0x206b, 0x207b, - 0x208b, 0x209b, 0x20ab, 0x20bb, 0x20cb, 0x20db, 0x20eb, 0x20fb, 0x220b, - 0x100c, 0x201c, 0x202c, 0x203c, 0x204c, 0x205c, 0x206c, 0x207c, - 0x208c, 0x209c, 0x20ac, 0x20bc, 0x20cc, 0x20dc, 0x20ec, 0x20fc, 0x220c, - 0x100d, 0x201d, 0x202d, 0x203d, 0x204d, 0x205d, 0x206d, 0x207d, - 0x208d, 0x209d, 0x20ad, 0x20bd, 0x20cd, 0x20dd, 0x20ed, 0x20fd, 0x220d, - 0x100e, 0x201e, 0x202e, 0x203e, 0x204e, 0x205e, 0x206e, 0x207e, - 0x208e, 0x209e, 0x20ae, 0x20be, 0x20ce, 0x20de, 0x20ee, 0x20fe, 0x220e, - 0x100f, 0x201f, 0x202f, 0x203f, 0x204f, 0x205f, 0x206f, 0x207f, - 0x208f, 0x209f, 0x20af, 0x20bf, 0x20cf, 0x20df, 0x20ef, 0x20ff, 0x220f, - 0x1100, 0x2110, 0x2120, 0x2130, 0x2140, 0x2150, 0x2160, 0x2170, - 0x2180, 0x2190, 0x21a0, 0x21b0, 0x21c0, 0x21d0, 0x21e0, 0x21f0, 0x2300, -}; - -const float *const ff_aac_codebook_vector_vals[] = { - codebook_vector0_vals, codebook_vector0_vals, - codebook_vector10_vals, codebook_vector10_vals, - codebook_vector4_vals, codebook_vector4_vals, - codebook_vector10_vals, codebook_vector10_vals, - codebook_vector10_vals, codebook_vector10_vals, - codebook_vector10_vals, -}; - -const uint16_t *const ff_aac_codebook_vector_idx[] = { - codebook_vector02_idx, codebook_vector02_idx, - codebook_vector02_idx, codebook_vector02_idx, - codebook_vector4_idx, codebook_vector4_idx, - codebook_vector6_idx, codebook_vector6_idx, - codebook_vector8_idx, codebook_vector8_idx, - codebook_vector10_idx, -}; - -/* @name swb_offsets - * Sample offset into the window indicating the beginning of a scalefactor - * window band - * - * scalefactor window band - term for scalefactor bands within a window, - * given in Table 4.110 to Table 4.128. - * - * scalefactor band - a set of spectral coefficients which are scaled by one - * scalefactor. In case of EIGHT_SHORT_SEQUENCE and grouping a scalefactor band - * may contain several scalefactor window bands of corresponding frequency. For - * all other window_sequences scalefactor bands and scalefactor window bands are - * identical. - * @{ - */ - -static const uint16_t swb_offset_1024_96[] = { - 0, 4, 8, 12, 16, 20, 24, 28, - 32, 36, 40, 44, 48, 52, 56, 64, - 72, 80, 88, 96, 108, 120, 132, 144, - 156, 172, 188, 212, 240, 276, 320, 384, - 448, 512, 576, 640, 704, 768, 832, 896, - 960, 1024 -}; - -static const uint16_t swb_offset_128_96[] = { - 0, 4, 8, 12, 16, 20, 24, 32, 40, 48, 64, 92, 128 -}; - -static const uint16_t swb_offset_1024_64[] = { - 0, 4, 8, 12, 16, 20, 24, 28, - 32, 36, 40, 44, 48, 52, 56, 64, - 72, 80, 88, 100, 112, 124, 140, 156, - 172, 192, 216, 240, 268, 304, 344, 384, - 424, 464, 504, 544, 584, 624, 664, 704, - 744, 784, 824, 864, 904, 944, 984, 1024 -}; - -static const uint16_t swb_offset_1024_48[] = { - 0, 4, 8, 12, 16, 20, 24, 28, - 32, 36, 40, 48, 56, 64, 72, 80, - 88, 96, 108, 120, 132, 144, 160, 176, - 196, 216, 240, 264, 292, 320, 352, 384, - 416, 448, 480, 512, 544, 576, 608, 640, - 672, 704, 736, 768, 800, 832, 864, 896, - 928, 1024 -}; - -static const uint16_t swb_offset_128_48[] = { - 0, 4, 8, 12, 16, 20, 28, 36, - 44, 56, 68, 80, 96, 112, 128 -}; - -static const uint16_t swb_offset_1024_32[] = { - 0, 4, 8, 12, 16, 20, 24, 28, - 32, 36, 40, 48, 56, 64, 72, 80, - 88, 96, 108, 120, 132, 144, 160, 176, - 196, 216, 240, 264, 292, 320, 352, 384, - 416, 448, 480, 512, 544, 576, 608, 640, - 672, 704, 736, 768, 800, 832, 864, 896, - 928, 960, 992, 1024 -}; - -static const uint16_t swb_offset_1024_24[] = { - 0, 4, 8, 12, 16, 20, 24, 28, - 32, 36, 40, 44, 52, 60, 68, 76, - 84, 92, 100, 108, 116, 124, 136, 148, - 160, 172, 188, 204, 220, 240, 260, 284, - 308, 336, 364, 396, 432, 468, 508, 552, - 600, 652, 704, 768, 832, 896, 960, 1024 -}; - -static const uint16_t swb_offset_128_24[] = { - 0, 4, 8, 12, 16, 20, 24, 28, - 36, 44, 52, 64, 76, 92, 108, 128 -}; - -static const uint16_t swb_offset_1024_16[] = { - 0, 8, 16, 24, 32, 40, 48, 56, - 64, 72, 80, 88, 100, 112, 124, 136, - 148, 160, 172, 184, 196, 212, 228, 244, - 260, 280, 300, 320, 344, 368, 396, 424, - 456, 492, 532, 572, 616, 664, 716, 772, - 832, 896, 960, 1024 -}; - -static const uint16_t swb_offset_128_16[] = { - 0, 4, 8, 12, 16, 20, 24, 28, - 32, 40, 48, 60, 72, 88, 108, 128 -}; - -static const uint16_t swb_offset_1024_8[] = { - 0, 12, 24, 36, 48, 60, 72, 84, - 96, 108, 120, 132, 144, 156, 172, 188, - 204, 220, 236, 252, 268, 288, 308, 328, - 348, 372, 396, 420, 448, 476, 508, 544, - 580, 620, 664, 712, 764, 820, 880, 944, - 1024 -}; - -static const uint16_t swb_offset_128_8[] = { - 0, 4, 8, 12, 16, 20, 24, 28, - 36, 44, 52, 60, 72, 88, 108, 128 -}; - -const uint16_t * const ff_swb_offset_1024[] = { - swb_offset_1024_96, swb_offset_1024_96, swb_offset_1024_64, - swb_offset_1024_48, swb_offset_1024_48, swb_offset_1024_32, - swb_offset_1024_24, swb_offset_1024_24, swb_offset_1024_16, - swb_offset_1024_16, swb_offset_1024_16, swb_offset_1024_8, - swb_offset_1024_8 -}; - -const uint16_t * const ff_swb_offset_128[] = { - /* The last entry on the following row is swb_offset_128_64 but is a - duplicate of swb_offset_128_96. */ - swb_offset_128_96, swb_offset_128_96, swb_offset_128_96, - swb_offset_128_48, swb_offset_128_48, swb_offset_128_48, - swb_offset_128_24, swb_offset_128_24, swb_offset_128_16, - swb_offset_128_16, swb_offset_128_16, swb_offset_128_8, - swb_offset_128_8 -}; - -// @} - -/* @name ff_tns_max_bands - * The maximum number of scalefactor bands on which TNS can operate for the long - * and short transforms respectively. The index to these tables is related to - * the sample rate of the audio. - * @{ - */ -const uint8_t ff_tns_max_bands_1024[] = { - 31, 31, 34, 40, 42, 51, 46, 46, 42, 42, 42, 39, 39 -}; - -const uint8_t ff_tns_max_bands_128[] = { - 9, 9, 10, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14 -}; -// @} +/*
+ * AAC data
+ * Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org )
+ * Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com )
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * AAC data
+ * @author Oded Shimon ( ods15 ods15 dyndns org )
+ * @author Maxim Gavrilov ( maxim.gavrilov gmail com )
+ */
+
+#include "libavutil/mem.h"
+#include "aac.h"
+#include "aac_tablegen.h"
+
+#include <stdint.h>
+
+DECLARE_ALIGNED(16, float, ff_aac_kbd_long_1024)[1024];
+DECLARE_ALIGNED(16, float, ff_aac_kbd_short_128)[128];
+
+const uint8_t ff_aac_num_swb_1024[] = {
+ 41, 41, 47, 49, 49, 51, 47, 47, 43, 43, 43, 40, 40
+};
+
+const uint8_t ff_aac_num_swb_128[] = {
+ 12, 12, 12, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15
+};
+
+const uint8_t ff_aac_pred_sfb_max[] = {
+ 33, 33, 38, 40, 40, 40, 41, 41, 37, 37, 37, 34, 34
+};
+
+const uint32_t ff_aac_scalefactor_code[121] = {
+ 0x3ffe8, 0x3ffe6, 0x3ffe7, 0x3ffe5, 0x7fff5, 0x7fff1, 0x7ffed, 0x7fff6,
+ 0x7ffee, 0x7ffef, 0x7fff0, 0x7fffc, 0x7fffd, 0x7ffff, 0x7fffe, 0x7fff7,
+ 0x7fff8, 0x7fffb, 0x7fff9, 0x3ffe4, 0x7fffa, 0x3ffe3, 0x1ffef, 0x1fff0,
+ 0x0fff5, 0x1ffee, 0x0fff2, 0x0fff3, 0x0fff4, 0x0fff1, 0x07ff6, 0x07ff7,
+ 0x03ff9, 0x03ff5, 0x03ff7, 0x03ff3, 0x03ff6, 0x03ff2, 0x01ff7, 0x01ff5,
+ 0x00ff9, 0x00ff7, 0x00ff6, 0x007f9, 0x00ff4, 0x007f8, 0x003f9, 0x003f7,
+ 0x003f5, 0x001f8, 0x001f7, 0x000fa, 0x000f8, 0x000f6, 0x00079, 0x0003a,
+ 0x00038, 0x0001a, 0x0000b, 0x00004, 0x00000, 0x0000a, 0x0000c, 0x0001b,
+ 0x00039, 0x0003b, 0x00078, 0x0007a, 0x000f7, 0x000f9, 0x001f6, 0x001f9,
+ 0x003f4, 0x003f6, 0x003f8, 0x007f5, 0x007f4, 0x007f6, 0x007f7, 0x00ff5,
+ 0x00ff8, 0x01ff4, 0x01ff6, 0x01ff8, 0x03ff8, 0x03ff4, 0x0fff0, 0x07ff4,
+ 0x0fff6, 0x07ff5, 0x3ffe2, 0x7ffd9, 0x7ffda, 0x7ffdb, 0x7ffdc, 0x7ffdd,
+ 0x7ffde, 0x7ffd8, 0x7ffd2, 0x7ffd3, 0x7ffd4, 0x7ffd5, 0x7ffd6, 0x7fff2,
+ 0x7ffdf, 0x7ffe7, 0x7ffe8, 0x7ffe9, 0x7ffea, 0x7ffeb, 0x7ffe6, 0x7ffe0,
+ 0x7ffe1, 0x7ffe2, 0x7ffe3, 0x7ffe4, 0x7ffe5, 0x7ffd7, 0x7ffec, 0x7fff4,
+ 0x7fff3,
+};
+
+const uint8_t ff_aac_scalefactor_bits[121] = {
+ 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 18, 19, 18, 17, 17, 16, 17, 16, 16, 16, 16, 15, 15,
+ 14, 14, 14, 14, 14, 14, 13, 13, 12, 12, 12, 11, 12, 11, 10, 10,
+ 10, 9, 9, 8, 8, 8, 7, 6, 6, 5, 4, 3, 1, 4, 4, 5,
+ 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 11, 12,
+ 12, 13, 13, 13, 14, 14, 16, 15, 16, 15, 18, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19,
+};
+
+static const uint16_t codes1[81] = {
+ 0x7f8, 0x1f1, 0x7fd, 0x3f5, 0x068, 0x3f0, 0x7f7, 0x1ec,
+ 0x7f5, 0x3f1, 0x072, 0x3f4, 0x074, 0x011, 0x076, 0x1eb,
+ 0x06c, 0x3f6, 0x7fc, 0x1e1, 0x7f1, 0x1f0, 0x061, 0x1f6,
+ 0x7f2, 0x1ea, 0x7fb, 0x1f2, 0x069, 0x1ed, 0x077, 0x017,
+ 0x06f, 0x1e6, 0x064, 0x1e5, 0x067, 0x015, 0x062, 0x012,
+ 0x000, 0x014, 0x065, 0x016, 0x06d, 0x1e9, 0x063, 0x1e4,
+ 0x06b, 0x013, 0x071, 0x1e3, 0x070, 0x1f3, 0x7fe, 0x1e7,
+ 0x7f3, 0x1ef, 0x060, 0x1ee, 0x7f0, 0x1e2, 0x7fa, 0x3f3,
+ 0x06a, 0x1e8, 0x075, 0x010, 0x073, 0x1f4, 0x06e, 0x3f7,
+ 0x7f6, 0x1e0, 0x7f9, 0x3f2, 0x066, 0x1f5, 0x7ff, 0x1f7,
+ 0x7f4,
+};
+
+static const uint8_t bits1[81] = {
+ 11, 9, 11, 10, 7, 10, 11, 9, 11, 10, 7, 10, 7, 5, 7, 9,
+ 7, 10, 11, 9, 11, 9, 7, 9, 11, 9, 11, 9, 7, 9, 7, 5,
+ 7, 9, 7, 9, 7, 5, 7, 5, 1, 5, 7, 5, 7, 9, 7, 9,
+ 7, 5, 7, 9, 7, 9, 11, 9, 11, 9, 7, 9, 11, 9, 11, 10,
+ 7, 9, 7, 5, 7, 9, 7, 10, 11, 9, 11, 10, 7, 9, 11, 9,
+ 11,
+};
+
+static const uint16_t codes2[81] = {
+ 0x1f3, 0x06f, 0x1fd, 0x0eb, 0x023, 0x0ea, 0x1f7, 0x0e8,
+ 0x1fa, 0x0f2, 0x02d, 0x070, 0x020, 0x006, 0x02b, 0x06e,
+ 0x028, 0x0e9, 0x1f9, 0x066, 0x0f8, 0x0e7, 0x01b, 0x0f1,
+ 0x1f4, 0x06b, 0x1f5, 0x0ec, 0x02a, 0x06c, 0x02c, 0x00a,
+ 0x027, 0x067, 0x01a, 0x0f5, 0x024, 0x008, 0x01f, 0x009,
+ 0x000, 0x007, 0x01d, 0x00b, 0x030, 0x0ef, 0x01c, 0x064,
+ 0x01e, 0x00c, 0x029, 0x0f3, 0x02f, 0x0f0, 0x1fc, 0x071,
+ 0x1f2, 0x0f4, 0x021, 0x0e6, 0x0f7, 0x068, 0x1f8, 0x0ee,
+ 0x022, 0x065, 0x031, 0x002, 0x026, 0x0ed, 0x025, 0x06a,
+ 0x1fb, 0x072, 0x1fe, 0x069, 0x02e, 0x0f6, 0x1ff, 0x06d,
+ 0x1f6,
+};
+
+static const uint8_t bits2[81] = {
+ 9, 7, 9, 8, 6, 8, 9, 8, 9, 8, 6, 7, 6, 5, 6, 7,
+ 6, 8, 9, 7, 8, 8, 6, 8, 9, 7, 9, 8, 6, 7, 6, 5,
+ 6, 7, 6, 8, 6, 5, 6, 5, 3, 5, 6, 5, 6, 8, 6, 7,
+ 6, 5, 6, 8, 6, 8, 9, 7, 9, 8, 6, 8, 8, 7, 9, 8,
+ 6, 7, 6, 4, 6, 8, 6, 7, 9, 7, 9, 7, 6, 8, 9, 7,
+ 9,
+};
+
+static const uint16_t codes3[81] = {
+ 0x0000, 0x0009, 0x00ef, 0x000b, 0x0019, 0x00f0, 0x01eb, 0x01e6,
+ 0x03f2, 0x000a, 0x0035, 0x01ef, 0x0034, 0x0037, 0x01e9, 0x01ed,
+ 0x01e7, 0x03f3, 0x01ee, 0x03ed, 0x1ffa, 0x01ec, 0x01f2, 0x07f9,
+ 0x07f8, 0x03f8, 0x0ff8, 0x0008, 0x0038, 0x03f6, 0x0036, 0x0075,
+ 0x03f1, 0x03eb, 0x03ec, 0x0ff4, 0x0018, 0x0076, 0x07f4, 0x0039,
+ 0x0074, 0x03ef, 0x01f3, 0x01f4, 0x07f6, 0x01e8, 0x03ea, 0x1ffc,
+ 0x00f2, 0x01f1, 0x0ffb, 0x03f5, 0x07f3, 0x0ffc, 0x00ee, 0x03f7,
+ 0x7ffe, 0x01f0, 0x07f5, 0x7ffd, 0x1ffb, 0x3ffa, 0xffff, 0x00f1,
+ 0x03f0, 0x3ffc, 0x01ea, 0x03ee, 0x3ffb, 0x0ff6, 0x0ffa, 0x7ffc,
+ 0x07f2, 0x0ff5, 0xfffe, 0x03f4, 0x07f7, 0x7ffb, 0x0ff7, 0x0ff9,
+ 0x7ffa,
+};
+
+static const uint8_t bits3[81] = {
+ 1, 4, 8, 4, 5, 8, 9, 9, 10, 4, 6, 9, 6, 6, 9, 9,
+ 9, 10, 9, 10, 13, 9, 9, 11, 11, 10, 12, 4, 6, 10, 6, 7,
+ 10, 10, 10, 12, 5, 7, 11, 6, 7, 10, 9, 9, 11, 9, 10, 13,
+ 8, 9, 12, 10, 11, 12, 8, 10, 15, 9, 11, 15, 13, 14, 16, 8,
+ 10, 14, 9, 10, 14, 12, 12, 15, 11, 12, 16, 10, 11, 15, 12, 12,
+ 15,
+};
+
+static const uint16_t codes4[81] = {
+ 0x007, 0x016, 0x0f6, 0x018, 0x008, 0x0ef, 0x1ef, 0x0f3,
+ 0x7f8, 0x019, 0x017, 0x0ed, 0x015, 0x001, 0x0e2, 0x0f0,
+ 0x070, 0x3f0, 0x1ee, 0x0f1, 0x7fa, 0x0ee, 0x0e4, 0x3f2,
+ 0x7f6, 0x3ef, 0x7fd, 0x005, 0x014, 0x0f2, 0x009, 0x004,
+ 0x0e5, 0x0f4, 0x0e8, 0x3f4, 0x006, 0x002, 0x0e7, 0x003,
+ 0x000, 0x06b, 0x0e3, 0x069, 0x1f3, 0x0eb, 0x0e6, 0x3f6,
+ 0x06e, 0x06a, 0x1f4, 0x3ec, 0x1f0, 0x3f9, 0x0f5, 0x0ec,
+ 0x7fb, 0x0ea, 0x06f, 0x3f7, 0x7f9, 0x3f3, 0xfff, 0x0e9,
+ 0x06d, 0x3f8, 0x06c, 0x068, 0x1f5, 0x3ee, 0x1f2, 0x7f4,
+ 0x7f7, 0x3f1, 0xffe, 0x3ed, 0x1f1, 0x7f5, 0x7fe, 0x3f5,
+ 0x7fc,
+};
+
+static const uint8_t bits4[81] = {
+ 4, 5, 8, 5, 4, 8, 9, 8, 11, 5, 5, 8, 5, 4, 8, 8,
+ 7, 10, 9, 8, 11, 8, 8, 10, 11, 10, 11, 4, 5, 8, 4, 4,
+ 8, 8, 8, 10, 4, 4, 8, 4, 4, 7, 8, 7, 9, 8, 8, 10,
+ 7, 7, 9, 10, 9, 10, 8, 8, 11, 8, 7, 10, 11, 10, 12, 8,
+ 7, 10, 7, 7, 9, 10, 9, 11, 11, 10, 12, 10, 9, 11, 11, 10,
+ 11,
+};
+
+static const uint16_t codes5[81] = {
+ 0x1fff, 0x0ff7, 0x07f4, 0x07e8, 0x03f1, 0x07ee, 0x07f9, 0x0ff8,
+ 0x1ffd, 0x0ffd, 0x07f1, 0x03e8, 0x01e8, 0x00f0, 0x01ec, 0x03ee,
+ 0x07f2, 0x0ffa, 0x0ff4, 0x03ef, 0x01f2, 0x00e8, 0x0070, 0x00ec,
+ 0x01f0, 0x03ea, 0x07f3, 0x07eb, 0x01eb, 0x00ea, 0x001a, 0x0008,
+ 0x0019, 0x00ee, 0x01ef, 0x07ed, 0x03f0, 0x00f2, 0x0073, 0x000b,
+ 0x0000, 0x000a, 0x0071, 0x00f3, 0x07e9, 0x07ef, 0x01ee, 0x00ef,
+ 0x0018, 0x0009, 0x001b, 0x00eb, 0x01e9, 0x07ec, 0x07f6, 0x03eb,
+ 0x01f3, 0x00ed, 0x0072, 0x00e9, 0x01f1, 0x03ed, 0x07f7, 0x0ff6,
+ 0x07f0, 0x03e9, 0x01ed, 0x00f1, 0x01ea, 0x03ec, 0x07f8, 0x0ff9,
+ 0x1ffc, 0x0ffc, 0x0ff5, 0x07ea, 0x03f3, 0x03f2, 0x07f5, 0x0ffb,
+ 0x1ffe,
+};
+
+static const uint8_t bits5[81] = {
+ 13, 12, 11, 11, 10, 11, 11, 12, 13, 12, 11, 10, 9, 8, 9, 10,
+ 11, 12, 12, 10, 9, 8, 7, 8, 9, 10, 11, 11, 9, 8, 5, 4,
+ 5, 8, 9, 11, 10, 8, 7, 4, 1, 4, 7, 8, 11, 11, 9, 8,
+ 5, 4, 5, 8, 9, 11, 11, 10, 9, 8, 7, 8, 9, 10, 11, 12,
+ 11, 10, 9, 8, 9, 10, 11, 12, 13, 12, 12, 11, 10, 10, 11, 12,
+ 13,
+};
+
+static const uint16_t codes6[81] = {
+ 0x7fe, 0x3fd, 0x1f1, 0x1eb, 0x1f4, 0x1ea, 0x1f0, 0x3fc,
+ 0x7fd, 0x3f6, 0x1e5, 0x0ea, 0x06c, 0x071, 0x068, 0x0f0,
+ 0x1e6, 0x3f7, 0x1f3, 0x0ef, 0x032, 0x027, 0x028, 0x026,
+ 0x031, 0x0eb, 0x1f7, 0x1e8, 0x06f, 0x02e, 0x008, 0x004,
+ 0x006, 0x029, 0x06b, 0x1ee, 0x1ef, 0x072, 0x02d, 0x002,
+ 0x000, 0x003, 0x02f, 0x073, 0x1fa, 0x1e7, 0x06e, 0x02b,
+ 0x007, 0x001, 0x005, 0x02c, 0x06d, 0x1ec, 0x1f9, 0x0ee,
+ 0x030, 0x024, 0x02a, 0x025, 0x033, 0x0ec, 0x1f2, 0x3f8,
+ 0x1e4, 0x0ed, 0x06a, 0x070, 0x069, 0x074, 0x0f1, 0x3fa,
+ 0x7ff, 0x3f9, 0x1f6, 0x1ed, 0x1f8, 0x1e9, 0x1f5, 0x3fb,
+ 0x7fc,
+};
+
+static const uint8_t bits6[81] = {
+ 11, 10, 9, 9, 9, 9, 9, 10, 11, 10, 9, 8, 7, 7, 7, 8,
+ 9, 10, 9, 8, 6, 6, 6, 6, 6, 8, 9, 9, 7, 6, 4, 4,
+ 4, 6, 7, 9, 9, 7, 6, 4, 4, 4, 6, 7, 9, 9, 7, 6,
+ 4, 4, 4, 6, 7, 9, 9, 8, 6, 6, 6, 6, 6, 8, 9, 10,
+ 9, 8, 7, 7, 7, 7, 8, 10, 11, 10, 9, 9, 9, 9, 9, 10,
+ 11,
+};
+
+static const uint16_t codes7[64] = {
+ 0x000, 0x005, 0x037, 0x074, 0x0f2, 0x1eb, 0x3ed, 0x7f7,
+ 0x004, 0x00c, 0x035, 0x071, 0x0ec, 0x0ee, 0x1ee, 0x1f5,
+ 0x036, 0x034, 0x072, 0x0ea, 0x0f1, 0x1e9, 0x1f3, 0x3f5,
+ 0x073, 0x070, 0x0eb, 0x0f0, 0x1f1, 0x1f0, 0x3ec, 0x3fa,
+ 0x0f3, 0x0ed, 0x1e8, 0x1ef, 0x3ef, 0x3f1, 0x3f9, 0x7fb,
+ 0x1ed, 0x0ef, 0x1ea, 0x1f2, 0x3f3, 0x3f8, 0x7f9, 0x7fc,
+ 0x3ee, 0x1ec, 0x1f4, 0x3f4, 0x3f7, 0x7f8, 0xffd, 0xffe,
+ 0x7f6, 0x3f0, 0x3f2, 0x3f6, 0x7fa, 0x7fd, 0xffc, 0xfff,
+};
+
+static const uint8_t bits7[64] = {
+ 1, 3, 6, 7, 8, 9, 10, 11, 3, 4, 6, 7, 8, 8, 9, 9,
+ 6, 6, 7, 8, 8, 9, 9, 10, 7, 7, 8, 8, 9, 9, 10, 10,
+ 8, 8, 9, 9, 10, 10, 10, 11, 9, 8, 9, 9, 10, 10, 11, 11,
+ 10, 9, 9, 10, 10, 11, 12, 12, 11, 10, 10, 10, 11, 11, 12, 12,
+};
+
+static const uint16_t codes8[64] = {
+ 0x00e, 0x005, 0x010, 0x030, 0x06f, 0x0f1, 0x1fa, 0x3fe,
+ 0x003, 0x000, 0x004, 0x012, 0x02c, 0x06a, 0x075, 0x0f8,
+ 0x00f, 0x002, 0x006, 0x014, 0x02e, 0x069, 0x072, 0x0f5,
+ 0x02f, 0x011, 0x013, 0x02a, 0x032, 0x06c, 0x0ec, 0x0fa,
+ 0x071, 0x02b, 0x02d, 0x031, 0x06d, 0x070, 0x0f2, 0x1f9,
+ 0x0ef, 0x068, 0x033, 0x06b, 0x06e, 0x0ee, 0x0f9, 0x3fc,
+ 0x1f8, 0x074, 0x073, 0x0ed, 0x0f0, 0x0f6, 0x1f6, 0x1fd,
+ 0x3fd, 0x0f3, 0x0f4, 0x0f7, 0x1f7, 0x1fb, 0x1fc, 0x3ff,
+};
+
+static const uint8_t bits8[64] = {
+ 5, 4, 5, 6, 7, 8, 9, 10, 4, 3, 4, 5, 6, 7, 7, 8,
+ 5, 4, 4, 5, 6, 7, 7, 8, 6, 5, 5, 6, 6, 7, 8, 8,
+ 7, 6, 6, 6, 7, 7, 8, 9, 8, 7, 6, 7, 7, 8, 8, 10,
+ 9, 7, 7, 8, 8, 8, 9, 9, 10, 8, 8, 8, 9, 9, 9, 10,
+};
+
+static const uint16_t codes9[169] = {
+ 0x0000, 0x0005, 0x0037, 0x00e7, 0x01de, 0x03ce, 0x03d9, 0x07c8,
+ 0x07cd, 0x0fc8, 0x0fdd, 0x1fe4, 0x1fec, 0x0004, 0x000c, 0x0035,
+ 0x0072, 0x00ea, 0x00ed, 0x01e2, 0x03d1, 0x03d3, 0x03e0, 0x07d8,
+ 0x0fcf, 0x0fd5, 0x0036, 0x0034, 0x0071, 0x00e8, 0x00ec, 0x01e1,
+ 0x03cf, 0x03dd, 0x03db, 0x07d0, 0x0fc7, 0x0fd4, 0x0fe4, 0x00e6,
+ 0x0070, 0x00e9, 0x01dd, 0x01e3, 0x03d2, 0x03dc, 0x07cc, 0x07ca,
+ 0x07de, 0x0fd8, 0x0fea, 0x1fdb, 0x01df, 0x00eb, 0x01dc, 0x01e6,
+ 0x03d5, 0x03de, 0x07cb, 0x07dd, 0x07dc, 0x0fcd, 0x0fe2, 0x0fe7,
+ 0x1fe1, 0x03d0, 0x01e0, 0x01e4, 0x03d6, 0x07c5, 0x07d1, 0x07db,
+ 0x0fd2, 0x07e0, 0x0fd9, 0x0feb, 0x1fe3, 0x1fe9, 0x07c4, 0x01e5,
+ 0x03d7, 0x07c6, 0x07cf, 0x07da, 0x0fcb, 0x0fda, 0x0fe3, 0x0fe9,
+ 0x1fe6, 0x1ff3, 0x1ff7, 0x07d3, 0x03d8, 0x03e1, 0x07d4, 0x07d9,
+ 0x0fd3, 0x0fde, 0x1fdd, 0x1fd9, 0x1fe2, 0x1fea, 0x1ff1, 0x1ff6,
+ 0x07d2, 0x03d4, 0x03da, 0x07c7, 0x07d7, 0x07e2, 0x0fce, 0x0fdb,
+ 0x1fd8, 0x1fee, 0x3ff0, 0x1ff4, 0x3ff2, 0x07e1, 0x03df, 0x07c9,
+ 0x07d6, 0x0fca, 0x0fd0, 0x0fe5, 0x0fe6, 0x1feb, 0x1fef, 0x3ff3,
+ 0x3ff4, 0x3ff5, 0x0fe0, 0x07ce, 0x07d5, 0x0fc6, 0x0fd1, 0x0fe1,
+ 0x1fe0, 0x1fe8, 0x1ff0, 0x3ff1, 0x3ff8, 0x3ff6, 0x7ffc, 0x0fe8,
+ 0x07df, 0x0fc9, 0x0fd7, 0x0fdc, 0x1fdc, 0x1fdf, 0x1fed, 0x1ff5,
+ 0x3ff9, 0x3ffb, 0x7ffd, 0x7ffe, 0x1fe7, 0x0fcc, 0x0fd6, 0x0fdf,
+ 0x1fde, 0x1fda, 0x1fe5, 0x1ff2, 0x3ffa, 0x3ff7, 0x3ffc, 0x3ffd,
+ 0x7fff,
+};
+
+static const uint8_t bits9[169] = {
+ 1, 3, 6, 8, 9, 10, 10, 11, 11, 12, 12, 13, 13, 3, 4, 6,
+ 7, 8, 8, 9, 10, 10, 10, 11, 12, 12, 6, 6, 7, 8, 8, 9,
+ 10, 10, 10, 11, 12, 12, 12, 8, 7, 8, 9, 9, 10, 10, 11, 11,
+ 11, 12, 12, 13, 9, 8, 9, 9, 10, 10, 11, 11, 11, 12, 12, 12,
+ 13, 10, 9, 9, 10, 11, 11, 11, 12, 11, 12, 12, 13, 13, 11, 9,
+ 10, 11, 11, 11, 12, 12, 12, 12, 13, 13, 13, 11, 10, 10, 11, 11,
+ 12, 12, 13, 13, 13, 13, 13, 13, 11, 10, 10, 11, 11, 11, 12, 12,
+ 13, 13, 14, 13, 14, 11, 10, 11, 11, 12, 12, 12, 12, 13, 13, 14,
+ 14, 14, 12, 11, 11, 12, 12, 12, 13, 13, 13, 14, 14, 14, 15, 12,
+ 11, 12, 12, 12, 13, 13, 13, 13, 14, 14, 15, 15, 13, 12, 12, 12,
+ 13, 13, 13, 13, 14, 14, 14, 14, 15,
+};
+
+static const uint16_t codes10[169] = {
+ 0x022, 0x008, 0x01d, 0x026, 0x05f, 0x0d3, 0x1cf, 0x3d0,
+ 0x3d7, 0x3ed, 0x7f0, 0x7f6, 0xffd, 0x007, 0x000, 0x001,
+ 0x009, 0x020, 0x054, 0x060, 0x0d5, 0x0dc, 0x1d4, 0x3cd,
+ 0x3de, 0x7e7, 0x01c, 0x002, 0x006, 0x00c, 0x01e, 0x028,
+ 0x05b, 0x0cd, 0x0d9, 0x1ce, 0x1dc, 0x3d9, 0x3f1, 0x025,
+ 0x00b, 0x00a, 0x00d, 0x024, 0x057, 0x061, 0x0cc, 0x0dd,
+ 0x1cc, 0x1de, 0x3d3, 0x3e7, 0x05d, 0x021, 0x01f, 0x023,
+ 0x027, 0x059, 0x064, 0x0d8, 0x0df, 0x1d2, 0x1e2, 0x3dd,
+ 0x3ee, 0x0d1, 0x055, 0x029, 0x056, 0x058, 0x062, 0x0ce,
+ 0x0e0, 0x0e2, 0x1da, 0x3d4, 0x3e3, 0x7eb, 0x1c9, 0x05e,
+ 0x05a, 0x05c, 0x063, 0x0ca, 0x0da, 0x1c7, 0x1ca, 0x1e0,
+ 0x3db, 0x3e8, 0x7ec, 0x1e3, 0x0d2, 0x0cb, 0x0d0, 0x0d7,
+ 0x0db, 0x1c6, 0x1d5, 0x1d8, 0x3ca, 0x3da, 0x7ea, 0x7f1,
+ 0x1e1, 0x0d4, 0x0cf, 0x0d6, 0x0de, 0x0e1, 0x1d0, 0x1d6,
+ 0x3d1, 0x3d5, 0x3f2, 0x7ee, 0x7fb, 0x3e9, 0x1cd, 0x1c8,
+ 0x1cb, 0x1d1, 0x1d7, 0x1df, 0x3cf, 0x3e0, 0x3ef, 0x7e6,
+ 0x7f8, 0xffa, 0x3eb, 0x1dd, 0x1d3, 0x1d9, 0x1db, 0x3d2,
+ 0x3cc, 0x3dc, 0x3ea, 0x7ed, 0x7f3, 0x7f9, 0xff9, 0x7f2,
+ 0x3ce, 0x1e4, 0x3cb, 0x3d8, 0x3d6, 0x3e2, 0x3e5, 0x7e8,
+ 0x7f4, 0x7f5, 0x7f7, 0xffb, 0x7fa, 0x3ec, 0x3df, 0x3e1,
+ 0x3e4, 0x3e6, 0x3f0, 0x7e9, 0x7ef, 0xff8, 0xffe, 0xffc,
+ 0xfff,
+};
+
+static const uint8_t bits10[169] = {
+ 6, 5, 6, 6, 7, 8, 9, 10, 10, 10, 11, 11, 12, 5, 4, 4,
+ 5, 6, 7, 7, 8, 8, 9, 10, 10, 11, 6, 4, 5, 5, 6, 6,
+ 7, 8, 8, 9, 9, 10, 10, 6, 5, 5, 5, 6, 7, 7, 8, 8,
+ 9, 9, 10, 10, 7, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 10,
+ 10, 8, 7, 6, 7, 7, 7, 8, 8, 8, 9, 10, 10, 11, 9, 7,
+ 7, 7, 7, 8, 8, 9, 9, 9, 10, 10, 11, 9, 8, 8, 8, 8,
+ 8, 9, 9, 9, 10, 10, 11, 11, 9, 8, 8, 8, 8, 8, 9, 9,
+ 10, 10, 10, 11, 11, 10, 9, 9, 9, 9, 9, 9, 10, 10, 10, 11,
+ 11, 12, 10, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 12, 11,
+ 10, 9, 10, 10, 10, 10, 10, 11, 11, 11, 11, 12, 11, 10, 10, 10,
+ 10, 10, 10, 11, 11, 12, 12, 12, 12,
+};
+
+static const uint16_t codes11[289] = {
+ 0x000, 0x006, 0x019, 0x03d, 0x09c, 0x0c6, 0x1a7, 0x390,
+ 0x3c2, 0x3df, 0x7e6, 0x7f3, 0xffb, 0x7ec, 0xffa, 0xffe,
+ 0x38e, 0x005, 0x001, 0x008, 0x014, 0x037, 0x042, 0x092,
+ 0x0af, 0x191, 0x1a5, 0x1b5, 0x39e, 0x3c0, 0x3a2, 0x3cd,
+ 0x7d6, 0x0ae, 0x017, 0x007, 0x009, 0x018, 0x039, 0x040,
+ 0x08e, 0x0a3, 0x0b8, 0x199, 0x1ac, 0x1c1, 0x3b1, 0x396,
+ 0x3be, 0x3ca, 0x09d, 0x03c, 0x015, 0x016, 0x01a, 0x03b,
+ 0x044, 0x091, 0x0a5, 0x0be, 0x196, 0x1ae, 0x1b9, 0x3a1,
+ 0x391, 0x3a5, 0x3d5, 0x094, 0x09a, 0x036, 0x038, 0x03a,
+ 0x041, 0x08c, 0x09b, 0x0b0, 0x0c3, 0x19e, 0x1ab, 0x1bc,
+ 0x39f, 0x38f, 0x3a9, 0x3cf, 0x093, 0x0bf, 0x03e, 0x03f,
+ 0x043, 0x045, 0x09e, 0x0a7, 0x0b9, 0x194, 0x1a2, 0x1ba,
+ 0x1c3, 0x3a6, 0x3a7, 0x3bb, 0x3d4, 0x09f, 0x1a0, 0x08f,
+ 0x08d, 0x090, 0x098, 0x0a6, 0x0b6, 0x0c4, 0x19f, 0x1af,
+ 0x1bf, 0x399, 0x3bf, 0x3b4, 0x3c9, 0x3e7, 0x0a8, 0x1b6,
+ 0x0ab, 0x0a4, 0x0aa, 0x0b2, 0x0c2, 0x0c5, 0x198, 0x1a4,
+ 0x1b8, 0x38c, 0x3a4, 0x3c4, 0x3c6, 0x3dd, 0x3e8, 0x0ad,
+ 0x3af, 0x192, 0x0bd, 0x0bc, 0x18e, 0x197, 0x19a, 0x1a3,
+ 0x1b1, 0x38d, 0x398, 0x3b7, 0x3d3, 0x3d1, 0x3db, 0x7dd,
+ 0x0b4, 0x3de, 0x1a9, 0x19b, 0x19c, 0x1a1, 0x1aa, 0x1ad,
+ 0x1b3, 0x38b, 0x3b2, 0x3b8, 0x3ce, 0x3e1, 0x3e0, 0x7d2,
+ 0x7e5, 0x0b7, 0x7e3, 0x1bb, 0x1a8, 0x1a6, 0x1b0, 0x1b2,
+ 0x1b7, 0x39b, 0x39a, 0x3ba, 0x3b5, 0x3d6, 0x7d7, 0x3e4,
+ 0x7d8, 0x7ea, 0x0ba, 0x7e8, 0x3a0, 0x1bd, 0x1b4, 0x38a,
+ 0x1c4, 0x392, 0x3aa, 0x3b0, 0x3bc, 0x3d7, 0x7d4, 0x7dc,
+ 0x7db, 0x7d5, 0x7f0, 0x0c1, 0x7fb, 0x3c8, 0x3a3, 0x395,
+ 0x39d, 0x3ac, 0x3ae, 0x3c5, 0x3d8, 0x3e2, 0x3e6, 0x7e4,
+ 0x7e7, 0x7e0, 0x7e9, 0x7f7, 0x190, 0x7f2, 0x393, 0x1be,
+ 0x1c0, 0x394, 0x397, 0x3ad, 0x3c3, 0x3c1, 0x3d2, 0x7da,
+ 0x7d9, 0x7df, 0x7eb, 0x7f4, 0x7fa, 0x195, 0x7f8, 0x3bd,
+ 0x39c, 0x3ab, 0x3a8, 0x3b3, 0x3b9, 0x3d0, 0x3e3, 0x3e5,
+ 0x7e2, 0x7de, 0x7ed, 0x7f1, 0x7f9, 0x7fc, 0x193, 0xffd,
+ 0x3dc, 0x3b6, 0x3c7, 0x3cc, 0x3cb, 0x3d9, 0x3da, 0x7d3,
+ 0x7e1, 0x7ee, 0x7ef, 0x7f5, 0x7f6, 0xffc, 0xfff, 0x19d,
+ 0x1c2, 0x0b5, 0x0a1, 0x096, 0x097, 0x095, 0x099, 0x0a0,
+ 0x0a2, 0x0ac, 0x0a9, 0x0b1, 0x0b3, 0x0bb, 0x0c0, 0x18f,
+ 0x004,
+};
+
+static const uint8_t bits11[289] = {
+ 4, 5, 6, 7, 8, 8, 9, 10, 10, 10, 11, 11, 12, 11, 12, 12,
+ 10, 5, 4, 5, 6, 7, 7, 8, 8, 9, 9, 9, 10, 10, 10, 10,
+ 11, 8, 6, 5, 5, 6, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10,
+ 10, 10, 8, 7, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 10,
+ 10, 10, 10, 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9,
+ 10, 10, 10, 10, 8, 8, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9,
+ 9, 10, 10, 10, 10, 8, 9, 8, 8, 8, 8, 8, 8, 8, 9, 9,
+ 9, 10, 10, 10, 10, 10, 8, 9, 8, 8, 8, 8, 8, 8, 9, 9,
+ 9, 10, 10, 10, 10, 10, 10, 8, 10, 9, 8, 8, 9, 9, 9, 9,
+ 9, 10, 10, 10, 10, 10, 10, 11, 8, 10, 9, 9, 9, 9, 9, 9,
+ 9, 10, 10, 10, 10, 10, 10, 11, 11, 8, 11, 9, 9, 9, 9, 9,
+ 9, 10, 10, 10, 10, 10, 11, 10, 11, 11, 8, 11, 10, 9, 9, 10,
+ 9, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 8, 11, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 9, 11, 10, 9,
+ 9, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 9, 11, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 9, 12,
+ 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 12, 12, 9,
+ 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9,
+ 5,
+};
+
+const uint16_t * const ff_aac_spectral_codes[11] = {
+ codes1, codes2, codes3, codes4, codes5, codes6, codes7, codes8,
+ codes9, codes10, codes11,
+};
+
+const uint8_t * const ff_aac_spectral_bits[11] = {
+ bits1, bits2, bits3, bits4, bits5, bits6, bits7, bits8,
+ bits9, bits10, bits11,
+};
+
+const uint16_t ff_aac_spectral_sizes[11] = {
+ 81, 81, 81, 81, 81, 81, 64, 64, 169, 169, 289,
+};
+
+/* NOTE:
+ * 64.0f is a special value indicating the existence of an escape code in the
+ * bitstream.
+ */
+static const DECLARE_ALIGNED(16, float, codebook_vector0)[324] = {
+ -1.0000000, -1.0000000, -1.0000000, -1.0000000,
+ -1.0000000, -1.0000000, -1.0000000, 0.0000000,
+ -1.0000000, -1.0000000, -1.0000000, 1.0000000,
+ -1.0000000, -1.0000000, 0.0000000, -1.0000000,
+ -1.0000000, -1.0000000, 0.0000000, 0.0000000,
+ -1.0000000, -1.0000000, 0.0000000, 1.0000000,
+ -1.0000000, -1.0000000, 1.0000000, -1.0000000,
+ -1.0000000, -1.0000000, 1.0000000, 0.0000000,
+ -1.0000000, -1.0000000, 1.0000000, 1.0000000,
+ -1.0000000, 0.0000000, -1.0000000, -1.0000000,
+ -1.0000000, 0.0000000, -1.0000000, 0.0000000,
+ -1.0000000, 0.0000000, -1.0000000, 1.0000000,
+ -1.0000000, 0.0000000, 0.0000000, -1.0000000,
+ -1.0000000, 0.0000000, 0.0000000, 0.0000000,
+ -1.0000000, 0.0000000, 0.0000000, 1.0000000,
+ -1.0000000, 0.0000000, 1.0000000, -1.0000000,
+ -1.0000000, 0.0000000, 1.0000000, 0.0000000,
+ -1.0000000, 0.0000000, 1.0000000, 1.0000000,
+ -1.0000000, 1.0000000, -1.0000000, -1.0000000,
+ -1.0000000, 1.0000000, -1.0000000, 0.0000000,
+ -1.0000000, 1.0000000, -1.0000000, 1.0000000,
+ -1.0000000, 1.0000000, 0.0000000, -1.0000000,
+ -1.0000000, 1.0000000, 0.0000000, 0.0000000,
+ -1.0000000, 1.0000000, 0.0000000, 1.0000000,
+ -1.0000000, 1.0000000, 1.0000000, -1.0000000,
+ -1.0000000, 1.0000000, 1.0000000, 0.0000000,
+ -1.0000000, 1.0000000, 1.0000000, 1.0000000,
+ 0.0000000, -1.0000000, -1.0000000, -1.0000000,
+ 0.0000000, -1.0000000, -1.0000000, 0.0000000,
+ 0.0000000, -1.0000000, -1.0000000, 1.0000000,
+ 0.0000000, -1.0000000, 0.0000000, -1.0000000,
+ 0.0000000, -1.0000000, 0.0000000, 0.0000000,
+ 0.0000000, -1.0000000, 0.0000000, 1.0000000,
+ 0.0000000, -1.0000000, 1.0000000, -1.0000000,
+ 0.0000000, -1.0000000, 1.0000000, 0.0000000,
+ 0.0000000, -1.0000000, 1.0000000, 1.0000000,
+ 0.0000000, 0.0000000, -1.0000000, -1.0000000,
+ 0.0000000, 0.0000000, -1.0000000, 0.0000000,
+ 0.0000000, 0.0000000, -1.0000000, 1.0000000,
+ 0.0000000, 0.0000000, 0.0000000, -1.0000000,
+ 0.0000000, 0.0000000, 0.0000000, 0.0000000,
+ 0.0000000, 0.0000000, 0.0000000, 1.0000000,
+ 0.0000000, 0.0000000, 1.0000000, -1.0000000,
+ 0.0000000, 0.0000000, 1.0000000, 0.0000000,
+ 0.0000000, 0.0000000, 1.0000000, 1.0000000,
+ 0.0000000, 1.0000000, -1.0000000, -1.0000000,
+ 0.0000000, 1.0000000, -1.0000000, 0.0000000,
+ 0.0000000, 1.0000000, -1.0000000, 1.0000000,
+ 0.0000000, 1.0000000, 0.0000000, -1.0000000,
+ 0.0000000, 1.0000000, 0.0000000, 0.0000000,
+ 0.0000000, 1.0000000, 0.0000000, 1.0000000,
+ 0.0000000, 1.0000000, 1.0000000, -1.0000000,
+ 0.0000000, 1.0000000, 1.0000000, 0.0000000,
+ 0.0000000, 1.0000000, 1.0000000, 1.0000000,
+ 1.0000000, -1.0000000, -1.0000000, -1.0000000,
+ 1.0000000, -1.0000000, -1.0000000, 0.0000000,
+ 1.0000000, -1.0000000, -1.0000000, 1.0000000,
+ 1.0000000, -1.0000000, 0.0000000, -1.0000000,
+ 1.0000000, -1.0000000, 0.0000000, 0.0000000,
+ 1.0000000, -1.0000000, 0.0000000, 1.0000000,
+ 1.0000000, -1.0000000, 1.0000000, -1.0000000,
+ 1.0000000, -1.0000000, 1.0000000, 0.0000000,
+ 1.0000000, -1.0000000, 1.0000000, 1.0000000,
+ 1.0000000, 0.0000000, -1.0000000, -1.0000000,
+ 1.0000000, 0.0000000, -1.0000000, 0.0000000,
+ 1.0000000, 0.0000000, -1.0000000, 1.0000000,
+ 1.0000000, 0.0000000, 0.0000000, -1.0000000,
+ 1.0000000, 0.0000000, 0.0000000, 0.0000000,
+ 1.0000000, 0.0000000, 0.0000000, 1.0000000,
+ 1.0000000, 0.0000000, 1.0000000, -1.0000000,
+ 1.0000000, 0.0000000, 1.0000000, 0.0000000,
+ 1.0000000, 0.0000000, 1.0000000, 1.0000000,
+ 1.0000000, 1.0000000, -1.0000000, -1.0000000,
+ 1.0000000, 1.0000000, -1.0000000, 0.0000000,
+ 1.0000000, 1.0000000, -1.0000000, 1.0000000,
+ 1.0000000, 1.0000000, 0.0000000, -1.0000000,
+ 1.0000000, 1.0000000, 0.0000000, 0.0000000,
+ 1.0000000, 1.0000000, 0.0000000, 1.0000000,
+ 1.0000000, 1.0000000, 1.0000000, -1.0000000,
+ 1.0000000, 1.0000000, 1.0000000, 0.0000000,
+ 1.0000000, 1.0000000, 1.0000000, 1.0000000,
+};
+
+static const DECLARE_ALIGNED(16, float, codebook_vector2)[324] = {
+ 0.0000000, 0.0000000, 0.0000000, 0.0000000,
+ 0.0000000, 0.0000000, 0.0000000, 1.0000000,
+ 0.0000000, 0.0000000, 0.0000000, 2.5198421,
+ 0.0000000, 0.0000000, 1.0000000, 0.0000000,
+ 0.0000000, 0.0000000, 1.0000000, 1.0000000,
+ 0.0000000, 0.0000000, 1.0000000, 2.5198421,
+ 0.0000000, 0.0000000, 2.5198421, 0.0000000,
+ 0.0000000, 0.0000000, 2.5198421, 1.0000000,
+ 0.0000000, 0.0000000, 2.5198421, 2.5198421,
+ 0.0000000, 1.0000000, 0.0000000, 0.0000000,
+ 0.0000000, 1.0000000, 0.0000000, 1.0000000,
+ 0.0000000, 1.0000000, 0.0000000, 2.5198421,
+ 0.0000000, 1.0000000, 1.0000000, 0.0000000,
+ 0.0000000, 1.0000000, 1.0000000, 1.0000000,
+ 0.0000000, 1.0000000, 1.0000000, 2.5198421,
+ 0.0000000, 1.0000000, 2.5198421, 0.0000000,
+ 0.0000000, 1.0000000, 2.5198421, 1.0000000,
+ 0.0000000, 1.0000000, 2.5198421, 2.5198421,
+ 0.0000000, 2.5198421, 0.0000000, 0.0000000,
+ 0.0000000, 2.5198421, 0.0000000, 1.0000000,
+ 0.0000000, 2.5198421, 0.0000000, 2.5198421,
+ 0.0000000, 2.5198421, 1.0000000, 0.0000000,
+ 0.0000000, 2.5198421, 1.0000000, 1.0000000,
+ 0.0000000, 2.5198421, 1.0000000, 2.5198421,
+ 0.0000000, 2.5198421, 2.5198421, 0.0000000,
+ 0.0000000, 2.5198421, 2.5198421, 1.0000000,
+ 0.0000000, 2.5198421, 2.5198421, 2.5198421,
+ 1.0000000, 0.0000000, 0.0000000, 0.0000000,
+ 1.0000000, 0.0000000, 0.0000000, 1.0000000,
+ 1.0000000, 0.0000000, 0.0000000, 2.5198421,
+ 1.0000000, 0.0000000, 1.0000000, 0.0000000,
+ 1.0000000, 0.0000000, 1.0000000, 1.0000000,
+ 1.0000000, 0.0000000, 1.0000000, 2.5198421,
+ 1.0000000, 0.0000000, 2.5198421, 0.0000000,
+ 1.0000000, 0.0000000, 2.5198421, 1.0000000,
+ 1.0000000, 0.0000000, 2.5198421, 2.5198421,
+ 1.0000000, 1.0000000, 0.0000000, 0.0000000,
+ 1.0000000, 1.0000000, 0.0000000, 1.0000000,
+ 1.0000000, 1.0000000, 0.0000000, 2.5198421,
+ 1.0000000, 1.0000000, 1.0000000, 0.0000000,
+ 1.0000000, 1.0000000, 1.0000000, 1.0000000,
+ 1.0000000, 1.0000000, 1.0000000, 2.5198421,
+ 1.0000000, 1.0000000, 2.5198421, 0.0000000,
+ 1.0000000, 1.0000000, 2.5198421, 1.0000000,
+ 1.0000000, 1.0000000, 2.5198421, 2.5198421,
+ 1.0000000, 2.5198421, 0.0000000, 0.0000000,
+ 1.0000000, 2.5198421, 0.0000000, 1.0000000,
+ 1.0000000, 2.5198421, 0.0000000, 2.5198421,
+ 1.0000000, 2.5198421, 1.0000000, 0.0000000,
+ 1.0000000, 2.5198421, 1.0000000, 1.0000000,
+ 1.0000000, 2.5198421, 1.0000000, 2.5198421,
+ 1.0000000, 2.5198421, 2.5198421, 0.0000000,
+ 1.0000000, 2.5198421, 2.5198421, 1.0000000,
+ 1.0000000, 2.5198421, 2.5198421, 2.5198421,
+ 2.5198421, 0.0000000, 0.0000000, 0.0000000,
+ 2.5198421, 0.0000000, 0.0000000, 1.0000000,
+ 2.5198421, 0.0000000, 0.0000000, 2.5198421,
+ 2.5198421, 0.0000000, 1.0000000, 0.0000000,
+ 2.5198421, 0.0000000, 1.0000000, 1.0000000,
+ 2.5198421, 0.0000000, 1.0000000, 2.5198421,
+ 2.5198421, 0.0000000, 2.5198421, 0.0000000,
+ 2.5198421, 0.0000000, 2.5198421, 1.0000000,
+ 2.5198421, 0.0000000, 2.5198421, 2.5198421,
+ 2.5198421, 1.0000000, 0.0000000, 0.0000000,
+ 2.5198421, 1.0000000, 0.0000000, 1.0000000,
+ 2.5198421, 1.0000000, 0.0000000, 2.5198421,
+ 2.5198421, 1.0000000, 1.0000000, 0.0000000,
+ 2.5198421, 1.0000000, 1.0000000, 1.0000000,
+ 2.5198421, 1.0000000, 1.0000000, 2.5198421,
+ 2.5198421, 1.0000000, 2.5198421, 0.0000000,
+ 2.5198421, 1.0000000, 2.5198421, 1.0000000,
+ 2.5198421, 1.0000000, 2.5198421, 2.5198421,
+ 2.5198421, 2.5198421, 0.0000000, 0.0000000,
+ 2.5198421, 2.5198421, 0.0000000, 1.0000000,
+ 2.5198421, 2.5198421, 0.0000000, 2.5198421,
+ 2.5198421, 2.5198421, 1.0000000, 0.0000000,
+ 2.5198421, 2.5198421, 1.0000000, 1.0000000,
+ 2.5198421, 2.5198421, 1.0000000, 2.5198421,
+ 2.5198421, 2.5198421, 2.5198421, 0.0000000,
+ 2.5198421, 2.5198421, 2.5198421, 1.0000000,
+ 2.5198421, 2.5198421, 2.5198421, 2.5198421,
+};
+
+static const DECLARE_ALIGNED(16, float, codebook_vector4)[162] = {
+ -6.3496042, -6.3496042, -6.3496042, -4.3267487,
+ -6.3496042, -2.5198421, -6.3496042, -1.0000000,
+ -6.3496042, 0.0000000, -6.3496042, 1.0000000,
+ -6.3496042, 2.5198421, -6.3496042, 4.3267487,
+ -6.3496042, 6.3496042, -4.3267487, -6.3496042,
+ -4.3267487, -4.3267487, -4.3267487, -2.5198421,
+ -4.3267487, -1.0000000, -4.3267487, 0.0000000,
+ -4.3267487, 1.0000000, -4.3267487, 2.5198421,
+ -4.3267487, 4.3267487, -4.3267487, 6.3496042,
+ -2.5198421, -6.3496042, -2.5198421, -4.3267487,
+ -2.5198421, -2.5198421, -2.5198421, -1.0000000,
+ -2.5198421, 0.0000000, -2.5198421, 1.0000000,
+ -2.5198421, 2.5198421, -2.5198421, 4.3267487,
+ -2.5198421, 6.3496042, -1.0000000, -6.3496042,
+ -1.0000000, -4.3267487, -1.0000000, -2.5198421,
+ -1.0000000, -1.0000000, -1.0000000, 0.0000000,
+ -1.0000000, 1.0000000, -1.0000000, 2.5198421,
+ -1.0000000, 4.3267487, -1.0000000, 6.3496042,
+ 0.0000000, -6.3496042, 0.0000000, -4.3267487,
+ 0.0000000, -2.5198421, 0.0000000, -1.0000000,
+ 0.0000000, 0.0000000, 0.0000000, 1.0000000,
+ 0.0000000, 2.5198421, 0.0000000, 4.3267487,
+ 0.0000000, 6.3496042, 1.0000000, -6.3496042,
+ 1.0000000, -4.3267487, 1.0000000, -2.5198421,
+ 1.0000000, -1.0000000, 1.0000000, 0.0000000,
+ 1.0000000, 1.0000000, 1.0000000, 2.5198421,
+ 1.0000000, 4.3267487, 1.0000000, 6.3496042,
+ 2.5198421, -6.3496042, 2.5198421, -4.3267487,
+ 2.5198421, -2.5198421, 2.5198421, -1.0000000,
+ 2.5198421, 0.0000000, 2.5198421, 1.0000000,
+ 2.5198421, 2.5198421, 2.5198421, 4.3267487,
+ 2.5198421, 6.3496042, 4.3267487, -6.3496042,
+ 4.3267487, -4.3267487, 4.3267487, -2.5198421,
+ 4.3267487, -1.0000000, 4.3267487, 0.0000000,
+ 4.3267487, 1.0000000, 4.3267487, 2.5198421,
+ 4.3267487, 4.3267487, 4.3267487, 6.3496042,
+ 6.3496042, -6.3496042, 6.3496042, -4.3267487,
+ 6.3496042, -2.5198421, 6.3496042, -1.0000000,
+ 6.3496042, 0.0000000, 6.3496042, 1.0000000,
+ 6.3496042, 2.5198421, 6.3496042, 4.3267487,
+ 6.3496042, 6.3496042,
+};
+
+static const DECLARE_ALIGNED(16, float, codebook_vector6)[128] = {
+ 0.0000000, 0.0000000, 0.0000000, 1.0000000,
+ 0.0000000, 2.5198421, 0.0000000, 4.3267487,
+ 0.0000000, 6.3496042, 0.0000000, 8.5498797,
+ 0.0000000, 10.9027236, 0.0000000, 13.3905183,
+ 1.0000000, 0.0000000, 1.0000000, 1.0000000,
+ 1.0000000, 2.5198421, 1.0000000, 4.3267487,
+ 1.0000000, 6.3496042, 1.0000000, 8.5498797,
+ 1.0000000, 10.9027236, 1.0000000, 13.3905183,
+ 2.5198421, 0.0000000, 2.5198421, 1.0000000,
+ 2.5198421, 2.5198421, 2.5198421, 4.3267487,
+ 2.5198421, 6.3496042, 2.5198421, 8.5498797,
+ 2.5198421, 10.9027236, 2.5198421, 13.3905183,
+ 4.3267487, 0.0000000, 4.3267487, 1.0000000,
+ 4.3267487, 2.5198421, 4.3267487, 4.3267487,
+ 4.3267487, 6.3496042, 4.3267487, 8.5498797,
+ 4.3267487, 10.9027236, 4.3267487, 13.3905183,
+ 6.3496042, 0.0000000, 6.3496042, 1.0000000,
+ 6.3496042, 2.5198421, 6.3496042, 4.3267487,
+ 6.3496042, 6.3496042, 6.3496042, 8.5498797,
+ 6.3496042, 10.9027236, 6.3496042, 13.3905183,
+ 8.5498797, 0.0000000, 8.5498797, 1.0000000,
+ 8.5498797, 2.5198421, 8.5498797, 4.3267487,
+ 8.5498797, 6.3496042, 8.5498797, 8.5498797,
+ 8.5498797, 10.9027236, 8.5498797, 13.3905183,
+ 10.9027236, 0.0000000, 10.9027236, 1.0000000,
+ 10.9027236, 2.5198421, 10.9027236, 4.3267487,
+ 10.9027236, 6.3496042, 10.9027236, 8.5498797,
+ 10.9027236, 10.9027236, 10.9027236, 13.3905183,
+ 13.3905183, 0.0000000, 13.3905183, 1.0000000,
+ 13.3905183, 2.5198421, 13.3905183, 4.3267487,
+ 13.3905183, 6.3496042, 13.3905183, 8.5498797,
+ 13.3905183, 10.9027236, 13.3905183, 13.3905183,
+};
+
+static const DECLARE_ALIGNED(16, float, codebook_vector8)[338] = {
+ 0.0000000, 0.0000000, 0.0000000, 1.0000000,
+ 0.0000000, 2.5198421, 0.0000000, 4.3267487,
+ 0.0000000, 6.3496042, 0.0000000, 8.5498797,
+ 0.0000000, 10.9027236, 0.0000000, 13.3905183,
+ 0.0000000, 16.0000000, 0.0000000, 18.7207544,
+ 0.0000000, 21.5443469, 0.0000000, 24.4637810,
+ 0.0000000, 27.4731418, 1.0000000, 0.0000000,
+ 1.0000000, 1.0000000, 1.0000000, 2.5198421,
+ 1.0000000, 4.3267487, 1.0000000, 6.3496042,
+ 1.0000000, 8.5498797, 1.0000000, 10.9027236,
+ 1.0000000, 13.3905183, 1.0000000, 16.0000000,
+ 1.0000000, 18.7207544, 1.0000000, 21.5443469,
+ 1.0000000, 24.4637810, 1.0000000, 27.4731418,
+ 2.5198421, 0.0000000, 2.5198421, 1.0000000,
+ 2.5198421, 2.5198421, 2.5198421, 4.3267487,
+ 2.5198421, 6.3496042, 2.5198421, 8.5498797,
+ 2.5198421, 10.9027236, 2.5198421, 13.3905183,
+ 2.5198421, 16.0000000, 2.5198421, 18.7207544,
+ 2.5198421, 21.5443469, 2.5198421, 24.4637810,
+ 2.5198421, 27.4731418, 4.3267487, 0.0000000,
+ 4.3267487, 1.0000000, 4.3267487, 2.5198421,
+ 4.3267487, 4.3267487, 4.3267487, 6.3496042,
+ 4.3267487, 8.5498797, 4.3267487, 10.9027236,
+ 4.3267487, 13.3905183, 4.3267487, 16.0000000,
+ 4.3267487, 18.7207544, 4.3267487, 21.5443469,
+ 4.3267487, 24.4637810, 4.3267487, 27.4731418,
+ 6.3496042, 0.0000000, 6.3496042, 1.0000000,
+ 6.3496042, 2.5198421, 6.3496042, 4.3267487,
+ 6.3496042, 6.3496042, 6.3496042, 8.5498797,
+ 6.3496042, 10.9027236, 6.3496042, 13.3905183,
+ 6.3496042, 16.0000000, 6.3496042, 18.7207544,
+ 6.3496042, 21.5443469, 6.3496042, 24.4637810,
+ 6.3496042, 27.4731418, 8.5498797, 0.0000000,
+ 8.5498797, 1.0000000, 8.5498797, 2.5198421,
+ 8.5498797, 4.3267487, 8.5498797, 6.3496042,
+ 8.5498797, 8.5498797, 8.5498797, 10.9027236,
+ 8.5498797, 13.3905183, 8.5498797, 16.0000000,
+ 8.5498797, 18.7207544, 8.5498797, 21.5443469,
+ 8.5498797, 24.4637810, 8.5498797, 27.4731418,
+ 10.9027236, 0.0000000, 10.9027236, 1.0000000,
+ 10.9027236, 2.5198421, 10.9027236, 4.3267487,
+ 10.9027236, 6.3496042, 10.9027236, 8.5498797,
+ 10.9027236, 10.9027236, 10.9027236, 13.3905183,
+ 10.9027236, 16.0000000, 10.9027236, 18.7207544,
+ 10.9027236, 21.5443469, 10.9027236, 24.4637810,
+ 10.9027236, 27.4731418, 13.3905183, 0.0000000,
+ 13.3905183, 1.0000000, 13.3905183, 2.5198421,
+ 13.3905183, 4.3267487, 13.3905183, 6.3496042,
+ 13.3905183, 8.5498797, 13.3905183, 10.9027236,
+ 13.3905183, 13.3905183, 13.3905183, 16.0000000,
+ 13.3905183, 18.7207544, 13.3905183, 21.5443469,
+ 13.3905183, 24.4637810, 13.3905183, 27.4731418,
+ 16.0000000, 0.0000000, 16.0000000, 1.0000000,
+ 16.0000000, 2.5198421, 16.0000000, 4.3267487,
+ 16.0000000, 6.3496042, 16.0000000, 8.5498797,
+ 16.0000000, 10.9027236, 16.0000000, 13.3905183,
+ 16.0000000, 16.0000000, 16.0000000, 18.7207544,
+ 16.0000000, 21.5443469, 16.0000000, 24.4637810,
+ 16.0000000, 27.4731418, 18.7207544, 0.0000000,
+ 18.7207544, 1.0000000, 18.7207544, 2.5198421,
+ 18.7207544, 4.3267487, 18.7207544, 6.3496042,
+ 18.7207544, 8.5498797, 18.7207544, 10.9027236,
+ 18.7207544, 13.3905183, 18.7207544, 16.0000000,
+ 18.7207544, 18.7207544, 18.7207544, 21.5443469,
+ 18.7207544, 24.4637810, 18.7207544, 27.4731418,
+ 21.5443469, 0.0000000, 21.5443469, 1.0000000,
+ 21.5443469, 2.5198421, 21.5443469, 4.3267487,
+ 21.5443469, 6.3496042, 21.5443469, 8.5498797,
+ 21.5443469, 10.9027236, 21.5443469, 13.3905183,
+ 21.5443469, 16.0000000, 21.5443469, 18.7207544,
+ 21.5443469, 21.5443469, 21.5443469, 24.4637810,
+ 21.5443469, 27.4731418, 24.4637810, 0.0000000,
+ 24.4637810, 1.0000000, 24.4637810, 2.5198421,
+ 24.4637810, 4.3267487, 24.4637810, 6.3496042,
+ 24.4637810, 8.5498797, 24.4637810, 10.9027236,
+ 24.4637810, 13.3905183, 24.4637810, 16.0000000,
+ 24.4637810, 18.7207544, 24.4637810, 21.5443469,
+ 24.4637810, 24.4637810, 24.4637810, 27.4731418,
+ 27.4731418, 0.0000000, 27.4731418, 1.0000000,
+ 27.4731418, 2.5198421, 27.4731418, 4.3267487,
+ 27.4731418, 6.3496042, 27.4731418, 8.5498797,
+ 27.4731418, 10.9027236, 27.4731418, 13.3905183,
+ 27.4731418, 16.0000000, 27.4731418, 18.7207544,
+ 27.4731418, 21.5443469, 27.4731418, 24.4637810,
+ 27.4731418, 27.4731418,
+};
+
+static const DECLARE_ALIGNED(16, float, codebook_vector10)[578] = {
+ 0.0000000, 0.0000000, 0.0000000, 1.0000000,
+ 0.0000000, 2.5198421, 0.0000000, 4.3267487,
+ 0.0000000, 6.3496042, 0.0000000, 8.5498797,
+ 0.0000000, 10.9027236, 0.0000000, 13.3905183,
+ 0.0000000, 16.0000000, 0.0000000, 18.7207544,
+ 0.0000000, 21.5443469, 0.0000000, 24.4637810,
+ 0.0000000, 27.4731418, 0.0000000, 30.5673509,
+ 0.0000000, 33.7419917, 0.0000000, 36.9931811,
+ 0.0000000, 64.0f, 1.0000000, 0.0000000,
+ 1.0000000, 1.0000000, 1.0000000, 2.5198421,
+ 1.0000000, 4.3267487, 1.0000000, 6.3496042,
+ 1.0000000, 8.5498797, 1.0000000, 10.9027236,
+ 1.0000000, 13.3905183, 1.0000000, 16.0000000,
+ 1.0000000, 18.7207544, 1.0000000, 21.5443469,
+ 1.0000000, 24.4637810, 1.0000000, 27.4731418,
+ 1.0000000, 30.5673509, 1.0000000, 33.7419917,
+ 1.0000000, 36.9931811, 1.0000000, 64.0f,
+ 2.5198421, 0.0000000, 2.5198421, 1.0000000,
+ 2.5198421, 2.5198421, 2.5198421, 4.3267487,
+ 2.5198421, 6.3496042, 2.5198421, 8.5498797,
+ 2.5198421, 10.9027236, 2.5198421, 13.3905183,
+ 2.5198421, 16.0000000, 2.5198421, 18.7207544,
+ 2.5198421, 21.5443469, 2.5198421, 24.4637810,
+ 2.5198421, 27.4731418, 2.5198421, 30.5673509,
+ 2.5198421, 33.7419917, 2.5198421, 36.9931811,
+ 2.5198421, 64.0f, 4.3267487, 0.0000000,
+ 4.3267487, 1.0000000, 4.3267487, 2.5198421,
+ 4.3267487, 4.3267487, 4.3267487, 6.3496042,
+ 4.3267487, 8.5498797, 4.3267487, 10.9027236,
+ 4.3267487, 13.3905183, 4.3267487, 16.0000000,
+ 4.3267487, 18.7207544, 4.3267487, 21.5443469,
+ 4.3267487, 24.4637810, 4.3267487, 27.4731418,
+ 4.3267487, 30.5673509, 4.3267487, 33.7419917,
+ 4.3267487, 36.9931811, 4.3267487, 64.0f,
+ 6.3496042, 0.0000000, 6.3496042, 1.0000000,
+ 6.3496042, 2.5198421, 6.3496042, 4.3267487,
+ 6.3496042, 6.3496042, 6.3496042, 8.5498797,
+ 6.3496042, 10.9027236, 6.3496042, 13.3905183,
+ 6.3496042, 16.0000000, 6.3496042, 18.7207544,
+ 6.3496042, 21.5443469, 6.3496042, 24.4637810,
+ 6.3496042, 27.4731418, 6.3496042, 30.5673509,
+ 6.3496042, 33.7419917, 6.3496042, 36.9931811,
+ 6.3496042, 64.0f, 8.5498797, 0.0000000,
+ 8.5498797, 1.0000000, 8.5498797, 2.5198421,
+ 8.5498797, 4.3267487, 8.5498797, 6.3496042,
+ 8.5498797, 8.5498797, 8.5498797, 10.9027236,
+ 8.5498797, 13.3905183, 8.5498797, 16.0000000,
+ 8.5498797, 18.7207544, 8.5498797, 21.5443469,
+ 8.5498797, 24.4637810, 8.5498797, 27.4731418,
+ 8.5498797, 30.5673509, 8.5498797, 33.7419917,
+ 8.5498797, 36.9931811, 8.5498797, 64.0f,
+ 10.9027236, 0.0000000, 10.9027236, 1.0000000,
+ 10.9027236, 2.5198421, 10.9027236, 4.3267487,
+ 10.9027236, 6.3496042, 10.9027236, 8.5498797,
+ 10.9027236, 10.9027236, 10.9027236, 13.3905183,
+ 10.9027236, 16.0000000, 10.9027236, 18.7207544,
+ 10.9027236, 21.5443469, 10.9027236, 24.4637810,
+ 10.9027236, 27.4731418, 10.9027236, 30.5673509,
+ 10.9027236, 33.7419917, 10.9027236, 36.9931811,
+ 10.9027236, 64.0f, 13.3905183, 0.0000000,
+ 13.3905183, 1.0000000, 13.3905183, 2.5198421,
+ 13.3905183, 4.3267487, 13.3905183, 6.3496042,
+ 13.3905183, 8.5498797, 13.3905183, 10.9027236,
+ 13.3905183, 13.3905183, 13.3905183, 16.0000000,
+ 13.3905183, 18.7207544, 13.3905183, 21.5443469,
+ 13.3905183, 24.4637810, 13.3905183, 27.4731418,
+ 13.3905183, 30.5673509, 13.3905183, 33.7419917,
+ 13.3905183, 36.9931811, 13.3905183, 64.0f,
+ 16.0000000, 0.0000000, 16.0000000, 1.0000000,
+ 16.0000000, 2.5198421, 16.0000000, 4.3267487,
+ 16.0000000, 6.3496042, 16.0000000, 8.5498797,
+ 16.0000000, 10.9027236, 16.0000000, 13.3905183,
+ 16.0000000, 16.0000000, 16.0000000, 18.7207544,
+ 16.0000000, 21.5443469, 16.0000000, 24.4637810,
+ 16.0000000, 27.4731418, 16.0000000, 30.5673509,
+ 16.0000000, 33.7419917, 16.0000000, 36.9931811,
+ 16.0000000, 64.0f, 18.7207544, 0.0000000,
+ 18.7207544, 1.0000000, 18.7207544, 2.5198421,
+ 18.7207544, 4.3267487, 18.7207544, 6.3496042,
+ 18.7207544, 8.5498797, 18.7207544, 10.9027236,
+ 18.7207544, 13.3905183, 18.7207544, 16.0000000,
+ 18.7207544, 18.7207544, 18.7207544, 21.5443469,
+ 18.7207544, 24.4637810, 18.7207544, 27.4731418,
+ 18.7207544, 30.5673509, 18.7207544, 33.7419917,
+ 18.7207544, 36.9931811, 18.7207544, 64.0f,
+ 21.5443469, 0.0000000, 21.5443469, 1.0000000,
+ 21.5443469, 2.5198421, 21.5443469, 4.3267487,
+ 21.5443469, 6.3496042, 21.5443469, 8.5498797,
+ 21.5443469, 10.9027236, 21.5443469, 13.3905183,
+ 21.5443469, 16.0000000, 21.5443469, 18.7207544,
+ 21.5443469, 21.5443469, 21.5443469, 24.4637810,
+ 21.5443469, 27.4731418, 21.5443469, 30.5673509,
+ 21.5443469, 33.7419917, 21.5443469, 36.9931811,
+ 21.5443469, 64.0f, 24.4637810, 0.0000000,
+ 24.4637810, 1.0000000, 24.4637810, 2.5198421,
+ 24.4637810, 4.3267487, 24.4637810, 6.3496042,
+ 24.4637810, 8.5498797, 24.4637810, 10.9027236,
+ 24.4637810, 13.3905183, 24.4637810, 16.0000000,
+ 24.4637810, 18.7207544, 24.4637810, 21.5443469,
+ 24.4637810, 24.4637810, 24.4637810, 27.4731418,
+ 24.4637810, 30.5673509, 24.4637810, 33.7419917,
+ 24.4637810, 36.9931811, 24.4637810, 64.0f,
+ 27.4731418, 0.0000000, 27.4731418, 1.0000000,
+ 27.4731418, 2.5198421, 27.4731418, 4.3267487,
+ 27.4731418, 6.3496042, 27.4731418, 8.5498797,
+ 27.4731418, 10.9027236, 27.4731418, 13.3905183,
+ 27.4731418, 16.0000000, 27.4731418, 18.7207544,
+ 27.4731418, 21.5443469, 27.4731418, 24.4637810,
+ 27.4731418, 27.4731418, 27.4731418, 30.5673509,
+ 27.4731418, 33.7419917, 27.4731418, 36.9931811,
+ 27.4731418, 64.0f, 30.5673509, 0.0000000,
+ 30.5673509, 1.0000000, 30.5673509, 2.5198421,
+ 30.5673509, 4.3267487, 30.5673509, 6.3496042,
+ 30.5673509, 8.5498797, 30.5673509, 10.9027236,
+ 30.5673509, 13.3905183, 30.5673509, 16.0000000,
+ 30.5673509, 18.7207544, 30.5673509, 21.5443469,
+ 30.5673509, 24.4637810, 30.5673509, 27.4731418,
+ 30.5673509, 30.5673509, 30.5673509, 33.7419917,
+ 30.5673509, 36.9931811, 30.5673509, 64.0f,
+ 33.7419917, 0.0000000, 33.7419917, 1.0000000,
+ 33.7419917, 2.5198421, 33.7419917, 4.3267487,
+ 33.7419917, 6.3496042, 33.7419917, 8.5498797,
+ 33.7419917, 10.9027236, 33.7419917, 13.3905183,
+ 33.7419917, 16.0000000, 33.7419917, 18.7207544,
+ 33.7419917, 21.5443469, 33.7419917, 24.4637810,
+ 33.7419917, 27.4731418, 33.7419917, 30.5673509,
+ 33.7419917, 33.7419917, 33.7419917, 36.9931811,
+ 33.7419917, 64.0f, 36.9931811, 0.0000000,
+ 36.9931811, 1.0000000, 36.9931811, 2.5198421,
+ 36.9931811, 4.3267487, 36.9931811, 6.3496042,
+ 36.9931811, 8.5498797, 36.9931811, 10.9027236,
+ 36.9931811, 13.3905183, 36.9931811, 16.0000000,
+ 36.9931811, 18.7207544, 36.9931811, 21.5443469,
+ 36.9931811, 24.4637810, 36.9931811, 27.4731418,
+ 36.9931811, 30.5673509, 36.9931811, 33.7419917,
+ 36.9931811, 36.9931811, 36.9931811, 64.0f,
+ 64.0f, 0.0000000, 64.0f, 1.0000000,
+ 64.0f, 2.5198421, 64.0f, 4.3267487,
+ 64.0f, 6.3496042, 64.0f, 8.5498797,
+ 64.0f, 10.9027236, 64.0f, 13.3905183,
+ 64.0f, 16.0000000, 64.0f, 18.7207544,
+ 64.0f, 21.5443469, 64.0f, 24.4637810,
+ 64.0f, 27.4731418, 64.0f, 30.5673509,
+ 64.0f, 33.7419917, 64.0f, 36.9931811,
+ 64.0f, 64.0f,
+};
+
+const float * const ff_aac_codebook_vectors[] = {
+ codebook_vector0, codebook_vector0, codebook_vector2,
+ codebook_vector2, codebook_vector4, codebook_vector4,
+ codebook_vector6, codebook_vector6, codebook_vector8,
+ codebook_vector8, codebook_vector10,
+};
+
+static const float codebook_vector0_vals[] = {
+ -1.0000000, 0.0000000, 1.0000000
+};
+
+/*
+ * bits 0:1, 2:3, 4:5, 6:7 index into _vals array
+ * 8:11 number of non-zero values
+ * 12:15 bit mask of non-zero values
+ */
+static const uint16_t codebook_vector02_idx[] = {
+ 0x0000, 0x8140, 0x8180, 0x4110, 0xc250, 0xc290, 0x4120, 0xc260, 0xc2a0,
+ 0x2104, 0xa244, 0xa284, 0x6214, 0xe354, 0xe394, 0x6224, 0xe364, 0xe3a4,
+ 0x2108, 0xa248, 0xa288, 0x6218, 0xe358, 0xe398, 0x6228, 0xe368, 0xe3a8,
+ 0x1101, 0x9241, 0x9281, 0x5211, 0xd351, 0xd391, 0x5221, 0xd361, 0xd3a1,
+ 0x3205, 0xb345, 0xb385, 0x7315, 0xf455, 0xf495, 0x7325, 0xf465, 0xf4a5,
+ 0x3209, 0xb349, 0xb389, 0x7319, 0xf459, 0xf499, 0x7329, 0xf469, 0xf4a9,
+ 0x1102, 0x9242, 0x9282, 0x5212, 0xd352, 0xd392, 0x5222, 0xd362, 0xd3a2,
+ 0x3206, 0xb346, 0xb386, 0x7316, 0xf456, 0xf496, 0x7326, 0xf466, 0xf4a6,
+ 0x320a, 0xb34a, 0xb38a, 0x731a, 0xf45a, 0xf49a, 0x732a, 0xf46a, 0xf4aa,
+};
+
+static const float codebook_vector4_vals[] = {
+ -6.3496042, -4.3267487,
+ -2.5198421, -1.0000000,
+ 0.0000000, 1.0000000,
+ 2.5198421, 4.3267487,
+ 6.3496042,
+};
+
+/*
+ * bits 0:3, 4:7 index into _vals array
+ */
+static const uint16_t codebook_vector4_idx[] = {
+ 0x0000, 0x0010, 0x0020, 0x0030, 0x0040, 0x0050, 0x0060, 0x0070, 0x0080,
+ 0x0001, 0x0011, 0x0021, 0x0031, 0x0041, 0x0051, 0x0061, 0x0071, 0x0081,
+ 0x0002, 0x0012, 0x0022, 0x0032, 0x0042, 0x0052, 0x0062, 0x0072, 0x0082,
+ 0x0003, 0x0013, 0x0023, 0x0033, 0x0043, 0x0053, 0x0063, 0x0073, 0x0083,
+ 0x0004, 0x0014, 0x0024, 0x0034, 0x0044, 0x0054, 0x0064, 0x0074, 0x0084,
+ 0x0005, 0x0015, 0x0025, 0x0035, 0x0045, 0x0055, 0x0065, 0x0075, 0x0085,
+ 0x0006, 0x0016, 0x0026, 0x0036, 0x0046, 0x0056, 0x0066, 0x0076, 0x0086,
+ 0x0007, 0x0017, 0x0027, 0x0037, 0x0047, 0x0057, 0x0067, 0x0077, 0x0087,
+ 0x0008, 0x0018, 0x0028, 0x0038, 0x0048, 0x0058, 0x0068, 0x0078, 0x0088,
+};
+
+/*
+ * bits 0:3, 4:7 index into _vals array
+ * 8:11 number of non-zero values
+ * 12:15 1: only second value non-zero
+ * 0: other cases
+ */
+static const uint16_t codebook_vector6_idx[] = {
+ 0x0000, 0x0110, 0x0120, 0x0130, 0x0140, 0x0150, 0x0160, 0x0170,
+ 0x1101, 0x0211, 0x0221, 0x0231, 0x0241, 0x0251, 0x0261, 0x0271,
+ 0x1102, 0x0212, 0x0222, 0x0232, 0x0242, 0x0252, 0x0262, 0x0272,
+ 0x1103, 0x0213, 0x0223, 0x0233, 0x0243, 0x0253, 0x0263, 0x0273,
+ 0x1104, 0x0214, 0x0224, 0x0234, 0x0244, 0x0254, 0x0264, 0x0274,
+ 0x1105, 0x0215, 0x0225, 0x0235, 0x0245, 0x0255, 0x0265, 0x0275,
+ 0x1106, 0x0216, 0x0226, 0x0236, 0x0246, 0x0256, 0x0266, 0x0276,
+ 0x1107, 0x0217, 0x0227, 0x0237, 0x0247, 0x0257, 0x0267, 0x0277,
+};
+
+/*
+ * bits 0:3, 4:7 index into _vals array
+ * 8:11 number of non-zero values
+ * 12:15 1: only second value non-zero
+ * 0: other cases
+ */
+static const uint16_t codebook_vector8_idx[] = {
+ 0x0000, 0x0110, 0x0120, 0x0130, 0x0140, 0x0150, 0x0160,
+ 0x0170, 0x0180, 0x0190, 0x01a0, 0x01b0, 0x01c0,
+ 0x1101, 0x0211, 0x0221, 0x0231, 0x0241, 0x0251, 0x0261,
+ 0x0271, 0x0281, 0x0291, 0x02a1, 0x02b1, 0x02c1,
+ 0x1102, 0x0212, 0x0222, 0x0232, 0x0242, 0x0252, 0x0262,
+ 0x0272, 0x0282, 0x0292, 0x02a2, 0x02b2, 0x02c2,
+ 0x1103, 0x0213, 0x0223, 0x0233, 0x0243, 0x0253, 0x0263,
+ 0x0273, 0x0283, 0x0293, 0x02a3, 0x02b3, 0x02c3,
+ 0x1104, 0x0214, 0x0224, 0x0234, 0x0244, 0x0254, 0x0264,
+ 0x0274, 0x0284, 0x0294, 0x02a4, 0x02b4, 0x02c4,
+ 0x1105, 0x0215, 0x0225, 0x0235, 0x0245, 0x0255, 0x0265,
+ 0x0275, 0x0285, 0x0295, 0x02a5, 0x02b5, 0x02c5,
+ 0x1106, 0x0216, 0x0226, 0x0236, 0x0246, 0x0256, 0x0266,
+ 0x0276, 0x0286, 0x0296, 0x02a6, 0x02b6, 0x02c6,
+ 0x1107, 0x0217, 0x0227, 0x0237, 0x0247, 0x0257, 0x0267,
+ 0x0277, 0x0287, 0x0297, 0x02a7, 0x02b7, 0x02c7,
+ 0x1108, 0x0218, 0x0228, 0x0238, 0x0248, 0x0258, 0x0268,
+ 0x0278, 0x0288, 0x0298, 0x02a8, 0x02b8, 0x02c8,
+ 0x1109, 0x0219, 0x0229, 0x0239, 0x0249, 0x0259, 0x0269,
+ 0x0279, 0x0289, 0x0299, 0x02a9, 0x02b9, 0x02c9,
+ 0x110a, 0x021a, 0x022a, 0x023a, 0x024a, 0x025a, 0x026a,
+ 0x027a, 0x028a, 0x029a, 0x02aa, 0x02ba, 0x02ca,
+ 0x110b, 0x021b, 0x022b, 0x023b, 0x024b, 0x025b, 0x026b,
+ 0x027b, 0x028b, 0x029b, 0x02ab, 0x02bb, 0x02cb,
+ 0x110c, 0x021c, 0x022c, 0x023c, 0x024c, 0x025c, 0x026c,
+ 0x027c, 0x028c, 0x029c, 0x02ac, 0x02bc, 0x02cc,
+};
+
+static const float codebook_vector10_vals[] = {
+ 0.0000000, 1.0000000,
+ 2.5198421, 4.3267487,
+ 6.3496042, 8.5498797,
+ 10.9027236, 13.3905183,
+ 16.0000000, 18.7207544,
+ 21.5443469, 24.4637810,
+ 27.4731418, 30.5673509,
+ 33.7419917, 36.9931811,
+};
+
+/*
+ * bits 0:3, 4:7 index into _vals array
+ * 8:9 bit mask of escape-coded entries
+ * 12:15 number of non-zero values
+ */
+static const uint16_t codebook_vector10_idx[] = {
+ 0x0000, 0x1010, 0x1020, 0x1030, 0x1040, 0x1050, 0x1060, 0x1070,
+ 0x1080, 0x1090, 0x10a0, 0x10b0, 0x10c0, 0x10d0, 0x10e0, 0x10f0, 0x1200,
+ 0x1001, 0x2011, 0x2021, 0x2031, 0x2041, 0x2051, 0x2061, 0x2071,
+ 0x2081, 0x2091, 0x20a1, 0x20b1, 0x20c1, 0x20d1, 0x20e1, 0x20f1, 0x2201,
+ 0x1002, 0x2012, 0x2022, 0x2032, 0x2042, 0x2052, 0x2062, 0x2072,
+ 0x2082, 0x2092, 0x20a2, 0x20b2, 0x20c2, 0x20d2, 0x20e2, 0x20f2, 0x2202,
+ 0x1003, 0x2013, 0x2023, 0x2033, 0x2043, 0x2053, 0x2063, 0x2073,
+ 0x2083, 0x2093, 0x20a3, 0x20b3, 0x20c3, 0x20d3, 0x20e3, 0x20f3, 0x2203,
+ 0x1004, 0x2014, 0x2024, 0x2034, 0x2044, 0x2054, 0x2064, 0x2074,
+ 0x2084, 0x2094, 0x20a4, 0x20b4, 0x20c4, 0x20d4, 0x20e4, 0x20f4, 0x2204,
+ 0x1005, 0x2015, 0x2025, 0x2035, 0x2045, 0x2055, 0x2065, 0x2075,
+ 0x2085, 0x2095, 0x20a5, 0x20b5, 0x20c5, 0x20d5, 0x20e5, 0x20f5, 0x2205,
+ 0x1006, 0x2016, 0x2026, 0x2036, 0x2046, 0x2056, 0x2066, 0x2076,
+ 0x2086, 0x2096, 0x20a6, 0x20b6, 0x20c6, 0x20d6, 0x20e6, 0x20f6, 0x2206,
+ 0x1007, 0x2017, 0x2027, 0x2037, 0x2047, 0x2057, 0x2067, 0x2077,
+ 0x2087, 0x2097, 0x20a7, 0x20b7, 0x20c7, 0x20d7, 0x20e7, 0x20f7, 0x2207,
+ 0x1008, 0x2018, 0x2028, 0x2038, 0x2048, 0x2058, 0x2068, 0x2078,
+ 0x2088, 0x2098, 0x20a8, 0x20b8, 0x20c8, 0x20d8, 0x20e8, 0x20f8, 0x2208,
+ 0x1009, 0x2019, 0x2029, 0x2039, 0x2049, 0x2059, 0x2069, 0x2079,
+ 0x2089, 0x2099, 0x20a9, 0x20b9, 0x20c9, 0x20d9, 0x20e9, 0x20f9, 0x2209,
+ 0x100a, 0x201a, 0x202a, 0x203a, 0x204a, 0x205a, 0x206a, 0x207a,
+ 0x208a, 0x209a, 0x20aa, 0x20ba, 0x20ca, 0x20da, 0x20ea, 0x20fa, 0x220a,
+ 0x100b, 0x201b, 0x202b, 0x203b, 0x204b, 0x205b, 0x206b, 0x207b,
+ 0x208b, 0x209b, 0x20ab, 0x20bb, 0x20cb, 0x20db, 0x20eb, 0x20fb, 0x220b,
+ 0x100c, 0x201c, 0x202c, 0x203c, 0x204c, 0x205c, 0x206c, 0x207c,
+ 0x208c, 0x209c, 0x20ac, 0x20bc, 0x20cc, 0x20dc, 0x20ec, 0x20fc, 0x220c,
+ 0x100d, 0x201d, 0x202d, 0x203d, 0x204d, 0x205d, 0x206d, 0x207d,
+ 0x208d, 0x209d, 0x20ad, 0x20bd, 0x20cd, 0x20dd, 0x20ed, 0x20fd, 0x220d,
+ 0x100e, 0x201e, 0x202e, 0x203e, 0x204e, 0x205e, 0x206e, 0x207e,
+ 0x208e, 0x209e, 0x20ae, 0x20be, 0x20ce, 0x20de, 0x20ee, 0x20fe, 0x220e,
+ 0x100f, 0x201f, 0x202f, 0x203f, 0x204f, 0x205f, 0x206f, 0x207f,
+ 0x208f, 0x209f, 0x20af, 0x20bf, 0x20cf, 0x20df, 0x20ef, 0x20ff, 0x220f,
+ 0x1100, 0x2110, 0x2120, 0x2130, 0x2140, 0x2150, 0x2160, 0x2170,
+ 0x2180, 0x2190, 0x21a0, 0x21b0, 0x21c0, 0x21d0, 0x21e0, 0x21f0, 0x2300,
+};
+
+const float *const ff_aac_codebook_vector_vals[] = {
+ codebook_vector0_vals, codebook_vector0_vals,
+ codebook_vector10_vals, codebook_vector10_vals,
+ codebook_vector4_vals, codebook_vector4_vals,
+ codebook_vector10_vals, codebook_vector10_vals,
+ codebook_vector10_vals, codebook_vector10_vals,
+ codebook_vector10_vals,
+};
+
+const uint16_t *const ff_aac_codebook_vector_idx[] = {
+ codebook_vector02_idx, codebook_vector02_idx,
+ codebook_vector02_idx, codebook_vector02_idx,
+ codebook_vector4_idx, codebook_vector4_idx,
+ codebook_vector6_idx, codebook_vector6_idx,
+ codebook_vector8_idx, codebook_vector8_idx,
+ codebook_vector10_idx,
+};
+
+/* @name swb_offsets
+ * Sample offset into the window indicating the beginning of a scalefactor
+ * window band
+ *
+ * scalefactor window band - term for scalefactor bands within a window,
+ * given in Table 4.110 to Table 4.128.
+ *
+ * scalefactor band - a set of spectral coefficients which are scaled by one
+ * scalefactor. In case of EIGHT_SHORT_SEQUENCE and grouping a scalefactor band
+ * may contain several scalefactor window bands of corresponding frequency. For
+ * all other window_sequences scalefactor bands and scalefactor window bands are
+ * identical.
+ * @{
+ */
+
+static const uint16_t swb_offset_1024_96[] = {
+ 0, 4, 8, 12, 16, 20, 24, 28,
+ 32, 36, 40, 44, 48, 52, 56, 64,
+ 72, 80, 88, 96, 108, 120, 132, 144,
+ 156, 172, 188, 212, 240, 276, 320, 384,
+ 448, 512, 576, 640, 704, 768, 832, 896,
+ 960, 1024
+};
+
+static const uint16_t swb_offset_128_96[] = {
+ 0, 4, 8, 12, 16, 20, 24, 32, 40, 48, 64, 92, 128
+};
+
+static const uint16_t swb_offset_1024_64[] = {
+ 0, 4, 8, 12, 16, 20, 24, 28,
+ 32, 36, 40, 44, 48, 52, 56, 64,
+ 72, 80, 88, 100, 112, 124, 140, 156,
+ 172, 192, 216, 240, 268, 304, 344, 384,
+ 424, 464, 504, 544, 584, 624, 664, 704,
+ 744, 784, 824, 864, 904, 944, 984, 1024
+};
+
+static const uint16_t swb_offset_1024_48[] = {
+ 0, 4, 8, 12, 16, 20, 24, 28,
+ 32, 36, 40, 48, 56, 64, 72, 80,
+ 88, 96, 108, 120, 132, 144, 160, 176,
+ 196, 216, 240, 264, 292, 320, 352, 384,
+ 416, 448, 480, 512, 544, 576, 608, 640,
+ 672, 704, 736, 768, 800, 832, 864, 896,
+ 928, 1024
+};
+
+static const uint16_t swb_offset_128_48[] = {
+ 0, 4, 8, 12, 16, 20, 28, 36,
+ 44, 56, 68, 80, 96, 112, 128
+};
+
+static const uint16_t swb_offset_1024_32[] = {
+ 0, 4, 8, 12, 16, 20, 24, 28,
+ 32, 36, 40, 48, 56, 64, 72, 80,
+ 88, 96, 108, 120, 132, 144, 160, 176,
+ 196, 216, 240, 264, 292, 320, 352, 384,
+ 416, 448, 480, 512, 544, 576, 608, 640,
+ 672, 704, 736, 768, 800, 832, 864, 896,
+ 928, 960, 992, 1024
+};
+
+static const uint16_t swb_offset_1024_24[] = {
+ 0, 4, 8, 12, 16, 20, 24, 28,
+ 32, 36, 40, 44, 52, 60, 68, 76,
+ 84, 92, 100, 108, 116, 124, 136, 148,
+ 160, 172, 188, 204, 220, 240, 260, 284,
+ 308, 336, 364, 396, 432, 468, 508, 552,
+ 600, 652, 704, 768, 832, 896, 960, 1024
+};
+
+static const uint16_t swb_offset_128_24[] = {
+ 0, 4, 8, 12, 16, 20, 24, 28,
+ 36, 44, 52, 64, 76, 92, 108, 128
+};
+
+static const uint16_t swb_offset_1024_16[] = {
+ 0, 8, 16, 24, 32, 40, 48, 56,
+ 64, 72, 80, 88, 100, 112, 124, 136,
+ 148, 160, 172, 184, 196, 212, 228, 244,
+ 260, 280, 300, 320, 344, 368, 396, 424,
+ 456, 492, 532, 572, 616, 664, 716, 772,
+ 832, 896, 960, 1024
+};
+
+static const uint16_t swb_offset_128_16[] = {
+ 0, 4, 8, 12, 16, 20, 24, 28,
+ 32, 40, 48, 60, 72, 88, 108, 128
+};
+
+static const uint16_t swb_offset_1024_8[] = {
+ 0, 12, 24, 36, 48, 60, 72, 84,
+ 96, 108, 120, 132, 144, 156, 172, 188,
+ 204, 220, 236, 252, 268, 288, 308, 328,
+ 348, 372, 396, 420, 448, 476, 508, 544,
+ 580, 620, 664, 712, 764, 820, 880, 944,
+ 1024
+};
+
+static const uint16_t swb_offset_128_8[] = {
+ 0, 4, 8, 12, 16, 20, 24, 28,
+ 36, 44, 52, 60, 72, 88, 108, 128
+};
+
+const uint16_t * const ff_swb_offset_1024[] = {
+ swb_offset_1024_96, swb_offset_1024_96, swb_offset_1024_64,
+ swb_offset_1024_48, swb_offset_1024_48, swb_offset_1024_32,
+ swb_offset_1024_24, swb_offset_1024_24, swb_offset_1024_16,
+ swb_offset_1024_16, swb_offset_1024_16, swb_offset_1024_8,
+ swb_offset_1024_8
+};
+
+const uint16_t * const ff_swb_offset_128[] = {
+ /* The last entry on the following row is swb_offset_128_64 but is a
+ duplicate of swb_offset_128_96. */
+ swb_offset_128_96, swb_offset_128_96, swb_offset_128_96,
+ swb_offset_128_48, swb_offset_128_48, swb_offset_128_48,
+ swb_offset_128_24, swb_offset_128_24, swb_offset_128_16,
+ swb_offset_128_16, swb_offset_128_16, swb_offset_128_8,
+ swb_offset_128_8
+};
+
+// @}
+
+/* @name ff_tns_max_bands
+ * The maximum number of scalefactor bands on which TNS can operate for the long
+ * and short transforms respectively. The index to these tables is related to
+ * the sample rate of the audio.
+ * @{
+ */
+const uint8_t ff_tns_max_bands_1024[] = {
+ 31, 31, 34, 40, 42, 51, 46, 46, 42, 42, 42, 39, 39
+};
+
+const uint8_t ff_tns_max_bands_128[] = {
+ 9, 9, 10, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14
+};
+// @}
diff --git a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aactab.h b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aactab.h index c76d65db9..e9a0f1c44 100644 --- a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aactab.h +++ b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/aactab.h @@ -1,77 +1,77 @@ -/* - * AAC data declarations - * Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org ) - * Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com ) - * - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/** - * @file - * AAC data declarations - * @author Oded Shimon ( ods15 ods15 dyndns org ) - * @author Maxim Gavrilov ( maxim.gavrilov gmail com ) - */ - -#ifndef AVCODEC_AACTAB_H -#define AVCODEC_AACTAB_H - -#include "libavutil/mem.h" -#include "aac.h" -#include "aac_tablegen_decl.h" - -#include <stdint.h> - -/* NOTE: - * Tables in this file are used by the AAC decoder and will be used by the AAC - * encoder. - */ - -/* @name window coefficients - * @{ - */ -DECLARE_ALIGNED(16, extern float, ff_aac_kbd_long_1024)[1024]; -DECLARE_ALIGNED(16, extern float, ff_aac_kbd_short_128)[128]; -// @} - -/* @name number of scalefactor window bands for long and short transform windows respectively - * @{ - */ -extern const uint8_t ff_aac_num_swb_1024[]; -extern const uint8_t ff_aac_num_swb_128 []; -// @} - -extern const uint8_t ff_aac_pred_sfb_max []; - -extern const uint32_t ff_aac_scalefactor_code[121]; -extern const uint8_t ff_aac_scalefactor_bits[121]; - -extern const uint16_t * const ff_aac_spectral_codes[11]; -extern const uint8_t * const ff_aac_spectral_bits [11]; -extern const uint16_t ff_aac_spectral_sizes[11]; - -extern const float *ff_aac_codebook_vectors[]; -extern const float *ff_aac_codebook_vector_vals[]; -extern const uint16_t *ff_aac_codebook_vector_idx[]; - -extern const uint16_t * const ff_swb_offset_1024[13]; -extern const uint16_t * const ff_swb_offset_128 [13]; - -extern const uint8_t ff_tns_max_bands_1024[13]; -extern const uint8_t ff_tns_max_bands_128 [13]; - -#endif /* AVCODEC_AACTAB_H */ +/*
+ * AAC data declarations
+ * Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org )
+ * Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com )
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * AAC data declarations
+ * @author Oded Shimon ( ods15 ods15 dyndns org )
+ * @author Maxim Gavrilov ( maxim.gavrilov gmail com )
+ */
+
+#ifndef AVCODEC_AACTAB_H
+#define AVCODEC_AACTAB_H
+
+#include "libavutil/mem.h"
+#include "aac.h"
+#include "aac_tablegen_decl.h"
+
+#include <stdint.h>
+
+/* NOTE:
+ * Tables in this file are used by the AAC decoder and will be used by the AAC
+ * encoder.
+ */
+
+/* @name window coefficients
+ * @{
+ */
+DECLARE_ALIGNED(16, extern float, ff_aac_kbd_long_1024)[1024];
+DECLARE_ALIGNED(16, extern float, ff_aac_kbd_short_128)[128];
+// @}
+
+/* @name number of scalefactor window bands for long and short transform windows respectively
+ * @{
+ */
+extern const uint8_t ff_aac_num_swb_1024[];
+extern const uint8_t ff_aac_num_swb_128 [];
+// @}
+
+extern const uint8_t ff_aac_pred_sfb_max [];
+
+extern const uint32_t ff_aac_scalefactor_code[121];
+extern const uint8_t ff_aac_scalefactor_bits[121];
+
+extern const uint16_t * const ff_aac_spectral_codes[11];
+extern const uint8_t * const ff_aac_spectral_bits [11];
+extern const uint16_t ff_aac_spectral_sizes[11];
+
+extern const float *ff_aac_codebook_vectors[];
+extern const float *ff_aac_codebook_vector_vals[];
+extern const uint16_t *ff_aac_codebook_vector_idx[];
+
+extern const uint16_t * const ff_swb_offset_1024[13];
+extern const uint16_t * const ff_swb_offset_128 [13];
+
+extern const uint8_t ff_tns_max_bands_1024[13];
+extern const uint8_t ff_tns_max_bands_128 [13];
+
+#endif /* AVCODEC_AACTAB_H */
diff --git a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/fmtconvert.c b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/fmtconvert.c index 58fece70b..21dfa09fb 100644 --- a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/fmtconvert.c +++ b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/fmtconvert.c @@ -1,88 +1,119 @@ -/* - * Format Conversion Utils - * Copyright (c) 2000, 2001 Fabrice Bellard - * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at> - * - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "avcodec.h" -#include "fmtconvert.h" - -static void int32_to_float_fmul_scalar_c(float *dst, const int *src, float mul, int len){ - int i; - for(i=0; i<len; i++) - dst[i] = src[i] * mul; -} - -static av_always_inline int float_to_int16_one(const float *src){ - return av_clip_int16(lrintf(*src)); -} - -static void float_to_int16_c(int16_t *dst, const float *src, long len) -{ - int i; - for(i=0; i<len; i++) - dst[i] = float_to_int16_one(src+i); -} - -static void float_to_int16_interleave_c(int16_t *dst, const float **src, - long len, int channels) -{ - int i,j,c; - if(channels==2){ - for(i=0; i<len; i++){ - dst[2*i] = float_to_int16_one(src[0]+i); - dst[2*i+1] = float_to_int16_one(src[1]+i); - } - }else{ - for(c=0; c<channels; c++) - for(i=0, j=c; i<len; i++, j+=channels) - dst[j] = float_to_int16_one(src[c]+i); - } -} - -void ff_float_interleave_c(float *dst, const float **src, unsigned int len, - int channels) -{ - int j, c; - unsigned int i; - if (channels == 2) { - for (i = 0; i < len; i++) { - dst[2*i] = src[0][i]; - dst[2*i+1] = src[1][i]; - } - } else if (channels == 1 && len < INT_MAX / sizeof(float)) { - memcpy(dst, src[0], len * sizeof(float)); - } else { - for (c = 0; c < channels; c++) - for (i = 0, j = c; i < len; i++, j += channels) - dst[j] = src[c][i]; - } -} - -av_cold void ff_fmt_convert_init(FmtConvertContext *c, AVCodecContext *avctx) -{ - c->int32_to_float_fmul_scalar = int32_to_float_fmul_scalar_c; - c->float_to_int16 = float_to_int16_c; - c->float_to_int16_interleave = float_to_int16_interleave_c; - c->float_interleave = ff_float_interleave_c; - - if (ARCH_ARM) ff_fmt_convert_init_arm(c, avctx); - if (HAVE_ALTIVEC) ff_fmt_convert_init_altivec(c, avctx); - if (HAVE_MMX) ff_fmt_convert_init_x86(c, avctx); -} +/*
+ * Format Conversion Utils
+ * Copyright (c) 2000, 2001 Fabrice Bellard
+ * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "avcodec.h"
+#include "fmtconvert.h"
+
+static void int32_to_float_fmul_scalar_c(float *dst, const int *src, float mul, int len){
+ int i;
+ for(i=0; i<len; i++)
+ dst[i] = src[i] * mul;
+}
+
+static av_always_inline int float_to_int16_one(const float *src){
+ return av_clip_int16(lrintf(*src));
+}
+
+static void float_to_int16_c(int16_t *dst, const float *src, long len)
+{
+ int i;
+ for(i=0; i<len; i++)
+ dst[i] = float_to_int16_one(src+i);
+}
+
+static void float_to_int16_interleave_c(int16_t *dst, const float **src,
+ long len, int channels)
+{
+ int i,j,c;
+ if(channels==2){
+ for(i=0; i<len; i++){
+ dst[2*i] = float_to_int16_one(src[0]+i);
+ dst[2*i+1] = float_to_int16_one(src[1]+i);
+ }
+ }else{
+ for(c=0; c<channels; c++)
+ for(i=0, j=c; i<len; i++, j+=channels)
+ dst[j] = float_to_int16_one(src[c]+i);
+ }
+}
+
+void ff_float_interleave_c(float *dst, const float **src, unsigned int len,
+ int channels)
+{
+ int j, c;
+ unsigned int i;
+ if (channels == 2) {
+ for (i = 0; i < len; i++) {
+ dst[2*i] = src[0][i];
+ dst[2*i+1] = src[1][i];
+ }
+ } else if (channels == 1 && len < INT_MAX / sizeof(float)) {
+ memcpy(dst, src[0], len * sizeof(float));
+ } else {
+ for (c = 0; c < channels; c++)
+ for (i = 0, j = c; i < len; i++, j += channels)
+ dst[j] = src[c][i];
+ }
+}
+
+av_cold void ff_fmt_convert_init(FmtConvertContext *c, AVCodecContext *avctx)
+{
+ c->int32_to_float_fmul_scalar = int32_to_float_fmul_scalar_c;
+ c->float_to_int16 = float_to_int16_c;
+ c->float_to_int16_interleave = float_to_int16_interleave_c;
+ c->float_interleave = ff_float_interleave_c;
+
+ if (ARCH_ARM) ff_fmt_convert_init_arm(c, avctx);
+ if (HAVE_ALTIVEC) ff_fmt_convert_init_altivec(c, avctx);
+ if (HAVE_MMX) ff_fmt_convert_init_x86(c, avctx);
+}
+
+/* ffdshow custom code */
+void float_interleave(float *dst, const float **src, long len, int channels)
+{
+ int i,j,c;
+ if(channels==2){
+ for(i=0; i<len; i++){
+ dst[2*i] = src[0][i] / 32768.0f;
+ dst[2*i+1] = src[1][i] / 32768.0f;
+ }
+ }else{
+ for(c=0; c<channels; c++)
+ for(i=0, j=c; i<len; i++, j+=channels)
+ dst[j] = src[c][i] / 32768.0f;
+ }
+}
+
+void float_interleave_noscale(float *dst, const float **src, long len, int channels)
+{
+ int i,j,c;
+ if(channels==2){
+ for(i=0; i<len; i++){
+ dst[2*i] = src[0][i];
+ dst[2*i+1] = src[1][i];
+ }
+ }else{
+ for(c=0; c<channels; c++)
+ for(i=0, j=c; i<len; i++, j+=channels)
+ dst[j] = src[c][i];
+ }
+}
diff --git a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/fmtconvert.h b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/fmtconvert.h index 1b534019f..4fc12dae1 100644 --- a/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/fmtconvert.h +++ b/src/filters/transform/MPCVideoDec/ffmpeg/libavcodec/fmtconvert.h @@ -1,96 +1,100 @@ -/* - * Format Conversion Utils - * Copyright (c) 2000, 2001 Fabrice Bellard - * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at> - * - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef AVCODEC_FMTCONVERT_H -#define AVCODEC_FMTCONVERT_H - -#include "avcodec.h" - -typedef struct FmtConvertContext { - /** - * Convert an array of int32_t to float and multiply by a float value. - * @param dst destination array of float. - * constraints: 16-byte aligned - * @param src source array of int32_t. - * constraints: 16-byte aligned - * @param len number of elements to convert. - * constraints: multiple of 8 - */ - void (*int32_to_float_fmul_scalar)(float *dst, const int *src, float mul, int len); - - /** - * Convert an array of float to an array of int16_t. - * - * Convert floats from in the range [-32768.0,32767.0] to ints - * without rescaling - * - * @param dst destination array of int16_t. - * constraints: 16-byte aligned - * @param src source array of float. - * constraints: 16-byte aligned - * @param len number of elements to convert. - * constraints: multiple of 8 - */ - void (*float_to_int16)(int16_t *dst, const float *src, long len); - - /** - * Convert multiple arrays of float to an interleaved array of int16_t. - * - * Convert floats from in the range [-32768.0,32767.0] to ints - * without rescaling - * - * @param dst destination array of interleaved int16_t. - * constraints: 16-byte aligned - * @param src source array of float arrays, one for each channel. - * constraints: 16-byte aligned - * @param len number of elements to convert. - * constraints: multiple of 8 - * @param channels number of channels - */ - void (*float_to_int16_interleave)(int16_t *dst, const float **src, - long len, int channels); - - /** - * Convert multiple arrays of float to an array of interleaved float. - * - * @param dst destination array of interleaved float. - * constraints: 16-byte aligned - * @param src source array of float arrays, one for each channel. - * constraints: 16-byte aligned - * @param len number of elements to convert. - * constraints: multiple of 8 - * @param channels number of channels - */ - void (*float_interleave)(float *dst, const float **src, unsigned int len, - int channels); -} FmtConvertContext; - -void ff_float_interleave_c(float *dst, const float **src, unsigned int len, - int channels); - -void ff_fmt_convert_init(FmtConvertContext *c, AVCodecContext *avctx); - -void ff_fmt_convert_init_arm(FmtConvertContext *c, AVCodecContext *avctx); -void ff_fmt_convert_init_altivec(FmtConvertContext *c, AVCodecContext *avctx); -void ff_fmt_convert_init_x86(FmtConvertContext *c, AVCodecContext *avctx); - -#endif /* AVCODEC_FMTCONVERT_H */ +/*
+ * Format Conversion Utils
+ * Copyright (c) 2000, 2001 Fabrice Bellard
+ * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_FMTCONVERT_H
+#define AVCODEC_FMTCONVERT_H
+
+#include "avcodec.h"
+
+typedef struct FmtConvertContext {
+ /**
+ * Convert an array of int32_t to float and multiply by a float value.
+ * @param dst destination array of float.
+ * constraints: 16-byte aligned
+ * @param src source array of int32_t.
+ * constraints: 16-byte aligned
+ * @param len number of elements to convert.
+ * constraints: multiple of 8
+ */
+ void (*int32_to_float_fmul_scalar)(float *dst, const int *src, float mul, int len);
+
+ /**
+ * Convert an array of float to an array of int16_t.
+ *
+ * Convert floats from in the range [-32768.0,32767.0] to ints
+ * without rescaling
+ *
+ * @param dst destination array of int16_t.
+ * constraints: 16-byte aligned
+ * @param src source array of float.
+ * constraints: 16-byte aligned
+ * @param len number of elements to convert.
+ * constraints: multiple of 8
+ */
+ void (*float_to_int16)(int16_t *dst, const float *src, long len);
+
+ /**
+ * Convert multiple arrays of float to an interleaved array of int16_t.
+ *
+ * Convert floats from in the range [-32768.0,32767.0] to ints
+ * without rescaling
+ *
+ * @param dst destination array of interleaved int16_t.
+ * constraints: 16-byte aligned
+ * @param src source array of float arrays, one for each channel.
+ * constraints: 16-byte aligned
+ * @param len number of elements to convert.
+ * constraints: multiple of 8
+ * @param channels number of channels
+ */
+ void (*float_to_int16_interleave)(int16_t *dst, const float **src,
+ long len, int channels);
+
+ /**
+ * Convert multiple arrays of float to an array of interleaved float.
+ *
+ * @param dst destination array of interleaved float.
+ * constraints: 16-byte aligned
+ * @param src source array of float arrays, one for each channel.
+ * constraints: 16-byte aligned
+ * @param len number of elements to convert.
+ * constraints: multiple of 8
+ * @param channels number of channels
+ */
+ void (*float_interleave)(float *dst, const float **src, unsigned int len,
+ int channels);
+} FmtConvertContext;
+
+void ff_float_interleave_c(float *dst, const float **src, unsigned int len,
+ int channels);
+
+void ff_fmt_convert_init(FmtConvertContext *c, AVCodecContext *avctx);
+
+void ff_fmt_convert_init_arm(FmtConvertContext *c, AVCodecContext *avctx);
+void ff_fmt_convert_init_altivec(FmtConvertContext *c, AVCodecContext *avctx);
+void ff_fmt_convert_init_x86(FmtConvertContext *c, AVCodecContext *avctx);
+
+/* ffdshow custom code */
+void float_interleave(float *dst, const float **src, long len, int channels);
+void float_interleave_noscale(float *dst, const float **src, long len, int channels);
+
+#endif /* AVCODEC_FMTCONVERT_H */
|