mirror of
https://github.com/linux-speakup/espeakup.git
synced 2026-08-09 09:19:09 +02:00
Obtain sample rate from the value of espeak_Initialize.
espeak uses a sample rate of 22050 HZ, but let's not rely on that knowledge. espeak_Initialize returns the sample rate on success, so rely on that value when selecting a rate.
This commit is contained in:
parent
3bb78df86c
commit
a5d1a48f42
4 changed files with 14 additions and 11 deletions
6
alsa.c
6
alsa.c
|
|
@ -35,7 +35,6 @@ static pthread_mutex_t audio_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|||
static snd_pcm_t *handle;
|
||||
static snd_pcm_hw_params_t *params;
|
||||
snd_pcm_status_t *status;
|
||||
static unsigned int rate = 22050; /* sample rate */
|
||||
static int dir = 0;
|
||||
|
||||
void lock_audio_mutex(void)
|
||||
|
|
@ -95,12 +94,10 @@ static int alsa_play_callback(short *audio, int numsamples,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int init_audio(void)
|
||||
int init_audio(unsigned int rate)
|
||||
{
|
||||
int rc;
|
||||
unsigned saved_rate;
|
||||
|
||||
rate = 22050;
|
||||
|
||||
/* Open PCM device for playback. */
|
||||
rc = snd_pcm_open(&handle, "default", SND_PCM_STREAM_PLAYBACK, 0);
|
||||
|
|
@ -141,7 +138,6 @@ int init_audio(void)
|
|||
/* One channel */
|
||||
snd_pcm_hw_params_set_channels(handle, params, 1);
|
||||
|
||||
saved_rate = rate;
|
||||
snd_pcm_hw_params_set_rate_near(handle, params, &rate, &dir);
|
||||
|
||||
/* Write the parameters to the driver */
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#include "espeakup.h"
|
||||
int init_audio(void)
|
||||
int init_audio(unsigned int rate)
|
||||
{
|
||||
audio_mode = AUDIO_OUTPUT_PLAYBACK;
|
||||
audio_callback = NULL;
|
||||
|
|
|
|||
15
espeakup.c
15
espeakup.c
|
|
@ -95,6 +95,7 @@ void espeakup_sighandler(int sig)
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int rate;
|
||||
pthread_t queue_thread_id;
|
||||
struct synth_t s = {
|
||||
.voice = "",
|
||||
|
|
@ -119,9 +120,6 @@ int main(int argc, char **argv)
|
|||
signal(SIGINT, espeakup_sighandler);
|
||||
signal(SIGTERM, espeakup_sighandler);
|
||||
|
||||
if (init_audio() < 0) {
|
||||
return 5;
|
||||
}
|
||||
|
||||
if (!debug) {
|
||||
/* become a daemon */
|
||||
|
|
@ -135,7 +133,16 @@ int main(int argc, char **argv)
|
|||
}
|
||||
|
||||
/* initialize espeak */
|
||||
espeak_Initialize(audio_mode, 0, NULL, 0);
|
||||
rate = espeak_Initialize(audio_mode, 0, NULL, 0);
|
||||
if (rate < 0) {
|
||||
fprintf(stderr, "Unable to initialize espeak.\n");
|
||||
return 5;
|
||||
}
|
||||
|
||||
if (init_audio((unsigned int) rate) < 0) {
|
||||
return 6;
|
||||
}
|
||||
|
||||
espeak_SetSynthCallback(audio_callback);
|
||||
|
||||
/* Setup initial voice parameters */
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ extern int open_softsynth(void);
|
|||
extern void close_softsynth(void);
|
||||
extern void main_loop(struct synth_t *s);
|
||||
extern void *queue_runner(void *arg);
|
||||
extern int init_audio(void);
|
||||
extern int init_audio(unsigned int rate);
|
||||
extern void lock_audio_mutex(void);
|
||||
extern void unlock_audio_mutex(void);
|
||||
extern volatile int stopped;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue