From 38651574d3a7b26237b9004b1936f9bba64ffccf Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Wed, 4 Oct 2017 11:35:22 -0700 Subject: [PATCH] Remove multtable, replace with logical equivalent Multtable stored the result of a 8-bit signed multiply of the upper nibble of A (interpreted as signed) and the amplitude lower nibble (interpreted as unsigned), then divided by two. On the 6510 this made sense, but in modern processors it's way faster and cleaner to simply do the multiply. Replace the render sin/sin/rect mixer with equivalent C code. --- src/RenderTabs.h | 37 ------------------------------------- src/render.c | 18 ++++++++++-------- 2 files changed, 10 insertions(+), 45 deletions(-) diff --git a/src/RenderTabs.h b/src/RenderTabs.h index 4989a86..20a647b 100755 --- a/src/RenderTabs.h +++ b/src/RenderTabs.h @@ -263,43 +263,6 @@ unsigned char rectangle[] = }; -//tab42752 -unsigned char multtable[] = -{ - 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , - 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , - 0x00 , 0x00 , 1 , 1 , 2 , 2 , 3 , 3 , - 4 , 4 , 5 , 5 , 6 , 6 , 7 , 7 , - 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , - 8 , 9 ,0xA ,0xB ,0xC ,0xD ,0xE ,0xF , - 0x00 , 1 , 3 , 4 , 6 , 7 , 9 ,0xA , - 0xC ,0xD ,0xF , 0x10 , 0x12 , 0x13 , 0x15 , 0x16 , - 0x00 , 2 , 4 , 6 , 8 ,0xA ,0xC ,0xE , - 0x10 , 0x12 , 0x14 , 0x16 , 0x18 , 0x1A , 0x1C , 0x1E , - 0x00 , 2 , 5 , 7 ,0xA ,0xC ,0xF , 0x11 , - 0x14 , 0x16 , 0x19 , 0x1B , 0x1E , 0x20 , 0x23 , 0x25 , - 0x00 , 3 , 6 , 9 ,0xC ,0xF , 0x12 , 0x15 , - 0x18 , 0x1B , 0x1E , 0x21 , 0x24 , 0x27 , 0x2A , 0x2D , - 0x00 , 0x03 , 0x07 , 0x0A , 0x0E , 0x11 , 0x15 , 0x18 , - 0x1C , 0x1F , 0x23 , 0x26 , 0x2A , 0x2D , 0x31 , 0x34 , - 0x00 , 0xFC , 0xF8 , 0xF4 , 0xF0 , 0xEC , 0xE8 , 0xE4 , - 0xE0 , 0xDC , 0xD8 , 0xD4 , 0xD0 , 0xCC , 0xC8 , 0xC4 , - 0x00 , 0xFC , 0xF9 , 0xF5 , 0xF2 , 0xEE , 0xEB , 0xE7 , - 0xE4 , 0xE0 , 0xDD , 0xD9 , 0xD6 , 0xD2 , 0xCF , 0xCB , - 0x00 , 0xFD , 0xFA , 0xF7 , 0xF4 , 0xF1 , 0xEE , 0xEB , - 0xE8 , 0xE5 , 0xE2 , 0xDF , 0xDC , 0xD9 , 0xD6 , 0xD3 , - 0x00 , 0xFD , 0xFB , 0xF8 , 0xF6 , 0xF3 , 0xF1 , 0xEE , - 0xEC , 0xE9 , 0xE7 , 0xE4 , 0xE2 , 0xDF , 0xDD , 0xDA , - 0x00 , 0xFE , 0xFC , 0xFA , 0xF8 , 0xF6 , 0xF4 , 0xF2 , - 0xF0 , 0xEE , 0xEC , 0xEA , 0xE8 , 0xE6 , 0xE4 , 0xE2 , - 0x00 , 0xFE , 0xFD , 0xFB , 0xFA , 0xF8 , 0xF7 , 0xF5 , - 0xF4 , 0xF2 , 0xF1 , 0xEF , 0xEE , 0xEC , 0xEB , 0xE9 , - 0x00 , 0xFF , 0xFE , 0xFD , 0xFC , 0xFB , 0xFA , 0xF9 , - 0xF8 , 0xF7 , 0xF6 , 0xF5 , 0xF4 , 0xF3 , 0xF2 , 0xF1 , - 0x00 , 0xFF , 0xFF , 0xFE , 0xFE , 0xFD , 0xFD , 0xFC , - 0xFC , 0xFB , 0xFB , 0xFA , 0xFA , 0xF9 , 0xF9 , 0xF8 -}; - //random data ? unsigned char sampleTable[0x500] = { diff --git a/src/render.c b/src/render.c index 3bce174..f3cd864 100755 --- a/src/render.c +++ b/src/render.c @@ -361,7 +361,6 @@ void Render() unsigned char speedcounter; //mem45 unsigned char mem48; int i; - int carry; if (phonemeIndexOutput[0] == 255) return; //exit if no data A = 0; @@ -806,13 +805,16 @@ if (debug) } else { // simulate the glottal pulse and formants - mem56 = multtable[sinus[phase1] | amplitude1[Y]]; - - carry = 0; - if ((mem56+multtable[sinus[phase2] | amplitude2[Y]] ) > 255) carry = 1; - mem56 += multtable[sinus[phase2] | amplitude2[Y]]; - A = mem56 + multtable[rectangle[phase3] | amplitude3[Y]] + (carry?1:0); - A = ((A + 136) & 255) >> 4; //there must be also a carry + signed char sp1 = (signed char)sinus[phase1]; + signed char sp2 = (signed char)sinus[phase2]; + signed char rp3 = (signed char)rectangle[phase3]; + signed int sin1 = sp1 * ((unsigned char)amplitude1[Y] & 0x0f); + signed int sin2 = sp2 * ((unsigned char)amplitude2[Y] & 0x0f); + signed int rect = rp3 * ((unsigned char)amplitude3[Y] & 0x0f); + signed int mux = sin1 + sin2 + rect; + mux /= 32; + mux += 128; // Go from signed to unsigned amplitude + A = (mux>>4) & 0x0f; //mem[54296] = A; // output the accumulated value