- Add Sndio backend from [1] and fix it

- Remove dead code
  - Fix format selection and playback with raw devices
- Fix OSS backend
  - Remove dead code
  - Don't open the device in non-blocking mode.  There is no error
    handling for short writes and looking at how audio_play() is used in say.c
    it is expected to block.
  - Fix format selection
  - Let the kernel handle sample conversion instead of doing it in the backend
- Make NAS support optional
- Make installing dictionary database tools optional
- Add LICENSE

Obtained from:	OpenBSD [1] (based on)
Approved by:	lme (mentor)
Differential Revision:	https://reviews.freebsd.org/D10828
This commit is contained in:
Tobias Kortkamp 2017-05-30 16:18:54 +00:00
parent 98885b3265
commit b910ce6bef
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=442097
6 changed files with 163 additions and 75 deletions

View file

@ -3,7 +3,7 @@
PORTNAME= rsynth
PORTVERSION= 2.0
PORTREVISION= 4
PORTREVISION= 5
CATEGORIES= audio accessibility
MASTER_SITES= ftp://svr-ftp.eng.cam.ac.uk/pub/comp.speech/synthesis/ \
ftp://ftp.enst.fr/pub/unix/multimedia/
@ -11,14 +11,27 @@ MASTER_SITES= ftp://svr-ftp.eng.cam.ac.uk/pub/comp.speech/synthesis/ \
MAINTAINER= ports@FreeBSD.org
COMMENT= Speech synthesizer
LIB_DEPENDS= libgdbm.so:databases/gdbm \
libaudio.so:audio/nas
LICENSE= PD
OPTIONS_DEFINE= DB NAS SNDIO
OPTIONS_SUB= yes
DB_DESC= Build dictionary database tools
DB_LIB_DEPENDS= libgdbm.so:databases/gdbm
DB_CONFIGURE_ENV_OFF= ac_cv_lib_gdbm_gdbm_open=no
NAS_LIB_DEPENDS= libaudio.so:audio/nas
NAS_CONFIGURE_ENV_OFF= ac_cv_header_audio_audiolib_h=no
SNDIO_LIB_DEPENDS= libsndio.so:audio/sndio
SNDIO_MAKE_ENV= SAY_LIBS=-lsndio
USES= autoreconf
GNU_CONFIGURE= yes
pre-configure:
@${CP} ${FILESDIR}/freebsdplay.c ${WRKSRC}/config/freebsdplay.c
pre-configure-SNDIO-on:
@${CP} ${FILESDIR}/sndioplay.c ${WRKSRC}/config/freebsdplay.c
pre-configure-SNDIO-off:
@${CP} ${FILESDIR}/ossplay.c ${WRKSRC}/config/freebsdplay.c
post-configure:
@${REINPLACE_CMD} -E 's,(BIN|LIB)_DIR\),DESTDIR\)$$\(&,g' \

View file

@ -29,57 +29,43 @@
#define SAMP_RATE 8000
long samp_rate = SAMP_RATE;
/* Audio Parameters */
static int dev_fd = -1;
/* file descriptor for audio device */
char *dev_file = "/dev/dsp";
static int linear_fd = -1;
static char *linear_file = NULL;
char *prog = "hplay";
static int
audio_open(void)
{
dev_fd = open(dev_file, O_WRONLY | O_NDELAY);
if (dev_fd < 0)
{
perror(dev_file);
return 0;
}
return 1;
}
int
audio_init(int argc, char *argv[])
{
int rate_set = 0;
int use_audio = 1;
int fmt;
prog = argv[0];
argc = getargs("freebsd Audio",argc, argv,
argc = getargs("Audio output",argc, argv,
"r", "%d", &rate_set, "Sample rate",
"a", NULL, &use_audio, "Audio enable",
NULL);
if (help_only)
if (help_only || !use_audio)
return argc;
if (use_audio)
audio_open();
dev_fd = open(dev_file, O_WRONLY);
if (dev_fd < 0) {
perror(dev_file);
return argc;
}
if (rate_set)
samp_rate = rate_set;
if (dev_fd > 0)
{
ioctl(dev_fd, SNDCTL_DSP_SPEED, &samp_rate);
printf("Actual sound rate: %ld\n", samp_rate);
}
fmt = AFMT_S16_NE;
if (ioctl(dev_fd, SNDCTL_DSP_SETFMT, &fmt) < 0)
perror("SNDCTL_DSP_SETFMT");
if (ioctl(dev_fd, SNDCTL_DSP_SPEED, &samp_rate) < 0)
perror("SNDCTL_DSP_SPEED");
return argc;
}
@ -87,54 +73,20 @@ audio_init(int argc, char *argv[])
void
audio_term()
{
int dummy;
/* Close audio system */
if (dev_fd >= 0)
{
ioctl(dev_fd, SNDCTL_DSP_SYNC, &dummy);
close(dev_fd);
dev_fd = -1;
}
/* Finish linear file */
if (linear_fd >= 0)
{
ftruncate(linear_fd, lseek(linear_fd, 0L, SEEK_CUR));
close(linear_fd);
linear_fd = -1;
}
}
void
audio_play(int n, short *data)
{
if (n > 0)
if (n > 0 && dev_fd >= 0)
{
unsigned char *converted = (unsigned char *) malloc(n);
int i;
if (converted == NULL)
{
fprintf(stderr, "Could not allocate memory for conversion\n");
exit(3);
}
for (i = 0; i < n; i++)
converted[i] = (data[i] - 32768) / 256;
if (linear_fd >= 0)
{
if (write(linear_fd, converted, n) != n)
perror("write");
}
if (dev_fd >= 0)
{
if (write(dev_fd, converted, n) != n)
perror("write");
}
free(converted);
size_t size = n * sizeof(short);
if (write(dev_fd, data, size) != size)
perror("write");
}
}

View file

@ -0,0 +1,11 @@
--- Makefile.in.orig 2017-05-20 02:25:06 UTC
+++ Makefile.in
@@ -34,7 +34,7 @@ SAY_OBJS = say.o saynum.o darray.o ASCII.o phones.o te
getarg.o Revision.o
say : $(SAY_OBJS) hplay.o
- $(CC) -o $@ $(LDFLAGS) $(SAY_OBJS) hplay.o $(LDLIBS)
+ $(CC) -o $@ $(LDFLAGS) $(SAY_OBJS) hplay.o $(SAY_LIBS) $(LDLIBS)
nasay : $(SAY_OBJS) naplay.o
$(CC) -o $@ $(LDFLAGS) $(SAY_OBJS) naplay.o $(XLIBS) $(LDLIBS)

View file

@ -27,7 +27,7 @@
PROGS="$PROGS mkdictdb dlookup"
else
DICTS=""
@@ -126,7 +128,7 @@ if test "$ac_cv_header_audio_audiolib_h"
@@ -126,7 +128,7 @@ if test "$ac_cv_header_audio_audiolib_h" = yes ; then
XLIBS="-laudio $XLIBS"
AC_DEFINE(HAVE_NAS)
],,$XLIBS $LIBS)

View file

@ -0,0 +1,112 @@
#include <config.h>
/*****************************************************************/
/*** ***/
/*** Play out a file on OpenBSD ***/
/*** (conf/linuxplay.c with changes) ***/
/*** ***/
/*****************************************************************/
#include <useconfig.h>
#include <stdio.h>
#include <math.h>
#include <ctype.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <sys/signal.h>
#include <sndio.h>
#include "proto.h"
#include "getargs.h"
#include "hplay.h"
#define SAMP_RATE 8000
long samp_rate = SAMP_RATE;
static struct sio_hdl *hdl;
static struct sio_par par;
char *prog = "hplay";
int
audio_init(int argc, char *argv[])
{
int rate_set = 0;
int use_audio = 1;
prog = argv[0];
argc = getargs("Audio output",argc, argv,
"r", "%d", &rate_set, "Sample rate",
"a", NULL, &use_audio, "Audio enable",
NULL);
if (help_only)
return argc;
if (rate_set)
samp_rate = rate_set;
if (!use_audio)
return argc;
hdl = sio_open(NULL, SIO_PLAY, 0);
if (hdl == NULL)
{
fprintf(stderr, "sio_open failed\n");
return argc;
}
sio_initpar(&par);
par.bits = 16;
par.sig = 1;
par.le = SIO_LE_NATIVE;
par.rate = samp_rate;
par.pchan = 1;
if (!sio_setpar(hdl, &par) || !sio_getpar(hdl, &par))
{
fprintf(stderr, "error setting sndio parameters\n");
hdl = NULL;
}
if (par.bits != 16 || par.le != SIO_LE_NATIVE || par.sig != 1 || par.pchan != 1)
{
fprintf(stderr, "returned incorrect sndio parameters\n");
hdl = NULL;
}
samp_rate = par.rate;
if (hdl && !sio_start(hdl))
{
fprintf(stderr, "error starting sndio\n");
hdl = NULL;
}
return argc;
}
void
audio_term()
{
if (hdl)
{
sio_close(hdl);
hdl = NULL;
}
}
void
audio_play(int n, short *data)
{
if (n > 0 && hdl)
{
size_t size = n * sizeof(short);
if (sio_write(hdl, data, size) != size)
fprintf(stderr, "sio_write: short write");
}
}

View file

@ -1,4 +1,4 @@
bin/dlookup
bin/mkdictdb
%%DB%%bin/dlookup
%%DB%%bin/mkdictdb
bin/say
bin/nasay
%%NAS%%bin/nasay