shithub: sox

Download patch

ref: 8a376c3c99401f239c80abbac11111a673aa2e1a
parent: 273089322f62e5b01d40228bf8095d9414f5d778
author: cbagwell <cbagwell>
date: Wed Feb 24 22:33:33 EST 1999

fixed rawread/writes for most handlers

--- a/sbdsp.c
+++ b/sbdsp.c
@@ -55,6 +55,9 @@
 	int off = 0;
 #endif
 
+	/* The following is needed to init block reads */
+	rawstartread(ft);
+
 	/* If you need to seek around the input file. */
 	if (0 && ! ft->seekable)
 		fail("SKEL input file must be a file, not a pipe");
@@ -102,6 +105,8 @@
 sbdspstopread(ft) 
 ft_t ft;
 {
+	rawstopread(ft);
+
 #ifdef SBLAST
 	ioctl(fileno(ft->fp), DSP_IOCTL_FLUSH, 0);
 #endif
@@ -115,6 +120,8 @@
 	int on = 1;
 #endif
 
+	rawstartwrite(ft);
+
 	/* If you have to seek around the output file */
 	if (0 && ! ft->seekable)
 		fail("Output .sbdsp file must be a file, not a pipe");
@@ -148,6 +155,9 @@
 sbdspstopwrite(ft) 
 ft_t ft;
 {
+	/* This is needed to flush out block writes */
+	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. */
--- a/src/aiff.c
+++ b/src/aiff.c
@@ -90,6 +90,8 @@
 	char *copyright;
 	char *nametext;
 
+	/* Needed because of rawread() */
+	rawstartread(ft);
 
 	/* AIFF is in Big Endian format.  Swap whats read in on Little */
 	/* Endian machines.                                            */
@@ -419,13 +421,15 @@
 	ULONG chunksize;
 
 	if (!ft->seekable)
-	    while (! feof(ft->fp)) {
+	{
+	    while (! feof(ft->fp)) 
+	    {
 		if (fread(buf, 1, 4, ft->fp) != 4)
-			return;
+			break;
 
 		chunksize = rlong(ft);
 		if (feof(ft->fp))
-			return;
+			break;
 		buf[4] = '\0';
 		warn("Ignoring AIFF tail chunk: '%s', %d bytes long\n", 
 			buf, chunksize);
@@ -432,9 +436,16 @@
 		if (! strcmp(buf, "MARK") || ! strcmp(buf, "INST"))
 			warn("	You're stripping MIDI/loop info!\n");
 		while ((LONG) (--chunksize) >= 0) 
+		{
 			if (getc(ft->fp) == EOF)
-				return;
+				break;
+		}
+	    }
 	}
+
+	/* Needed because of rawwrite() */
+	rawstopread(ft);
+
 	return;
 }
 
@@ -455,6 +466,9 @@
 	int littlendian;
 	char *endptr;
 
+	/* Needed because rawwrite() */
+	rawstartwrite(ft);
+
 	/* AIFF is in Big Endian format.  Swap whats read in on Little */
 	/* Endian machines.                                            */
 	littlendian = 1;
@@ -493,11 +507,15 @@
 ft_t ft;
 {
 	struct aiffpriv *p = (struct aiffpriv *) ft->priv;
+
 	if (!ft->seekable)
 		return;
 	if (fseek(ft->fp, 0L, SEEK_SET) != 0)
 		fail("can't rewind output file to rewrite AIFF header");
 	aiffwriteheader(ft, p->nsamples / ft->info.channels);
+
+	/* Needed because of rawwrite() */
+	rawstopwrite(ft);
 }
 
 void aiffwriteheader(ft, nframes)
--- a/src/au.c
+++ b/src/au.c
@@ -80,6 +80,9 @@
 	int littlendian = 1;
 	char *endptr;
 
+	/* Needed for rawread() */
+	rawstartread(ft);
+
 	endptr = (char *) &littlendian;
 	/* AU is in big endian format.  Swap whats read
 	 * in onlittle endian machines.
@@ -214,8 +217,8 @@
 	int littlendian = 1;
 	char *endptr;
 
-	p->data_size = 0;
-	auwriteheader(ft, SUN_UNSPEC);
+	/* Needed because of rawwrite(); */
+	rawstartread(ft);
 
 	endptr = (char *) &littlendian;
 	/* AU is in big endian format.  Swap whats read in
@@ -225,6 +228,9 @@
 	{
 		ft->swap = ft->swap ? 0 : 1;
 	}
+
+	p->data_size = 0;
+	auwriteheader(ft, SUN_UNSPEC);
 }
 
 /*
@@ -287,11 +293,15 @@
 ft_t ft;
 {
 	struct aupriv *p = (struct aupriv *) ft->priv;
+
 	if (!ft->seekable)
 		return;
 	if (fseek(ft->fp, 0L, 0) != 0)
 		fail("Can't rewind output file to rewrite Sun header.");
 	auwriteheader(ft, p->data_size);
+
+	/* Needed because of rawwrite() */
+	rawstopwrite(ft);
 }
 
 void auwriteheader(ft, data_size)
--- a/src/cdr.c
+++ b/src/cdr.c
@@ -49,6 +49,9 @@
 	int     littlendian = 1;
 	char    *endptr;
 
+	/* Needed because of rawread() */
+	rawstartread(ft);
+
 	endptr = (char *) &littlendian;
 	/* CDR is in Big Endian format.  Swap whats read in on */
         /* Little Endian machines.                             */
@@ -86,6 +89,8 @@
 void cdrstopread(ft) 
 ft_t ft;
 {
+	/* Needed because of rawread() */
+	rawstopread(ft);
 }
 
 void cdrstartwrite(ft) 
@@ -104,6 +109,9 @@
 	    ft->swap = ft->swap ? 0 : 1;
 	}
 
+	/* Needed because of rawwrite() */
+	rawstartwrite(ft);
+
 	cdr->samples = 0;
 
 	ft->info.rate = 44100L;
@@ -137,13 +145,14 @@
 
 	zero = 0;
 
-	if (padsamps == SECTORSIZE) {
-		return;
+	if (padsamps != SECTORSIZE) 
+	{
+		while (padsamps > 0) {
+			wshort(ft, zero);
+			padsamps--;
+		}
 	}
 
-	while (padsamps > 0) {
-		wshort(ft, zero);
-		padsamps--;
-	}
+	rawstopwrite(ft);
 }
 
--- a/src/handlers.c
+++ b/src/handlers.c
@@ -322,7 +322,7 @@
 		alstartread, rawread, rawstopread, 	   /* a-law byte raw */
 		alstartwrite, rawwrite, rawstopwrite},	
 	{aunames, FILE_STEREO,
-		austartread, auread, nothing,	       /* SPARC .AU w/header */
+		austartread, auread, rawstopread,      /* SPARC .AU w/header */
 		austartwrite, auwrite, austopwrite},	
 	{autonames, FILE_STEREO,
 		autostartread, nothing_success, nothing,/* Guess from header */
@@ -369,16 +369,16 @@
 		sbstartread, rawread, rawstopread, 	  /* signed byte raw */
 		sbstartwrite, rawwrite, rawstopwrite},	
 	{sfnames, FILE_STEREO,
-		sfstartread, rawread, nothing, 	         /* IRCAM Sound File */
-		sfstartwrite, rawwrite, nothing},	    /* Relies on raw */
+		sfstartread, rawread, rawstopread,       /* IRCAM Sound File */
+		sfstartwrite, rawwrite, rawstopwrite},
 	{smpnames, FILE_STEREO | FILE_LOOPS,
 		smpstartread, smpread, nothing,	       /* SampleVision sound */
 		smpstartwrite, smpwrite, smpstopwrite},	     /* Turtle Beach */
 	{sndrnames, FILE_STEREO,
-		sndtstartread, rawread, nothing,       /* Sounder Sound File */
-		sndrstartwrite, rawwrite, nothing},
+		sndtstartread, rawread, rawstopread,   /* Sounder Sound File */
+		sndrstartwrite, rawwrite, rawstopwrite},
 	{sndtnames, FILE_STEREO,
-		sndtstartread, rawread, nothing,       /* Sndtool Sound File */
+		sndtstartread, rawread, rawstopread,   /* Sndtool Sound File */
 		sndtstartwrite, sndtwrite, sndtstopwrite},
 #if	defined(SUNAUDIO_PLAYER)
 	/* Sun /dev/audio player. */
@@ -411,7 +411,7 @@
 		wavstartread, wavread, nothing, 	   /* Microsoft .wav */
 		wavstartwrite, wavwrite, wavstopwrite},	
 	{wvenames, 0,
-		wvestartread, wveread, nothing,                /* Psion .wve */
+		wvestartread, wveread, rawstopread,            /* Psion .wve */
 		wvestartwrite, wvewrite, wvestopwrite},
 	{0, 0,
 	 0, 0, 0, 0, 0, 0}
--- a/src/sf.c
+++ b/src/sf.c
@@ -83,6 +83,9 @@
 {
 	sf_t sf = (sf_t) ft->priv;
 	SFHEADER sfhead;
+
+	/* Needed for rawread() */
+	rawstartread(ft);
 	
 	if (fread(&sfhead, 1, sizeof(SFHEADER), ft->fp) != sizeof(SFHEADER))
 		fail("unexpected EOF in SF header");
@@ -145,6 +148,9 @@
 	char *sfcharp;
 	int littlendian = 1;
 	char *endptr;
+
+	/* Needed for rawwrite() */
+	rawstartwrite(ft);
 
 #ifdef	IRCAM
 	sf->info.magic_union._magic_bytes.sf_magic1 = SF_MAGIC1;
--- a/src/sndrtool.c
+++ b/src/sndrtool.c
@@ -34,6 +34,9 @@
 	int littlendian = 1;
 	char *endptr;
 
+	/* Needed for rawread() */
+	rawstartread(ft);
+
 	endptr = (char *) &littlendian;
 	/* sndt is in little endian format so 
 	 * swap bytes on big endian machines.
@@ -93,6 +96,9 @@
 	int littlendian = 1;
 	char *endptr;
 
+	/* Needed for rawwrite() */
+	rawstopwrite(ft);
+
 	endptr = (char *) &littlendian;
 	/* sndt is in little endian format so
 	 * swap bytes on big endian machines
@@ -154,6 +160,9 @@
 if (fseek(ft->fp, 0L, 0) != 0)
 	fail("can't rewind output file to rewrite SND header");
 sndtwriteheader(ft, p->nsamples);
+
+	/* Needed for rawwrite() */
+	rawstopwrite(ft);
 }
 
 /*======================================================================*/
--- a/src/wav.c
+++ b/src/wav.c
@@ -452,6 +452,9 @@
     ULONG    data_length;	    /* length of sound data in bytes */
     ULONG    bytespersample;	    /* bytes per sample (per channel */
 
+    /* This is needed for rawread() */
+    rawstartread(ft);
+
     endptr = (char *) &littlendian;
     if (!*endptr) ft->swap = ft->swap ? 0 : 1;
 
@@ -796,6 +799,9 @@
     if (wav->packet) free(wav->packet);
     if (wav->samples[0]) free(wav->samples[0]);
     if (wav->samples[1]) free(wav->samples[1]);
+
+    /* Needed for rawread() */
+    rawstopread(ft);
 }
 
 void wavstartwrite(ft) 
@@ -830,6 +836,9 @@
         ULONG  data_length;             	/* length of sound data in bytes */
 	ULONG  bytespersample; 			/* bytes per sample (per channel) */
 
+	/* Needed for rawwrite() */
+	rawstartwrite(ft);
+
 	switch (ft->info.size)
 	{
 		case BYTE:
@@ -945,6 +954,9 @@
 		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);
 }
 
 /*
--- a/src/wve.c
+++ b/src/wve.c
@@ -33,6 +33,9 @@
 	int littlendian = 1;
 	char *endptr;
 
+	/* Needed for rawread() */
+	rawstartread(ft);
+
 	endptr = (char *) &littlendian;
 	/* WVE is in big endian format.  Swap whats read in
 	 * on little endian machines.
@@ -110,6 +113,9 @@
 	int littlendian = 1;
 	char *endptr;
 
+	/* Needed for rawwrite() */
+	rawstartwrite(ft);
+
 	endptr = (char *) &littlendian;
 	/* wve is in big endian format.  Swap whats read in
 	 * on little endian machines.
@@ -152,9 +158,13 @@
 {
 	if (!ft->seekable)
 		return;
+
 	if (fseek(ft->fp, 0L, 0) != 0)
 		fail("Can't rewind output file to rewrite Psion header.");
 	wvewriteheader(ft);
+
+	/* Needed for rawwrite() */
+	rawstopwrite(ft);
 }
 
 void wvewriteheader(ft)