Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 30 May 2017 16:18:54 +0000 (UTC)
From:      Tobias Kortkamp <tobik@FreeBSD.org>
To:        ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org
Subject:   svn commit: r442097 - in head/audio/rsynth: . files
Message-ID:  <201705301618.v4UGIsQt010550@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: tobik
Date: Tue May 30 16:18:54 2017
New Revision: 442097
URL: https://svnweb.freebsd.org/changeset/ports/442097

Log:
  - 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

Added:
  head/audio/rsynth/files/ossplay.c
     - copied, changed from r442096, head/audio/rsynth/files/freebsdplay.c
  head/audio/rsynth/files/patch-Makefile.in   (contents, props changed)
  head/audio/rsynth/files/sndioplay.c   (contents, props changed)
Deleted:
  head/audio/rsynth/files/freebsdplay.c
Modified:
  head/audio/rsynth/Makefile
  head/audio/rsynth/files/patch-configure.in
  head/audio/rsynth/pkg-plist

Modified: head/audio/rsynth/Makefile
==============================================================================
--- head/audio/rsynth/Makefile	Tue May 30 16:02:52 2017	(r442096)
+++ head/audio/rsynth/Makefile	Tue May 30 16:18:54 2017	(r442097)
@@ -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.spe
 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' \

Copied and modified: head/audio/rsynth/files/ossplay.c (from r442096, head/audio/rsynth/files/freebsdplay.c)
==============================================================================
--- head/audio/rsynth/files/freebsdplay.c	Tue May 30 16:02:52 2017	(r442096, copy source)
+++ head/audio/rsynth/files/ossplay.c	Tue May 30 16:18:54 2017	(r442097)
@@ -29,112 +29,64 @@
 #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;
 }
 
 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");
   }
 }

Added: head/audio/rsynth/files/patch-Makefile.in
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/audio/rsynth/files/patch-Makefile.in	Tue May 30 16:18:54 2017	(r442097)
@@ -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)

Modified: head/audio/rsynth/files/patch-configure.in
==============================================================================
--- head/audio/rsynth/files/patch-configure.in	Tue May 30 16:02:52 2017	(r442096)
+++ head/audio/rsynth/files/patch-configure.in	Tue May 30 16:18:54 2017	(r442097)
@@ -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)

Added: head/audio/rsynth/files/sndioplay.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/audio/rsynth/files/sndioplay.c	Tue May 30 16:18:54 2017	(r442097)
@@ -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");
+  }
+}

Modified: head/audio/rsynth/pkg-plist
==============================================================================
--- head/audio/rsynth/pkg-plist	Tue May 30 16:02:52 2017	(r442096)
+++ head/audio/rsynth/pkg-plist	Tue May 30 16:18:54 2017	(r442097)
@@ -1,4 +1,4 @@
-bin/dlookup
-bin/mkdictdb
+%%DB%%bin/dlookup
+%%DB%%bin/mkdictdb
 bin/say
-bin/nasay
+%%NAS%%bin/nasay



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201705301618.v4UGIsQt010550>