Make better use of the type range when converting from float

This commit is contained in:
Chris Robinson
2010-12-09 05:06:29 -08:00
parent d1ca8b4470
commit be3f3c4bf0
2 changed files with 38 additions and 46 deletions
+14 -22
View File
@@ -640,38 +640,30 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
}
static __inline ALfloat aluF2F(ALfloat Value)
static __inline ALfloat aluF2F(ALfloat val)
{
return Value;
return val;
}
static __inline ALshort aluF2US(ALfloat Value)
static __inline ALushort aluF2US(ALfloat val)
{
ALint i;
if(Value <= -1.0f) i = 0;
else if(Value >= 1.0f) i = 65535;
else i = (ALint)(Value*32767.0f) + 32768;
return ((ALushort)i);
if(val > 1.0f) return 65535;
if(val < -1.0f) return 0;
return (ALint)(val*32767.0f) + 32768;
}
static __inline ALshort aluF2S(ALfloat Value)
static __inline ALshort aluF2S(ALfloat val)
{
ALint i;
if(Value <= -1.0f) i = -32768;
else if(Value >= 1.0f) i = 32767;
else i = (ALint)(Value*32767.0f);
return ((ALshort)i);
if(val > 1.0f) return 32767;
if(val < -1.0f) return -32768;
return (ALint)(val*32767.0f);
}
static __inline ALubyte aluF2UB(ALfloat Value)
static __inline ALubyte aluF2UB(ALfloat val)
{
ALshort i = aluF2US(Value);
ALushort i = aluF2US(val);
return i>>8;
}
static __inline ALubyte aluF2B(ALfloat Value)
static __inline ALbyte aluF2B(ALfloat val)
{
ALshort i = aluF2S(Value);
ALshort i = aluF2S(val);
return i>>8;
}
+24 -24
View File
@@ -995,14 +995,14 @@ static __inline ALbyte Conv_ALbyte_ALuint(ALuint val)
{ return (val>>24)-128; }
static __inline ALbyte Conv_ALbyte_ALfloat(ALfloat val)
{
if(val >= 1.0f) return 127;
if(val <= -1.0f) return -128;
if(val > 1.0f) return 127;
if(val < -1.0f) return -128;
return (ALint)(val * 127.0f);
}
static __inline ALbyte Conv_ALbyte_ALdouble(ALdouble val)
{
if(val >= 1.0) return 127;
if(val <= -1.0) return -128;
if(val > 1.0) return 127;
if(val < -1.0) return -128;
return (ALint)(val * 127.0);
}
static __inline ALbyte Conv_ALbyte_ALmulaw(ALmulaw val)
@@ -1022,14 +1022,14 @@ static __inline ALubyte Conv_ALubyte_ALuint(ALuint val)
{ return val>>24; }
static __inline ALubyte Conv_ALubyte_ALfloat(ALfloat val)
{
if(val >= 1.0f) return 255;
if(val <= -1.0f) return 0;
if(val > 1.0f) return 255;
if(val < -1.0f) return 0;
return (ALint)(val * 127.0f) + 128;
}
static __inline ALubyte Conv_ALubyte_ALdouble(ALdouble val)
{
if(val >= 1.0) return 255;
if(val <= -1.0) return 0;
if(val > 1.0) return 255;
if(val < -1.0) return 0;
return (ALint)(val * 127.0) + 128;
}
static __inline ALubyte Conv_ALubyte_ALmulaw(ALmulaw val)
@@ -1049,14 +1049,14 @@ static __inline ALshort Conv_ALshort_ALuint(ALuint val)
{ return (val>>16)-32768; }
static __inline ALshort Conv_ALshort_ALfloat(ALfloat val)
{
if(val >= 1.0f) return 32767;
if(val <= -1.0f) return -32768;
if(val > 1.0f) return 32767;
if(val < -1.0f) return -32768;
return (ALint)(val * 32767.0f);
}
static __inline ALshort Conv_ALshort_ALdouble(ALdouble val)
{
if(val >= 1.0) return 32767;
if(val <= -1.0) return -32768;
if(val > 1.0) return 32767;
if(val < -1.0) return -32768;
return (ALint)(val * 32767.0);
}
static __inline ALshort Conv_ALshort_ALmulaw(ALmulaw val)
@@ -1076,14 +1076,14 @@ static __inline ALushort Conv_ALushort_ALuint(ALuint val)
{ return val>>16; }
static __inline ALushort Conv_ALushort_ALfloat(ALfloat val)
{
if(val >= 1.0f) return 65535;
if(val <= -1.0f) return 0;
if(val > 1.0f) return 65535;
if(val < -1.0f) return 0;
return (ALint)(val * 32767.0f) + 32768;
}
static __inline ALushort Conv_ALushort_ALdouble(ALdouble val)
{
if(val >= 1.0) return 65535;
if(val <= -1.0) return 0;
if(val > 1.0) return 65535;
if(val < -1.0) return 0;
return (ALint)(val * 32767.0) + 32768;
}
static __inline ALushort Conv_ALushort_ALmulaw(ALmulaw val)
@@ -1103,14 +1103,14 @@ static __inline ALint Conv_ALint_ALuint(ALuint val)
{ return val^0x80000000; }
static __inline ALint Conv_ALint_ALfloat(ALfloat val)
{
if(val >= 1.0f) return 2147483647;
if(val <= -1.0f) return -2147483648u;
if(val > 1.0f) return 2147483647;
if(val < -1.0f) return -2147483648u;
return (ALint)(val * 2147483647.0);
}
static __inline ALint Conv_ALint_ALdouble(ALdouble val)
{
if(val >= 1.0) return 2147483647;
if(val <= -1.0) return -2147483648u;
if(val > 1.0) return 2147483647;
if(val < -1.0) return -2147483648u;
return (ALint)(val * 2147483647.0);
}
static __inline ALint Conv_ALint_ALmulaw(ALmulaw val)
@@ -1130,14 +1130,14 @@ static __inline ALuint Conv_ALuint_ALuint(ALuint val)
{ return val; }
static __inline ALuint Conv_ALuint_ALfloat(ALfloat val)
{
if(val >= 1.0f) return 4294967295u;
if(val <= -1.0f) return 0;
if(val > 1.0f) return 4294967295u;
if(val < -1.0f) return 0;
return (ALint)(val * 2147483647.0) + 2147483648u;
}
static __inline ALuint Conv_ALuint_ALdouble(ALdouble val)
{
if(val >= 1.0) return 4294967295u;
if(val <= -1.0) return 0;
if(val > 1.0) return 4294967295u;
if(val < -1.0) return 0;
return (ALint)(val * 2147483647.0) + 2147483648u;
}
static __inline ALuint Conv_ALuint_ALmulaw(ALmulaw val)