EFX environment and reverb effect. Closes #697.#702
EFX environment and reverb effect. Closes #697.#702ArtemPopof wants to merge 17 commits intorwengine:mainfrom
Conversation
|
It can be used like this: Multiple Sound instances can be attached to one effect slot. Effect slot can be binded to one effect. |
Codecov Report
@@ Coverage Diff @@
## master #702 +/- ##
==========================================
+ Coverage 18.11% 18.22% +0.10%
==========================================
Files 247 253 +6
Lines 22633 22765 +132
Branches 5808 5824 +16
==========================================
+ Hits 4101 4149 +48
- Misses 17395 17478 +83
- Partials 1137 1138 +1
Continue to review full report at Codecov.
|
| #include "SoundEffect.hpp" | ||
| #include "OpenAlExtensions.hpp" | ||
|
|
||
| EffectSlot::EffectSlot() { |
There was a problem hiding this comment.
Consider using an initialization list
rwengine/src/audio/EffectSlot.cpp
Outdated
| } | ||
|
|
||
| void EffectSlot::setGain(float gain) { | ||
| alAuxiliaryEffectSlotf(slotId, AL_EFFECTSLOT_GAIN, this->gain = gain); |
There was a problem hiding this comment.
Split a variable assigning and a function invocation
| */ | ||
| std::shared_ptr<SoundEffect> effect; | ||
|
|
||
| ALuint slotId; |
There was a problem hiding this comment.
Or you can set members to defaults right here
rwengine/src/audio/SoundEffect.hpp
Outdated
| * @param type OpenAl specific effect type. | ||
| */ | ||
| SoundEffect(ALint type); | ||
| ~SoundEffect(); |
There was a problem hiding this comment.
You should make the destructor virtual:
https://stackoverflow.com/questions/461203/when-to-use-virtual-destructors
rwengine/src/audio/ReverbEffect.hpp
Outdated
| public: | ||
| ReverbEffect(); | ||
|
|
||
| void setDensity ( float density = 1.0f ); |
There was a problem hiding this comment.
Remove table-like formatting?
There was a problem hiding this comment.
I think there should be some comments describing parameters that functions are setting
rwengine/src/audio/ReverbEffect.cpp
Outdated
| alEffectf(id, AL_REVERB_LATE_REVERB_GAIN, g); | ||
| } | ||
|
|
||
| void ReverbEffect :: setLateReverbDelay (float t) { |
There was a problem hiding this comment.
Something wrong with a formatting
rwengine/src/audio/Sound.hpp
Outdated
|
|
||
| void setMaxDistance(float maxDist); | ||
|
|
||
| void attachToEffectSlot(const std::shared_ptr<EffectSlot> effectSlot); |
There was a problem hiding this comment.
You should pass a shared_ptr by const reference or by value and use std::move
rwengine/src/audio/SoundBuffer.cpp
Outdated
| } | ||
|
|
||
| void SoundBuffer::attachToEffectSlot(const std::shared_ptr<EffectSlot> slot) { | ||
| alCheck(alSource3i(source, AL_AUXILIARY_SEND_FILTER, slot->getSlotId(), slot->getSlotNumber(), AL_FILTER_NULL)); |
rwengine/src/audio/SoundBuffer.cpp
Outdated
| } | ||
|
|
||
| void SoundBuffer::detachFromEffectSlot(const std::shared_ptr<EffectSlot> slot) { | ||
| alCheck(alSource3i (source, AL_AUXILIARY_SEND_FILTER, AL_EFFECTSLOT_NULL, slot->getSlotNumber(), AL_FILTER_NULL)); |
rwengine/src/audio/SoundManager.cpp
Outdated
|
|
||
| initEfxFunctionPointers(); | ||
|
|
||
| SoundEffect effect(0); |
There was a problem hiding this comment.
Have no idea what zero mean... Maybe define some constants?
There was a problem hiding this comment.
It's just a test code, deleted.
rwengine/src/audio/ReverbEffect.h
Outdated
| @@ -0,0 +1,11 @@ | |||
| #ifndef REVERBEFFECT_H | |||
rwengine/src/audio/EffectSlot.cpp
Outdated
| EffectSlot::EffectSlot() { | ||
| alGenAuxiliaryEffectSlots(1, &slotId); | ||
|
|
||
| effect = nullptr; |
|
I've kept possibility to manually operate on basic blocks It (should) make usage of Sounds simpler and prevent code duplication. So I think So code would become something: I look forward to your opinion about this idea. ;) |
|
Suggested improvements look good to me. |
SoundEffect and SoundSlot is merged SoundManager contains all pre-initialized effects
| std::shared_ptr<SoundSource> source; | ||
| std::unique_ptr<SoundBuffer> buffer; | ||
|
|
||
| std::shared_ptr<SoundEffect> effect; |
| #include "audio/SoundBuffer.hpp" | ||
|
|
||
| Sound::~Sound() | ||
| { |
There was a problem hiding this comment.
Formatting. Use clang-format with our config file.
| } | ||
|
|
||
| void Sound::enableEffect(std::shared_ptr<SoundEffect> effect) | ||
| { |
| if (!pickup->isEnabled()) return; | ||
|
|
||
|
|
||
| static constexpr float kRotationSpeedCoeff = 3.0f; |
There was a problem hiding this comment.
imho it's better to avoid unnecessary code in this pull.
| float _musicVolume = 1.f; | ||
|
|
||
| /// Available sound effects for sfx | ||
| std::vector<std::shared_ptr<SoundEffect>> soundEffects; |
There was a problem hiding this comment.
std::vector<std::unique_ptr<SoundEffect>> soundEffects; should be enough. (pass raw ptr to Sounds)
| playSfx(name, position, SoundEffect::Type::Reverb, looping, maxDist); | ||
| } | ||
|
|
||
| void SoundManager::playSfx(size_t name, const glm::vec3& position, SoundEffect::Type effectType, bool looping, int maxDist) { |
|
|
||
| // first effect is placeholder | ||
| // it allows index to be like in enum | ||
| soundEffects.push_back(nullptr); |
There was a problem hiding this comment.
Maybe it's better to remove None from enum and add bool enabled. I think there are too many parameters for sfx to pass them around. Probably we should add some abstraction/wrapper later.
| // first effect is placeholder | ||
| // it allows index to be like in enum | ||
| soundEffects.push_back(nullptr); | ||
| soundEffects.push_back(std::make_shared<ReverbEffect>()); |
There was a problem hiding this comment.
nit(not need to do in this pull): lazy initialization / do when there's need
| } | ||
|
|
||
| void SoundBuffer::enableEffect(std::shared_ptr<SoundEffect> effect) { | ||
| alCheck(alSource3i(source, AL_AUXILIARY_SEND_FILTER, (ALint) effect->getSlotId(), effect->getSlotNumber(), AL_FILTER_NULL)); |
| } | ||
|
|
||
| void SoundBuffer::disableEffect(std::shared_ptr<SoundEffect> effect) { | ||
| alCheck(alSource3i (source, AL_AUXILIARY_SEND_FILTER, AL_EFFECTSLOT_NULL, effect->getSlotNumber(), AL_FILTER_NULL)); |
| #ifndef _RWENGINE_SOUND_HPP_ | ||
| #define _RWENGINE_SOUND_HPP_ | ||
|
|
||
| #include <audio/SoundEffect.hpp> |
| * Many sound sources can be attached to one slot. | ||
| * Different effects can be binded to this (e.g reverb, delay). | ||
| */ | ||
| class EffectSlot { |
There was a problem hiding this comment.
I have problems with understanding connection between this class and SoundEffect. I mean where is EffectSlot created, used, deleted. Because instances of EffectSlot and SoundEffect are in relation 1 to 1. I think solution when one of them contains/owns instances of second would be good enough.
|
Do you need some help with changes? You can catch me on IRC. ;) |
|
Do you plan to continue work on this pull? |
|
Bump? |
Some classes to support EFX and realisation of a reverb.
Closes #697