Commit graph

179 commits

Author SHA1 Message Date
William Hubbs
32d848cb76 make callback honor should_run
The callback should return and abort synthesis if should_run is 0.  This
fixes slow shutdown times in alsa mode.
2009-07-01 12:22:14 -05:00
William Hubbs
4de82bf24c added a couple of #defines to the alsa code 2009-06-30 21:32:52 -05:00
William Hubbs
739e074072 reworked the queue_remove function
Now, when queue_remove is called, it returns the pointer to the data of
the first entry in the queue and removes the entry.
2009-06-30 20:15:20 -05:00
William Hubbs
014d27b7aa removed some unlock_audio_mutex() calls 2009-06-30 19:15:44 -05:00
William Hubbs
82490a98d2 call snd_pcm_prepare after snd_pcm_drop in stop_audio 2009-06-30 15:54:52 -05:00
William Hubbs
101e14901e removed white space in the makefile 2009-06-30 13:21:52 -05:00
William Hubbs
dc056e6c77 broke the queue definitions out into their own header file 2009-06-30 13:08:07 -05:00
William Hubbs
0a9a8cce9b small style changes 2009-06-30 08:15:27 -05:00
Christopher Brannon
40479540b4 Fix a memory leak.
If we fail to add entries to the queue in queue_add_cmd or
queue_add_text, properly free the entry.
2009-06-29 18:42:25 -05:00
William Hubbs
ccb8cea91e stop speech before clearing the queue
Thanks to Kirk Reiser for pointing out that this makes the cancel
response faster.
2009-06-29 18:12:04 -05:00
Christopher Brannon
31ad5f04ca Completely data-agnostic queue functions.
The functions in queue.c no longer use static variables.  We can now use
them for multiple queues, if necessary.
2009-06-29 18:07:18 -05:00
Christopher Brannon
011ec27162 Create pipe before starting the signal handler thread.
The thread can write to the pipe, so the pipe must be initialized
before the thread starts.
2009-06-29 17:49:49 -05:00
William Hubbs
04d10d88ec more sound updates
removed the user_data processing code and put the call to snd_pcm_drop
in stop_audio.
2009-06-29 17:48:16 -05:00
William Hubbs
ceaae3640a audio should be stopped in softsynth_thread not espeak_thread 2009-06-29 15:59:55 -05:00
William Hubbs
c9f871f687 see if we need to silence speech before we process the queue 2009-06-29 15:26:48 -05:00
William Hubbs
a82bbd8140 fixed a memory leak
If we processed an entry from the queue successfully, we were removing
the entry itself from the queue but not freeing the memory allocated to
the entry.
2009-06-28 17:56:21 -05:00
William Hubbs
58f09983f8 fixed callback return code
The callback should use the value of stop_requested as its return code.
2009-06-28 15:52:59 -05:00
William Hubbs
0238baa5c2 more alsa updates
Made an 'if' statement in the callback more clear and added some locking
for the audio mutex.
2009-06-28 13:52:31 -05:00
William Hubbs
bcd64cb263 created a start_audio function
This moves audio control to the specific files, espeak_sound.c and
alsa.c, which are tied to the sound systems.
2009-06-27 17:49:57 -05:00
William Hubbs
9b7dcebb6d alsa updates
The first while loop in the callback doesn't need to be a loop.  If the
audio fails, we can just print an error and return.
2009-06-27 17:10:10 -05:00
William Hubbs
46bf3d99d5 all access of the audio mutex should go through our functions 2009-06-27 16:05:27 -05:00
William Hubbs
87ab6c6ea8 make sure that snd_pcm_drop is successful.
This was suggested by Kirk Reiser and Chris Brannon.
2009-06-27 13:32:43 -05:00
William Hubbs
4889572ad1 use user_data to detect old events
When espeak_Cancel is called, change the value of user_data that is
passed to the events, and, in the callback, use this to test to see if
cancel was received.  If the value of user_data has changed, discarde
events that have the old value.  This patch is from Chris Brannon.
2009-06-27 13:20:43 -05:00
William Hubbs
a9398bdeb4 Added another error check for alsa 2009-06-26 23:11:15 -05:00
William Hubbs
be879d206b alsa update
I changed the name of the callback to alsa_callback and removed a line
that was making the amount of data written to the sound card very small.
2009-06-26 16:12:31 -05:00
William Hubbs
c1d33d6738 Set the espeak audio buffer size to 50 ms
This should help make the cancel command more responsive.
2009-06-26 16:00:08 -05:00
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