From 55fb5c9c008216ba7ce18b4e43252ac1d1cedabe Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 23 May 2023 05:49:09 -0700 Subject: Use a variant to call the proper filter handler function --- al/filter.h | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) (limited to 'al/filter.h') diff --git a/al/filter.h b/al/filter.h index 65a9e30f..2ed483cc 100644 --- a/al/filter.h +++ b/al/filter.h @@ -1,6 +1,7 @@ #ifndef AL_FILTER_H #define AL_FILTER_H +#include #include "AL/al.h" #include "AL/alc.h" @@ -12,6 +13,25 @@ #define HIGHPASSFREQREF 250.0f +template +struct FilterTable { + static void setParami(struct ALfilter*, ALenum, int); + static void setParamiv(struct ALfilter*, ALenum, const int*); + static void setParamf(struct ALfilter*, ALenum, float); + static void setParamfv(struct ALfilter*, ALenum, const float*); + + static void getParami(const struct ALfilter*, ALenum, int*); + static void getParamiv(const struct ALfilter*, ALenum, int*); + static void getParamf(const struct ALfilter*, ALenum, float*); + static void getParamfv(const struct ALfilter*, ALenum, float*); +}; + +struct NullFilterTable : public FilterTable { }; +struct LowpassFilterTable : public FilterTable { }; +struct HighpassFilterTable : public FilterTable { }; +struct BandpassFilterTable : public FilterTable { }; + + struct ALfilter { ALenum type{AL_FILTER_NULL}; @@ -21,31 +41,13 @@ struct ALfilter { float GainLF{1.0f}; float LFReference{HIGHPASSFREQREF}; - struct Vtable { - void (*const setParami )(ALfilter *filter, ALenum param, int val); - void (*const setParamiv)(ALfilter *filter, ALenum param, const int *vals); - void (*const setParamf )(ALfilter *filter, ALenum param, float val); - void (*const setParamfv)(ALfilter *filter, ALenum param, const float *vals); - - void (*const getParami )(const ALfilter *filter, ALenum param, int *val); - void (*const getParamiv)(const ALfilter *filter, ALenum param, int *vals); - void (*const getParamf )(const ALfilter *filter, ALenum param, float *val); - void (*const getParamfv)(const ALfilter *filter, ALenum param, float *vals); - }; - const Vtable *vtab{nullptr}; + using TableTypes = std::variant; + TableTypes mTypeVariant; /* Self ID */ ALuint id{0}; - void setParami(ALenum param, int value) { vtab->setParami(this, param, value); } - void setParamiv(ALenum param, const int *values) { vtab->setParamiv(this, param, values); } - void setParamf(ALenum param, float value) { vtab->setParamf(this, param, value); } - void setParamfv(ALenum param, const float *values) { vtab->setParamfv(this, param, values); } - void getParami(ALenum param, int *value) const { vtab->getParami(this, param, value); } - void getParamiv(ALenum param, int *values) const { vtab->getParamiv(this, param, values); } - void getParamf(ALenum param, float *value) const { vtab->getParamf(this, param, value); } - void getParamfv(ALenum param, float *values) const { vtab->getParamfv(this, param, values); } - DISABLE_ALLOC() }; -- cgit v1.2.3