Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EFX environment and reverb effect. Closes #697. #702

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

ArtemPopof
Copy link
Contributor

@ArtemPopof ArtemPopof commented Feb 16, 2019

Some classes to support EFX and realisation of a reverb.
Closes #697

@ArtemPopof
Copy link
Contributor Author

ArtemPopof commented Feb 16, 2019

It can be used like this:

// load random sound
size_t index = game->getWorld()->sound.createSfxInstance(555);

auto reverb = std::shared_ptr<SoundEffect>(new ReverbEffect);
auto slot = std::shared_ptr<EffectSlot>(new EffectSlot());
Sound& sound = game->getWorld()->sound.getSoundRef(index);
slot->attachEffect(reverb);
sound.attachToEffectSlot(slot);

game->getWorld()->sound.playSfx(index, {0.0f, 0.0f, 0.0f});

Multiple Sound instances can be attached to one effect slot. Effect slot can be binded to one effect.

@codecov
Copy link

codecov bot commented Feb 16, 2019

Codecov Report

Merging #702 into master will increase coverage by 0.10%.
The diff coverage is 36.64%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
rwengine/src/audio/EffectSlot.cpp 0.00% <0.00%> (ø)
rwengine/src/audio/Sound.hpp 0.00% <ø> (-25.00%) ⬇️
rwengine/src/audio/SoundBuffer.cpp 44.61% <0.00%> (-4.54%) ⬇️
rwengine/src/audio/SoundEffect.hpp 0.00% <0.00%> (ø)
rwengine/src/render/ObjectRenderer.cpp 11.29% <0.00%> (ø)
rwgame/states/IngameState.cpp 0.00% <ø> (ø)
rwengine/src/audio/ReverbEffect.cpp 6.89% <6.89%> (ø)
rwengine/src/audio/Sound.cpp 46.34% <44.44%> (-0.54%) ⬇️
rwengine/src/audio/SoundManager.cpp 29.08% <57.89%> (+2.04%) ⬆️
rwengine/src/audio/SoundEffect.cpp 73.33% <71.42%> (ø)
... and 10 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9b4ebc1...960d1a1. Read the comment docs.

#include "SoundEffect.hpp"
#include "OpenAlExtensions.hpp"

EffectSlot::EffectSlot() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using an initialization list

}

void EffectSlot::setGain(float gain) {
alAuxiliaryEffectSlotf(slotId, AL_EFFECTSLOT_GAIN, this->gain = gain);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split a variable assigning and a function invocation

*/
std::shared_ptr<SoundEffect> effect;

ALuint slotId;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or you can set members to defaults right here

* @param type OpenAl specific effect type.
*/
SoundEffect(ALint type);
~SoundEffect();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public:
ReverbEffect();

void setDensity ( float density = 1.0f );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove table-like formatting?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there should be some comments describing parameters that functions are setting

alEffectf(id, AL_REVERB_LATE_REVERB_GAIN, g);
}

void ReverbEffect :: setLateReverbDelay (float t) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something wrong with a formatting

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it

@@ -42,6 +43,8 @@ struct Sound {

void setMaxDistance(float maxDist);

void attachToEffectSlot(const std::shared_ptr<EffectSlot> effectSlot);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should pass a shared_ptr by const reference or by value and use std::move

@@ -83,3 +86,11 @@ void SoundBuffer::setGain(float gain) {
void SoundBuffer::setMaxDistance(float maxDist) {
alCheck(alSourcef(source, AL_MAX_DISTANCE, maxDist));
}

void SoundBuffer::attachToEffectSlot(const std::shared_ptr<EffectSlot> slot) {
alCheck(alSource3i(source, AL_AUXILIARY_SEND_FILTER, slot->getSlotId(), slot->getSlotNumber(), AL_FILTER_NULL));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use const reference here

}

void SoundBuffer::detachFromEffectSlot(const std::shared_ptr<EffectSlot> slot) {
alCheck(alSource3i (source, AL_AUXILIARY_SEND_FILTER, AL_EFFECTSLOT_NULL, slot->getSlotNumber(), AL_FILTER_NULL));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment above


initEfxFunctionPointers();

SoundEffect effect(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have no idea what zero mean... Maybe define some constants?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just a test code, deleted.

@@ -0,0 +1,11 @@
#ifndef REVERBEFFECT_H
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this file is unneeded.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleted.

EffectSlot::EffectSlot() {
alGenAuxiliaryEffectSlots(1, &slotId);

effect = nullptr;
Copy link

@ghost ghost Feb 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default member initializer

@ghost
Copy link

ghost commented Feb 16, 2019

I've kept possibility to manually operate on basic blocks Sound, SoundSource, SoundBuffer. It's useful to create simple tidy tests. But engine should use neat interface of SoundManager.

It (should) make usage of Sounds simpler and prevent code duplication.

So I think SoundEffect, EffectSlot should be squashed together. Instances of that class stored in vector (which is member of SoundManager).

So code would become something:

// Somewhere in header defined
enum class SoundEffectType {
    None,
    Reverb
};

// load random sound
size_t index = game->getWorld()->sound.createSfxInstance(555);

game->getWorld()->sound.playSfx(index, SoundEffectType::None, {0.0f, 0.0f, 0.0f}); // All logic are done behind

I look forward to your opinion about this idea. ;)

@ArtemPopof
Copy link
Contributor Author

ArtemPopof commented Feb 18, 2019

Suggested improvements look good to me.

ArtemPopof and others added 2 commits February 20, 2019 11:26
SoundEffect and SoundSlot is merged
SoundManager contains all pre-initialized effects
@@ -18,8 +21,10 @@ struct Sound {
std::shared_ptr<SoundSource> source;
std::unique_ptr<SoundBuffer> buffer;

std::shared_ptr<SoundEffect> effect;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

raw ptr is enough

@@ -2,6 +2,13 @@

#include "audio/SoundBuffer.hpp"

Sound::~Sound()
{
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting. Use clang-format with our config file.

@@ -46,6 +53,12 @@ void Sound::setMaxDistance(float maxDist) {
buffer->setMaxDistance(maxDist);
}

void Sound::enableEffect(std::shared_ptr<SoundEffect> effect)
{
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also

@@ -307,10 +307,11 @@ void ObjectRenderer::renderVehicle(VehicleObject* vehicle,

void ObjectRenderer::renderPickup(PickupObject* pickup, RenderList& outList) {
if (!pickup->isEnabled()) return;


static constexpr float kRotationSpeedCoeff = 3.0f;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imho it's better to avoid unnecessary code in this pull.

@@ -117,6 +123,9 @@ class SoundManager {

/// Multiplier for music and cutscenes audio
float _musicVolume = 1.f;

/// Available sound effects for sfx
std::vector<std::shared_ptr<SoundEffect>> soundEffects;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting


// first effect is placeholder
// it allows index to be like in enum
soundEffects.push_back(nullptr);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit(not need to do in this pull): lazy initialization / do when there's need

@@ -83,3 +85,11 @@ void SoundBuffer::setGain(float gain) {
void SoundBuffer::setMaxDistance(float maxDist) {
alCheck(alSourcef(source, AL_MAX_DISTANCE, maxDist));
}

void SoundBuffer::enableEffect(std::shared_ptr<SoundEffect> effect) {
alCheck(alSource3i(source, AL_AUXILIARY_SEND_FILTER, (ALint) effect->getSlotId(), effect->getSlotNumber(), AL_FILTER_NULL));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting

}

void SoundBuffer::disableEffect(std::shared_ptr<SoundEffect> effect) {
alCheck(alSource3i (source, AL_AUXILIARY_SEND_FILTER, AL_EFFECTSLOT_NULL, effect->getSlotNumber(), AL_FILTER_NULL));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also

@@ -1,9 +1,12 @@
#ifndef _RWENGINE_SOUND_HPP_
#define _RWENGINE_SOUND_HPP_

#include <audio/SoundEffect.hpp>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forward declaration

* Many sound sources can be attached to one slot.
* Different effects can be binded to this (e.g reverb, delay).
*/
class EffectSlot {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ghost
Copy link

ghost commented Feb 27, 2019

Do you need some help with changes? You can catch me on IRC. ;)

@ghost
Copy link

ghost commented Mar 17, 2019

Do you plan to continue work on this pull?

@ghost
Copy link

ghost commented May 25, 2019

Bump?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SFX lacks reverb
2 participants