From 9db9134383ebebbec54f437754a0b9cc56de74db Mon Sep 17 00:00:00 2001 From: Adam Gashlin Date: Tue, 24 Jan 2023 18:59:22 -0800 Subject: [PATCH] Compute CDB2 cubes with S.15 fixed point --- src/coding/sdx2_decoder.c | 62 +++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/src/coding/sdx2_decoder.c b/src/coding/sdx2_decoder.c index ff6022c3..ff662cdc 100644 --- a/src/coding/sdx2_decoder.c +++ b/src/coding/sdx2_decoder.c @@ -33,32 +33,44 @@ static int16_t squares[256] = { 31250, 31752, 32258 }; -/* for (i=-128;i<128;i++) { double j = (i/2)/2.0; cubes[i+128] = floor(j*j*j); } */ +/* +for (uint16_t i = 0; i < 0x100; i += 1) { + int16_t v = i; + v -= 0x80; + v *= 0x100; + int32_t a = v; + a *= a; + a >>= 15; + a *= v; + a >>= 15; + cubes[i] = a; +} +*/ static int16_t cubes[256] = { - -32768,-31256,-31256,-29791,-29791,-28373,-28373,-27000,-27000,-25672,-25672, - -24389,-24389,-23149,-23149,-21952,-21952,-20797,-20797,-19683,-19683,-18610, - -18610,-17576,-17576,-16581,-16581,-15625,-15625,-14706,-14706,-13824,-13824, - -12978,-12978,-12167,-12167,-11391,-11391,-10648,-10648, -9938, -9938, -9261, - -9261, -8615, -8615, -8000, -8000, -7415, -7415, -6859, -6859, -6332, -6332, - -5832, -5832, -5359, -5359, -4913, -4913, -4492, -4492, -4096, -4096, -3724, - -3724, -3375, -3375, -3049, -3049, -2744, -2744, -2460, -2460, -2197, -2197, - -1953, -1953, -1728, -1728, -1521, -1521, -1331, -1331, -1158, -1158, -1000, - -1000, -857, -857, -729, -729, -614, -614, -512, -512, -422, -422, - -343, -343, -275, -275, -216, -216, -166, -166, -125, -125, -91, - -91, -64, -64, -43, -43, -27, -27, -16, -16, -8, -8, - -3, -3, -1, -1, 0, 0, 0, 0, 0, 0, 0, - 1, 1, 3, 3, 8, 8, 16, 16, 27, 27, 43, - 43, 64, 64, 91, 91, 125, 125, 166, 166, 216, 216, - 275, 275, 343, 343, 422, 422, 512, 512, 614, 614, 729, - 729, 857, 857, 1000, 1000, 1158, 1158, 1331, 1331, 1521, 1521, - 1728, 1728, 1953, 1953, 2197, 2197, 2460, 2460, 2744, 2744, 3049, - 3049, 3375, 3375, 3724, 3724, 4096, 4096, 4492, 4492, 4913, 4913, - 5359, 5359, 5832, 5832, 6332, 6332, 6859, 6859, 7415, 7415, 8000, - 8000, 8615, 8615, 9261, 9261, 9938, 9938, 10648, 10648, 11391, 11391, - 12167, 12167, 12978, 12978, 13824, 13824, 14706, 14706, 15625, 15625, 16581, - 16581, 17576, 17576, 18610, 18610, 19683, 19683, 20797, 20797, 21952, 21952, - 23149, 23149, 24389, 24389, 25672, 25672, 27000, 27000, 28373, 28373, 29791, - 29791, 31256, 31256 + -32768,-32006,-31256,-30518,-29791,-29077,-28373,-27681,-27000,-26331,-25673, + -25026,-24389,-23764,-23150,-22546,-21952,-21370,-20797,-20235,-19683,-19142, + -18610,-18088,-17576,-17074,-16582,-16099,-15625,-15161,-14707,-14261,-13824, + -13397,-12978,-12569,-12167,-11775,-11391,-11016,-10648,-10290, -9939, -9596, + -9261, -8935, -8616, -8304, -8000, -7704, -7415, -7134, -6859, -6592, -6332, + -6079, -5832, -5593, -5360, -5133, -4913, -4700, -4493, -4292, -4096, -3907, + -3724, -3547, -3375, -3210, -3049, -2894, -2744, -2600, -2461, -2327, -2197, + -2073, -1954, -1839, -1728, -1623, -1521, -1424, -1331, -1243, -1158, -1077, + -1000, -927, -858, -792, -729, -670, -615, -562, -512, -466, -422, + -382, -343, -308, -275, -245, -216, -191, -167, -145, -125, -108, + -92, -77, -64, -53, -43, -35, -27, -21, -16, -12, -8, + -6, -4, -2, -1, -1, -1, -1, 0, 0, 0, 0, + 1, 1, 3, 5, 8, 11, 15, 20, 27, 34, 42, + 52, 64, 76, 91, 107, 125, 144, 166, 190, 216, 244, + 274, 307, 343, 381, 421, 465, 512, 561, 614, 669, 729, + 791, 857, 926, 1000, 1076, 1157, 1242, 1331, 1423, 1520, 1622, + 1728, 1838, 1953, 2072, 2197, 2326, 2460, 2599, 2744, 2893, 3048, + 3209, 3375, 3546, 3723, 3906, 4096, 4291, 4492, 4699, 4913, 5132, + 5359, 5592, 5832, 6078, 6331, 6591, 6859, 7133, 7414, 7703, 8000, + 8303, 8615, 8934, 9261, 9595, 9938, 10289, 10648, 11015, 11390, 11774, + 12167, 12568, 12977, 13396, 13824, 14260, 14706, 15160, 15625, 16098, 16581, + 17073, 17576, 18087, 18609, 19141, 19683, 20234, 20796, 21369, 21952, 22545, + 23149, 23763, 24389, 25025, 25672, 26330, 27000, 27680, 28372, 29076, 29791, + 30517, 31255, 32005 }; static void decode_delta_exact(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int16_t * table) {