Skip to content

Commit a41570b

Browse files
markshannonntoll
authored andcommitted
Speech: Fix insertion of breath. Remove most global variables.
1 parent 310b01d commit a41570b

File tree

6 files changed

+167
-139
lines changed

6 files changed

+167
-139
lines changed

source/lib/sam/reciter.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "ReciterTabs.h"
55
#include "debug.h"
66

7-
unsigned char A, X, Y;
7+
static unsigned char A, X, Y;
88
extern int debug;
99

1010
void Code37055(reciter_memory* mem, unsigned char mem59)
@@ -158,6 +158,7 @@ int TextToPhonemes(reciter_memory* mem) // Code36484
158158
if(A == 0)
159159
{
160160
//36683: BRK
161+
sam_error = "Err 36683";
161162
return 0;
162163
}
163164

@@ -263,6 +264,7 @@ int TextToPhonemes(reciter_memory* mem) // Code36484
263264
if (A == ':') goto pos37040;
264265
// Code42041(); //Error
265266
//36894: BRK
267+
sam_error = "Err 36894";
266268
return 0;
267269

268270
// --------------
@@ -434,6 +436,7 @@ int TextToPhonemes(reciter_memory* mem) // Code36484
434436
//pos37291:
435437
// Code42041(); //Error
436438
//37294: BRK
439+
sam_error = "Err 36894";
437440
return 0;
438441

439442
// --------------

source/lib/sam/render.c

Lines changed: 49 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,7 @@
99
#include "sam.h"
1010
extern int debug;
1111

12-
unsigned char wait1 = 7;
13-
unsigned char wait2 = 6;
14-
15-
extern unsigned char A, X, Y;
16-
17-
18-
void AddInflection(sam_memory* sam, unsigned char mem48, unsigned char phase1);
12+
void AddInflection(sam_memory* sam, unsigned char mem48, unsigned char phase1, unsigned char punctuation);
1913

2014

2115
// contains the final soundbuffer
@@ -54,6 +48,10 @@ void Output(int index, unsigned char A)
5448
// 174=amplitude3
5549
unsigned char Read(sam_memory* sam, unsigned char p, unsigned char Y)
5650
{
51+
if (p > RENDER_FRAMES) {
52+
sam_error = "Out-of-buffer read";
53+
return 0;
54+
}
5755
switch(p)
5856
{
5957
case 168: return sam->render.pitch[Y];
@@ -64,12 +62,16 @@ unsigned char Read(sam_memory* sam, unsigned char p, unsigned char Y)
6462
case 173: return sam->render.freq_amp[Y].amp2;
6563
case 174: return sam->render.freq_amp[Y].amp3;
6664
}
65+
sam_error = "Read error";
6766
return 0;
6867
}
6968

7069
void Write(sam_memory* sam, unsigned char p, unsigned char Y, unsigned char value)
7170
{
72-
71+
if (p > RENDER_FRAMES) {
72+
sam_error = "Out-of-buffer write";
73+
return;
74+
}
7375
switch(p)
7476
{
7577
case 168: sam->render.pitch[Y] = value; return;
@@ -80,10 +82,10 @@ void Write(sam_memory* sam, unsigned char p, unsigned char Y, unsigned char valu
8082
case 173: sam->render.freq_amp[Y].amp2 = value; return;
8183
case 174: sam->render.freq_amp[Y].amp3 = value; return;
8284
}
85+
sam_error = "Write error";
8386
}
8487

8588

86-
8789
// -------------------------------------------------------------------------
8890
//Code48227
8991
// Render a sampled sound from the sampleTable.
@@ -140,19 +142,19 @@ void Write(sam_memory* sam, unsigned char p, unsigned char Y, unsigned char valu
140142

141143

142144
// Code48227()
143-
void RenderSample(sam_memory* sam, unsigned char *mem66, unsigned sample)
145+
unsigned char RenderSample(sam_memory* sam, unsigned char *mem66, unsigned sample, unsigned char pos)
144146
{
145147
int tempA;
146148
// current phoneme's index
147149
unsigned char mem47;
148-
unsigned char mem49 = Y;
150+
unsigned char mem49 = pos;
149151
unsigned char mem53;
150152
unsigned char mem56;
151153

152154
// mask low three bits and subtract 1 get value to
153155
// convert 0 bits on unvoiced samples.
154-
A = sample&7;
155-
X = A-1;
156+
unsigned char A = sample&7;
157+
unsigned char X = A-1;
156158

157159
// store the result
158160
mem56 = X;
@@ -165,6 +167,8 @@ void RenderSample(sam_memory* sam, unsigned char *mem66, unsigned sample)
165167
// /X 4 0x17
166168

167169
// get value from the table
170+
if (X >= sizeof(tab48426))
171+
sam_error = "Out-of-buffer read";
168172
mem53 = tab48426[X];
169173
mem47 = X; //46016+mem[56]*256
170174

@@ -173,22 +177,22 @@ void RenderSample(sam_memory* sam, unsigned char *mem66, unsigned sample)
173177
if(A == 0)
174178
{
175179
// voiced phoneme: Z*, ZH, V*, DH
176-
Y = mem49;
180+
pos = mem49;
177181
A = sam->render.pitch[9] >> 4;
178182

179183
// jump to voiced portion
180184
goto pos48315;
181185
}
182186

183-
Y = A ^ 255;
187+
pos = A ^ 255;
184188
pos48274:
185189

186190
// step through the 8 bits in the sample
187191
mem56 = 8;
188192

189193
// get the next sample from the table
190194
// mem47*256 = offset to start of samples
191-
A = sampleTable[mem47*256+Y];
195+
A = sampleTable[mem47*256+pos];
192196
pos48280:
193197

194198
// left shift to get the high bit
@@ -223,12 +227,12 @@ void RenderSample(sam_memory* sam, unsigned char *mem66, unsigned sample)
223227
if (mem56 != 0) goto pos48280;
224228

225229
// increment position
226-
Y++;
227-
if (Y != 0) goto pos48274;
230+
pos++;
231+
if (pos != 0) goto pos48274;
228232

229233
// restore values and return
230-
Y = mem49;
231-
return;
234+
pos = mem49;
235+
return pos;
232236

233237

234238
unsigned char phase1;
@@ -239,17 +243,17 @@ void RenderSample(sam_memory* sam, unsigned char *mem66, unsigned sample)
239243
// number of samples?
240244
phase1 = A ^ 255;
241245

242-
Y = *mem66;
246+
pos = *mem66;
243247
do
244248
{
245249
//pos48321:
246250

247251
// shift through all 8 bits
248252
mem56 = 8;
249-
//A = Read(sam, mem47, Y);
253+
//A = Read(sam, mem47, pos);
250254

251255
// fetch value from table
252-
A = sampleTable[mem47*256+Y];
256+
A = sampleTable[mem47*256+pos];
253257

254258
// loop 8 times
255259
//pos48327:
@@ -278,7 +282,7 @@ void RenderSample(sam_memory* sam, unsigned char *mem66, unsigned sample)
278282
} while(mem56 != 0);
279283

280284
// move ahead in the table
281-
Y++;
285+
pos++;
282286

283287
// continue until counter done
284288
phase1++;
@@ -288,9 +292,9 @@ void RenderSample(sam_memory* sam, unsigned char *mem66, unsigned sample)
288292

289293
// restore values and return
290294
A = 1;
291-
*mem66 = Y;
292-
Y = mem49;
293-
return;
295+
*mem66 = pos;
296+
pos = mem49;
297+
return pos;
294298
}
295299

296300

@@ -331,8 +335,8 @@ void Render(sam_memory* sam)
331335
int i;
332336
if (sam->common.phoneme_output[0].index == PHONEME_END) return; //exit if no data
333337

334-
A = 0;
335-
X = 0;
338+
unsigned char A = 0;
339+
unsigned char X = 0;
336340

337341
// CREATE FRAMES
338342
//
@@ -346,7 +350,7 @@ void Render(sam_memory* sam)
346350
do
347351
{
348352
// get the index
349-
Y = mem44;
353+
unsigned char Y = mem44;
350354
// get the phoneme at the index
351355
A = sam->common.phoneme_output[mem44].index;
352356
mem56 = A;
@@ -361,7 +365,7 @@ void Render(sam_memory* sam)
361365
A = 1;
362366
mem48 = 1;
363367
//goto pos48376;
364-
AddInflection(sam, mem48, phase1);
368+
AddInflection(sam, mem48, phase1, X);
365369
}
366370
/*
367371
if (A == 2) goto pos48372;
@@ -372,7 +376,7 @@ void Render(sam_memory* sam)
372376
{
373377
// create falling inflection
374378
mem48 = 255;
375-
AddInflection(sam, mem48, phase1);
379+
AddInflection(sam, mem48, phase1, X);
376380
}
377381
// pos47615:
378382

@@ -540,7 +544,7 @@ void Render(sam_memory* sam)
540544
while(1) //while No. 1
541545
{
542546
// get the current and following phoneme
543-
Y = sam->common.phoneme_output[X].index;
547+
unsigned char Y = sam->common.phoneme_output[X].index;
544548
A = sam->common.phoneme_output[X+1].index;
545549
X++;
546550

@@ -717,25 +721,21 @@ void OutputFrames(sam_memory *sam, unsigned char frame_count) {
717721
unsigned char phase2 = 0;
718722
unsigned char phase3 = 0;
719723
unsigned char speedcounter = 72; //sam standard speed
720-
unsigned char count;
721-
unsigned char glottal_pulse;
722-
unsigned char sample;
723724
unsigned char mem66 = 0;
724725

725726
// RESCALE AMPLITUDE
726-
// Rescale volume from a linear scale to decibels.
727+
// Rescale volume from decibels to a linear scale.
727728
for(int i=RENDER_FRAMES-1; i>=0; i--)
728729
{
729730
sam->render.freq_amp[i].amp1 = amplitudeRescale[sam->render.freq_amp[i].amp1];
730731
sam->render.freq_amp[i].amp2 = amplitudeRescale[sam->render.freq_amp[i].amp2];
731732
sam->render.freq_amp[i].amp3 = amplitudeRescale[sam->render.freq_amp[i].amp3];
732733
}
733734

734-
Y = 0;
735-
A = sam->render.pitch[0];
736-
glottal_pulse = A;
737-
X = A;
738-
count = A - (A>>2); // 3/4*A ???
735+
unsigned char Y = 0;
736+
unsigned char A = sam->render.pitch[0];
737+
unsigned char glottal_pulse = A;
738+
unsigned char count = A - (A>>2); // 3/4*A ???
739739

740740
if (debug)
741741
{
@@ -757,16 +757,16 @@ void OutputFrames(sam_memory *sam, unsigned char frame_count) {
757757
{
758758
// get the sampled information on the phoneme
759759
A = sam->render.flags[Y];
760-
sample = A;
760+
unsigned char sample = A;
761761

762762
// unvoiced sampled phoneme?
763763
A = A & 248;
764764
if(A != 0)
765765
{
766766
// render the sample for the phoneme
767-
RenderSample(sam, &mem66, sample);
767+
Y = RenderSample(sam, &mem66, sample, Y);
768768

769-
// skip ahead two in the fram ebuffer
769+
// skip ahead two in the frame buffer
770770
Y += 2;
771771
frame_count -= 2;
772772
} else
@@ -832,7 +832,7 @@ void OutputFrames(sam_memory *sam, unsigned char frame_count) {
832832
// voiced sampled phonemes interleave the sample with the
833833
// glottal pulse. The sample flag is non-zero, so render
834834
// the sample for the phoneme.
835-
RenderSample(sam, &mem66, sample);
835+
Y = RenderSample(sam, &mem66, sample, Y);
836836
goto pos48159;
837837
}
838838
}
@@ -842,19 +842,16 @@ void OutputFrames(sam_memory *sam, unsigned char frame_count) {
842842
// index X. A rising inflection is used for questions, and
843843
// a falling inflection is used for statements.
844844

845-
void AddInflection(sam_memory* sam, unsigned char mem48, unsigned char phase1)
845+
void AddInflection(sam_memory* sam, unsigned char mem48, unsigned char phase1, unsigned char punctuation)
846846
{
847-
848-
// store the location of the punctuation
849-
unsigned char punctuation = X;
850-
A = X;
847+
unsigned char A = punctuation;
851848
int Atemp = A;
852849

853850
// backup 30 frames
854851
A = A - 30;
855852
// if index is before buffer, point to start of buffer
856853
if (Atemp <= 30) A=0;
857-
X = A;
854+
unsigned char X = A;
858855

859856
// FIXME: Explain this fix better, it's not obvious
860857
// ML : A =, fixes a problem with invalid pitch with '.'

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy