mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-15 07:51:50 +00:00
minor refactor
This commit is contained in:
parent
53ebe566b0
commit
3523816378
2 changed files with 33 additions and 25 deletions
|
|
@ -53,6 +53,8 @@ static LPALISFILTER alIsFilter = nullptr;
|
||||||
static LPALFILTERI alFilteri = nullptr;
|
static LPALFILTERI alFilteri = nullptr;
|
||||||
static LPALFILTERF alFilterf = nullptr;
|
static LPALFILTERF alFilterf = nullptr;
|
||||||
|
|
||||||
|
static inline constexpr int REVERB_EFFECT = 0;
|
||||||
|
static inline constexpr int LOWPASS_FILTER = 0;
|
||||||
|
|
||||||
ALSound::ALSound(
|
ALSound::ALSound(
|
||||||
ALAudio* al, uint buffer, const std::shared_ptr<PCM>& pcm, bool keepPCM
|
ALAudio* al, uint buffer, const std::shared_ptr<PCM>& pcm, bool keepPCM
|
||||||
|
|
@ -398,7 +400,7 @@ void ALSpeaker::play() {
|
||||||
));
|
));
|
||||||
if (al->useEffects) {
|
if (al->useEffects) {
|
||||||
AL_CHECK(alSource3i(source, AL_AUXILIARY_SEND_FILTER, al->effectSlots[0], 0, al->filters[0]));
|
AL_CHECK(alSource3i(source, AL_AUXILIARY_SEND_FILTER, al->effectSlots[0], 0, al->filters[0]));
|
||||||
//AL_CHECK(alSourcei(source, AL_DIRECT_FILTER, al->filters[0]));
|
//AL_CHECK(alSourcei(source, AL_DIRECT_FILTER, al->filters[LOWPASS_FILTER]));
|
||||||
}
|
}
|
||||||
AL_CHECK(alSourcePlay(source));
|
AL_CHECK(alSourcePlay(source));
|
||||||
}
|
}
|
||||||
|
|
@ -507,7 +509,7 @@ ALAudio::ALAudio(ALCdevice* device, ALCcontext* context, bool useEffects)
|
||||||
alGetError();
|
alGetError();
|
||||||
|
|
||||||
if (useEffects) {
|
if (useEffects) {
|
||||||
initEffects();
|
this->useEffects = initEffects();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -541,8 +543,8 @@ static bool get_proc_address(const char* name, T& ptr) {
|
||||||
return ptr != nullptr;
|
return ptr != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALAudio::initEffects() {
|
static bool request_efx_ext_functions() {
|
||||||
bool ok = get_proc_address("alAuxiliaryEffectSloti", alAuxiliaryEffectSloti)
|
return get_proc_address("alAuxiliaryEffectSloti", alAuxiliaryEffectSloti)
|
||||||
&& get_proc_address("alGenAuxiliaryEffectSlots", alGenAuxiliaryEffectSlots)
|
&& get_proc_address("alGenAuxiliaryEffectSlots", alGenAuxiliaryEffectSlots)
|
||||||
&& get_proc_address("alGenEffects", alGenEffects)
|
&& get_proc_address("alGenEffects", alGenEffects)
|
||||||
&& get_proc_address("alDeleteEffects", alDeleteEffects)
|
&& get_proc_address("alDeleteEffects", alDeleteEffects)
|
||||||
|
|
@ -553,12 +555,13 @@ void ALAudio::initEffects() {
|
||||||
&& get_proc_address("alDeleteFilters", alDeleteFilters)
|
&& get_proc_address("alDeleteFilters", alDeleteFilters)
|
||||||
&& get_proc_address("alIsFilter", alIsFilter)
|
&& get_proc_address("alIsFilter", alIsFilter)
|
||||||
&& get_proc_address("alFilteri", alFilteri)
|
&& get_proc_address("alFilteri", alFilteri)
|
||||||
&& get_proc_address("alFilterf", alFilterf)
|
&& get_proc_address("alFilterf", alFilterf);
|
||||||
;
|
}
|
||||||
if (!ok) {
|
|
||||||
|
bool ALAudio::initEffects() {
|
||||||
|
if (!request_efx_ext_functions()) {
|
||||||
logger.error() << "could not get effects extension function pointers";
|
logger.error() << "could not get effects extension function pointers";
|
||||||
useEffects = false;
|
return false;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
for (uint i = 0; i < maxEffectSlots; i++) {
|
for (uint i = 0; i < maxEffectSlots; i++) {
|
||||||
effectSlots.emplace_back();
|
effectSlots.emplace_back();
|
||||||
|
|
@ -574,8 +577,7 @@ void ALAudio::initEffects() {
|
||||||
alGenEffects(1, &effects[i]);
|
alGenEffects(1, &effects[i]);
|
||||||
if (alGetError() != AL_NO_ERROR || !alIsEffect(effects[i])) {
|
if (alGetError() != AL_NO_ERROR || !alIsEffect(effects[i])) {
|
||||||
logger.error() << "could not to create effect #" << i;
|
logger.error() << "could not to create effect #" << i;
|
||||||
useEffects = false;
|
return false;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logger.info() << "created " << effects.size() << " effects";
|
logger.info() << "created " << effects.size() << " effects";
|
||||||
|
|
@ -584,36 +586,32 @@ void ALAudio::initEffects() {
|
||||||
alGenFilters(1, &filters[i]);
|
alGenFilters(1, &filters[i]);
|
||||||
if (alGetError() != AL_NO_ERROR || !alIsFilter(filters[i])) {
|
if (alGetError() != AL_NO_ERROR || !alIsFilter(filters[i])) {
|
||||||
logger.error() << "could not to create filter #" << i;
|
logger.error() << "could not to create filter #" << i;
|
||||||
useEffects = false;
|
return false;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create reverb effect
|
// Create reverb effect
|
||||||
alEffecti(effects[0], AL_EFFECT_TYPE, AL_EFFECT_REVERB);
|
alEffecti(effects[REVERB_EFFECT], AL_EFFECT_TYPE, AL_EFFECT_REVERB);
|
||||||
if (alGetError() != AL_NO_ERROR) {
|
if (alGetError() != AL_NO_ERROR) {
|
||||||
logger.error() << "reverb effect is not supported";
|
logger.error() << "reverb effect is not supported";
|
||||||
useEffects = false;
|
return false;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
alEffectf(effects[0], AL_REVERB_DECAY_TIME, 1.0f);
|
|
||||||
alEffectf(effects[0], AL_REVERB_ROOM_ROLLOFF_FACTOR, 0.07f); // default is 0
|
|
||||||
|
|
||||||
// Create lowpass filter
|
// Create lowpass filter
|
||||||
alFilteri(filters[0], AL_FILTER_TYPE, AL_FILTER_LOWPASS);
|
alFilteri(filters[LOWPASS_FILTER], AL_FILTER_TYPE, AL_FILTER_LOWPASS);
|
||||||
if (alGetError() != AL_NO_ERROR) {
|
if (alGetError() != AL_NO_ERROR) {
|
||||||
logger.error() << "lowpass filter is not supported";
|
logger.error() << "lowpass filter is not supported";
|
||||||
useEffects = false;
|
return false;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
alFilterf(filters[0], AL_LOWPASS_GAIN, 1.0f);
|
alFilterf(filters[LOWPASS_FILTER], AL_LOWPASS_GAIN, 1.0f);
|
||||||
alFilterf(filters[0], AL_LOWPASS_GAINHF, 0.1f);
|
alFilterf(filters[LOWPASS_FILTER], AL_LOWPASS_GAINHF, 0.01f);
|
||||||
|
|
||||||
// Attach effect to aux effect slot
|
// Attach effect to aux effect slot
|
||||||
alAuxiliaryEffectSloti(effectSlots[0], AL_EFFECTSLOT_EFFECT, effects[0]);
|
alAuxiliaryEffectSloti(effectSlots[0], AL_EFFECTSLOT_EFFECT, effects[0]);
|
||||||
if (alGetError() == AL_NO_ERROR) {
|
if (alGetError() == AL_NO_ERROR) {
|
||||||
logger.info() << "successfully loaded effect into effect slot";
|
logger.info() << "successfully loaded effect into effect slot";
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Sound> ALAudio::createSound(
|
std::unique_ptr<Sound> ALAudio::createSound(
|
||||||
|
|
@ -782,5 +780,15 @@ void ALAudio::setListener(
|
||||||
AL_CHECK(alListenerf(AL_GAIN, get_channel(0)->getVolume()));
|
AL_CHECK(alListenerf(AL_GAIN, get_channel(0)->getVolume()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALAudio::update(double) {
|
void ALAudio::update(double delta) {
|
||||||
|
if (!useEffects) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int reverbEffect = effects[REVERB_EFFECT];
|
||||||
|
AL_CHECK(alEffectf(reverbEffect, AL_REVERB_DECAY_TIME, 1.0f));
|
||||||
|
AL_CHECK(alEffectf(reverbEffect, AL_REVERB_ROOM_ROLLOFF_FACTOR, 0.07f));
|
||||||
|
AL_CHECK(alEffectf(reverbEffect, AL_REVERB_GAIN, 0.0f));
|
||||||
|
AL_CHECK(alEffectf(reverbEffect, AL_REVERB_GAINHF, 0.0f));
|
||||||
|
AL_CHECK(alEffectf(reverbEffect, AL_REVERB_REFLECTIONS_GAIN, 0.0f));
|
||||||
|
alAuxiliaryEffectSloti(effectSlots[0], AL_EFFECTSLOT_EFFECT, reverbEffect);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -183,7 +183,7 @@ namespace audio {
|
||||||
uint maxSources = 256;
|
uint maxSources = 256;
|
||||||
uint maxEffectSlots = 64;
|
uint maxEffectSlots = 64;
|
||||||
|
|
||||||
void initEffects();
|
bool initEffects();
|
||||||
public:
|
public:
|
||||||
std::vector<uint> effectSlots;
|
std::vector<uint> effectSlots;
|
||||||
std::vector<uint> effects;
|
std::vector<uint> effects;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue