Skip to content

Commit ff92746

Browse files
author
Kurt Dekker
committed
UnitySAM: fix my failure to do 8-bit math and wrap when appropriate! Phoneme processing appears to work now, modifying the input in place!
1 parent eae031d commit ff92746

File tree

3 files changed

+66
-29
lines changed

3 files changed

+66
-29
lines changed

UnitySAM/Assets/SAMCSourceCode/src/Modernity.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public static string TextToPhonemes(string s)
2323

2424
bool success = TextToPhonemes(ia);
2525

26+
Debug.Log( "success = " + success);
27+
2628
var what = ia;
2729

2830
what = inputtemp;

UnitySAM/Assets/SAMCSourceCode/src/SamDebug.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ static void printf(string s)
77
Debug.Log("Print:'" + s + "'");
88
}
99

10+
static void printf( int i)
11+
{
12+
int[] ia = new int[1] { i};
13+
printf(ia);
14+
}
15+
1016
static void printf(int[] ia)
1117
{
1218
byte[] bytes = new byte[ia.Length];
@@ -27,9 +33,25 @@ static void printf(int[] ia)
2733
printf( s);
2834
}
2935

30-
static void PrintRule(int i)
36+
static void PrintRule(int offset)
3137
{
32-
Debug.Log("PrintRule:" + i.ToString());
38+
int i = 1;
39+
int A = 0;
40+
string s = "Applying rule: ";
41+
do
42+
{
43+
A = GetRuleByte(offset, i);
44+
if ((A&127) == '=')
45+
{
46+
s = s + " -> ";
47+
}
48+
else
49+
{
50+
s = s + System.String.Format( "{0}", (char) (A & 127));
51+
}
52+
i++;
53+
} while ((A&128)==0);
54+
printf(s);
3355
}
3456

3557
static void PrintPhonemes( int[] phonemeindex, int[] phonemeLength, int[] stress)

UnitySAM/Assets/SAMCSourceCode/src/reciter_c.cs

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static void Code37055(int mem59)
1919
static void Code37066(int mem58)
2020
{
2121
X = mem58;
22-
X++;
22+
INC8( ref X);
2323
A = inputtemp[X];
2424
Y = A;
2525
A = tab36376[Y];
@@ -38,6 +38,18 @@ static int GetRuleByte(int mem62, int Y)
3838
return rules[address + Y];
3939
}
4040

41+
static void INC8( ref int xxx)
42+
{
43+
xxx++;
44+
xxx &= 255;
45+
}
46+
47+
static void DEC8( ref int xxx)
48+
{
49+
xxx--;
50+
xxx &= 255;
51+
}
52+
4153
static bool TextToPhonemes( int[] input) // Code36484
4254
{
4355
//unsigned char *tab39445 = &mem[39445]; //input and output
@@ -48,6 +60,7 @@ static bool TextToPhonemes( int[] input) // Code36484
4860
int mem59 = 0;
4961
int mem60 = 0;
5062
int mem61 = 0;
63+
5164
int mem62 = 0; // memory position of current rule
5265

5366
int mem64 = 0; // position of '=' or current character
@@ -71,8 +84,8 @@ static bool TextToPhonemes( int[] input) // Code36484
7184
else if (A >= 96) A = A & 79;
7285

7386
inputtemp[X] = A;
74-
X++;
75-
Y++;
87+
INC8(ref X);
88+
INC8(ref Y);
7689
} while (Y != 255);
7790

7891
printf( inputtemp);
@@ -90,7 +103,7 @@ static bool TextToPhonemes( int[] input) // Code36484
90103
pos36554:
91104
while (true)
92105
{
93-
mem61++;
106+
INC8( ref mem61);
94107
X = mem61;
95108

96109
if (X >= inputtemp.Length) break;
@@ -99,7 +112,7 @@ static bool TextToPhonemes( int[] input) // Code36484
99112
mem64 = A;
100113
if (A == '[')
101114
{
102-
mem56++;
115+
INC8(ref mem56);
103116
X = mem56;
104117
A = 155;
105118
input[X] = 155;
@@ -110,11 +123,11 @@ static bool TextToPhonemes( int[] input) // Code36484
110123

111124
//pos36579:
112125
if (A != '.') break;
113-
X++;
126+
INC8(ref X);
114127
Y = inputtemp[X];
115128
A = tab36376[Y] & 1;
116129
if (A != 0) break;
117-
mem56++;
130+
INC8(ref mem56);
118131
X = mem56;
119132
A = '.';
120133
input[X] = '.';
@@ -140,7 +153,7 @@ static bool TextToPhonemes( int[] input) // Code36484
140153
if (X >= inputtemp.Length) return true;
141154

142155
inputtemp[X] = ' ';
143-
mem56++;
156+
INC8(ref mem56);
144157
X = mem56;
145158
if (X > 120) goto pos36654;
146159
input[X] = A;
@@ -185,26 +198,26 @@ static bool TextToPhonemes( int[] input) // Code36484
185198
Y = 0;
186199
do
187200
{
188-
mem62 += 1;
201+
mem62++;
189202
A = GetRuleByte(mem62, Y);
190203
} while ((A & 128) == 0);
191-
Y++;
204+
INC8( ref Y);
192205

193206
//pos36720:
194207
// find '('
195208
while (true)
196209
{
197210
A = GetRuleByte(mem62, Y);
198211
if (A == '(') break;
199-
Y++;
212+
INC8( ref Y);
200213
}
201214
mem66 = Y;
202215

203216
//pos36732:
204217
// find ')'
205218
do
206219
{
207-
Y++;
220+
INC8( ref Y);
208221
A = GetRuleByte(mem62, Y);
209222
} while (A != ')');
210223
mem65 = Y;
@@ -213,7 +226,7 @@ static bool TextToPhonemes( int[] input) // Code36484
213226
// find '='
214227
do
215228
{
216-
Y++;
229+
INC8( ref Y);
217230
A = GetRuleByte(mem62, Y);
218231
A = A & 127;
219232
} while (A != '=');
@@ -224,16 +237,16 @@ static bool TextToPhonemes( int[] input) // Code36484
224237

225238
// compare the string within the bracket
226239
Y = mem66;
227-
Y++;
240+
INC8( ref Y);
228241
//pos36759:
229242
while (true)
230243
{
231244
mem57 = inputtemp[X];
232245
A = GetRuleByte(mem62, Y);
233246
if (A != mem57) goto pos36700;
234-
Y++;
247+
INC8( ref Y);
235248
if (Y == mem65) break;
236-
X++;
249+
INC8( ref X);
237250
mem60 = X;
238251
}
239252

@@ -365,12 +378,12 @@ static bool TextToPhonemes( int[] input) // Code36484
365378
X = mem58 + 1;
366379
A = inputtemp[X];
367380
if (A != 'E') goto pos37157;
368-
X++;
381+
INC8( ref X);
369382
Y = inputtemp[X];
370383
X--;
371384
A = tab36376[Y] & 128;
372385
if (A == 0) goto pos37108;
373-
X++;
386+
INC8( ref X);
374387
A = inputtemp[X];
375388
if (A != 'R') goto pos37113;
376389
pos37108:
@@ -380,27 +393,27 @@ static bool TextToPhonemes( int[] input) // Code36484
380393
pos37113:
381394
if ((A == 83) || (A == 68)) goto pos37108; // 'S' 'D'
382395
if (A != 76) goto pos37135; // 'L'
383-
X++;
396+
INC8( ref X);
384397
A = inputtemp[X];
385398
if (A != 89) goto pos36700;
386399
goto pos37108;
387400

388401
pos37135:
389402
if (A != 70) goto pos36700;
390-
X++;
403+
INC8( ref X);
391404
A = inputtemp[X];
392405
if (A != 85) goto pos36700;
393-
X++;
406+
INC8( ref X);
394407
A = inputtemp[X];
395408
if (A == 76) goto pos37108;
396409
goto pos36700;
397410

398411
pos37157:
399412
if (A != 73) goto pos36700;
400-
X++;
413+
INC8( ref X);
401414
A = inputtemp[X];
402415
if (A != 78) goto pos36700;
403-
X++;
416+
INC8( ref X);
404417
A = inputtemp[X];
405418
if (A == 71) goto pos37108;
406419
//pos37177:
@@ -487,7 +500,7 @@ static bool TextToPhonemes( int[] input) // Code36484
487500
if (A != 0) goto pos37330;
488501
A = inputtemp[X];
489502
if (A != 72) goto pos36700;
490-
X++;
503+
INC8( ref X);
491504
A = inputtemp[X];
492505
if ((A == 67) || (A == 83)) goto pos37330;
493506
goto pos36700;
@@ -519,7 +532,7 @@ static bool TextToPhonemes( int[] input) // Code36484
519532

520533
pos37419:
521534
X = mem58;
522-
X++;
535+
INC8( ref X);
523536
A = inputtemp[X];
524537
if ((A == 69) || (A == 73) || (A == 89)) goto pos37414;
525538
goto pos36700;
@@ -547,7 +560,7 @@ static bool TextToPhonemes( int[] input) // Code36484
547560
A = A & 127;
548561
if (A != '=')
549562
{
550-
mem56++;
563+
INC8( ref mem56);
551564
X = mem56;
552565
input[X] = A;
553566
}
@@ -557,7 +570,7 @@ static bool TextToPhonemes( int[] input) // Code36484
557570
if ((mem57 & 128) == 0) goto pos37485; //???
558571
goto pos36554;
559572
pos37485:
560-
Y++;
573+
INC8( ref Y);
561574
goto pos37461;
562575
}
563576
}

0 commit comments

Comments
 (0)