* 4/11/94, rjc Added wait_for_sounds to be called when user wants to
* be sure all play has finished.
* 1998-10-01 rlt Added support for WAVE files.
+ * 2002-10-16 Jon Trulson modifed this to work with NAS releases
+ * 1.5f and higher. We were using the private variable
+ * SoundFileInfo that doesn't exist anymore. But preserve
+ * backward compatibility. This will not work for some
+ * versions of NAS around 1.5b to 1.5f or so. Known to
+ * work on 1.2p5 and 1.6.
*/
#ifdef emacs
#include <unistd.h>
#endif
+/* NAS <= 1.2p5 defines {BIG,LITTLE}_ENDIAN in <audio/fileutil.h>,
+ conflicting with GNU libc (at least); newer versions avoid this
+ name space pollution.
+ DO NOT USE THOSE MACROS in this file. Use NAS_{BIG,LITTLE}_ENDIAN.
+
+ It would be slightly more reliable to do this via configure, but that
+ seems unnecessarily complex.
+*/
#undef LITTLE_ENDIAN
#undef BIG_ENDIAN
+
#include <audio/audiolib.h>
#include <audio/soundlib.h>
#include <audio/snd.h>
#include <audio/wave.h>
#include <audio/fileutil.h>
+/* NAS <= 1.2p5 <audio/fileutil.h> doesn't define the NAS_ versions */
+#ifndef NAS_LITTLE_ENDIAN
+#define NAS_LITTLE_ENDIAN LITTLE_ENDIAN
+#define NAS_BIG_ENDIAN BIG_ENDIAN
+#endif
+
#ifdef emacs
# define XTOOLKIT
#else /* !emacs */
# define warn(str) fprintf (stderr, "%s\n", (str))
-# define CONST const
#endif /* emacs */
#ifdef XTOOLKIT
#else
char *server
#endif
+ );
+char *
+init_play (
+#ifdef XTOOLKIT
+ Display *display
+#else
+ char *server
+#endif
)
{
char *err_message;
- SIGTYPE (*old_sigpipe) ();
+ SIGTYPE (*old_sigpipe) (int);
#ifdef XTOOLKIT
char * server = DisplayString (display);
return NULL;
}
-void
+static void
close_down_play (void)
{
\********************************************************************/
static void
-doneCB (AuServer *aud,
+doneCB (AuServer *auserver,
AuEventHandlerRec *handler,
AuEvent *ev,
AuPointer data)
if (list == NULL)
{
- unsigned char *my_buf;
+ AuPointer my_buf;
if (buf==NULL)
{
- if ((my_buf=malloc (SoundNumBytes (s)))==NULL)
+ if ((my_buf= (AuPointer) malloc (SoundNumBytes (s)))==NULL)
{
return;
}
- if (SoundReadFile (my_buf, SoundNumBytes (s), s) != SoundNumBytes (s))
+ if (SoundReadFile ((char *) my_buf, SoundNumBytes (s), s) != SoundNumBytes (s))
{
free (my_buf);
return;
}
}
else
- my_buf=buf;
+ my_buf = (AuPointer) buf;
id = AuSoundCreateBucketFromData (aud,
s,
#endif /* CACHE_SOUNDS */
+void wait_for_sounds (void);
void
wait_for_sounds (void)
}
}
+int play_sound_file (char *sound_file, int volume);
int
play_sound_file (char *sound_file,
int volume)
{
- SIGTYPE (*old_sigpipe) ();
+ SIGTYPE (*old_sigpipe) (int);
#ifdef ROBUST_PLAY
old_sigpipe=signal (SIGPIPE, sigpipe_handle);
return 1;
}
+int play_sound_data (unsigned char *data, int length, int volume);
int
play_sound_data (unsigned char *data,
int length,
{
Sound s;
int offset;
- SIGTYPE (*old_sigpipe) ();
+ SIGTYPE (*old_sigpipe) (int);
#if !defined (XTEVENTS)
AuEvent ev;
/* Create a name from the sound. */
static char *
-NameFromData (CONST unsigned char *buf,
+NameFromData (const char *buf,
int len)
{
- unsigned char name[9];
+ char name[9];
int i;
char *s;
if (i==8)
{
- strcpy (s=malloc (10), name);
+ strcpy (s = (char *) malloc (10), name);
}
else
{
- strcpy (s=malloc (15), "short sound");
+ strcpy (s = (char *) malloc (15), "short sound");
}
return s;
*/
static SndInfo *
-SndOpenDataForReading (CONST char *data,
+SndOpenDataForReading (const char *data,
int length)
{
memcpy (&si->h, data, sizeof (SndHeader));
- if (LITTLE_ENDIAN)
+ if (NAS_LITTLE_ENDIAN)
{
char n;
/* Stuff taken from wave.c from NAS. Just like snd files, NAS can't
read wave data from memory, so these functions do that for us. */
-#define Err() { return NULL; }
+#define Err() { free (wi); return NULL; }
#define readFourcc(_f) dread(_f, sizeof(RIFF_FOURCC), 1)
#define cmpID(_x, _y) \
strncmp((char *) (_x), (char *) (_y), sizeof(RIFF_FOURCC))
/* These functions here are for faking file I/O from buffer. */
/* The "file" position */
-static int file_posn;
+static size_t file_posn;
/* The length of the "file" */
-static int file_len;
+static size_t file_len;
/* The actual "file" data. */
-CONST static char* file_data;
+static const void* file_data;
/* Like fopen, but for a buffer in memory */
static void
-dopen(CONST char* data, int length)
+dopen (const void* data, size_t length)
{
file_data = data;
file_len = length;
/* Like fread, but for a buffer in memory */
static int
-dread(char* buf, int size, int nitems)
+dread (void* buf, size_t size, size_t nitems)
{
- int nread;
-
- nread = size * nitems;
+ size_t nread = size * nitems;
if (file_posn + nread <= file_len)
{
- memcpy(buf, file_data + file_posn, size * nitems);
+ memcpy(buf, (char *) file_data + file_posn, size * nitems);
file_posn += nread;
return nitems;
}
/* Like fgetc, but for a buffer in memory */
static int
-dgetc()
+dgetc (void)
{
- int ch;
-
if (file_posn < file_len)
- return file_data[file_posn++];
+ return ((char *)file_data)[file_posn++];
else
return -1;
}
/* Like fseek, but for a buffer in memory */
static int
-dseek(long offset, int from)
+dseek (long offset, int from)
{
if (from == 0)
file_posn = offset;
}
/* Like ftell, but for a buffer in memory */
-static int
-dtell()
+static long
+dtell (void)
{
return file_posn;
}
/* Data buffer analogs for FileReadS and FileReadL in NAS. */
static unsigned short
-DataReadS(int swapit)
+DataReadS (int swapit)
{
unsigned short us;
}
static AuUint32
-DataReadL(int swapit)
+DataReadL (int swapit)
{
AuUint32 ul;
}
static int
-readChunk(RiffChunk *c)
+readChunk (RiffChunk *c)
{
int status;
char n;
if ((status = dread(c, sizeof(RiffChunk), 1)))
- if (BIG_ENDIAN)
+ if (NAS_BIG_ENDIAN)
swapl(&c->ckSize, n);
return status;
read the wave data from a buffer in memory. */
static WaveInfo *
-WaveOpenDataForReading(CONST char *data,
- int length)
+WaveOpenDataForReading (const char *data,
+ int length)
{
RiffChunk ck;
RIFF_FOURCC fourcc;
fileSize = PAD2(ck.ckSize) - sizeof(RIFF_FOURCC);
- while (fileSize >= sizeof(RiffChunk))
+ while (fileSize >= (AuInt32) sizeof(RiffChunk))
{
if (!readChunk(&ck))
Err();
{
AuInt32 dummy;
- wi->format = DataReadS(BIG_ENDIAN);
- wi->channels = DataReadS(BIG_ENDIAN);
- wi->sampleRate = DataReadL(BIG_ENDIAN);
+ wi->format = DataReadS(NAS_BIG_ENDIAN);
+ wi->channels = DataReadS(NAS_BIG_ENDIAN);
+ wi->sampleRate = DataReadL(NAS_BIG_ENDIAN);
/* we don't care about the next two fields */
- dummy = DataReadL(BIG_ENDIAN);
- dummy = DataReadS(BIG_ENDIAN);
+ dummy = DataReadL(NAS_BIG_ENDIAN);
+ dummy = DataReadS(NAS_BIG_ENDIAN);
if (wi->format != RIFF_WAVE_FORMAT_PCM)
Err();
- wi->bitsPerSample = DataReadS(BIG_ENDIAN);
+ wi->bitsPerSample = DataReadS(NAS_BIG_ENDIAN);
/* skip any other format specific fields */
dseek(PAD2(ck.ckSize - 16), 1);
{
Sound s;
+#if (AudioLibraryVersionMajor >= 2 ) && (AudioLibraryVersionMinor >= 3)
+ SoundFileInfoProc toProc;
+#endif
if (!(s = (Sound) malloc (sizeof (SoundRec))))
return NULL;
- if ((s->formatInfo = SndOpenDataForReading (data, length)) != NULL)
+ if ((s->formatInfo = SndOpenDataForReading ((char *) data, length)) != NULL)
{
- if (!(SoundFileInfo[SoundFileFormatSnd].toSound) (s))
+#if (AudioLibraryVersionMajor >= 2 ) && (AudioLibraryVersionMinor >= 3)
+ if ((toProc = SoundFileGetProc(SoundFileFormatSnd,
+ SoundFileInfoProcTo)) == NULL)
+ {
+ SndCloseFile ((SndInfo *) (s->formatInfo));
+ free (s);
+
+ return NULL;
+ }
+ if (!((*toProc)(s)))
+#else
+ if (!((int(*)(Sound))(SoundFileInfo[SoundFileFormatSnd].toSound)) (s))
+#endif
{
- SndCloseFile (s->formatInfo);
+ SndCloseFile ((SndInfo *) (s->formatInfo));
free (s);
return NULL;
}
}
- else if ((s->formatInfo = WaveOpenDataForReading (data, length)) != NULL)
+ else if ((s->formatInfo = WaveOpenDataForReading ((char *) data, length)) != NULL)
{
- if (!(SoundFileInfo[SoundFileFormatWave].toSound) (s))
+#if (AudioLibraryVersionMajor >= 2 ) && (AudioLibraryVersionMinor >= 3)
+ if ((toProc = SoundFileGetProc(SoundFileFormatWave,
+ SoundFileInfoProcTo)) == NULL)
{
- WaveCloseFile (s->formatInfo);
+ WaveCloseFile ((WaveInfo *) (s->formatInfo));
+ free (s);
+
+ return NULL;
+ }
+ if (!((*toProc)(s)))
+#else
+ if (!((int(*)(Sound))(SoundFileInfo[SoundFileFormatWave].toSound)) (s))
+#endif
+ {
+ WaveCloseFile ((WaveInfo *) (s->formatInfo));
free (s);
return NULL;
}
return s;
}
-