summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2013-05-26 00:01:07 -0700
committerChris Robinson <[email protected]>2013-05-26 00:01:07 -0700
commit8808159d55a65cec92010622f63844e76644722c (patch)
tree7efadd52692b8558e1da4c476c3f63632e60d974
parent2759239754c4e9b7ff3f6d8a267c6a208dae48ed (diff)
Add helper macros to set an error and return, and use it in a few places
-rw-r--r--Alc/effects/chorus.c50
-rw-r--r--Alc/effects/dedicated.c17
-rw-r--r--Alc/effects/distortion.c65
-rw-r--r--OpenAL32/Include/alError.h10
4 files changed, 57 insertions, 85 deletions
diff --git a/Alc/effects/chorus.c b/Alc/effects/chorus.c
index 4dc6cd98..783e5642 100644
--- a/Alc/effects/chorus.c
+++ b/Alc/effects/chorus.c
@@ -289,17 +289,15 @@ void ALchorus_SetParami(ALeffect *effect, ALCcontext *context, ALenum param, ALi
switch(param)
{
case AL_CHORUS_WAVEFORM:
- if(val >= AL_CHORUS_MIN_WAVEFORM && val <= AL_CHORUS_MAX_WAVEFORM)
- props->Chorus.Waveform = val;
- else
- alSetError(context, AL_INVALID_VALUE);
+ if(!(val >= AL_CHORUS_MIN_WAVEFORM && val <= AL_CHORUS_MAX_WAVEFORM))
+ SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ props->Chorus.Waveform = val;
break;
case AL_CHORUS_PHASE:
- if(val >= AL_CHORUS_MIN_PHASE && val <= AL_CHORUS_MAX_PHASE)
- props->Chorus.Phase = val;
- else
- alSetError(context, AL_INVALID_VALUE);
+ if(!(val >= AL_CHORUS_MIN_PHASE && val <= AL_CHORUS_MAX_PHASE))
+ SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ props->Chorus.Phase = val;
break;
default:
@@ -317,36 +315,31 @@ void ALchorus_SetParamf(ALeffect *effect, ALCcontext *context, ALenum param, ALf
switch(param)
{
case AL_CHORUS_RATE:
- if(val >= AL_CHORUS_MIN_RATE && val <= AL_CHORUS_MAX_RATE)
- props->Chorus.Rate = val;
- else
- alSetError(context, AL_INVALID_VALUE);
+ if(!(val >= AL_CHORUS_MIN_RATE && val <= AL_CHORUS_MAX_RATE))
+ SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ props->Chorus.Rate = val;
break;
case AL_CHORUS_DEPTH:
- if(val >= AL_CHORUS_MIN_DEPTH && val <= AL_CHORUS_MAX_DEPTH)
- props->Chorus.Depth = val;
- else
- alSetError(context, AL_INVALID_VALUE);
+ if(!(val >= AL_CHORUS_MIN_DEPTH && val <= AL_CHORUS_MAX_DEPTH))
+ SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ props->Chorus.Depth = val;
break;
case AL_CHORUS_FEEDBACK:
- if(val >= AL_CHORUS_MIN_FEEDBACK && val <= AL_CHORUS_MAX_FEEDBACK)
- props->Chorus.Feedback = val;
- else
- alSetError(context, AL_INVALID_VALUE);
+ if(!(val >= AL_CHORUS_MIN_FEEDBACK && val <= AL_CHORUS_MAX_FEEDBACK))
+ SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ props->Chorus.Feedback = val;
break;
case AL_CHORUS_DELAY:
- if(val >= AL_CHORUS_MIN_DELAY && val <= AL_CHORUS_MAX_DELAY)
- props->Chorus.Delay = val;
- else
- alSetError(context, AL_INVALID_VALUE);
+ if(!(val >= AL_CHORUS_MIN_DELAY && val <= AL_CHORUS_MAX_DELAY))
+ SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ props->Chorus.Delay = val;
break;
default:
- alSetError(context, AL_INVALID_ENUM);
- break;
+ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
}
}
void ALchorus_SetParamfv(ALeffect *effect, ALCcontext *context, ALenum param, const ALfloat *vals)
@@ -368,8 +361,7 @@ void ALchorus_GetParami(ALeffect *effect, ALCcontext *context, ALenum param, ALi
break;
default:
- alSetError(context, AL_INVALID_ENUM);
- break;
+ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
}
}
void ALchorus_GetParamiv(ALeffect *effect, ALCcontext *context, ALenum param, ALint *vals)
@@ -398,7 +390,7 @@ void ALchorus_GetParamf(ALeffect *effect, ALCcontext *context, ALenum param, ALf
break;
default:
- alSetError(context, AL_INVALID_ENUM);
+ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
break;
}
}
diff --git a/Alc/effects/dedicated.c b/Alc/effects/dedicated.c
index 35d26cc0..9ed68af2 100644
--- a/Alc/effects/dedicated.c
+++ b/Alc/effects/dedicated.c
@@ -125,7 +125,7 @@ ALeffectStateFactory *ALdedicatedStateFactory_getFactory(void)
void ALdedicated_SetParami(ALeffect *effect, ALCcontext *context, ALenum param, ALint val)
-{ (void)effect;(void)param;(void)val; alSetError(context, AL_INVALID_ENUM); }
+{ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); (void)effect;(void)param;(void)val; }
void ALdedicated_SetParamiv(ALeffect *effect, ALCcontext *context, ALenum param, const ALint *vals)
{
ALdedicated_SetParami(effect, context, param, vals[0]);
@@ -136,15 +136,13 @@ void ALdedicated_SetParamf(ALeffect *effect, ALCcontext *context, ALenum param,
switch(param)
{
case AL_DEDICATED_GAIN:
- if(val >= 0.0f && isfinite(val))
- props->Dedicated.Gain = val;
- else
- alSetError(context, AL_INVALID_VALUE);
+ if(!(val >= 0.0f && isfinite(val)))
+ SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ props->Dedicated.Gain = val;
break;
default:
- alSetError(context, AL_INVALID_ENUM);
- break;
+ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
}
}
void ALdedicated_SetParamfv(ALeffect *effect, ALCcontext *context, ALenum param, const ALfloat *vals)
@@ -153,7 +151,7 @@ void ALdedicated_SetParamfv(ALeffect *effect, ALCcontext *context, ALenum param,
}
void ALdedicated_GetParami(ALeffect *effect, ALCcontext *context, ALenum param, ALint *val)
-{ (void)effect;(void)param;(void)val; alSetError(context, AL_INVALID_ENUM); }
+{ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); (void)effect;(void)param;(void)val; }
void ALdedicated_GetParamiv(ALeffect *effect, ALCcontext *context, ALenum param, ALint *vals)
{
ALdedicated_GetParami(effect, context, param, vals);
@@ -168,8 +166,7 @@ void ALdedicated_GetParamf(ALeffect *effect, ALCcontext *context, ALenum param,
break;
default:
- alSetError(context, AL_INVALID_ENUM);
- break;
+ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
}
}
void ALdedicated_GetParamfv(ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *vals)
diff --git a/Alc/effects/distortion.c b/Alc/effects/distortion.c
index 5be2215e..950ce109 100644
--- a/Alc/effects/distortion.c
+++ b/Alc/effects/distortion.c
@@ -280,17 +280,7 @@ ALeffectStateFactory *ALdistortionStateFactory_getFactory(void)
void ALdistortion_SetParami(ALeffect *effect, ALCcontext *context, ALenum param, ALint val)
-{
- const ALeffectProps *props = &effect->Props;
- switch(param)
- {
- default:
- alSetError(context, AL_INVALID_ENUM);
- break;
- }
- (void)props;
- (void)val;
-}
+{ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); (void)effect;(void)param;(void)val; }
void ALdistortion_SetParamiv(ALeffect *effect, ALCcontext *context, ALenum param, const ALint *vals)
{
ALdistortion_SetParami(effect, context, param, vals[0]);
@@ -301,43 +291,37 @@ void ALdistortion_SetParamf(ALeffect *effect, ALCcontext *context, ALenum param,
switch(param)
{
case AL_DISTORTION_EDGE:
- if(val >= AL_DISTORTION_MIN_EDGE && val <= AL_DISTORTION_MAX_EDGE)
- props->Distortion.Edge = val;
- else
- alSetError(context, AL_INVALID_VALUE);
+ if(!(val >= AL_DISTORTION_MIN_EDGE && val <= AL_DISTORTION_MAX_EDGE))
+ SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ props->Distortion.Edge = val;
break;
case AL_DISTORTION_GAIN:
- if(val >= AL_DISTORTION_MIN_GAIN && val <= AL_DISTORTION_MAX_GAIN)
- props->Distortion.Gain = val;
- else
- alSetError(context, AL_INVALID_VALUE);
+ if(!(val >= AL_DISTORTION_MIN_GAIN && val <= AL_DISTORTION_MAX_GAIN))
+ SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ props->Distortion.Gain = val;
break;
case AL_DISTORTION_LOWPASS_CUTOFF:
- if(val >= AL_DISTORTION_MIN_LOWPASS_CUTOFF && val <= AL_DISTORTION_MAX_LOWPASS_CUTOFF)
- props->Distortion.LowpassCutoff = val;
- else
- alSetError(context, AL_INVALID_VALUE);
+ if(!(val >= AL_DISTORTION_MIN_LOWPASS_CUTOFF && val <= AL_DISTORTION_MAX_LOWPASS_CUTOFF))
+ SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ props->Distortion.LowpassCutoff = val;
break;
case AL_DISTORTION_EQCENTER:
- if(val >= AL_DISTORTION_MIN_EQCENTER && val <= AL_DISTORTION_MAX_EQCENTER)
- props->Distortion.EQCenter = val;
- else
- alSetError(context, AL_INVALID_VALUE);
+ if(!(val >= AL_DISTORTION_MIN_EQCENTER && val <= AL_DISTORTION_MAX_EQCENTER))
+ SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ props->Distortion.EQCenter = val;
break;
case AL_DISTORTION_EQBANDWIDTH:
- if(val >= AL_DISTORTION_MIN_EQBANDWIDTH && val <= AL_DISTORTION_MAX_EQBANDWIDTH)
- props->Distortion.EQBandwidth = val;
- else
- alSetError(context, AL_INVALID_VALUE);
+ if(!(val >= AL_DISTORTION_MIN_EQBANDWIDTH && val <= AL_DISTORTION_MAX_EQBANDWIDTH))
+ SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ props->Distortion.EQBandwidth = val;
break;
default:
- alSetError(context, AL_INVALID_ENUM);
- break;
+ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
}
}
void ALdistortion_SetParamfv(ALeffect *effect, ALCcontext *context, ALenum param, const ALfloat *vals)
@@ -346,17 +330,7 @@ void ALdistortion_SetParamfv(ALeffect *effect, ALCcontext *context, ALenum param
}
void ALdistortion_GetParami(ALeffect *effect, ALCcontext *context, ALenum param, ALint *val)
-{
- const ALeffectProps *props = &effect->Props;
- switch(param)
- {
- default:
- alSetError(context, AL_INVALID_ENUM);
- break;
- }
- (void)props;
- (void)val;
-}
+{ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); (void)effect;(void)param;(void)val; }
void ALdistortion_GetParamiv(ALeffect *effect, ALCcontext *context, ALenum param, ALint *vals)
{
ALdistortion_GetParami(effect, context, param, vals);
@@ -387,8 +361,7 @@ void ALdistortion_GetParamf(ALeffect *effect, ALCcontext *context, ALenum param,
break;
default:
- alSetError(context, AL_INVALID_ENUM);
- break;
+ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
}
}
void ALdistortion_GetParamfv(ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *vals)
diff --git a/OpenAL32/Include/alError.h b/OpenAL32/Include/alError.h
index 0ade342d..b6186054 100644
--- a/OpenAL32/Include/alError.h
+++ b/OpenAL32/Include/alError.h
@@ -11,6 +11,16 @@ extern ALboolean TrapALError;
ALvoid alSetError(ALCcontext *Context, ALenum errorCode);
+#define SET_ERROR_AND_RETURN(ctx, err) do { \
+ alSetError((ctx), (err)); \
+ return; \
+} while(0)
+
+#define SET_AND_RETURN_ERROR(ctx, err) do { \
+ alSetError((ctx), (err)); \
+ return (err); \
+} while(0)
+
#ifdef __cplusplus
}
#endif