libaudiofile and endian-ness

I've been able to make libaudiofile, esd, and sound work on a few applications
for Solaris, 16 bit WAV's and etc.

The problem is as points out, the endian-ness is hard-wired
everywhere to little-endian, or Intel. This is fine as long as you are trying to
run sound on a PC. But Sparcs, and probably powerPC's, etc. will have problems,
varying from total silence to white noise.

The problem is complexicated by the fact that most applications are unnecessarily setting
the endian-ness; so both libaudiofile and the application need to be modified to make 
sound work on bigendian machines.

There was one other complication related to endian-ness in libaudiofile, with WAV
files; the header strings weren't comparing right and would cause a crash.
I've sent fixes in, but changes to esd, libaudiofile, etc. are still pending. What, in 
my not-always-so-humble-opinion (IMNASHO), needs to be done is:

1. No application should call afSetVirtualByteOrder(); libaudiofile calls it when you do
   an afOpenFile.

2. libaudiofile needs to calculate the byteorder at Configure time, and use macros in the
   code to set up the endianness of the machine it's running on.

Here is a fix I included to avoid the crash on wave files in audiofile-0.1.6:

Only in Makefile
Only in audiofile-config
diff -ru audiofile-0.1.6/audiofile.spec
--- audiofile-0.1.6/audiofile.spec	Thu Feb 25 07:59:39 1999
+++	Sat Mar 13 11:58:37 1999
@@ -51,7 +51,7 @@
 %defattr(-, root, root)
+%doc COPYING TODO README ChangeLog docs
Only in config.cache
Only in config.h
Only in config.log
Only in config.status
Only in Makefile
Only in .libs
Only in Makefile
Only in aes.lo
Only in aes.o
Only in aiff.lo
Only in aiff.o
Only in aiffwrite.lo
Only in aiffwrite.o
Only in au.lo
Only in au.o
Only in audiofile.lo
Only in audiofile.o
Only in aupv.lo
Only in aupv.o
Only in auwrite.lo
Only in auwrite.o
Only in bread.lo
Only in bread.o
Only in bwrite.lo
Only in bwrite.o
Only in byteorder.lo
Only in byteorder.o
Only in error.lo
Only in error.o
Only in extended.lo
Only in extended.o
Only in instrument.lo
Only in instrument.o
Only in
Only in loop.lo
Only in loop.o
Only in marker.lo
Only in marker.o
Only in misc.lo
Only in misc.o
Only in swapblock.lo
Only in swapblock.o
Only in track.lo
Only in track.o
Only in ulaw.lo
Only in ulaw.o
Only in util.lo
Only in util.o
diff -ru audiofile-0.1.6/libaudiofile/wave.c
--- audiofile-0.1.6/libaudiofile/wave.c	Mon Feb 22 11:06:08 1999
+++	Sat Mar 13 13:21:58 1999
@@ -118,13 +118,13 @@
 	/* include the offset of the form type */
 	while (index < size)
-		u_int32_t	chunkid, chunksize;
+		u_int32_t	chunkid1, chunkid2, chunksize;
 #ifdef DEBUG
 		printf("index: %d\n", index);
-		fread(&chunkid, 4, 1, file->fp);
-		chunkid = LENDIAN_TO_HOST_INT32(chunkid);
+		fread(&chunkid1, 4, 1, file->fp);
+		chunkid2 = LENDIAN_TO_HOST_INT32(chunkid1);
 		fread(&chunksize, 4, 1, file->fp);
 		chunksize = LENDIAN_TO_HOST_INT32(chunksize);
@@ -134,10 +134,14 @@
 		printf(" size: %d\n", chunksize);
-		if (memcmp (&chunkid, "data", 4) == 0)
-			ParseData(file, file->fp, chunkid, chunksize);
-		else if (memcmp (&chunkid, "fmt ", 4) == 0)
-			ParseFormat(file, file->fp, chunkid, chunksize);
+		if (memcmp (&chunkid1, "data", 4) == 0)
+			ParseData(file, file->fp, chunkid1, chunksize);
+		else if ( memcmp (&chunkid2, "data", 4) == 0)
+			ParseData(file, file->fp, chunkid2, chunksize);
+		else if (memcmp (&chunkid1, "fmt ", 4) == 0)
+			ParseFormat(file, file->fp, chunkid1, chunksize);
+		else if(memcmp (&chunkid2, "fmt ", 4) == 0)
+			ParseFormat(file, file->fp, chunkid2, chunksize);
 		index += chunksize + 8;
Only in wave.c~
Only in wave.lo
Only in wave.o
Only in wavewrite.lo
Only in wavewrite.o
Only in write.lo
Only in write.o
Only in libtool
Only in Makefile
Only in printinfo.o
Only in sfconvert
Only in sfconvert.o
Only in sfinfo
Only in sfinfo.o
Only in stamp-h
Only in Makefile
Only in addcoffset
Only in adddcoffset.o
Only in copy
Only in copy.o
Only in miscread
Only in miscread.o
Only in miscwrite
Only in miscwrite.o
Only in results
Only in results.o
Only in testaupv
Only in testaupv.o
Only in transparency
Only in transparency.o

Oops, on #1 above, I said "libaudiofile **calls** it" but I really should have said, "libaudiofile
**sets*** it", as the code really just sets the VirtualByteOrder in the file structure to
LITTLE endian or BIG endian.

Then, just make sure that you examine all sets of 

code that set the value of ->virtualByteOrder in libaudiofile/audiofile.c.

For enlightenment, check "sound.c", if my memory is correct. 

In esd, I made and sent in a chunk of changes; I'm not sure they got included in
0.2.8... I just double check new releases to see if they are still needed.

I don't know how many applications need to be changed to remove calls to afSetVirtualByteOrder();
it could end up being quite a few if they support sound.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]