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() { void ALSpeaker::play() {
paused = false; paused = false;
manuallyStopped = false; manuallyStopped = false;
auto p_channel = get_channel(this->channel); auto channel = get_channel(this->channel);
AL_CHECK(alSourcef( AL_CHECK(alSourcef(
source, source,
AL_GAIN, 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(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)); AL_CHECK(alSourcePlay(source));
} }
@ -598,14 +601,12 @@ bool ALAudio::initEffects() {
} }
} }
// Create reverb effect
alEffecti(effects[REVERB_EFFECT], 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";
return false; return false;
} }
// Create lowpass filter
alFilteri(filters[LOWPASS_FILTER], 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";
@ -614,7 +615,6 @@ bool ALAudio::initEffects() {
alFilterf(filters[LOWPASS_FILTER], AL_LOWPASS_GAIN, 1.0f); alFilterf(filters[LOWPASS_FILTER], AL_LOWPASS_GAIN, 1.0f);
alFilterf(filters[LOWPASS_FILTER], AL_LOWPASS_GAINHF, 0.01f); alFilterf(filters[LOWPASS_FILTER], AL_LOWPASS_GAINHF, 0.01f);
// 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";

View file

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

View file

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