Skip to content

Commit

Permalink
add output hooks for wavegen
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Platen committed Jul 7, 2020
1 parent 22a3043 commit a6dbed8
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/include/espeak-ng/espeak_ng.h
Expand Up @@ -77,6 +77,14 @@ typedef enum {
ENGENDER_NEUTRAL = 3,
} espeak_ng_VOICE_GENDER;

typedef struct
{
void (*outputPhoSymbol)(char* pho_code,int pho_type);
void (*outputSilence)(short echo_tail);
void (*outputVoiced)(short sample);
void (*outputUnvoiced)(short sample);
} espeak_ng_OUTPUT_HOOKS;

/* eSpeak NG 1.49.0 */

typedef struct espeak_ng_ERROR_CONTEXT_ *espeak_ng_ERROR_CONTEXT;
Expand Down Expand Up @@ -188,6 +196,12 @@ espeak_ng_CompilePhonemeDataPath(long rate,
const char *destination_path,
FILE *log,
espeak_ng_ERROR_CONTEXT *context);

ESPEAK_NG_API espeak_ng_STATUS
espeak_ng_SetOutputHooks(espeak_ng_OUTPUT_HOOKS* hooks);
ESPEAK_NG_API espeak_ng_STATUS
espeak_ng_SetConstF0(int f0);


#ifdef __cplusplus
}
Expand Down
18 changes: 18 additions & 0 deletions src/libespeak-ng/synthesize.c
Expand Up @@ -146,6 +146,14 @@ static void DoAmplitude(int amp, unsigned char *amp_env)
WcmdqInc();
}

static void DoPhonemeAlignment(char* pho, int type)
{
wcmdq[wcmdq_tail][0] = WCMD_PHONEME_ALIGNMENT;
wcmdq[wcmdq_tail][1] = pho;
wcmdq[wcmdq_tail][2] = type;
WcmdqInc();
}

static void DoPitch(unsigned char *env, int pitch1, int pitch2)
{
intptr_t *q;
Expand Down Expand Up @@ -1131,6 +1139,8 @@ void DoEmbedded(int *embix, int sourceix)
} while ((word & 0x80) == 0);
}

extern espeak_ng_OUTPUT_HOOKS* output_hooks;

int Generate(PHONEME_LIST *phoneme_list, int *n_ph, bool resume)
{
static int ix;
Expand Down Expand Up @@ -1187,6 +1197,14 @@ int Generate(PHONEME_LIST *phoneme_list, int *n_ph, bool resume)

while ((ix < (*n_ph)) && (ix < N_PHONEME_LIST-2)) {
p = &phoneme_list[ix];

if(output_hooks && output_hooks->outputPhoSymbol)
{
char buf[30];
int dummy=0;
WritePhMnemonic(buf, p->ph, p, 0, &dummy);
DoPhonemeAlignment(strdup(buf),p->type);
}

if (p->type == phPAUSE)
free_min = 10;
Expand Down
1 change: 1 addition & 0 deletions src/libespeak-ng/synthesize.h
Expand Up @@ -433,6 +433,7 @@ extern unsigned char pitch_adjust_tab[MAX_PITCH_VALUE+1];
#define WCMD_MBROLA_DATA 13
#define WCMD_FMT_AMPLITUDE 14
#define WCMD_SONIC_SPEED 15
#define WCMD_PHONEME_ALIGNMENT 16

#define N_WCMDQ 170
#define MIN_WCMDQ 25 // need this many free entries before adding new phoneme
Expand Down
36 changes: 36 additions & 0 deletions src/libespeak-ng/wavegen.c
Expand Up @@ -116,6 +116,9 @@ unsigned char *out_ptr;
unsigned char *out_start;
unsigned char *out_end;

espeak_ng_OUTPUT_HOOKS* output_hooks = NULL;
int const_f0 = 0;

// the queue of operations passed to wavegen from sythesize
intptr_t wcmdq[N_WCMDQ][4];
int wcmdq_head = 0;
Expand Down Expand Up @@ -545,6 +548,8 @@ static void AdvanceParameters()
if ((ix = wdata.pitch_ix>>8) > 127) ix = 127;
x = wdata.pitch_env[ix] * wdata.pitch_range;
wdata.pitch = (x>>8) + wdata.pitch_base;



amp_ix += amp_inc;

Expand All @@ -554,6 +559,10 @@ static void AdvanceParameters()
x = ((int)(Flutter_tab[Flutter_ix >> 6])-0x80) * flutter_amp;
Flutter_ix += Flutter_inc;
wdata.pitch += x;

if(const_f0)
wdata.pitch = (const_f0<<12);

if (wdata.pitch < 102400)
wdata.pitch = 102400; // min pitch, 25 Hz (25 << 12)

Expand Down Expand Up @@ -884,6 +893,7 @@ static int Wavegen()
}
*out_ptr++ = z;
*out_ptr++ = z >> 8;
if(output_hooks && output_hooks->outputVoiced) output_hooks->outputVoiced(z);

echo_buf[echo_head++] = z;
if (echo_head >= N_ECHO_BUF)
Expand Down Expand Up @@ -917,6 +927,7 @@ static int PlaySilence(int length, bool resume)

*out_ptr++ = value;
*out_ptr++ = value >> 8;
if(output_hooks && output_hooks->outputSilence) output_hooks->outputSilence(value);

echo_buf[echo_head++] = value;
if (echo_head >= N_ECHO_BUF)
Expand Down Expand Up @@ -969,6 +980,7 @@ static int PlayWave(int length, bool resume, unsigned char *data, int scale, int

out_ptr[0] = value;
out_ptr[1] = value >> 8;
if(output_hooks && output_hooks->outputUnvoiced) output_hooks->outputUnvoiced(value);
out_ptr += 2;

echo_buf[echo_head++] = (value*3)/4;
Expand Down Expand Up @@ -1284,6 +1296,13 @@ static int WavegenFill2()
case WCMD_PITCH:
SetPitch(length, (unsigned char *)q[2], q[3] >> 16, q[3] & 0xffff);
break;
case WCMD_PHONEME_ALIGNMENT:
{
char* data = (char*)q[1];
output_hooks->outputPhoSymbol(data,q[2]);
free(data);
}
break;
case WCMD_PAUSE:
if (resume == false)
echo_complete -= length;
Expand Down Expand Up @@ -1418,3 +1437,20 @@ int WavegenFill(void)
#endif
return finished;
}

#pragma GCC visibility push(default)

ESPEAK_NG_API espeak_ng_STATUS
espeak_ng_SetOutputHooks(espeak_ng_OUTPUT_HOOKS* hooks)
{
output_hooks = hooks;
return 0;
}

ESPEAK_NG_API espeak_ng_STATUS
espeak_ng_SetConstF0(int f0)
{
const_f0 = f0;
}

#pragma GCC visibility pop

0 comments on commit a6dbed8

Please sign in to comment.