Skip to content

Commit 1261d55

Browse files
markshannonntoll
authored andcommitted
Speech: Reduce memory use for phonemes. Saves about 300 bytes of heap.
1 parent 874b652 commit 1261d55

File tree

5 files changed

+186
-177
lines changed

5 files changed

+186
-177
lines changed

source/lib/sam/debug.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#include<stdio.h>
2+
#include "sam.h"
23

34
extern unsigned char signInputTable1[];
45
extern unsigned char signInputTable2[];
56

6-
void PrintPhonemes(unsigned char *phonemeindex, unsigned char *phonemeLength, unsigned char *stress)
7+
void PrintPhonemes(phoneme_t *phonemes)
78
{
89
int i = 0;
910
printf("===========================================\n");
@@ -12,20 +13,20 @@ void PrintPhonemes(unsigned char *phonemeindex, unsigned char *phonemeLength, un
1213
printf(" idx phoneme length stress\n");
1314
printf("------------------------------\n");
1415

15-
while((phonemeindex[i] != 255) && (i < 255))
16+
while((phonemes[i].index != PHONEME_END) && (i < 255))
1617
{
17-
if (phonemeindex[i] < 81)
18+
if (phonemes[i].index < 81)
1819
{
1920
printf(" %3i %c%c %3i %i\n",
20-
phonemeindex[i],
21-
signInputTable1[phonemeindex[i]],
22-
signInputTable2[phonemeindex[i]],
23-
phonemeLength[i],
24-
stress[i]
21+
phonemes[i].index,
22+
signInputTable1[phonemes[i].index],
23+
signInputTable2[phonemes[i].index],
24+
phonemes[i].length,
25+
phonemes[i].stress
2526
);
2627
} else
2728
{
28-
printf(" %3i ?? %3i %i\n", phonemeindex[i], phonemeLength[i], stress[i]);
29+
printf(" %3i ?? %3i %i\n", phonemes[i].index, phonemes[i].length, phonemes[i].stress);
2930
}
3031
i++;
3132
}

source/lib/sam/debug.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#ifndef DEBUG_H
22
#define DEBUG_H
33

4-
void PrintPhonemes(unsigned char *phonemeindex, unsigned char *phonemeLength, unsigned char *stress);
4+
#include "sam.h"
5+
6+
void PrintPhonemes(phoneme_t *phonemes);
57
void PrintOutput(
68
unsigned char *flag,
79
unsigned char *f1,

source/lib/sam/render.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ void Render(sam_memory* sam)
335335
unsigned char mem44 = 0;
336336
int i;
337337
int carry;
338-
if (sam->common.phonemeIndexOutput[0] == 255) return; //exit if no data
338+
if (sam->common.phoneme_output[0].index == PHONEME_END) return; //exit if no data
339339

340340
A = 0;
341341
X = 0;
@@ -355,11 +355,11 @@ do
355355
// get the index
356356
Y = mem44;
357357
// get the phoneme at the index
358-
A = sam->common.phonemeIndexOutput[mem44];
358+
A = sam->common.phoneme_output[mem44].index;
359359
mem56 = A;
360360

361361
// if terminal phoneme, exit the loop
362-
if (A == 255) break;
362+
if (A == PHONEME_END) break;
363363

364364
// period phoneme *.
365365
if (A == 1)
@@ -384,10 +384,10 @@ do
384384
// pos47615:
385385

386386
// get the stress amount (more stress = higher pitch)
387-
phase1 = tab47492[sam->common.stressOutput[Y] + 1];
387+
phase1 = tab47492[sam->common.phoneme_output[Y].stress + 1];
388388

389389
// get number of frames to write
390-
phase2 = sam->common.phonemeLengthOutput[Y];
390+
phase2 = sam->common.phoneme_output[Y].length;
391391
Y = mem56;
392392

393393
// copy from the source to the frames list
@@ -547,12 +547,12 @@ do
547547
while(1) //while No. 1
548548
{
549549
// get the current and following phoneme
550-
Y = sam->common.phonemeIndexOutput[X];
551-
A = sam->common.phonemeIndexOutput[X+1];
550+
Y = sam->common.phoneme_output[X].index;
551+
A = sam->common.phoneme_output[X+1].index;
552552
X++;
553553

554554
// exit loop at end token
555-
if (A == 255) break;//goto pos47970;
555+
if (A == PHONEME_END) break;//goto pos47970;
556556

557557

558558
// get the ranking of each phoneme
@@ -581,7 +581,7 @@ do
581581
}
582582

583583
Y = mem44;
584-
A = mem49 + sam->common.phonemeLengthOutput[mem44]; // A is mem49 + length
584+
A = mem49 + sam->common.phoneme_output[mem44].length; // A is mem49 + length
585585
mem49 = A; // mem49 now holds length + position
586586
A = A + phase2; //Maybe Problem because of carry flag
587587

@@ -619,9 +619,9 @@ do
619619

620620
unsigned char mem36, mem37;
621621
// half the width of the current phoneme
622-
mem36 = sam->common.phonemeLengthOutput[mem44] >> 1;
622+
mem36 = sam->common.phoneme_output[mem44].length >> 1;
623623
// half the width of the next phoneme
624-
mem37 = sam->common.phonemeLengthOutput[mem44+1] >> 1;
624+
mem37 = sam->common.phoneme_output[mem44+1].length >> 1;
625625
// sum the values
626626
mem40 = mem36 + mem37; // length of both halves
627627
mem37 += mem49; // center of next phoneme
@@ -695,7 +695,7 @@ do
695695
//pos47970:
696696

697697
// add the length of this phoneme
698-
mem48 = mem49 + sam->common.phonemeLengthOutput[mem44];
698+
mem48 = mem49 + sam->common.phoneme_output[mem44].length;
699699

700700

701701
// ASSIGN PITCH CONTOUR

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