comparison aac.c @ 11481:96dde15b2e0d libavcodec

aac: Don't bias output during the IMDCT if SBR will be used.
author alexc
date Sat, 13 Mar 2010 21:12:10 +0000
parents e340262ba532
children 1aba21918874
comparison
equal deleted inserted replaced
11480:534872e7ab38 11481:96dde15b2e0d
1717 } 1717 }
1718 1718
1719 /** 1719 /**
1720 * Conduct IMDCT and windowing. 1720 * Conduct IMDCT and windowing.
1721 */ 1721 */
1722 static void imdct_and_windowing(AACContext *ac, SingleChannelElement *sce) 1722 static void imdct_and_windowing(AACContext *ac, SingleChannelElement *sce, float bias)
1723 { 1723 {
1724 IndividualChannelStream *ics = &sce->ics; 1724 IndividualChannelStream *ics = &sce->ics;
1725 float *in = sce->coeffs; 1725 float *in = sce->coeffs;
1726 float *out = sce->ret; 1726 float *out = sce->ret;
1727 float *saved = sce->saved; 1727 float *saved = sce->saved;
1749 * transitions. This leaves just two cases (long to long and short to short) 1749 * transitions. This leaves just two cases (long to long and short to short)
1750 * with a little special sauce for EIGHT_SHORT_SEQUENCE. 1750 * with a little special sauce for EIGHT_SHORT_SEQUENCE.
1751 */ 1751 */
1752 if ((ics->window_sequence[1] == ONLY_LONG_SEQUENCE || ics->window_sequence[1] == LONG_STOP_SEQUENCE) && 1752 if ((ics->window_sequence[1] == ONLY_LONG_SEQUENCE || ics->window_sequence[1] == LONG_STOP_SEQUENCE) &&
1753 (ics->window_sequence[0] == ONLY_LONG_SEQUENCE || ics->window_sequence[0] == LONG_START_SEQUENCE)) { 1753 (ics->window_sequence[0] == ONLY_LONG_SEQUENCE || ics->window_sequence[0] == LONG_START_SEQUENCE)) {
1754 ac->dsp.vector_fmul_window( out, saved, buf, lwindow_prev, ac->add_bias, 512); 1754 ac->dsp.vector_fmul_window( out, saved, buf, lwindow_prev, bias, 512);
1755 } else { 1755 } else {
1756 for (i = 0; i < 448; i++) 1756 for (i = 0; i < 448; i++)
1757 out[i] = saved[i] + ac->add_bias; 1757 out[i] = saved[i] + bias;
1758 1758
1759 if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { 1759 if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
1760 ac->dsp.vector_fmul_window(out + 448 + 0*128, saved + 448, buf + 0*128, swindow_prev, ac->add_bias, 64); 1760 ac->dsp.vector_fmul_window(out + 448 + 0*128, saved + 448, buf + 0*128, swindow_prev, bias, 64);
1761 ac->dsp.vector_fmul_window(out + 448 + 1*128, buf + 0*128 + 64, buf + 1*128, swindow, ac->add_bias, 64); 1761 ac->dsp.vector_fmul_window(out + 448 + 1*128, buf + 0*128 + 64, buf + 1*128, swindow, bias, 64);
1762 ac->dsp.vector_fmul_window(out + 448 + 2*128, buf + 1*128 + 64, buf + 2*128, swindow, ac->add_bias, 64); 1762 ac->dsp.vector_fmul_window(out + 448 + 2*128, buf + 1*128 + 64, buf + 2*128, swindow, bias, 64);
1763 ac->dsp.vector_fmul_window(out + 448 + 3*128, buf + 2*128 + 64, buf + 3*128, swindow, ac->add_bias, 64); 1763 ac->dsp.vector_fmul_window(out + 448 + 3*128, buf + 2*128 + 64, buf + 3*128, swindow, bias, 64);
1764 ac->dsp.vector_fmul_window(temp, buf + 3*128 + 64, buf + 4*128, swindow, ac->add_bias, 64); 1764 ac->dsp.vector_fmul_window(temp, buf + 3*128 + 64, buf + 4*128, swindow, bias, 64);
1765 memcpy( out + 448 + 4*128, temp, 64 * sizeof(float)); 1765 memcpy( out + 448 + 4*128, temp, 64 * sizeof(float));
1766 } else { 1766 } else {
1767 ac->dsp.vector_fmul_window(out + 448, saved + 448, buf, swindow_prev, ac->add_bias, 64); 1767 ac->dsp.vector_fmul_window(out + 448, saved + 448, buf, swindow_prev, bias, 64);
1768 for (i = 576; i < 1024; i++) 1768 for (i = 576; i < 1024; i++)
1769 out[i] = buf[i-512] + ac->add_bias; 1769 out[i] = buf[i-512] + bias;
1770 } 1770 }
1771 } 1771 }
1772 1772
1773 // buffer update 1773 // buffer update
1774 if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { 1774 if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
1775 for (i = 0; i < 64; i++) 1775 for (i = 0; i < 64; i++)
1776 saved[i] = temp[64 + i] - ac->add_bias; 1776 saved[i] = temp[64 + i] - bias;
1777 ac->dsp.vector_fmul_window(saved + 64, buf + 4*128 + 64, buf + 5*128, swindow, 0, 64); 1777 ac->dsp.vector_fmul_window(saved + 64, buf + 4*128 + 64, buf + 5*128, swindow, 0, 64);
1778 ac->dsp.vector_fmul_window(saved + 192, buf + 5*128 + 64, buf + 6*128, swindow, 0, 64); 1778 ac->dsp.vector_fmul_window(saved + 192, buf + 5*128 + 64, buf + 6*128, swindow, 0, 64);
1779 ac->dsp.vector_fmul_window(saved + 320, buf + 6*128 + 64, buf + 7*128, swindow, 0, 64); 1779 ac->dsp.vector_fmul_window(saved + 320, buf + 6*128 + 64, buf + 7*128, swindow, 0, 64);
1780 memcpy( saved + 448, buf + 7*128 + 64, 64 * sizeof(float)); 1780 memcpy( saved + 448, buf + 7*128 + 64, 64 * sizeof(float));
1781 } else if (ics->window_sequence[0] == LONG_START_SEQUENCE) { 1781 } else if (ics->window_sequence[0] == LONG_START_SEQUENCE) {
1882 * Convert spectral data to float samples, applying all supported tools as appropriate. 1882 * Convert spectral data to float samples, applying all supported tools as appropriate.
1883 */ 1883 */
1884 static void spectral_to_sample(AACContext *ac) 1884 static void spectral_to_sample(AACContext *ac)
1885 { 1885 {
1886 int i, type; 1886 int i, type;
1887 float imdct_bias = (ac->m4ac.sbr <= 0) ? ac->add_bias : 0.0f;
1887 for (type = 3; type >= 0; type--) { 1888 for (type = 3; type >= 0; type--) {
1888 for (i = 0; i < MAX_ELEM_ID; i++) { 1889 for (i = 0; i < MAX_ELEM_ID; i++) {
1889 ChannelElement *che = ac->che[type][i]; 1890 ChannelElement *che = ac->che[type][i];
1890 if (che) { 1891 if (che) {
1891 if (type <= TYPE_CPE) 1892 if (type <= TYPE_CPE)
1895 if (che->ch[1].tns.present) 1896 if (che->ch[1].tns.present)
1896 apply_tns(che->ch[1].coeffs, &che->ch[1].tns, &che->ch[1].ics, 1); 1897 apply_tns(che->ch[1].coeffs, &che->ch[1].tns, &che->ch[1].ics, 1);
1897 if (type <= TYPE_CPE) 1898 if (type <= TYPE_CPE)
1898 apply_channel_coupling(ac, che, type, i, BETWEEN_TNS_AND_IMDCT, apply_dependent_coupling); 1899 apply_channel_coupling(ac, che, type, i, BETWEEN_TNS_AND_IMDCT, apply_dependent_coupling);
1899 if (type != TYPE_CCE || che->coup.coupling_point == AFTER_IMDCT) { 1900 if (type != TYPE_CCE || che->coup.coupling_point == AFTER_IMDCT) {
1900 imdct_and_windowing(ac, &che->ch[0]); 1901 imdct_and_windowing(ac, &che->ch[0], imdct_bias);
1901 if (ac->m4ac.sbr > 0) { 1902 if (ac->m4ac.sbr > 0) {
1902 ff_sbr_dequant(ac, &che->sbr, type == TYPE_CPE ? TYPE_CPE : TYPE_SCE); 1903 ff_sbr_dequant(ac, &che->sbr, type == TYPE_CPE ? TYPE_CPE : TYPE_SCE);
1903 ff_sbr_apply(ac, &che->sbr, 0, che->ch[0].ret, che->ch[0].ret); 1904 ff_sbr_apply(ac, &che->sbr, 0, che->ch[0].ret, che->ch[0].ret);
1904 } 1905 }
1905 } 1906 }
1906 if (type == TYPE_CPE) { 1907 if (type == TYPE_CPE) {
1907 imdct_and_windowing(ac, &che->ch[1]); 1908 imdct_and_windowing(ac, &che->ch[1], imdct_bias);
1908 if (ac->m4ac.sbr > 0) 1909 if (ac->m4ac.sbr > 0)
1909 ff_sbr_apply(ac, &che->sbr, 1, che->ch[1].ret, che->ch[1].ret); 1910 ff_sbr_apply(ac, &che->sbr, 1, che->ch[1].ret, che->ch[1].ret);
1910 } 1911 }
1911 if (type <= TYPE_CCE) 1912 if (type <= TYPE_CCE)
1912 apply_channel_coupling(ac, che, type, i, AFTER_IMDCT, apply_independent_coupling); 1913 apply_channel_coupling(ac, che, type, i, AFTER_IMDCT, apply_independent_coupling);