diff options
author | Chris Robinson <[email protected]> | 2023-05-23 05:49:09 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2023-05-23 05:49:09 -0700 |
commit | 55fb5c9c008216ba7ce18b4e43252ac1d1cedabe (patch) | |
tree | 41675136a482c95782c4de4f50fa9a93eea0f91d /al/filter.h | |
parent | 7f72f83fcb3d463d4e5db5d393fff8606f0e2763 (diff) |
Use a variant to call the proper filter handler function
Diffstat (limited to 'al/filter.h')
-rw-r--r-- | al/filter.h | 44 |
1 files changed, 23 insertions, 21 deletions
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 <variant> #include "AL/al.h" #include "AL/alc.h" @@ -12,6 +13,25 @@ #define HIGHPASSFREQREF 250.0f +template<typename T> +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<NullFilterTable> { }; +struct LowpassFilterTable : public FilterTable<LowpassFilterTable> { }; +struct HighpassFilterTable : public FilterTable<HighpassFilterTable> { }; +struct BandpassFilterTable : public FilterTable<BandpassFilterTable> { }; + + 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<NullFilterTable,LowpassFilterTable,HighpassFilterTable, + BandpassFilterTable>; + 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() }; |