comparison ac3dec.c @ 5318:ef4ef249ca72 libavcodec

AC-3 decoder, soc revision 58, Aug 19 14:20:45 2006 UTC by cloud9 Further optimizations.
author jbr
date Sat, 14 Jul 2007 16:02:32 +0000
parents 6d81881f257f
children 40af705cef7e
comparison
equal deleted inserted replaced
5317:6d81881f257f 5318:ef4ef249ca72
1577 1577
1578 ff_imdct_calc(&ctx->imdct_256, ctx->tmp_output, x1, ctx->tmp_imdct); 1578 ff_imdct_calc(&ctx->imdct_256, ctx->tmp_output, x1, ctx->tmp_imdct);
1579 ff_imdct_calc(&ctx->imdct_256, ctx->tmp_output + 256, x2, ctx->tmp_imdct); 1579 ff_imdct_calc(&ctx->imdct_256, ctx->tmp_output + 256, x2, ctx->tmp_imdct);
1580 1580
1581 ptr = ctx->output[chindex]; 1581 ptr = ctx->output[chindex];
1582 ctx->dsp.vector_fmul_add_add(ptr, ctx->tmp_output, window, ctx->delay[chindex], 0, BLOCK_SIZE, 1); 1582 ctx->dsp.vector_fmul_add_add(ptr, ctx->tmp_output, window, ctx->delay[chindex], 384, BLOCK_SIZE, 1);
1583 ptr = ctx->delay[chindex]; 1583 ptr = ctx->delay[chindex];
1584 ctx->dsp.vector_fmul_reverse(ptr, ctx->tmp_output + 256, window, BLOCK_SIZE); 1584 ctx->dsp.vector_fmul_reverse(ptr, ctx->tmp_output + 256, window, BLOCK_SIZE);
1585 /*for (k = 0; k < N / 2; k++) {
1586 ctx->output[chindex][k] = ctx->tmp_output[k] * window[k] + ctx->delay[chindex][k];
1587 //dump_floats("samples", 10, ctx->output[chindex], 256);
1588 ctx->delay[chindex][k] = ctx->tmp_output[N / 2 + k] * window[255 - k];
1589 }*/
1590 } 1585 }
1591 1586
1592 static void do_imdct_512(AC3DecodeContext *ctx, int chindex) 1587 static void do_imdct_512(AC3DecodeContext *ctx, int chindex)
1593 { 1588 {
1594 //int k;
1595 float *ptr; 1589 float *ptr;
1596 1590
1597 ff_imdct_calc(&ctx->imdct_512, ctx->tmp_output, 1591 ff_imdct_calc(&ctx->imdct_512, ctx->tmp_output,
1598 ctx->transform_coeffs[chindex], ctx->tmp_imdct); 1592 ctx->transform_coeffs[chindex], ctx->tmp_imdct);
1599 //ff_imdct_calc_ac3_512(&ctx->imdct_512, ctx->tmp_output, ctx->transform_coeffs[chindex],
1600 // ctx->tmp_imdct, window);
1601 ptr = ctx->output[chindex]; 1593 ptr = ctx->output[chindex];
1602 ctx->dsp.vector_fmul_add_add(ptr, ctx->tmp_output, window, ctx->delay[chindex], 0, BLOCK_SIZE, 1); 1594 ctx->dsp.vector_fmul_add_add(ptr, ctx->tmp_output, window, ctx->delay[chindex], 384, BLOCK_SIZE, 1);
1603 ptr = ctx->delay[chindex]; 1595 ptr = ctx->delay[chindex];
1604 ctx->dsp.vector_fmul_reverse(ptr, ctx->tmp_output + 256, window, BLOCK_SIZE); 1596 ctx->dsp.vector_fmul_reverse(ptr, ctx->tmp_output + 256, window, BLOCK_SIZE);
1605
1606 /*for (k = 0; k < N / 2; k++) {
1607 ctx->output[chindex][k] = ctx->tmp_output[k] * window[k] + ctx->delay[chindex][k];
1608 //dump_floats("samples", 10, ctx->output[chindex], 256);
1609 ctx->delay[chindex][k] = ctx->tmp_output[N / 2 + k] * window[255 - k];
1610 } */
1611 } 1597 }
1612 1598
1613 static inline void do_imdct(AC3DecodeContext *ctx) 1599 static inline void do_imdct(AC3DecodeContext *ctx)
1614 { 1600 {
1615 int i; 1601 int i;
1897 1883
1898 /* recover coefficients if rematrixing is in use */ 1884 /* recover coefficients if rematrixing is in use */
1899 if (ctx->rematflg) 1885 if (ctx->rematflg)
1900 do_rematrixing(ctx); 1886 do_rematrixing(ctx);
1901 1887
1888 do_downmix(ctx);
1889
1902 do_imdct(ctx); 1890 do_imdct(ctx);
1903 /*for(i = 0; i < nfchans; i++) 1891 /*for(i = 0; i < nfchans; i++)
1904 dump_floats("channel output", 10, ctx->output[i + 1], BLOCK_SIZE);*/ 1892 dump_floats("channel output", 10, ctx->output[i + 1], BLOCK_SIZE);*/
1905 1893
1906 do_downmix(ctx);
1907
1908 return 0; 1894 return 0;
1909 } 1895 }
1910 1896
1911 static inline int16_t convert(float f) 1897 /*static inline int16_t convert(float f)
1912 { 1898 {
1913 if (f >= 1.0) 1899 if (f >= 1.0)
1914 return 32767; 1900 return 32767;
1915 else if (f <= -1.0) 1901 else if (f <= -1.0)
1916 return -32768; 1902 return -32768;
1917 else 1903 else
1918 return (lrintf(f * 32767.0)); 1904 return (lrintf(f * 32767.0));
1905 }*/
1906
1907 static inline int16_t convert(int32_t i)
1908 {
1909 if (i > 0x43c07fff)
1910 return 32767;
1911 else if (i <= 0x43bf8000)
1912 return -32768;
1913 else
1914 return (i - 0x43c00000);
1919 } 1915 }
1920 1916
1921 static int frame_count = 0; 1917 static int frame_count = 0;
1922 1918
1923 static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size, uint8_t *buf, int buf_size) 1919 static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size, uint8_t *buf, int buf_size)
1924 { 1920 {
1925 AC3DecodeContext *ctx = (AC3DecodeContext *)avctx->priv_data; 1921 AC3DecodeContext *ctx = (AC3DecodeContext *)avctx->priv_data;
1926 int frame_start; 1922 int frame_start;
1927 int16_t *out_samples = (int16_t *)data; 1923 int16_t *out_samples = (int16_t *)data;
1928 int i, j, k, value; 1924 int i, j, k, start;
1929 1925 int32_t *int_ptr[6];
1930 av_log(NULL, AV_LOG_INFO, "decoding frame %d buf_size = %d\n", frame_count++, buf_size); 1926
1927 for (i = 0; i < 6; i++)
1928 int_ptr[i] = (int32_t *)(&ctx->output[i]);
1929
1930 //av_log(NULL, AV_LOG_INFO, "decoding frame %d buf_size = %d\n", frame_count++, buf_size);
1931 1931
1932 //Synchronize the frame. 1932 //Synchronize the frame.
1933 frame_start = ac3_synchronize(buf, buf_size); 1933 frame_start = ac3_synchronize(buf, buf_size);
1934 if (frame_start == -1) { 1934 if (frame_start == -1) {
1935 av_log(avctx, AV_LOG_ERROR, "frame is not synchronized\n"); 1935 av_log(avctx, AV_LOG_ERROR, "frame is not synchronized\n");
1976 if (ctx->lfeon) 1976 if (ctx->lfeon)
1977 ctx->blkoutput |= AC3_OUTPUT_LFEON; 1977 ctx->blkoutput |= AC3_OUTPUT_LFEON;
1978 avctx->channels = ctx->nfchans + ctx->lfeon; 1978 avctx->channels = ctx->nfchans + ctx->lfeon;
1979 } 1979 }
1980 1980
1981 av_log(avctx, AV_LOG_INFO, "channels = %d \t bit rate = %d \t sampling rate = %d \n", avctx->channels, avctx->bit_rate * 1000, avctx->sample_rate); 1981 //av_log(avctx, AV_LOG_INFO, "channels = %d \t bit rate = %d \t sampling rate = %d \n", avctx->channels, avctx->bit_rate * 1000, avctx->sample_rate);
1982 1982
1983 //Parse the Audio Blocks. 1983 //Parse the Audio Blocks.
1984 for (i = 0; i < AUDIO_BLOCKS; i++) { 1984 for (i = 0; i < AUDIO_BLOCKS; i++) {
1985 if (ac3_parse_audio_block(ctx)) { 1985 if (ac3_parse_audio_block(ctx)) {
1986 av_log(avctx, AV_LOG_ERROR, "error parsing the audio block\n"); 1986 av_log(avctx, AV_LOG_ERROR, "error parsing the audio block\n");
1987 *data_size = 0; 1987 *data_size = 0;
1988 return ctx->frame_size; 1988 return ctx->frame_size;
1989 } 1989 }
1990 for (k = 0; k < BLOCK_SIZE; k++) { 1990 start = (ctx->blkoutput & AC3_OUTPUT_LFEON) ? 0 : 1;
1991 j = (ctx->blkoutput & AC3_OUTPUT_LFEON) ? 0 : 1; 1991 for (k = 0; k < BLOCK_SIZE; k++)
1992 for (; j <= avctx->channels; j++) { 1992 for (j = start; j <= avctx->channels; j++)
1993 value = convert(ctx->output[j][k]); 1993 *(out_samples++) = convert(int_ptr[j][k]);
1994 *(out_samples++) = value;
1995 }
1996 }
1997 } 1994 }
1998 *data_size = AUDIO_BLOCKS * BLOCK_SIZE * avctx->channels * sizeof (int16_t); 1995 *data_size = AUDIO_BLOCKS * BLOCK_SIZE * avctx->channels * sizeof (int16_t);
1999 return ctx->frame_size; 1996 return ctx->frame_size;
2000 } 1997 }
2001 1998