shithub: pt2-clone

Download patch

ref: 47752ff46560097dfeeb04cafe91b350312074ee
parent: 5d1114967dc5dee345cc8823e3e53df2ff15a1c5
author: Olav Sørensen <olav.sorensen@live.no>
date: Sat Jun 27 08:35:13 EDT 2020

Rescale values in musicTimeTab64 table to prevent division

--- a/src/pt2_audio.c
+++ b/src/pt2_audio.c
@@ -1267,7 +1267,7 @@
 	calculateFilterCoeffs();
 
 	audio.dSamplesPerTick = audio.bpmTab[125-32]; // BPM 125
-	audio.dTickSampleCounter = 0;
+	audio.dTickSampleCounter = 0.0;
 
 	calcAudioLatencyVars(audio.audioBufferSize, audio.outputRate);
 
--- a/src/pt2_tables.c
+++ b/src/pt2_tables.c
@@ -157,49 +157,49 @@
 };
 
 /*
-** const double dBpmMs = 1000.0 / (bpm / 2.5);
-** x = (uint64_t)round((UINT32_MAX + 1.0) * dBpmMs);
+** const double dBpmMs1024 = 1024.0 / (bpm / 2.5); // milliseconds (scaled from 1000 to 1024)
+** x = (uint64_t)floor((UINT32_MAX + 1.0) * dBpmMs1024);
 */
 const uint64_t musicTimeTab64[256-32] =
 {
-	0x4e20000000,0x4bc1f07c1f,0x4987878788,0x476db6db6e,0x4571c71c72,0x43914c1bad,
-	0x41ca1af287,0x401a41a41a,0x3e80000000,0x3cf9c18f9c,0x3b86186186,0x3a23b88ee2,
-	0x38d1745d17,0x378e38e38e,0x36590b2164,0x3531057262,0x3415555555,0x330539782a,
-	0x3200000000,0x3105050505,0x3013b13b14,0x2f2b78c135,0x2e4bda12f7,0x2d745d1746,
-	0x2ca4924925,0x2bdc11f704,0x2b1a7b9612,0x2a5f75270d,0x29aaaaaaab,0x28fbcda3ac,
-	0x285294a529,0x27aebaebaf,0x2710000000,0x2676276276,0x25e0f83e10,0x25503d2263,
-	0x24c3c3c3c4,0x243b5cc0ed,0x23b6db6db7,0x233615a241,0x22b8e38e39,0x223f1f8fc8,
-	0x21c8a60dd6,0x2155555555,0x20e50d7943,0x2077b03532,0x200d20d20d,0x1fa5440cf6,
-	0x1f40000000,0x1edd3c0ca4,0x1e7ce0c7ce,0x1e1ed7e753,0x1dc30c30c3,0x1d69696969,
-	0x1d11dc4771,0x1cbc52640c,0x1c68ba2e8c,0x1c1702e05c,0x1bc71c71c7,0x1b78f78f79,
-	0x1b2c8590b2,0x1ae1b86e1c,0x1a9882b931,0x1a50d79436,0x1a0aaaaaab,0x19c5f02a3a,
-	0x19829cbc15,0x1940a57eb5,0x1900000000,0x18c0a237c3,0x1882828283,0x1845979c95,
-	0x1809d89d8a,0x17cf3cf3cf,0x1795bc609b,0x175d4ef40a,0x1725ed097b,0x16ef8f441c,
-	0x16ba2e8ba3,0x1685c4093a,0x1652492492,0x161fb78122,0x15ee08fb82,0x15bd37a6f5,
-	0x158d3dcb09,0x155e15e15e,0x152fba9387,0x150226b902,0x14d5555555,0x14a9419637,
-	0x147de6d1d6,0x1453408534,0x14294a5295,0x1400000000,0x13d75d75d7,0x13af5ebd7b,
-	0x1388000000,0x13613d84f6,0x133b13b13b,0x13157f05dd,0x12f07c1f08,0x12cc07b302,
-	0x12a81e9132,0x1284bda12f,0x1261e1e1e2,0x123f8868a4,0x121dae6077,0x11fc510935,
-	0x11db6db6db,0x11bb01d0cb,0x119b0ad120,0x117b864407,0x115c71c71c,0x113dcb08d4,
-	0x111f8fc7e4,0x1101bdd2b9,0x10e45306eb,0x10c74d50c0,0x10aaaaaaab,0x108e691cd2,
-	0x107286bca2,0x105701ac57,0x103bd81a99,0x1021084211,0x1006906907,0x0fec6ee105,
-	0x0fd2a2067b,0x0fb9284067,0x0fa0000000,0x0f8727c066,0x0f6e9e0652,0x0f56615fce,
-	0x0f3e7063e7,0x0f26c9b26d,0x0f0f6bf3aa,0x0ef855d825,0x0ee1861862,0x0ecafb74a4,
-	0x0eb4b4b4b5,0x0e9eb0a7ac,0x0e88ee23b9,0x0e736c05eb,0x0e5e293206,0x0e49249249,
-	0x0e345d1746,0x0e1fd1b7af,0x0e0b81702e,0x0df76b4338,0x0de38e38e4,0x0dcfe95ec3,
-	0x0dbc7bc7bc,0x0da9448be4,0x0d9642c859,0x0d83759f23,0x0d70dc370e,0x0d5e75bb8d,
-	0x0d4c415c99,0x0d3a3e4e90,0x0d286bca1b,0x0d16c90c10,0x0d05555555,0x0cf40feac7,
-	0x0ce2f8151d,0x0cd20d20d2,0x0cc14e5e0a,0x0cb0bb207d,0x0ca052bf5b,0x0c9014953a,
-	0x0c80000000,0x0c701460cc,0x0c60511be2,0x0c50b59897,0x0c41414141,0x0c31f3831f,
-	0x0c22cbce4b,0x0c13c995a4,0x0c04ec4ec5,0x0bf63371ea,0x0be79e79e8,0x0bd92ce418,
-	0x0bcade304d,0x0bbcb1e0c0,0x0baea77a05,0x0ba0be82fa,0x0b92f684be,0x0b854f0a9e,
-	0x0b77c7a20e,0x0b6a5fda98,0x0b5d1745d1,0x0b4fed7750,0x0b42e2049d,0x0b35f4852a,
-	0x0b29249249,0x0b1c71c71c,0x0b0fdbc091,0x0b03621d52,0x0af7047dc1,0x0aeac283ea,
-	0x0ade9bd37a,0x0ad29011bb,0x0ac69ee584,0x0abac7f736,0x0aaf0af0af,0x0aa3677d47,
-	0x0a97dd49c3,0x0a8c6c0452,0x0a81135c81,0x0a75d30337,0x0a6aaaaaab,0x0a5f9a0660,
-	0x0a54a0cb1c,0x0a49beaee1,0x0a3ef368eb,0x0a343eb1a2,0x0a29a0429a,0x0a1f17d68b,
-	0x0a14a5294a,0x0a0a47f7c6,0x0a00000000,0x09f5cd0105,0x09ebaebaec,0x09e1a4eecc,
-	0x09d7af5ebd,0x09cdcdcdce
+	0x0000000000,0x4D9364D936,0x4B4B4B4B4B,0x4924924924,0x471C71C71C,0x45306EB3E4,
+	0x435E50D794,0x41A41A41A4,0x4000000000,0x3E7063E706,0x3CF3CF3CF3,0x3B88EE23B8,
+	0x3A2E8BA2E8,0x38E38E38E3,0x37A6F4DE9B,0x3677D46CEF,0x3555555555,0x343EB1A1F5,
+	0x3333333333,0x3232323232,0x313B13B13B,0x304D4873EC,0x2F684BDA12,0x2E8BA2E8BA,
+	0x2DB6DB6DB6,0x2CE98B3A62,0x2C234F72C2,0x2B63CBEEA4,0x2AAAAAAAAA,0x29F79B4758,
+	0x294A5294A5,0x28A28A28A2,0x2800000000,0x2762762762,0x26C9B26C9B,0x26357E16EC,
+	0x25A5A5A5A5,0x2519F89467,0x2492492492,0x240E6C2B44,0x238E38E38E,0x231188C462,
+	0x22983759F2,0x2222222222,0x21AF286BCA,0x213F2B3884,0x20D20D20D2,0x2067B23A54,
+	0x2000000000,0x1F9ADD3C0C,0x1F3831F383,0x1ED7E75346,0x1E79E79E79,0x1E1E1E1E1E,
+	0x1DC47711DC,0x1D6CDFA1D6,0x1D1745D174,0x1CC398730E,0x1C71C71C71,0x1C21C21C21,
+	0x1BD37A6F4D,0x1B86E1B86E,0x1B3BEA3677,0x1AF286BCA1,0x1AAAAAAAAA,0x1A6449E59B,
+	0x1A1F58D0FA,0x19DBCC4867,0x1999999999,0x1958B67EBB,0x1919191919,0x18DAB7EC1D,
+	0x189D89D89D,0x1861861861,0x1826A439F6,0x17ECDC1CB5,0x17B425ED09,0x177C7A20E1,
+	0x1745D1745D,0x171024E6A1,0x16DB6DB6DB,0x16A7A5616A,0x1674C59D31,0x1642C8590B,
+	0x1611A7B961,0x15E15E15E1,0x15B1E5F752,0x15833A1583,0x1555555555,0x152832C6E0,
+	0x14FBCDA3AC,0x14D0214D02,0x14A5294A52,0x147AE147AE,0x1451451451,0x142850A142,
+	0x1400000000,0x13D84F613D,0x13B13B13B1,0x138ABF82EE,0x1364D9364D,0x133F84CFE1,
+	0x131ABF0B76,0x12F684BDA1,0x12D2D2D2D2,0x12AFA64E7B,0x128CFC4A33,0x126AD1F4F3,
+	0x1249249249,0x1227F179A5,0x12073615A2,0x11E6EFE35B,0x11C71C71C7,0x11A7B9611A,
+	0x1188C46231,0x116A3B35FC,0x114C1BACF9,0x112E63A6A8,0x1111111111,0x10F421E843,
+	0x10D79435E5,0x10BB6610BB,0x109F959C42,0x1084210842,0x1069069069,0x104E447BEC,
+	0x1033D91D2A,0x1019C2D14E,0x1000000000,0x0FE68F1B07,0x0FCD6E9E06,0x0FB49D0E22,
+	0x0F9C18F9C1,0x0F83E0F83E,0x0F6BF3A9A3,0x0F544FB66B,0x0F3CF3CF3C,0x0F25DEACAF,
+	0x0F0F0F0F0F,0x0EF883BE20,0x0EE23B88EE,0x0ECC35458C,0x0EB66FD0EB,0x0EA0EA0EA0,
+	0x0E8BA2E8BA,0x0E76994F8C,0x0E61CC3987,0x0E4D3AA30A,0x0E38E38E38,0x0E24C602D4,
+	0x0E10E10E10,0x0DFD33C272,0x0DE9BD37A6,0x0DD67C8A60,0x0DC370DC37,0x0DB0995382,
+	0x0D9DF51B3B,0x0D8B8362E0,0x0D79435E50,0x0D673445B2,0x0D55555555,0x0D43A5CD98,
+	0x0D3224F2CD,0x0D20D20D20,0x0D0FAC687D,0x0CFEB35477,0x0CEDE62433,0x0CDD442E4F,
+	0x0CCCCCCCCC,0x0CBC7F5CF9,0x0CAC5B3F5D,0x0C9C5FD7A5,0x0C8C8C8C8C,0x0C7CE0C7CE,
+	0x0C6D5BF60E,0x0C5DFD86CD,0x0C4EC4EC4E,0x0C3FB19B8F,0x0C30C30C30,0x0C21F8B86A,
+	0x0C13521CFB,0x0C04CEB916,0x0BF66E0E5A,0x0BE82FA0BE,0x0BDA12F684,0x0BCC17982F,
+	0x0BBE3D1070,0x0BB082EC20,0x0BA2E8BA2E,0x0B956E0B95,0x0B88127350,0x0B7AD58650,
+	0x0B6DB6DB6D,0x0B60B60B60,0x0B53D2B0B5,0x0B470C67C0,0x0B3A62CE98,0x0B2DD58507,
+	0x0B21642C85,0x0B150E682C,0x0B08D3DCB0,0x0AFCB43057,0x0AF0AF0AF0,0x0AE4C415C9,
+	0x0AD8F2FBA9,0x0ACD3B68C6,0x0AC19D0AC1,0x0AB617909A,0x0AAAAAAAAA,0x0A9F560A9F,
+	0x0A94196370,0x0A88F46959,0x0A7DE6D1D6,0x0A72F05397,0x0A6810A681,0x0A5D4783A0,
+	0x0A5294A529,0x0A47F7C66C,0x0A3D70A3D7,0x0A32FEFAE6,0x0A28A28A28,0x0A1E5B1133,
+	0x0A142850A1,0x0A0A0A0A0A
 };
 
 // button tables taken from the ptplay project + modified
--- a/src/pt2_visuals.c
+++ b/src/pt2_visuals.c
@@ -601,15 +601,13 @@
 
 	// playback timer
 
-	const uint32_t milliseconds = editor.musicTime64 >> 32;
-	uint32_t seconds = milliseconds / 1000;
+	const uint32_t ms1024 = editor.musicTime64 >> 32; // milliseconds (scaled from 1000 to 1024)
 
-	seconds -= ((seconds / 3600) * 3600); // remove hours
-	if (seconds <= 5999) // below 99 minutes 59 seconds
+	uint32_t seconds = ms1024 >> 10;
+	if (seconds <= 5999) // below 100 minutes (99:59 is max for the UI)
 	{
-		uint32_t MI_TimeM = seconds / 60;
-		seconds -= MI_TimeM * 60; // remove minutes
-		uint32_t MI_TimeS = seconds;
+		const uint32_t MI_TimeM = seconds / 60;
+		const uint32_t MI_TimeS = seconds - (MI_TimeM * 60);
 
 		// xx:xx
 		printTwoDecimalsBg(272, 102, MI_TimeM, video.palette[PAL_GENTXT], video.palette[PAL_GENBKG]);