2 ===================================================================
3 --- flite-1.2-release/configure (.../flite-1.2-orig) (revision 10)
4 +++ flite-1.2-release/configure (.../release-v1.2) (revision 10)
5 @@ -1415,16 +1415,16 @@
9 -ac_safe=`echo "sys/asoundlib.h" | sed 'y%./+-%__p_%'`
10 -echo $ac_n "checking for sys/asoundlib.h""... $ac_c" 1>&6
11 -echo "configure:1421: checking for sys/asoundlib.h" >&5
12 +ac_safe=`echo "alsa/asoundlib.h" | sed 'y%./+-%__p_%'`
13 +echo $ac_n "checking for alsa/asoundlib.h""... $ac_c" 1>&6
14 +echo "configure:1421: checking for alsa/asoundlib.h" >&5
15 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
16 echo $ac_n "(cached) $ac_c" 1>&6
18 cat > conftest.$ac_ext <<EOF
19 #line 1426 "configure"
21 -#include <sys/asoundlib.h>
22 +#include <alsa/asoundlib.h>
24 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
25 { (eval echo configure:1431: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
26 @@ -1445,23 +1445,24 @@
27 echo "$ac_t""yes" 1>&6
29 AUDIODEFS=-DCST_AUDIO_ALSA
35 ac_safe=`echo "mmsystem.h" | sed 'y%./+-%__p_%'`
36 echo $ac_n "checking for mmsystem.h""... $ac_c" 1>&6
37 -echo "configure:1455: checking for mmsystem.h" >&5
38 +echo "configure:1456: checking for mmsystem.h" >&5
39 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
40 echo $ac_n "(cached) $ac_c" 1>&6
42 cat > conftest.$ac_ext <<EOF
43 -#line 1460 "configure"
44 +#line 1461 "configure"
48 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
49 -{ (eval echo configure:1465: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
50 +{ (eval echo configure:1466: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
51 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
52 if test -z "$ac_err"; then
54 Index: include/cst_sts.h
55 ===================================================================
56 --- flite-1.2-release/include/cst_sts.h (.../flite-1.2-orig) (revision 10)
57 +++ flite-1.2-release/include/cst_sts.h (.../release-v1.2) (revision 10)
59 /* else where, this information plus the indexes in the Unit relation */
60 /* allow reconstruction of the signal itself */
61 struct cst_sts_struct {
62 - const unsigned short *frame;
63 - const int size; /* in samples */
64 - const unsigned char *residual;
65 + unsigned short *frame;
66 + int size; /* in samples */
67 + unsigned char *residual;
69 typedef struct cst_sts_struct cst_sts;
72 ===================================================================
73 --- flite-1.2-release/configure.in (.../flite-1.2-orig) (revision 10)
74 +++ flite-1.2-release/configure.in (.../release-v1.2) (revision 10)
76 AC_CHECK_HEADER(sys/audioio.h,
78 AUDIODEFS=-DCST_AUDIO_SUNOS])
79 -AC_CHECK_HEADER(sys/asoundlib.h,
80 +AC_CHECK_HEADER(alsa/asoundlib.h,
82 - AUDIODEFS=-DCST_AUDIO_ALSA])
83 + AUDIODEFS=-DCST_AUDIO_ALSA
84 + AUDIOLIBS=-lasound])
85 AC_CHECK_HEADER(mmsystem.h,
87 AUDIODEFS=-DCST_AUDIO_WINCE
88 Index: src/audio/au_alsa.c
89 ===================================================================
90 --- flite-1.2-release/src/audio/au_alsa.c (.../flite-1.2-orig) (revision 10)
91 +++ flite-1.2-release/src/audio/au_alsa.c (.../release-v1.2) (revision 10)
94 /* Language Technologies Institute */
95 /* Carnegie Mellon University */
96 -/* Copyright (c) 2001 */
97 +/* Copyright (c) 2000 */
98 /* All Rights Reserved. */
100 /* Permission is hereby granted, free of charge, to use and distribute */
101 @@ -29,158 +29,283 @@
102 /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
105 +/*********************************************************************** */
106 +/* Author: Lukas Loehrer ( */
107 +/* Date: January 2005 */
108 /*************************************************************************/
109 -/* Author: Geoff Harrison (mandrake@cepstral.com) */
110 -/* Date: Sepetember 2001 */
111 -/*************************************************************************/
113 -/* Access to ALSA audio devices */
115 +/* Native access to alsa audio devices on Linux */
116 +/* Tested with libasound version 1.0.10 */
117 /*************************************************************************/
122 #include <sys/types.h>
126 #include "cst_string.h"
127 #include "cst_wave.h"
128 #include "cst_audio.h"
130 -#include <sys/asoundlib.h>
131 +#include <alsa/asoundlib.h>
133 -#include <sys/stat.h>
136 -static int alsa_card = 0, alsa_device = 0;
137 +/*static char *pcm_dev_name = "hw:0,0"; */
138 +static char *pcm_dev_name ="default";
140 +static inline void print_pcm_state(snd_pcm_t *handle, char *msg)
142 + fprintf(stderr, "PCM state at %s = %s\n", msg,
143 + snd_pcm_state_name(snd_pcm_state(handle)));
146 cst_audiodev *audio_open_alsa(int sps, int channels, cst_audiofmt fmt)
148 - snd_pcm_channel_info_t pinfo;
149 - snd_pcm_channel_params_t params;
150 - snd_pcm_channel_setup_t setup;
155 + unsigned int real_rate;
159 - if (snd_pcm_open_preferred(&pcm,&alsa_card,&alsa_device,SND_PCM_OPEN_PLAYBACK) < 0)
161 - cst_errmsg("alsa_audio: failed to open audio device\n");
164 - if (snd_pcm_plugin_set_disable(pcm,PLUGIN_DISABLE_MMAP) < 0)
166 - cst_errmsg("alsa_audio: failed to disable mmap\n");
167 - snd_pcm_close(pcm);
171 - if (snd_pcm_open(&pcm,alsa_card,alsa_device,SND_PCM_OPEN_PLAYBACK) < 0)
173 - cst_errmsg("alsa_audio: failed to open audio device\n");
177 + /* alsa specific stuff */
178 + snd_pcm_t *pcm_handle;
179 + snd_pcm_stream_t stream = SND_PCM_STREAM_PLAYBACK;
180 + snd_pcm_hw_params_t *hwparams;
181 + snd_pcm_format_t format;
182 + snd_pcm_access_t access = SND_PCM_ACCESS_RW_INTERLEAVED;
184 + /* Allocate the snd_pcm_hw_params_t structure on the stack. */
185 + snd_pcm_hw_params_alloca(&hwparams);
187 - memset(&pinfo, 0, sizeof(pinfo));
188 - memset(¶ms, 0, sizeof(params));
189 - memset(&setup, 0, sizeof(setup));
190 + /* Open pcm device */
191 + err = snd_pcm_open(&pcm_handle, pcm_dev_name, stream, 0);
194 + cst_errmsg("audio_open_alsa: failed to open audio device %s. %s\n",
195 + pcm_dev_name, snd_strerror(err));
199 - pinfo.channel = SND_PCM_CHANNEL_PLAYBACK;
200 - snd_pcm_plugin_info(pcm,&pinfo);
201 + /* Init hwparams with full configuration space */
202 + err = snd_pcm_hw_params_any(pcm_handle, hwparams);
205 + snd_pcm_close(pcm_handle);
206 + cst_errmsg("audio_open_alsa: failed to get hardware parameters from audio device. %s\n", snd_strerror(err));
210 - params.mode = SND_PCM_MODE_BLOCK;
211 - params.channel = SND_PCM_CHANNEL_PLAYBACK;
212 - params.start_mode = SND_PCM_START_DATA;
213 - params.stop_mode = SND_PCM_STOP_STOP;
214 + /* Set access mode */
215 + err = snd_pcm_hw_params_set_access(pcm_handle, hwparams, access);
218 + snd_pcm_close(pcm_handle);
219 + cst_errmsg("audio_open_alsa: failed to set access mode. %s.\n", snd_strerror(err));
223 - params.buf.block.frag_size = pinfo.max_fragment_size;
224 - params.buf.block.frags_max = 1;
225 - params.buf.block.frags_min = 1;
227 - params.format.interleave = 1;
228 - params.format.rate = sps;
229 - params.format.voices = channels;
233 - case CST_AUDIO_LINEAR16:
234 + /* Determine matching alsa sample format */
235 + /* This could be implemented in a more */
236 + /* flexible way (byte order conversion). */
239 + case CST_AUDIO_LINEAR16:
240 if (CST_LITTLE_ENDIAN)
241 - params.format.format = SND_PCM_SFMT_S16_LE;
242 + format = SND_PCM_FORMAT_S16_LE;
244 - params.format.format = SND_PCM_SFMT_S16_BE;
245 + format = SND_PCM_FORMAT_S16_BE;
247 - case CST_AUDIO_LINEAR8:
248 - params.format.format = SND_PCM_SFMT_U8;
249 + case CST_AUDIO_LINEAR8:
250 + format = SND_PCM_FORMAT_U8;
252 - case CST_AUDIO_MULAW:
253 - params.format.format = SND_PCM_SFMT_MU_LAW;
254 + case CST_AUDIO_MULAW:
255 + format = SND_PCM_FORMAT_MU_LAW;
259 + snd_pcm_close(pcm_handle);
260 + cst_errmsg("audio_open_alsa: failed to find suitable format.\n");
265 - if((err = snd_pcm_plugin_params(pcm,¶ms)) < 0)
267 - cst_errmsg("alsa_audio params setting failed: %s\n",snd_strerror(err));
268 - snd_pcm_close(pcm);
271 - if((err = snd_pcm_plugin_setup(pcm,SND_PCM_CHANNEL_PLAYBACK)) > 0) {
272 - cst_errmsg("alsa_audio sound prepare setting failed: %s\n",snd_strerror(err));
273 - snd_pcm_close(pcm);
276 - if((err = snd_pcm_plugin_prepare(pcm,SND_PCM_CHANNEL_PLAYBACK)) > 0) {
277 - cst_errmsg("alsa_audio sound prepare setting failed: %s\n",snd_strerror(err));
278 - snd_pcm_close(pcm);
281 + /* Set samble format */
282 + err = snd_pcm_hw_params_set_format(pcm_handle, hwparams, format);
285 + snd_pcm_close(pcm_handle);
286 + cst_errmsg("audio_open_alsa: failed to set format. %s.\n", snd_strerror(err));
290 - pinfo.channel = SND_PCM_CHANNEL_PLAYBACK;
291 - snd_pcm_plugin_info(pcm,&pinfo);
292 + /* Set sample rate near the disired rate */
294 + err = snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams, &real_rate, 0);
297 + snd_pcm_close(pcm_handle);
298 + cst_errmsg("audio_open_alsa: failed to set sample rate near %d. %s.\n", sps, snd_strerror(err));
301 + /*FIXME: This is probably too strict */
302 + assert(sps == real_rate);
304 - ad = cst_alloc(cst_audiodev, 1);
305 - ad->platform_data = pcm;
306 - ad->sps = ad->real_sps = sps;
307 - ad->channels = ad->real_channels = channels;
308 - ad->fmt = ad->real_fmt = fmt;
309 + /* Set number of channels */
310 + assert(channels >0);
311 + err = snd_pcm_hw_params_set_channels(pcm_handle, hwparams, channels);
314 + snd_pcm_close(pcm_handle);
315 + cst_errmsg("audio_open_alsa: failed to set number of channels to %d. %s.\n", channels, snd_strerror(err));
320 + /* Commit hardware parameters */
321 + err = snd_pcm_hw_params(pcm_handle, hwparams);
324 + snd_pcm_close(pcm_handle);
325 + cst_errmsg("audio_open_alsa: failed to set hw parameters. %s.\n", snd_strerror(err));
329 + /* Make sure the device is ready to accept data */
330 + assert(snd_pcm_state(pcm_handle) == SND_PCM_STATE_PREPARED);
332 + /* Write hardware parameters to flite audio device data structure */
333 + ad = cst_alloc(cst_audiodev, 1);
334 + assert(ad != NULL);
335 + ad->real_sps = ad->sps = sps;
336 + ad->real_channels = ad->channels = channels;
337 + ad->real_fmt = ad->fmt = fmt;
338 + ad->platform_data = (void *) pcm_handle;
343 int audio_close_alsa(cst_audiodev *ad)
347 + snd_pcm_t *pcm_handle;
354 - pcm = ad->platform_data;
355 - snd_pcm_plugin_flush(pcm,0);
356 - snd_pcm_close(pcm);
358 + pcm_handle = (snd_pcm_t *) ad->platform_data;
359 + result = snd_pcm_close(pcm_handle);
362 + cst_errmsg("audio_close_alsa: Error: %s.\n", snd_strerror(result));
369 +/* Returns zero if recovery was successful. */
370 +static int recover_from_error(snd_pcm_t *pcm_handle, ssize_t res)
372 + if (res == -EPIPE) /* xrun */
374 + res = snd_pcm_prepare(pcm_handle);
377 + /* Failed to recover from xrun */
378 + cst_errmsg("recover_from_write_error: failed to recover from xrun. %s\n.", snd_strerror(res));
382 + else if (res == -ESTRPIPE) /* Suspend */
384 + while ((res = snd_pcm_resume(pcm_handle)) == -EAGAIN)
386 + snd_pcm_wait(pcm_handle, 1000);
390 + res = snd_pcm_prepare(pcm_handle);
393 + /* Resume failed */
394 + cst_errmsg("audio_recover_from_write_error: failed to resume after suspend. %s\n.", snd_strerror(res));
401 + /* Unknown failure */
402 + cst_errmsg("audio_recover_from_write_error: %s.\n", snd_strerror(res));
408 int audio_write_alsa(cst_audiodev *ad, void *samples, int num_bytes)
410 - snd_pcm_t *pcm = ad->platform_data;
412 + ssize_t num_frames, res;
413 + snd_pcm_t *pcm_handle;
414 + char *buf = (char *) samples;
416 - return snd_pcm_plugin_write(pcm,samples,num_bytes);
417 + /* Determine frame size in bytes */
418 + frame_size = audio_bps(ad->real_fmt) * ad->real_channels;
419 + /* Require that only complete frames are handed in */
420 + assert((num_bytes % frame_size) == 0);
421 + num_frames = num_bytes / frame_size;
422 + pcm_handle = (snd_pcm_t *) ad->platform_data;
424 + while (num_frames > 0)
426 + res = snd_pcm_writei(pcm_handle, buf, num_frames);
427 + if (res != num_frames)
429 + if (res == -EAGAIN || (res > 0 && res < num_frames))
431 + snd_pcm_wait(pcm_handle, 100);
433 + else if (recover_from_error(pcm_handle, res) < 0)
442 + buf += res * frame_size;
448 int audio_flush_alsa(cst_audiodev *ad)
450 - snd_pcm_t *pcm = ad->platform_data;
452 - return snd_pcm_plugin_flush(pcm,0);
454 + result = snd_pcm_drain((snd_pcm_t *) ad->platform_data);
457 + cst_errmsg("audio_flush_alsa: Error: %s.\n", snd_strerror(result));
459 + /* Prepare device for more data */
460 + result = snd_pcm_prepare((snd_pcm_t *) ad->platform_data);
463 + cst_errmsg("audio_flush_alsa: Error: %s.\n", snd_strerror(result));
468 int audio_drain_alsa(cst_audiodev *ad)
470 - snd_pcm_t *pcm = ad->platform_data;
472 - return snd_pcm_plugin_playback_drain(pcm);
474 + result = snd_pcm_drop((snd_pcm_t *) ad->platform_data);
477 + cst_errmsg("audio_drain_alsa: Error: %s.\n", snd_strerror(result));
479 +/* Prepare device for more data */
480 + result = snd_pcm_prepare((snd_pcm_t *) ad->platform_data);
483 + cst_errmsg("audio_drain_alsa: Error: %s.\n", snd_strerror(result));
489 ===================================================================
490 --- flite-1.2-release/doc/Makefile (.../flite-1.2-orig) (revision 10)
491 +++ flite-1.2-release/doc/Makefile (.../release-v1.2) (revision 10)
493 @ if [ ! -d html ] ; \
494 then mkdir -p html ; fi
495 (cd html; texi2html -number -split_chapter ../flite.texi)
496 + mv html/flite/*.html html/ && rmdir html/flite
497 @ for i in html/*.html ; \
499 sed 's/<BODY>/<BODY bgcolor="#ffffff">/' $$i >ttt.html; \
500 Index: config/common_make_rules
501 ===================================================================
502 --- flite-1.2-release/config/common_make_rules (.../flite-1.2-orig) (revision 10)
503 +++ flite-1.2-release/config/common_make_rules (.../release-v1.2) (revision 10)
505 @ rm -rf shared_os && mkdir shared_os
506 @ rm -f $@ $(LIBDIR)/$@.${PROJECT_VERSION} $(LIBDIR)/$@.${PROJECT_SHLIB_VERSION}
507 @ (cd shared_os && ar x ../$<)
508 - @ (cd shared_os && $(CC) -shared -Wl,-soname,$@.${PROJECT_SHLIB_VERSION} -o ../$@.${PROJECT_VERSION} *.os)
509 + @ (cd shared_os && $(CC) -shared -Wl,-soname,$@.${PROJECT_SHLIB_VERSION} -o ../$@.${PROJECT_VERSION} *.os $(AUDIOLIBS))
510 @ ln -s $(LIBDIR)/$@.${PROJECT_VERSION} $(LIBDIR)/$@.${PROJECT_SHLIB_VERSION}
511 @ ln -s $(LIBDIR)/$@.${PROJECT_SHLIB_VERSION} $(LIBDIR)/$@