shithub: sox

Download patch

ref: a99b80e0dd49ea72692879671da3ed16891e5183
parent: efad487ddcfd58db200cab4389a5856b97c0b26f
author: cbagwell <cbagwell>
date: Wed Mar 3 10:28:52 EST 1999

Changing Sun audio drivers to use new rawread()/write()

--- a/configure.in
+++ b/configure.in
@@ -206,9 +206,12 @@
 		)
 	if test "$ac_cv_dev_sun_audio" = yes
 	then
-		AC_CHECK_HEADER(audioio.h,
-			sun_audio=yes,
-			AC_WARN([No audioio.h to compile with SUN /dev/audio]))
+		AC_CHECK_HEADER(sys/audioio.h, sun_audio=yes)
+		AC_CHECK_HEADER(sun/audioio.h, sun_audio=yes)
+		if test "$sun_audio" = auto
+		then
+			AC_WARN([No audioio.h to compile with SUN /dev/audio])
+		fi
 	fi
 fi
 if test "$sun_audio" = yes
@@ -237,7 +240,14 @@
 AC_SUBST(NEED_OSS)
 AC_SUBST(NEED_SUNAU)
 AC_SUBST(NEED_ALSA)
+
+dnl Generate output files...
+
 AC_OUTPUT([Makefile])
+
+if test ! -f tests.sh; then cp ${srcdir}/tests.sh tests.sh; fi
+if test ! -f monkey.au; then cp ${srcdir}/monkey.au monkey.au; fi
+if test ! -f monkey.voc; then cp ${srcdir}/monkey.voc monkey.voc; fi
 
 touch .depend
 
--- a/src/handlers.c
+++ b/src/handlers.c
@@ -227,11 +227,7 @@
 	(char *) 0
 };
 extern void sunstartread();
-extern LONG sunread();
-extern void sunstopread();
 extern void sunstartwrite();
-extern void sunwrite();
-extern void sunstopwrite();
 #endif
 
 char *svxnames[] = {
@@ -397,8 +393,8 @@
 #if	defined(SUNAUDIO_PLAYER)
 	/* Sun /dev/audio player. */
 	{sunnames, FILE_STEREO,
-		sunstartread, sunread, sunstopread, 	       /* /dev/audio */
-		sunstartwrite, sunwrite, sunstopwrite},
+		sunstartread, rawread, rawstopread, 	       /* /dev/audio */
+		sunstartwrite, rawwrite, rawstopwrite},
 #endif
 	{svxnames, FILE_STEREO,
 		svxstartread, svxread, svxstopread,            /* Amiga 8SVX */
--- a/src/sunaudio.c
+++ b/src/sunaudio.c
@@ -31,26 +31,6 @@
 #include "st.h"
 #include "libst.h"
 
-static int got_int = 0;
-
-static int abuf_size = 0;
-static int abuf_cnt = 0;
-static char *audiobuf;
-
-/* This is how we know when to stop recording.  User sends interrupt
- * (eg. control-c) and then we mark a flag to show we are done.
- * Must call "sigint(0)" during init so that the OS can be notified
- * what to do.
- */
-static void
-sigint(s)
-int s;
-{
-    fprintf(stderr,"Got SIGINT\n");
-    if (s) got_int = 1;
-    else signal(SIGINT, sigint);
-}
-
 /*
  * Do anything required before you start reading samples.
  * Read file header.
@@ -65,9 +45,12 @@
     audio_info_t audio_if;
 
     /* Hard code for now. */
-    abuf_size = 1024;
-    if ((audiobuf = malloc (abuf_size)) == NULL) {
-	fail("unable to allocate input buffer of size %d", abuf_size);
+    ft->file.count = 0;
+    ft->file.pos = 0;
+    ft->file.eof = 0;
+    ft->file.size = 1024;
+    if ((ft->file.buf = malloc (ft->file.size)) == NULL) {
+	fail("unable to allocate input buffer of size %d", ft->file.size);
     }
 
     if (ft->info.rate == 0.0) ft->info.rate = 8000;
@@ -131,159 +114,9 @@
     if (audio_if.record.encoding != encoding) {
 	fail("Unable to initialize style for /dev/audio");
     }
-    sigint(0);	/* Prepare to catch SIGINT */
+    sigintreg(ft);	/* Prepare to catch SIGINT */
 }
 
-int dspget(ft)
-ft_t ft;
-{
-    int rval;
-
-    if (abuf_cnt < 1) {
-	abuf_cnt = read (fileno(ft->fp), (char *)audiobuf, abuf_size);
-	if (abuf_cnt == 0) {
-	    got_int = 1; /* Act like user said end record */
-	    return(0);
-	}
-    }
-    rval = *(audiobuf + (abuf_size-abuf_cnt));
-    abuf_cnt--;
-    return(rval);
-}
-
-/* Read short. */
-unsigned short dsprshort(ft)
-ft_t ft;
-{
-    unsigned short rval;
-    if (abuf_cnt < 2) {
-	abuf_cnt = read (fileno(ft->fp), (char *)audiobuf, abuf_size);
-	if (abuf_cnt == 0) {
-	    got_int = 1;  /* act like user said end recording */
-	    return(0);
-	}
-    }
-    rval = *((unsigned short *)(audiobuf + (abuf_size-abuf_cnt)));
-    abuf_cnt -= 2;
-    return(rval);
-}
-
-/*
- * Read up to len samples from file.
- * Convert to signed longs.
- * Place in buf[].
- * Return number of samples read.
- */
-
-LONG sunread(ft, buf, len)
-ft_t ft;
-LONG *buf, len;
-{
-    register int datum;
-    int done = 0;
-
-    if (got_int)
-	return(0); /* Return with length 0 read so program will end */
-
-    switch(ft->info.size) {
-    case BYTE:
-	switch(ft->info.style) {
-	case SIGN2:
-	    while(done < len) {
-		datum = dspget(ft);
-		if (got_int || feof(ft->fp))
-		    return(done);
-		/* scale signed up to long's range */
-		*buf++ = LEFT(datum, 24);
-		done++;
-	    }
-	    return done;
-	case UNSIGNED:
-	    while(done < len) {
-		datum = dspget(ft);
-		if (got_int || feof(ft->fp))
-		    return(done);
-		/* Convert to unsigned */
-		datum ^= 128;
-		/* scale signed up to long's range */
-		*buf++ = LEFT(datum, 24);
-		done++;
-	    }
-	    return done;
-	case ULAW:
-	    /* grab table from Posk stuff */
-	    while(done < len) {
-		datum = dspget(ft);
-		if (got_int || feof(ft->fp))
-		    return(done);
-		datum = st_ulaw_to_linear(datum);
-		/* scale signed up to long's range */
-		*buf++ = LEFT(datum, 16);
-		done++;
-	    }
-	    return done;
-	case ALAW:
-	    while(done < len) {
-		datum = dspget(ft);
-		if (got_int || feof(ft->fp))
-		    return(done);
-		datum = st_Alaw_to_linear(datum);
-		/* scale signed up to long's range */
-		*buf++ = LEFT(datum, 16);
-		done++;
-	    }
-	    return done;
-	}
-    case WORD:
-	switch(ft->info.style) {
-	case SIGN2:
-	    while(done < len) {
-		datum = dsprshort(ft);
-		if (got_int || feof(ft->fp))
-		{
-		    fprintf(stderr,"Returning early\n");
-		    return(done);
-		}
-		/* scale signed up to long's range */
-		*buf++ = LEFT(datum, 16);
-		done++;
-	    }
-	    return done;
-	case UNSIGNED:
-	    while(done < len) {
-		datum = dsprshort(ft);
-		if (got_int || feof(ft->fp))
-		    return(done);
-		/* Convert to unsigned */
-		datum ^= 0x8000;
-		/* scale signed up to long's range */
-		*buf++ = LEFT(datum, 16);
-		done++;
-	    }
-	    return done;
-	case ULAW:
-	    fail("No U-Law support for shorts");
-	    return done;
-	case ALAW:
-	    fail("No A-Law support");
-	    return done;
-	}
-    }
-    fail("Drop through in sunread!");
-
-    /* Return number of samples read */
-    return(done);
-}
-
-/*
- * Do anything required when you stop reading samples.
- * Don't close input file!
- */
-void sunstopread(ft)
-ft_t ft;
-{
-}
-
 void sunstartwrite(ft)
 ft_t ft;
 {
@@ -291,9 +124,12 @@
     audio_info_t audio_if;
 
     /* Hard code for now. */
-    abuf_size = 1024;
-    if ((audiobuf = malloc (abuf_size)) == NULL) {
-	fail("unable to allocate output buffer of size %d", abuf_size);
+    ft->file.count = 0;
+    ft->file.pos = 0;
+    ft->file.eof = 0;
+    ft->file.size = 1024;
+    if ((ft->file.buf = malloc (ft->file.size)) == NULL) {
+	fail("unable to allocate output buffer of size %d", ft->file.size);
     }
     
     if (ft->info.rate == 0.0) ft->info.rate = 8000;
@@ -356,123 +192,7 @@
     if (audio_if.play.encoding != encoding) {
 	fail("Unable to initialize style for /dev/audio");
     }
+    sigintreg(ft);
 }
 
-void dspflush(ft)
-ft_t ft;
-{
-    if (write (fileno(ft->fp), audiobuf, abuf_cnt) != abuf_cnt) {
-	fail("Error writing to sound driver");
-    }
-    abuf_cnt = 0;
-}
-
-void dspput(ft,c)
-ft_t ft;
-int c;
-{
-    if (abuf_cnt > abuf_size-1) dspflush(ft);
-    *(audiobuf + abuf_cnt) = c;
-    abuf_cnt++;
-}
-
-/* Write short. */
-void
-dspshort(ft,ui)
-ft_t ft;
-unsigned short ui;
-{
-    if (abuf_cnt > abuf_size-2) dspflush(ft);
-    *((unsigned short *)(audiobuf + abuf_cnt)) = ui;
-    abuf_cnt += 2;
-}
-
-void sunwrite(ft, buf, len)
-ft_t ft;
-LONG *buf, len;
-{
-    register int datum;
-    int done = 0;
-
-    switch(ft->info.size) {
-    case BYTE:
-	switch(ft->info.style) {
-	case SIGN2:
-	    while(done < len) {
-		/* scale signed up to long's range */
-		datum = RIGHT(*buf++, 24);
-		dspput(ft,datum);
-		done++;
-	    }
-	    return;
-	case UNSIGNED:
-	    while(done < len) {
-		/* scale signed up to long's range */
-		datum = RIGHT(*buf++, 24);
-		/* Convert to unsigned */
-		datum ^= 128;
-		dspput(ft,datum);
-		done++;
-	    }
-	    return;
-	case ULAW:
-	    while(done < len) {
-		/* scale signed up to long's range */
-		datum = (int) RIGHT(*buf++, 16);
-		/* round up to 12 bits of data */
-		datum += 0x8;	/* + 0b1000 */
-		datum = st_linear_to_ulaw(datum);
-		dspput(ft,datum);
-		done++;
-	    }
-	    return;
-	case ALAW:
-	    while(done < len) {
-		/* scale signed up to long's range */
-		datum = RIGHT(*buf++, 16);
-		/* round up to 12 bits of data */
-		datum += 0x8;	/* + 0b1000 */
-		datum = st_linear_to_Alaw(datum);
-		dspput(ft,datum);
-		done++;
-	    }
-	    return;
-	}
-    case WORD:
-	switch(ft->info.style) {
-	case SIGN2:
-	    while(done < len) {
-		/* scale signed up to long's range */
-		datum = RIGHT(*buf++, 16);
-		dspshort(ft,datum);
-		done++;
-	    }
-	    return;
-	case UNSIGNED:
-	    while(done < len) {
-		/* scale signed up to long's range */
-		datum = RIGHT(*buf++, 16);
-		/* Convert to unsigned */
-		datum ^= 0x8000;
-		dspshort(ft,datum);
-		done++;
-	    }
-	    return;
-	case ULAW:
-	    fail("No U-Law support for words");
-	    return;
-	case ALAW:
-	    fail("No A-Law support for words");
-	    return;
-	}
-    }
-
-    fail("Drop through in sunwrite!");
-}
-
-void sunstopwrite(ft)
-ft_t ft;
-{
-    dspflush(ft);
-}
 #endif
--- a/src/wav.c
+++ b/src/wav.c
@@ -945,6 +945,9 @@
 wavstopwrite(ft) 
 ft_t ft;
 {
+	/* Call this to flush out any remaining data. */
+	rawstopwrite(ft);
+
 	/* All samples are already written out. */
 	/* If file header needs fixing up, for example it needs the */
  	/* the number of samples in a field, seek back and write them here. */
@@ -954,9 +957,6 @@
 		fail("Sorry, can't rewind output file to rewrite .wav header.");
 	((wav_t) ft->priv)->second_header = 1;
 	wavwritehdr(ft);
-
-	/* Needed for rawwrite() */
-	rawstopwrite(ft);
 }
 
 /*