Skip to content

Commit

Permalink
Merge pull request #33 from zeehio/feat-allow-pulse-and-alsa
Browse files Browse the repository at this point in the history
Decouple ALSA and PulseAudio audio modules
  • Loading branch information
lenzo-ka authored Sep 15, 2020
2 parents 66a8ff6 + d94ccf9 commit a3d7234
Show file tree
Hide file tree
Showing 11 changed files with 190 additions and 88 deletions.
15 changes: 1 addition & 14 deletions audio/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ LOCAL_DEFAULT_LIBRARY = estbase
H = audioP.h
CPPSRCS = gen_audio.cc nas.cc esd.cc sun16audio.cc \
mplayer.cc win32audio.cc irixaudio.cc os2audio.cc \
macosxaudio.cc linux_sound.cc
macosxaudio.cc pulseaudio.cc linux_sound.cc

SRCS = $(CPPSRCS)
OBJS = $(SRCS:.cc=.o)
Expand All @@ -59,16 +59,3 @@ include $(TOP)/config/common_make_rules
DEFINES += $(AUDIO_DEFINES)
INCLUDES += $(AUDIO_INCLUDES)














2 changes: 2 additions & 0 deletions audio/audioP.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#define __AUDIOP_H__

int play_nas_wave(EST_Wave &inwave, EST_Option &al);
int play_pulse_wave(EST_Wave &inwave, EST_Option &al);
int play_esd_wave(EST_Wave &inwave, EST_Option &al);
int play_sun16_wave(EST_Wave &inwave, EST_Option &al);
int play_linux_wave(EST_Wave &inwave, EST_Option &al);
Expand All @@ -49,6 +50,7 @@ int play_irix_wave(EST_Wave &inwave, EST_Option &al);
int play_macosx_wave(EST_Wave &inwave, EST_Option &al);

int record_nas_wave(EST_Wave &inwave, EST_Option &al);
int record_pulse_wave(EST_Wave &inwave, EST_Option &al);
int record_esd_wave(EST_Wave &inwave, EST_Option &al);
int record_sun16_wave(EST_Wave &inwave, EST_Option &al);
int record_linux_wave(EST_Wave &inwave, EST_Option &al);
Expand Down
10 changes: 10 additions & 0 deletions audio/gen_audio.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ int play_wave(EST_Wave &inwave, EST_Option &al)
{
if (nas_supported)
protocol = "netaudio"; // the default protocol
else if (pulse_supported)
protocol = "pulseaudio";
else if (esd_supported)
protocol = "esdaudio";
else if (sun16_supported)
Expand Down Expand Up @@ -112,6 +114,8 @@ int play_wave(EST_Wave &inwave, EST_Option &al)

if (upcase(protocol) == "NETAUDIO")
return play_nas_wave(*toplay,al);
else if (upcase(protocol) == "PULSEAUDIO")
return play_pulse_wave(*toplay,al);
else if (upcase(protocol) == "ESDAUDIO")
return play_esd_wave(*toplay,al);
else if (upcase(protocol) == "SUNAUDIO")
Expand Down Expand Up @@ -246,6 +250,8 @@ EST_String options_supported_audio(void)
audios += " audio_command";
if (nas_supported)
audios += " netaudio";
else if (pulse_supported)
audios += " pulseaudio";
else if (esd_supported)
audios += " esdaudio";
if (sun16_supported)
Expand Down Expand Up @@ -288,6 +294,8 @@ int record_wave(EST_Wave &wave, EST_Option &al)
{
if (nas_supported)
protocol = "netaudio"; // the default protocol
else if (pulse_supported)
protocol = "pulseaudio"; // the default protocol
else if (esd_supported)
protocol = "esdaudio"; // the default protocol
else if (sun16_supported)
Expand All @@ -308,6 +316,8 @@ int record_wave(EST_Wave &wave, EST_Option &al)

if (upcase(protocol) == "NETAUDIO")
return record_nas_wave(wave,al);
else if (upcase(protocol) == "PULSEAUDIO")
return record_pulse_wave(wave,al);
else if (upcase(protocol) == "ESDAUDIO")
return record_esd_wave(wave,al);
else if (upcase(protocol) == "SUN16AUDIO")
Expand Down
67 changes: 0 additions & 67 deletions audio/linux_sound.cc
Original file line number Diff line number Diff line change
Expand Up @@ -869,72 +869,6 @@ int record_linux_wave(EST_Wave &inwave, EST_Option &al)

#else

#ifdef SUPPORT_PULSEAUDIO
#include <pulse/simple.h>

int freebsd16_supported = FALSE;
int linux16_supported = TRUE;

static const char *aud_sys_name = "PULSEAUDIO";

#define AUDIOBUFFSIZE 256
// #define AUDIOBUFFSIZE 20480

int play_linux_wave(EST_Wave &inwave, EST_Option &al)
{
pa_sample_spec *ss;
pa_simple *s;
short *waveform;
int num_samples;
int err=0, i, r;

ss = walloc(pa_sample_spec,1);
ss->rate = inwave.sample_rate();
ss->channels = inwave.num_channels();

if (EST_BIG_ENDIAN)
ss->format = PA_SAMPLE_S16BE;
else
ss->format = PA_SAMPLE_S16LE;

s = pa_simple_new(
NULL, /* use default server */
"festival",
PA_STREAM_PLAYBACK,
NULL, /* use default device */
"Speech",
ss,
NULL, /* default channel map */
NULL, /* default buffering attributes */
&err);
if (err < 0)
return NULL;

waveform = inwave.values().memory();
num_samples = inwave.num_samples();

for (i=0; i < num_samples; i += AUDIOBUFFSIZE/2)
{
if (i + AUDIOBUFFSIZE/2 < num_samples)
pa_simple_write(s,&waveform[i],(size_t)AUDIOBUFFSIZE,&err);
else
pa_simple_write(s,&waveform[i],(size_t)(num_samples-i)*2,&err);
}

pa_simple_drain(s,&err);
pa_simple_free(s);
wfree(ss);

return 1;
}

int record_linux_wave(EST_Wave &inwave, EST_Option &al)
{
return -1;
}

#else /* not supported */

int freebsd16_supported = FALSE;
int linux16_supported = FALSE;

Expand All @@ -954,6 +888,5 @@ int record_linux_wave(EST_Wave &inwave, EST_Option &al)
}

#endif /* ALSA */
#endif /* PULSEAUDIO */
#endif /* VOXWARE */

123 changes: 123 additions & 0 deletions audio/pulseaudio.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1997,1998 */
/* Red Hat, Inc. */
/* Copyright (c) 2008 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* Optional support for PulseAudio */
/*=======================================================================*/

#include "EST_Wave.h"
#include "EST_Option.h"
#include "audioP.h"

using namespace std;

#ifdef SUPPORT_PULSEAUDIO

#include <pulse/simple.h>
int pulse_supported = TRUE;

#define AUDIOBUFFSIZE 256
// #define AUDIOBUFFSIZE 20480

int play_pulse_wave(EST_Wave &inwave, EST_Option &al)
{
pa_sample_spec *ss;
pa_simple *s;
short *waveform;
int num_samples;
int err=0, i;

ss = walloc(pa_sample_spec,1);
ss->rate = inwave.sample_rate();
ss->channels = inwave.num_channels();

ss->format = PA_SAMPLE_S16NE;

s = pa_simple_new(
NULL, /* use default server */
"festival",
PA_STREAM_PLAYBACK,
NULL, /* use default device */
"Speech",
ss,
NULL, /* default channel map */
NULL, /* default buffering attributes */
&err);
if (err < 0)
return 0;

waveform = inwave.values().memory();
num_samples = inwave.num_samples();

for (i=0; i < num_samples; i += AUDIOBUFFSIZE/2)
{
if (i + AUDIOBUFFSIZE/2 < num_samples)
pa_simple_write(s,&waveform[i],(size_t)AUDIOBUFFSIZE,&err);
else
pa_simple_write(s,&waveform[i],(size_t)(num_samples-i)*2,&err);
}

pa_simple_drain(s,&err);
pa_simple_free(s);
wfree(ss);

return 1;
}

int record_pulse_wave(EST_Wave &inwave, EST_Option &al)
{
return -1;
}

#else /* SUPPORT_PULSEAUDIO */

int pulse_supported = FALSE;

int play_pulse_wave(EST_Wave &inwave, EST_Option &al)
{
(void)inwave;
(void)al;
cerr << "Audio: pulseaudio not compiled in this version" << endl;
return -1;
}

int record_pulse_wave(EST_Wave &inwave, EST_Option &al)
{
(void)inwave;
(void)al;
cerr << "Audio: pulseaudio not compiled in this version" << endl;
return -1;
}


#endif /* SUPPORT_PULSEAUDIO */
3 changes: 3 additions & 0 deletions config/config.in
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ OPTIMISE_sigpr = 3
## Elightenment Sound Demon, for KDE etc.
# INCLUDE_MODULES += ESD_AUDIO

## PulseAudio sound server. Write PULSE_AUDIO to include it.
INCLUDE_MODULES += @PULSE_AUDIO@

## Native audio for your platform (sun, linux, freebsd, irix, macosx, windows)
INCLUDE_MODULES += NATIVE_AUDIO

Expand Down
7 changes: 0 additions & 7 deletions config/modules/linux16_audio.mak
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@ ifeq ($(LINUXAUDIO),alsa)
PROJECT_LIBRARY_SYSLIBS_estbase += -lasound
endif

ifeq ($(LINUXAUDIO),pulseaudio)
AUDIO_DEFINES += -DSUPPORT_PULSEAUDIO
MODULE_LIBS += -lpulse-simple -lpulse

PROJECT_LIBRARY_SYSLIBS_estbase += -lpulse-simple -lpulse
endif

ifeq ($(LINUXAUDIO),none)
AUDIO_DEFINES += -DSUPPORT_VOXWARE
endif
Expand Down
11 changes: 11 additions & 0 deletions config/modules/pulse_audio.mak
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Definitions for PulseAudio

INCLUDE_PULSE_AUDIO=1

MOD_DESC_PULSE_AUDIO=PulseAudio support

AUDIO_DEFINES += -DSUPPORT_PULSEAUDIO
AUDIO_INCLUDES += -I$(PULSE_INCLUDE)
MODULE_LIBS += -lpulse-simple -lpulse
PROJECT_LIBRARY_SYSLIBS_estbase += -lpulse-simple -lpulse

24 changes: 24 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ ac_subst_vars='LTLIBOBJS
LIBOBJS
OMP_DEFS
OMP_OPTS
PULSE_AUDIO
LINUXAUDIO
DEBUG
SHARED
Expand Down Expand Up @@ -697,6 +698,7 @@ SHELL'
ac_subst_files=''
ac_user_opts='
enable_option_checking
with_pulseaudio
'
ac_precious_vars='build_alias
host_alias
Expand Down Expand Up @@ -1332,6 +1334,11 @@ if test -n "$ac_init_help"; then

cat <<\_ACEOF
Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
--with-pulseaudio Compile PulseAudio audio module [default=no]
Some influential environment variables:
CXX C++ compiler command
CXXFLAGS C++ compiler flags
Expand Down Expand Up @@ -4297,6 +4304,23 @@ fi
# Check whether --with-pulseaudio was given.
if test "${with_pulseaudio+set}" = set; then :
withval=$with_pulseaudio;
else
with_pulseaudio=no
fi
PULSE_AUDIO=
if test "x$with_pulseaudio" != xno; then :
PULSE_AUDIO="PULSE_AUDIO"
fi
OMP_OPTS=
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
Expand Down
Loading

0 comments on commit a3d7234

Please sign in to comment.