diff options
Diffstat (limited to 'libavcodec/aacsbr.c')
-rw-r--r-- | libavcodec/aacsbr.c | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/libavcodec/aacsbr.c b/libavcodec/aacsbr.c index add9f18b49..714e48c1ff 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 <alex.converse@gmail.com> * - * 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 <stdint.h> #include <float.h> +#include <math.h> #define ENVELOPE_ADJUSTMENT_OFFSET 2 #define NOISE_FLOOR_OFFSET 6.0f @@ -139,6 +141,8 @@ static void sbr_turnoff(SpectralBandReplication *sbr) { av_cold void ff_aac_sbr_ctx_init(AACContext *ac, SpectralBandReplication *sbr) { + 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); @@ -333,9 +337,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]; @@ -361,6 +362,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) { @@ -548,7 +552,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; @@ -742,7 +746,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; @@ -926,7 +930,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; @@ -1570,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; @@ -1597,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; @@ -1627,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; |