shithub: sox

Download patch

ref: 6d2efb5fa5417b1bf2c7c37e1c6220ec74f591fa
parent: e993a7636065d7bcb1bf135da5e0e2ee1f25f041
author: cbagwell <cbagwell>
date: Sun Aug 13 14:04:29 EDT 2000

Adding initial support for NIST Sphere file formats.

--- a/Makefile.dos
+++ b/Makefile.dos
@@ -13,7 +13,8 @@
 FOBJ	= 8svx.obj adpcm.obj aiff.obj alsa.obj au.obj auto.obj avr.obj cdr.obj \
 	  cvsd.obj dat.obj g721.obj g723_24.obj g723_40.obj g72x.obj gsm.obj \
 	  hcom.obj ima_rw.obj maud.obj oss.obj raw.obj sf.obj smp.obj \
-	  sndrtool.obj sunaudio.obj tx16w.obj voc.obj wav.obj wve.obj
+	  sndrtool.obj sphere.obj sunaudio.obj tx16w.obj voc.obj \
+	  wav.obj wve.obj
 
 EOBJ	= avg.obj band.obj bandpass.obj breject.obj btrworth.obj chorus.obj \
 	  compand.obj copy.obj cut.obj deemphas.obj echo.obj \
--- a/Makefile.gcc
+++ b/Makefile.gcc
@@ -30,8 +30,8 @@
 
 FOBJ	= 8svx.o adpcm.o aiff.o alsa.o au.o auto.o avr.o cdr.o cvsd.o dat.o \
 	  g721.o g723_24.o g723_40.o g72x.o gsm.o hcom.o ima_rw.o maud.o \
-	  oss.o raw.o sf.o smp.o sndrtool.o sunaudio.o tx16w.o voc.o wav.o \
-	  wve.o
+	  oss.o raw.o sf.o smp.o sndrtool.o sphere.o sunaudio.o tx16w.o \
+	  voc.o wav.o wve.o
 
 EOBJ    = avg.o band.o bandpass.o breject.o btrworth.o chorus.o compand.o \
           copy.o cut.o deemphas.o echo.o echos.o filter.o flanger.o \
--- a/TODO
+++ b/TODO
@@ -1,8 +1,6 @@
 People are encouraged to pick some of these and implement it.  Send
 all patches to cbagwell@sprynet.com.
 
-  o SJB: The old highp.c filter is IMHO broken, need to review that code.
-
   o All comment code has a memory leak.  They must malloc memory to
     store comment but its never free()'d.
 
@@ -9,9 +7,6 @@
   o Create a version of OSS and Sun driver that can play and record from the
     same device in duplex.
 
-  o Internally sox can handle multiple effects on a given sound file.
-    Add support for this from the command line.
-
   o Add support for mixing multiple inputs from command line.
 
   o Endian checks are probably invalid on 64-bit machines.  Need to use
@@ -34,7 +29,7 @@
 
   o Comment strings.  Some file formats have space for embedded comments.
     These are currently thrown away.  Printing them out, carrying them
-    forward, and an to add new ones would be handy.
+    forward, and an option to add new ones would be handy.
 
   o Add support for .TXT format as Cooledit supports.  Not really fit for
     graphing since it is only a stream of ascii sample values but some
@@ -43,17 +38,14 @@
 
   o Update auto file type to include detection of .wve and .smp files.
 
-  o This software wants to be a dataflow system with signal
-    sources, sinks, and processors.  It wants to be class-based.
-    It wants to have a scripting control language.
-    It's really a shame I hate C++.
-
   o Keep sox from using "fail" on errors.  Sox was supposed to be
     a sound library called "ST" but libraries shouldn't exit a program,
-    they should return error codes for users to handle.
+    they should return error codes for users to handle.  Initial support
+    for this has been added.  Needs to be completed.
 
   o Enhance general robustness... For instance, malloc is called in
-    lots of places without checking its return value.
+    lots of places without checking its return value.  See last option
+    as well.
 
 SOX includes skeleton format files to assist you in supporting new 
 formats, sound effect loops, and special-purpose programs.
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -43,7 +43,7 @@
 
 FOBJ	= 8svx.o adpcm.o aiff.o au.o auto.o avr.o cdr.o cvsd.o dat.o g721.o \
 	  g723_24.o g723_40.o g72x.o gsm.o hcom.o ima_rw.o maud.o raw.o \
-	  sf.o smp.o sndrtool.o tx16w.o voc.o wav.o wve.o
+	  sf.o smp.o sndrtool.o sphere.o tx16w.o voc.o wav.o wve.o
 
 EOBJ	= avg.o band.o bandpass.o breject.o btrworth.o chorus.o compand.o \
 	  copy.o cut.o deemphas.o echo.o echos.o filter.o flanger.o \
--- a/src/handlers.c
+++ b/src/handlers.c
@@ -231,6 +231,16 @@
 extern LONG st_sndtwrite();
 extern int  st_sndtstopwrite();
 
+static char *spherenames[] = {
+	"sph",
+	(char *) 0
+};
+
+extern int  st_spherestartread();
+extern LONG st_sphereread();
+extern int  st_spherestartwrite();
+extern int  st_spherestopwrite();
+
 #if	defined(SUNAUDIO_PLAYER)
 static char *sunnames[] = {
 	"sunau",
@@ -409,6 +419,9 @@
 	{sndtnames, ST_FILE_STEREO,		/* Sndtool Sound File */
 		st_sndtstartread, st_rawread, st_rawstopread, 
 		st_sndtstartwrite, st_sndtwrite, st_sndtstopwrite},
+	{spherenames, ST_FILE_STEREO,		/* NIST Sphere File */
+	        st_spherestartread, st_sphereread, st_rawstopread,
+		st_spherestartwrite, st_rawwrite, st_spherestopwrite},
 #if	defined(SUNAUDIO_PLAYER)
 	{sunnames, ST_FILE_STEREO,		/* Sun /dev/audio player */
 		st_sunstartread, st_rawread, st_rawstopread,
--- a/src/misc.c
+++ b/src/misc.c
@@ -47,11 +47,38 @@
 
 /* Utilities */
 
+/* Read in a buffer of data of length len and each element is size bytes.
+ * Returns number of elements read, not bytes read.
+ */
+
+LONG st_read(ft, buf, size, len)
+ft_t ft;
+void *buf;
+int size;
+LONG len;
+{
+    return fread(buf, size, len, ft->fp);
+}
+
+/* Write a buffer of data of length len and each element is size bytes.
+ * Returns number of elements writen, not bytes writen.
+ */
+
+LONG st_write(ft, buf, size, len)
+ft_t ft;
+void *buf;
+int size;
+LONG len;
+{
+    return fwrite(buf, size, len, ft->fp);
+}
+
 /* Read and write known datatypes in "machine format".  Swap if indicated.
  * They all return ST_EOF on error and ST_SUCCESS on success.
  */
-
-/* Read n-char string (and possibly null-terminating). */
+/* Read n-char string (and possibly null-terminating). 
+ * Stop reading and null-terminate string if either a 0 or \n is reached. 
+ */
 int
 st_reads(ft, c, len)
 ft_t ft;
@@ -69,7 +96,7 @@
 	    *sc = 0;
 	    return (ST_EOF);
 	}
-	if (in == 0)
+	if (in == 0 || in == '\n')
 	{
 	    break;
 	}
--- a/src/oss.c
+++ b/src/oss.c
@@ -105,22 +105,42 @@
     }
 
     tmp = samplesize;
-    if (ioctl(fileno(ft->fp), SNDCTL_DSP_SAMPLESIZE, &tmp) < 0 || 
-	tmp != samplesize)
+    if (ioctl(fileno(ft->fp), SNDCTL_DSP_SAMPLESIZE, &tmp) < 0)
     {
 	st_fail("Unable to set the sample size to %d", samplesize);
 	return (ST_EOF);
     }
 
+    if (tmp != samplesize)
+    {
+	if (tmp == 16)
+	{
+	    st_warn("Sound card appears to only support singled word samples.  Overriding format");
+	    ft->info.size = ST_SIZE_WORD;
+	    ft->info.encoding = ST_ENCODING_SIGN2;
+	}
+	else if (tmp == 8)
+	{
+	    st_warn("Sound card appears to only support unsigned byte samples. Overriding format");
+	    ft->info.size = ST_SIZE_BYTE;
+	    ft->info.encoding = ST_ENCODING_UNSIGNED;
+	}
+    }
+
     if (ft->info.channels == 2) dsp_stereo = 1;
     else dsp_stereo = 0;
 
     tmp = dsp_stereo;
-    if (ioctl(fileno(ft->fp), SNDCTL_DSP_STEREO, &tmp) < 0 ||
-	tmp != dsp_stereo) {
-	ft->info.channels = 1;
+    if (ioctl(fileno(ft->fp), SNDCTL_DSP_STEREO, &tmp) < 0)
+    {
 	st_warn("Couldn't set to %s", dsp_stereo?  "stereo":"mono");
 	dsp_stereo = 0;
+    }
+
+    if (tmp != dsp_stereo)
+    {
+	st_warn("Sound card appears to only support %d channels.  Overriding format\n", tmp+1);
+	ft->info.channels = tmp + 1;
     }
 
     tmp = ft->info.rate;
--- a/src/st.h
+++ b/src/st.h
@@ -292,6 +292,8 @@
  * possible byte swapping.
  */
 /* declared in misc.c */
+LONG	st_read(P4(ft_t ft, void *buf, int size, LONG len));
+LONG	st_write(P4(ft_t ft, void *buf, int size, LONG len));
 int	st_reads(P3(ft_t ft, char *c, int len));
 int	st_writes(P2(ft_t ft, char *c));
 int	st_readb(P2(ft_t ft, unsigned char *uc));
--- a/src/stat.c
+++ b/src/stat.c
@@ -89,7 +89,7 @@
 		{
 			stat->fft = 1;
 		}
-		else if (!(strcmp(argv[0], "debug"))) {
+		else if (!(strcmp(argv[0], "-d"))) {
 			stat->volume = 2;
 		}
 		else