diff src/linuxplay.c @ 563:183866b06e0b

[xemacs-hg @ 2001-05-24 07:50:48 by ben] Makefile.in.in, abbrev.c, alloc.c, buffer.c, bytecode.c, callint.c, callproc.c, casetab.c, chartab.c, cmdloop.c, cmds.c, console-msw.c, console-msw.h, console-stream.c, console-tty.c, console-x.c, console.c, data.c, database.c, debug.c, device-gtk.c, device-msw.c, device-tty.c, device-x.c, device.c, dialog-gtk.c, dialog-msw.c, dialog-x.c, dialog.c, dired-msw.c, dired.c, doc.c, doprnt.c, dragdrop.c, editfns.c, eldap.c, eldap.h, elhash.c, emacs-widget-accessors.c, emacs.c, emodules.c, esd.c, eval.c, event-Xt.c, event-gtk.c, event-msw.c, event-stream.c, events.c, extents.c, faces.c, file-coding.c, fileio.c, filelock.c, floatfns.c, fns.c, font-lock.c, frame-gtk.c, frame-x.c, frame.c, general-slots.h, glade.c, glyphs-gtk.c, glyphs-msw.c, glyphs-widget.c, glyphs-x.c, glyphs.c, glyphs.h, gpmevent.c, gui-gtk.c, gui-x.c, gui.c, gutter.c, hpplay.c, indent.c, input-method-xlib.c, insdel.c, intl.c, keymap.c, libsst.c, libsst.h, linuxplay.c, lisp.h, lread.c, lstream.c, lstream.h, macros.c, marker.c, md5.c, menubar-gtk.c, menubar-msw.c, menubar-x.c, menubar.c, minibuf.c, miscplay.c, miscplay.h, mule-ccl.c, mule-charset.c, mule-wnnfns.c, mule.c, nas.c, ntplay.c, ntproc.c, objects-gtk.c, objects-msw.c, objects-x.c, objects.c, postgresql.c, print.c, process-nt.c, process-unix.c, process.c, ralloc.c, rangetab.c, redisplay.c, scrollbar.c, search.c, select-gtk.c, select-x.c, select.c, sgiplay.c, sheap.c, sound.c, specifier.c, sunplay.c, symbols.c, symeval.h, symsinit.h, syntax.c, sysdep.c, toolbar-msw.c, toolbar.c, tooltalk.c, ui-byhand.c, ui-gtk.c, undo.c, unexaix.c, unexapollo.c, unexconvex.c, unexec.c, widget.c, win32.c, window.c: -- defsymbol -> DEFSYMBOL. -- add an error type to all errors. -- eliminate the error functions in eval.c that let you just use Qerror as the type. -- redo the error API to be more consistent, sensibly named, and easier to use. -- redo the error hierarchy somewhat. create new errors: structure-formation-error, gui-error, invalid-constant, stack-overflow, out-of-memory, process-error, network-error, sound-error, printing-unreadable-object, base64-conversion- error; coding-system-error renamed to text-conversion error; some others. -- fix Mule problems in error strings in emodules.c, tooltalk.c. -- fix error handling in mswin open-network-stream. -- Mule-ize all sound files and clean up the headers. -- nativesound.h -> sound.h and used for all sound files. -- move some shared stuff into glyphs-shared.c: first attempt at eliminating some of the massive GTK code duplication. xemacs.mak: add glyphs-shared.c. xemacs-faq.texi: document how to debug X errors subr.el: fix doc string to reflect reality
author ben
date Thu, 24 May 2001 07:51:33 +0000
parents abe6d1db359e
children 13e3d7ae7155
line wrap: on
line diff
--- a/src/linuxplay.c	Thu May 24 06:30:21 2001 +0000
+++ b/src/linuxplay.c	Thu May 24 07:51:33 2001 +0000
@@ -46,6 +46,8 @@
 
 /* Synched up with: Not in FSF. */
 
+/* This file Mule-ized by Ben Wing, 5-15-01. */
+
 /* XEmacs beta testers say:  undef this by default. */
 #undef NOVOLUMECTRLFORMULAW /* Changing the volume for uLaw-encoded
 			       samples sounds very poor; possibly,
@@ -53,35 +55,16 @@
 			       driver, so undefine this symbol at your
 			       discretion */
 
-#ifdef HAVE_CONFIG_H
 #include <config.h>
-#endif
+#include "lisp.h"
 
 #include "miscplay.h"
-#include "nativesound.h"
+#include "sound.h"
 
-#include <errno.h>
-#include <fcntl.h>
-#include SOUNDCARD_H_FILE /* Path computed by configure */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <fcntl.h>
-#include <sys/file.h>
-#include <sys/ioctl.h>
-#include <sys/signal.h>
-#include <unistd.h>
-
-#ifdef LINUXPLAYSTANDALONE
-#define perror(str) fprintf(stderr,"audio: %s %s\n",str,strerror(errno));
-#define warn(str)   fprintf(stderr,"audio: %s\n",str);
-#else
-#include "lisp.h"
 #include "syssignal.h"
 #include "sysfile.h"
-#define perror(str) message("audio: %s, %s ",str,strerror(errno))
-#define warn(str)   message("audio: %s ",GETTEXT(str))
-#endif
+#include "systty.h" /* for sys/ioctl.h */
+#include SOUNDCARD_H_FILE /* Path computed by configure */
 
 static  SIGTYPE (*sighup_handler) (int);
 static  SIGTYPE (*sigint_handler) (int);
@@ -89,7 +72,7 @@
 static int           mix_fd;
 static int           audio_vol;
 static int           audio_fd;
-static char	     *audio_dev = "/dev/dsp";
+static Char_ASCII    *audio_dev = "/dev/dsp";
 
 /* Intercept SIGINT and SIGHUP in order to close the audio and mixer
    devices before terminating sound output; this requires reliable
@@ -123,16 +106,17 @@
    others, too. Thus we do quite a lot of double checking; actually most of
    this is not needed right now, but it will come in handy, if the kernel's
    sounddriver ever changes or if third-party sounddrivers are used. */
-static int audio_init(int mixx_fd, int auddio_fd, int fmt, int speed,
-		      int tracks, int *volume,
-		      size_t (**sndcnv) (void **, size_t *sz, void **))
+static int
+audio_init(int mixx_fd, int auddio_fd, int fmt, int speed,
+	   int tracks, int *volume,
+	   size_t (**sndcnv) (void **, size_t *sz, void **))
 {
   int i,the_speed,the_stereo,the_fmt;
 
   *sndcnv = sndcnvnop;
 
   if (ioctl(auddio_fd,SNDCTL_DSP_SYNC,NULL) < 0) {
-    perror("SNDCTL_DSP_SYNC");
+    sound_perror("SNDCTL_DSP_SYNC");
     return(0); }
 
   /* Initialize sound hardware with preferred parameters */
@@ -142,7 +126,7 @@
 
   the_fmt = fmt;
   if(ioctl(audio_fd,SNDCTL_DSP_SETFMT,&the_fmt) < 0) {
-  	perror("SNDCTL_DSP_SETFMT");
+  	sound_perror("SNDCTL_DSP_SETFMT");
   	return(0);
   }
 
@@ -152,19 +136,19 @@
       if (((i=fmt=AFMT_U8),ioctl(audio_fd,SNDCTL_DSP_SETFMT,&i)) < 0 ||
 	  fmt != i || ioctl(audio_fd,SNDCTL_DSP_SETFMT,&the_fmt) < 0 ||
 	  fmt != the_fmt) {
-  	perror("SNDCTL_DSP_SETFMT");
+  	sound_perror("SNDCTL_DSP_SETFMT");
   	return(0); } }
     else if (fmt == AFMT_MU_LAW && the_fmt == AFMT_U8 ) {
       /* the kernel will convert for us */ }
     else {
-      perror("SNDCTL_DSP_SETFMT");
+      sound_perror("SNDCTL_DSP_SETFMT");
       return(0); } }
   else if (fmt == AFMT_S8) {
     *sndcnv = sndcnv2unsigned;
     if (((i=fmt=AFMT_U8),ioctl(audio_fd,SNDCTL_DSP_SETFMT,&i)) < 0 ||
         fmt != i || ioctl(audio_fd,SNDCTL_DSP_SETFMT,&the_fmt) < 0 ||
         fmt != the_fmt) {
-      perror("SNDCTRL_DSP_SETFMT");
+      sound_perror("SNDCTRL_DSP_SETFMT");
       return(0); } }
 
   /* The PCSP driver does not support reading of the sampling rate via the
@@ -193,11 +177,11 @@
 	the_fmt == AFMT_U8     ? sndcnv8U_2mono :
 	the_fmt == AFMT_MU_LAW ? sndcnvULaw_2mono : NULL;
       if (*sndcnv == NULL) { /* this should not happen */
-	perror("SNDCTL_DSP_STEREO");
+	sound_perror("SNDCTL_DSP_STEREO");
 	return(0); }
       /* Switch to mono mode */
       if (((i = 0),ioctl(audio_fd,SNDCTL_DSP_STEREO,&i)) < 0 || i) {
-  	perror("SNDCTL_DSP_STEREO");
+  	sound_perror("SNDCTL_DSP_STEREO");
 	return(0); }
       /* Now double check that everything is set as expected */
       if (((i = AFMT_QUERY),ioctl(audio_fd,SNDCTL_DSP_SETFMT,&i)) < 0 ||
@@ -210,18 +194,18 @@
 	   i != 1)) {
 	/* There was no way that we could set the soundcard to a meaningful
            mode */
- 	perror("SNDCTL_DSP_SETFMT and SNDCTL_DSP_STEREO");
+ 	sound_perror("SNDCTL_DSP_SETFMT and SNDCTL_DSP_STEREO");
   	return(0); } }
     else {
       /* Somebody set the soundcard to stereo even though we requested
          mono; this should not happen... */
       if (((i = the_stereo = tracks),ioctl(audio_fd,SNDCTL_DSP_STEREO,&i))<0 ||
 	  i != the_stereo-1) {
-	perror("SNDCTL_DSP_STEREO");
+	sound_perror("SNDCTL_DSP_STEREO");
 	return(0); }
       if (((i = AFMT_QUERY),ioctl(audio_fd,SNDCTL_DSP_SETFMT,&i)) < 0 ||
 	  i != the_fmt) {
-	perror("SNDCTL_DSP_SETFMT");
+	sound_perror("SNDCTL_DSP_SETFMT");
 	return(0); } } }
 
   /* Fail if deviations from desired sampling frequency are too big */
@@ -230,9 +214,9 @@
      "the_speed" is still unchanged */
   ioctl(audio_fd,SOUND_PCM_READ_RATE,&the_speed);
   if (speed*14 < the_speed*10 || speed*6 > the_speed*10) {
-    char buffer[256];
+    Extbyte buffer[256];
     sprintf(buffer,"SNDCTL_DSP_SPEED (req: %d, rtn: %d)",speed,the_speed);
-    perror(buffer);
+    sound_perror(buffer);
     return(0); }
 
   /* Use the mixer device for setting the playback volume */
@@ -282,16 +266,17 @@
 
    Returns 1 on succes. 0 otherwise.
 */
-static int linux_play_data_or_file(int fd,unsigned char *data,
-				    int length,int volume)
+static int
+linux_play_data_or_file(int fd, UChar_Binary *data,
+			int length, int volume)
 {
   size_t         (*parsesndfile)(void **dayta,size_t *sz,void **outbuf);
   size_t         (*sndcnv)(void **dayta,size_t *sz,void **);
   fmtType        ffmt;
   int            fmt,speed,tracks;
-  unsigned char *pptr,*optr,*cptr,*sptr;
+  UChar_Binary *pptr,*optr,*cptr,*sptr;
   int            wrtn,rrtn,crtn,prtn;
-  unsigned char         sndbuf[SNDBUFSZ];
+  UChar_Binary         sndbuf[SNDBUFSZ];
 
   /* We need to read at least the header information before we can start
      doing anything */
@@ -308,7 +293,7 @@
   ffmt = analyze_format(data,&fmt,&speed,&tracks,&parsesndfile);
 
   if (ffmt != fmtRaw && ffmt != fmtSunAudio && ffmt != fmtWave) {
-    warn("Unsupported file format (neither RAW, nor Sun/DECAudio, nor WAVE)");
+    sound_warn("Unsupported file format (neither RAW, nor Sun/DECAudio, nor WAVE)");
       return 0; }
 
   /* The VoxWare-SDK discourages opening /dev/audio; opening /dev/dsp and
@@ -316,7 +301,7 @@
   if ((audio_fd=open(audio_dev, O_WRONLY | O_NONBLOCK, 0)) < 0) {
     /* JV. Much too verbose. In addition this can crash. See NOTE: in
        Fplay_sound 
-       perror(audio_dev); */
+       sound_perror(audio_dev); */
     if (mix_fd > 0 && mix_fd != audio_fd) { close(mix_fd); mix_fd = -1; }
     return 0; }
 
@@ -344,18 +329,18 @@
 				       (void **)&sptr)) > 0; ) {
 	for (;;) {
 	  if ((wrtn = write(audio_fd,sptr,crtn)) < 0) {
-	    perror("write"); goto END_OF_PLAY; }
+	    sound_perror("write"); goto END_OF_PLAY; }
 	  else if (wrtn) break;
 	  else if (ioctl(audio_fd,SNDCTL_DSP_SYNC,NULL) < 0) {
-	    perror("SNDCTL_DSP_SYNC"); goto END_OF_PLAY; } }
+	    sound_perror("SNDCTL_DSP_SYNC"); goto END_OF_PLAY; } }
 	if (wrtn != crtn) {
-	  char buf[255];
+	  Extbyte buf[255];
 	  sprintf(buf,"play: crtn = %d, wrtn = %d",crtn,wrtn);
-	  warn(buf);
+	  sound_warn(buf);
 	  goto END_OF_PLAY; } }
     if (fd >= 0) {
       if ((rrtn = read(fd,sndbuf,SNDBUFSZ)) < 0) {
-	perror("read"); goto END_OF_PLAY; } }
+	sound_perror("read"); goto END_OF_PLAY; } }
     else
       break;
   } while (rrtn > 0);
@@ -389,12 +374,13 @@
 
 /* Call "linux_play_data_or_file" with the appropriate parameters for
    playing a soundfile */
-void play_sound_file (char *sound_file, int volume)
+void
+play_sound_file (Extbyte *sound_file, int volume)
 {
   int fd;
 
   if ((fd=open(sound_file,O_RDONLY,0)) < 0) {
-    perror(sound_file);
+    sound_perror(sound_file);
     return; }
   linux_play_data_or_file(fd,NULL,0,volume);
   close(fd);
@@ -403,7 +389,8 @@
 
 /* Call "linux_play_data_or_file" with the appropriate parameters for
    playing pre-loaded data */
-int play_sound_data (unsigned char *data, int length, int volume)
+int
+play_sound_data (UChar_Binary *data, int length, int volume)
 {
   return linux_play_data_or_file(-1,data,length,volume);
 }