Commit graph

153 commits

Author SHA1 Message Date
William Hubbs
0471ff47f4 add support for the user_data parameter to espeak_synth
The user_data parameter is just a pointer that is passed into the
espeak_synth call that is passed back to the callback.  In native mode,
we are not using it since there is not a callback.  However, in alsa
mode, it will be used to indicate when a cancel was processed.
2009-06-26 11:34:28 -05:00
William Hubbs
520bbae365 renamed stopped to stop_requested
This is more descriptive of what the variable actually does.  It signals
the callback to stop the audio.
2009-06-26 10:03:11 -05:00
William Hubbs
8f3e8f1967 moved the audio_mutex code to alsa
This is not needed for native sound support, so it has been moved into
the alsa specific code.
2009-06-26 09:50:11 -05:00
William Hubbs
e49acbb59a removed a debug print 2009-06-25 22:03:57 -05:00
William Hubbs
24bcdf5666 another termination fix
espeak_thread needs to signal softsynth_thread once more as it is going
town so that softsynth_thread will see that should_run is now 0 and
terminate.
2009-06-25 22:00:25 -05:00
William Hubbs
5ec3809c59 wake up espeak_thread when softsynth_thread terminates
espeak_thread needs a signal since it might be sleeping and
should_run has changed.  This makes sure it terminates.
2009-06-25 21:17:34 -05:00
William Hubbs
5ebe506026 more mutex fixes
Make sure that should_run is protected by the mutex in the softsynth
thread.
2009-06-25 21:07:24 -05:00
Chris Brannon
d5fd5d69b8 don't wait on a condition variable if should_run is false 2009-06-25 20:39:35 -05:00
William Hubbs
633743117c mutex fixes
We need to make sure that should_run is protected by the mutex.
2009-06-25 20:24:34 -05:00
William Hubbs
1750b92cfb fixed signal handling issue
The signal handler stopped working after I moved the initialization
calls to the main function.  Creating the signal handler thread first
fixed this issue.
2009-06-25 20:04:42 -05:00
William Hubbs
eb74a3ce17 removed an unnecessary call to espeak_Terminate() 2009-06-25 18:45:37 -05:00
William Hubbs
dd00775695 initialization update
The main function now initializes espeak and opens the softsynth before
starting the threads.  This insures that the resources we need are
active.
2009-06-25 18:30:36 -05:00
William Hubbs
6a15f2cccf fixed first wait in softsynth thread
The thread should wait if there is nothing in the queue and if there is
not a request to stop.
Thanks to Chris Brannon for the patch.
2009-06-25 18:17:14 -05:00
William Hubbs
3687f16b09 wait for acknowledgements correctly
pthread_cond_wait() can have spurious wakeups, so we need to be sure
that the condition is actually true when we return from this function.
Thanks to Chris Brannon for the patch.
2009-06-25 17:05:51 -05:00
William Hubbs
938e10b66a removed a nested lock/unlock 2009-06-25 14:36:25 -05:00
William Hubbs
975765289b made sure all cond_wait and cond_signal calls are inside lock/unlock
calls
2009-06-25 14:17:21 -05:00
William Hubbs
b8c7247feb removed acknowledge_guard and substituted queue_guard 2009-06-25 14:05:36 -05:00
William Hubbs
1091182f88 removed a debug print call 2009-06-25 12:57:29 -05:00
William Hubbs
0bf2cae5a6 moved lock/unlock in queue_process_entry
The only time queue_process_entry should lock the queue gard is when it
is removing the item from the queue.  This happens only when the item
was successfully processed.
2009-06-25 12:06:51 -05:00
William Hubbs
554a03d26c white space fix 2009-06-25 12:06:33 -05:00
Christopher Brannon
b7f324072f Fix concurrency bugs.
1. Don't lock or unlock queue_guard during queue_clear.
It is locked when queue_clear is called, and it should remain so.
2. Protect runner_must_stop with queue_guard in
the request_espeak_stop function.
The following condition should always hold: queue_guard is locked while
testing or modifying runner_must_stop.
3. Rename stop_guard to acknowledge_guard.  This is a more
descriptive name.  This mutex simply protects the acknowledgement of
the stop request from being lost.
4. Remove the pthread_mutex_lock from the top of queue_process_entry,
because queue_guard is already locked when the function is called.
2009-06-25 11:56:20 -05:00
William Hubbs
a8cad20de8 more multithreading work
Rearranged the queue handling code so that queue.c is generic.  Also
rearranged several functions in the threads.
2009-06-25 09:05:21 -05:00
William Hubbs
42c3f76a08 moved include for pthread.h to espeakup.h 2009-06-25 01:21:44 -05:00
William Hubbs
3e8e7d12ae added back the declaration for softFD 2009-06-24 22:44:18 -05:00
William Hubbs
af5717b8cb moved queue_add_xxx functions to softsynth thread 2009-06-24 22:23:10 -05:00
William Hubbs
c6b57885c9 removed declaration of rate from main 2009-06-24 22:22:34 -05:00
Christopher Brannon
d82bfcd09c Make one thread responsible for handling espeak interaction.
Most of the idea for this change came from William:
Renamed queue_runner to espeak_thread.  Moved espeak initialization
and termination to espeak_thread.  The while loops that process
the queue now use the variable should_run.
2009-06-24 22:11:52 -05:00
William Hubbs
0fdca827b8 check for terminalFD after select()
If terminalFD has something to read, we break out of the loop in the
softsynth thread.
2009-06-24 21:29:46 -05:00
William Hubbs
474580b08b add pipe to wake up the softsynth thread
This adds a pipe to wake up the softsynth thread, in case we receive a
signal while it is in a select.  Thanks to Chris Brannon.
2009-06-24 21:16:30 -05:00
William Hubbs
c5fce64f25 removed open_softsynth and close_softsynth
The thread can now handle the softsynth device, so main doesn't need to
call these functions.
2009-06-24 20:44:42 -05:00
William Hubbs
a58f93cd74 renamed reader_thread to softsynth_thread 2009-06-24 20:19:24 -05:00
William Hubbs
dfc9bbff65 fixed should_run declaration
Removed the local declaration of should_run and set up the extern.
2009-06-24 20:12:15 -05:00
William Hubbs
9d1cabdd0d started work on multi-threading more of the program
The goal is to create threads for the reader, que runner/espeak
processing and signal handling.
As of this commit, this code is still being worked on, so it is broken.
2009-06-24 20:03:31 -05:00
William Hubbs
f58d9984ce Now the queue runner/softsynth handler clears the queue
Thanks to Chris Brannon for the patch.
2009-06-24 16:59:23 -05:00
William Hubbs
24e7d667bc queue fixes
This adds retry processing back to the queue functions.  queue_remove
should only be called after the head entry on the queue is processed
successfully.
2009-06-23 20:34:04 -05:00
William Hubbs
26ab109bd8 moved the check for stop out of the loop
In the callback, we should check to see if the stopped flag is true
whether or not we are processing audio.
2009-06-23 16:13:52 -05:00
William Hubbs
b108764b02 removed the audio_callback variable 2009-06-23 11:02:09 -05:00
Christopher Brannon
739d79cff8 Select audio mode before initializing espeak. 2009-06-23 10:48:56 -05:00
Christopher Brannon
ec9d8b1ee2 Add error-checking to the snd_pcm_set_* calls.
These can fail.  They do more than simply manipulate a structure.
2009-06-22 23:05:07 -05:00
Christopher Brannon
a5d1a48f42 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.
2009-06-22 22:32:27 -05:00
William Hubbs
3bb78df86c Do not set the period. 2009-06-22 21:36:31 -05:00
William Hubbs
94e23a3a02 fixed error condition check in alsa.c
The check was looking for a specific error when it should have been just
checking for failure.
2009-06-22 20:44:42 -05:00
William Hubbs
a69342fcad removed some blank lines and put the variables at the top of the file 2009-06-22 19:09:07 -05:00
Christopher Brannon
91b8960b6a Protect the stopped variable with a mutex.
An oversight.  Should have done this in the initial commit.
volatile does not imply atomic.
2009-06-21 14:36:13 -05:00
William Hubbs
0ad70b4eaa Revert "fixed stop_speech issue"
This reverts commit 1c440e5a42.
2009-06-20 19:14:42 -05:00
William Hubbs
1d02169aa5 alsa support is conditional
This commit updates the makefile and the documentation to explain how to
build alsa support.  It has not been fully tested, so it is not built by
default.  Also, I was able to remove the conditional compile directives
from the source.
2009-06-20 16:46:50 -05:00
William Hubbs
1c440e5a42 fixed stop_speech issue
The stop_speech function needs to test the return code from
espeak_Cancel() to be sure the operation was successful before
signaling the callback to stop the audio.
2009-06-20 16:17:42 -05:00
William Hubbs
08e46c58a8 indentation fixes 2009-06-20 13:09:57 -05:00
Christopher Brannon
d373fb2aa7 An initial stab at ALSA support.
It's very raw right now.
2009-06-19 15:11:51 -05:00
William Hubbs
b31985f97c released v0.71 v0.71 2009-05-30 12:44:33 -05:00