Subject: pkg/15382: Endianess fixes for splay
To: None <gnats-bugs@gnats.netbsd.org>
From: None <martijnb@stack.nl>
List: netbsd-bugs
Date: 01/26/2002 18:50:28
>Number: 15382
>Category: pkg
>Synopsis: splay generates static on bigendian platforms
>Confidential: no
>Severity: serious
>Priority: low
>Responsible: pkg-manager
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sat Jan 26 09:51:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: Martijn van Buul
>Release: NetBSD 1.5.2
>Organization:
>Environment:
>Description:
Splay contains a few endian-related bugs. Apperently, the original
author was aware of them, and introduced some obvious compile-time
errors when splay is compiled on a bigendian machine. Ironically,
these "bugs" didn't even exist in the first place - the "little-
endian-only" code works on bigendian systems too. The NetBSD pkgsrc
contains two patches for splay (patch-ad and patch-ah), that
try to fix this, but fail. There is no endian-issue in that piece
of code; trying to "fix" it creates a bug.
Furthermore, the audiodevice is opened with audio format '16',
which is equal to "AMT_S16_LE" for historical reasons. Unfortunately,
it is also incorrect for bigendian systems. The "AFMT_S16_NE"
macro is better here - it translates to AFMT_S16_LE on little
endian systems, and to AFMT_S16_BE on big-endian ones.
I fixed this bug a long time ago for Mp3blaster (which uses the
same library), and submitted a fix to the author of splay, who
seems to have vanished, unfortunately.
>How-To-Repeat:
Run splay on a bigendian machine -> static.
>Fix:
Remove pkgsrc/sound/splay/patches/patch-ad and patch-ah
Apply the following patches on the source, and recompile.
These patches do not change the behaviour on little-endian systems;
they have been used in mp3blaster for over a year.
--- PATCHES - snip here ---
--- mpegsound/mpeglayer3.cc.orig Sat Jan 26 16:09:12 2002
+++ mpegsound/mpeglayer3.cc Sat Jan 26 16:00:29 2002
@@ -45,18 +45,9 @@
inline int Mpegbitwindow::getbits9(int bits)
{
register unsigned short a;
-
-#ifndef WORDS_BIGENDIAN
- {
- // int offset=(bitindex>>3)&(WINDOWSIZE-1);
int offset=bitindex>>3;
a=(((unsigned char)buffer[offset])<<8) | ((unsigned char)buffer[offset+1]);
- }
-#else
- // a=((unsigned short *)(buffer+((bixindex>>3)&(WINDOWSIZE-1))));
- a=((unsigned short *)(buffer+((bixindex>>3))));
-#endif
a<<=(bitindex&7);
bitindex+=bits;
@@ -769,7 +760,7 @@
for(i=0;i<e;)
{
const HUFFMANCODETABLE *h;
- register end;
+ register int end;
if (i<region1Start)
{
--- mpegsound/mpegsound_locals.h.orig Sat Jan 26 16:08:58 2002
+++ mpegsound/mpegsound_locals.h Sat Jan 26 15:59:14 2002
@@ -20,15 +20,9 @@
inline int Mpegtoraw::getbits9(int bits)
{
register unsigned short a;
-#ifndef WORDS_BIGENDIAN
- {
int offset=bitindex>>3;
a=(((unsigned char)buffer[offset])<<8) | ((unsigned char)buffer[offset+1]);
- }
-#else
- a=((unsigned short *)(buffer+((bixindex>>3))));
-#endif
a<<=(bitindex&7);
bitindex+=bits;
@@ -39,15 +33,9 @@
{
register unsigned short a;
-#ifndef WORDS_BIGENDIAN
- {
int offset=bitindex>>3;
a=(((unsigned char)buffer[offset])<<8) | ((unsigned char)buffer[offset+1]);
- }
-#else
- a=((unsigned short *)(buffer+((bixindex>>3))));
-#endif
--- mpegsound/mpegtoraw.orig Sat Jan 26 16:08:23 2002
+++ mpegsound/mpegtoraw.cc Sat Jan 26 16:03:03 2002
@@ -15,6 +15,7 @@
#include "mpegsound.h"
#include "mpegsound_locals.h"
+#include <soundcard.h>
#define MY_PI 3.14159265358979323846
@@ -618,7 +619,7 @@
if(frames<0)
{
frames=-frames;
- player->setsoundtype(outputstereo,16,
+ player->setsoundtype(outputstereo,AFMT_S16_NE,
frequencies[version][frequency]>>downfrequency);
}
bitindex+=8;
>Release-Note:
>Audit-Trail:
>Unformatted:
>System: NetBSD grannysmith.inet 1.5.2 NetBSD 1.5.2 (GRANNYSMITH) #11: Thu Jan 24 23:32:52 CET 2002 martijnb@grannysmith.inet:/usr/src/sys/arch/macppc/compile/GRANNYSMITH macppc