Skip to content

Commit

Permalink
Remove multtable, replace with logical equivalent
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
earlephilhower committed Oct 4, 2017
1 parent 760786f commit 3865157
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 45 deletions.
37 changes: 0 additions & 37 deletions src/RenderTabs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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] =
{
Expand Down
18 changes: 10 additions & 8 deletions src/render.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3865157

Please sign in to comment.