[PD] floating point soundfiles

Krzysztof Czaja czaja at chopin.edu.pl
Wed Jan 9 12:07:04 CET 2002


hi Miller,

soundfiler would read 32-bit float .wav files quite willingly, if
this possibility had not been blocked by rejecting their headers
-- would you accept them, please?

Adding ``...else if (format == 32) bytespersamp = 4;'' option to
.wav portion of open_soundfile() magically allows the soundfiler
to correctly load such sounds, at least if they were recorded in
Samplitude (I have not checked other editors).  Why this works?
Speaking in t_wave terms, soundfiler ignores w_fmttag (which is now
equal 3), w_navgbytespersec and w_nblockalign fields, using only
w_nbitspersample (equal 32) as a clue.  All other fields are generic,
and the original nextstep processing does the trick for sample data.

Btw, after taking closer look at soundfiler, I would like to know if
anybody has been using it to load .wav files containing extra chunks
before data chunk, such as recorded with WaveLab?  I had not been so
lucky (except in raw mode) without making little changes in the
sources.  With those changes soundfiler appears to gracefully skip
unknown chunks and read all the remaining data (both 16, and 24-bit).

All of this applies also to readsf~.  The changes are attached below.

Krzysztof

Miller Puckette wrote:
...
> soundfiler only knows about "nextstep" floating-point soundfiles, but can
> read Wav and Aiff 24-bit fixed files too.  I think there's a 23-bit
> floating point type defined fo Wav files, but I don't know what the 
> header looks like; someday I hope to find this out and support it.
-------------- next part --------------
--- d_soundfile.c~	Thu Aug 23 18:23:37 2001
+++ d_soundfile.c	Tue Jan  8 23:21:42 2002
@@ -254,20 +254,25 @@
 	    	bytespersamp = 2;
 	    else if (format == 24)
 	    	bytespersamp = 3;
+	    else if (format == 32)
+	    	bytespersamp = 4;
 	    else goto badheader;
 	    headersize = sizeof(t_wave);
 	    while (strncmp(((t_wave *)buf)->w_datachunkid, "data", 4))
 	    {
 	    	/* extra chunk at beginning: try to skip it and pray */
-		long skip = swap4(((t_wave *)buf)->w_datachunksize, swap) + 4;
+		long skip = swap4(((t_wave *)buf)->w_datachunksize, swap);
+#ifdef DEBUG
+		post("skipping unknown chunk (0x%08lX bytes)", skip);
+#endif
 		if ((skip < 4) || (lseek(fd, skip, SEEK_CUR) < 0))
 		{
 		    perror("lseek");
 		    post("confused by extra chunks in wave header?");
 		    goto badheader;
 		}
-		headersize += skip;
-		if (read(fd, buf, sizeof(t_wave)) < (int)sizeof(t_wave))
+		headersize += skip + 8;
+		if (read(fd, ((t_wave *)buf)->w_datachunkid, 8) < 8)
 		{
 		    perror("read");
 		    post("couldn't read past extra chunks in wave header?");


More information about the Pd-list mailing list