Originally committed as revision 23647 to svn://svn.ffmpeg.org/ffmpeg/trunktags/n0.8
| @@ -11,6 +11,7 @@ version <next>: | |||
| - CODEC_CAP_EXPERIMENTAL added | |||
| - Demuxer for On2's IVF format | |||
| - Pictor/PC Paint decoder | |||
| - HE-AAC v2 decoder | |||
| @@ -42,7 +42,7 @@ OBJS-$(CONFIG_VAAPI) += vaapi.o | |||
| OBJS-$(CONFIG_VDPAU) += vdpau.o | |||
| # decoders/encoders/hardware accelerators | |||
| OBJS-$(CONFIG_AAC_DECODER) += aacdec.o aactab.o aacsbr.o | |||
| OBJS-$(CONFIG_AAC_DECODER) += aacdec.o aactab.o aacsbr.o ps.o | |||
| OBJS-$(CONFIG_AAC_ENCODER) += aacenc.o aaccoder.o \ | |||
| aacpsy.o aactab.o \ | |||
| psymodel.o iirfilter.o \ | |||
| @@ -667,5 +667,6 @@ $(SUBDIR)mpegaudiodec.o: $(SUBDIR)mpegaudio_tables.h | |||
| $(SUBDIR)mpegaudiodec_float.o: $(SUBDIR)mpegaudio_tables.h | |||
| $(SUBDIR)motionpixels.o: $(SUBDIR)motionpixels_tables.h | |||
| $(SUBDIR)pcm.o: $(SUBDIR)pcm_tables.h | |||
| $(SUBDIR)ps.o: $(SUBDIR)ps_tables.h | |||
| $(SUBDIR)qdm2.o: $(SUBDIR)qdm2_tables.h | |||
| endif | |||
| @@ -67,7 +67,7 @@ | |||
| * Y (not in this code) Layer-2 | |||
| * Y (not in this code) Layer-3 | |||
| * N SinuSoidal Coding (Transient, Sinusoid, Noise) | |||
| * N (planned) Parametric Stereo | |||
| * Y Parametric Stereo | |||
| * N Direct Stream Transfer | |||
| * | |||
| * Note: - HE AAC v1 comprises LC AAC with Spectral Band Replication. | |||
| @@ -200,7 +200,8 @@ static av_cold int che_configure(AACContext *ac, | |||
| ff_aac_sbr_ctx_init(&ac->che[type][id]->sbr); | |||
| if (type != TYPE_CCE) { | |||
| ac->output_data[(*channels)++] = ac->che[type][id]->ch[0].ret; | |||
| if (type == TYPE_CPE) { | |||
| if (type == TYPE_CPE || | |||
| (type == TYPE_SCE && ac->m4ac.ps == 1)) { | |||
| ac->output_data[(*channels)++] = ac->che[type][id]->ch[1].ret; | |||
| } | |||
| } | |||
| @@ -228,6 +229,7 @@ static av_cold int output_configure(AACContext *ac, | |||
| AVCodecContext *avctx = ac->avctx; | |||
| int i, type, channels = 0, ret; | |||
| if (new_che_pos != che_pos) | |||
| memcpy(che_pos, new_che_pos, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0])); | |||
| if (channel_config) { | |||
| @@ -471,6 +473,8 @@ static int decode_audio_specific_config(AACContext *ac, void *data, | |||
| av_log(ac->avctx, AV_LOG_ERROR, "invalid sampling rate index %d\n", ac->m4ac.sampling_index); | |||
| return -1; | |||
| } | |||
| if (ac->m4ac.sbr == 1 && ac->m4ac.ps == -1) | |||
| ac->m4ac.ps = 1; | |||
| skip_bits_long(&gb, i); | |||
| @@ -1667,6 +1671,10 @@ static int decode_extension_payload(AACContext *ac, GetBitContext *gb, int cnt, | |||
| 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->che_pos, ac->che_pos, ac->m4ac.chan_config, ac->output_configured); | |||
| } else { | |||
| ac->m4ac.sbr = 1; | |||
| } | |||
| @@ -1946,8 +1954,10 @@ static int parse_adts_frame_header(AACContext *ac, GetBitContext *gb) | |||
| } else if (ac->output_configured != OC_LOCKED) { | |||
| ac->output_configured = OC_NONE; | |||
| } | |||
| if (ac->output_configured != OC_LOCKED) | |||
| 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; | |||
| @@ -31,6 +31,7 @@ | |||
| #include "aacsbr.h" | |||
| #include "aacsbrdata.h" | |||
| #include "fft.h" | |||
| #include "ps.h" | |||
| #include <stdint.h> | |||
| #include <float.h> | |||
| @@ -120,6 +121,8 @@ av_cold void ff_aac_sbr_init(void) | |||
| 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(SpectralBandReplication *sbr) | |||
| @@ -130,6 +133,7 @@ av_cold void ff_aac_sbr_ctx_init(SpectralBandReplication *sbr) | |||
| sbr->data[1].synthesis_filterbank_samples_offset = SBR_SYNTHESIS_BUF_SIZE - (1280 - 128); | |||
| ff_mdct_init(&sbr->mdct, 7, 1, 1.0/64); | |||
| ff_mdct_init(&sbr->mdct_ana, 7, 1, -2.0); | |||
| ff_ps_ctx_init(&sbr->ps); | |||
| } | |||
| av_cold void ff_aac_sbr_ctx_close(SpectralBandReplication *sbr) | |||
| @@ -890,7 +894,6 @@ static void read_sbr_extension(AACContext *ac, SpectralBandReplication *sbr, | |||
| GetBitContext *gb, | |||
| int bs_extension_id, int *num_bits_left) | |||
| { | |||
| //TODO - implement ps_data for parametric stereo parsing | |||
| switch (bs_extension_id) { | |||
| case EXTENSION_ID_PS: | |||
| if (!ac->m4ac.ps) { | |||
| @@ -898,8 +901,8 @@ static void read_sbr_extension(AACContext *ac, SpectralBandReplication *sbr, | |||
| skip_bits_long(gb, *num_bits_left); // bs_fill_bits | |||
| *num_bits_left = 0; | |||
| } else { | |||
| #if 0 | |||
| *num_bits_left -= ff_ps_data(gb, ps); | |||
| #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 | |||
| @@ -1008,6 +1011,11 @@ static unsigned int read_sbr_data(AACContext *ac, SpectralBandReplication *sbr, | |||
| 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; | |||
| @@ -1166,7 +1174,7 @@ static void sbr_qmf_analysis(DSPContext *dsp, FFTContext *mdct, const float *in, | |||
| * (14496-3 sp04 p206) | |||
| */ | |||
| static void sbr_qmf_synthesis(DSPContext *dsp, FFTContext *mdct, | |||
| float *out, float X[2][32][64], | |||
| float *out, float X[2][38][64], | |||
| float mdct_buf[2][64], | |||
| float *v0, int *v_off, const unsigned int div, | |||
| float bias, float scale) | |||
| @@ -1402,7 +1410,7 @@ static int sbr_hf_gen(AACContext *ac, SpectralBandReplication *sbr, | |||
| } | |||
| /// Generate the subband filtered lowband | |||
| static int sbr_x_gen(SpectralBandReplication *sbr, float X[2][32][64], | |||
| static int sbr_x_gen(SpectralBandReplication *sbr, float X[2][38][64], | |||
| const float X_low[32][40][2], const float Y[2][38][64][2], | |||
| int ch) | |||
| { | |||
| @@ -1424,7 +1432,7 @@ static int sbr_x_gen(SpectralBandReplication *sbr, float X[2][32][64], | |||
| } | |||
| for (k = 0; k < sbr->kx[1]; k++) { | |||
| for (i = i_Temp; i < i_f; i++) { | |||
| 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]; | |||
| } | |||
| @@ -1740,6 +1748,16 @@ void ff_sbr_apply(AACContext *ac, SpectralBandReplication *sbr, int id_aac, | |||
| /* synthesis */ | |||
| sbr_x_gen(sbr, sbr->X[ch], sbr->X_low, sbr->data[ch].Y, 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, L, sbr->X[0], sbr->qmf_filter_scratch, | |||
| sbr->data[0].synthesis_filterbank_samples, | |||
| &sbr->data[0].synthesis_filterbank_samples_offset, | |||
| @@ -30,7 +30,7 @@ | |||
| #include "libavutil/avutil.h" | |||
| #define LIBAVCODEC_VERSION_MAJOR 52 | |||
| #define LIBAVCODEC_VERSION_MINOR 76 | |||
| #define LIBAVCODEC_VERSION_MINOR 77 | |||
| #define LIBAVCODEC_VERSION_MICRO 0 | |||
| #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ | |||
| @@ -131,6 +131,14 @@ int ff_mpeg4audio_get_config(MPEG4AudioConfig *c, const uint8_t *buf, int buf_si | |||
| get_bits1(&gb); // skip 1 bit | |||
| } | |||
| } | |||
| //PS requires SBR | |||
| if (!c->sbr) | |||
| c->ps = 0; | |||
| //Limit implicit PS to the HE-AACv2 Profile | |||
| if ((c->ps == -1 && c->object_type != AOT_AAC_LC) || c->channels & ~0x01) | |||
| c->ps = 0; | |||
| return specific_config_bitindex; | |||
| } | |||
| @@ -0,0 +1,80 @@ | |||
| /* | |||
| * 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> | |||
| #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_mode; | |||
| 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 */ | |||
| @@ -0,0 +1,93 @@ | |||
| /* | |||
| * Generate a 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 | |||
| */ | |||
| #include <stdlib.h> | |||
| #define CONFIG_HARDCODED_TABLES 0 | |||
| #include "ps_tablegen.h" | |||
| #include "tableprint.h" | |||
| void write_float_3d_array (const void *p, int b, int c, int d) | |||
| { | |||
| int i; | |||
| const float *f = p; | |||
| for (i = 0; i < b; i++) { | |||
| printf("{\n"); | |||
| write_float_2d_array(f, c, d); | |||
| printf("},\n"); | |||
| f += c * d; | |||
| } | |||
| } | |||
| void write_float_4d_array (const void *p, int a, int b, int c, int d) | |||
| { | |||
| int i; | |||
| const float *f = p; | |||
| for (i = 0; i < a; i++) { | |||
| printf("{\n"); | |||
| write_float_3d_array(f, b, c, d); | |||
| printf("},\n"); | |||
| f += b * c * d; | |||
| } | |||
| } | |||
| int main(void) | |||
| { | |||
| ps_tableinit(); | |||
| write_fileheader(); | |||
| printf("static const float pd_re_smooth[8*8*8] = {\n"); | |||
| write_float_array(pd_re_smooth, 8*8*8); | |||
| printf("};\n"); | |||
| printf("static const float pd_im_smooth[8*8*8] = {\n"); | |||
| write_float_array(pd_im_smooth, 8*8*8); | |||
| printf("};\n"); | |||
| printf("static const float HA[46][8][4] = {\n"); | |||
| write_float_3d_array(HA, 46, 8, 4); | |||
| printf("};\n"); | |||
| printf("static const float HB[46][8][4] = {\n"); | |||
| write_float_3d_array(HB, 46, 8, 4); | |||
| printf("};\n"); | |||
| printf("static const float f20_0_8[8][7][2] = {\n"); | |||
| write_float_3d_array(f20_0_8, 8, 7, 2); | |||
| printf("};\n"); | |||
| printf("static const float f34_0_12[12][7][2] = {\n"); | |||
| write_float_3d_array(f34_0_12, 12, 7, 2); | |||
| printf("};\n"); | |||
| printf("static const float f34_1_8[8][7][2] = {\n"); | |||
| write_float_3d_array(f34_1_8, 8, 7, 2); | |||
| printf("};\n"); | |||
| printf("static const float f34_2_4[4][7][2] = {\n"); | |||
| write_float_3d_array(f34_2_4, 4, 7, 2); | |||
| printf("};\n"); | |||
| printf("static const float Q_fract_allpass[2][50][3][2] = {\n"); | |||
| write_float_4d_array(Q_fract_allpass, 2, 50, 3, 2); | |||
| printf("};\n"); | |||
| printf("static const float phi_fract[2][50][2] = {\n"); | |||
| write_float_3d_array(phi_fract, 2, 50, 2); | |||
| printf("};\n"); | |||
| return 0; | |||
| } | |||
| @@ -0,0 +1,221 @@ | |||
| /* | |||
| * 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 PS_TABLEGEN_H | |||
| #define PS_TABLEGEN_H | |||
| #include <stdint.h> | |||
| #include <math.h> | |||
| #if CONFIG_HARDCODED_TABLES | |||
| #define ps_tableinit() | |||
| #include "libavcodec/ps_tables.h" | |||
| #else | |||
| #include "../libavutil/common.h" | |||
| #ifndef M_SQRT1_2 | |||
| #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ | |||
| #endif | |||
| #ifndef M_PI | |||
| #define M_PI 3.14159265358979323846 /* pi */ | |||
| #endif | |||
| #ifndef M_SQRT2 | |||
| #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ | |||
| #endif | |||
| #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 /* PS_TABLEGEN_H */ | |||
| @@ -0,0 +1,163 @@ | |||
| /* | |||
| * 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 | |||
| }; | |||
| @@ -31,6 +31,7 @@ | |||
| #include <stdint.h> | |||
| #include "fft.h" | |||
| #include "ps.h" | |||
| /** | |||
| * Spectral Band Replication header - spectrum parameters that invoke a reset if they differ from the previous header. | |||
| @@ -133,6 +134,7 @@ typedef struct { | |||
| ///The number of frequency bands in f_master | |||
| unsigned n_master; | |||
| SBRData data[2]; | |||
| PSContext ps; | |||
| ///N_Low and N_High respectively, the number of frequency bands for low and high resolution | |||
| unsigned n[2]; | |||
| ///Number of noise floor bands | |||
| @@ -157,7 +159,7 @@ typedef struct { | |||
| ///QMF output of the HF generator | |||
| float X_high[64][40][2]; | |||
| ///QMF values of the reconstructed signal | |||
| DECLARE_ALIGNED(16, float, X)[2][2][32][64]; | |||
| DECLARE_ALIGNED(16, float, X)[2][2][38][64]; | |||
| ///Zeroth coefficient used to filter the subband signals | |||
| float alpha0[64][2]; | |||
| ///First coefficient used to filter the subband signals | |||