Blame SOURCES/festival-speech-tools-pulse.patch

dd2b13
diff -up festival/lib/init.scm.pulse festival/lib/init.scm
dd2b13
--- festival/lib/init.scm.pulse	2009-09-29 02:05:53.156687751 -0400
dd2b13
+++ festival/lib/init.scm	2009-09-29 02:14:18.911692694 -0400
dd2b13
@@ -77,6 +77,9 @@
dd2b13
 ;;;  Some default parameters
dd2b13
 (Parameter.def 'Wavefiletype 'riff)
dd2b13
 
dd2b13
+;;; default to pulseaudio
dd2b13
+(Parameter.def 'Audio_Method 'pulseaudio)
dd2b13
+
dd2b13
 ;;; Set default audio method
dd2b13
 (cond
dd2b13
  ((member 'nas *modules*)
dd2b13
diff -up festival/speech_tools/audio/audioP.h.pulse festival/speech_tools/audio/audioP.h
dd2b13
--- festival/speech_tools/audio/audioP.h.pulse	2004-07-15 19:03:04.000000000 -0400
dd2b13
+++ festival/speech_tools/audio/audioP.h	2009-09-29 02:05:53.353695375 -0400
dd2b13
@@ -40,6 +40,7 @@
dd2b13
 #define __AUDIOP_H__
dd2b13
 
dd2b13
 int play_nas_wave(EST_Wave &inwave, EST_Option &al);
dd2b13
+int play_pulse_wave(EST_Wave &inwave, EST_Option &al);
dd2b13
 int play_esd_wave(EST_Wave &inwave, EST_Option &al);
dd2b13
 int play_sun16_wave(EST_Wave &inwave, EST_Option &al);
dd2b13
 int play_voxware_wave(EST_Wave &inwave, EST_Option &al);
dd2b13
@@ -49,6 +50,7 @@ int play_irix_wave(EST_Wave &inwave, EST
dd2b13
 int play_macosx_wave(EST_Wave &inwave, EST_Option &al);
dd2b13
 
dd2b13
 int record_nas_wave(EST_Wave &inwave, EST_Option &al);
dd2b13
+int record_pulse_wave(EST_Wave &inwave, EST_Option &al);
dd2b13
 int record_esd_wave(EST_Wave &inwave, EST_Option &al);
dd2b13
 int record_sun16_wave(EST_Wave &inwave, EST_Option &al);
dd2b13
 int record_voxware_wave(EST_Wave &inwave, EST_Option &al);
dd2b13
diff -up festival/speech_tools/audio/gen_audio.cc.pulse festival/speech_tools/audio/gen_audio.cc
dd2b13
--- festival/speech_tools/audio/gen_audio.cc.pulse	2004-09-30 08:53:35.000000000 -0400
dd2b13
+++ festival/speech_tools/audio/gen_audio.cc	2009-09-29 02:05:53.354687890 -0400
dd2b13
@@ -89,6 +89,8 @@ int play_wave(EST_Wave &inwave, EST_Opti
dd2b13
     {
dd2b13
 	if (nas_supported)
dd2b13
 	    protocol = "netaudio";  // the default protocol
dd2b13
+	else if (pulse_supported)
dd2b13
+	    protocol = "pulseaudio";
dd2b13
 	else if (esd_supported)
dd2b13
 	    protocol = "esdaudio";
dd2b13
 	else if (sun16_supported)
dd2b13
@@ -111,6 +113,8 @@ int play_wave(EST_Wave &inwave, EST_Opti
dd2b13
 
dd2b13
     if (upcase(protocol) == "NETAUDIO")
dd2b13
 	return play_nas_wave(*toplay,al);
dd2b13
+    else if (upcase(protocol) == "PULSEAUDIO")
dd2b13
+	return play_pulse_wave(*toplay,al);
dd2b13
     else if (upcase(protocol) == "ESDAUDIO")
dd2b13
 	return play_esd_wave(*toplay,al);
dd2b13
     else if (upcase(protocol) == "SUNAUDIO")
dd2b13
@@ -246,6 +250,8 @@ EST_String options_supported_audio(void)
dd2b13
 	audios += " netaudio";
dd2b13
     else if (esd_supported)
dd2b13
 	audios += " esdaudio";
dd2b13
+    if (pulse_supported)
dd2b13
+	audios += " pulseaudio";
dd2b13
     if (sun16_supported)
dd2b13
 	audios += " sun16audio";
dd2b13
     if (freebsd16_supported)
dd2b13
@@ -286,8 +292,10 @@ int record_wave(EST_Wave &wave, EST_Opti
dd2b13
     {
dd2b13
 	if (nas_supported)
dd2b13
 	    protocol = "netaudio";  // the default protocol
dd2b13
+	else if (pulse_supported)
dd2b13
+	    protocol = "pulseaudio";
dd2b13
 	else if (esd_supported)
dd2b13
-	    protocol = "esdaudio";  // the default protocol
dd2b13
+	    protocol = "esdaudio";
dd2b13
 	else if (sun16_supported)
dd2b13
 	    protocol = "sun16audio";
dd2b13
 	else if (freebsd16_supported)
dd2b13
@@ -306,6 +314,8 @@ int record_wave(EST_Wave &wave, EST_Opti
dd2b13
 
dd2b13
     if (upcase(protocol) == "NETAUDIO")
dd2b13
 	return record_nas_wave(wave,al);
dd2b13
+    else if (upcase(protocol) == "PULSEAUDIO")
dd2b13
+	return record_pulse_wave(wave,al);
dd2b13
     else if (upcase(protocol) == "ESDAUDIO")
dd2b13
         return record_esd_wave(wave,al);
dd2b13
     else if (upcase(protocol) == "SUN16AUDIO")
dd2b13
diff -up festival/speech_tools/audio/Makefile.pulse festival/speech_tools/audio/Makefile
dd2b13
--- festival/speech_tools/audio/Makefile.pulse	2004-07-15 19:03:04.000000000 -0400
dd2b13
+++ festival/speech_tools/audio/Makefile	2009-09-29 02:05:53.355692417 -0400
dd2b13
@@ -44,7 +44,7 @@ LOCAL_DEFAULT_LIBRARY = estbase
dd2b13
 H = audioP.h
dd2b13
 CPPSRCS = gen_audio.cc nas.cc esd.cc sun16audio.cc voxware.cc  \
dd2b13
           mplayer.cc win32audio.cc irixaudio.cc os2audio.cc \
dd2b13
-          macosxaudio.cc
dd2b13
+          macosxaudio.cc pulseaudio.cc
dd2b13
 
dd2b13
 SRCS = $(CPPSRCS)
dd2b13
 OBJS = $(CPPSRCS:.cc=.o)
dd2b13
diff -up /dev/null festival/speech_tools/audio/pulseaudio.cc
dd2b13
--- /dev/null	2009-09-29 00:23:01.118964058 -0400
dd2b13
+++ festival/speech_tools/audio/pulseaudio.cc	2009-09-29 02:05:53.357688202 -0400
dd2b13
@@ -0,0 +1,134 @@
dd2b13
+/*************************************************************************/
dd2b13
+/*                                                                       */
dd2b13
+/*                Centre for Speech Technology Research                  */
dd2b13
+/*                     University of Edinburgh, UK                       */
dd2b13
+/*                      Copyright (c) 1997,1998                          */
dd2b13
+/*                            Red Hat, Inc.                              */
dd2b13
+/*                         Copyright (c) 2008                            */
dd2b13
+/*                        All Rights Reserved.                           */
dd2b13
+/*                                                                       */
dd2b13
+/*  Permission is hereby granted, free of charge, to use and distribute  */
dd2b13
+/*  this software and its documentation without restriction, including   */
dd2b13
+/*  without limitation the rights to use, copy, modify, merge, publish,  */
dd2b13
+/*  distribute, sublicense, and/or sell copies of this work, and to      */
dd2b13
+/*  permit persons to whom this work is furnished to do so, subject to   */
dd2b13
+/*  the following conditions:                                            */
dd2b13
+/*   1. The code must retain the above copyright notice, this list of    */
dd2b13
+/*      conditions and the following disclaimer.                         */
dd2b13
+/*   2. Any modifications must be clearly marked as such.                */
dd2b13
+/*   3. Original authors' names are not deleted.                         */
dd2b13
+/*   4. The authors' names are not used to endorse or promote products   */
dd2b13
+/*      derived from this software without specific prior written        */
dd2b13
+/*      permission.                                                      */
dd2b13
+/*                                                                       */
dd2b13
+/*  THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK        */
dd2b13
+/*  DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING      */
dd2b13
+/*  ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT   */
dd2b13
+/*  SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE     */
dd2b13
+/*  FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES    */
dd2b13
+/*  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN   */
dd2b13
+/*  AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,          */
dd2b13
+/*  ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF       */
dd2b13
+/*  THIS SOFTWARE.                                                       */
dd2b13
+/*                                                                       */
dd2b13
+/*************************************************************************/
dd2b13
+/*                Author :  Michal Schmidt                               */
dd2b13
+/*                Date   :  November 2008                                */
dd2b13
+/*-----------------------------------------------------------------------*/
dd2b13
+/*  Optional support for PulseAudio                                      */
dd2b13
+/*=======================================================================*/
dd2b13
+
dd2b13
+#include "EST_Wave.h"
dd2b13
+#include "EST_Option.h"
dd2b13
+#include "audioP.h"
dd2b13
+
dd2b13
+#ifdef SUPPORT_PULSE
dd2b13
+
dd2b13
+#include <pulse/simple.h>
dd2b13
+#include <pulse/error.h>
dd2b13
+
dd2b13
+int pulse_supported = TRUE;
dd2b13
+const static char *err_prefix = "Pulseaudio: ";
dd2b13
+
dd2b13
+static int transfer_pulse_wave(EST_Wave &inwave, EST_Option &al, int record)
dd2b13
+{
dd2b13
+    short *waveform;
dd2b13
+    int num_samples;
dd2b13
+    int err, pa_ret;
dd2b13
+    int ret = -1;
dd2b13
+    pa_simple *s = NULL;
dd2b13
+    pa_sample_spec ss;
dd2b13
+
dd2b13
+    ss.format   = PA_SAMPLE_S16NE;
dd2b13
+    ss.channels = 1;
dd2b13
+    ss.rate     = inwave.sample_rate();
dd2b13
+
dd2b13
+    waveform    = inwave.values().memory();
dd2b13
+    num_samples = inwave.num_samples();
dd2b13
+
dd2b13
+    s = pa_simple_new(NULL,           // Use the default server.
dd2b13
+	"Festival",                   // Our application's name.
dd2b13
+	record ? PA_STREAM_RECORD : PA_STREAM_PLAYBACK,
dd2b13
+	NULL,                         // Use the default device.
dd2b13
+	record ? "Record" : "Speech", // Description of our stream.
dd2b13
+	&ss,                // Our sample format.
dd2b13
+	NULL,               // Use default channel map
dd2b13
+	NULL,               // Use default buffering attributes.
dd2b13
+	&err;;
dd2b13
+
dd2b13
+    if (!s) {
dd2b13
+	cerr << err_prefix << pa_strerror(err) << endl;
dd2b13
+	goto finish;
dd2b13
+    }
dd2b13
+
dd2b13
+    pa_ret = record ?
dd2b13
+	pa_simple_read (s, waveform, num_samples*sizeof(short), &err) :
dd2b13
+	pa_simple_write(s, waveform, num_samples*sizeof(short), &err;;
dd2b13
+
dd2b13
+    if (pa_ret < 0) {
dd2b13
+	cerr << err_prefix << pa_strerror(err) << endl;
dd2b13
+	goto finish;
dd2b13
+    }
dd2b13
+
dd2b13
+    if (!record && pa_simple_drain(s, &err) < 0) {
dd2b13
+	cerr << err_prefix << pa_strerror(err) << endl;
dd2b13
+	goto finish;
dd2b13
+    }
dd2b13
+
dd2b13
+    ret = 1;
dd2b13
+finish:
dd2b13
+    if (s)
dd2b13
+	pa_simple_free(s);
dd2b13
+    return ret;
dd2b13
+}
dd2b13
+
dd2b13
+int play_pulse_wave(EST_Wave &inwave, EST_Option &al)
dd2b13
+{
dd2b13
+	return transfer_pulse_wave(inwave, al, 0);
dd2b13
+}
dd2b13
+
dd2b13
+int record_pulse_wave(EST_Wave &inwave, EST_Option &al)
dd2b13
+{
dd2b13
+	return transfer_pulse_wave(inwave, al, 1);
dd2b13
+}
dd2b13
+
dd2b13
+#else
dd2b13
+int pulse_supported = FALSE;
dd2b13
+
dd2b13
+int play_pulse_wave(EST_Wave &inwave, EST_Option &al)
dd2b13
+{
dd2b13
+    (void)inwave;
dd2b13
+    (void)al;
dd2b13
+    cerr << "Audio: pulse not compiled in this version" << endl;
dd2b13
+    return -1;
dd2b13
+}
dd2b13
+
dd2b13
+int record_pulse_wave(EST_Wave &inwave, EST_Option &al)
dd2b13
+{
dd2b13
+    (void)inwave;
dd2b13
+    (void)al;
dd2b13
+    cerr << "Audio: pulse not compiled in this version" << endl;
dd2b13
+    return -1;
dd2b13
+}
dd2b13
+
dd2b13
+#endif
dd2b13
diff -up festival/speech_tools/config/config.in.pulse festival/speech_tools/config/config.in
dd2b13
--- festival/speech_tools/config/config.in.pulse	2009-09-29 02:05:53.045693311 -0400
dd2b13
+++ festival/speech_tools/config/config.in	2009-09-29 02:05:53.358687421 -0400
dd2b13
@@ -79,6 +79,9 @@ OPTIMISE_sigpr = 3
dd2b13
 ## NCD's network audio system, This is recommended.
dd2b13
 # INCLUDE_MODULES += NAS_AUDIO
dd2b13
 
dd2b13
+## PulseAudio sound server
dd2b13
+INCLUDE_MODULES += PULSE_AUDIO
dd2b13
+
dd2b13
 ## Elightenment Sound Demon, for KDE etc.
dd2b13
 # INCLUDE_MODULES += ESD_AUDIO
dd2b13
 
dd2b13
diff -up festival/speech_tools/config/modules/Makefile.pulse festival/speech_tools/config/modules/Makefile
dd2b13
--- festival/speech_tools/config/modules/Makefile.pulse	2004-07-15 19:03:05.000000000 -0400
dd2b13
+++ festival/speech_tools/config/modules/Makefile	2009-09-29 02:05:53.359687618 -0400
dd2b13
@@ -41,7 +41,8 @@ RULESETS = efence.mak dmalloc.mak debugg
dd2b13
 	psola_tm.mak editline.mak tcl.mak \
dd2b13
 	freebsd16_audio.mak irix_audio.mak linux16_audio.mak \
dd2b13
 	sun16_audio.mak win32_audio.mak macosx_audio.mak \
dd2b13
-	mplayer_audio.mak nas_audio.mak esd_audio.mak
dd2b13
+	mplayer_audio.mak nas_audio.mak esd_audio.mak \
dd2b13
+	pulse_audio.mak
dd2b13
 
dd2b13
 FILES = Makefile descriptions $(RULESETS) 
dd2b13
 
dd2b13
diff -up /dev/null festival/speech_tools/config/modules/pulse_audio.mak
dd2b13
--- /dev/null	2009-09-29 00:23:01.118964058 -0400
dd2b13
+++ festival/speech_tools/config/modules/pulse_audio.mak	2009-09-29 02:05:53.361688082 -0400
dd2b13
@@ -0,0 +1,9 @@
dd2b13
+## Definitions for PulseAudio
dd2b13
+
dd2b13
+INCLUDE_PULSE_AUDIO=1
dd2b13
+
dd2b13
+MOD_DESC_PULSE_AUDIO=PulseAudio support
dd2b13
+
dd2b13
+AUDIO_DEFINES += -DSUPPORT_PULSE
dd2b13
+AUDIO_INCLUDES += -I$(PULSE_INCLUDE)
dd2b13
+MODULE_LIBS += -lpulse-simple
dd2b13
diff -up festival/speech_tools/config/project.mak.pulse festival/speech_tools/config/project.mak
dd2b13
--- festival/speech_tools/config/project.mak.pulse	2009-09-29 02:05:53.104720729 -0400
dd2b13
+++ festival/speech_tools/config/project.mak	2009-09-29 02:05:53.362687372 -0400
dd2b13
@@ -60,7 +60,7 @@ MODULE_DIRECTORY = $(TOP)
dd2b13
 # List of all known modules
dd2b13
 
dd2b13
 DISTRIBUTED_MODULES = \
dd2b13
-	NAS_AUDIO ESD_AUDIO NATIVE_AUDIO MPLAYER_AUDIO \
dd2b13
+	NAS_AUDIO PULSE_AUDIO ESD_AUDIO NATIVE_AUDIO MPLAYER_AUDIO \
dd2b13
 	EDITLINE \
dd2b13
 	SIOD WAGON SCFG WFST OLS \
dd2b13
 	JAVA JAVA_CPP JAVA_MEDIA \
dd2b13
@@ -109,6 +109,7 @@ PROJECT_LIBRARY_VERSION_estbase = $(PROJ
dd2b13
 PROJECT_LIBRARY_VERSION_eststring = 1.2
dd2b13
 PROJECT_LIBRARY_VERSION_estjava = $(PROJECT_VERSION).1
dd2b13
 
dd2b13
+PROJECT_LIBRARY_NEEDS_SYSLIBS_estbase=1
dd2b13
 PROJECT_LIBRARY_NEEDS_SYSLIBS_estjava=1
dd2b13
 
dd2b13
 PROJECT_DEFAULT_LIBRARY = estools
dd2b13
diff -up festival/speech_tools/config/systems/default.mak.pulse festival/speech_tools/config/systems/default.mak
dd2b13
--- festival/speech_tools/config/systems/default.mak.pulse	2005-07-17 09:06:49.000000000 -0400
dd2b13
+++ festival/speech_tools/config/systems/default.mak	2009-09-29 02:05:53.364688115 -0400
dd2b13
@@ -61,6 +61,12 @@ NAS_INCLUDE = /usr/X11R6/include
dd2b13
 NAS_LIB = /usr/X11R6/lib
dd2b13
 
dd2b13
 ###########################################################################
dd2b13
+## Where to find PulseAudio
dd2b13
+
dd2b13
+PULSE_INCLUDE = /usr/include
dd2b13
+PULSE_LIB = /usr/lib
dd2b13
+
dd2b13
+###########################################################################
dd2b13
 ## Where to find Enlightenment Speech Demon
dd2b13
 
dd2b13
 ESD_INCLUDE = /usr/local/include
dd2b13
diff -up festival/speech_tools/include/EST_audio.h.pulse festival/speech_tools/include/EST_audio.h
dd2b13
--- festival/speech_tools/include/EST_audio.h.pulse	2004-07-15 19:03:05.000000000 -0400
dd2b13
+++ festival/speech_tools/include/EST_audio.h	2009-09-29 02:05:53.365689290 -0400
dd2b13
@@ -43,6 +43,7 @@
dd2b13
 #include "EST_Option.h"
dd2b13
 
dd2b13
 extern int nas_supported;
dd2b13
+extern int pulse_supported;
dd2b13
 extern int esd_supported;
dd2b13
 extern int sun16_supported;
dd2b13
 extern int freebsd16_supported;