On Sun, Oct 26, 2014 at 04:01:03PM +0100, Alexandre Ratchov wrote:
> Hi,
> 
> emacs is able to play sound files, which currently uses
> libossaudio. It can play certain .wav and .au files but it blocks
> during playback (means that you can't edit files during playback).
> 
> Is someone using this feature? or is it there because it compiled
> by accident?
> 
> Some suggested to disable it rather than writing the missing sndio
> bits. I agree. As an emacs user, I couldn't convince myself that it
> could be useful, neither I see the point of spending time on
> maintaining it.
> 
> OK to disable it?
> 

Just for completness and the archives (and to not be accused of
slackness ;), here a diff that would add the sndio bits.

Index: Makefile
===================================================================
RCS file: /cvs/ports/editors/emacs/Makefile,v
retrieving revision 1.45
diff -u -p -u -p -r1.45 Makefile
--- Makefile    10 Sep 2014 19:47:17 -0000      1.45
+++ Makefile    26 Oct 2014 15:05:11 -0000
@@ -4,7 +4,7 @@ COMMENT=                GNU editor: extensible, custom
 
 VERSION=               24.3
 DISTNAME=              emacs-${VERSION}
-REVISION=              4
+REVISION=              5
 
 CATEGORIES=            editors
 
@@ -15,7 +15,7 @@ MAINTAINER=           Jeremie Courreges-Anglas <j
 # GPLv3+
 PERMIT_PACKAGE_CDROM=  Yes
 
-WANTLIB=               c m ncurses ossaudio pthread execinfo gnutls xml2
+WANTLIB=               c m ncurses sndio pthread execinfo gnutls xml2
 
 MASTER_SITES=          ${MASTER_SITE_GNU:=emacs/}
 
Index: patches/patch-configure_ac
===================================================================
RCS file: /cvs/ports/editors/emacs/patches/patch-configure_ac,v
retrieving revision 1.1
diff -u -p -u -p -r1.1 patch-configure_ac
--- patches/patch-configure_ac  25 Sep 2013 07:56:57 -0000      1.1
+++ patches/patch-configure_ac  26 Oct 2014 15:05:11 -0000
@@ -5,9 +5,35 @@ newer than 4.1.0b1" by using a check for
 http://lists.gnu.org/archive/html/emacs-devel/2002-08/msg00417.html) but
 that function has since been removed.
 
---- configure.ac.orig  Thu Sep 19 14:05:18 2013
-+++ configure.ac       Thu Sep 19 14:05:37 2013
-@@ -2661,7 +2661,7 @@ if test "${HAVE_X11}" = "yes" && test "${with_gif}" !=
+--- configure.ac.orig  Tue Mar  5 09:24:59 2013
++++ configure.ac       Sun Oct 26 14:38:49 2014
+@@ -1221,9 +1221,23 @@ if test "${with_sound}" != "no"; then
+   AC_CHECK_HEADERS(machine/soundcard.h sys/soundcard.h soundcard.h,
+     have_sound_header=yes)
+   # Emulation library used on NetBSD.
+-  AC_CHECK_LIB(ossaudio, _oss_ioctl, LIBSOUND=-lossaudio, LIBSOUND=)
+-  AC_SUBST(LIBSOUND)
++  case "$opsys" in
++  openbsd)
++    # OpenBSD may have old ossaudio lib that we want to skip
++    ;;
++  netbsd)
++    AC_CHECK_LIB(ossaudio, _oss_ioctl, LIBSOUND=-lossaudio, LIBSOUND=)
++    AC_SUBST(LIBSOUND)
++    ;;
++  esac
+ 
++  # sndio available on OpenBSD by default, an optional on other systems
++  AC_CHECK_LIB(sndio, sio_initpar, have_libsndio=yes, have_libsndio=no)
++  if test $have_libsndio = yes; then
++    LIBSOUND="$LIBSOUND -lsndio"
++    AC_DEFINE(HAVE_SNDIO, 1, [Define to 1 if sndio is available.])
++  fi
++
+   ALSA_REQUIRED=1.0.0
+   ALSA_MODULES="alsa >= $ALSA_REQUIRED"
+   PKG_CHECK_MODULES(ALSA, $ALSA_MODULES, HAVE_ALSA=yes, HAVE_ALSA=no)
+@@ -2661,7 +2675,7 @@ if test "${HAVE_X11}" = "yes" && test "${with_gif}" !=
    AC_CHECK_HEADER(gif_lib.h,
  # EGifPutExtensionLast only exists from version libungif-4.1.0b1.
  # Earlier versions can crash Emacs.
Index: patches/patch-src_sound_c
===================================================================
RCS file: patches/patch-src_sound_c
diff -N patches/patch-src_sound_c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-src_sound_c   26 Oct 2014 15:05:11 -0000
@@ -0,0 +1,276 @@
+$OpenBSD$
+--- src/sound.c.orig   Tue Jan  1 21:37:17 2013
++++ src/sound.c        Sun Oct 26 15:41:34 2014
+@@ -55,6 +55,12 @@ along with GNU Emacs.  If not, see <http://www.gnu.org
+ /* BEGIN: Non Windows Includes */
+ #ifndef WINDOWSNT
+ 
++/* If sndio is present, then don't try to build the voxware driver,
++   because the soundcard.h is probably not present at all. TODO: add
++   the necessary autoconf bits to detect OSS ioctls */
++#ifdef HAVE_SNDIO
++#include <sndio.h>
++#else
+ #include <sys/ioctl.h>
+ 
+ /* FreeBSD has machine/soundcard.h.  Voxware sound driver docs mention
+@@ -69,6 +75,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org
+ #ifdef HAVE_SOUNDCARD_H
+ #include <soundcard.h>
+ #endif
++#endif /* HAVE_SNDIO */
+ #ifdef HAVE_ALSA
+ #ifdef ALSA_SUBDIR_INCLUDE
+ #include <alsa/asoundlib.h>
+@@ -698,7 +705,214 @@ au_play (struct sound *s, struct sound_device *sd)
+ }
+ 
+ 
++#ifdef HAVE_SNDIO
++
+ /***********************************************************************
++                     SNDIO Driver Interface
++ ***********************************************************************/
++
++/* This driver is available on OpenBSD, and some other systems if
++   sndio is installed */
++
++#include <stdio.h>
++
++struct sndio_params
++{
++  struct sio_hdl *hdl;
++  unsigned int bits, le;
++  unsigned int blksz;
++};
++
++/* Open device SD.  If SD->file is non-null, open that device,
++   otherwise use a default device name.  */
++
++static void
++sndio_open (struct sound_device *sd)
++{
++  const char *file;
++  struct sndio_params *p;
++  int err;
++
++  /* Open the sound device.  Default is "default".  */
++  if (sd->file)
++    file = sd->file;
++  else
++    file = SIO_DEVANY;
++
++  p = xmalloc (sizeof *p);
++  p->hdl = NULL;
++
++  sd->fd = -1;
++  sd->data = p;
++
++  p->hdl = sio_open(file, SIO_PLAY, 0);
++  if (p->hdl == NULL)
++    error("%s: couldn't open audio device", file);
++}
++
++static ptrdiff_t
++sndio_period_size (struct sound_device *sd)
++{
++  struct sndio_params *p = (struct sndio_params *)sd->data;
++
++  return p->blksz;
++}
++
++static void
++sndio_configure (struct sound_device *sd)
++{
++  struct sio_par askpar, retpar;
++  struct sndio_params *p = (struct sndio_params *) sd->data;
++  unsigned int nfr;
++
++  sio_initpar(&askpar);
++
++  askpar.bits = p->bits;
++  askpar.bps = askpar.bits / 8;
++  if (askpar.bps > 1) {
++    askpar.sig = 1;
++    askpar.le = p->le;
++  } else
++    askpar.sig = 0;
++  
++  /* 1 = mono, 2 = stereo, 0 = don't set.  */
++  askpar.pchan = sd->channels > 0 ? sd->channels : 2;
++
++  /* Sample rate.  */
++  askpar.rate = sd->sample_rate;
++
++  /* Buffer size */
++  askpar.appbufsz = askpar.rate / 4;
++
++  if (!sio_setpar(p->hdl, &askpar)) {
++    error("%s: couldn't set audio parameters");
++    return;
++  }
++
++  if (!sio_getpar(p->hdl, &retpar)) {
++    error("%s: couldn't get audio parameters");
++    return;
++  }
++
++  if (retpar.rate != askpar.rate ||
++      retpar.pchan != askpar.pchan ||
++      retpar.bps != askpar.bps ||
++      retpar.bits != askpar.bits ||
++      retpar.sig != askpar.sig ||
++      (retpar.bps * 8 > retpar.bits && !retpar.msb) ||
++      (retpar.bps > 1 && retpar.le != SIO_LE_NATIVE)) {
++    error("%s: unsupported audio parameters");
++    return;
++  }
++
++  /*
++   * set the emacs block size to half the audio buffer size, but round
++   * it to retpar.round (the h/w block size)
++   */
++  nfr = retpar.appbufsz / 2;
++  nfr -= nfr % retpar.round;
++  if (nfr == 0)
++    nfr = retpar.round;
++  p->blksz = nfr * retpar.pchan * retpar.bps;
++
++  if (!sio_start(p->hdl)) {
++    error("%s: couldn't start audio device");
++    return;
++  }
++}
++
++
++/* Close device SD if it is open.  */
++
++static void
++sndio_close (struct sound_device *sd)
++{
++  struct sndio_params *p = (struct sndio_params *) sd->data;
++
++  if (p) {
++    if (p->hdl)
++      sio_close(p->hdl);
++    xfree(p);
++  }
++  sd->data = NULL;
++}
++
++/* Choose device-dependent format for device SD from sound file S.  */
++
++static void
++sndio_choose_format (struct sound_device *sd, struct sound *s)
++{
++  struct sndio_params *p = (struct sndio_params *) sd->data;
++
++  if (s->type == RIFF)
++    {
++      struct wav_header *h = (struct wav_header *) s->header;
++      if (h->precision % 8 != 0)
++      error ("Unsupported WAV file format");
++      p->bits = h->precision;
++      if (p->bits > 8)
++        p->le = 1;
++    }
++  else if (s->type == SUN_AUDIO)
++    {
++      struct au_header *header = (struct au_header *) s->header;
++      switch (header->encoding)
++      {
++      case AU_ENCODING_8:
++          p->bits = 8;
++        break;
++      case AU_ENCODING_16:
++          p->bits = 16;
++        break;
++      case AU_ENCODING_24:
++          p->bits = 24;
++        break;
++      case AU_ENCODING_32:
++          p->bits = 32;
++        break;
++
++      default:
++        error ("Unsupported AU file format");
++      }
++      if (p->bits > 8)
++        p->le = 0;
++    }
++  else
++    emacs_abort ();
++}
++
++/* Write NBYTES bytes from BUFFER to device SD.  */
++
++static void
++sndio_write (struct sound_device *sd, const char *buffer, ptrdiff_t nbytes)
++{  
++  struct sndio_params *p = (struct sndio_params *) sd->data;
++
++  if (sio_write(p->hdl, buffer, nbytes) == 0)
++    error("audio device i/o error");
++}
++
++
++/* Initialize device SD.  Set up the interface functions in the device
++   structure.  */
++
++static int
++sndio_init (struct sound_device *sd)
++{
++  sd->fd = -1;
++  sd->open = sndio_open;
++  sd->close = sndio_close;
++  sd->configure = sndio_configure;
++  sd->choose_format = sndio_choose_format;
++  sd->write = sndio_write;
++  sd->period_size = sndio_period_size;
++
++  return 1;
++}
++
++#else /* HAVE_SNDIO */
++
++/***********************************************************************
+                      Voxware Driver Interface
+  ***********************************************************************/
+ 
+@@ -899,6 +1113,8 @@ vox_write (struct sound_device *sd, const char *buffer
+     sound_perror ("Error writing to sound device");
+ }
+ 
++#endif /* HAVE_SNDIO */
++
+ #ifdef HAVE_ALSA
+ /***********************************************************************
+                      ALSA Driver Interface
+@@ -1245,7 +1461,6 @@ alsa_init (struct sound_device *sd)
+ 
+ #endif /* HAVE_ALSA */
+ 
+-
+ /* END: Non Windows functions */
+ #else /* WINDOWSNT */
+ 
+@@ -1420,11 +1635,16 @@ Internal use only, use `play-sound' instead.  */)
+   args[1] = sound;
+   Frun_hook_with_args (2, args);
+ 
++#ifdef HAVE_SNDIO
++  if (!sndio_init (current_sound_device))
++#endif
+ #ifdef HAVE_ALSA
+-  if (!alsa_init (current_sound_device))
++    if (!alsa_init (current_sound_device))
+ #endif
+-    if (!vox_init (current_sound_device))
+-      error ("No usable sound device driver found");
++#ifndef HAVE_SNDIO
++      if (!vox_init (current_sound_device))
++#endif
++      error ("No usable sound device driver found");
+ 
+   /* Open the device.  */
+   current_sound_device->open (current_sound_device);

Reply via email to