disable effects in non-world channels

This commit is contained in:
MihailRis 2026-02-13 01:40:35 +03:00
parent a43f41182d
commit 310d79be47
3 changed files with 29 additions and 18 deletions

View file

@ -392,15 +392,18 @@ void ALSpeaker::setLoop(bool loop) {
void ALSpeaker::play() {
paused = false;
manuallyStopped = false;
auto p_channel = get_channel(this->channel);
auto channel = get_channel(this->channel);
AL_CHECK(alSourcef(
source,
AL_GAIN,
volume * p_channel->getVolume()
volume * channel->getVolume()
));
if (al->useEffects) {
if (al->useEffects && channel->isEffectsApplied()) {
AL_CHECK(alSource3i(source, AL_AUXILIARY_SEND_FILTER, al->effectSlots[0], 0, al->filters[0]));
//AL_CHECK(alSourcei(source, AL_DIRECT_FILTER, al->filters[LOWPASS_FILTER]));
//AL_CHECK(alSourcei(source, AL_DIRECT_FILTER, al->filters[LOWPASS_FILTER])); // TODO: use lowpass filter
} else {
AL_CHECK(alSource3i(source, AL_AUXILIARY_SEND_FILTER, 0, 0, 0));
AL_CHECK(alSourcei(source, AL_DIRECT_FILTER, 0));
}
AL_CHECK(alSourcePlay(source));
}
@ -598,14 +601,12 @@ bool ALAudio::initEffects() {
}
}
// Create reverb effect
alEffecti(effects[REVERB_EFFECT], AL_EFFECT_TYPE, AL_EFFECT_REVERB);
if (alGetError() != AL_NO_ERROR) {
logger.error() << "reverb effect is not supported";
return false;
}
// Create lowpass filter
alFilteri(filters[LOWPASS_FILTER], AL_FILTER_TYPE, AL_FILTER_LOWPASS);
if (alGetError() != AL_NO_ERROR) {
logger.error() << "lowpass filter is not supported";
@ -614,7 +615,6 @@ bool ALAudio::initEffects() {
alFilterf(filters[LOWPASS_FILTER], AL_LOWPASS_GAIN, 1.0f);
alFilterf(filters[LOWPASS_FILTER], AL_LOWPASS_GAINHF, 0.01f);
// Attach effect to aux effect slot
alAuxiliaryEffectSloti(effectSlots[0], AL_EFFECTSLOT_EFFECT, effects[0]);
if (alGetError() == AL_NO_ERROR) {
logger.info() << "successfully loaded effect into effect slot";

View file

@ -27,7 +27,8 @@ namespace {
static bool input_enabled = false;
}
Channel::Channel(std::string name) : name(std::move(name)) {
Channel::Channel(std::string name, bool effects)
: name(std::move(name)), effects(effects) {
}
float Channel::getVolume() const {
@ -56,6 +57,10 @@ bool Channel::isPaused() const {
return paused;
}
bool Channel::isEffectsApplied() const {
return effects;
}
size_t PCMStream::readFully(char* buffer, size_t bufferSize, bool loop) {
if (!isOpen()) {
return 0;
@ -171,15 +176,16 @@ void audio::initialize(
struct {
std::string name;
NumberSetting* setting;
bool effects;
} builtin_channels[] {
{"master", &settings.volumeMaster},
{"regular", &settings.volumeRegular},
{"music", &settings.volumeMusic},
{"ambient", &settings.volumeAmbient},
{"ui", &settings.volumeUI}
{"master", &settings.volumeMaster, false},
{"regular", &settings.volumeRegular, true},
{"music", &settings.volumeMusic, false},
{"ambient", &settings.volumeAmbient, true},
{"ui", &settings.volumeUI, false}
};
for (auto& channel : builtin_channels) {
create_channel(channel.name);
create_channel(channel.name, channel.effects);
objects_keeper.keepAlive(channel.setting->observe([=](auto value) {
audio::get_channel(channel.name)->setVolume(value * value);
}, true));
@ -419,12 +425,12 @@ Speaker* audio::get_speaker(speakerid_t id) {
return found->second.get();
}
int audio::create_channel(const std::string& name) {
int audio::create_channel(const std::string& name, bool effects) {
int index = get_channel_index(name);
if (index != -1) {
return index;
}
channels.emplace_back(std::make_unique<Channel>(name));
channels.emplace_back(std::make_unique<Channel>(name, effects));
return channels.size() - 1;
}

View file

@ -43,8 +43,9 @@ namespace audio {
/// @brief Channel volume setting
float volume = 1.0f;
bool paused = false;
bool effects;
public:
Channel(std::string name);
Channel(std::string name, bool effects);
/// @brief Get channel volume
float getVolume() const;
@ -73,6 +74,9 @@ namespace audio {
/// @brief Check if the channel is paused
bool isPaused() const;
/// @brief Check if the channel uses common acoustic effects / filters
bool isEffectsApplied() const;
};
/// @brief Pulse-code modulation data
@ -549,8 +553,9 @@ namespace audio {
/// @brief Create new channel.
/// All non-builtin channels will be destroyed on audio::reset() call
/// @param name channel name
/// @param effects use common acoustic effects / filters
/// @return new channel index
int create_channel(const std::string& name);
int create_channel(const std::string& name, bool effects);
/// @brief Get channel index by name
/// @param name channel name