mirror of
https://github.com/linux-speakup/espeakup.git
synced 2026-08-23 16:14:17 +02:00
moved queue_add_xxx functions to softsynth thread
This commit is contained in:
parent
c6b57885c9
commit
af5717b8cb
3 changed files with 49 additions and 50 deletions
14
espeakup.h
14
espeakup.h
|
|
@ -43,6 +43,15 @@ enum adjust_t {
|
|||
ADJ_INC,
|
||||
};
|
||||
|
||||
struct queue_entry_t {
|
||||
enum command_t cmd;
|
||||
enum adjust_t adjust;
|
||||
int value;
|
||||
char *buf;
|
||||
int len;
|
||||
struct queue_entry_t *next;
|
||||
};
|
||||
|
||||
struct synth_t {
|
||||
int frequency;
|
||||
int pitch;
|
||||
|
|
@ -57,10 +66,9 @@ struct synth_t {
|
|||
extern int debug;
|
||||
|
||||
extern void process_cli(int argc, char **argv);
|
||||
extern void queue_add(struct queue_entry_t *entry);
|
||||
extern void queue_remove(void);
|
||||
extern void queue_clear(void);
|
||||
extern void queue_add_cmd(enum command_t cmd, enum adjust_t adj,
|
||||
int value);
|
||||
extern void queue_add_text(char *txt, size_t length);
|
||||
extern espeak_ERROR set_frequency(struct synth_t *s, int freq,
|
||||
enum adjust_t adj);
|
||||
extern espeak_ERROR set_pitch(struct synth_t *s, int pitch,
|
||||
|
|
|
|||
49
queue.c
49
queue.c
|
|
@ -38,20 +38,11 @@ pthread_cond_t stop_acknowledged = PTHREAD_COND_INITIALIZER;
|
|||
pthread_mutex_t queue_guard = PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_mutex_t stop_guard = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
struct queue_entry_t {
|
||||
enum command_t cmd;
|
||||
enum adjust_t adjust;
|
||||
int value;
|
||||
char *buf;
|
||||
int len;
|
||||
struct queue_entry_t *next;
|
||||
};
|
||||
|
||||
volatile int runner_must_stop = 0;
|
||||
static struct queue_entry_t *first = NULL;
|
||||
static struct queue_entry_t *last = NULL;
|
||||
|
||||
static void queue_add(struct queue_entry_t *entry)
|
||||
void queue_add(struct queue_entry_t *entry)
|
||||
{
|
||||
pthread_mutex_lock(&queue_guard);
|
||||
assert(entry);
|
||||
|
|
@ -78,7 +69,7 @@ static void free_entry(struct queue_entry_t *entry)
|
|||
/* Remove and return the entry at the head of the queue.
|
||||
* Return NULL if queue is empty. */
|
||||
|
||||
static void queue_remove(void)
|
||||
void queue_remove(void)
|
||||
{
|
||||
struct queue_entry_t *temp;
|
||||
|
||||
|
|
@ -102,42 +93,6 @@ void queue_clear(void)
|
|||
/* We aren't adding data to the queue, so no need to signal. */
|
||||
}
|
||||
|
||||
void queue_add_cmd(enum command_t cmd, enum adjust_t adj, int value)
|
||||
{
|
||||
struct queue_entry_t *entry;
|
||||
|
||||
entry = malloc(sizeof(struct queue_entry_t));
|
||||
if (!entry) {
|
||||
perror("unable to allocate memory for queue entry");
|
||||
return;
|
||||
}
|
||||
entry->cmd = cmd;
|
||||
entry->adjust = adj;
|
||||
entry->value = value;
|
||||
queue_add(entry);
|
||||
}
|
||||
|
||||
void queue_add_text(char *txt, size_t length)
|
||||
{
|
||||
struct queue_entry_t *entry;
|
||||
|
||||
entry = malloc(sizeof(struct queue_entry_t));
|
||||
if (!entry) {
|
||||
perror("unable to allocate memory for queue entry");
|
||||
return;
|
||||
}
|
||||
entry->cmd = CMD_SPEAK_TEXT;
|
||||
entry->adjust = ADJ_SET;
|
||||
entry->buf = strdup(txt);
|
||||
if (!entry->buf) {
|
||||
perror("unable to allocate space for text");
|
||||
free(entry);
|
||||
return;
|
||||
}
|
||||
entry->len = length;
|
||||
queue_add(entry);
|
||||
}
|
||||
|
||||
static void queue_process_entry(struct synth_t *s)
|
||||
{
|
||||
espeak_ERROR error;
|
||||
|
|
|
|||
36
softsynth.c
36
softsynth.c
|
|
@ -33,6 +33,42 @@ const size_t maxBufferSize = 1025;
|
|||
/* synth flush character */
|
||||
const int synthFlushChar = 0x18;
|
||||
|
||||
static void queue_add_cmd(enum command_t cmd, enum adjust_t adj, int value)
|
||||
{
|
||||
struct queue_entry_t *entry;
|
||||
|
||||
entry = malloc(sizeof(struct queue_entry_t));
|
||||
if (!entry) {
|
||||
perror("unable to allocate memory for queue entry");
|
||||
return;
|
||||
}
|
||||
entry->cmd = cmd;
|
||||
entry->adjust = adj;
|
||||
entry->value = value;
|
||||
queue_add(entry);
|
||||
}
|
||||
|
||||
static void queue_add_text(char *txt, size_t length)
|
||||
{
|
||||
struct queue_entry_t *entry;
|
||||
|
||||
entry = malloc(sizeof(struct queue_entry_t));
|
||||
if (!entry) {
|
||||
perror("unable to allocate memory for queue entry");
|
||||
return;
|
||||
}
|
||||
entry->cmd = CMD_SPEAK_TEXT;
|
||||
entry->adjust = ADJ_SET;
|
||||
entry->buf = strdup(txt);
|
||||
if (!entry->buf) {
|
||||
perror("unable to allocate space for text");
|
||||
free(entry);
|
||||
return;
|
||||
}
|
||||
entry->len = length;
|
||||
queue_add(entry);
|
||||
}
|
||||
|
||||
static int process_command(struct synth_t *s, char *buf, int start)
|
||||
{
|
||||
char *cp;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue