[SDL] newbie is back :)

Dave Ashley (SDL list) sdl at xdr.com
Thu Aug 5 10:08:33 PDT 1999

>But, I wanted to half all samples volume, by multiplying every
>byte for 128 instead 256..but , in this way, I obtained not
>an half volume sample..but a  noisy and lousy sample..only similar
>to original...
>The question is..WHY? :)

Samples are either signed or unsigned. Your problem is symptomatic of
getting the sign of the samples different from the sign of the audio device.
So during a waveform that is smooth, you're actually wrapping around to the
opposite end of the range of values (causing a discontinuity).

Probably you could fix your problem by doing the multiply by 256, then
shifting it right by 1 bit but duplicate the sign bit.

Best thing is to set the audio device to expect signed samples, make sure
your 8 bit samples are signed, and converting to 16 bits by multiplying by
128 or 256 should work fine. Summing signed samples is easier also, you
only have to clip once and you can sum a variable number of samples without

More information about the SDL mailing list