Commit 4bb23ea9 authored by Stefan Westerfeld's avatar Stefan Westerfeld

Use floats internally in limiter for performance reasons.

Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent 138c6142
......@@ -14,21 +14,21 @@ Limiter::Limiter (int n_channels, int sample_rate) :
}
void
Limiter::set_attack (double attack_ms)
Limiter::set_attack (float attack_ms)
{
look_ahead = sample_rate / 1000.0 * attack_ms;
look_ahead = max (look_ahead, 1u);
}
void
Limiter::set_release (double release_ms)
Limiter::set_release (float release_ms)
{
release_factor = exp (log (0.5) / (sample_rate / 1000.0 * release_ms));
release_factor = max (release_factor, 0.5);
release_factor = max (release_factor, 0.5f);
}
void
Limiter::set_ceiling (double new_ceiling)
Limiter::set_ceiling (float new_ceiling)
{
ceiling = new_ceiling;
maximum = ceiling;
......@@ -58,8 +58,8 @@ Limiter::process (const vector<float>& samples)
{
if (int (i) - int (j) >= 0)
{
double alpha = double (j) / look_ahead;
max_buffer[i - j] = max<float> (max_buffer[i - j], channel_max * (1 - alpha) + ceiling * alpha);
float alpha = float (j) / look_ahead;
max_buffer[i - j] = max (max_buffer[i - j], channel_max * (1 - alpha) + ceiling * alpha);
}
}
}
......
......@@ -6,9 +6,9 @@
class Limiter
{
double ceiling = 1;
double maximum = 1;
double release_factor = 0;
float ceiling = 1;
float maximum = 1;
float release_factor = 0;
uint look_ahead = 0;
uint n_channels = 0;
uint sample_rate = 0;
......@@ -18,9 +18,9 @@ class Limiter
public:
Limiter (int n_channels, int sample_rate);
void set_release (double value_ms);
void set_attack (double value_ms);
void set_ceiling (double ceiling);
void set_release (float value_ms);
void set_attack (float value_ms);
void set_ceiling (float ceiling);
std::vector<float> process (const std::vector<float>& samples);
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment