summaryrefslogtreecommitdiff
path: root/apps/codecs
diff options
context:
space:
mode:
authorMichael Giacomelli <giac2000@hotmail.com>2007-08-02 04:47:33 +0000
committerMichael Giacomelli <giac2000@hotmail.com>2007-08-02 04:47:33 +0000
commit206e883e78fe6bb5d65b150b757d7a9af76f472e (patch)
tree424b5c80c9ebe6f587dbd3bb93fcdb59b6374140 /apps/codecs
parent66029a58aeac41340f57d6b6c4f5c79eae04cc4a (diff)
downloadrockbox-206e883e78fe6bb5d65b150b757d7a9af76f472e.tar.gz
rockbox-206e883e78fe6bb5d65b150b757d7a9af76f472e.zip
Initial attept at supporting Line Spectral Pairs. Various issues remain, and the ffmpeg decoder itself often fails on certain valid LSP files. Expect some issues.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14134 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs')
-rw-r--r--apps/codecs/libwma/wmadata.h100
-rw-r--r--apps/codecs/libwma/wmadec.h4
-rw-r--r--apps/codecs/libwma/wmadeci.c99
3 files changed, 125 insertions, 78 deletions
diff --git a/apps/codecs/libwma/wmadata.h b/apps/codecs/libwma/wmadata.h
index d470d14581..7e2b6dd4a0 100644
--- a/apps/codecs/libwma/wmadata.h
+++ b/apps/codecs/libwma/wmadata.h
@@ -1425,9 +1425,10 @@ static const CoefVLCTable coef_vlcs[6] = {
1425 }, 1425 },
1426}; 1426};
1427 1427
1428 1428/*table of the values of 10^(index*.05)*/
1429const fixed64 pow_table[] = 1429const fixed64 pow_table[] =
1430 { 1430 { 0x199a, 0x1cb9, 0x203a, 0x2429, 0x2893, 0x2d86, 0x3314, 0x3950, 0x404e, 0x4827,
1431 0x50f4, 0x5ad5, 0x65ea, 0x725a, 0x804e, 0x8ff6, 0xa186, 0xb53c, 0xcb59, 0xe429,
1431 0x10000LL,0x11f3dLL,0x14249LL,0x1699cLL,0x195bcLL,0x1c73dLL,0x1fec9LL,0x23d1dLL,0x2830bLL,0x2d182LL, 1432 0x10000LL,0x11f3dLL,0x14249LL,0x1699cLL,0x195bcLL,0x1c73dLL,0x1fec9LL,0x23d1dLL,0x2830bLL,0x2d182LL,
1432 0x3298bLL,0x38c53LL,0x3fb28LL,0x47783LL,0x5030aLL,0x59f98LL,0x64f40LL,0x71457LL,0x7f17bLL,0x8e99aLL, 1433 0x3298bLL,0x38c53LL,0x3fb28LL,0x47783LL,0x5030aLL,0x59f98LL,0x64f40LL,0x71457LL,0x7f17bLL,0x8e99aLL,
1433 0xa0000LL,0xb385eLL,0xc96d9LL,0xe2019LL,0xfd954LL,0x11c865LL,0x13f3dfLL,0x166320LL,0x191e6eLL,0x1c2f10LL, 1434 0xa0000LL,0xb385eLL,0xc96d9LL,0xe2019LL,0xfd954LL,0x11c865LL,0x13f3dfLL,0x166320LL,0x191e6eLL,0x1c2f10LL,
@@ -1479,46 +1480,69 @@ const fixed32 pow_a_table[] =
14790x12fe,0x1307 14800x12fe,0x1307
1480}; 1481};
1481 1482
1483
1484/* 32.32 unsigned fixed format */
1485/* This is a table of exponent values for an IEEE SP float. Theres never anything less then about index 115
1486 * making the size of this table fairly ridiculous.
1487 */
1488
1489
1482const fixed64 lsp_pow_e_table[] = 1490const fixed64 lsp_pow_e_table[] =
1483{ 1491{
1484 0xf333f9deLL, 0xf0518db9LL, 0x0LL, 0x7e656b4fLL, 0x7999fcefLL, 0xf828c6dcLL, 0x0LL, 1492 0xb504f30000000000LL, 0x9837f00000000000LL, 0x8000000000000000LL, 0x6ba27e8000000000LL, 0x5a82798000000000LL,
1485 0x3f32b5a7LL, 0x3cccfe78LL, 0xfc14636eLL, 0x0LL, 0x9f995ad4LL, 0x9e667f3cLL, 0xfe0a31b7LL, 1493 0x4c1bf80000000000LL, 0x4000000000000000LL, 0x35d13f4000000000LL, 0x2d413cc000000000LL, 0x260dfc0000000000LL,
1486 0x0LL, 0x4fccad6aLL, 0x4f333f9eLL, 0x7f0518dcLL, 0x0LL, 0x27e656b5LL, 0x27999fcfLL, 1494 0x2000000000000000LL, 0x1ae89fa000000000LL, 0x16a09e6000000000LL, 0x1306fe0000000000LL, 0x1000000000000000LL,
1487 0xbf828c6eLL, 0x0LL, 0x13f32b5aLL, 0x13cccfe7LL, 0xdfc14637LL, 0x0LL, 0x89f995adLL, 1495 0xd744fd000000000LL, 0xb504f3000000000LL, 0x9837f0000000000LL, 0x800000000000000LL, 0x6ba27e800000000LL,
1488 0x9e667f4LL, 0x6fe0a31bLL, 0x0LL, 0x44fccad7LL, 0x4f333faLL, 0x37f0518eLL, 0x0LL, 1496 0x5a8279800000000LL, 0x4c1bf8000000000LL, 0x400000000000000LL, 0x35d13f400000000LL, 0x2d413cc00000000LL,
1489 0xa27e656bLL, 0x827999fdLL, 0x1bf828c7LL, 0x0LL, 0xd13f32b6LL, 0x413cccfeLL, 0xdfc1463LL, 1497 0x260dfc000000000LL, 0x200000000000000LL, 0x1ae89fa00000000LL, 0x16a09e600000000LL, 0x1306fe000000000LL,
1490 0x0LL, 0xe89f995bLL, 0xa09e667fLL, 0x6fe0a32LL, 0x0LL, 0x744fccadLL, 0x504f3340LL, 1498 0x100000000000000LL, 0xd744fd00000000LL, 0xb504f300000000LL, 0x9837f000000000LL, 0x80000000000000LL,
1491 0x837f0519LL, 0x0LL, 0xba27e657LL, 0xa82799a0LL, 0xc1bf828cLL, 0x0LL, 0x5d13f32bLL, 1499 0x6ba27e80000000LL, 0x5a827980000000LL, 0x4c1bf800000000LL, 0x40000000000000LL, 0x35d13f40000000LL,
1492 0xd413ccd0LL, 0x60dfc146LL, 0x0LL, 0xae89f996LL, 0x6a09e668LL, 0x306fe0a3LL, 0x0LL, 1500 0x2d413cc0000000LL, 0x260dfc00000000LL, 0x20000000000000LL, 0x1ae89fa0000000LL, 0x16a09e60000000LL,
1493 0xd744fccbLL, 0xb504f334LL, 0x9837f052LL, 0x80000000LL, 0x6ba27e65LL, 0x5a82799aLL, 1501 0x1306fe00000000LL, 0x10000000000000LL, 0xd744fd0000000LL, 0xb504f30000000LL, 0x9837f00000000LL,
1494 0x4c1bf829LL, 0x40000000LL, 0x35d13f33LL, 0x2d413ccdLL, 0x260dfc14LL, 0x20000000LL, 1502 0x8000000000000LL, 0x6ba27e8000000LL, 0x5a82798000000LL, 0x4c1bf80000000LL, 0x4000000000000LL,
1495 0x1ae89f99LL, 0x16a09e66LL, 0x1306fe0aLL, 0x10000000LL, 0xd744fcdLL, 0xb504f33LL, 1503 0x35d13f4000000LL, 0x2d413cc000000LL, 0x260dfc0000000LL, 0x2000000000000LL, 0x1ae89fa000000LL,
1496 0x9837f05LL, 0x8000000LL, 0x6ba27e6LL, 0x5a8279aLL, 0x4c1bf83LL, 0x4000000LL, 1504 0x16a09e6000000LL, 0x1306fe0000000LL, 0x1000000000000LL, 0xd744fd000000LL, 0xb504f3000000LL,
1497 0x35d13f3LL, 0x2d413cdLL, 0x260dfc1LL, 0x2000000LL, 0x1ae89faLL, 0x16a09e6LL, 1505 0x9837f0000000LL, 0x800000000000LL, 0x6ba27e800000LL, 0x5a8279800000LL, 0x4c1bf8000000LL,
1498 0x1306fe1LL, 0x1000000LL, 0xd744fdLL, 0xb504f3LL, 0x9837f0LL, 0x800000LL, 1506 0x400000000000LL, 0x35d13f400000LL, 0x2d413cc00000LL, 0x260dfc000000LL, 0x200000000000LL,
1499 0x6ba27eLL, 0x5a827aLL, 0x4c1bf8LL, 0x400000LL, 0x35d13fLL, 0x2d413dLL, 1507 0x1ae89fa00000LL, 0x16a09e600000LL, 0x1306fe000000LL, 0x100000000000LL, 0xd744fd00000LL,
1500 0x260dfcLL, 0x200000LL, 0x1ae8a0LL, 0x16a09eLL, 0x1306feLL, 0x100000LL, 1508 0xb504f300000LL, 0x9837f000000LL, 0x80000000000LL, 0x6ba27e80000LL, 0x5a827980000LL,
1501 0xd7450LL, 0xb504fLL, 0x9837fLL, 0x80000LL, 0x6ba28LL, 0x5a828LL, 0x4c1c0LL, 1509 0x4c1bf800000LL, 0x40000000000LL, 0x35d13f40000LL, 0x2d413cc0000LL, 0x260dfc00000LL,
1502 0x40000LL, 0x35d14LL, 0x2d414LL, 0x260e0LL, 0x20000LL, 0x1ae8aLL, 0x16a0aLL, 1510 0x20000000000LL, 0x1ae89fa0000LL, 0x16a09e60000LL, 0x1306fe00000LL, 0x10000000000LL,
1503 0x13070LL, 0x10000LL, 0xd745LL, 0xb505LL, 0x9838LL, 0x8000LL, 0x6ba2LL, 1511 0xd744fd0000LL, 0xb504f30000LL, 0x9837f00000LL, 0x8000000000LL, 0x6ba27e8000LL,
1504 0x5a82LL, 0x4c1cLL, 0x4000LL, 0x35d1LL, 0x2d41LL, 0x260eLL, 0x2000LL, 1512 0x5a82798000LL, 0x4c1bf80000LL, 0x4000000000LL, 0x35d13f4000LL, 0x2d413cc000LL,
1505 0x1ae9LL, 0x16a1LL, 0x1307LL, 0x1000LL, 0xd74LL, 0xb50LL, 0x983LL, 0x800LL, 1513 0x260dfc0000LL, 0x2000000000LL, 0x1ae89fa000LL, 0x16a09e6000LL, 0x1306fe0000LL,
1506 0x6baLL, 0x5a8LL, 0x4c2LL, 0x400LL, 0x35dLL, 0x2d4LL, 0x261LL, 0x200LL, 0x1afLL, 1514 0x1000000000LL, 0xd744fd000LL, 0xb504f3000LL, 0x9837f0000LL, 0x800000000LL,
1507 0x16aLL, 0x130LL, 0x100LL, 0xd7LL, 0xb5LL, 0x98LL, 0x80LL, 0x6cLL, 0x5bLL, 1515 0x6ba27e800LL, 0x5a8279800LL, 0x4c1bf8000LL, 0x400000000LL, 0x35d13f400LL,
1508 0x4cLL, 0x40LL, 0x36LL, 0x2dLL, 0x26LL, 0x20LL, 0x1bLL, 0x17LL, 0x13LL, 1516 0x2d413cc00LL, 0x260dfc000LL, 0x200000000LL, 0x1ae89fa00LL, 0x16a09e600LL,
1509 0x10LL, 0xdLL, 0xbLL, 0xaLL, 0x8LL, 0x7LL, 0x6LL, 0x5LL, 0x4LL, 0x3LL, 1517 0x1306fe000LL, 0x100000000LL, 0xd744fd00LL, 0xb504f300LL, 0x9837f000LL,
1510 0x3LL, 0x2LL, 0x2LL, 0x2LL, 0x1LL, 0x1LL, 0x1LL, 0x1LL, 0x1LL, 0x1LL, 1518 0x80000000LL, 0x6ba27e80LL, 0x5a827980LL, 0x4c1bf800LL, 0x40000000LL,
1511 0x1LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 1519 0x35d13f40LL, 0x2d413cc0LL, 0x260dfc00LL, 0x20000000LL, 0x1ae89fa0LL,
1512 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 1520 0x16a09e60LL, 0x1306fe00LL, 0x10000000LL, 0xd744fd0LL, 0xb504f30LL,
1513 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 1521 0x9837f00LL, 0x8000000LL, 0x6ba27e8LL, 0x5a82798LL, 0x4c1bf80LL,
1514 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 1522 0x4000000LL, 0x35d13f4LL, 0x2d413ccLL, 0x260dfc0LL, 0x2000000LL,
1515 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 1523 0x1ae89faLL, 0x16a09e6LL, 0x1306fe0LL, 0x1000000LL, 0xd744fdLL,
1516 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 0x0LL, 1524 0xb504f3LL, 0x9837f0LL, 0x800000LL, 0x6ba27eLL, 0x5a8279LL,
1517 0x0LL, 0x0LL 1525 0x4c1bf8LL, 0x400000LL, 0x35d13fLL, 0x2d413cLL, 0x260dfcLL,
1526 0x200000LL, 0x1ae89fLL, 0x16a09eLL, 0x1306feLL, 0x100000LL,
1527 0xd744fLL, 0xb504fLL, 0x9837fLL, 0x80000LL, 0x6ba27LL,
1528 0x5a827LL, 0x4c1bfLL, 0x40000LL, 0x35d13LL, 0x2d413LL,
1529 0x260dfLL, 0x20000LL, 0x1ae89LL, 0x16a09LL, 0x1306fLL,
1530 0x10000LL, 0xd744LL, 0xb504LL, 0x9837LL, 0x8000LL,
1531 0x6ba2LL, 0x5a82LL, 0x4c1bLL, 0x4000LL, 0x35d1LL,
1532 0x2d41LL, 0x260dLL, 0x2000LL, 0x1ae8LL, 0x16a0LL,
1533 0x1306LL, 0x1000LL, 0xd74LL, 0xb50LL, 0x983LL,
1534 0x800LL, 0x6baLL, 0x5a8LL, 0x4c1LL, 0x400LL,
1535 0x35dLL, 0x2d4LL, 0x260LL, 0x200LL, 0x1aeLL,
1536 0x16aLL, 0x130LL, 0x100LL, 0xd7LL, 0xb5LL,
1537 0x98LL, 0x80LL, 0x6bLL, 0x5aLL, 0x4cLL,
1538 0x40LL, 0x35LL, 0x2dLL, 0x26LL, 0x20LL,
1539 0x1aLL, 0x16LL, 0x13LL, 0x10LL, 0xdLL,
1540 0xbLL, 0x9LL, 0x8LL, 0x6LL, 0x5LL,
1541 0x4LL, 0x4LL, 0x3LL, 0x2LL, 0x2LL,
1542 0x2LL, 0x1LL, 0x1LL, 0x1LL, 0x1LL,
1543 0x0LL
1518}; 1544};
1519 1545
1520
1521
1522/* table of exp noise values multiplied by 16 in order to reduce rounding error */ 1546/* table of exp noise values multiplied by 16 in order to reduce rounding error */
1523 fixed32 noisetable_exp[] = 1547 fixed32 noisetable_exp[] =
1524{ 1548{
diff --git a/apps/codecs/libwma/wmadec.h b/apps/codecs/libwma/wmadec.h
index a3e4acdc94..8ae49eed0c 100644
--- a/apps/codecs/libwma/wmadec.h
+++ b/apps/codecs/libwma/wmadec.h
@@ -153,8 +153,8 @@ typedef struct WMADecodeContext
153 /* lsp_to_curve tables */ 153 /* lsp_to_curve tables */
154 fixed32 lsp_cos_table[BLOCK_MAX_SIZE]; 154 fixed32 lsp_cos_table[BLOCK_MAX_SIZE];
155 fixed64 lsp_pow_e_table[256]; 155 fixed64 lsp_pow_e_table[256];
156 fixed64 lsp_pow_m_table1[(1 << LSP_POW_BITS)]; 156 fixed32 lsp_pow_m_table1[(1 << LSP_POW_BITS)];
157 fixed64 lsp_pow_m_table2[(1 << LSP_POW_BITS)]; 157 fixed32 lsp_pow_m_table2[(1 << LSP_POW_BITS)];
158 158
159 /* State of current superframe decoding */ 159 /* State of current superframe decoding */
160 int bit_offset; 160 int bit_offset;
diff --git a/apps/codecs/libwma/wmadeci.c b/apps/codecs/libwma/wmadeci.c
index ecde2fd034..552f85183c 100644
--- a/apps/codecs/libwma/wmadeci.c
+++ b/apps/codecs/libwma/wmadeci.c
@@ -286,10 +286,9 @@ int ff_mdct_init(MDCTContext *s, int nbits, int inverse)
286 s->tsin[i] = - fsincos(ip<<16, &(s->tcos[i])); //I can't remember why this works, but it seems to agree for ~24 bits, maybe more! 286 s->tsin[i] = - fsincos(ip<<16, &(s->tcos[i])); //I can't remember why this works, but it seems to agree for ~24 bits, maybe more!
287 s->tcos[i] *=-1; 287 s->tcos[i] *=-1;
288 } 288 }
289 s->fft.nbits = s->nbits - 2; 289 (&s->fft)->nbits = nbits-2;
290 290
291 291 (&s->fft)->inverse = inverse;
292 s->fft.inverse = inverse;
293 292
294 return 0; 293 return 0;
295 294
@@ -733,8 +732,10 @@ int wma_decode_init(WMADecodeContext* s, asf_waveformatex_t *wfx)
733 s->coefs_end[k] = (s->frame_len - ((s->frame_len * 9) / 100)) >> k; 732 s->coefs_end[k] = (s->frame_len - ((s->frame_len * 9) / 100)) >> k;
734 /* high freq computation */ 733 /* high freq computation */
735 734
736 fixed32 tmp = high_freq*2; 735 fixed32 tmp1 = high_freq*2; /* high_freq is a fixed32!*/
737 s->high_band_start[k] = fixtoi32(fixdiv32(tmp, itofix32(s->sample_rate)) *block_len +0x8000); 736 fixed32 tmp2=itofix32(s->sample_rate>>1);
737 s->high_band_start[k] = fixtoi32( fixdiv32(tmp1, tmp2) * (block_len>>1) +0x8000);
738
738 /* 739 /*
739 s->high_band_start[k] = (int)((block_len * 2 * high_freq) / 740 s->high_band_start[k] = (int)((block_len * 2 * high_freq) /
740 s->sample_rate + 0.5);*/ 741 s->sample_rate + 0.5);*/
@@ -935,48 +936,57 @@ int wma_decode_init(WMADecodeContext* s, asf_waveformatex_t *wfx)
935static inline fixed32 pow_m1_4(WMADecodeContext *s, fixed32 x) 936static inline fixed32 pow_m1_4(WMADecodeContext *s, fixed32 x)
936{ 937{
937 union { 938 union {
938 fixed64 f; 939 float f;
939 unsigned int v; 940 unsigned int v;
940 } u, t; 941 } u, t;
941 unsigned int e, m; 942 unsigned int e, m;
942 fixed64 a, b; 943 fixed32 a, b;
943 944
944 u.f = x; 945 u.f = fixtof64(x);
945 e = u.v >> 23; 946 e = u.v >> 23;
946 m = (u.v >> (23 - LSP_POW_BITS)) & ((1 << LSP_POW_BITS) - 1); 947 m = (u.v >> (23 - LSP_POW_BITS)) & ((1 << LSP_POW_BITS) - 1);
947 /* build interpolation scale: 1 <= t < 2. */ 948 /* build interpolation scale: 1 <= t < 2. */
948 t.v = ((u.v << LSP_POW_BITS) & ((1 << 23) - 1)) | (127 << 23); 949 t.v = ((u.v << LSP_POW_BITS) & ((1 << 23) - 1)) | (127 << 23);
949 a = s->lsp_pow_m_table1[m]; 950 a = s->lsp_pow_m_table1[m];
950 b = s->lsp_pow_m_table2[m]; 951 b = s->lsp_pow_m_table2[m];
951 return lsp_pow_e_table[e] * (a + b * t.f); 952
953 /*lsp_pow_e_table contains 32.32 format */
954 /*TODO: Since we're unlikely have value that cover the whole
955 * IEEE754 range, we probably don't need to have all possible exponents*/
956
957 return (lsp_pow_e_table[e] * (a + fixmul32(b, ftofix32(t.f))) >>32);
952} 958}
953 959
954static void wma_lsp_to_curve_init(WMADecodeContext *s, int frame_len) 960static void wma_lsp_to_curve_init(WMADecodeContext *s, int frame_len)
955{ 961{
956 fixed32 wdel, a, b; 962 fixed32 wdel, a, b, temp, temp2;
957 int i, m; 963 int i, m;
958 964
959 wdel = fixdiv32(M_PI_F, itofix32(frame_len)); 965 wdel = fixdiv32(M_PI_F, itofix32(frame_len));
966 temp = fixdiv32(itofix32(1), itofix32(frame_len));
960 for (i=0; i<frame_len; ++i) 967 for (i=0; i<frame_len; ++i)
961 { 968 {
962 s->lsp_cos_table[i] = 0x20000 * fixcos32(wdel * i); //wdel*i between 0 and pi 969 /*TODO: can probably reuse the trig_init values here */
970 fsincos((temp*i)<<15, &temp2);
971 /*get 3 bits headroom + 1 bit from not doubleing the values*/
972 s->lsp_cos_table[i] = temp2>>3;
963 973
964 } 974 }
965
966
967 /* NOTE: these two tables are needed to avoid two operations in 975 /* NOTE: these two tables are needed to avoid two operations in
968 pow_m1_4 */ 976 pow_m1_4 */
969 b = itofix32(1); 977 b = itofix32(1);
970 int ix = 0; 978 int ix = 0;
979
980 /*double check this later*/
971 for(i=(1 << LSP_POW_BITS) - 1;i>=0;i--) 981 for(i=(1 << LSP_POW_BITS) - 1;i>=0;i--)
972 { 982 {
973 m = (1 << LSP_POW_BITS) + i; 983 m = (1 << LSP_POW_BITS) + i;
974 a = m * (0x8000 / (1 << LSP_POW_BITS)); //PJJ 984 a = pow_a_table[ix++]<<4;
975 a = pow_a_table[ix++]; // PJJ : further refinement
976 s->lsp_pow_m_table1[i] = 2 * a - b; 985 s->lsp_pow_m_table1[i] = 2 * a - b;
977 s->lsp_pow_m_table2[i] = b - a; 986 s->lsp_pow_m_table2[i] = b - a;
978 b = a; 987 b = a;
979 } 988 }
989
980} 990}
981 991
982/* NOTE: We use the same code as Vorbis here */ 992/* NOTE: We use the same code as Vorbis here */
@@ -988,27 +998,42 @@ static void wma_lsp_to_curve(WMADecodeContext *s,
988 fixed32 *lsp) 998 fixed32 *lsp)
989{ 999{
990 int i, j; 1000 int i, j;
991 fixed32 p, q, w, v, val_max; 1001 fixed32 p, q, w, v, val_max, temp, temp2;
992 1002
993 val_max = 0; 1003 val_max = 0;
994 for(i=0;i<n;++i) 1004 for(i=0;i<n;++i)
995 { 1005 {
996 p = 0x8000; 1006 /* shift by 2 now to reduce rounding error,
997 q = 0x8000; 1007 * we can renormalize right before pow_m1_4
1008 */
1009
1010 p = 0x8000<<5;
1011 q = 0x8000<<5;
998 w = s->lsp_cos_table[i]; 1012 w = s->lsp_cos_table[i];
1013
999 for (j=1;j<NB_LSP_COEFS;j+=2) 1014 for (j=1;j<NB_LSP_COEFS;j+=2)
1000 { 1015 {
1001 q *= w - lsp[j - 1]; 1016
1002 p *= w - lsp[j]; 1017 /*w is 5.27 format, lsp is in 16.16, temp2 becomes 5.27 format*/
1018 temp2 = ((w - (lsp[j - 1]<<11)));
1019 temp = q;
1020 /*q is 16.16 format, temp2 is 5.27, q becomes 16.16 */
1021 q = fixmul32b(q, temp2 )<<4;
1022 p = fixmul32b(p, (w - (lsp[j]<<11)))<<4;
1003 } 1023 }
1004 p *= p * (0x20000 - w); 1024
1005 q *= q * (0x20000 + w); 1025 /* 2 in 5.27 format is 0x10000000 */
1006 v = p + q; 1026 p = fixmul32(p, fixmul32b(p, (0x10000000 - w)))<<3;
1007 v = pow_m1_4(s, v); // PJJ 1027 q = fixmul32(q, fixmul32b(q, (0x10000000 + w)))<<3;
1028
1029 v = (p + q) >>9; /* p/q end up as 16.16 */
1030 v = pow_m1_4(s, v);
1008 if (v > val_max) 1031 if (v > val_max)
1009 val_max = v; 1032 val_max = v;
1010 out[i] = v; 1033 out[i] = v;
1034
1011 } 1035 }
1036
1012 *val_max_ptr = val_max; 1037 *val_max_ptr = val_max;
1013} 1038}
1014 1039
@@ -1392,13 +1417,11 @@ static int wma_decode_block(WMADecodeContext *s)
1392 coefs1 = s->coefs1[ch]; 1417 coefs1 = s->coefs1[ch];
1393 exponents = s->exponents[ch]; 1418 exponents = s->exponents[ch];
1394 esize = s->exponents_bsize[ch]; 1419 esize = s->exponents_bsize[ch];
1395 mult = fixdiv64(pow_table[total_gain],Fixed32To64(s->max_exponent[ch])); 1420 mult = fixdiv64(pow_table[total_gain+20],Fixed32To64(s->max_exponent[ch]));
1396 // mul = fixtof64(pow_table[total_gain])/(s->block_len/2)/fixtof64(s->max_exponent[ch]);
1397
1398 mult = fixmul64byfixed(mult, mdct_norm); //what the hell? This is actually fixed64*2^16! 1421 mult = fixmul64byfixed(mult, mdct_norm); //what the hell? This is actually fixed64*2^16!
1399 coefs = (*(s->coefs))[ch]; //VLC exponenents are used to get MDCT coef here! 1422 coefs = (*(s->coefs))[ch];
1400 1423
1401 n=0; 1424 n=0;
1402 1425
1403 if (s->use_noise_coding) 1426 if (s->use_noise_coding)
1404 { 1427 {
@@ -1428,8 +1451,9 @@ static int wma_decode_block(WMADecodeContext *s)
1428 e2 = 0; 1451 e2 = 0;
1429 for(i = 0;i < n; ++i) 1452 for(i = 0;i < n; ++i)
1430 { 1453 {
1431 v = exp_ptr[i]>>5; /*v is noramlized later on so its fixed format is irrelevant*/ 1454 /*v is noramlized later on so its fixed format is irrelevant*/
1432 e2 += fixmul32(v, v); 1455 v = exp_ptr[i]>>4;
1456 e2 += fixmul32(v, v)>>3;
1433 } 1457 }
1434 exp_power[j] = e2/n; /*n is an int...*/ 1458 exp_power[j] = e2/n; /*n is an int...*/
1435 last_high_band = j; 1459 last_high_band = j;
@@ -1456,7 +1480,8 @@ static int wma_decode_block(WMADecodeContext *s)
1456 fixed32 tmp = fixdiv32(exp_power[j],exp_power[last_high_band]); 1480 fixed32 tmp = fixdiv32(exp_power[j],exp_power[last_high_band]);
1457 mult1 = (fixed64)fixsqrt32(tmp); 1481 mult1 = (fixed64)fixsqrt32(tmp);
1458 /* XXX: use a table */ 1482 /* XXX: use a table */
1459 mult1 = mult1 * pow_table[s->high_band_values[ch][j]] >> PRECISION; 1483 /*mult1 is 48.16, pow_table is 48.16*/
1484 mult1 = mult1 * pow_table[s->high_band_values[ch][j]+20] >> PRECISION;
1460 1485
1461 /*this step has a fairly high degree of error for some reason*/ 1486 /*this step has a fairly high degree of error for some reason*/
1462 mult1 = fixdiv64(mult1,fixmul32(s->max_exponent[ch],s->noise_mult)); 1487 mult1 = fixdiv64(mult1,fixmul32(s->max_exponent[ch],s->noise_mult));
@@ -1481,9 +1506,9 @@ static int wma_decode_block(WMADecodeContext *s)
1481 1506
1482 /*don't forget to renormalize the noise*/ 1507 /*don't forget to renormalize the noise*/
1483 temp1 = (((int32_t)*coefs1++)<<16) + (noise>>4); 1508 temp1 = (((int32_t)*coefs1++)<<16) + (noise>>4);
1484 temp2 = fixmul32(*exponents, mult>>16); 1509 temp2 = fixmul32(*exponents, mult>>17);
1485 *coefs++ = fixmul32(temp1, temp2)>>1; 1510 *coefs++ = fixmul32(temp1, temp2);
1486 ++exponents; 1511 ++exponents;
1487 } 1512 }
1488 } 1513 }
1489 } 1514 }
@@ -1637,10 +1662,8 @@ static int wma_decode_frame(WMADecodeContext *s, int16_t *samples)
1637 1662
1638 for (i=0;i<n;++i) 1663 for (i=0;i<n;++i)
1639 { 1664 {
1640 a = fixtoi32(*iptr++)<<1; //ugly but good enough for now
1641
1642
1643 1665
1666 a = fixtoi32(*iptr++)<<1; //ugly but good enough for now
1644 1667
1645 1668
1646 if (a > 32767) 1669 if (a > 32767)