aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2010-12-09 05:06:29 -0800
committerChris Robinson <[email protected]>2010-12-09 05:06:29 -0800
commitbe3f3c4bf03dd5800e25f0d3144f2e122bac2f94 (patch)
tree4c76feee964f98665a0c81f6fcf57485e895a3d1
parentd1ca8b44708bedf87002b85a7482aed5486d51cd (diff)
Make better use of the type range when converting from float
-rw-r--r--Alc/ALu.c36
-rw-r--r--OpenAL32/alBuffer.c48
2 files changed, 38 insertions, 46 deletions
diff --git a/Alc/ALu.c b/Alc/ALu.c
index 5b10fb54..e0fd5c9f 100644
--- a/Alc/ALu.c
+++ b/Alc/ALu.c
@@ -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;
}
diff --git a/OpenAL32/alBuffer.c b/OpenAL32/alBuffer.c
index 8bdfc8c1..30ca9ea8 100644
--- a/OpenAL32/alBuffer.c
+++ b/OpenAL32/alBuffer.c
@@ -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)