Mercurial > libavcodec.hg
comparison ac3dec.c @ 5307:1bcccd2de20d libavcodec
AC-3 decoder, soc revision 33, Jul 17 12:13:40 2006 UTC by cloud9
getting weired output
but its working
| author | jbr |
|---|---|
| date | Sat, 14 Jul 2007 15:49:12 +0000 |
| parents | abc5c130b448 |
| children | 82b41f5a86ef |
comparison
equal
deleted
inserted
replaced
| 5306:abc5c130b448 | 5307:1bcccd2de20d |
|---|---|
| 1480 } | 1480 } |
| 1481 if ((i & 7) != 0) | 1481 if ((i & 7) != 0) |
| 1482 av_log(NULL, AV_LOG_INFO, "\n"); | 1482 av_log(NULL, AV_LOG_INFO, "\n"); |
| 1483 } | 1483 } |
| 1484 | 1484 |
| 1485 static void window_and_de_interleave(float *output) | 1485 /*static void window_and_de_interleave(float *output) |
| 1486 { | 1486 { |
| 1487 int n2, n4, n8; | 1487 int n2, n4, n8; |
| 1488 int k; | 1488 int k; |
| 1489 | 1489 |
| 1490 n2 = 512 >> 1; | 1490 n2 = 512 >> 1; |
| 1491 n4 = 512 >> 2; | 1491 n4 = 512 >> 2; |
| 1492 n8 = 512 >> 3; | 1492 n8 = 512 >> 3; |
| 1493 | 1493 |
| 1494 for (k = 0; k < n8; k++) { | 1494 for (k = 0; k < n8; k++) { |
| 1495 output[2 * k] *= window[2 * k]; | 1495 output[2 * k] *= window[2 * k]; |
| 1496 output[n2 - 2 * k - 1] *= window[n2 - 2 * k - 1]; | |
| 1497 | |
| 1496 output[2 * k + 1] *= window[2 * k + 1]; | 1498 output[2 * k + 1] *= window[2 * k + 1]; |
| 1497 output[n4 + 2 * k] *= window[n4 + 2 * k]; | 1499 output[n2 - 2 * k - 2] *= window[n2 - 2 * k - 2]; |
| 1498 output[n4 + 2 * k + 1] *= window[n4 + 2 * k + 1]; | 1500 |
| 1499 output[n2 + 2 * k] *= window[n2 - 2 * k - 1]; | 1501 output[n2 + 2 * k] *= window[n2 - 2 * k - 1]; |
| 1502 output[n - 2 * k - 1] *= window[n - 2 * k - 1]; | |
| 1503 | |
| 1500 output[n2 + 2 * k + 1] *= window[n2 - 2 * k - 2]; | 1504 output[n2 + 2 * k + 1] *= window[n2 - 2 * k - 2]; |
| 1501 output[3 * n4 + 2 * k] *= window[n4 -2 * k - 1]; | 1505 output[n - 2 * k - 2] *= window[n - 2 * k - 2]; |
| 1502 output[3 * n4 + 2 * k + 1] *= window[n4 - 2 * k - 2]; | 1506 output[3 * n4 + 2 * k + 1] *= window[n4 - 2 * k - 2]; |
| 1503 } | 1507 } |
| 1504 } | 1508 }*/ |
| 1505 | 1509 |
| 1506 static inline void overlap_and_add(float *tmp_output, float *delay, float *output) | 1510 static inline void overlap_and_add(float *tmp_output, float *delay, float *output) |
| 1507 { | 1511 { |
| 1508 int n; | 1512 int n; |
| 1509 | 1513 |
| 1510 for (n = 0; n < BLOCK_SIZE; n++) { | 1514 for (n = 0; n < BLOCK_SIZE; n++) { |
| 1511 output[n] = 2 * (tmp_output[n] + delay[n]); | 1515 output[n] = 2 * (tmp_output[n] * window[n] + delay[n] * window[255 - n]); |
| 1512 delay[n] = tmp_output[BLOCK_SIZE + n]; | 1516 delay[n] = tmp_output[BLOCK_SIZE + n]; |
| 1513 } | 1517 } |
| 1514 } | 1518 } |
| 1515 | 1519 |
| 1516 | 1520 |
| 1520 int i; | 1524 int i; |
| 1521 | 1525 |
| 1522 if (ctx->output & AC3_OUTPUT_LFEON) { | 1526 if (ctx->output & AC3_OUTPUT_LFEON) { |
| 1523 av_log(NULL, AV_LOG_INFO, "imdct lfe\n"); | 1527 av_log(NULL, AV_LOG_INFO, "imdct lfe\n"); |
| 1524 ff_imdct_calc(&ctx->imdct_ctx_512, ab->tmp_output, ab->transform_coeffs[0], ab->tmp_imdct); | 1528 ff_imdct_calc(&ctx->imdct_ctx_512, ab->tmp_output, ab->transform_coeffs[0], ab->tmp_imdct); |
| 1525 window_and_de_interleave(ab->tmp_output); | 1529 //window_and_de_interleave(ab->tmp_output); |
| 1526 overlap_and_add(ab->tmp_output, ab->delay[0], ab->output[0]); | 1530 overlap_and_add(ab->tmp_output, ab->delay[0], ab->output[0]); |
| 1527 } | 1531 } |
| 1528 for (i = 0; i < ctx->bsi.nfchans; i++) { | 1532 for (i = 0; i < ctx->bsi.nfchans; i++) { |
| 1529 if (!(((ab->blksw) >> i) & 1)) { | 1533 if (!(((ab->blksw) >> i) & 1)) { |
| 1530 av_log(NULL, AV_LOG_INFO, "imdct channel %d - block switching not enabled\n", i); | 1534 av_log(NULL, AV_LOG_INFO, "imdct channel %d - block switching not enabled\n", i); |
| 1531 ff_imdct_calc(&ctx->imdct_ctx_512, ab->tmp_output, ab->transform_coeffs[i + 1], ab->tmp_imdct); | 1535 ff_imdct_calc(&ctx->imdct_ctx_512, ab->tmp_output, ab->transform_coeffs[i + 1], ab->tmp_imdct); |
| 1532 window_and_de_interleave(ab->tmp_output); | 1536 //window_and_de_interleave(ab->tmp_output); |
| 1533 overlap_and_add(ab->tmp_output, ab->delay[i + 1], ab->output[i + 1]); | 1537 overlap_and_add(ab->tmp_output, ab->delay[i + 1], ab->output[i + 1]); |
| 1534 } else { | 1538 } else { |
| 1535 av_log(NULL, AV_LOG_INFO, "imdct channel %d skipping - block switching enabled\n", i); | 1539 av_log(NULL, AV_LOG_INFO, "imdct channel %d skipping - block switching enabled\n", i); |
| 1536 } | 1540 } |
| 1537 } | 1541 } |
| 1811 /* recover coefficients if rematrixing is in use */ | 1815 /* recover coefficients if rematrixing is in use */ |
| 1812 if (*flags & AC3_AB_REMATSTR) | 1816 if (*flags & AC3_AB_REMATSTR) |
| 1813 do_rematrixing(ctx); | 1817 do_rematrixing(ctx); |
| 1814 | 1818 |
| 1815 do_imdct(ctx); | 1819 do_imdct(ctx); |
| 1816 for(i = 0; i < nfchans; i++) | 1820 /*for(i = 0; i < nfchans; i++) |
| 1817 dump_floats("channel output", 10, ab->output[i + 1], BLOCK_SIZE); | 1821 dump_floats("channel output", 10, ab->output[i + 1], BLOCK_SIZE);*/ |
| 1818 | 1822 |
| 1819 do_downmix(ctx); | 1823 do_downmix(ctx); |
| 1820 | 1824 |
| 1821 return 0; | 1825 return 0; |
| 1822 } | 1826 } |
| 1826 #define MAXSAMPLE (float)0x7fff | 1830 #define MAXSAMPLE (float)0x7fff |
| 1827 | 1831 |
| 1828 | 1832 |
| 1829 static inline int16_t convert(float f) | 1833 static inline int16_t convert(float f) |
| 1830 { | 1834 { |
| 1831 short s; | 1835 /*short s; |
| 1832 f = f * NORMFACT; | 1836 f = f * NORMFACT; |
| 1833 if (f >= 0) | 1837 if (f >= 0) |
| 1834 s = (short)(f + 0.5); | 1838 s = (short)(f + 0.5); |
| 1835 else | 1839 else |
| 1836 s = (short)(f - 0.5); | 1840 s = (short)(f - 0.5); |
| 1837 if ((float)s > MAXSAMPLE) | 1841 if ((float)s > MAXSAMPLE) |
| 1838 s = (float)MAXSAMPLE; | 1842 s = (float)MAXSAMPLE; |
| 1839 if (s < (short) -MAXSAMPLE) | 1843 if (s < (short) -MAXSAMPLE) |
| 1840 s = (short) -MAXSAMPLE; | 1844 s = (short) -MAXSAMPLE; |
| 1841 | 1845 |
| 1842 return s; | 1846 return s;*/ |
| 1847 int a; | |
| 1848 a = lrintf(f * 32767.0); | |
| 1849 return ((int16_t)a); | |
| 1843 } | 1850 } |
| 1844 | 1851 |
| 1845 static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size, uint8_t *buf, int buf_size) | 1852 static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size, uint8_t *buf, int buf_size) |
| 1846 { | 1853 { |
| 1847 AC3DecodeContext *ctx = (AC3DecodeContext *)avctx->priv_data; | 1854 AC3DecodeContext *ctx = (AC3DecodeContext *)avctx->priv_data; |
| 1913 } | 1920 } |
| 1914 j = ((ctx->output & AC3_OUTPUT_LFEON) ? 0 : 1); | 1921 j = ((ctx->output & AC3_OUTPUT_LFEON) ? 0 : 1); |
| 1915 for (;j < avctx->channels; j++) { | 1922 for (;j < avctx->channels; j++) { |
| 1916 for(k = 0; k < BLOCK_SIZE; k++) { | 1923 for(k = 0; k < BLOCK_SIZE; k++) { |
| 1917 value = convert(ab->output[j][k]); | 1924 value = convert(ab->output[j][k]); |
| 1925 av_log(NULL, AV_LOG_INFO, "%d\t", value); | |
| 1918 *(out_samples++) = value; | 1926 *(out_samples++) = value; |
| 1919 } | 1927 } |
| 1920 } | 1928 } |
| 1921 } | 1929 } |
| 1922 *data_size = AUDIO_BLOCKS * BLOCK_SIZE * avctx->channels * sizeof (int16_t); | 1930 *data_size = AUDIO_BLOCKS * BLOCK_SIZE * avctx->channels * sizeof (int16_t); |
