Browse Source

Protect against wvoice being NULL in wavegen.c.

This can occur in cases where the voice is not found, or
espeak_ng_Initialize is called more than once.
master
Reece H. Dunn 9 years ago
parent
commit
371216006f
1 changed files with 30 additions and 6 deletions
  1. 30
    6
      src/libespeak-ng/wavegen.c

+ 30
- 6
src/libespeak-ng/wavegen.c View File



#define N_WAV_BUF 10 #define N_WAV_BUF 10


voice_t *wvoice; voice_t *wvoice = NULL;


FILE *f_log = NULL; FILE *f_log = NULL;
static int option_harmonic1 = 10; static int option_harmonic1 = 10;


static void WavegenSetEcho(void) static void WavegenSetEcho(void)
{ {
if (wvoice == NULL)
return;

int delay; int delay;
int amp; int amp;




int PeaksToHarmspect(wavegen_peaks_t *peaks, int pitch, int *htab, int control) int PeaksToHarmspect(wavegen_peaks_t *peaks, int pitch, int *htab, int control)
{ {
if (wvoice == NULL)
return 1;

// Calculate the amplitude of each harmonics from the formants // Calculate the amplitude of each harmonics from the formants
// Only for formants 0 to 5 // Only for formants 0 to 5


int h1; int h1;


// initialise as much of *out as we will need // initialise as much of *out as we will need
if (wvoice == NULL)
return 1;
hmax = (peaks[wvoice->n_harmonic_peaks].freq + peaks[wvoice->n_harmonic_peaks].right)/pitch; hmax = (peaks[wvoice->n_harmonic_peaks].freq + peaks[wvoice->n_harmonic_peaks].right)/pitch;
if (hmax >= MAX_HARMONIC) if (hmax >= MAX_HARMONIC)
hmax = MAX_HARMONIC-1; hmax = MAX_HARMONIC-1;
static void AdvanceParameters() static void AdvanceParameters()
{ {
// Called every 64 samples to increment the formant freq, height, and widths // Called every 64 samples to increment the formant freq, height, and widths
if (wvoice == NULL)
return;


int x; int x;
int ix; int ix;
{ {
int pk; int pk;


if (wvoice->breath[0] == 0) if (wvoice == NULL || wvoice->breath[0] == 0)
return; return;


for (pk = 1; pk < N_PEAKS; pk++) { for (pk = 1; pk < N_PEAKS; pk++) {


static int ApplyBreath(void) static int ApplyBreath(void)
{ {
if (wvoice == NULL)
return 0;

int value = 0; int value = 0;
int noise; int noise;
int ix; int ix;


int Wavegen() int Wavegen()
{ {
if (wvoice == NULL)
return 0;

unsigned short waveph; unsigned short waveph;
unsigned short theta; unsigned short theta;
int total; int total;


static void SetPitchFormants() static void SetPitchFormants()
{ {
if (wvoice == NULL)
return;

int ix; int ix;
int factor = 256; int factor = 256;
int pitch_value; int pitch_value;


static void SetAmplitude(int length, unsigned char *amp_env, int value) static void SetAmplitude(int length, unsigned char *amp_env, int value)
{ {
if (wvoice == NULL)
return;

amp_ix = 0; amp_ix = 0;
if (length == 0) if (length == 0)
amp_inc = 0; amp_inc = 0;


void SetPitch(int length, unsigned char *env, int pitch1, int pitch2) void SetPitch(int length, unsigned char *env, int pitch1, int pitch2)
{ {
if (wvoice == NULL)
return;

// length in samples // length in samples


if ((wdata.pitch_env = env) == NULL) if ((wdata.pitch_env = env) == NULL)


void SetSynth(int length, int modn, frame_t *fr1, frame_t *fr2, voice_t *v) void SetSynth(int length, int modn, frame_t *fr1, frame_t *fr2, voice_t *v)
{ {
if (wvoice == NULL || v == NULL)
return;

int ix; int ix;
DOUBLEX next; DOUBLEX next;
int length2; int length2;
// Pick up next wavegen commands from the queue // Pick up next wavegen commands from the queue
// return: 0 output buffer has been filled // return: 0 output buffer has been filled
// return: 1 input command queue is now empty // return: 1 input command queue is now empty

intptr_t *q; intptr_t *q;
int length; int length;
int result; int result;
SetEmbedded(q[1], q[2]); SetEmbedded(q[1], q[2]);
break; break;
case WCMD_MBROLA_DATA: case WCMD_MBROLA_DATA:
result = MbrolaFill(length, resume, (general_amplitude * wvoice->voicing)/64); if (wvoice != NULL)
result = MbrolaFill(length, resume, (general_amplitude * wvoice->voicing)/64);
break; break;
case WCMD_FMT_AMPLITUDE: case WCMD_FMT_AMPLITUDE:
if ((wdata.amplitude_fmt = q[1]) == 0) if ((wdata.amplitude_fmt = q[1]) == 0)

Loading…
Cancel
Save