Browse Source

Combine wave_init and wave_open.

master
Reece H. Dunn 9 years ago
parent
commit
843f4d0dd4

+ 2
- 5
src/libespeak-ng/speak_lib.c View File

@@ -108,12 +108,12 @@ static int dispatch_audio(short *outbuf, int length, espeak_EVENT *event)
sleep(1);
}
out_samplerate = voice_samplerate;
if (!wave_init(voice_samplerate)) {
my_audio = wave_open(voice_samplerate);
if (!my_audio) {
err = EE_INTERNAL_ERROR;
return -1;
}
wave_set_callback_is_output_enabled(fifo_is_command_enabled);
my_audio = wave_open();
event_init();
}
}
@@ -216,9 +216,6 @@ static void select_output(espeak_AUDIO_OUTPUT output_type)
switch (my_mode)
{
case AUDIO_OUTPUT_PLAYBACK:
// wave_init() is now called just before the first wave_write()
synchronous_mode = 0;
break;
case AUDIO_OUTPUT_RETRIEVAL:
synchronous_mode = 0;
break;

+ 11
- 30
src/libespeak-ng/wave.c View File

@@ -65,12 +65,11 @@ enum { ONE_BILLION = 1000000000 };
#ifdef USE_PULSEAUDIO
// create some wrappers for runtime detection

// checked on wave_init
// checked on wave_open
static int pulse_running;

// wave.cpp (this file)
int wave_port_init(int);
void *wave_port_open();
void *wave_port_open(int);
size_t wave_port_write(void *theHandler, char *theMono16BitsWaveBuffer, size_t theSize);
int wave_port_close(void *theHandler);
int wave_port_is_busy(void *theHandler);
@@ -84,8 +83,7 @@ int wave_port_get_remaining_time(uint32_t sample, uint32_t *time);

// wave_pulse.cpp
int is_pulse_running();
int wave_pulse_init(int);
void *wave_pulse_open();
void *wave_pulse_open(int);
size_t wave_pulse_write(void *theHandler, char *theMono16BitsWaveBuffer, size_t theSize);
int wave_pulse_close(void *theHandler);
int wave_pulse_is_busy(void *theHandler);
@@ -98,22 +96,12 @@ void *wave_pulse_test_get_write_buffer();
int wave_pulse_get_remaining_time(uint32_t sample, uint32_t *time);

// wrappers
int wave_init(int srate)
{
pulse_running = is_pulse_running();

if (pulse_running)
return wave_pulse_init(srate);
else
return wave_port_init(srate);
}

void *wave_open()
void *wave_open(int srate)
{
if (pulse_running)
return wave_pulse_open();
return wave_pulse_open(srate);
else
return wave_port_open();
return wave_port_open(srate);
}

size_t wave_write(void *theHandler, char *theMono16BitsWaveBuffer, size_t theSize)
@@ -197,7 +185,6 @@ int wave_get_remaining_time(uint32_t sample, uint32_t *time)
}

// rename functions to be wrapped
#define wave_init wave_port_init
#define wave_open wave_port_open
#define wave_write wave_port_write
#define wave_close wave_port_close
@@ -580,7 +567,7 @@ void wave_set_callback_is_output_enabled(t_wave_callback *cb)
my_callback_is_output_enabled = cb;
}

int wave_init(int srate)
void *wave_open(int srate)
{
PaError err;

@@ -592,17 +579,16 @@ int wave_init(int srate)
// PortAudio sound output library
err = Pa_Initialize();
pa_init_err = err;
return err == paNoError;
}
if (err != paNoError)
return NULL;

void *wave_open()
{
static int once = 0;

if (!once) {
select_device();
once = 1;
}

return (void *)1;
}

@@ -861,15 +847,10 @@ void *wave_test_get_write_buffer()

#else

int wave_init(int srate)
void *wave_open(int srate)
{
(void)srate; // unused

return 1;
}

void *wave_open()
{
return (void *)1;
}


+ 1
- 2
src/libespeak-ng/wave.h View File

@@ -31,8 +31,7 @@ extern "C"

extern int option_device_number;

extern int wave_init(int samplerate);
extern void *wave_open();
extern void *wave_open(int samplerate);

extern size_t wave_write(void *theHandler, char *theMono16BitsWaveBuffer, size_t theSize);
extern int wave_close(void *theHandler);

+ 4
- 12
src/libespeak-ng/wave_pulse.c View File

@@ -71,7 +71,6 @@ static t_wave_callback *my_callback_is_output_enabled = NULL;

#ifdef USE_PORTAUDIO
// rename functions to be wrapped
#define wave_init wave_pulse_init
#define wave_open wave_pulse_open
#define wave_write wave_pulse_write
#define wave_close wave_pulse_close
@@ -525,16 +524,14 @@ void wave_set_callback_is_output_enabled(t_wave_callback *cb)
my_callback_is_output_enabled = cb;
}

int wave_init(int srate)
void *wave_open(int srate)
{
stream = NULL;
wave_samplerate = srate;

return pulse_open() == PULSE_OK;
}
if (pulse_open() != PULSE_OK)
return NULL;

void *wave_open()
{
return (void *)1;
}

@@ -676,15 +673,10 @@ void *wave_test_get_write_buffer()

#else

int wave_init(int srate)
void *wave_open(int srate)
{
(void)srate; // unused

return 1;
}

void *wave_open()
{
return (void *)1;
}


+ 8
- 34
src/libespeak-ng/wave_sada.c View File

@@ -63,7 +63,7 @@ static uint32_t last_play_position = 0;

static uint32_t wave_samplerate;

// wave_init
// wave_open
//
// DESCRIPTION:
//
@@ -74,7 +74,7 @@ static uint32_t wave_samplerate;
// sun_audio_fd: modified to hold the file descriptor of the opened
// audio device.
//
int wave_init(int srate)
void *wave_open(int srate)
{
audio_info_t ainfo;
char *audio_device = NULL;
@@ -84,20 +84,20 @@ int wave_init(int srate)
audio_device = getenv("AUDIODEV");
if (audio_device != NULL) {
if ((sun_audio_fd = open(audio_device, O_WRONLY)) < 0) {
fprintf(stderr, "wave_init() could not open: %s (%d)\n",
fprintf(stderr, "wave_open() could not open: %s (%d)\n",
audio_device, sun_audio_fd);
}
}

if (sun_audio_fd < 0) {
if ((sun_audio_fd = open(sun_audio_device, O_WRONLY)) < 0) {
fprintf(stderr, "wave_init() could not open: %s (%d)\n",
fprintf(stderr, "wave_open() could not open: %s (%d)\n",
sun_audio_device, sun_audio_fd);
}
}

if (sun_audio_fd < 0)
return 0;
return NULL;

ioctl(sun_audio_fd, AUDIO_GETINFO, &ainfo);
ainfo.play.encoding = AUDIO_ENCODING_LINEAR;
@@ -106,32 +106,11 @@ int wave_init(int srate)
ainfo.play.precision = SAMPLE_SIZE;

if (ioctl(sun_audio_fd, AUDIO_SETINFO, &ainfo) == -1) {
fprintf(stderr, "wave_init() failed to set audio params: %s\n", strerror(errno));
fprintf(stderr, "wave_open() failed to set audio params: %s\n", strerror(errno));
close(sun_audio_fd);
return 0;
return NULL;
}
return 1;
}

// wave_open
//
// DESCRIPTION:
//
// opens the audio subsystem. We just return the sun_audio_fd we
// opened in wave_init. This return value will be passed in as the
// theHandler parameter in all other methods.
//
// GLOBALS USED/MODIFIED:
//
// sun_audio_fd: used as return value
//
// RETURNS:
//
// sun_audio_fd opened in wave_init, which is passed in as theHandler
// parameter in all other methods
//
void *wave_open()
{
return (void *)sun_audio_fd;
}

@@ -458,15 +437,10 @@ int wave_get_remaining_time(uint32_t sample, uint32_t *time)

#else

int wave_init(int srate)
void *wave_open(int srate)
{
(void)srate; // unused

return 1;
}

void *wave_open()
{
return (void *)1;
}


Loading…
Cancel
Save