[sdlsound] SDL_sound v2's internal mixer format...
Tyler Montbriand
tsm at accesscomm.ca
Tue Aug 10 11:08:46 EDT 2004
I accidentally sent that before I was ready, my apologies. Here's the
corrected code:
#include <stdio.h>
#include <SDL/SDL_types.h>
typedef union intfloat
{
Uint32 ival;
float fval;
} intfloat;
/* Converts an int into a float with range [-1.0,1.0) */
float quickfloat(Uint16 val)
{
/* 2.0f: 01000000 00000000 00000000 00000000 b */
intfloat f;
f.ival=0x40000000|(val<<7));
return(f.fval-3.0f);
}
int main(int argc, char *argv[])
{
int n;
Uint16 vals[]={0x0000,0x8000,0xffff};
for(n=0; n<3; n++)
printf("%5i -> %f\n",vals[n],quickfloat(vals[n]));
return(0);
}
> From a conceptual point of view, it seems that float
> is the "proper" way of handling clipping.
True, it'll never clip, but that can actually be a problem; instead of
clipping, it loses accuracy.
> (As graphics have moved from int to float, I kind of expect audio to
> do the same.)
Actually, graphics are still integer. OpenGL can take floats(but it doesn't
have to), but it still renders to integers. The movement to floating-point
audio kind of already happened with formats like MP3.
More information about the sdlsound
mailing list