Skip to content

Commit c58a550

Browse files
committed
Speech refactor and clarify output part of renderer.
1 parent 21cece6 commit c58a550

File tree

3 files changed

+112
-118
lines changed

3 files changed

+112
-118
lines changed

source/lib/sam/render.c

Lines changed: 110 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,7 @@ void Render(sam_memory* sam)
317317
unsigned char phase1 = 0; //mem43
318318
unsigned char phase2;
319319
unsigned char phase3;
320-
unsigned char mem66;
321320
unsigned char mem38;
322-
unsigned char sample;
323321
unsigned char mem40;
324322
unsigned char speedcounter; //mem45
325323
unsigned char mem47;
@@ -331,7 +329,6 @@ void Render(sam_memory* sam)
331329
unsigned char mem56;
332330
unsigned char mem44 = 0;
333331
int i;
334-
int carry;
335332
if (sam->common.phoneme_output[0].index == PHONEME_END) return; //exit if no data
336333

337334
A = 0;
@@ -346,63 +343,62 @@ void Render(sam_memory* sam)
346343
// The parameters are copied from the phoneme to the frame verbatim.
347344

348345

349-
// pos47587:
350-
do
351-
{
352-
// get the index
353-
Y = mem44;
354-
// get the phoneme at the index
355-
A = sam->common.phoneme_output[mem44].index;
356-
mem56 = A;
357-
358-
// if terminal phoneme, exit the loop
359-
if (A == PHONEME_END) break;
360-
361-
// period phoneme *.
362-
if (A == 1)
363-
{
364-
// add rising inflection
365-
A = 1;
366-
mem48 = 1;
367-
//goto pos48376;
368-
AddInflection(sam, mem48, phase1);
369-
}
370-
/*
371-
if (A == 2) goto pos48372;
372-
*/
373-
374-
// question mark phoneme?
375-
if (A == 2)
376-
{
377-
// create falling inflection
378-
mem48 = 255;
379-
AddInflection(sam, mem48, phase1);
380-
}
381-
// pos47615:
382-
383-
// get the stress amount (more stress = higher pitch)
384-
phase1 = tab47492[sam->common.phoneme_output[Y].stress + 1];
385-
386-
// get number of frames to write
387-
phase2 = sam->common.phoneme_output[Y].length;
388-
Y = mem56;
389-
390-
// copy from the source to the frames list
391-
do
392-
{
393-
sam->render.freq_amp[X].freq1 = get_freq1(Y, sam->common.mouth); // F1 frequency
394-
sam->render.freq_amp[X].freq2 = get_freq2(Y, sam->common.throat); // F2 frequency
395-
sam->render.freq_amp[X].freq3 = freq3data[Y]; // F3 frequency
396-
sam->render.freq_amp[X].amp1 = ampl1data[Y]; // F1 amplitude
397-
sam->render.freq_amp[X].amp2 = ampl2data[Y]; // F2 amplitude
398-
sam->render.freq_amp[X].amp3 = ampl3data[Y]; // F3 amplitude
399-
sam->render.flags[X] = sampledConsonantFlags[Y]; // phoneme data for sampled consonants
400-
sam->render.pitch[X] = sam->common.pitch + phase1; // pitch
401-
X++;
402-
phase2--;
403-
} while(phase2 != 0);
404-
mem44++;
405-
} while(mem44 != RENDER_FRAMES);
346+
do
347+
{
348+
// get the index
349+
Y = mem44;
350+
// get the phoneme at the index
351+
A = sam->common.phoneme_output[mem44].index;
352+
mem56 = A;
353+
354+
// if terminal phoneme, exit the loop
355+
if (A == PHONEME_END) break;
356+
357+
// period phoneme *.
358+
if (A == 1)
359+
{
360+
// add rising inflection
361+
A = 1;
362+
mem48 = 1;
363+
//goto pos48376;
364+
AddInflection(sam, mem48, phase1);
365+
}
366+
/*
367+
if (A == 2) goto pos48372;
368+
*/
369+
370+
// question mark phoneme?
371+
if (A == 2)
372+
{
373+
// create falling inflection
374+
mem48 = 255;
375+
AddInflection(sam, mem48, phase1);
376+
}
377+
// pos47615:
378+
379+
// get the stress amount (more stress = higher pitch)
380+
phase1 = tab47492[sam->common.phoneme_output[Y].stress + 1];
381+
382+
// get number of frames to write
383+
phase2 = sam->common.phoneme_output[Y].length;
384+
Y = mem56;
385+
386+
// copy from the source to the frames list
387+
do
388+
{
389+
sam->render.freq_amp[X].freq1 = get_freq1(Y, sam->common.mouth); // F1 frequency
390+
sam->render.freq_amp[X].freq2 = get_freq2(Y, sam->common.throat); // F2 frequency
391+
sam->render.freq_amp[X].freq3 = freq3data[Y]; // F3 frequency
392+
sam->render.freq_amp[X].amp1 = ampl1data[Y]; // F1 amplitude
393+
sam->render.freq_amp[X].amp2 = ampl2data[Y]; // F2 amplitude
394+
sam->render.freq_amp[X].amp3 = ampl3data[Y]; // F3 amplitude
395+
sam->render.flags[X] = sampledConsonantFlags[Y]; // phoneme data for sampled consonants
396+
sam->render.pitch[X] = sam->common.pitch + phase1; // pitch
397+
X++;
398+
phase2--;
399+
} while(phase2 != 0);
400+
mem44++;
401+
} while(mem44 != OUTPUT_PHONEMES);
406402

407403

408404
// -------------------
@@ -712,20 +708,23 @@ do
712708
sam->render.pitch[i] -= (sam->render.freq_amp[i].freq1 >> 1);
713709
}
714710
}
711+
OutputFrames(sam, mem48);
712+
}
715713

716-
phase1 = 0;
717-
phase2 = 0;
718-
phase3 = 0;
719-
mem49 = 0;
720-
speedcounter = 72; //sam standard speed
714+
void OutputFrames(sam_memory *sam, unsigned char frame_count) {
721715

722-
// RESCALE AMPLITUDE
723-
//
724-
// Rescale volume from a linear scale to decibels.
725-
//
716+
unsigned char phase1 = 0;
717+
unsigned char phase2 = 0;
718+
unsigned char phase3 = 0;
719+
unsigned char speedcounter = 72; //sam standard speed
720+
unsigned char count;
721+
unsigned char glottal_pulse;
722+
unsigned char sample;
723+
unsigned char mem66 = 0;
726724

727-
//amplitude rescaling
728-
for(i=RENDER_FRAMES-1; i>=0; i--)
725+
// RESCALE AMPLITUDE
726+
// Rescale volume from a linear scale to decibels.
727+
for(int i=RENDER_FRAMES-1; i>=0; i--)
729728
{
730729
sam->render.freq_amp[i].amp1 = amplitudeRescale[sam->render.freq_amp[i].amp1];
731730
sam->render.freq_amp[i].amp2 = amplitudeRescale[sam->render.freq_amp[i].amp2];
@@ -734,14 +733,14 @@ do
734733

735734
Y = 0;
736735
A = sam->render.pitch[0];
737-
mem44 = A;
736+
glottal_pulse = A;
738737
X = A;
739-
mem38 = A - (A>>2); // 3/4*A ???
738+
count = A - (A>>2); // 3/4*A ???
740739

741-
if (debug)
742-
{
743-
PrintOutput(sam->render.flags, sam->render.freq_amp, sam->render.pitch, mem48);
744-
}
740+
if (debug)
741+
{
742+
PrintOutput(sam->render.flags, sam->render.freq_amp, sam->render.pitch, frame_count);
743+
}
745744

746745
// PROCESS THE FRAMES
747746
//
@@ -767,18 +766,18 @@ if (debug)
767766
// render the sample for the phoneme
768767
RenderSample(sam, &mem66, sample);
769768

770-
// skip ahead two in the phoneme buffer
769+
// skip ahead two in the fram ebuffer
771770
Y += 2;
772-
mem48 -= 2;
771+
frame_count -= 2;
773772
} else
774773
{
775774
// simulate the glottal pulse and formants
776-
mem56 = multtable[sinus[phase1] | sam->render.freq_amp[Y].amp1];
775+
unsigned char accum = multtable[sinus[phase1] | sam->render.freq_amp[Y].amp1];
777776

778-
carry = 0;
779-
if ((mem56+multtable[sinus[phase2] | sam->render.freq_amp[Y].amp2] ) > 255) carry = 1;
780-
mem56 += multtable[sinus[phase2] | sam->render.freq_amp[Y].amp2];
781-
A = mem56 + multtable[rectangle[phase3] | sam->render.freq_amp[Y].amp3] + (carry?1:0);
777+
int carry = 0;
778+
if ((accum+multtable[sinus[phase2] | sam->render.freq_amp[Y].amp2] ) > 255) carry = 1;
779+
accum += multtable[sinus[phase2] | sam->render.freq_amp[Y].amp2];
780+
A = accum + multtable[rectangle[phase3] | sam->render.freq_amp[Y].amp3] + (carry?1:0);
782781
A = ((A + 136) & 255) >> 4; //there must be also a carry
783782
//mem[54296] = A;
784783

@@ -789,26 +788,26 @@ if (debug)
789788
Y++; //go to next amplitude
790789

791790
// decrement the frame count
792-
mem48--;
791+
frame_count--;
793792
}
794793

795794
// if the frame count is zero, exit the loop
796-
if(mem48 == 0) return;
795+
if(frame_count == 0) return;
797796
speedcounter = sam->common.speed;
798797
pos48155:
799798

800799
// decrement the remaining length of the glottal pulse
801-
mem44--;
800+
glottal_pulse--;
802801

803802
// finished with a glottal pulse?
804-
if(mem44 == 0)
803+
if(glottal_pulse == 0)
805804
{
806805
pos48159:
807806
// fetch the next glottal pulse length
808807
A = sam->render.pitch[Y];
809-
mem44 = A;
808+
glottal_pulse = A;
810809
A = A - (A>>2);
811-
mem38 = A;
810+
count = A;
812811

813812
// reset the formant wave generators to keep them in
814813
// sync with the glottal pulse
@@ -819,11 +818,10 @@ if (debug)
819818
}
820819

821820
// decrement the count
822-
mem38--;
821+
count--;
823822

824823
// is the count non-zero and the sampled flag is zero?
825-
if((mem38 != 0) || (sample == 0))
826-
{
824+
if((count != 0) || (sample == 0)) {
827825
// reset the phase of the formants to match the pulse
828826
phase1 += sam->render.freq_amp[Y].freq1;
829827
phase2 += sam->render.freq_amp[Y].freq2;
@@ -846,12 +844,9 @@ if (debug)
846844

847845
void AddInflection(sam_memory* sam, unsigned char mem48, unsigned char phase1)
848846
{
849-
//pos48372:
850-
// mem48 = 255;
851-
//pos48376:
852847

853848
// store the location of the punctuation
854-
unsigned char mem49 = X;
849+
unsigned char punctuation = X;
855850
A = X;
856851
int Atemp = A;
857852

@@ -866,26 +861,24 @@ void AddInflection(sam_memory* sam, unsigned char mem48, unsigned char phase1)
866861
while( (A=sam->render.pitch[X]) == 127) X++;
867862

868863

869-
pos48398:
870-
//48398: CLC
871-
//48399: ADC 48
872-
873-
// add the inflection direction
874-
A += mem48;
875-
phase1 = A;
876-
877-
// set the inflection
878-
sam->render.pitch[X] = A;
879-
pos48406:
880-
881-
// increment the position
882-
X++;
883-
884-
// exit if the punctuation has been reached
885-
if (X == mem49) return; //goto pos47615;
886-
if (sam->render.pitch[X] == 255) goto pos48406;
887-
A = phase1;
888-
goto pos48398;
864+
while(1) {
865+
866+
// add the inflection direction
867+
A += mem48;
868+
phase1 = A;
869+
870+
// set the inflection
871+
sam->render.pitch[X] = A;
872+
do {
873+
874+
// increment the position
875+
X++;
876+
877+
// exit if the punctuation has been reached
878+
if (X == punctuation) return; //goto pos47615;
879+
} while (sam->render.pitch[X] == 255);
880+
A = phase1;
881+
}
889882
}
890883

891884
static inline unsigned char trans(unsigned char mem39212, unsigned char mem39213) {

source/lib/sam/render.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
void Render(sam_memory* sam);
77
void SetMouthThroat(unsigned char mouth, unsigned char throat);
8+
void OutputFrames(sam_memory *sam, unsigned char frame_count);
89

910
/** Scaling c64 rate to sample rate */
1011
// Rate for 22.05kHz

source/lib/sam/sam.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,7 @@ void AdjustLengths(sam_memory* sam)
13231323
//DEBUG: printf("phoneme %d (%c%c) length %d\n", X, signInputTable1[sam->prepare.phoneme_input[X].index], signInputTable2[sam->prepare.phoneme_input[X].index], sam->prepare.phoneme_input[X].length);
13241324
//DEBUG: printf("phoneme %d (%c%c) length %d\n", X-1, signInputTable1[sam->prepare.phoneme_input[X-1].index], signInputTable2[sam->prepare.phoneme_input[X-1].index], sam->prepare.phoneme_input[X-1].length);
13251325
// X gets overwritten, so hold prior X value for debug statement
1326-
int debugX = X;
1326+
// int debugX = X;
13271327
// shorten the prior phoneme length to (length/2 + 1)
13281328
sam->prepare.phoneme_input[X].length = (sam->prepare.phoneme_input[X].length >> 1) + 1;
13291329
X = loopIndex;

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