Browse Source

code cleanup: pass WGEN_DATA wdata as a parameter instead of using a global

Contributes to #68.
master
Juho Hiltunen 5 years ago
parent
commit
1b7c3303ef
3 changed files with 20 additions and 21 deletions
  1. 18
    19
      src/libespeak-ng/klatt.c
  2. 1
    1
      src/libespeak-ng/klatt.h
  3. 1
    1
      src/libespeak-ng/wavegen.c

+ 18
- 19
src/libespeak-ng/klatt.c View File

extern unsigned char *out_ptr; extern unsigned char *out_ptr;
extern unsigned char *out_start; extern unsigned char *out_start;
extern unsigned char *out_end; extern unsigned char *out_end;
extern WGEN_DATA wdata;
static int nsamples; static int nsamples;
static int sample_count; static int sample_count;


Converts synthesis parameters to a waveform. Converts synthesis parameters to a waveform.
*/ */


static int parwave(klatt_frame_ptr frame)
static int parwave(klatt_frame_ptr frame, WGEN_DATA *wdata)
{ {
double temp; double temp;
int value; int value;
out = outbypas - out; out = outbypas - out;


out = resonator(&(kt_globals.rsn[Rout]), out); out = resonator(&(kt_globals.rsn[Rout]), out);
temp = (int)(out * wdata.amplitude * kt_globals.amp_gain0); // Convert back to integer
temp = (int)(out * wdata->amplitude * kt_globals.amp_gain0); // Convert back to integer


// mix with a recorded WAV if required for this phoneme // mix with a recorded WAV if required for this phoneme
signed char c; signed char c;
int sample; int sample;


if (wdata.mix_wavefile_ix < wdata.n_mix_wavefile) {
if (wdata.mix_wave_scale == 0) {
if (wdata->mix_wavefile_ix < wdata->n_mix_wavefile) {
if (wdata->mix_wave_scale == 0) {
// a 16 bit sample // a 16 bit sample
c = wdata.mix_wavefile[wdata.mix_wavefile_ix+1];
sample = wdata.mix_wavefile[wdata.mix_wavefile_ix] + (c * 256);
wdata.mix_wavefile_ix += 2;
c = wdata->mix_wavefile[wdata->mix_wavefile_ix+1];
sample = wdata->mix_wavefile[wdata->mix_wavefile_ix] + (c * 256);
wdata->mix_wavefile_ix += 2;
} else { } else {
// a 8 bit sample, scaled // a 8 bit sample, scaled
sample = (signed char)wdata.mix_wavefile[wdata.mix_wavefile_ix++] * wdata.mix_wave_scale;
sample = (signed char)wdata->mix_wavefile[wdata->mix_wavefile_ix++] * wdata->mix_wave_scale;
} }
int z2 = sample * wdata.amplitude_v / 1024;
z2 = (z2 * wdata.mix_wave_amp)/40;
int z2 = sample * wdata->amplitude_v / 1024;
z2 = (z2 * wdata->mix_wave_amp)/40;
temp += z2; temp += z2;
} }


static double klattp1[N_KLATTP]; static double klattp1[N_KLATTP];
static double klattp_inc[N_KLATTP]; static double klattp_inc[N_KLATTP];


int Wavegen_Klatt(int length, int resume, frame_t *fr1, frame_t *fr2)
int Wavegen_Klatt(int length, int resume, frame_t *fr1, frame_t *fr2, WGEN_DATA *wdata)
{ {
if (resume == 0) if (resume == 0)
SetSynth_Klatt(length, fr1, fr2, wvoice, 1); SetSynth_Klatt(length, fr1, fr2, wvoice, 1);
sample_count = 0; sample_count = 0;


while (sample_count < nsamples) { while (sample_count < nsamples) {
kt_frame.F0hz10 = (wdata.pitch * 10) / 4096;
kt_frame.F0hz10 = (wdata->pitch * 10) / 4096;


// formants F6,F7,F8 are fixed values for cascade resonators, set in KlattInit() // formants F6,F7,F8 are fixed values for cascade resonators, set in KlattInit()
// but F6 is used for parallel resonator // but F6 is used for parallel resonator
} }


// advance the pitch // advance the pitch
wdata.pitch_ix += wdata.pitch_inc;
if ((ix = wdata.pitch_ix>>8) > 127) ix = 127;
x = wdata.pitch_env[ix] * wdata.pitch_range;
wdata.pitch = (x>>8) + wdata.pitch_base;
wdata->pitch_ix += wdata->pitch_inc;
if ((ix = wdata->pitch_ix>>8) > 127) ix = 127;
x = wdata->pitch_env[ix] * wdata->pitch_range;
wdata->pitch = (x>>8) + wdata->pitch_base;


kt_globals.nspfr = (nsamples - sample_count); kt_globals.nspfr = (nsamples - sample_count);
if (kt_globals.nspfr > STEPSIZE) if (kt_globals.nspfr > STEPSIZE)


frame_init(&kt_frame); // get parameters for next frame of speech frame_init(&kt_frame); // get parameters for next frame of speech


if (parwave(&kt_frame) == 1)
if (parwave(&kt_frame, wdata) == 1)
return 1; // output buffer is full return 1; // output buffer is full
} }


end_wave = 0; end_wave = 0;
sample_count -= fade; sample_count -= fade;
kt_globals.nspfr = fade; kt_globals.nspfr = fade;
if (parwave(&kt_frame) == 1)
if (parwave(&kt_frame, wdata) == 1)
return 1; // output buffer is full return 1; // output buffer is full
} }



+ 1
- 1
src/libespeak-ng/klatt.h View File



void KlattInit(void); void KlattInit(void);
void KlattReset(int control); void KlattReset(int control);
int Wavegen_Klatt(int length, int resume, frame_t *fr1, frame_t *fr2);
int Wavegen_Klatt(int length, int resume, frame_t *fr1, frame_t *fr2, WGEN_DATA *wdata);


#ifdef __cplusplus #ifdef __cplusplus
} }

+ 1
- 1
src/libespeak-ng/wavegen.c View File

wdata.n_mix_wavefile = 0; // ... and drop through to WCMD_SPECT case wdata.n_mix_wavefile = 0; // ... and drop through to WCMD_SPECT case
case WCMD_KLATT: case WCMD_KLATT:
echo_complete = echo_length; echo_complete = echo_length;
result = Wavegen_Klatt(length & 0xffff, resume, (frame_t *)q[2], (frame_t *)q[3]);
result = Wavegen_Klatt(length & 0xffff, resume, (frame_t *)q[2], (frame_t *)q[3], &wdata);
break; break;
#endif #endif
case WCMD_MARKER: case WCMD_MARKER:

Loading…
Cancel
Save