X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Faacsbr.c;h=5bae921e18407693a7418135ea35c6dd38ce4c53;hb=59b68ee8870ad7b831321ff39638660ac59e4a18;hp=b1c4e73ffc5631baa4b1cef0fe3c3ce70a658fce;hpb=8f4c414df6b81c3ee3f12de1504ae7ccb5f8053a;p=ffmpeg diff --git a/libavcodec/aacsbr.c b/libavcodec/aacsbr.c index b1c4e73ffc5..5bae921e184 100644 --- a/libavcodec/aacsbr.c +++ b/libavcodec/aacsbr.c @@ -3,20 +3,20 @@ * Copyright (c) 2008-2009 Robert Swain ( rob opendot cl ) * Copyright (c) 2009-2010 Alex Converse * - * 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 */ @@ -34,9 +34,11 @@ #include "aacps.h" #include "sbrdsp.h" #include "libavutil/libm.h" +#include "libavutil/avassert.h" #include #include +#include #define ENVELOPE_ADJUSTMENT_OFFSET 2 #define NOISE_FLOOR_OFFSET 6.0f @@ -140,7 +142,8 @@ static void sbr_turnoff(SpectralBandReplication *sbr) { 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]; sbr_turnoff(sbr); sbr->data[0].synthesis_filterbank_samples_offset = SBR_SYNTHESIS_BUF_SIZE - (1280 - 128); @@ -148,9 +151,8 @@ av_cold void ff_aac_sbr_ctx_init(AACContext *ac, SpectralBandReplication *sbr) /* 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_mdct_init(&sbr->mdct, 7, 1, 1.0 / (64 * 32768.0)); + ff_mdct_init(&sbr->mdct_ana, 7, 1, -2.0 * 32768.0); ff_ps_ctx_init(&sbr->ps); ff_sbrdsp_init(&sbr->dsp); } @@ -336,9 +338,6 @@ static int sbr_make_f_master(AACContext *ac, SpectralBandReplication *sbr, } 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]; @@ -364,6 +363,9 @@ static int sbr_make_f_master(AACContext *ac, SpectralBandReplication *sbr, return -1; } + start_min = ((temp << 7) + (sbr->sample_rate >> 1)) / sbr->sample_rate; + stop_min = ((temp << 8) + (sbr->sample_rate >> 1)) / sbr->sample_rate; + sbr->k[0] = start_min + sbr_offset_ptr[spectrum->bs_start_freq]; if (spectrum->bs_stop_freq < 14) { @@ -551,7 +553,7 @@ static int sbr_hf_calc_npatches(AACContext *ac, SpectralBandReplication *sbr) 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) + if (sbr->num_patches > 1 && sbr->patch_num_subbands[sbr->num_patches-1] < 3) sbr->num_patches--; return 0; @@ -745,7 +747,7 @@ static int read_sbr_grid(AACContext *ac, SpectralBandReplication *sbr, 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); + idx = ch_data->bs_num_env - FFMAX((int)bs_pointer - 1, 1); } else { // VARFIX if (!bs_pointer) idx = 1; @@ -929,7 +931,9 @@ static void read_sbr_extension(AACContext *ac, SpectralBandReplication *sbr, } break; default: - av_log_missing_feature(ac->avctx, "Reserved SBR extensions", 1); + // some files contain 0-padding + if (bs_extension_id || *num_bits_left > 16 || show_bits(gb, *num_bits_left)) + av_log_missing_feature(ac->avctx, "Reserved SBR extensions", 1); skip_bits_long(gb, *num_bits_left); // bs_fill_bits *num_bits_left = 0; break; @@ -1572,10 +1576,6 @@ static void sbr_hf_assemble(float Y1[38][64][2], 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; @@ -1599,7 +1599,6 @@ static void sbr_hf_assemble(float Y1[38][64][2], 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; @@ -1629,13 +1628,17 @@ static void sbr_hf_assemble(float Y1[38][64][2], 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; + int idx = indexsine&1; + int A = (1-((indexsine+(kx & 1))&2)); + int B = (A^(-idx)) + idx; + float *out = &Y1[i][kx][idx]; + float *in = sbr->s_m[e]; + for (m = 0; m+1 < m_max; m+=2) { + out[2*m ] += in[m ] * A; + out[2*m+2] += in[m+1] * B; } + if(m_max&1) + out[2*m ] += in[m ] * A; } indexnoise = (indexnoise + m_max) & 0x1ff; indexsine = (indexsine + 1) & 3;