commit - e393e19a4ee86a1caaec027f3fb6679aea903da8
commit + 525b1b68da9b0738d21c4debdf729af00708298c
blob - 06ab40804559c985f1c35028f1a4ac3faffd0ca8
blob + 10bcdd0dd5eee91a503beb76d1ee32ff03cfb4f8
--- src/RenderTabs.h
+++ src/RenderTabs.h
, 0xFE , 1 , 0xFC , 3 , 0xE0 ,0xF , 0 , 0xFC
};
-
-
#endif
-
blob - 88a39fd332276adc526e833a0d2d1a650bbca01d
blob + 2ba757457cf56a77850e21af63bb26fec283a0df
--- src/SamTabs.h
+++ src/SamTabs.h
//tab40672
unsigned char stressInputTable[] =
-{
- '*', '1', '2', '3', '4', '5', '6', '7', '8'
-};
-
-//tab40682
-unsigned char signInputTable1[]={
- ' ', '.', '?', ',', '-', 'I', 'I', 'E',
- 'A', 'A', 'A', 'A', 'U', 'A', 'I', 'E',
- 'U', 'O', 'R', 'L', 'W', 'Y', 'W', 'R',
- 'L', 'W', 'Y', 'M', 'N', 'N', 'D', 'Q',
- 'S', 'S', 'F', 'T', '/', '/', 'Z', 'Z',
- 'V', 'D', 'C', '*', 'J', '*', '*', '*',
- 'E', 'A', 'O', 'A', 'O', 'U', 'B', '*',
- '*', 'D', '*', '*', 'G', '*', '*', 'G',
- '*', '*', 'P', '*', '*', 'T', '*', '*',
- 'K', '*', '*', 'K', '*', '*', 'U', 'U',
- 'U'
-};
-
-//tab40763
-unsigned char signInputTable2[] =
-{
- '*', '*', '*', '*', '*', 'Y', 'H', 'H',
- 'E', 'A', 'H', 'O', 'H', 'X', 'X', 'R',
- 'X', 'H', 'X', 'X', 'X', 'X', 'H', '*',
- '*', '*', '*', '*', '*', 'X', 'X', '*',
- '*', 'H', '*', 'H', 'H', 'X', '*', 'H',
- '*', 'H', 'H', '*', '*', '*', '*', '*',
- 'Y', 'Y', 'Y', 'W', 'W', 'W', '*', '*',
- '*', '*', '*', '*', '*', '*', '*', 'X',
- '*', '*', '*', '*', '*', '*', '*', '*',
- '*', '*', '*', 'X', '*', '*', 'L', 'M',
- 'N'
-};
-
-//loc_9F8C
-enum {
- FLAG_PLOSIVE = 0x0001,
- FLAG_STOPCONS = 0x0002, /* stop consonant */
- FLAG_VOICED = 0x0004,
- /* 0x08 */
- FLAG_DIPTHONG = 0x0010,
- FLAG_DIP_YX = 0x0020, /* dipthong ending with YX */
- FLAG_CONSONANT= 0x0040,
- FLAG_VOWEL = 0x0080,
- FLAG_PUNCT = 0x0100,
- /* 0x200 */
- FLAG_ALVEOLAR = 0x0400,
- FLAG_NASAL = 0x0800,
- FLAG_LIQUIC = 0x1000, /* liquic consonant */
- FLAG_FRICATIVE= 0x2000
-};
-
-unsigned short flags[]={
- 0x8000 , 0xC100 , 0xC100 , 0xC100 , 0xC100 , 0x00A4 , 0x00A4 , 0x00A4 ,
- 0x00A4 , 0x00A4 , 0x00A4 , 0x0084 , 0x0084 , 0x00A4 , 0x00A4 , 0x0084 ,
- 0x0084 , 0x0084 , 0x0084 , 0x0084 , 0x0084 , 0x0084 , 0x0044 , 0x1044 ,
- 0x1044 , 0x1044 , 0x1044 , 0x084C , 0x0C4C , 0x084C , 0x0448 , 0x404C ,
-
- 0x2440 , 0x2040 , 0x2040 , 0x2440 , 0x0040 , 0x0040 , 0x2444 , 0x2044 ,
- 0x2044 , 0x2444 , 0x2048 , 0x2040 , 0x004C , 0x2044 , 0x0000 , 0x0000 ,
- 0x00B4 , 0x00B4 , 0x00B4 , 0x0094 , 0x0094 , 0x0094 , 0x004E , 0x004E ,
-
- 0x004E , 0x044E , 0x044E , 0x044E , 0x004E , 0x004E , 0x004E , 0x004E ,
- 0x004E , 0x004E , 0x004B , 0x004B , 0x004B , 0x044B , 0x044B , 0x044B ,
- 0x004B , 0x004B , 0x004B , 0x004B , 0x004B , 0x004B , 0x0080 , 0x00C1 ,
- 0x00C1
-};
-
-
-//tab45616???
+{
+ '*', '1', '2', '3', '4', '5', '6', '7', '8'
+};
+
+//tab40682
+unsigned char signInputTable1[]={
+ ' ', '.', '?', ',', '-', 'I', 'I', 'E',
+ 'A', 'A', 'A', 'A', 'U', 'A', 'I', 'E',
+ 'U', 'O', 'R', 'L', 'W', 'Y', 'W', 'R',
+ 'L', 'W', 'Y', 'M', 'N', 'N', 'D', 'Q',
+ 'S', 'S', 'F', 'T', '/', '/', 'Z', 'Z',
+ 'V', 'D', 'C', '*', 'J', '*', '*', '*',
+ 'E', 'A', 'O', 'A', 'O', 'U', 'B', '*',
+ '*', 'D', '*', '*', 'G', '*', '*', 'G',
+ '*', '*', 'P', '*', '*', 'T', '*', '*',
+ 'K', '*', '*', 'K', '*', '*', 'U', 'U',
+ 'U'
+};
+
+//tab40763
+unsigned char signInputTable2[] =
+{
+ '*', '*', '*', '*', '*', 'Y', 'H', 'H',
+ 'E', 'A', 'H', 'O', 'H', 'X', 'X', 'R',
+ 'X', 'H', 'X', 'X', 'X', 'X', 'H', '*',
+ '*', '*', '*', '*', '*', 'X', 'X', '*',
+ '*', 'H', '*', 'H', 'H', 'X', '*', 'H',
+ '*', 'H', 'H', '*', '*', '*', '*', '*',
+ 'Y', 'Y', 'Y', 'W', 'W', 'W', '*', '*',
+ '*', '*', '*', '*', '*', '*', '*', 'X',
+ '*', '*', '*', '*', '*', '*', '*', '*',
+ '*', '*', '*', 'X', '*', '*', 'L', 'M',
+ 'N'
+};
+
+//loc_9F8C
+enum {
+ FLAG_PLOSIVE = 0x0001,
+ FLAG_STOPCONS = 0x0002, /* stop consonant */
+ FLAG_VOICED = 0x0004,
+ /* 0x08 */
+ FLAG_DIPTHONG = 0x0010,
+ FLAG_DIP_YX = 0x0020, /* dipthong ending with YX */
+ FLAG_CONSONANT= 0x0040,
+ FLAG_VOWEL = 0x0080,
+ FLAG_PUNCT = 0x0100,
+ /* 0x200 */
+ FLAG_ALVEOLAR = 0x0400,
+ FLAG_NASAL = 0x0800,
+ FLAG_LIQUIC = 0x1000, /* liquic consonant */
+ FLAG_FRICATIVE= 0x2000
+};
+
+unsigned short flags[]={
+ 0x8000 , 0xC100 , 0xC100 , 0xC100 , 0xC100 , 0x00A4 , 0x00A4 , 0x00A4 ,
+ 0x00A4 , 0x00A4 , 0x00A4 , 0x0084 , 0x0084 , 0x00A4 , 0x00A4 , 0x0084 ,
+ 0x0084 , 0x0084 , 0x0084 , 0x0084 , 0x0084 , 0x0084 , 0x0044 , 0x1044 ,
+ 0x1044 , 0x1044 , 0x1044 , 0x084C , 0x0C4C , 0x084C , 0x0448 , 0x404C ,
+
+ 0x2440 , 0x2040 , 0x2040 , 0x2440 , 0x0040 , 0x0040 , 0x2444 , 0x2044 ,
+ 0x2044 , 0x2444 , 0x2048 , 0x2040 , 0x004C , 0x2044 , 0x0000 , 0x0000 ,
+ 0x00B4 , 0x00B4 , 0x00B4 , 0x0094 , 0x0094 , 0x0094 , 0x004E , 0x004E ,
+
+ 0x004E , 0x044E , 0x044E , 0x044E , 0x004E , 0x004E , 0x004E , 0x004E ,
+ 0x004E , 0x004E , 0x004B , 0x004B , 0x004B , 0x044B , 0x044B , 0x044B ,
+ 0x004B , 0x004B , 0x004B , 0x004B , 0x004B , 0x004B , 0x0080 , 0x00C1 ,
+ 0x00C1
+};
+
+
+//tab45616???
unsigned char phonemeStressedLengthTable[] =
-{
- 0x00 , 0x12 , 0x12 , 0x12 , 8 ,0xB , 9 ,0xB ,
- 0xE ,0xF ,0xB , 0x10 ,0xC , 6 , 6 ,0xE ,
- 0xC ,0xE ,0xC ,0xB , 8 , 8 ,0xB ,0xA ,
- 9 , 8 , 8 , 8 , 8 , 8 , 3 , 5 ,
- 2 , 2 , 2 , 2 , 2 , 2 , 6 , 6 ,
- 8 , 6 , 6 , 2 , 9 , 4 , 2 , 1 ,
- 0xE ,0xF ,0xF ,0xF ,0xE ,0xE , 8 , 2 ,
- 2 , 7 , 2 , 1 , 7 , 2 , 2 , 7 ,
- 2 , 2 , 8 , 2 , 2 , 6 , 2 , 2 ,
+{
+ 0x00 , 0x12 , 0x12 , 0x12 , 8 ,0xB , 9 ,0xB ,
+ 0xE ,0xF ,0xB , 0x10 ,0xC , 6 , 6 ,0xE ,
+ 0xC ,0xE ,0xC ,0xB , 8 , 8 ,0xB ,0xA ,
+ 9 , 8 , 8 , 8 , 8 , 8 , 3 , 5 ,
+ 2 , 2 , 2 , 2 , 2 , 2 , 6 , 6 ,
+ 8 , 6 , 6 , 2 , 9 , 4 , 2 , 1 ,
+ 0xE ,0xF ,0xF ,0xF ,0xE ,0xE , 8 , 2 ,
+ 2 , 7 , 2 , 1 , 7 , 2 , 2 , 7 ,
+ 2 , 2 , 8 , 2 , 2 , 6 , 2 , 2 ,
7 , 2 , 4 , 7 , 1 , 4 , 5 , 5
};
-
-//tab45536???
+
+//tab45536???
unsigned char phonemeLengthTable[] =
-{
- 0 , 0x12 , 0x12 , 0x12 , 8 , 8 , 8 , 8 ,
- 8 ,0xB , 6 ,0xC ,0xA , 5 , 5 ,0xB ,
- 0xA ,0xA ,0xA , 9 , 8 , 7 , 9 , 7 ,
- 6 , 8 , 6 , 7 , 7 , 7 , 2 , 5 ,
- 2 , 2 , 2 , 2 , 2 , 2 , 6 , 6 ,
- 7 , 6 , 6 , 2 , 8 , 3 , 1 , 0x1E ,
- 0xD ,0xC ,0xC ,0xC ,0xE , 9 , 6 , 1 ,
- 2 , 5 , 1 , 1 , 6 , 1 , 2 , 6 ,
- 1 , 2 , 8 , 2 , 2 , 4 , 2 , 2 ,
+{
+ 0 , 0x12 , 0x12 , 0x12 , 8 , 8 , 8 , 8 ,
+ 8 ,0xB , 6 ,0xC ,0xA , 5 , 5 ,0xB ,
+ 0xA ,0xA ,0xA , 9 , 8 , 7 , 9 , 7 ,
+ 6 , 8 , 6 , 7 , 7 , 7 , 2 , 5 ,
+ 2 , 2 , 2 , 2 , 2 , 2 , 6 , 6 ,
+ 7 , 6 , 6 , 2 , 8 , 3 , 1 , 0x1E ,
+ 0xD ,0xC ,0xC ,0xC ,0xE , 9 , 6 , 1 ,
+ 2 , 5 , 1 , 1 , 6 , 1 , 2 , 6 ,
+ 1 , 2 , 8 , 2 , 2 , 4 , 2 , 2 ,
6 , 1 , 4 , 6 , 1 , 4 , 0xC7 , 0xFF
};
-
+
/*
Ind | phoneme | flags |
blob - 5940246d8826032a820f333ef2547b21494ccca9
blob + 71d3c7f35061d2981f129ec6acc95bca14151a0d
--- src/createtransitions.c
+++ src/createtransitions.c
extern unsigned char inBlendLength[];
extern unsigned char pitches[];
-extern unsigned char Read(unsigned char p, unsigned char Y);
-extern void Write(unsigned char p, unsigned char Y, unsigned char value);
-
extern unsigned char frequency1[256];
extern unsigned char frequency2[256];
extern unsigned char frequency3[256];
case 172: return amplitude1[Y];
case 173: return amplitude2[Y];
case 174: return amplitude3[Y];
+ default:
+ printf("Error reading from tables");
+ return 0;
}
- printf("Error reading to tables");
- return 0;
}
void Write(unsigned char p, unsigned char Y, unsigned char value)
{
-
switch(p)
{
- case 168: pitches[Y] = value; return;
- case 169: frequency1[Y] = value; return;
- case 170: frequency2[Y] = value; return;
- case 171: frequency3[Y] = value; return;
- case 172: amplitude1[Y] = value; return;
- case 173: amplitude2[Y] = value; return;
- case 174: amplitude3[Y] = value; return;
+ case 168: pitches[Y] = value; return;
+ case 169: frequency1[Y] = value; return;
+ case 170: frequency2[Y] = value; return;
+ case 171: frequency3[Y] = value; return;
+ case 172: amplitude1[Y] = value; return;
+ case 173: amplitude2[Y] = value; return;
+ case 174: amplitude3[Y] = value; return;
+ default:
+ printf("Error writing to tables\n");
+ return;
}
- printf("Error writing to tables\n");
}
// linearly interpolate values
-void interpolate(unsigned char width, unsigned char table, unsigned char frame, unsigned char mem53)
+void interpolate(unsigned char width, unsigned char table, unsigned char frame, char mem53)
{
- unsigned char sign = ((char)(mem53) < 0);
- unsigned char remainder = abs((char)mem53) % width;
- unsigned char div = (unsigned char)((char)(mem53) / width);
+ unsigned char sign = (mem53 < 0);
+ unsigned char remainder = abs(mem53) % width;
+ unsigned char div = mem53 / width;
unsigned char error = 0;
unsigned char pos = width;
}
}
-void interpolate_pitch(unsigned char width, unsigned char pos, unsigned char mem49, unsigned char phase3) {
+void interpolate_pitch(unsigned char pos, unsigned char mem49, unsigned char phase3) {
// unlike the other values, the pitches[] interpolates from
// the middle of the current phoneme to the middle of the
// next phoneme
unsigned char cur_width = phonemeLengthOutput[pos] / 2;
unsigned char next_width = phonemeLengthOutput[pos+1] / 2;
// sum the values
- width = cur_width + next_width;
- unsigned char pitch = pitches[next_width + mem49] - pitches[mem49- cur_width];
+ unsigned char width = cur_width + next_width;
+ char pitch = pitches[next_width + mem49] - pitches[mem49- cur_width];
interpolate(width, 168, phase3, pitch);
}
unsigned char CreateTransitions()
{
- unsigned char phase1;
- unsigned char phase2;
unsigned char mem49 = 0;
unsigned char pos = 0;
while(1) {
+ unsigned char next_rank;
+ unsigned char rank;
+ unsigned char speedcounter;
+ unsigned char phase1;
+ unsigned char phase2;
+ unsigned char phase3;
+ unsigned char transition;
+
unsigned char phoneme = phonemeIndexOutput[pos];
unsigned char next_phoneme = phonemeIndexOutput[pos+1];
if (next_phoneme == 255) break; // 255 == end_token
// get the ranking of each phoneme
- unsigned char next_rank = blendRank[next_phoneme];
- unsigned char rank = blendRank[phoneme];
+ next_rank = blendRank[next_phoneme];
+ rank = blendRank[phoneme];
// compare the rank - lower rank value is stronger
if (rank == next_rank) {
mem49 += phonemeLengthOutput[pos];
- unsigned char speedcounter = mem49 + phase2;
- unsigned char phase3 = mem49 - phase1;
- unsigned char transition = phase1 + phase2; // total transition?
+ speedcounter = mem49 + phase2;
+ phase3 = mem49 - phase1;
+ transition = phase1 + phase2; // total transition?
if (((transition - 2) & 128) == 0) {
-
- interpolate_pitch(transition, pos, mem49, phase3);
- unsigned table = 169;
+ unsigned char table = 169;
+ interpolate_pitch(pos, mem49, phase3);
while (table < 175) {
// tables:
// 168 pitches[]
// 173 amplitude2
// 174 amplitude3
- unsigned char value = Read(table, speedcounter) - Read(table, phase3);
+ char value = Read(table, speedcounter) - Read(table, phase3);
interpolate(transition, table, phase3, value);
table++;
}
// add the length of this phoneme
return mem49 + phonemeLengthOutput[pos];
}
-
-
-
blob - 38941334b2f958ae34c6869aaa22b4d8fffa51c8
blob + e7ff81923c6122c314149c1828dc77c990627fff
--- src/debug.c
+++ src/debug.c
unsigned char *a3,
unsigned char *p)
{
+ int i = 0;
printf("===========================================\n");
printf("Final data for speech output:\n\n");
- int i = 0;
printf(" flags ampl1 freq1 ampl2 freq2 ampl3 freq3 pitch\n");
printf("------------------------------------------------\n");
while(i < 255)
extern unsigned char GetRuleByte(unsigned short mem62, unsigned char Y);
-void PrintRule(int offset)
+void PrintRule(unsigned short offset)
{
- int i = 1;
+ unsigned char i = 1;
unsigned char A = 0;
printf("Applying rule: ");
do
} while ((A&128)==0);
printf("\n");
}
-
blob - 0ac71e692180ba5afc0eb3c5ee699e277fb4c9b1
blob + 8a394edab40b17772ad50eb540112f4a4a113025
--- src/debug.h
+++ src/debug.h
unsigned char *a3,
unsigned char *p);
-void PrintRule(int offset);
+void PrintRule(unsigned short offset);
-#endif
\ No newline at end of file
+#endif
blob - 8ab17f3e45a1d6f057107081e5fef14a1ef51dc7
blob + 9ea9b9ea1127703c23da3794dd07f7f267c71ad5
--- src/main.c
+++ src/main.c
void WriteWav(char* filename, char* buffer, int bufferlength)
{
- FILE *file = fopen(filename, "wb");
+ unsigned int filesize;
+ unsigned int fmtlength = 16;
+ unsigned short int format=1; //PCM
+ unsigned short int channels=1;
+ unsigned int samplerate = 22050;
+ unsigned short int blockalign = 1;
+ unsigned short int bitspersample=8;
+
+ FILE *file;
+ fopen_s(&file, filename, "wb");
if (file == NULL) return;
//RIFF header
fwrite("RIFF", 4, 1,file);
- unsigned int filesize=bufferlength + 12 + 16 + 8 - 8;
+ filesize=bufferlength + 12 + 16 + 8 - 8;
fwrite(&filesize, 4, 1, file);
fwrite("WAVE", 4, 1, file);
//format chunk
fwrite("fmt ", 4, 1, file);
- unsigned int fmtlength = 16;
fwrite(&fmtlength, 4, 1, file);
- unsigned short int format=1; //PCM
fwrite(&format, 2, 1, file);
- unsigned short int channels=1;
fwrite(&channels, 2, 1, file);
- unsigned int samplerate = 22050;
fwrite(&samplerate, 4, 1, file);
fwrite(&samplerate, 4, 1, file); // bytes/second
- unsigned short int blockalign = 1;
fwrite(&blockalign, 2, 1, file);
- unsigned short int bitspersample=8;
fwrite(&bitspersample, 2, 1, file);
//data chunk
int phonetic = 0;
char* wavfilename = NULL;
- char input[256];
+ unsigned char input[256];
- for(i=0; i<256; i++) input[i] = 0;
+ memset(input, 0, 256);
if (argc <= 1)
{
{
if (argv[i][0] != '-')
{
- strcat(input, argv[i]);
- strcat(input, " ");
+ strcat_s((char*)input, 256, argv[i]);
+ strcat_s((char*)input, 256, " ");
} else
{
if (strcmp(&argv[i][1], "wav")==0)
} else
if (strcmp(&argv[i][1], "pitch")==0)
{
- SetPitch(atoi(argv[i+1]));
+ SetPitch((unsigned char)min(atoi(argv[i+1]),255));
i++;
} else
if (strcmp(&argv[i][1], "speed")==0)
{
- SetSpeed(atoi(argv[i+1]));
+ SetSpeed((unsigned char)min(atoi(argv[i+1]),255));
i++;
} else
if (strcmp(&argv[i][1], "mouth")==0)
{
- SetMouth(atoi(argv[i+1]));
+ SetMouth((unsigned char)min(atoi(argv[i+1]),255));
i++;
} else
if (strcmp(&argv[i][1], "throat")==0)
{
- SetThroat(atoi(argv[i+1]));
+ SetThroat((unsigned char)min(atoi(argv[i+1]),255));
i++;
} else
{
} //while
for(i=0; input[i] != 0; i++)
- input[i] = toupper((int)input[i]);
+ input[i] = (unsigned char)toupper((int)input[i]);
if (debug)
{
if (!phonetic)
{
- strcat(input, "[");
+ strcat_s((char*)input, 256, "[");
if (!TextToPhonemes(input)) return 1;
if (debug)
printf("phonetic input: %s\n", input);
- } else strcat(input, "\x9b");
+ } else strcat_s((char*)input, 256, "\x9b");
#ifdef USESDL
if ( SDL_Init(SDL_INIT_AUDIO) < 0 )
PrintUsage();
return 1;
}
-
+
if (wavfilename != NULL)
WriteWav(wavfilename, GetBuffer(), GetBufferLength()/50);
else
OutputSound();
-
return 0;
-
}
-
-
-
-
-
-
blob - 7eb20b72ac4f60332a2630163142626c3af58698
blob + 92bb86d876793fcb7f6b09b61530d13eee7c9d11
--- src/processframes.c
+++ src/processframes.c
-
#include "render.h"
extern unsigned char speed;
//
void ProcessFrames(unsigned char mem48)
{
-
unsigned char speedcounter = 72;
unsigned char phase1 = 0;
unsigned char phase2 = 0;
unsigned char phase3 = 0;
- unsigned char mem66;
+ unsigned char mem66 = 0; //!! was not initialized
unsigned char Y = 0;
Y++; //go to next amplitude
// decrement the frame count
mem48--;
- if(mem48 == 0) return;
+ if(mem48 == 0) return;
speedcounter = speed;
}
phase3 = 0;
}
}
-
blob - 806a0c2c8a2995667105ebd9fc44811951b81d88
blob + 5b72d3b3e276406ec594b7d48fdb163f0901fefb
--- src/reciter.c
+++ src/reciter.c
-#include <stdio.h>
-#include <string.h>
-#include "reciter.h"
-#include "ReciterTabs.h"
-#include "debug.h"
-
-unsigned char A, X, Y;
+#include <stdio.h>
+#include <string.h>
+#include "reciter.h"
+#include "ReciterTabs.h"
+#include "debug.h"
+
+unsigned char A, X;
extern int debug;
-
-static unsigned char inputtemp[256]; // secure copy of input tab36096
-
-/* Retrieve flags for character at mem59-1 */
-unsigned char Code37055(unsigned char npos, unsigned char mask)
-{
- X = npos;
- return tab36376[inputtemp[X]] & mask;
-}
-
-unsigned int match(const char * str) {
- unsigned char ch;
- while ((ch = *str)) {
- A = inputtemp[X++];
- if (A != ch) return 0;
- ++str;
- }
- return 1;
-}
-
-unsigned char GetRuleByte(unsigned short mem62, unsigned char Y) {
- unsigned int address = mem62;
- if (mem62 >= 37541) {
- address -= 37541;
- return rules2[address+Y];
- }
- address -= 32000;
- return rules[address+Y];
-}
-
-int handle_ch2(unsigned char ch, unsigned char mem) {
- X = mem;
- unsigned char tmp = tab36376[inputtemp[mem]];
- if (ch == ' ') {
- if(tmp & 128) return 1;
- } else if (ch == '#') {
- if(!(tmp & 64)) return 1;
- } else if (ch == '.') {
- if(!(tmp & 8)) return 1;
- } else if (ch == '^') {
- if(!(tmp & 32)) return 1;
- } else return -1;
- return 0;
-}
-
-
-int handle_ch(unsigned char A, unsigned char mem) {
- X = mem;
- unsigned char tmp = tab36376[inputtemp[X]];
- if (A == ' ') {
- if ((tmp & 128) != 0) return 1;
- } else if (A == '#') {
- if ((tmp & 64) == 0) return 1;
- } else if (A == '.') {
- if((tmp & 8) == 0) return 1;
- } else if (A == '&') {
- if((tmp & 16) == 0) {
- if (inputtemp[X] != 72) return 1;
- ++X;
- }
- } else if (A == '^') {
- if ((tmp & 32) == 0) return 1;
- } else if (A == '+') {
- X = mem;
- A = inputtemp[X];
- if ((A != 69) && (A != 73) && (A != 89)) return 1;
- } else return -1;
- return 0;
-}
-
-
-int TextToPhonemes(char *input) {
- unsigned char mem56; //output position for phonemes
- unsigned char mem58;
- unsigned char mem60;
- unsigned char mem61;
- unsigned short mem62; // memory position of current rule
-
- unsigned char mem64; // position of '=' or current character
- unsigned char mem65; // position of ')'
- unsigned char mem66; // position of '('
-
- inputtemp[0] = ' ';
-
- // secure copy of input
- // because input will be overwritten by phonemes
- X = 0;
- do {
- A = input[X] & 127;
- if ( A >= 112) A = A & 95;
- else if ( A >= 96) A = A & 79;
- inputtemp[++X] = A;
- } while (X < 255);
- inputtemp[255] = 27;
- mem56 = mem61 = 255;
-
- unsigned char mem57;
-pos36554:
- while (1) {
- while(1) {
- X = ++mem61;
- mem64 = inputtemp[X];
- if (mem64 == '[') {
- X = ++mem56;
- input[X] = 155;
- return 1;
- }
-
- if (mem64 != '.') break;
- X++;
- A = tab36376[inputtemp[X]] & 1;
- if(A != 0) break;
- mem56++;
- X = mem56;
- A = '.';
- input[X] = '.';
- }
- mem57 = tab36376[mem64];
- if((mem57&2) != 0) {
- mem62 = 37541;
- goto pos36700;
- }
-
- if(mem57 != 0) break;
- inputtemp[X] = ' ';
- X = ++mem56;
- if (X > 120) {
- input[X] = 155;
- return 1;
- }
- input[X] = 32;
- }
-
- if(!(mem57 & 128)) return 0;
-
- // go to the right rules for this character.
- X = mem64 - 'A';
- mem62 = tab37489[X] | (tab37515[X]<<8);
-
-pos36700:
- // find next rule
- while ((GetRuleByte(++mem62, 0) & 128) == 0);
- unsigned char Y = 0;
- while(GetRuleByte(mem62, ++Y) != '(');
- mem66 = Y;
- while(GetRuleByte(mem62, ++Y) != ')');
- mem65 = Y;
- while((GetRuleByte(mem62, ++Y) & 127) != '=');
- mem64 = Y;
-
-
- mem60 = X = mem61;
- // compare the string within the bracket
- Y = mem66 + 1;
-
- while(1) {
- if (GetRuleByte(mem62, Y) != inputtemp[X]) goto pos36700;
- if(++Y == mem65) break;
- mem60 = ++X;
- }
-
-
- // the string in the bracket is correct
-
- unsigned char mem59 = mem61;
-
- while(1) {
- while(1) {
- mem66--;
- mem57 = GetRuleByte(mem62, mem66);
- if ((mem57 & 128) != 0) {
- mem58 = mem60;
- goto pos37184;
- }
- X = mem57 & 127;
- if ((tab36376[X] & 128) == 0) break;
- if (inputtemp[mem59-1] != mem57) goto pos36700;
- --mem59;
- }
-
- unsigned char ch = mem57;
-
- int r = handle_ch2(ch, mem59-1);
- if (r == -1) {
- switch (ch) {
- case '&':
- if (!Code37055(mem59-1,16)) {
- if (inputtemp[X] != 'H') r = 1;
- else {
- A = inputtemp[--X];
- if ((A != 'C') && (A != 'S')) r = 1;
- }
- }
- break;
-
- case '@':
- if(!Code37055(mem59-1,4)) {
- A = inputtemp[X];
- if (A != 72) r = 1;
- if ((A != 84) && (A != 67) && (A != 83)) r = 1;
- }
- break;
- case '+':
- X = mem59;
- A = inputtemp[--X];
- if ((A != 'E') && (A != 'I') && (A && 'Y')) r = 1;
- break;
- case ':':
- while (Code37055(mem59-1,32)) --mem59;
- continue;
- default:
- return 0;
- }
- }
-
- if (r == 1) goto pos36700;
-
- mem59 = X;
- }
-
- do {
- X = mem58+1;
- if (inputtemp[X] == 'E') {
- if((tab36376[inputtemp[X+1]] & 128) != 0) {
- A = inputtemp[++X];
- if (A == 'L') {
- if (inputtemp[++X] != 'Y') goto pos36700;
- } else if ((A != 'R') && (A != 'S') && (A != 'D') && !match("FUL")) goto pos36700;
- }
- } else {
- if (!match("ING")) goto pos36700;
- mem58 = X;
- }
-
-pos37184:
- X;
- int r = 0;
- do {
- unsigned char mem57;
- while (1) {
- unsigned char Y = mem65 + 1;
- if(Y == mem64) {
- mem61 = mem60;
-
- if (debug) PrintRule(mem62);
-
- while(1) {
- mem57 = A = GetRuleByte(mem62, Y);
- A = A & 127;
- if (A != '=') input[++mem56] = A;
- if ((mem57 & 128) != 0) goto pos36554;
- Y++;
- }
- }
- mem65 = Y;
- mem57 = GetRuleByte(mem62, Y);
- if((tab36376[mem57] & 128) == 0) break;
- if (inputtemp[mem58+1] != mem57) {
- r = 1;
- break;
- }
- ++mem58;
- }
-
- if (r == 0) {
- A = mem57;
- if (A == '@') {
- if(Code37055(mem58+1, 4) == 0) {
- A = inputtemp[X];
- if ((A != 82) && (A != 84) &&
- (A != 67) && (A != 83)) r = 1;
- } else {
- r = -2;
- }
- } else if (A == ':') {
- while (Code37055(mem58+1, 32)) mem58 = X;
- r = -2;
- } else r = handle_ch(A, mem58+1);
- }
-
- if (r == 1) goto pos36700;
- if (r == -2) {
- r = 0;
- continue;
- }
- if (r == 0) mem58 = X;
- } while (r == 0);
- } while (A == '%');
- return 0;
-}
-
+
+static unsigned char inputtemp[256]; // secure copy of input tab36096
+
+/* Retrieve flags for character at mem59-1 */
+unsigned char Code37055(unsigned char npos, unsigned char mask)
+{
+ X = npos;
+ return tab36376[inputtemp[X]] & mask;
+}
+
+unsigned int match(const char * str) {
+ while (*str) {
+ unsigned char ch = *str;
+ A = inputtemp[X++];
+ if (A != ch) return 0;
+ ++str;
+ }
+ return 1;
+}
+
+unsigned char GetRuleByte(unsigned short mem62, unsigned char Y) {
+ unsigned int address = mem62;
+ if (mem62 >= 37541) {
+ address -= 37541;
+ return rules2[address+Y];
+ }
+ address -= 32000;
+ return rules[address+Y];
+}
+
+int handle_ch2(unsigned char ch, unsigned char mem) {
+ unsigned char tmp;
+ X = mem;
+ tmp = tab36376[inputtemp[mem]];
+ if (ch == ' ') {
+ if(tmp & 128) return 1;
+ } else if (ch == '#') {
+ if(!(tmp & 64)) return 1;
+ } else if (ch == '.') {
+ if(!(tmp & 8)) return 1;
+ } else if (ch == '^') {
+ if(!(tmp & 32)) return 1;
+ } else return -1;
+ return 0;
+}
+
+
+int handle_ch(unsigned char ch, unsigned char mem) {
+ unsigned char tmp;
+ X = mem;
+ tmp = tab36376[inputtemp[X]];
+ if (ch == ' ') {
+ if ((tmp & 128) != 0) return 1;
+ } else if (ch == '#') {
+ if ((tmp & 64) == 0) return 1;
+ } else if (ch == '.') {
+ if((tmp & 8) == 0) return 1;
+ } else if (ch == '&') {
+ if((tmp & 16) == 0) {
+ if (inputtemp[X] != 72) return 1;
+ ++X;
+ }
+ } else if (ch == '^') {
+ if ((tmp & 32) == 0) return 1;
+ } else if (ch == '+') {
+ X = mem;
+ ch = inputtemp[X];
+ if ((ch != 69) && (ch != 73) && (ch != 89)) return 1;
+ } else return -1;
+ return 0;
+}
+
+
+int TextToPhonemes(unsigned char *input) {
+ unsigned char mem56; //output position for phonemes
+ unsigned char mem57;
+ unsigned char mem58;
+ unsigned char mem59;
+ unsigned char mem60;
+ unsigned char mem61;
+ unsigned short mem62; // memory position of current rule
+
+ unsigned char mem64; // position of '=' or current character
+ unsigned char mem65; // position of ')'
+ unsigned char mem66; // position of '('
+
+ unsigned char Y;
+
+ int r;
+
+ inputtemp[0] = ' ';
+
+ // secure copy of input
+ // because input will be overwritten by phonemes
+ X = 0;
+ do {
+ A = input[X] & 127;
+ if ( A >= 112) A = A & 95;
+ else if ( A >= 96) A = A & 79;
+ inputtemp[++X] = A;
+ } while (X < 255);
+ inputtemp[255] = 27;
+ mem56 = mem61 = 255;
+
+pos36554:
+ while (1) {
+ while(1) {
+ X = ++mem61;
+ mem64 = inputtemp[X];
+ if (mem64 == '[') {
+ X = ++mem56;
+ input[X] = 155;
+ return 1;
+ }
+
+ if (mem64 != '.') break;
+ X++;
+ A = tab36376[inputtemp[X]] & 1;
+ if(A != 0) break;
+ mem56++;
+ X = mem56;
+ A = '.';
+ input[X] = '.';
+ }
+ mem57 = tab36376[mem64];
+ if((mem57&2) != 0) {
+ mem62 = 37541;
+ goto pos36700;
+ }
+
+ if(mem57 != 0) break;
+ inputtemp[X] = ' ';
+ X = ++mem56;
+ if (X > 120) {
+ input[X] = 155;
+ return 1;
+ }
+ input[X] = 32;
+ }
+
+ if(!(mem57 & 128)) return 0;
+
+ // go to the right rules for this character.
+ X = mem64 - 'A';
+ mem62 = tab37489[X] | (tab37515[X]<<8);
+
+pos36700:
+ // find next rule
+ while ((GetRuleByte(++mem62, 0) & 128) == 0);
+ Y = 0;
+ while(GetRuleByte(mem62, ++Y) != '(');
+ mem66 = Y;
+ while(GetRuleByte(mem62, ++Y) != ')');
+ mem65 = Y;
+ while((GetRuleByte(mem62, ++Y) & 127) != '=');
+ mem64 = Y;
+
+
+ mem60 = X = mem61;
+ // compare the string within the bracket
+ Y = mem66 + 1;
+
+ while(1) {
+ if (GetRuleByte(mem62, Y) != inputtemp[X]) goto pos36700;
+ if(++Y == mem65) break;
+ mem60 = ++X;
+ }
+
+ // the string in the bracket is correct
+
+ mem59 = mem61;
+
+ while(1) {
+ unsigned char ch;
+ while(1) {
+ mem66--;
+ mem57 = GetRuleByte(mem62, mem66);
+ if ((mem57 & 128) != 0) {
+ mem58 = mem60;
+ goto pos37184;
+ }
+ X = mem57 & 127;
+ if ((tab36376[X] & 128) == 0) break;
+ if (inputtemp[mem59-1] != mem57) goto pos36700;
+ --mem59;
+ }
+
+ ch = mem57;
+
+ r = handle_ch2(ch, mem59-1);
+ if (r == -1) {
+ switch (ch) {
+ case '&':
+ if (!Code37055(mem59-1,16)) {
+ if (inputtemp[X] != 'H') r = 1;
+ else {
+ A = inputtemp[--X];
+ if ((A != 'C') && (A != 'S')) r = 1;
+ }
+ }
+ break;
+
+ case '@':
+ if(!Code37055(mem59-1,4)) {
+ A = inputtemp[X];
+ if (A != 72) r = 1;
+ if ((A != 84) && (A != 67) && (A != 83)) r = 1;
+ }
+ break;
+ case '+':
+ X = mem59;
+ A = inputtemp[--X];
+ if ((A != 'E') && (A != 'I') && (A != 'Y')) r = 1;
+ break;
+ case ':':
+ while (Code37055(mem59-1,32)) --mem59;
+ continue;
+ default:
+ return 0;
+ }
+ }
+
+ if (r == 1) goto pos36700;
+
+ mem59 = X;
+ }
+
+ do {
+ X = mem58+1;
+ if (inputtemp[X] == 'E') {
+ if((tab36376[inputtemp[X+1]] & 128) != 0) {
+ A = inputtemp[++X];
+ if (A == 'L') {
+ if (inputtemp[++X] != 'Y') goto pos36700;
+ } else if ((A != 'R') && (A != 'S') && (A != 'D') && !match("FUL")) goto pos36700;
+ }
+ } else {
+ if (!match("ING")) goto pos36700;
+ mem58 = X;
+ }
+
+pos37184:
+ r = 0;
+ do {
+ while (1) {
+ Y = mem65 + 1;
+ if(Y == mem64) {
+ mem61 = mem60;
+
+ if (debug) PrintRule(mem62);
+
+ while(1) {
+ mem57 = A = GetRuleByte(mem62, Y);
+ A = A & 127;
+ if (A != '=') input[++mem56] = A;
+ if ((mem57 & 128) != 0) goto pos36554;
+ Y++;
+ }
+ }
+ mem65 = Y;
+ mem57 = GetRuleByte(mem62, Y);
+ if((tab36376[mem57] & 128) == 0) break;
+ if (inputtemp[mem58+1] != mem57) {
+ r = 1;
+ break;
+ }
+ ++mem58;
+ }
+
+ if (r == 0) {
+ A = mem57;
+ if (A == '@') {
+ if(Code37055(mem58+1, 4) == 0) {
+ A = inputtemp[X];
+ if ((A != 82) && (A != 84) &&
+ (A != 67) && (A != 83)) r = 1;
+ } else {
+ r = -2;
+ }
+ } else if (A == ':') {
+ while (Code37055(mem58+1, 32)) mem58 = X;
+ r = -2;
+ } else r = handle_ch(A, mem58+1);
+ }
+
+ if (r == 1) goto pos36700;
+ if (r == -2) {
+ r = 0;
+ continue;
+ }
+ if (r == 0) mem58 = X;
+ } while (r == 0);
+ } while (A == '%');
+ return 0;
+}
blob - 1429ec69e1eed3b0c05dec68290164505a310158
blob + b23ac550eed41072d996d339072911b52b389f3c
--- src/reciter.h
+++ src/reciter.h
#ifndef RECITER_C
#define RECITER_C
-//int TextToPhonemes(char *input, char *output);
+//int TextToPhonemes(unsigned char *input, unsigned char *output);
-int TextToPhonemes(char *input);
+int TextToPhonemes(unsigned char *input);
#endif
blob - 5468c2f4ba99f1b380e30c686328e449958c389f
blob + 9aebeb096fe596c182b80b26f70250728984dcda
--- src/render.c
+++ src/render.c
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
-#include "render.h"
-#include "RenderTabs.h"
-
-#include "debug.h"
-extern int debug;
-
-unsigned char wait1 = 7;
-unsigned char wait2 = 6;
-
-//extern unsigned char A, X, Y;
-//extern unsigned char mem44;
-
-extern unsigned char speed;
-extern unsigned char pitch;
-extern int singmode;
-
-
-extern unsigned char phonemeIndexOutput[60]; //tab47296
-extern unsigned char stressOutput[60]; //tab47365
-extern unsigned char phonemeLengthOutput[60]; //tab47416
-
-unsigned char pitches[256]; // tab43008
-
-unsigned char frequency1[256];
-unsigned char frequency2[256];
-unsigned char frequency3[256];
-
-unsigned char amplitude1[256];
-unsigned char amplitude2[256];
-unsigned char amplitude3[256];
-
-unsigned char sampledConsonantFlag[256]; // tab44800
-
-
-void AddInflection(unsigned char mem48, unsigned char phase1, unsigned char X);
-
-//return = hibyte(mem39212*mem39213) << 1
-unsigned char trans(unsigned char a, unsigned char b)
-{
- return ((a * b) >> 8) << 1;
-}
-
-
-
-
-// contains the final soundbuffer
-extern int bufferpos;
-extern char *buffer;
-
-
-
-//timetable for more accurate c64 simulation
-int timetable[5][5] =
-{
- {162, 167, 167, 127, 128},
- {226, 60, 60, 0, 0},
- {225, 60, 59, 0, 0},
- {200, 0, 0, 54, 55},
- {199, 0, 0, 54, 54}
-};
-
-void Output(int index, unsigned char A)
-{
- static unsigned oldtimetableindex = 0;
- int k;
- bufferpos += timetable[oldtimetableindex][index];
- oldtimetableindex = index;
- // write a little bit in advance
- for(k=0; k<5; k++)
- buffer[bufferpos/50 + k] = (A & 15)*16;
-}
-
-
-static unsigned char RenderVoicedSample(unsigned short hi, unsigned char off, unsigned char phase1)
-{
- do {
- unsigned char sample = sampleTable[hi+off];
- unsigned char bit = 8;
- do {
- if ((sample & 128) != 0) Output(3, 26);
- else Output(4, 6);
- sample <<= 1;
- } while(--bit != 0);
- off++;
- } while (++phase1 != 0);
- return off;
-}
-
-static void RenderUnvoicedSample(unsigned short hi, unsigned char off, unsigned char mem53)
-{
- do {
- unsigned char bit = 8;
- unsigned char sample = sampleTable[hi+off];
- do {
- if ((sample & 128) != 0) Output(2, 5);
- else Output(1, mem53);
- sample <<= 1;
- } while (--bit != 0);
- } while (++off != 0);
-}
-
-
-
-// -------------------------------------------------------------------------
-//Code48227
-// Render a sampled sound from the sampleTable.
-//
-// Phoneme Sample Start Sample End
-// 32: S* 15 255
-// 33: SH 257 511
-// 34: F* 559 767
-// 35: TH 583 767
-// 36: /H 903 1023
-// 37: /X 1135 1279
-// 38: Z* 84 119
-// 39: ZH 340 375
-// 40: V* 596 639
-// 41: DH 596 631
-//
-// 42: CH
-// 43: ** 399 511
-//
-// 44: J*
-// 45: ** 257 276
-// 46: **
-//
-// 66: P*
-// 67: ** 743 767
-// 68: **
-//
-// 69: T*
-// 70: ** 231 255
-// 71: **
-//
-// The SampledPhonemesTable[] holds flags indicating if a phoneme is
-// voiced or not. If the upper 5 bits are zero, the sample is voiced.
-//
-// Samples in the sampleTable are compressed, with bits being converted to
-// bytes from high bit to low, as follows:
-//
-// unvoiced 0 bit -> X
-// unvoiced 1 bit -> 5
-//
-// voiced 0 bit -> 6
-// voiced 1 bit -> 24
-//
-// Where X is a value from the table:
-//
-// { 0x18, 0x1A, 0x17, 0x17, 0x17 };
-//
-// The index into this table is determined by masking off the lower
-// 3 bits from the SampledPhonemesTable:
-//
-// index = (SampledPhonemesTable[i] & 7) - 1;
-//
-// For voices samples, samples are interleaved between voiced output.
-
-
-void RenderSample(unsigned char *mem66, unsigned char consonantFlag, unsigned char mem49)
-{
- // mem49 == current phoneme's index
-
- // mask low three bits and subtract 1 get value to
- // convert 0 bits on unvoiced samples.
- unsigned char hibyte = (consonantFlag & 7)-1;
-
- // determine which offset to use from table { 0x18, 0x1A, 0x17, 0x17, 0x17 }
- // T, S, Z 0 0x18
- // CH, J, SH, ZH 1 0x1A
- // P, F*, V, TH, DH 2 0x17
- // /H 3 0x17
- // /X 4 0x17
-
- unsigned short hi = hibyte*256;
- // voiced sample?
- unsigned char pitch = consonantFlag & 248;
- if(pitch == 0) {
- // voiced phoneme: Z*, ZH, V*, DH
- pitch = pitches[mem49] >> 4;
- *mem66 = RenderVoicedSample(hi, *mem66, pitch ^ 255);
- return;
- }
- RenderUnvoicedSample(hi, pitch^255, tab48426[hibyte]);
-}
-
-
-
-// CREATE FRAMES
-//
-// The length parameter in the list corresponds to the number of frames
-// to expand the phoneme to. Each frame represents 10 milliseconds of time.
-// So a phoneme with a length of 7 = 7 frames = 70 milliseconds duration.
-//
-// The parameters are copied from the phoneme to the frame verbatim.
-//
-static void CreateFrames()
-{
- unsigned char phase1 = 0;
-
- unsigned char X = 0;
- unsigned int i = 0;
- while(i < 256) {
- // get the phoneme at the index
- unsigned char phoneme = phonemeIndexOutput[i];
-
- // if terminal phoneme, exit the loop
- if (phoneme == 255) break;
-
- if (phoneme == PHONEME_PERIOD) AddInflection(RISING_INFLECTION, phase1,X);
- else if (phoneme == PHONEME_QUESTION) AddInflection(FALLING_INFLECTION, phase1,X);
-
- // get the stress amount (more stress = higher pitch)
- phase1 = tab47492[stressOutput[i] + 1];
-
- // get number of frames to write
- unsigned phase2 = phonemeLengthOutput[i];
-
- // copy from the source to the frames list
- do {
- frequency1[X] = freq1data[phoneme]; // F1 frequency
- frequency2[X] = freq2data[phoneme]; // F2 frequency
- frequency3[X] = freq3data[phoneme]; // F3 frequency
- amplitude1[X] = ampl1data[phoneme]; // F1 amplitude
- amplitude2[X] = ampl2data[phoneme]; // F2 amplitude
- amplitude3[X] = ampl3data[phoneme]; // F3 amplitude
- sampledConsonantFlag[X] = sampledConsonantFlags[phoneme]; // phoneme data for sampled consonants
- pitches[X] = pitch + phase1; // pitch
- ++X;
- } while(--phase2 != 0);
-
- ++i;
- }
-}
-
-
-// RESCALE AMPLITUDE
-//
-// Rescale volume from a linear scale to decibels.
-//
-void RescaleAmplitude()
-{
- int i;
- for(i=255; i>=0; i--)
- {
- amplitude1[i] = amplitudeRescale[amplitude1[i]];
- amplitude2[i] = amplitudeRescale[amplitude2[i]];
- amplitude3[i] = amplitudeRescale[amplitude3[i]];
- }
-}
-
-
-
-// ASSIGN PITCH CONTOUR
-//
-// This subtracts the F1 frequency from the pitch to create a
-// pitch contour. Without this, the output would be at a single
-// pitch level (monotone).
-
-void AssignPitchContour()
-{
- int i;
- for(i=0; i<256; i++) {
- // subtract half the frequency of the formant 1.
- // this adds variety to the voice
- pitches[i] -= (frequency1[i] >> 1);
- }
-}
-
-
-// RENDER THE PHONEMES IN THE LIST
-//
-// The phoneme list is converted into sound through the steps:
-//
-// 1. Copy each phoneme <length> number of times into the frames list,
-// where each frame represents 10 milliseconds of sound.
-//
-// 2. Determine the transitions lengths between phonemes, and linearly
-// interpolate the values across the frames.
-//
-// 3. Offset the pitches by the fundamental frequency.
-//
-// 4. Render the each frame.
-void Render()
-{
- if (phonemeIndexOutput[0] == 255) return; //exit if no data
-
- CreateFrames();
- unsigned char t = CreateTransitions();
-
- if (!singmode) AssignPitchContour();
- RescaleAmplitude();
-
- if (debug) {
- PrintOutput(sampledConsonantFlag, frequency1, frequency2, frequency3, amplitude1, amplitude2, amplitude3, pitches);
- }
-
- ProcessFrames(t);
-}
-
-
-// Create a rising or falling inflection 30 frames prior to
-// index X. A rising inflection is used for questions, and
-// a falling inflection is used for statements.
-
-void AddInflection(unsigned char inflection, unsigned char phase1, unsigned char pos)
-{
- unsigned char A;
- // store the location of the punctuation
- unsigned char end = pos;
-
- if (pos < 30) pos = 0;
- else pos -= 30;
-
- // FIXME: Explain this fix better, it's not obvious
- // ML : A =, fixes a problem with invalid pitch with '.'
- while( (A = pitches[pos]) == 127) ++pos;
-
- while (pos != end) {
- // add the inflection direction
- A += inflection;
-
- // set the inflection
- pitches[pos] = A;
-
- while ((++pos != end) && pitches[pos] == 255);
- }
-}
-
-/*
- SAM's voice can be altered by changing the frequencies of the
- mouth formant (F1) and the throat formant (F2). Only the voiced
- phonemes (5-29 and 48-53) are altered.
-*/
-void SetMouthThroat(unsigned char mouth, unsigned char throat)
-{
- unsigned char initialFrequency;
- unsigned char newFrequency = 0;
-
- // mouth formants (F1) 5..29
- unsigned char mouthFormants5_29[30] = {
- 0, 0, 0, 0, 0, 10,
- 14, 19, 24, 27, 23, 21, 16, 20, 14, 18, 14, 18, 18,
- 16, 13, 15, 11, 18, 14, 11, 9, 6, 6, 6};
-
- // throat formants (F2) 5..29
- unsigned char throatFormants5_29[30] = {
- 255, 255,
- 255, 255, 255, 84, 73, 67, 63, 40, 44, 31, 37, 45, 73, 49,
- 36, 30, 51, 37, 29, 69, 24, 50, 30, 24, 83, 46, 54, 86,
- };
-
- // there must be no zeros in this 2 tables
- // formant 1 frequencies (mouth) 48..53
- unsigned char mouthFormants48_53[6] = {19, 27, 21, 27, 18, 13};
-
- // formant 2 frequencies (throat) 48..53
- unsigned char throatFormants48_53[6] = {72, 39, 31, 43, 30, 34};
-
- unsigned char pos = 5;
-
- // recalculate formant frequencies 5..29 for the mouth (F1) and throat (F2)
- while(pos < 30)
- {
- // recalculate mouth frequency
- initialFrequency = mouthFormants5_29[pos];
- if (initialFrequency != 0) newFrequency = trans(mouth, initialFrequency);
- freq1data[pos] = newFrequency;
-
- // recalculate throat frequency
- initialFrequency = throatFormants5_29[pos];
- if(initialFrequency != 0) newFrequency = trans(throat, initialFrequency);
- freq2data[pos] = newFrequency;
- pos++;
- }
-
- // recalculate formant frequencies 48..53
- pos = 0;
- while(pos < 6) {
- // recalculate F1 (mouth formant)
- initialFrequency = mouthFormants48_53[pos];
- newFrequency = trans(mouth, initialFrequency);
- freq1data[pos+48] = newFrequency;
-
- // recalculate F2 (throat formant)
- initialFrequency = throatFormants48_53[pos];
- newFrequency = trans(throat, initialFrequency);
- freq2data[pos+48] = newFrequency;
- pos++;
- }
-}
-
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "render.h"
+#include "RenderTabs.h"
+
+#include "debug.h"
+extern int debug;
+
+//extern unsigned char A, X, Y;
+//extern unsigned char mem44;
+
+extern unsigned char speed;
+extern unsigned char pitch;
+extern int singmode;
+
+
+extern unsigned char phonemeIndexOutput[60]; //tab47296
+extern unsigned char stressOutput[60]; //tab47365
+extern unsigned char phonemeLengthOutput[60]; //tab47416
+
+unsigned char pitches[256]; // tab43008
+
+unsigned char frequency1[256];
+unsigned char frequency2[256];
+unsigned char frequency3[256];
+
+unsigned char amplitude1[256];
+unsigned char amplitude2[256];
+unsigned char amplitude3[256];
+
+unsigned char sampledConsonantFlag[256]; // tab44800
+
+
+void AddInflection(unsigned char mem48, unsigned char X);
+
+//return = hibyte(mem39212*mem39213) << 1
+unsigned char trans(unsigned char a, unsigned char b)
+{
+ return (((unsigned int)a * b) >> 8) << 1;
+}
+
+
+
+
+// contains the final soundbuffer
+extern int bufferpos;
+extern char *buffer;
+
+
+
+//timetable for more accurate c64 simulation
+static const int timetable[5][5] =
+{
+ {162, 167, 167, 127, 128},
+ {226, 60, 60, 0, 0},
+ {225, 60, 59, 0, 0},
+ {200, 0, 0, 54, 55},
+ {199, 0, 0, 54, 54}
+};
+
+void Output(int index, unsigned char A)
+{
+ static unsigned oldtimetableindex = 0;
+ int k;
+ bufferpos += timetable[oldtimetableindex][index];
+ oldtimetableindex = index;
+ // write a little bit in advance
+ for(k=0; k<5; k++)
+ buffer[bufferpos/50 + k] = (A & 15)*16;
+}
+
+
+static unsigned char RenderVoicedSample(unsigned short hi, unsigned char off, unsigned char phase1)
+{
+ do {
+ unsigned char bit = 8;
+ unsigned char sample = sampleTable[hi+off];
+ do {
+ if ((sample & 128) != 0) Output(3, 26);
+ else Output(4, 6);
+ sample <<= 1;
+ } while(--bit != 0);
+ off++;
+ } while (++phase1 != 0);
+ return off;
+}
+
+static void RenderUnvoicedSample(unsigned short hi, unsigned char off, unsigned char mem53)
+{
+ do {
+ unsigned char bit = 8;
+ unsigned char sample = sampleTable[hi+off];
+ do {
+ if ((sample & 128) != 0) Output(2, 5);
+ else Output(1, mem53);
+ sample <<= 1;
+ } while (--bit != 0);
+ } while (++off != 0);
+}
+
+
+
+// -------------------------------------------------------------------------
+//Code48227
+// Render a sampled sound from the sampleTable.
+//
+// Phoneme Sample Start Sample End
+// 32: S* 15 255
+// 33: SH 257 511
+// 34: F* 559 767
+// 35: TH 583 767
+// 36: /H 903 1023
+// 37: /X 1135 1279
+// 38: Z* 84 119
+// 39: ZH 340 375
+// 40: V* 596 639
+// 41: DH 596 631
+//
+// 42: CH
+// 43: ** 399 511
+//
+// 44: J*
+// 45: ** 257 276
+// 46: **
+//
+// 66: P*
+// 67: ** 743 767
+// 68: **
+//
+// 69: T*
+// 70: ** 231 255
+// 71: **
+//
+// The SampledPhonemesTable[] holds flags indicating if a phoneme is
+// voiced or not. If the upper 5 bits are zero, the sample is voiced.
+//
+// Samples in the sampleTable are compressed, with bits being converted to
+// bytes from high bit to low, as follows:
+//
+// unvoiced 0 bit -> X
+// unvoiced 1 bit -> 5
+//
+// voiced 0 bit -> 6
+// voiced 1 bit -> 24
+//
+// Where X is a value from the table:
+//
+// { 0x18, 0x1A, 0x17, 0x17, 0x17 };
+//
+// The index into this table is determined by masking off the lower
+// 3 bits from the SampledPhonemesTable:
+//
+// index = (SampledPhonemesTable[i] & 7) - 1;
+//
+// For voices samples, samples are interleaved between voiced output.
+
+
+void RenderSample(unsigned char *mem66, unsigned char consonantFlag, unsigned char mem49)
+{
+ // mem49 == current phoneme's index
+
+ // mask low three bits and subtract 1 get value to
+ // convert 0 bits on unvoiced samples.
+ unsigned char hibyte = (consonantFlag & 7)-1;
+
+ // determine which offset to use from table { 0x18, 0x1A, 0x17, 0x17, 0x17 }
+ // T, S, Z 0 0x18
+ // CH, J, SH, ZH 1 0x1A
+ // P, F*, V, TH, DH 2 0x17
+ // /H 3 0x17
+ // /X 4 0x17
+
+ unsigned short hi = hibyte*256;
+ // voiced sample?
+ unsigned char pitchl = consonantFlag & 248;
+ if(pitchl == 0) {
+ // voiced phoneme: Z*, ZH, V*, DH
+ pitchl = pitches[mem49] >> 4;
+ *mem66 = RenderVoicedSample(hi, *mem66, pitchl ^ 255);
+ }
+ else
+ RenderUnvoicedSample(hi, pitchl^255, tab48426[hibyte]);
+}
+
+
+
+// CREATE FRAMES
+//
+// The length parameter in the list corresponds to the number of frames
+// to expand the phoneme to. Each frame represents 10 milliseconds of time.
+// So a phoneme with a length of 7 = 7 frames = 70 milliseconds duration.
+//
+// The parameters are copied from the phoneme to the frame verbatim.
+//
+static void CreateFrames()
+{
+ unsigned char X = 0;
+ unsigned int i = 0;
+ while(i < 256) {
+ // get the phoneme at the index
+ unsigned char phoneme = phonemeIndexOutput[i];
+ unsigned char phase1;
+ unsigned phase2;
+
+ // if terminal phoneme, exit the loop
+ if (phoneme == 255) break;
+
+ if (phoneme == PHONEME_PERIOD) AddInflection(RISING_INFLECTION, X);
+ else if (phoneme == PHONEME_QUESTION) AddInflection(FALLING_INFLECTION, X);
+
+ // get the stress amount (more stress = higher pitch)
+ phase1 = tab47492[stressOutput[i] + 1];
+
+ // get number of frames to write
+ phase2 = phonemeLengthOutput[i];
+
+ // copy from the source to the frames list
+ do {
+ frequency1[X] = freq1data[phoneme]; // F1 frequency
+ frequency2[X] = freq2data[phoneme]; // F2 frequency
+ frequency3[X] = freq3data[phoneme]; // F3 frequency
+ amplitude1[X] = ampl1data[phoneme]; // F1 amplitude
+ amplitude2[X] = ampl2data[phoneme]; // F2 amplitude
+ amplitude3[X] = ampl3data[phoneme]; // F3 amplitude
+ sampledConsonantFlag[X] = sampledConsonantFlags[phoneme]; // phoneme data for sampled consonants
+ pitches[X] = pitch + phase1; // pitch
+ ++X;
+ } while(--phase2 != 0);
+
+ ++i;
+ }
+}
+
+
+// RESCALE AMPLITUDE
+//
+// Rescale volume from a linear scale to decibels.
+//
+void RescaleAmplitude()
+{
+ int i;
+ for(i=255; i>=0; i--)
+ {
+ amplitude1[i] = amplitudeRescale[amplitude1[i]];
+ amplitude2[i] = amplitudeRescale[amplitude2[i]];
+ amplitude3[i] = amplitudeRescale[amplitude3[i]];
+ }
+}
+
+
+
+// ASSIGN PITCH CONTOUR
+//
+// This subtracts the F1 frequency from the pitch to create a
+// pitch contour. Without this, the output would be at a single
+// pitch level (monotone).
+
+void AssignPitchContour()
+{
+ int i;
+ for(i=0; i<256; i++) {
+ // subtract half the frequency of the formant 1.
+ // this adds variety to the voice
+ pitches[i] -= (frequency1[i] >> 1);
+ }
+}
+
+
+// RENDER THE PHONEMES IN THE LIST
+//
+// The phoneme list is converted into sound through the steps:
+//
+// 1. Copy each phoneme <length> number of times into the frames list,
+// where each frame represents 10 milliseconds of sound.
+//
+// 2. Determine the transitions lengths between phonemes, and linearly
+// interpolate the values across the frames.
+//
+// 3. Offset the pitches by the fundamental frequency.
+//
+// 4. Render the each frame.
+void Render()
+{
+ unsigned char t;
+
+ if (phonemeIndexOutput[0] == 255) return; //exit if no data
+
+ CreateFrames();
+ t = CreateTransitions();
+
+ if (!singmode) AssignPitchContour();
+ RescaleAmplitude();
+
+ if (debug) {
+ PrintOutput(sampledConsonantFlag, frequency1, frequency2, frequency3, amplitude1, amplitude2, amplitude3, pitches);
+ }
+
+ ProcessFrames(t);
+}
+
+
+// Create a rising or falling inflection 30 frames prior to
+// index X. A rising inflection is used for questions, and
+// a falling inflection is used for statements.
+
+void AddInflection(unsigned char inflection, unsigned char pos)
+{
+ unsigned char A;
+ // store the location of the punctuation
+ unsigned char end = pos;
+
+ if (pos < 30) pos = 0;
+ else pos -= 30;
+
+ // FIXME: Explain this fix better, it's not obvious
+ // ML : A =, fixes a problem with invalid pitch with '.'
+ while( (A = pitches[pos]) == 127) ++pos;
+
+ while (pos != end) {
+ // add the inflection direction
+ A += inflection;
+
+ // set the inflection
+ pitches[pos] = A;
+
+ while ((++pos != end) && pitches[pos] == 255);
+ }
+}
+
+/*
+ SAM's voice can be altered by changing the frequencies of the
+ mouth formant (F1) and the throat formant (F2). Only the voiced
+ phonemes (5-29 and 48-53) are altered.
+*/
+void SetMouthThroat(unsigned char mouth, unsigned char throat)
+{
+ // mouth formants (F1) 5..29
+ static const unsigned char mouthFormants5_29[30] = {
+ 0, 0, 0, 0, 0, 10,
+ 14, 19, 24, 27, 23, 21, 16, 20, 14, 18, 14, 18, 18,
+ 16, 13, 15, 11, 18, 14, 11, 9, 6, 6, 6};
+
+ // throat formants (F2) 5..29
+ static const unsigned char throatFormants5_29[30] = {
+ 255, 255,
+ 255, 255, 255, 84, 73, 67, 63, 40, 44, 31, 37, 45, 73, 49,
+ 36, 30, 51, 37, 29, 69, 24, 50, 30, 24, 83, 46, 54, 86,
+ };
+
+ // there must be no zeros in this 2 tables
+ // formant 1 frequencies (mouth) 48..53
+ static const unsigned char mouthFormants48_53[6] = {19, 27, 21, 27, 18, 13};
+
+ // formant 2 frequencies (throat) 48..53
+ static const unsigned char throatFormants48_53[6] = {72, 39, 31, 43, 30, 34};
+
+ unsigned char newFrequency = 0;
+ unsigned char pos = 5;
+
+ // recalculate formant frequencies 5..29 for the mouth (F1) and throat (F2)
+ while(pos < 30)
+ {
+ // recalculate mouth frequency
+ unsigned char initialFrequency = mouthFormants5_29[pos];
+ if (initialFrequency != 0) newFrequency = trans(mouth, initialFrequency);
+ freq1data[pos] = newFrequency;
+
+ // recalculate throat frequency
+ initialFrequency = throatFormants5_29[pos];
+ if(initialFrequency != 0) newFrequency = trans(throat, initialFrequency);
+ freq2data[pos] = newFrequency;
+ pos++;
+ }
+
+ // recalculate formant frequencies 48..53
+ pos = 0;
+ while(pos < 6) {
+ // recalculate F1 (mouth formant)
+ unsigned char initialFrequency = mouthFormants48_53[pos];
+ freq1data[pos+48] = trans(mouth, initialFrequency);
+
+ // recalculate F2 (throat formant)
+ initialFrequency = throatFormants48_53[pos];
+ freq2data[pos+48] = trans(throat, initialFrequency);
+ pos++;
+ }
+}
blob - beaf01df613cafd5d3b69d82dac7e3072f276d6d
blob + bce479b178bba6c8d6f560212e0707928112c204
--- src/sam.c
+++ src/sam.c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+
#include "debug.h"
#include "sam.h"
#include "render.h"
#include "SamTabs.h"
-
-enum {
- pR = 23,
- pD = 57,
- pT = 69,
- BREAK = 254,
- END = 255
-};
-
-
-char input[256]; //tab39445
+enum {
+ pR = 23,
+ pD = 57,
+ pT = 69,
+ BREAK = 254,
+ END = 255
+};
+
+unsigned char input[256]; //tab39445
//standard sam sound
unsigned char speed = 72;
unsigned char pitch = 64;
extern int debug;
-unsigned char mem39;
-unsigned char mem44;
-unsigned char mem47;
-unsigned char mem49;
-unsigned char mem50;
-unsigned char mem51;
-unsigned char mem53;
-unsigned char mem59=0;
-
-unsigned char X;
-
unsigned char stress[256]; //numbers from 0 to 8
unsigned char phonemeLength[256]; //tab40160
unsigned char phonemeindex[256];
unsigned char stressOutput[60]; //tab47365
unsigned char phonemeLengthOutput[60]; //tab47416
-
-
-
// contains the final soundbuffer
int bufferpos=0;
char *buffer = NULL;
-void SetInput(char *_input)
+void SetInput(unsigned char *_input)
{
int i, l;
- l = strlen(_input);
+ l = strlen((char*)_input);
if (l > 254) l = 254;
for(i=0; i<l; i++)
input[i] = _input[i];
void AdjustLengths();
void Code41240();
void Insert(unsigned char position, unsigned char mem60, unsigned char mem59, unsigned char mem58);
-void InsertBreath(unsigned char mem59);
+void InsertBreath();
void PrepareOutput();
void SetMouthThroat(unsigned char mouth, unsigned char throat);
-
-void Init() {
- int i;
- SetMouthThroat( mouth, throat);
-
- bufferpos = 0;
- // TODO, check for free the memory, 10 seconds of output should be more than enough
- buffer = malloc(22050*10);
-
- for(i=0; i<256; i++) {
- stress[i] = 0;
- phonemeLength[i] = 0;
- }
-
- for(i=0; i<60; i++) {
- phonemeIndexOutput[i] = 0;
- stressOutput[i] = 0;
- phonemeLengthOutput[i] = 0;
- }
- phonemeindex[255] = END; //to prevent buffer overflow // ML : changed from 32 to 255 to stop freezing with long inputs
-}
-
-int SAMMain() {
- Init();
- /* FIXME: At odds with assignment in Init() */
- phonemeindex[255] = 32; //to prevent buffer overflow
-
- if (!Parser1()) return 0;
- if (debug) PrintPhonemes(phonemeindex, phonemeLength, stress);
- Parser2();
- CopyStress();
- SetPhonemeLength();
- AdjustLengths();
- Code41240();
- do {
- if (phonemeindex[X] > 80) {
- phonemeindex[X] = END;
- break; // error: delete all behind it
- }
- } while (++X != 0);
- InsertBreath(mem59);
-
- if (debug) PrintPhonemes(phonemeindex, phonemeLength, stress);
-
- PrepareOutput();
- return 1;
-}
-
-void PrepareOutput() {
- unsigned char srcpos = 0; // Position in source
- unsigned char destpos = 0; // Position in output
-
- while(1) {
- unsigned char A = phonemeindex[srcpos];
- phonemeIndexOutput[destpos] = A;
- switch(A) {
- case END:
- Render();
- return;
- case BREAK:
- phonemeIndexOutput[destpos] = END;
- Render();
- destpos = 0;
- break;
- case 0:
- break;
- default:
- phonemeLengthOutput[destpos] = phonemeLength[srcpos];
- stressOutput[destpos] = stress[srcpos];
- ++destpos;
- }
- ++srcpos;
- }
-}
-
-
-void InsertBreath(unsigned char mem59) {
- unsigned char mem54 = 255;
- unsigned char len = 0;
- unsigned char index; //variable Y
-
- unsigned char pos = 0;
-
- while((index = phonemeindex[pos]) != END) {
- len += phonemeLength[pos];
- if (len < 232) {
- if (index == BREAK) {
- } else if (!(flags[index]& FLAG_PUNCT)) {
- if (index == 0) mem54 = pos;
- } else {
- len = 0;
- Insert(++pos, BREAK, mem59, 0);
- }
- } else {
- pos = mem54;
- phonemeindex[pos] = 31; // 'Q*' glottal stop
- phonemeLength[pos] = 4;
- stress[pos] = 0;
-
- len = 0;
- Insert(++pos, BREAK, mem59, 0);
- }
- ++pos;
- }
-}
-
-
+
+void Init() {
+ int i;
+ SetMouthThroat( mouth, throat);
+
+ bufferpos = 0;
+ // TODO, check for free the memory, 10 seconds of output should be more than enough
+ buffer = malloc(22050*10);
+
+ for(i=0; i<256; i++) {
+ stress[i] = 0;
+ phonemeLength[i] = 0;
+ }
+
+ for(i=0; i<60; i++) {
+ phonemeIndexOutput[i] = 0;
+ stressOutput[i] = 0;
+ phonemeLengthOutput[i] = 0;
+ }
+ phonemeindex[255] = END; //to prevent buffer overflow // ML : changed from 32 to 255 to stop freezing with long inputs
+}
+
+int SAMMain() {
+ unsigned char X = 0; //!! is this intended like this?
+ Init();
+ /* FIXME: At odds with assignment in Init() */
+ phonemeindex[255] = 32; //to prevent buffer overflow
+
+ if (!Parser1()) return 0;
+ if (debug) PrintPhonemes(phonemeindex, phonemeLength, stress);
+ Parser2();
+ CopyStress();
+ SetPhonemeLength();
+ AdjustLengths();
+ Code41240();
+ do {
+ if (phonemeindex[X] > 80) {
+ phonemeindex[X] = END;
+ break; // error: delete all behind it
+ }
+ } while (++X != 0);
+ InsertBreath();
+
+ if (debug) PrintPhonemes(phonemeindex, phonemeLength, stress);
+
+ PrepareOutput();
+ return 1;
+}
+
+void PrepareOutput() {
+ unsigned char srcpos = 0; // Position in source
+ unsigned char destpos = 0; // Position in output
+
+ while(1) {
+ unsigned char A = phonemeindex[srcpos];
+ phonemeIndexOutput[destpos] = A;
+ switch(A) {
+ case END:
+ Render();
+ return;
+ case BREAK:
+ phonemeIndexOutput[destpos] = END;
+ Render();
+ destpos = 0;
+ break;
+ case 0:
+ break;
+ default:
+ phonemeLengthOutput[destpos] = phonemeLength[srcpos];
+ stressOutput[destpos] = stress[srcpos];
+ ++destpos;
+ break;
+ }
+ ++srcpos;
+ }
+}
+
+
+void InsertBreath() {
+ unsigned char mem54 = 255;
+ unsigned char len = 0;
+ unsigned char index; //variable Y
+
+ unsigned char pos = 0;
+
+ while((index = phonemeindex[pos]) != END) {
+ len += phonemeLength[pos];
+ if (len < 232) {
+ if (index == BREAK) {
+ } else if (!(flags[index] & FLAG_PUNCT)) {
+ if (index == 0) mem54 = pos;
+ } else {
+ len = 0;
+ Insert(++pos, BREAK, 0, 0);
+ }
+ } else {
+ pos = mem54;
+ phonemeindex[pos] = 31; // 'Q*' glottal stop
+ phonemeLength[pos] = 4;
+ stress[pos] = 0;
+
+ len = 0;
+ Insert(++pos, BREAK, 0, 0);
+ }
+ ++pos;
+ }
+}
+
+
// Iterates through the phoneme buffer, copying the stress value from
// the following phoneme under the following circumstance:
// to the L that precedes it.
-
-void CopyStress() {
- // loop thought all the phonemes to be output
- unsigned char pos=0; //mem66
- unsigned char Y;
- while((Y = phonemeindex[pos]) != END) {
- // if CONSONANT_FLAG set, skip - only vowels get stress
- if (flags[Y] & 64) {
- Y = phonemeindex[pos+1];
-
- // if the following phoneme is the end, or a vowel, skip
- if (Y != END && (flags[Y] & 128) != 0) {
- // get the stress value at the next position
- Y = stress[pos+1];
- if (Y && !(Y&128)) {
- // if next phoneme is stressed, and a VOWEL OR ER
- // copy stress from next phoneme to this one
- stress[pos] = Y+1;
- }
- }
- }
-
- ++pos;
- }
-}
-
-void Insert(unsigned char position/*var57*/, unsigned char mem60, unsigned char mem59, unsigned char mem58)
-{
- int i;
- for(i=253; i >= position; i--) // ML : always keep last safe-guarding 255
- {
- phonemeindex[i+1] = phonemeindex[i];
- phonemeLength[i+1] = phonemeLength[i];
- stress[i+1] = stress[i];
- }
-
- phonemeindex[position] = mem60;
- phonemeLength[position] = mem59;
- stress[position] = mem58;
- return;
-}
-
-
-signed int full_match(unsigned char sign1, unsigned char sign2) {
- unsigned char Y = 0;
- do {
- // GET FIRST CHARACTER AT POSITION Y IN signInputTable
- // --> should change name to PhonemeNameTable1
- unsigned char A = signInputTable1[Y];
-
- if (A == sign1) {
- A = signInputTable2[Y];
- // NOT A SPECIAL AND MATCHES SECOND CHARACTER?
- if ((A != '*') && (A == sign2)) return Y;
- }
- } while (++Y != 81);
- return -1;
-}
-
-signed int wild_match(unsigned char sign1, unsigned char sign2) {
- signed int Y = 0;
- do {
- if (signInputTable2[Y] == '*') {
- if (signInputTable1[Y] == sign1) return Y;
- }
- } while (++Y != 81);
- return -1;
-}
-
-
-
+
+void CopyStress() {
+ // loop thought all the phonemes to be output
+ unsigned char pos=0; //mem66
+ unsigned char Y;
+ while((Y = phonemeindex[pos]) != END) {
+ // if CONSONANT_FLAG set, skip - only vowels get stress
+ if (flags[Y] & 64) {
+ Y = phonemeindex[pos+1];
+
+ // if the following phoneme is the end, or a vowel, skip
+ if (Y != END && (flags[Y] & 128) != 0) {
+ // get the stress value at the next position
+ Y = stress[pos+1];
+ if (Y && !(Y&128)) {
+ // if next phoneme is stressed, and a VOWEL OR ER
+ // copy stress from next phoneme to this one
+ stress[pos] = Y+1;
+ }
+ }
+ }
+
+ ++pos;
+ }
+}
+
+void Insert(unsigned char position/*var57*/, unsigned char mem60, unsigned char mem59, unsigned char mem58)
+{
+ int i;
+ for(i=253; i >= position; i--) // ML : always keep last safe-guarding 255
+ {
+ phonemeindex[i+1] = phonemeindex[i];
+ phonemeLength[i+1] = phonemeLength[i];
+ stress[i+1] = stress[i];
+ }
+
+ phonemeindex[position] = mem60;
+ phonemeLength[position] = mem59;
+ stress[position] = mem58;
+}
+
+
+signed int full_match(unsigned char sign1, unsigned char sign2) {
+ unsigned char Y = 0;
+ do {
+ // GET FIRST CHARACTER AT POSITION Y IN signInputTable
+ // --> should change name to PhonemeNameTable1
+ unsigned char A = signInputTable1[Y];
+
+ if (A == sign1) {
+ A = signInputTable2[Y];
+ // NOT A SPECIAL AND MATCHES SECOND CHARACTER?
+ if ((A != '*') && (A == sign2)) return Y;
+ }
+ } while (++Y != 81);
+ return -1;
+}
+
+signed int wild_match(unsigned char sign1) {
+ signed int Y = 0;
+ do {
+ if (signInputTable2[Y] == '*') {
+ if (signInputTable1[Y] == sign1) return Y;
+ }
+ } while (++Y != 81);
+ return -1;
+}
+
+
+
// The input[] buffer contains a string of phonemes and stress markers along
// the lines of:
//
// 1. phonemeIndex[] will contain the index of all the phonemes.
// 2. The last index in phonemeIndex[] will be 255.
// 3. stress[] will contain the stress value for each phoneme
-
-// input[] holds the string of phonemes, each two bytes wide
-// signInputTable1[] holds the first character of each phoneme
-// signInputTable2[] holds te second character of each phoneme
-// phonemeIndex[] holds the indexes of the phonemes after parsing input[]
-//
-// The parser scans through the input[], finding the names of the phonemes
-// by searching signInputTable1[] and signInputTable2[]. On a match, it
-// copies the index of the phoneme into the phonemeIndexTable[].
-//
-// The character <0x9B> marks the end of text in input[]. When it is reached,
-// the index 255 is placed at the end of the phonemeIndexTable[], and the
-// function returns with a 1 indicating success.
-int Parser1()
-{
- int i;
- unsigned char sign1;
- unsigned char sign2;
- unsigned char position = 0;
- unsigned char srcpos = 0;
-
- for(i=0; i<256; i++) stress[i] = 0; // Clear the stress table.
-
- while((sign1 = input[srcpos]) != 155) { // 155 (\233) is end of line marker
- sign2 = input[++srcpos];
- signed int match = 0;
- if ((match = full_match(sign1, sign2)) != -1) {
- // Matched both characters (no wildcards)
- phonemeindex[position++] = (unsigned char)match;
- ++srcpos; // Skip the second character of the input as we've matched it
- } else if ((match=wild_match(sign1,sign2)) != -1) {
- // Matched just the first character (with second character matching '*'
- phonemeindex[position++] = (unsigned char)match;
- } else {
- // Should be a stress character. Search through the
- // stress table backwards.
- match = 8; // End of stress table. FIXME: Don't hardcode.
- while( (sign1 != stressInputTable[match]) && (match>0)) --match;
-
- if (match == 0) return 0; // failure
-
- stress[position-1] = match; // Set stress for prior phoneme
- }
- } //while
-
- phonemeindex[position] = END;
- return 1;
-}
-
-
-//change phonemelength depedendent on stress
-void SetPhonemeLength() {
- int position = 0;
- while(phonemeindex[position] != 255 ) {
- unsigned char A = stress[position];
- if ((A == 0) || ((A&128) != 0)) {
- phonemeLength[position] = phonemeLengthTable[phonemeindex[position]];
- } else {
- phonemeLength[position] = phonemeStressedLengthTable[phonemeindex[position]];
- }
- position++;
- }
-}
-
-void Code41240() {
- unsigned char pos=0;
-
- while(phonemeindex[pos] != END) {
- unsigned char index = phonemeindex[pos];
-
- if ((flags[index]& FLAG_STOPCONS)) {
- if ((flags[index]& FLAG_PLOSIVE)) {
- unsigned char A;
- unsigned char X = pos;
- while(!(A = phonemeindex[++X])); /* Skip pause */
-
- if (A != END) {
- if ((flags[A] & 8) || (A == 36) || (A == 37)) {++pos; continue;} // '/H' '/X'
- }
-
- }
- Insert(pos+1, index+1, phonemeLengthTable[index+1], stress[pos]);
- Insert(pos+2, index+2, phonemeLengthTable[index+2], stress[pos]);
- pos += 2;
- }
- ++pos;
- }
-}
-
-
-void ChangeRule(unsigned char position, unsigned char rule,unsigned char mem60, unsigned char mem59, unsigned char stress, const char * descr)
-{
- if (debug) printf("RULE: %s\n",descr);
- phonemeindex[position] = rule;
- Insert(position+1, mem60, mem59, stress);
-}
-
-void drule(const char * str) {
- if (debug) printf("RULE: %s\n",str);
-}
-
-void drule_pre(const char *descr, unsigned char X) {
- drule(descr);
- if (debug) printf("PRE\n");
- if (debug) printf("phoneme %d (%c%c) length %d\n", X, signInputTable1[phonemeindex[X]], signInputTable2[phonemeindex[X]], phonemeLength[X]);
-}
-
-void drule_post(unsigned char X) {
- if (debug) printf("POST\n");
- if (debug) printf("phoneme %d (%c%c) length %d\n", X, signInputTable1[phonemeindex[X]], signInputTable2[phonemeindex[X]], phonemeLength[X]);
-}
-
-
+
+// input[] holds the string of phonemes, each two bytes wide
+// signInputTable1[] holds the first character of each phoneme
+// signInputTable2[] holds te second character of each phoneme
+// phonemeIndex[] holds the indexes of the phonemes after parsing input[]
+//
+// The parser scans through the input[], finding the names of the phonemes
+// by searching signInputTable1[] and signInputTable2[]. On a match, it
+// copies the index of the phoneme into the phonemeIndexTable[].
+//
+// The character <0x9B> marks the end of text in input[]. When it is reached,
+// the index 255 is placed at the end of the phonemeIndexTable[], and the
+// function returns with a 1 indicating success.
+int Parser1()
+{
+ unsigned char sign1;
+ unsigned char position = 0;
+ unsigned char srcpos = 0;
+
+ memset(stress, 0, 256); // Clear the stress table.
+
+ while((sign1 = input[srcpos]) != 155) { // 155 (\233) is end of line marker
+ signed int match;
+ unsigned char sign2 = input[++srcpos];
+ if ((match = full_match(sign1, sign2)) != -1) {
+ // Matched both characters (no wildcards)
+ phonemeindex[position++] = (unsigned char)match;
+ ++srcpos; // Skip the second character of the input as we've matched it
+ } else if ((match = wild_match(sign1)) != -1) {
+ // Matched just the first character (with second character matching '*'
+ phonemeindex[position++] = (unsigned char)match;
+ } else {
+ // Should be a stress character. Search through the
+ // stress table backwards.
+ match = 8; // End of stress table. FIXME: Don't hardcode.
+ while( (sign1 != stressInputTable[match]) && (match>0) ) --match;
+
+ if (match == 0) return 0; // failure
+
+ stress[position-1] = (unsigned char)match; // Set stress for prior phoneme
+ }
+ } //while
+
+ phonemeindex[position] = END;
+ return 1;
+}
+
+
+//change phonemelength depedendent on stress
+void SetPhonemeLength() {
+ int position = 0;
+ while(phonemeindex[position] != 255) {
+ unsigned char A = stress[position];
+ if ((A == 0) || ((A&128) != 0)) {
+ phonemeLength[position] = phonemeLengthTable[phonemeindex[position]];
+ } else {
+ phonemeLength[position] = phonemeStressedLengthTable[phonemeindex[position]];
+ }
+ position++;
+ }
+}
+
+void Code41240() {
+ unsigned char pos=0;
+
+ while(phonemeindex[pos] != END) {
+ unsigned char index = phonemeindex[pos];
+
+ if ((flags[index] & FLAG_STOPCONS)) {
+ if ((flags[index] & FLAG_PLOSIVE)) {
+ unsigned char A;
+ unsigned char X = pos;
+ while(!phonemeindex[++X]); /* Skip pause */
+ A = phonemeindex[X];
+ if (A != END) {
+ if ((flags[A] & 8) || (A == 36) || (A == 37)) {++pos; continue;} // '/H' '/X'
+ }
+
+ }
+ Insert(pos+1, index+1, phonemeLengthTable[index+1], stress[pos]);
+ Insert(pos+2, index+2, phonemeLengthTable[index+2], stress[pos]);
+ pos += 2;
+ }
+ ++pos;
+ }
+}
+
+
+void ChangeRule(unsigned char position, unsigned char mem60, const char * descr)
+{
+ if (debug) printf("RULE: %s\n",descr);
+ phonemeindex[position] = 13; //rule;
+ Insert(position+1, mem60, 0, stress[position]);
+}
+
+void drule(const char * str) {
+ if (debug) printf("RULE: %s\n",str);
+}
+
+void drule_pre(const char *descr, unsigned char X) {
+ drule(descr);
+ if (debug) {
+ printf("PRE\n");
+ printf("phoneme %d (%c%c) length %d\n", X, signInputTable1[phonemeindex[X]], signInputTable2[phonemeindex[X]], phonemeLength[X]);
+ }
+}
+
+void drule_post(unsigned char X) {
+ if (debug) {
+ printf("POST\n");
+ printf("phoneme %d (%c%c) length %d\n", X, signInputTable1[phonemeindex[X]], signInputTable2[phonemeindex[X]], phonemeLength[X]);
+ }
+}
+
+
// Rewrites the phonemes using the following rules:
//
// <DIPTHONG ENDING WITH WX> -> <DIPTHONG ENDING WITH WX> WX
// J -> J J' (J requires two phonemes to represent it)
// <UNSTRESSED VOWEL> T <PAUSE> -> <UNSTRESSED VOWEL> DX <PAUSE>
// <UNSTRESSED VOWEL> D <PAUSE> -> <UNSTRESSED VOWEL> DX <PAUSE>
-
-
-void rule_alveolar_uw(unsigned char X) {
- // ALVEOLAR flag set?
- if (flags[phonemeindex[X-1]] & FLAG_ALVEOLAR) {
- drule("<ALVEOLAR> UW -> <ALVEOLAR> UX");
- phonemeindex[X] = 16;
- }
-}
-
-void rule_ch(unsigned char X, unsigned char mem59) {
- drule("CH -> CH CH+1");
- Insert(X+1, 43, mem59, stress[X]);
-}
-
-void rule_j(unsigned char X, unsigned char mem59) {
- drule("J -> J J+1");
- Insert(X+1, 45, mem59, stress[X]);
-}
-
-void rule_g(unsigned char pos) {
- // G <VOWEL OR DIPTHONG NOT ENDING WITH IY> -> GX <VOWEL OR DIPTHONG NOT ENDING WITH IY>
- // Example: GO
-
- unsigned char index = phonemeindex[pos+1];
-
- // If dipthong ending with YX, move continue processing next phoneme
- if ((index != 255) && ((flags[index] & FLAG_DIP_YX) == 0)) {
- // replace G with GX and continue processing next phoneme
- drule("G <VOWEL OR DIPTHONG NOT ENDING WITH IY> -> GX <VOWEL OR DIPTHONG NOT ENDING WITH IY>");
- phonemeindex[pos] = 63; // 'GX'
- }
-}
-
-
-void change(unsigned char pos, unsigned char val, const char * rule) {
- drule(rule);
- phonemeindex[pos] = val;
-}
-
-
-void rule_dipthong(unsigned char p, unsigned char pf, unsigned char pos, unsigned char mem59) {
- // <DIPTHONG ENDING WITH WX> -> <DIPTHONG ENDING WITH WX> WX
- // <DIPTHONG NOT ENDING WITH WX> -> <DIPTHONG NOT ENDING WITH WX> YX
- // Example: OIL, COW
-
- // If ends with IY, use YX, else use WX
- unsigned char A = (pf & FLAG_DIP_YX) ? 21 : 20; // 'WX' = 20 'YX' = 21
-
- // Insert at WX or YX following, copying the stress
- if (A==20) drule("insert WX following dipthong NOT ending in IY sound");
- if (A==21) drule("insert YX following dipthong ending in IY sound");
- Insert(pos+1, A, mem59, stress[pos]);
-
- if (p == 53 || p == 42 || p == 44) {
- if (p == 53) rule_alveolar_uw(pos); // Example: NEW, DEW, SUE, ZOO, THOO, TOO
- else if (p == 42) rule_ch(pos,mem59); // Example: CHEW
- else if (p == 44) rule_j(pos,mem59); // Example: JAY
- }
-}
-
-void Parser2() {
- unsigned char pos = 0; //mem66;
- unsigned char p;
-
- if (debug) printf("Parser2\n");
-
- while((p = phonemeindex[pos]) != END) {
- if (debug) printf("%d: %c%c\n", pos, signInputTable1[p], signInputTable2[p]);
-
- if (p == 0) { // Is phoneme pause?
- ++pos;
- continue;
- }
-
- unsigned char pf = flags[p];
- unsigned char prior = phonemeindex[pos-1];
-
- if ((pf & FLAG_DIPTHONG)) rule_dipthong(p, pf, pos, mem59);
- else if (p == 78) ChangeRule(pos, 13, 24, mem59, stress[pos],"UL -> AX L"); // Example: MEDDLE
- else if (p == 79) ChangeRule(pos, 13, 27, mem59, stress[pos], "UM -> AX M"); // Example: ASTRONOMY
- else if (p == 80) ChangeRule(pos, 13, 28, mem59, stress[pos], "UN -> AX N"); // Example: FUNCTION
- else if ((pf & FLAG_VOWEL) && stress[pos]) {
- // RULE:
- // <STRESSED VOWEL> <SILENCE> <STRESSED VOWEL> -> <STRESSED VOWEL> <SILENCE> Q <VOWEL>
- // EXAMPLE: AWAY EIGHT
- if (!phonemeindex[pos+1]) { // If following phoneme is a pause, get next
- p = phonemeindex[pos+2];
- if (p!=END && (flags[p] & FLAG_VOWEL) && stress[pos+2]) {
- drule("Insert glottal stop between two stressed vowels with space between them");
- Insert(pos+2, 31, mem59, 0); // 31 = 'Q'
- }
- }
- } else if (p == pR) { // RULES FOR PHONEMES BEFORE R
- if (prior == pT) change(pos-1,42, "T R -> CH R"); // Example: TRACK
- else if (prior == pD) change(pos-1,44, "D R -> J R"); // Example: DRY
- else if (flags[prior] & FLAG_VOWEL) change(pos, 18, "<VOWEL> R -> <VOWEL> RX"); // Example: ART
- } else if (p == 24 && (flags[prior] & FLAG_VOWEL)) change(pos, 19, "<VOWEL> L -> <VOWEL> LX"); // Example: ALL
- else if (prior == 60 && p == 32) { // 'G' 'S'
- // Can't get to fire -
- // 1. The G -> GX rule intervenes
- // 2. Reciter already replaces GS -> GZ
- change(pos, 38, "G S -> G Z");
- } else if (p == 60) rule_g(pos);
- else {
- if (p == 72) { // 'K'
- // K <VOWEL OR DIPTHONG NOT ENDING WITH IY> -> KX <VOWEL OR DIPTHONG NOT ENDING WITH IY>
- // Example: COW
- unsigned char Y = phonemeindex[pos+1];
- // If at end, replace current phoneme with KX
- if ((flags[Y] & FLAG_DIP_YX)==0 || Y==END) { // VOWELS AND DIPTHONGS ENDING WITH IY SOUND flag set?
- change(pos, 75, "K <VOWEL OR DIPTHONG NOT ENDING WITH IY> -> KX <VOWEL OR DIPTHONG NOT ENDING WITH IY>");
- p = 75;
- pf = flags[p];
- }
- }
-
- // Replace with softer version?
- if ((flags[p] & FLAG_PLOSIVE) && (prior == 32)) { // 'S'
- // RULE:
- // S P -> S B
- // S T -> S D
- // S K -> S G
- // S KX -> S GX
- // Examples: SPY, STY, SKY, SCOWL
-
- if (debug) printf("RULE: S* %c%c -> S* %c%c\n", signInputTable1[p], signInputTable2[p],signInputTable1[p-12], signInputTable2[p-12]);
- phonemeindex[pos] = p-12;
- } else if (!(pf & FLAG_PLOSIVE)) {
- p = phonemeindex[pos];
- if (p == 53) rule_alveolar_uw(pos); // Example: NEW, DEW, SUE, ZOO, THOO, TOO
- else if (p == 42) rule_ch(pos,mem59); // Example: CHEW
- else if (p == 44) rule_j(pos,mem59); // Example: JAY
- }
-
- if (p == 69 || p == 57) { // 'T', 'D'
- // RULE: Soften T following vowel
- // NOTE: This rule fails for cases such as "ODD"
- // <UNSTRESSED VOWEL> T <PAUSE> -> <UNSTRESSED VOWEL> DX <PAUSE>
- // <UNSTRESSED VOWEL> D <PAUSE> -> <UNSTRESSED VOWEL> DX <PAUSE>
- // Example: PARTY, TARDY
- if (flags[phonemeindex[pos-1]] & FLAG_VOWEL) {
- p = phonemeindex[pos+1];
- if (!p) p = phonemeindex[pos+2];
- if ((flags[p] & FLAG_VOWEL) && !stress[pos+1]) change(pos,30, "Soften T or D following vowel or ER and preceding a pause -> DX");
- }
- }
- }
- pos++;
- } // while
-}
-
-// Applies various rules that adjust the lengths of phonemes
-//
-// Lengthen <FRICATIVE> or <VOICED> between <VOWEL> and <PUNCTUATION> by 1.5
-// <VOWEL> <RX | LX> <CONSONANT> - decrease <VOWEL> length by 1
-// <VOWEL> <UNVOICED PLOSIVE> - decrease vowel by 1/8th
-// <VOWEL> <UNVOICED CONSONANT> - increase vowel by 1/2 + 1
-// <NASAL> <STOP CONSONANT> - set nasal = 5, consonant = 6
-// <VOICED STOP CONSONANT> {optional silence} <STOP CONSONANT> - shorten both to 1/2 + 1
-// <LIQUID CONSONANT> <DIPTHONG> - decrease by 2
-//
-void AdjustLengths() {
- // LENGTHEN VOWELS PRECEDING PUNCTUATION
- //
- // Search for punctuation. If found, back up to the first vowel, then
- // process all phonemes between there and up to (but not including) the punctuation.
- // If any phoneme is found that is a either a fricative or voiced, the duration is
- // increased by (length * 1.5) + 1
-
- // loop index
- unsigned char X = 0;
- unsigned char index;
-
- while((index = phonemeindex[X]) != END) {
- // not punctuation?
- if((flags[index] & FLAG_PUNCT) == 0) {
- ++X;
- continue;
- }
-
- unsigned char loopIndex = X;
-
- while (--X && !(flags[phonemeindex[X]] & FLAG_VOWEL)); // back up while not a vowel
- if (X == 0) break;
-
- do {
- // test for vowel
- index = phonemeindex[X];
-
+
+
+void rule_alveolar_uw(unsigned char X) {
+ // ALVEOLAR flag set?
+ if (flags[phonemeindex[X-1]] & FLAG_ALVEOLAR) {
+ drule("<ALVEOLAR> UW -> <ALVEOLAR> UX");
+ phonemeindex[X] = 16;
+ }
+}
+
+void rule_ch(unsigned char X) {
+ drule("CH -> CH CH+1");
+ Insert(X+1, 43, 0, stress[X]);
+}
+
+void rule_j(unsigned char X) {
+ drule("J -> J J+1");
+ Insert(X+1, 45, 0, stress[X]);
+}
+
+void rule_g(unsigned char pos) {
+ // G <VOWEL OR DIPTHONG NOT ENDING WITH IY> -> GX <VOWEL OR DIPTHONG NOT ENDING WITH IY>
+ // Example: GO
+
+ unsigned char index = phonemeindex[pos+1];
+
+ // If dipthong ending with YX, move continue processing next phoneme
+ if ((index != 255) && ((flags[index] & FLAG_DIP_YX) == 0)) {
+ // replace G with GX and continue processing next phoneme
+ drule("G <VOWEL OR DIPTHONG NOT ENDING WITH IY> -> GX <VOWEL OR DIPTHONG NOT ENDING WITH IY>");
+ phonemeindex[pos] = 63; // 'GX'
+ }
+}
+
+
+void change(unsigned char pos, unsigned char val, const char * rule) {
+ drule(rule);
+ phonemeindex[pos] = val;
+}
+
+
+void rule_dipthong(unsigned char p, unsigned short pf, unsigned char pos) {
+ // <DIPTHONG ENDING WITH WX> -> <DIPTHONG ENDING WITH WX> WX
+ // <DIPTHONG NOT ENDING WITH WX> -> <DIPTHONG NOT ENDING WITH WX> YX
+ // Example: OIL, COW
+
+ // If ends with IY, use YX, else use WX
+ unsigned char A = (pf & FLAG_DIP_YX) ? 21 : 20; // 'WX' = 20 'YX' = 21
+
+ // Insert at WX or YX following, copying the stress
+ if (A==20) drule("insert WX following dipthong NOT ending in IY sound");
+ else if (A==21) drule("insert YX following dipthong ending in IY sound");
+ Insert(pos+1, A, 0, stress[pos]);
+
+ if (p == 53) rule_alveolar_uw(pos); // Example: NEW, DEW, SUE, ZOO, THOO, TOO
+ else if (p == 42) rule_ch(pos); // Example: CHEW
+ else if (p == 44) rule_j(pos); // Example: JAY
+}
+
+void Parser2() {
+ unsigned char pos = 0; //mem66;
+ unsigned char p;
+
+ if (debug) printf("Parser2\n");
+
+ while((p = phonemeindex[pos]) != END) {
+ unsigned short pf;
+ unsigned char prior;
+
+ if (debug) printf("%d: %c%c\n", pos, signInputTable1[p], signInputTable2[p]);
+
+ if (p == 0) { // Is phoneme pause?
+ ++pos;
+ continue;
+ }
+
+ pf = flags[p];
+ prior = phonemeindex[pos-1];
+
+ if ((pf & FLAG_DIPTHONG)) rule_dipthong(p, pf, pos);
+ else if (p == 78) ChangeRule(pos, 24, "UL -> AX L"); // Example: MEDDLE
+ else if (p == 79) ChangeRule(pos, 27, "UM -> AX M"); // Example: ASTRONOMY
+ else if (p == 80) ChangeRule(pos, 28, "UN -> AX N"); // Example: FUNCTION
+ else if ((pf & FLAG_VOWEL) && stress[pos]) {
+ // RULE:
+ // <STRESSED VOWEL> <SILENCE> <STRESSED VOWEL> -> <STRESSED VOWEL> <SILENCE> Q <VOWEL>
+ // EXAMPLE: AWAY EIGHT
+ if (!phonemeindex[pos+1]) { // If following phoneme is a pause, get next
+ p = phonemeindex[pos+2];
+ if (p!=END && (flags[p] & FLAG_VOWEL) && stress[pos+2]) {
+ drule("Insert glottal stop between two stressed vowels with space between them");
+ Insert(pos+2, 31, 0, 0); // 31 = 'Q'
+ }
+ }
+ } else if (p == pR) { // RULES FOR PHONEMES BEFORE R
+ if (prior == pT) change(pos-1,42, "T R -> CH R"); // Example: TRACK
+ else if (prior == pD) change(pos-1,44, "D R -> J R"); // Example: DRY
+ else if (flags[prior] & FLAG_VOWEL) change(pos, 18, "<VOWEL> R -> <VOWEL> RX"); // Example: ART
+ } else if (p == 24 && (flags[prior] & FLAG_VOWEL)) change(pos, 19, "<VOWEL> L -> <VOWEL> LX"); // Example: ALL
+ else if (prior == 60 && p == 32) { // 'G' 'S'
+ // Can't get to fire -
+ // 1. The G -> GX rule intervenes
+ // 2. Reciter already replaces GS -> GZ
+ change(pos, 38, "G S -> G Z");
+ } else if (p == 60) rule_g(pos);
+ else {
+ if (p == 72) { // 'K'
+ // K <VOWEL OR DIPTHONG NOT ENDING WITH IY> -> KX <VOWEL OR DIPTHONG NOT ENDING WITH IY>
+ // Example: COW
+ unsigned char Y = phonemeindex[pos+1];
+ // If at end, replace current phoneme with KX
+ if ((flags[Y] & FLAG_DIP_YX)==0 || Y==END) { // VOWELS AND DIPTHONGS ENDING WITH IY SOUND flag set?
+ change(pos, 75, "K <VOWEL OR DIPTHONG NOT ENDING WITH IY> -> KX <VOWEL OR DIPTHONG NOT ENDING WITH IY>");
+ p = 75;
+ pf = flags[p];
+ }
+ }
+
+ // Replace with softer version?
+ if ((flags[p] & FLAG_PLOSIVE) && (prior == 32)) { // 'S'
+ // RULE:
+ // S P -> S B
+ // S T -> S D
+ // S K -> S G
+ // S KX -> S GX
+ // Examples: SPY, STY, SKY, SCOWL
+
+ if (debug) printf("RULE: S* %c%c -> S* %c%c\n", signInputTable1[p], signInputTable2[p],signInputTable1[p-12], signInputTable2[p-12]);
+ phonemeindex[pos] = p-12;
+ } else if (!(pf & FLAG_PLOSIVE)) {
+ p = phonemeindex[pos];
+ if (p == 53) rule_alveolar_uw(pos); // Example: NEW, DEW, SUE, ZOO, THOO, TOO
+ else if (p == 42) rule_ch(pos); // Example: CHEW
+ else if (p == 44) rule_j(pos); // Example: JAY
+ }
+
+ if (p == 69 || p == 57) { // 'T', 'D'
+ // RULE: Soften T following vowel
+ // NOTE: This rule fails for cases such as "ODD"
+ // <UNSTRESSED VOWEL> T <PAUSE> -> <UNSTRESSED VOWEL> DX <PAUSE>
+ // <UNSTRESSED VOWEL> D <PAUSE> -> <UNSTRESSED VOWEL> DX <PAUSE>
+ // Example: PARTY, TARDY
+ if (flags[phonemeindex[pos-1]] & FLAG_VOWEL) {
+ p = phonemeindex[pos+1];
+ if (!p) p = phonemeindex[pos+2];
+ if ((flags[p] & FLAG_VOWEL) && !stress[pos+1]) change(pos,30, "Soften T or D following vowel or ER and preceding a pause -> DX");
+ }
+ }
+ }
+ pos++;
+ } // while
+}
+
+// Applies various rules that adjust the lengths of phonemes
+//
+// Lengthen <FRICATIVE> or <VOICED> between <VOWEL> and <PUNCTUATION> by 1.5
+// <VOWEL> <RX | LX> <CONSONANT> - decrease <VOWEL> length by 1
+// <VOWEL> <UNVOICED PLOSIVE> - decrease vowel by 1/8th
+// <VOWEL> <UNVOICED CONSONANT> - increase vowel by 1/2 + 1
+// <NASAL> <STOP CONSONANT> - set nasal = 5, consonant = 6
+// <VOICED STOP CONSONANT> {optional silence} <STOP CONSONANT> - shorten both to 1/2 + 1
+// <LIQUID CONSONANT> <DIPTHONG> - decrease by 2
+//
+void AdjustLengths() {
+ // LENGTHEN VOWELS PRECEDING PUNCTUATION
+ //
+ // Search for punctuation. If found, back up to the first vowel, then
+ // process all phonemes between there and up to (but not including) the punctuation.
+ // If any phoneme is found that is a either a fricative or voiced, the duration is
+ // increased by (length * 1.5) + 1
+
+ // loop index
+ {
+ unsigned char X = 0;
+ unsigned char index;
+
+ while((index = phonemeindex[X]) != END) {
+ unsigned char loopIndex;
+
+ // not punctuation?
+ if((flags[index] & FLAG_PUNCT) == 0) {
+ ++X;
+ continue;
+ }
+
+ loopIndex = X;
+
+ while (--X && !(flags[phonemeindex[X]] & FLAG_VOWEL)); // back up while not a vowel
+ if (X == 0) break;
+
+ do {
+ // test for vowel
+ index = phonemeindex[X];
+
// test for fricative/unvoiced or not voiced
- if(!(flags[index] & FLAG_FRICATIVE) || (flags[index] & FLAG_VOICED)) { //nochmal überprüfen
- unsigned char A = phonemeLength[X];
- // change phoneme length to (length * 1.5) + 1
- drule_pre("Lengthen <FRICATIVE> or <VOICED> between <VOWEL> and <PUNCTUATION> by 1.5",X);
- phonemeLength[X] = (A >> 1) + A + 1;
- drule_post(X);
- }
- } while (++X != loopIndex);
- X++;
- } // while
-
- // Similar to the above routine, but shorten vowels under some circumstances
-
- // Loop throught all phonemes
- unsigned char loopIndex=0;
-
- while((index = phonemeindex[loopIndex]) != END) {
- unsigned char X = loopIndex;
-
- if (flags[index] & FLAG_VOWEL) {
- index = phonemeindex[loopIndex+1];
- if (!(flags[index] & FLAG_CONSONANT)) {
- if ((index == 18) || (index == 19)) { // 'RX', 'LX'
- index = phonemeindex[loopIndex+2];
- if ((flags[index] & FLAG_CONSONANT)) {
- drule_pre("<VOWEL> <RX | LX> <CONSONANT> - decrease length of vowel by 1\n", loopIndex);
- phonemeLength[loopIndex]--;
- drule_post(loopIndex);
- }
- }
- } else { // Got here if not <VOWEL>
- unsigned char flag = (index == END) ? 65 : flags[index]; // 65 if end marker
-
- if (!(flag & FLAG_VOICED)) { // Unvoiced
- // *, .*, ?*, ,*, -*, DX, S*, SH, F*, TH, /H, /X, CH, P*, T*, K*, KX
- if((flag & FLAG_PLOSIVE)) { // unvoiced plosive
- // RULE: <VOWEL> <UNVOICED PLOSIVE>
- // <VOWEL> <P*, T*, K*, KX>
- drule_pre("<VOWEL> <UNVOICED PLOSIVE> - decrease vowel by 1/8th",loopIndex);
- phonemeLength[loopIndex] -= (phonemeLength[loopIndex] >> 3);
- drule_post(loopIndex);
- }
- } else {
- drule_pre("<VOWEL> <VOICED CONSONANT> - increase vowel by 1/2 + 1\n",X-1);
- // decrease length
- unsigned char A = phonemeLength[loopIndex];
- phonemeLength[loopIndex] = (A >> 2) + A + 1; // 5/4*A + 1
- drule_post(loopIndex);
- }
- }
- } else if((flags[index] & FLAG_NASAL) != 0) { // nasal?
- // RULE: <NASAL> <STOP CONSONANT>
- // Set punctuation length to 6
- // Set stop consonant length to 5
- index = phonemeindex[++X];
- if (index != END && (flags[index] & FLAG_STOPCONS)) {
- drule("<NASAL> <STOP CONSONANT> - set nasal = 5, consonant = 6");
- phonemeLength[X] = 6; // set stop consonant length to 6
- phonemeLength[X-1] = 5; // set nasal length to 5
- }
- } else if((flags[index] & FLAG_STOPCONS)) { // (voiced) stop consonant?
- // RULE: <VOICED STOP CONSONANT> {optional silence} <STOP CONSONANT>
- // Shorten both to (length/2 + 1)
-
- // move past silence
- while ((index = phonemeindex[++X]) == 0);
-
- if (index != END && (flags[index] & FLAG_STOPCONS)) {
- // FIXME, this looks wrong?
+ if(!(flags[index] & FLAG_FRICATIVE) || (flags[index] & FLAG_VOICED)) { //nochmal überprüfen
+ unsigned char A = phonemeLength[X];
+ // change phoneme length to (length * 1.5) + 1
+ drule_pre("Lengthen <FRICATIVE> or <VOICED> between <VOWEL> and <PUNCTUATION> by 1.5",X);
+ phonemeLength[X] = (A >> 1) + A + 1;
+ drule_post(X);
+ }
+ } while (++X != loopIndex);
+ X++;
+ } // while
+ }
+
+ // Similar to the above routine, but shorten vowels under some circumstances
+
+ // Loop through all phonemes
+ unsigned char loopIndex=0;
+ unsigned char index;
+
+ while((index = phonemeindex[loopIndex]) != END) {
+ unsigned char X = loopIndex;
+
+ if (flags[index] & FLAG_VOWEL) {
+ index = phonemeindex[loopIndex+1];
+ if (!(flags[index] & FLAG_CONSONANT)) {
+ if ((index == 18) || (index == 19)) { // 'RX', 'LX'
+ index = phonemeindex[loopIndex+2];
+ if ((flags[index] & FLAG_CONSONANT)) {
+ drule_pre("<VOWEL> <RX | LX> <CONSONANT> - decrease length of vowel by 1\n", loopIndex);
+ phonemeLength[loopIndex]--;
+ drule_post(loopIndex);
+ }
+ }
+ } else { // Got here if not <VOWEL>
+ unsigned short flag = (index == END) ? 65 : flags[index]; // 65 if end marker
+
+ if (!(flag & FLAG_VOICED)) { // Unvoiced
+ // *, .*, ?*, ,*, -*, DX, S*, SH, F*, TH, /H, /X, CH, P*, T*, K*, KX
+ if((flag & FLAG_PLOSIVE)) { // unvoiced plosive
+ // RULE: <VOWEL> <UNVOICED PLOSIVE>
+ // <VOWEL> <P*, T*, K*, KX>
+ drule_pre("<VOWEL> <UNVOICED PLOSIVE> - decrease vowel by 1/8th",loopIndex);
+ phonemeLength[loopIndex] -= (phonemeLength[loopIndex] >> 3);
+ drule_post(loopIndex);
+ }
+ } else {
+ unsigned char A;
+ drule_pre("<VOWEL> <VOICED CONSONANT> - increase vowel by 1/2 + 1\n",X-1);
+ // decrease length
+ A = phonemeLength[loopIndex];
+ phonemeLength[loopIndex] = (A >> 2) + A + 1; // 5/4*A + 1
+ drule_post(loopIndex);
+ }
+ }
+ } else if((flags[index] & FLAG_NASAL) != 0) { // nasal?
+ // RULE: <NASAL> <STOP CONSONANT>
+ // Set punctuation length to 6
+ // Set stop consonant length to 5
+ index = phonemeindex[++X];
+ if (index != END && (flags[index] & FLAG_STOPCONS)) {
+ drule("<NASAL> <STOP CONSONANT> - set nasal = 5, consonant = 6");
+ phonemeLength[X] = 6; // set stop consonant length to 6
+ phonemeLength[X-1] = 5; // set nasal length to 5
+ }
+ } else if((flags[index] & FLAG_STOPCONS)) { // (voiced) stop consonant?
+ // RULE: <VOICED STOP CONSONANT> {optional silence} <STOP CONSONANT>
+ // Shorten both to (length/2 + 1)
+
+ // move past silence
+ while ((index = phonemeindex[++X]) == 0);
+
+ if (index != END && (flags[index] & FLAG_STOPCONS)) {
+ // FIXME, this looks wrong?
// RULE: <UNVOICED STOP CONSONANT> {optional silence} <STOP CONSONANT>
- drule("<UNVOICED STOP CONSONANT> {optional silence} <STOP CONSONANT> - shorten both to 1/2 + 1");
- phonemeLength[X] = (phonemeLength[X] >> 1) + 1;
- phonemeLength[loopIndex] = (phonemeLength[loopIndex] >> 1) + 1;
- X = loopIndex;
- }
- } else if ((flags[index] & FLAG_LIQUIC)) { // liquic consonant?
- // RULE: <VOICED NON-VOWEL> <DIPTHONG>
- // Decrease <DIPTHONG> by 2
- index = phonemeindex[X-1]; // prior phoneme;
-
- // FIXME: The debug code here breaks the rule.
- // prior phoneme a stop consonant>
- if((flags[index] & FLAG_STOPCONS) != 0)
- drule_pre("<LIQUID CONSONANT> <DIPTHONG> - decrease by 2",X);
-
- phonemeLength[X] -= 2; // 20ms
- drule_post(X);
- }
-
- ++loopIndex;
- }
-}
+ drule("<UNVOICED STOP CONSONANT> {optional silence} <STOP CONSONANT> - shorten both to 1/2 + 1");
+ phonemeLength[X] = (phonemeLength[X] >> 1) + 1;
+ phonemeLength[loopIndex] = (phonemeLength[loopIndex] >> 1) + 1;
+ X = loopIndex;
+ }
+ } else if ((flags[index] & FLAG_LIQUIC)) { // liquic consonant?
+ // RULE: <VOICED NON-VOWEL> <DIPTHONG>
+ // Decrease <DIPTHONG> by 2
+ index = phonemeindex[X-1]; // prior phoneme;
+
+ // FIXME: The debug code here breaks the rule.
+ // prior phoneme a stop consonant>
+ if((flags[index] & FLAG_STOPCONS) != 0)
+ drule_pre("<LIQUID CONSONANT> <DIPTHONG> - decrease by 2",X);
+
+ phonemeLength[X] -= 2; // 20ms
+ drule_post(X);
+ }
+
+ ++loopIndex;
+ }
+}
blob - f8a366e4733017fae53d87d32656df3909c9058c
blob + 346c7b3f20bd8241ab59e96804e527f17d31640f
--- src/sam.h
+++ src/sam.h
#ifndef SAM_H
#define SAM_H
-void SetInput(char *_input);
+void SetInput(unsigned char *_input);
void SetSpeed(unsigned char _speed);
void SetPitch(unsigned char _pitch);
void SetMouth(unsigned char _mouth);
void SetThroat(unsigned char _throat);
void EnableSingmode();
-void EnableDebug();
int SAMMain();
#endif
-