HDCD Decoder: Adjust gain stepping algorithm
This is a fixed point implementation identical to Microsoft's original algorithm. Or at least I assume it's Microsoft's. It was actually adapted from hdcd_decode.exe, which was adapted from somewhere else. It's entirely in fixed point math now, so it's fairly deterministic. Signed-off-by: Christopher Snowhill <kode54@gmail.com>CQTexperiment
parent
6d9f1be7ea
commit
3069a81d85
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 2010-2017, Christopher Snowhill,
|
||||
Copyright (C) 2010-2022, Christopher Snowhill,
|
||||
All rights reserved.
|
||||
Optimizations by Gumboot
|
||||
Additional work by Burt P.
|
||||
|
@ -676,139 +676,36 @@ static const uint8_t readaheadtab[] = {
|
|||
0x20
|
||||
};
|
||||
|
||||
//values between 0 and 1 multiplied by 2^23 to avoid floating point numbers.
|
||||
//values between 0 and -7.5 dB multiplied by 2^23 to avoid floating point numbers.
|
||||
static const int32_t gaintab[] = {
|
||||
0x800000, 0x7ff144, 0x7fe28a, 0x7fd3d2, 0x7fc51b, 0x7fb666, 0x7fa7b3, 0x7f9901, 0x7f8a52, 0x7f7ba3, 0x7f6cf7, 0x7f5e4c, 0x7f4fa3, 0x7f40fc, 0x7f3256,
|
||||
0x7f23b2, 0x7f1510, 0x7f066f, 0x7ef7d0, 0x7ee933, 0x7eda97, 0x7ecbfd, 0x7ebd65, 0x7eaece, 0x7ea039, 0x7e91a6, 0x7e8315, 0x7e7485, 0x7e65f6, 0x7e576a,
|
||||
0x7e48df, 0x7e3a56, 0x7e2bce, 0x7e1d49, 0x7e0ec5, 0x7e0042, 0x7df1c1, 0x7de342, 0x7dd4c5, 0x7dc649, 0x7db7cf, 0x7da956, 0x7d9adf, 0x7d8c6a, 0x7d7df7,
|
||||
0x7d6f85, 0x7d6115, 0x7d52a6, 0x7d443a, 0x7d35ce, 0x7d2765, 0x7d18fd, 0x7d0a97, 0x7cfc32, 0x7cedd0, 0x7cdf6e, 0x7cd10f, 0x7cc2b1, 0x7cb455, 0x7ca5fa,
|
||||
0x7c97a1, 0x7c894a, 0x7c7af4, 0x7c6ca0, 0x7c5e4e, 0x7c4ffd, 0x7c41ae, 0x7c3361, 0x7c2515, 0x7c16cb, 0x7c0882, 0x7bfa3b, 0x7bebf6, 0x7bddb3, 0x7bcf71,
|
||||
0x7bc131, 0x7bb2f2, 0x7ba4b5, 0x7b967a, 0x7b8840, 0x7b7a08, 0x7b6bd2, 0x7b5d9d, 0x7b4f6a, 0x7b4138, 0x7b3308, 0x7b24da, 0x7b16ad, 0x7b0882, 0x7afa59,
|
||||
0x7aec31, 0x7ade0b, 0x7acfe7, 0x7ac1c4, 0x7ab3a3, 0x7aa583, 0x7a9765, 0x7a8949, 0x7a7b2e, 0x7a6d15, 0x7a5efd, 0x7a50e8, 0x7a42d3, 0x7a34c1, 0x7a26b0,
|
||||
0x7a18a0, 0x7a0a93, 0x79fc87, 0x79ee7c, 0x79e073, 0x79d26c, 0x79c466, 0x79b662, 0x79a860, 0x799a5f, 0x798c60, 0x797e62, 0x797066, 0x79626c, 0x795473,
|
||||
0x79467c, 0x793886, 0x792a92, 0x791ca0, 0x790eaf, 0x7900c0, 0x78f2d3, 0x78e4e7, 0x78d6fc, 0x78c914, 0x78bb2d, 0x78ad47, 0x789f63, 0x789181, 0x7883a0,
|
||||
0x7875c1, 0x7867e3, 0x785a07, 0x784c2d, 0x783e54, 0x78307d, 0x7822a8, 0x7814d4, 0x780701, 0x77f931, 0x77eb61, 0x77dd94, 0x77cfc8, 0x77c1fd, 0x77b434,
|
||||
0x77a66d, 0x7798a8, 0x778ae3, 0x777d21, 0x776f60, 0x7761a1, 0x7753e3, 0x774627, 0x77386c, 0x772ab3, 0x771cfc, 0x770f46, 0x770192, 0x76f3df, 0x76e62e,
|
||||
0x76d87e, 0x76cad0, 0x76bd24, 0x76af79, 0x76a1d0, 0x769428, 0x768682, 0x7678de, 0x766b3b, 0x765d99, 0x764ffa, 0x76425b, 0x7634bf, 0x762723, 0x76198a,
|
||||
0x760bf2, 0x75fe5c, 0x75f0c7, 0x75e333, 0x75d5a2, 0x75c811, 0x75ba83, 0x75acf6, 0x759f6a, 0x7591e0, 0x758458, 0x7576d1, 0x75694c, 0x755bc8, 0x754e46,
|
||||
0x7540c6, 0x753347, 0x7525c9, 0x75184d, 0x750ad3, 0x74fd5a, 0x74efe3, 0x74e26d, 0x74d4f9, 0x74c786, 0x74ba15, 0x74aca6, 0x749f38, 0x7491cb, 0x748460,
|
||||
0x7476f7, 0x74698f, 0x745c29, 0x744ec4, 0x744161, 0x7433ff, 0x74269f, 0x741941, 0x740be4, 0x73fe88, 0x73f12e, 0x73e3d6, 0x73d67f, 0x73c92a, 0x73bbd6,
|
||||
0x73ae84, 0x73a133, 0x7393e4, 0x738696, 0x73794a, 0x736bff, 0x735eb6, 0x73516f, 0x734429, 0x7336e4, 0x7329a1, 0x731c60, 0x730f20, 0x7301e1, 0x72f4a5,
|
||||
0x72e769, 0x72da2f, 0x72ccf7, 0x72bfc0, 0x72b28b, 0x72a557, 0x729825, 0x728af4, 0x727dc5, 0x727098, 0x72636c, 0x725641, 0x724918, 0x723bf0, 0x722eca,
|
||||
0x7221a6, 0x721482, 0x720761, 0x71fa41, 0x71ed22, 0x71e005, 0x71d2ea, 0x71c5d0, 0x71b8b7, 0x71aba0, 0x719e8b, 0x719177, 0x718465, 0x717754, 0x716a44,
|
||||
0x715d36, 0x71502a, 0x71431f, 0x713615, 0x71290e, 0x711c07, 0x710f02, 0x7101ff, 0x70f4fd, 0x70e7fc, 0x70dafd, 0x70ce00, 0x70c104, 0x70b40a, 0x70a711,
|
||||
0x709a19, 0x708d23, 0x70802f, 0x70733c, 0x70664a, 0x70595a, 0x704c6c, 0x703f7f, 0x703293, 0x7025a9, 0x7018c0, 0x700bd9, 0x6ffef4, 0x6ff20f, 0x6fe52d,
|
||||
0x6fd84c, 0x6fcb6c, 0x6fbe8e, 0x6fb1b1, 0x6fa4d6, 0x6f97fc, 0x6f8b24, 0x6f7e4d, 0x6f7178, 0x6f64a4, 0x6f57d2, 0x6f4b01, 0x6f3e31, 0x6f3163, 0x6f2497,
|
||||
0x6f17cc, 0x6f0b02, 0x6efe3a, 0x6ef174, 0x6ee4af, 0x6ed7eb, 0x6ecb29, 0x6ebe68, 0x6eb1a9, 0x6ea4eb, 0x6e982f, 0x6e8b74, 0x6e7ebb, 0x6e7203, 0x6e654c,
|
||||
0x6e5897, 0x6e4be4, 0x6e3f32, 0x6e3281, 0x6e25d2, 0x6e1924, 0x6e0c78, 0x6dffcd, 0x6df324, 0x6de67c, 0x6dd9d6, 0x6dcd31, 0x6dc08e, 0x6db3ec, 0x6da74b,
|
||||
0x6d9aac, 0x6d8e0e, 0x6d8172, 0x6d74d7, 0x6d683e, 0x6d5ba6, 0x6d4f10, 0x6d427b, 0x6d35e7, 0x6d2955, 0x6d1cc5, 0x6d1036, 0x6d03a8, 0x6cf71c, 0x6cea91,
|
||||
0x6cde07, 0x6cd17f, 0x6cc4f9, 0x6cb874, 0x6cabf0, 0x6c9f6e, 0x6c92ed, 0x6c866e, 0x6c79f0, 0x6c6d74, 0x6c60f9, 0x6c547f, 0x6c4807, 0x6c3b91, 0x6c2f1b,
|
||||
0x6c22a8, 0x6c1635, 0x6c09c4, 0x6bfd55, 0x6bf0e7, 0x6be47a, 0x6bd80f, 0x6bcba5, 0x6bbf3d, 0x6bb2d6, 0x6ba670, 0x6b9a0c, 0x6b8daa, 0x6b8148, 0x6b74e9,
|
||||
0x6b688a, 0x6b5c2d, 0x6b4fd2, 0x6b4378, 0x6b371f, 0x6b2ac8, 0x6b1e72, 0x6b121d, 0x6b05ca, 0x6af979, 0x6aed29, 0x6ae0da, 0x6ad48d, 0x6ac841, 0x6abbf6,
|
||||
0x6aafad, 0x6aa365, 0x6a971f, 0x6a8ada, 0x6a7e97, 0x6a7255, 0x6a6614, 0x6a59d5, 0x6a4d97, 0x6a415b, 0x6a3520, 0x6a28e6, 0x6a1cae, 0x6a1078, 0x6a0442,
|
||||
0x69f80e, 0x69ebdc, 0x69dfab, 0x69d37b, 0x69c74d, 0x69bb20, 0x69aef4, 0x69a2ca, 0x6996a1, 0x698a7a, 0x697e54, 0x697230, 0x69660c, 0x6959eb, 0x694dca,
|
||||
0x6941ab, 0x69358e, 0x692972, 0x691d57, 0x69113e, 0x690526, 0x68f90f, 0x68ecfa, 0x68e0e6, 0x68d4d4, 0x68c8c3, 0x68bcb3, 0x68b0a5, 0x68a498, 0x68988d,
|
||||
0x688c83, 0x68807a, 0x687473, 0x68686d, 0x685c68, 0x685065, 0x684463, 0x683863, 0x682c64, 0x682066, 0x68146a, 0x68086f, 0x67fc76, 0x67f07d, 0x67e487,
|
||||
0x67d891, 0x67cc9d, 0x67c0ab, 0x67b4ba, 0x67a8ca, 0x679cdb, 0x6790ee, 0x678502, 0x677918, 0x676d2f, 0x676147, 0x675561, 0x67497c, 0x673d99, 0x6731b7,
|
||||
0x6725d6, 0x6719f7, 0x670e19, 0x67023c, 0x66f661, 0x66ea87, 0x66deae, 0x66d2d7, 0x66c701, 0x66bb2d, 0x66af59, 0x66a388, 0x6697b7, 0x668be8, 0x66801a,
|
||||
0x66744e, 0x666883, 0x665cba, 0x6650f1, 0x66452a, 0x663965, 0x662da1, 0x6621de, 0x66161c, 0x660a5c, 0x65fe9e, 0x65f2e0, 0x65e724, 0x65db69, 0x65cfb0,
|
||||
0x65c3f8, 0x65b841, 0x65ac8c, 0x65a0d8, 0x659525, 0x658974, 0x657dc4, 0x657216, 0x656668, 0x655abc, 0x654f12, 0x654369, 0x6537c1, 0x652c1a, 0x652075,
|
||||
0x6514d1, 0x65092f, 0x64fd8d, 0x64f1ee, 0x64e64f, 0x64dab2, 0x64cf16, 0x64c37c, 0x64b7e3, 0x64ac4b, 0x64a0b4, 0x64951f, 0x64898b, 0x647df9, 0x647268,
|
||||
0x6466d8, 0x645b49, 0x644fbc, 0x644430, 0x6438a6, 0x642d1d, 0x642195, 0x64160e, 0x640a89, 0x63ff05, 0x63f383, 0x63e802, 0x63dc82, 0x63d103, 0x63c586,
|
||||
0x63ba0a, 0x63ae8f, 0x63a316, 0x63979e, 0x638c28, 0x6380b2, 0x63753e, 0x6369cc, 0x635e5a, 0x6352ea, 0x63477b, 0x633c0e, 0x6330a2, 0x632537, 0x6319ce,
|
||||
0x630e66, 0x6302ff, 0x62f799, 0x62ec35, 0x62e0d2, 0x62d571, 0x62ca10, 0x62beb1, 0x62b354, 0x62a7f7, 0x629c9c, 0x629142, 0x6285ea, 0x627a93, 0x626f3d,
|
||||
0x6263e9, 0x625895, 0x624d43, 0x6241f3, 0x6236a4, 0x622b56, 0x622009, 0x6214bd, 0x620973, 0x61fe2b, 0x61f2e3, 0x61e79d, 0x61dc58, 0x61d114, 0x61c5d2,
|
||||
0x61ba91, 0x61af51, 0x61a413, 0x6198d6, 0x618d9a, 0x61825f, 0x617726, 0x616bee, 0x6160b7, 0x615582, 0x614a4e, 0x613f1b, 0x6133ea, 0x6128b9, 0x611d8a,
|
||||
0x61125d, 0x610730, 0x60fc05, 0x60f0dc, 0x60e5b3, 0x60da8c, 0x60cf66, 0x60c441, 0x60b91e, 0x60adfc, 0x60a2db, 0x6097bc, 0x608c9d, 0x608180, 0x607665,
|
||||
0x606b4a, 0x606031, 0x605519, 0x604a03, 0x603eed, 0x6033d9, 0x6028c7, 0x601db5, 0x6012a5, 0x600796, 0x5ffc88, 0x5ff17c, 0x5fe671, 0x5fdb67, 0x5fd05e,
|
||||
0x5fc557, 0x5fba51, 0x5faf4c, 0x5fa449, 0x5f9947, 0x5f8e46, 0x5f8346, 0x5f7848, 0x5f6d4a, 0x5f624e, 0x5f5754, 0x5f4c5a, 0x5f4162, 0x5f366c, 0x5f2b76,
|
||||
0x5f2082, 0x5f158f, 0x5f0a9d, 0x5effac, 0x5ef4bd, 0x5ee9cf, 0x5edee2, 0x5ed3f7, 0x5ec90c, 0x5ebe23, 0x5eb33c, 0x5ea855, 0x5e9d70, 0x5e928c, 0x5e87a9,
|
||||
0x5e7cc8, 0x5e71e8, 0x5e6709, 0x5e5c2b, 0x5e514f, 0x5e4673, 0x5e3b99, 0x5e30c1, 0x5e25e9, 0x5e1b13, 0x5e103e, 0x5e056a, 0x5dfa98, 0x5defc7, 0x5de4f7,
|
||||
0x5dda28, 0x5dcf5a, 0x5dc48e, 0x5db9c3, 0x5daef9, 0x5da431, 0x5d996a, 0x5d8ea4, 0x5d83df, 0x5d791b, 0x5d6e59, 0x5d6398, 0x5d58d8, 0x5d4e19, 0x5d435c,
|
||||
0x5d38a0, 0x5d2de5, 0x5d232b, 0x5d1873, 0x5d0dbc, 0x5d0306, 0x5cf851, 0x5ced9d, 0x5ce2eb, 0x5cd83a, 0x5ccd8a, 0x5cc2dc, 0x5cb82e, 0x5cad82, 0x5ca2d7,
|
||||
0x5c982e, 0x5c8d85, 0x5c82de, 0x5c7838, 0x5c6d93, 0x5c62f0, 0x5c584e, 0x5c4dad, 0x5c430d, 0x5c386e, 0x5c2dd1, 0x5c2334, 0x5c1899, 0x5c0e00, 0x5c0367,
|
||||
0x5bf8d0, 0x5bee3a, 0x5be3a5, 0x5bd911, 0x5bce7f, 0x5bc3ee, 0x5bb95e, 0x5baecf, 0x5ba441, 0x5b99b5, 0x5b8f2a, 0x5b84a0, 0x5b7a17, 0x5b6f90, 0x5b6509,
|
||||
0x5b5a84, 0x5b5000, 0x5b457e, 0x5b3afc, 0x5b307c, 0x5b25fd, 0x5b1b7f, 0x5b1103, 0x5b0687, 0x5afc0d, 0x5af194, 0x5ae71c, 0x5adca6, 0x5ad230, 0x5ac7bc,
|
||||
0x5abd49, 0x5ab2d7, 0x5aa867, 0x5a9df7, 0x5a9389, 0x5a891c, 0x5a7eb1, 0x5a7446, 0x5a69dd, 0x5a5f74, 0x5a550d, 0x5a4aa8, 0x5a4043, 0x5a35e0, 0x5a2b7e,
|
||||
0x5a211d, 0x5a16bd, 0x5a0c5e, 0x5a0201, 0x59f7a5, 0x59ed4a, 0x59e2f0, 0x59d897, 0x59ce40, 0x59c3e9, 0x59b994, 0x59af40, 0x59a4ee, 0x599a9c, 0x59904c,
|
||||
0x5985fd, 0x597baf, 0x597162, 0x596717, 0x595ccc, 0x595283, 0x59483b, 0x593df4, 0x5933ae, 0x59296a, 0x591f27, 0x5914e5, 0x590aa4, 0x590064, 0x58f625,
|
||||
0x58ebe8, 0x58e1ac, 0x58d771, 0x58cd37, 0x58c2fe, 0x58b8c7, 0x58ae90, 0x58a45b, 0x589a27, 0x588ff5, 0x5885c3, 0x587b93, 0x587163, 0x586735, 0x585d08,
|
||||
0x5852dc, 0x5848b2, 0x583e88, 0x583460, 0x582a39, 0x582013, 0x5815ee, 0x580bcb, 0x5801a9, 0x57f787, 0x57ed67, 0x57e348, 0x57d92b, 0x57cf0e, 0x57c4f3,
|
||||
0x57bad8, 0x57b0bf, 0x57a6a7, 0x579c91, 0x57927b, 0x578866, 0x577e53, 0x577441, 0x576a30, 0x576020, 0x575612, 0x574c04, 0x5741f8, 0x5737ed, 0x572de3,
|
||||
0x5723da, 0x5719d2, 0x570fcc, 0x5705c6, 0x56fbc2, 0x56f1bf, 0x56e7bd, 0x56ddbc, 0x56d3bc, 0x56c9be, 0x56bfc1, 0x56b5c4, 0x56abc9, 0x56a1cf, 0x5697d7,
|
||||
0x568ddf, 0x5683e9, 0x5679f3, 0x566fff, 0x56660c, 0x565c1a, 0x56522a, 0x56483a, 0x563e4c, 0x56345e, 0x562a72, 0x562087, 0x56169d, 0x560cb5, 0x5602cd,
|
||||
0x55f8e7, 0x55ef01, 0x55e51d, 0x55db3a, 0x55d158, 0x55c777, 0x55bd98, 0x55b3b9, 0x55a9dc, 0x55a000, 0x559625, 0x558c4b, 0x558272, 0x55789a, 0x556ec4,
|
||||
0x5564ee, 0x555b1a, 0x555147, 0x554775, 0x553da4, 0x5533d4, 0x552a06, 0x552038, 0x55166c, 0x550ca1, 0x5502d7, 0x54f90e, 0x54ef46, 0x54e57f, 0x54dbba,
|
||||
0x54d1f5, 0x54c832, 0x54be6f, 0x54b4ae, 0x54aaee, 0x54a130, 0x549772, 0x548db5, 0x5483fa, 0x547a3f, 0x547086, 0x5466ce, 0x545d17, 0x545361, 0x5449ac,
|
||||
0x543ff9, 0x543646, 0x542c95, 0x5422e4, 0x541935, 0x540f87, 0x5405da, 0x53fc2e, 0x53f283, 0x53e8da, 0x53df31, 0x53d58a, 0x53cbe4, 0x53c23e, 0x53b89a,
|
||||
0x53aef7, 0x53a555, 0x539bb5, 0x539215, 0x538877, 0x537ed9, 0x53753d, 0x536ba2, 0x536208, 0x53586f, 0x534ed7, 0x534540, 0x533baa, 0x533216, 0x532882,
|
||||
0x531ef0, 0x53155e, 0x530bce, 0x53023f, 0x52f8b1, 0x52ef24, 0x52e599, 0x52dc0e, 0x52d284, 0x52c8fc, 0x52bf74, 0x52b5ee, 0x52ac69, 0x52a2e5, 0x529962,
|
||||
0x528fe0, 0x52865f, 0x527cdf, 0x527361, 0x5269e3, 0x526067, 0x5256eb, 0x524d71, 0x5243f8, 0x523a80, 0x523109, 0x522793, 0x521e1e, 0x5214ab, 0x520b38,
|
||||
0x5201c6, 0x51f856, 0x51eee7, 0x51e578, 0x51dc0b, 0x51d29f, 0x51c934, 0x51bfca, 0x51b661, 0x51acf9, 0x51a393, 0x519a2d, 0x5190c9, 0x518765, 0x517e03,
|
||||
0x5174a1, 0x516b41, 0x5161e2, 0x515884, 0x514f27, 0x5145cb, 0x513c70, 0x513317, 0x5129be, 0x512066, 0x511710, 0x510dba, 0x510466, 0x50fb13, 0x50f1c1,
|
||||
0x50e86f, 0x50df1f, 0x50d5d0, 0x50cc82, 0x50c336, 0x50b9ea, 0x50b09f, 0x50a755, 0x509e0d, 0x5094c5, 0x508b7f, 0x50823a, 0x5078f5, 0x506fb2, 0x506670,
|
||||
0x505d2f, 0x5053ef, 0x504ab0, 0x504172, 0x503835, 0x502ef9, 0x5025be, 0x501c85, 0x50134c, 0x500a15, 0x5000de, 0x4ff7a9, 0x4fee74, 0x4fe541, 0x4fdc0f,
|
||||
0x4fd2de, 0x4fc9ae, 0x4fc07e, 0x4fb750, 0x4fae23, 0x4fa4f8, 0x4f9bcd, 0x4f92a3, 0x4f897a, 0x4f8053, 0x4f772c, 0x4f6e06, 0x4f64e2, 0x4f5bbe, 0x4f529c,
|
||||
0x4f497b, 0x4f405a, 0x4f373b, 0x4f2e1d, 0x4f2500, 0x4f1be4, 0x4f12c9, 0x4f09af, 0x4f0096, 0x4ef77e, 0x4eee67, 0x4ee551, 0x4edc3c, 0x4ed328, 0x4eca16,
|
||||
0x4ec104, 0x4eb7f3, 0x4eaee4, 0x4ea5d5, 0x4e9cc8, 0x4e93bc, 0x4e8ab0, 0x4e81a6, 0x4e789c, 0x4e6f94, 0x4e668d, 0x4e5d87, 0x4e5482, 0x4e4b7e, 0x4e427a,
|
||||
0x4e3978, 0x4e3077, 0x4e2777, 0x4e1e79, 0x4e157b, 0x4e0c7e, 0x4e0382, 0x4dfa87, 0x4df18d, 0x4de895, 0x4ddf9d, 0x4dd6a6, 0x4dcdb1, 0x4dc4bc, 0x4dbbc9,
|
||||
0x4db2d6, 0x4da9e5, 0x4da0f4, 0x4d9805, 0x4d8f16, 0x4d8629, 0x4d7d3c, 0x4d7451, 0x4d6b67, 0x4d627e, 0x4d5995, 0x4d50ae, 0x4d47c8, 0x4d3ee3, 0x4d35ff,
|
||||
0x4d2d1b, 0x4d2439, 0x4d1b58, 0x4d1278, 0x4d0999, 0x4d00bb, 0x4cf7de, 0x4cef02, 0x4ce627, 0x4cdd4d, 0x4cd474, 0x4ccb9c, 0x4cc2c5, 0x4cb9f0, 0x4cb11b,
|
||||
0x4ca847, 0x4c9f74, 0x4c96a2, 0x4c8dd1, 0x4c8502, 0x4c7c33, 0x4c7365, 0x4c6a98, 0x4c61cd, 0x4c5902, 0x4c5038, 0x4c4770, 0x4c3ea8, 0x4c35e1, 0x4c2d1c,
|
||||
0x4c2457, 0x4c1b93, 0x4c12d1, 0x4c0a0f, 0x4c014f, 0x4bf88f, 0x4befd0, 0x4be713, 0x4bde56, 0x4bd59b, 0x4bcce0, 0x4bc426, 0x4bbb6e, 0x4bb2b6, 0x4baa00,
|
||||
0x4ba14a, 0x4b9896, 0x4b8fe2, 0x4b8730, 0x4b7e7e, 0x4b75cd, 0x4b6d1e, 0x4b646f, 0x4b5bc2, 0x4b5315, 0x4b4a6a, 0x4b41bf, 0x4b3916, 0x4b306d, 0x4b27c6,
|
||||
0x4b1f1f, 0x4b1679, 0x4b0dd5, 0x4b0531, 0x4afc8f, 0x4af3ed, 0x4aeb4c, 0x4ae2ad, 0x4ada0e, 0x4ad171, 0x4ac8d4, 0x4ac038, 0x4ab79e, 0x4aaf04, 0x4aa66b,
|
||||
0x4a9dd4, 0x4a953d, 0x4a8ca7, 0x4a8413, 0x4a7b7f, 0x4a72ec, 0x4a6a5a, 0x4a61ca, 0x4a593a, 0x4a50ab, 0x4a481d, 0x4a3f91, 0x4a3705, 0x4a2e7a, 0x4a25f0,
|
||||
0x4a1d67, 0x4a14df, 0x4a0c58, 0x4a03d2, 0x49fb4d, 0x49f2c9, 0x49ea46, 0x49e1c4, 0x49d943, 0x49d0c3, 0x49c844, 0x49bfc6, 0x49b749, 0x49aecd, 0x49a652,
|
||||
0x499dd7, 0x49955e, 0x498ce6, 0x49846f, 0x497bf8, 0x497383, 0x496b0f, 0x49629b, 0x495a29, 0x4951b8, 0x494947, 0x4940d8, 0x493869, 0x492ffc, 0x49278f,
|
||||
0x491f23, 0x4916b9, 0x490e4f, 0x4905e6, 0x48fd7f, 0x48f518, 0x48ecb2, 0x48e44d, 0x48dbe9, 0x48d386, 0x48cb25, 0x48c2c4, 0x48ba64, 0x48b205, 0x48a9a6,
|
||||
0x48a149, 0x4898ed, 0x489092, 0x488838, 0x487fdf, 0x487786, 0x486f2f, 0x4866d8, 0x485e83, 0x48562f, 0x484ddb, 0x484589, 0x483d37, 0x4834e6, 0x482c97,
|
||||
0x482448, 0x481bfa, 0x4813ad, 0x480b62, 0x480317, 0x47facd, 0x47f284, 0x47ea3c, 0x47e1f5, 0x47d9ae, 0x47d169, 0x47c925, 0x47c0e2, 0x47b89f, 0x47b05e,
|
||||
0x47a81e, 0x479fde, 0x4797a0, 0x478f62, 0x478725, 0x477eea, 0x4776af, 0x476e75, 0x47663c, 0x475e05, 0x4755ce, 0x474d98, 0x474563, 0x473d2f, 0x4734fb,
|
||||
0x472cc9, 0x472498, 0x471c68, 0x471438, 0x470c0a, 0x4703dc, 0x46fbb0, 0x46f384, 0x46eb59, 0x46e330, 0x46db07, 0x46d2df, 0x46cab8, 0x46c292, 0x46ba6d,
|
||||
0x46b249, 0x46aa26, 0x46a203, 0x4699e2, 0x4691c2, 0x4689a2, 0x468184, 0x467966, 0x46714a, 0x46692e, 0x466113, 0x4658f9, 0x4650e0, 0x4648c9, 0x4640b1,
|
||||
0x46389b, 0x463086, 0x462872, 0x46205f, 0x46184c, 0x46103b, 0x46082a, 0x46001b, 0x45f80c, 0x45effe, 0x45e7f2, 0x45dfe6, 0x45d7db, 0x45cfd1, 0x45c7c8,
|
||||
0x45bfbf, 0x45b7b8, 0x45afb2, 0x45a7ac, 0x459fa8, 0x4597a4, 0x458fa2, 0x4587a0, 0x457f9f, 0x45779f, 0x456fa0, 0x4567a2, 0x455fa5, 0x4557a9, 0x454fae,
|
||||
0x4547b3, 0x453fba, 0x4537c1, 0x452fca, 0x4527d3, 0x451fdd, 0x4517e8, 0x450ff5, 0x450802, 0x45000f, 0x44f81e, 0x44f02e, 0x44e83f, 0x44e050, 0x44d863,
|
||||
0x44d076, 0x44c88a, 0x44c09f, 0x44b8b6, 0x44b0cd, 0x44a8e4, 0x44a0fd, 0x449917, 0x449132, 0x44894d, 0x44816a, 0x447987, 0x4471a5, 0x4469c5, 0x4461e5,
|
||||
0x445a06, 0x445228, 0x444a4b, 0x44426e, 0x443a93, 0x4432b8, 0x442adf, 0x442306, 0x441b2e, 0x441358, 0x440b82, 0x4403ad, 0x43fbd8, 0x43f405, 0x43ec33,
|
||||
0x43e461, 0x43dc91, 0x43d4c1, 0x43ccf3, 0x43c525, 0x43bd58, 0x43b58c, 0x43adc1, 0x43a5f6, 0x439e2d, 0x439664, 0x438e9d, 0x4386d6, 0x437f10, 0x43774c,
|
||||
0x436f88, 0x4367c5, 0x436002, 0x435841, 0x435081, 0x4348c1, 0x434102, 0x433945, 0x433188, 0x4329cc, 0x432211, 0x431a57, 0x43129d, 0x430ae5, 0x43032e,
|
||||
0x42fb77, 0x42f3c1, 0x42ec0c, 0x42e458, 0x42dca5, 0x42d4f3, 0x42cd42, 0x42c591, 0x42bde2, 0x42b633, 0x42ae85, 0x42a6d9, 0x429f2d, 0x429781, 0x428fd7,
|
||||
0x42882e, 0x428085, 0x4278de, 0x427137, 0x426991, 0x4261ec, 0x425a48, 0x4252a5, 0x424b03, 0x424361, 0x423bc1, 0x423421, 0x422c82, 0x4224e5, 0x421d48,
|
||||
0x4215ab, 0x420e10, 0x420676, 0x41fedc, 0x41f744, 0x41efac, 0x41e815, 0x41e07f, 0x41d8ea, 0x41d155, 0x41c9c2, 0x41c22f, 0x41ba9e, 0x41b30d, 0x41ab7d,
|
||||
0x41a3ee, 0x419c60, 0x4194d2, 0x418d46, 0x4185ba, 0x417e30, 0x4176a6, 0x416f1d, 0x416795, 0x41600d, 0x415887, 0x415102, 0x41497d, 0x4141f9, 0x413a76,
|
||||
0x4132f4, 0x412b73, 0x4123f3, 0x411c73, 0x4114f5, 0x410d77, 0x4105fa, 0x40fe7e, 0x40f703, 0x40ef89, 0x40e80f, 0x40e097, 0x40d91f, 0x40d1a8, 0x40ca32,
|
||||
0x40c2bd, 0x40bb49, 0x40b3d5, 0x40ac63, 0x40a4f1, 0x409d80, 0x409610, 0x408ea1, 0x408733, 0x407fc5, 0x407859, 0x4070ed, 0x406982, 0x406218, 0x405aaf,
|
||||
0x405347, 0x404bdf, 0x404479, 0x403d13, 0x4035ae, 0x402e4a, 0x4026e7, 0x401f85, 0x401823, 0x4010c3, 0x400963, 0x400204, 0x3ffaa6, 0x3ff348, 0x3febec,
|
||||
0x3fe490, 0x3fdd36, 0x3fd5dc, 0x3fce83, 0x3fc72b, 0x3fbfd3, 0x3fb87d, 0x3fb127, 0x3fa9d3, 0x3fa27f, 0x3f9b2c, 0x3f93d9, 0x3f8c88, 0x3f8537, 0x3f7de8,
|
||||
0x3f7699, 0x3f6f4b, 0x3f67fd, 0x3f60b1, 0x3f5966, 0x3f521b, 0x3f4ad1, 0x3f4388, 0x3f3c40, 0x3f34f9, 0x3f2db2, 0x3f266c, 0x3f1f28, 0x3f17e4, 0x3f10a1,
|
||||
0x3f095e, 0x3f021d, 0x3efadc, 0x3ef39c, 0x3eec5d, 0x3ee51f, 0x3edde2, 0x3ed6a6, 0x3ecf6a, 0x3ec82f, 0x3ec0f5, 0x3eb9bc, 0x3eb284, 0x3eab4c, 0x3ea416,
|
||||
0x3e9ce0, 0x3e95ab, 0x3e8e77, 0x3e8743, 0x3e8011, 0x3e78df, 0x3e71ae, 0x3e6a7e, 0x3e634f, 0x3e5c21, 0x3e54f3, 0x3e4dc7, 0x3e469b, 0x3e3f70, 0x3e3845,
|
||||
0x3e311c, 0x3e29f3, 0x3e22cc, 0x3e1ba5, 0x3e147f, 0x3e0d59, 0x3e0635, 0x3dff11, 0x3df7ef, 0x3df0cd, 0x3de9ab, 0x3de28b, 0x3ddb6b, 0x3dd44d, 0x3dcd2f,
|
||||
0x3dc612, 0x3dbef6, 0x3db7da, 0x3db0c0, 0x3da9a6, 0x3da28d, 0x3d9b75, 0x3d945d, 0x3d8d47, 0x3d8631, 0x3d7f1c, 0x3d7808, 0x3d70f5, 0x3d69e2, 0x3d62d1,
|
||||
0x3d5bc0, 0x3d54b0, 0x3d4da1, 0x3d4692, 0x3d3f85, 0x3d3878, 0x3d316c, 0x3d2a61, 0x3d2356, 0x3d1c4d, 0x3d1544, 0x3d0e3c, 0x3d0735, 0x3d002f, 0x3cf929,
|
||||
0x3cf225, 0x3ceb21, 0x3ce41e, 0x3cdd1c, 0x3cd61a, 0x3ccf1a, 0x3cc81a, 0x3cc11b, 0x3cba1c, 0x3cb31f, 0x3cac22, 0x3ca527, 0x3c9e2c, 0x3c9731, 0x3c9038,
|
||||
0x3c893f, 0x3c8248, 0x3c7b51, 0x3c745b, 0x3c6d65, 0x3c6671, 0x3c5f7d, 0x3c588a, 0x3c5198, 0x3c4aa6, 0x3c43b6, 0x3c3cc6, 0x3c35d7, 0x3c2ee9, 0x3c27fb,
|
||||
0x3c210f, 0x3c1a23, 0x3c1338, 0x3c0c4e, 0x3c0564, 0x3bfe7c, 0x3bf794, 0x3bf0ad, 0x3be9c7, 0x3be2e1, 0x3bdbfd, 0x3bd519, 0x3bce36, 0x3bc753, 0x3bc072,
|
||||
0x3bb991, 0x3bb2b1, 0x3babd2, 0x3ba4f4, 0x3b9e17, 0x3b973a, 0x3b905e, 0x3b8983, 0x3b82a8, 0x3b7bcf, 0x3b74f6, 0x3b6e1e, 0x3b6747, 0x3b6070, 0x3b599b,
|
||||
0x3b52c6, 0x3b4bf2, 0x3b451f, 0x3b3e4c, 0x3b377b, 0x3b30aa, 0x3b29da, 0x3b230a, 0x3b1c3c, 0x3b156e, 0x3b0ea1, 0x3b07d5, 0x3b0109, 0x3afa3f, 0x3af375,
|
||||
0x3aecac, 0x3ae5e3, 0x3adf1c, 0x3ad855, 0x3ad18f, 0x3acaca, 0x3ac406, 0x3abd42, 0x3ab67f, 0x3aafbd, 0x3aa8fc, 0x3aa23b, 0x3a9b7c, 0x3a94bd, 0x3a8dfe,
|
||||
0x3a8741, 0x3a8084, 0x3a79c9, 0x3a730d, 0x3a6c53, 0x3a659a, 0x3a5ee1, 0x3a5829, 0x3a5172, 0x3a4abb, 0x3a4406, 0x3a3d51, 0x3a369d, 0x3a2fe9, 0x3a2937,
|
||||
0x3a2285, 0x3a1bd4, 0x3a1524, 0x3a0e74, 0x3a07c5, 0x3a0118, 0x39fa6a, 0x39f3be, 0x39ed12, 0x39e667, 0x39dfbd, 0x39d914, 0x39d26b, 0x39cbc4, 0x39c51d,
|
||||
0x39be76, 0x39b7d1, 0x39b12c, 0x39aa88, 0x39a3e5, 0x399d42, 0x3996a1, 0x399000, 0x398960, 0x3982c0, 0x397c22, 0x397584, 0x396ee7, 0x39684a, 0x3961af,
|
||||
0x395b14, 0x39547a, 0x394de0, 0x394748, 0x3940b0, 0x393a19, 0x393383, 0x392ced, 0x392658, 0x391fc4, 0x391931, 0x39129f, 0x390c0d, 0x39057c, 0x38feec,
|
||||
0x38f85c, 0x38f1ce, 0x38eb40, 0x38e4b2, 0x38de26, 0x38d79a, 0x38d10f, 0x38ca85, 0x38c3fc, 0x38bd73, 0x38b6eb, 0x38b064, 0x38a9de, 0x38a358, 0x389cd3,
|
||||
0x38964f, 0x388fcb, 0x388949, 0x3882c7, 0x387c46, 0x3875c5, 0x386f45, 0x3868c7, 0x386248, 0x385bcb, 0x38554e, 0x384ed2, 0x384857, 0x3841dd, 0x383b63,
|
||||
0x3834ea, 0x382e72, 0x3827fa, 0x382184, 0x381b0e, 0x381498, 0x380e24, 0x3807b0, 0x38013d, 0x37facb, 0x37f459, 0x37ede9, 0x37e778, 0x37e109, 0x37da9b,
|
||||
0x37d42d, 0x37cdc0, 0x37c753, 0x37c0e8, 0x37ba7d, 0x37b413, 0x37ada9, 0x37a741, 0x37a0d9, 0x379a72, 0x37940b, 0x378da6, 0x378741, 0x3780dc, 0x377a79,
|
||||
0x377416, 0x376db4, 0x376753, 0x3760f2, 0x375a93, 0x375433, 0x374dd5, 0x374777, 0x37411b, 0x373abe, 0x373463, 0x372e08, 0x3727ae, 0x372155, 0x371afd,
|
||||
0x3714a5, 0x370e4e, 0x3707f8, 0x3701a2, 0x36fb4d, 0x36f4f9, 0x36eea6, 0x36e853, 0x36e201, 0x36dbb0, 0x36d55f, 0x36cf10, 0x36c8c1, 0x36c272, 0x36bc25,
|
||||
0x36b5d8, 0x36af8c, 0x36a940, 0x36a2f6, 0x369cac, 0x369663, 0x36901a, 0x3689d2, 0x36838b, 0x367d45, 0x3676ff, 0x3670ba, 0x366a76, 0x366433, 0x365df0,
|
||||
0x3657ae, 0x36516d, 0x364b2c, 0x3644ec, 0x363ead, 0x36386f, 0x363231, 0x362bf4, 0x3625b8, 0x361f7c, 0x361942, 0x361308, 0x360cce, 0x360695, 0x36005e,
|
||||
0x35fa26
|
||||
0x0800000, 0x078d700, 0x0721500, 0x06bb300,
|
||||
0x065acff, 0x05ffd00, 0x05a9e00, 0x0558bff,
|
||||
0x050c300, 0x04c3f00, 0x047faff, 0x043f400,
|
||||
0x0402700, 0x03c8fff, 0x0392cff, 0x035f9ff
|
||||
};
|
||||
|
||||
//minimum steps from one gain to another - informational only
|
||||
#if 0
|
||||
static const int32_t gain_steps_from_to[16][16] = {
|
||||
{ 0, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, },
|
||||
{ 17, 0, 264, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, },
|
||||
{ 32, 129, 0, 255, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, },
|
||||
{ 48, 128, 128, 0, 256, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, },
|
||||
{ 64, 129, 127, 128, 0, 256, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, },
|
||||
{ 80, 129, 127, 128, 128, 0, 256, 128, 128, 128, 128, 128, 128, 128, 128, 128, },
|
||||
{ 97, 136, 128, 128, 128, 128, 0, 256, 128, 128, 128, 128, 128, 128, 128, 128, },
|
||||
{ 113, 136, 128, 128, 128, 128, 128, 0, 256, 128, 128, 128, 128, 128, 128, 128, },
|
||||
{ 129, 136, 128, 128, 128, 128, 128, 128, 0, 256, 128, 128, 128, 128, 128, 128, },
|
||||
{ 144, 128, 128, 128, 128, 128, 128, 128, 128, 0, 256, 128, 128, 128, 128, 128, },
|
||||
{ 160, 128, 128, 128, 128, 128, 128, 128, 128, 128, 0, 256, 128, 128, 128, 128, },
|
||||
{ 177, 136, 128, 128, 128, 128, 128, 128, 128, 128, 128, 0, 256, 128, 128, 128, },
|
||||
{ 193, 136, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 0, 256, 128, 128, },
|
||||
{ 209, 136, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 0, 256, 128, },
|
||||
{ 225, 136, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 0, 256, },
|
||||
{ 241, 136, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 0, },
|
||||
};
|
||||
#endif
|
||||
|
||||
#if !defined(FFMIN)
|
||||
#define FFMIN(x, y) ((x) <= (y) ? (x) : (y))
|
||||
#endif
|
||||
|
@ -823,7 +720,7 @@ static const int32_t gaintab[] = {
|
|||
|
||||
/* apply gain, 11-bit (3.8) fixed point,
|
||||
* always negative but stored positive. */
|
||||
#define APPLY_GAIN(s,g) do{int64_t s64 = s; s64 *= gaintab[g]; s = (int32_t)(s64 >> 23); }while(0);
|
||||
#define APPLY_GAIN(s,g) do{int64_t s64 = s; s64 *= g; s = (int32_t)(s64 >> 23); }while(0);
|
||||
|
||||
void hdcd_reset(hdcd_state_t *state, unsigned rate)
|
||||
{
|
||||
|
@ -834,7 +731,7 @@ void hdcd_reset(hdcd_state_t *state, unsigned rate)
|
|||
state->arg = 0;
|
||||
state->control = 0;
|
||||
|
||||
state->running_gain = 0;
|
||||
state->running_gain = 0x800000;
|
||||
|
||||
state->sustain = 0;
|
||||
state->sustain_reset = rate * 10;
|
||||
|
@ -928,6 +825,7 @@ static int hdcd_integrate(hdcd_state_t *state, int *flag, const int32_t *samples
|
|||
|
||||
if (state->arg) {
|
||||
switch (hdcd_code(bits, &state->control)) {
|
||||
default: break;
|
||||
case HDCD_CODE_A:
|
||||
*flag = 1;
|
||||
state->code_counterA++;
|
||||
|
@ -986,6 +884,7 @@ static int hdcd_integrate_stereo(hdcd_state_stereo_t *state, int *flag, const in
|
|||
uint32_t wbits = (uint32_t)(state->channel[i].window ^ state->channel[i].window >> 5 ^ state->channel[i].window >> 23);
|
||||
if (state->channel[i].arg) {
|
||||
switch (hdcd_code(wbits, &state->channel[i].control)) {
|
||||
default: break;
|
||||
case HDCD_CODE_A:
|
||||
*flag |= i+1;
|
||||
state->channel[i].code_counterA++;
|
||||
|
@ -1108,7 +1007,6 @@ static int hdcd_scan_stereo(hdcd_state_stereo_t *state, const int32_t *samples,
|
|||
static int hdcd_envelope(int32_t *samples, int count, int stride, int gain, int target_gain, int extend)
|
||||
{
|
||||
int i;
|
||||
int32_t *samples_end = samples + stride * count;
|
||||
|
||||
if (extend) {
|
||||
for (i = 0; i < count; i++) {
|
||||
|
@ -1126,30 +1024,26 @@ static int hdcd_envelope(int32_t *samples, int count, int stride, int gain, int
|
|||
samples[i * stride] <<= 15;
|
||||
}
|
||||
|
||||
if (gain <= target_gain) {
|
||||
int len = FFMIN(count, target_gain - gain);
|
||||
/* attenuate slowly */
|
||||
for (i = 0; i < len; i++) {
|
||||
++gain;
|
||||
if (gain > target_gain) {
|
||||
for (i = 0; i < count && gain > target_gain; i++) {
|
||||
gain = (int32_t)((((int64_t)gain) * 8384836) >> 23);
|
||||
if (gain < target_gain) gain = target_gain;
|
||||
APPLY_GAIN(*samples, gain);
|
||||
samples += stride;
|
||||
}
|
||||
count -= len;
|
||||
} else {
|
||||
int len = FFMIN(count, (gain - target_gain) >> 3);
|
||||
/* amplify quickly */
|
||||
for (i = 0; i < len; i++) {
|
||||
gain -= 8;
|
||||
count -= i;
|
||||
} else if (gain < target_gain) {
|
||||
for (i = 0; i < count && gain < target_gain; i++) {
|
||||
gain = (int32_t)((((int64_t)gain) * 8418843) >> 23);
|
||||
if (gain > target_gain) gain = target_gain;
|
||||
APPLY_GAIN(*samples, gain);
|
||||
samples += stride;
|
||||
}
|
||||
if (gain - 8 < target_gain)
|
||||
gain = target_gain;
|
||||
count -= len;
|
||||
count -= i;
|
||||
}
|
||||
|
||||
/* hold a steady level */
|
||||
if (gain == 0) {
|
||||
if (gain == 0x800000) {
|
||||
if (count > 0)
|
||||
samples += count * stride;
|
||||
} else {
|
||||
|
@ -1166,7 +1060,7 @@ static int hdcd_envelope(int32_t *samples, int count, int stride, int gain, int
|
|||
static void hdcd_control(hdcd_state_t *state, int *peak_extend, int *target_gain)
|
||||
{
|
||||
*peak_extend = (state->control & 16);
|
||||
*target_gain = (state->control & 15) << 7;
|
||||
*target_gain = gaintab[(state->control & 15)];
|
||||
}
|
||||
|
||||
typedef enum {
|
||||
|
@ -1190,7 +1084,6 @@ static hdcd_control_result_t hdcd_control_stereo(hdcd_state_stereo_t *state, int
|
|||
|
||||
void hdcd_process(hdcd_state_t *state, int32_t *samples, int count, int stride)
|
||||
{
|
||||
int32_t *samples_end = samples + count * stride;
|
||||
int gain = state->running_gain;
|
||||
int peak_extend, target_gain;
|
||||
int lead = 0;
|
||||
|
@ -1220,7 +1113,6 @@ void hdcd_process(hdcd_state_t *state, int32_t *samples, int count, int stride)
|
|||
void hdcd_process_stereo(hdcd_state_stereo_t *state, int32_t *samples, int count)
|
||||
{
|
||||
const int stride = 2;
|
||||
int32_t *samples_end = samples + count * stride;
|
||||
int gain[2] = {state->channel[0].running_gain, state->channel[1].running_gain};
|
||||
int peak_extend[2];
|
||||
int lead = 0;
|
||||
|
@ -1305,4 +1197,4 @@ void hdcd_detect_str(hdcd_detection_data_t *detect, char *str) {
|
|||
detect->errors );
|
||||
else
|
||||
strcpy(str, "HDCD detected: no");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ typedef struct {
|
|||
unsigned char arg, control;
|
||||
unsigned sustain, sustain_reset; /* code detect timer */
|
||||
|
||||
int running_gain; /* 11-bit (3.8) fixed point, extended from target_gain */
|
||||
int running_gain; /* 23-bit (1.22) fixed point gain level */
|
||||
|
||||
/* counters */
|
||||
int code_counterA; /* 8-bit format packet */
|
||||
|
|
Loading…
Reference in New Issue