remove experimental alsa support

The direct alsa support was experimental and never worked well. It had a
setting which was system specific. Also, I feel that it is better to let
espeak control the audio processing.
This commit is contained in:
William Hubbs 2011-03-05 16:49:58 -06:00
commit 7bf2eee07a
7 changed files with 1 additions and 175 deletions

View file

@ -1,12 +1,6 @@
bin_PROGRAMS = espeakup
espeakup_SOURCES = espeakup.c espeakup.h cli.c espeak.c queue.c queue.h signal.c softsynth.c
if ALSA
espeakup_SOURCES += alsa.c
else
espeakup_SOURCES += portaudio.c
endif
if STANDALONE
espeakup_LDFLAGS = -all-static
endif

9
README
View file

@ -33,15 +33,6 @@ autoreconf -i
If this runs successfully, you will have a configure script, so run it
then run make. If that completes successfully, run make install.
ALSA SUPPORT
============
Chris Brannon contributed the alsa support to this project, and I would
like to thank him for his work on it.
To build with alsa support, add --with-alsa to the command line when you
run the configure script.
Starting Up
===========

122
alsa.c
View file

@ -1,122 +0,0 @@
/*
* espeakup - interface which allows speakup to use espeak
*
* Copyright (C) 2008 William Hubbs
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* File: alsa.c
* Description: Produce audio by calling the ALSA library directly.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <alsa/asoundlib.h>
#include "espeakup.h"
static pthread_mutex_t audio_mutex = PTHREAD_MUTEX_INITIALIZER;
static snd_pcm_t *handle;
static const unsigned int channels = 1;
static const int soft_resample = 1;
static const unsigned int latency = 25000;
static void lock_audio_mutex(void)
{
pthread_mutex_lock(&audio_mutex);
}
static void unlock_audio_mutex(void)
{
pthread_mutex_unlock(&audio_mutex);
}
static int alsa_callback(short *audio, int numsamples, espeak_EVENT * events)
{
int frames = 0;
int rc = 0;
lock_audio_mutex();
if (stop_requested || !should_run) {
unlock_audio_mutex();
return 1;
}
while (numsamples > 0 && (!stop_requested && should_run)) {
frames = snd_pcm_writei(handle, audio, numsamples);
if (frames < 0)
frames = snd_pcm_recover(handle, frames, !debug);
if (frames < 0) {
fprintf(stderr, "snd_pcm_writei failed: %s\n", snd_strerror(frames));
break;
}
if (frames > 0 && frames < numsamples && debug)
fprintf(stderr, "Short write (expected %i, wrote %i)\n", numsamples, frames);
numsamples -= frames;
audio += frames;
}
rc = (stop_requested || !should_run);
unlock_audio_mutex();
return rc;
}
void select_audio_mode(void)
{
audio_mode = AUDIO_OUTPUT_RETRIEVAL;
}
int init_audio(unsigned int rate)
{
int err;
/* Open PCM device for playback. */
err = snd_pcm_open(&handle, "default", SND_PCM_STREAM_PLAYBACK, 0);
if (err < 0) {
fprintf(stderr, "Playback open error: %s\n", snd_strerror(err));
return err;
}
/* Set parameters. */
err = snd_pcm_set_params(handle,
SND_PCM_FORMAT_S16_LE,
SND_PCM_ACCESS_RW_INTERLEAVED,
channels,
rate,
soft_resample,
latency);
if (err < 0) {
fprintf(stderr, "Playback open error: %s\n", snd_strerror(err));
return err;
}
espeak_SetSynthCallback(alsa_callback);
return 0;
}
void stop_audio(void)
{
lock_audio_mutex();
if (snd_pcm_drop(handle) < 0)
fprintf(stderr, "Negative return from snd_pcm_drop!\n");
snd_pcm_prepare(handle);
unlock_audio_mutex();
}

View file

@ -15,12 +15,6 @@ AC_ARG_ENABLE([standalone],
[enable_standalone=no])
AM_CONDITIONAL([STANDALONE], [test x$enable_standalone = xyes])
AC_ARG_WITH([alsa],
[AS_HELP_STRING([--with-alsa],[build with ALSA support])],
[],
[with_alsa=no])
AM_CONDITIONAL([ALSA], [test x$with_alsa = xyes])
# Checks for programs.
AC_PROG_CC
AC_PROG_INSTALL

View file

@ -136,7 +136,6 @@ static espeak_ERROR stop_speech(void)
{
espeak_ERROR rc;
stop_audio();
rc = espeak_Cancel();
return rc;
}
@ -218,17 +217,12 @@ int initialize_espeak(struct synth_t *s)
int rate;
/* initialize espeak */
select_audio_mode();
rate = espeak_Initialize(audio_mode, 50, NULL, 0);
rate = espeak_Initialize(AUDIO_OUTPUT_PLAYBACK, 50, NULL, 0);
if (rate < 0) {
fprintf(stderr, "Unable to initialize espeak.\n");
return -1;
}
if (init_audio((unsigned int) rate) < 0) {
return -1;
}
/* Setup initial voice parameters */
if (defaultVoice) {
set_voice(s, defaultVoice);

View file

@ -75,17 +75,12 @@ extern void *espeak_thread(void *arg);
extern int open_softsynth(void);
extern void close_softsynth(void);
extern void *softsynth_thread(void *arg);
extern void select_audio_mode(void);
extern int init_audio(unsigned int rate);
extern void stop_audio(void);
extern volatile int should_run;
extern volatile int stop_requested;
extern int self_pipe_fds[2];
#define PIPE_READ_FD (self_pipe_fds[0])
#define PIPE_WRITE_FD (self_pipe_fds[1])
extern espeak_AUDIO_OUTPUT audio_mode;
extern pthread_cond_t runner_awake;
extern pthread_cond_t stop_acknowledged;
extern pthread_mutex_t queue_guard;

View file

@ -1,20 +0,0 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "espeakup.h"
void select_audio_mode(void)
{
audio_mode = AUDIO_OUTPUT_PLAYBACK;
}
int init_audio(unsigned int rate)
{
return 0;
}
void stop_audio(void)
{
return;
}