andrew@ambra.dk (Leif Andrew Rump) (06/12/90)
The reason I ask is that none of the documentation that I have access to
conform to the actual content of the files I found in
/usr/demo/SOUND/sounds neither that in /usr/demo/SOUND/man or SunOS 4.1
manuals!
The sample.au under 4.0.3 contained only data (about debug!) but under 4.1
a header which looks something like this
unsigned '.snd' ; magic number
unsigned offset ; header length
unsigned length ; data lengtgh
unsigned channels ; or encoding (1)
unsigned samples ; per second
unsigned encoding ; or channels (1)
4 * char title ; zterminated padded with 0's
char data ; sound
The title isn't mentioned anywhere in any of the documents and parts like
bytes per unit is missing completely!
BTW: Could somebody please explain to me - down to earth (I think that is
a Danish expression said in English!) - what signed/unsigned is (on a
SunSparc)! Or at least tell me why I have to write my programs like below:
#include <stdio.h>
main()
{
char tmp;
while ((tmp = getchar()) != EOF)
printf("%c", (tmp < 0) ? tmp : 128 - tmp);
}
I don't understand the: (tmp < 0) ? 128 - tmp : tmp; part. If I don't do
it my sound get mangled and looks very funny in the sound-tool
application. The lines below is from a program that generates sinus:
tmp = (128 + volume * sin((Hz * 2 * PI * nr) / SAMPLE / 10));
buffer[nr] = (tmp < 0) ? 128 - tmp : tmp;
Leif Andrew Rump, AmbraSoft AS, Stroedamvej 50, DK-2100 Copenhagen OE, Denmark
UUCP: andrew@ambra.dk, phone: +45 39 27 11 77 /
Currently at Scandinavian Airline Systems =======/
UUCP: andrew@resam.dk, phone: +45 32 32 22 79 \
SAS, RESAM Project Office, CPHML-V, P.O.BOX 150, DK-2770 Kastrup, Denmark
boissier@cs.utexas.edu (franck boissiere) (06/14/90)
From article <8823@brazos.Rice.edu>, by andrew@ambra.dk (Leif Andrew Rump): > > main() > { > char tmp; > > while ((tmp = getchar()) != EOF) > printf("%c", (tmp < 0) ? tmp : 128 - tmp); > } > > I don't understand the: (tmp < 0) ? 128 - tmp : tmp; part. If I don't do You'd better use bit masks rather than arithmetics. tmp & 128 means something (i.e. the eighth bit is set) and tmp & 127 means only the seven first bits are meaningful Franck BOISSIERE boissier@irisa.irisa.fr Prototyping Lab Manager boissier@ccettix.UUCP C.C.E.T.T. B.P. 59 boissier%irisa.irisa.fr@uunet.uu.net 35512 CESSON SEVIGNE CEDEX FRANCE
guy@uunet.uu.net (Guy Harris) (06/16/90)
>> I don't understand the: (tmp < 0) ? 128 - tmp : tmp; part. If I don't do > >You'd better use bit masks rather than arithmetics. tmp & 128 means >something (i.e. the eighth bit is set) and tmp & 127 means only the seven >first bits are meaningful The fact that the 8th bit is set just means that the value is, if considered signed, negative, and if considered unsigned, greater than 127. The crux of the biscuit is that he improperly declared "tmp" to be a "char"; "getchar()" returns an "int" value that's either in the range 0 through 255 on 8-bit-byte machines, or EOF (i.e., -1). If you stuff that value into a "char", Bad Things happen, such as the byte '\377' being indistinguishable from EOF on signed-char machines, or EOF turning into 255 and not comparing equal to EOF on unsigned-char machines. Another Bad Thing is that bytes in the unsigned range 128 through 255 get turned into negative values; the "(tmp < 0) ..." glop is attempting to compensate for that and turn them back into their proper positive values, but declaring "tmp" to be an "int" and not getting them turned into negative values in the first place is the proper fix.