mirror of
https://github.com/love2d/love.git
synced 2026-08-17 11:00:31 +02:00
naming updated, Filters patched up
--HG-- branch : minor
This commit is contained in:
@@ -39,7 +39,7 @@ Filter::Filter()
|
||||
Filter::Filter(const Filter &s)
|
||||
: Filter()
|
||||
{
|
||||
setParams(s.getType(), s.getParams());
|
||||
setParams(s.getParams());
|
||||
}
|
||||
|
||||
Filter::~Filter()
|
||||
@@ -85,10 +85,10 @@ ALuint Filter::getFilter() const
|
||||
return filter;
|
||||
}
|
||||
|
||||
bool Filter::setParams(Type type, const std::vector<float> ¶ms)
|
||||
bool Filter::setParams(const std::map<Parameter, float> ¶ms)
|
||||
{
|
||||
this->type = type;
|
||||
this->params = params;
|
||||
type = static_cast<Type>(this->params[FILTER_TYPE]);
|
||||
|
||||
if (!generateFilter())
|
||||
return false;
|
||||
@@ -105,6 +105,7 @@ bool Filter::setParams(Type type, const std::vector<float> ¶ms)
|
||||
case TYPE_BANDPASS:
|
||||
alFilteri(filter, AL_FILTER_TYPE, AL_FILTER_BANDPASS);
|
||||
break;
|
||||
case TYPE_BASIC:
|
||||
case TYPE_MAX_ENUM:
|
||||
break;
|
||||
}
|
||||
@@ -116,25 +117,28 @@ bool Filter::setParams(Type type, const std::vector<float> ¶ms)
|
||||
return false;
|
||||
}
|
||||
|
||||
#define PARAMSTR(i,e,v) filter, AL_ ## e ## _ ## v, clampf(params[(i)], AL_ ## e ## _MIN_ ## v, AL_ ## e ## _MAX_ ## v, AL_ ## e ## _DEFAULT_ ## v)
|
||||
#define clampf(v,l,h) fmax(fmin((v),(h)),(l))
|
||||
#define PARAMSTR(i,e,v) filter,AL_##e##_##v,clampf(getValue(i,AL_##e##_DEFAULT_##v),AL_##e##_MIN_##v,AL_##e##_MAX_##v)
|
||||
switch (type)
|
||||
{
|
||||
case TYPE_LOWPASS:
|
||||
alFilterf(PARAMSTR(0,LOWPASS,GAIN));
|
||||
alFilterf(PARAMSTR(1,LOWPASS,GAINHF));
|
||||
alFilterf(PARAMSTR(FILTER_VOLUME,LOWPASS,GAIN));
|
||||
alFilterf(PARAMSTR(FILTER_HIGHGAIN,LOWPASS,GAINHF));
|
||||
break;
|
||||
case TYPE_HIGHPASS:
|
||||
alFilterf(PARAMSTR(0,HIGHPASS,GAIN));
|
||||
alFilterf(PARAMSTR(1,HIGHPASS,GAINLF));
|
||||
alFilterf(PARAMSTR(FILTER_VOLUME,HIGHPASS,GAIN));
|
||||
alFilterf(PARAMSTR(FILTER_LOWGAIN,HIGHPASS,GAINLF));
|
||||
break;
|
||||
case TYPE_BANDPASS:
|
||||
alFilterf(PARAMSTR(0,BANDPASS,GAIN));
|
||||
alFilterf(PARAMSTR(1,BANDPASS,GAINLF));
|
||||
alFilterf(PARAMSTR(2,BANDPASS,GAINHF));
|
||||
alFilterf(PARAMSTR(FILTER_VOLUME,BANDPASS,GAIN));
|
||||
alFilterf(PARAMSTR(FILTER_LOWGAIN,BANDPASS,GAINLF));
|
||||
alFilterf(PARAMSTR(FILTER_HIGHGAIN,BANDPASS,GAINHF));
|
||||
break;
|
||||
case TYPE_BASIC:
|
||||
case TYPE_MAX_ENUM:
|
||||
break;
|
||||
}
|
||||
#undef clampf
|
||||
#undef PARAMSTR
|
||||
//alGetError();
|
||||
|
||||
@@ -144,18 +148,19 @@ bool Filter::setParams(Type type, const std::vector<float> ¶ms)
|
||||
#endif
|
||||
}
|
||||
|
||||
const std::vector<float> &Filter::getParams() const
|
||||
const std::map<Filter::Parameter, float> &Filter::getParams() const
|
||||
{
|
||||
return params;
|
||||
}
|
||||
|
||||
//clamp values silently to avoid randomly throwing errors due to implementation differences
|
||||
float Filter::clampf(float val, float min, float max, float def)
|
||||
float Filter::getValue(Parameter in, float def) const
|
||||
{
|
||||
if (isnanf(val)) return def;
|
||||
else if (val < min) val = min;
|
||||
else if (val > max) val = max;
|
||||
return val;
|
||||
return params.find(in) == params.end() ? def : params.at(in);
|
||||
}
|
||||
|
||||
int Filter::getValue(Parameter in, int def) const
|
||||
{
|
||||
return params.find(in) == params.end() ? def : static_cast<int>(params.at(in));
|
||||
}
|
||||
|
||||
} //openal
|
||||
|
||||
@@ -61,15 +61,16 @@ public:
|
||||
virtual ~Filter();
|
||||
virtual Filter *clone();
|
||||
ALuint getFilter() const;
|
||||
virtual bool setParams(Type type, const std::vector<float> ¶ms);
|
||||
virtual const std::vector<float> &getParams() const;
|
||||
virtual bool setParams(const std::map<Parameter, float> ¶ms);
|
||||
virtual const std::map<Parameter, float> &getParams() const;
|
||||
|
||||
private:
|
||||
bool generateFilter();
|
||||
void deleteFilter();
|
||||
float clampf(float val, float min, float max, float def);
|
||||
float getValue(Parameter in, float def) const;
|
||||
int getValue(Parameter in, int def) const;
|
||||
ALuint filter = AL_FILTER_NULL;
|
||||
std::vector<float> params;
|
||||
std::map<Parameter, float> params;
|
||||
};
|
||||
|
||||
} //openal
|
||||
|
||||
@@ -1252,12 +1252,12 @@ int Source::getChannels() const
|
||||
return channels;
|
||||
}
|
||||
|
||||
bool Source::setFilter(love::audio::Filter::Type type, std::vector<float> ¶ms)
|
||||
bool Source::setFilter(std::map<Filter::Parameter, float> ¶ms)
|
||||
{
|
||||
if (!directfilter)
|
||||
directfilter = new Filter();
|
||||
|
||||
bool result = directfilter->setParams(type, params);
|
||||
bool result = directfilter->setParams(params);
|
||||
|
||||
#ifdef ALC_EXT_EFX
|
||||
if (valid)
|
||||
@@ -1289,12 +1289,11 @@ bool Source::setFilter()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Source::getFilter(love::audio::Filter::Type &type, std::vector<float> ¶ms)
|
||||
bool Source::getFilter(std::map<Filter::Parameter, float> ¶ms)
|
||||
{
|
||||
if (!directfilter)
|
||||
return false;
|
||||
|
||||
type = directfilter->getType();
|
||||
params = directfilter->getParams();
|
||||
|
||||
return true;
|
||||
@@ -1323,7 +1322,7 @@ bool Source::setSceneEffect(int slot, int effect)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Source::setSceneEffect(int slot, int effect, love::audio::Filter::Type type, std::vector<float> ¶ms)
|
||||
bool Source::setSceneEffect(int slot, int effect, std::map<Filter::Parameter, float> ¶ms)
|
||||
{
|
||||
if (slot < 0 || slot >= (int)sendtargets.size())
|
||||
return false;
|
||||
@@ -1333,7 +1332,7 @@ bool Source::setSceneEffect(int slot, int effect, love::audio::Filter::Type type
|
||||
if (!sendfilters[slot])
|
||||
sendfilters[slot] = new Filter();
|
||||
|
||||
sendfilters[slot]->setParams(type, params);
|
||||
sendfilters[slot]->setParams(params);
|
||||
|
||||
#ifdef ALC_EXT_EFX
|
||||
if (valid)
|
||||
@@ -1368,7 +1367,7 @@ bool Source::setSceneEffect(int slot)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Source::getSceneEffect(int slot, int &effect, love::audio::Filter::Type &type, std::vector<float> ¶ms)
|
||||
bool Source::getSceneEffect(int slot, int &effect, std::map<Filter::Parameter, float> ¶ms)
|
||||
{
|
||||
if (slot < 0 || slot >= (int)sendtargets.size())
|
||||
return false;
|
||||
@@ -1379,10 +1378,7 @@ bool Source::getSceneEffect(int slot, int &effect, love::audio::Filter::Type &ty
|
||||
effect = dynamic_cast<Audio*>(audiomodule())->getSceneEffectIndex(sendtargets[slot]);
|
||||
|
||||
if(sendfilters[slot])
|
||||
{
|
||||
type = sendfilters[slot]->getType();
|
||||
params = sendfilters[slot]->getParams();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -146,14 +146,14 @@ public:
|
||||
virtual float getAirAbsorptionFactor() const;
|
||||
virtual int getChannels() const;
|
||||
|
||||
virtual bool setFilter(love::audio::Filter::Type type, std::vector<float> ¶ms);
|
||||
virtual bool setFilter(std::map<Filter::Parameter, float> ¶ms);
|
||||
virtual bool setFilter();
|
||||
virtual bool getFilter(love::audio::Filter::Type &type, std::vector<float> ¶ms);
|
||||
virtual bool getFilter(std::map<Filter::Parameter, float> ¶ms);
|
||||
|
||||
virtual bool setSceneEffect(int slot, int effect);
|
||||
virtual bool setSceneEffect(int slot, int effect, love::audio::Filter::Type type, std::vector<float> ¶ms);
|
||||
virtual bool setSceneEffect(int slot, int effect, std::map<Filter::Parameter, float> ¶ms);
|
||||
virtual bool setSceneEffect(int slot);
|
||||
virtual bool getSceneEffect(int slot, int &effect, love::audio::Filter::Type &type, std::vector<float> ¶ms);
|
||||
virtual bool getSceneEffect(int slot, int &effect, std::map<Filter::Parameter, float> ¶ms);
|
||||
|
||||
virtual int getFreeBufferCount() const;
|
||||
virtual bool queue(void *data, size_t length, int dataSampleRate, int dataBitDepth, int dataChannels);
|
||||
|
||||
Reference in New Issue
Block a user