Remove linear filter from volume control, use simple multiplication instead
This commit is contained in:
parent
8111af2c54
commit
e7d3bc45d1
2 changed files with 4 additions and 14 deletions
|
|
@ -26,8 +26,6 @@ namespace psemek::audio
|
||||||
std::atomic<float> gain_[2];
|
std::atomic<float> gain_[2];
|
||||||
std::atomic<float> smoothness_multiplier_;
|
std::atomic<float> smoothness_multiplier_;
|
||||||
float real_gain_[2];
|
float real_gain_[2];
|
||||||
float last_sample_src_[2];
|
|
||||||
float last_sample_tgt_[2];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
#include <psemek/audio/constants.hpp>
|
#include <psemek/audio/constants.hpp>
|
||||||
#include <psemek/audio/smooth.hpp>
|
#include <psemek/audio/smooth.hpp>
|
||||||
|
|
||||||
|
#include <psemek/log/log.hpp>
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
namespace psemek::audio
|
namespace psemek::audio
|
||||||
|
|
@ -11,8 +13,6 @@ namespace psemek::audio
|
||||||
: gain_{gain_left, gain_right}
|
: gain_{gain_left, gain_right}
|
||||||
, smoothness_multiplier_{smoothness_to_multiplier(smoothness)}
|
, smoothness_multiplier_{smoothness_to_multiplier(smoothness)}
|
||||||
, real_gain_{gain_left, gain_right}
|
, real_gain_{gain_left, gain_right}
|
||||||
, last_sample_src_{0.f, 0.f}
|
|
||||||
, last_sample_tgt_{0.f, 0.f}
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
float volume_base::smoothness() const
|
float volume_base::smoothness() const
|
||||||
|
|
@ -31,19 +31,11 @@ namespace psemek::audio
|
||||||
float gain[2] = {gain_[0].load(), gain_[1].load()};
|
float gain[2] = {gain_[0].load(), gain_[1].load()};
|
||||||
float smoothness_multiplier = smoothness_multiplier_.load();
|
float smoothness_multiplier = smoothness_multiplier_.load();
|
||||||
|
|
||||||
auto apply_impl = [this](float & target, int i)
|
|
||||||
{
|
|
||||||
auto old = target;
|
|
||||||
target = last_sample_tgt_[i] + (old - last_sample_src_[i]) * real_gain_[i];
|
|
||||||
last_sample_src_[i] = old;
|
|
||||||
last_sample_tgt_[i] = target;
|
|
||||||
};
|
|
||||||
|
|
||||||
auto end = data + sample_count;
|
auto end = data + sample_count;
|
||||||
for (auto p = data; p < end;)
|
for (auto p = data; p < end;)
|
||||||
{
|
{
|
||||||
apply_impl(*p++, 0);
|
*p++ *= real_gain_[0];
|
||||||
apply_impl(*p++, 1);
|
*p++ *= real_gain_[1];
|
||||||
|
|
||||||
smooth_update(real_gain_[0], gain[0], smoothness_multiplier);
|
smooth_update(real_gain_[0], gain[0], smoothness_multiplier);
|
||||||
smooth_update(real_gain_[1], gain[1], smoothness_multiplier);
|
smooth_update(real_gain_[1], gain[1], smoothness_multiplier);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue