Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9769346951 | |||
| 2a8adc954a | |||
| 8c996e4f54 | |||
| c5f4645980 |
@@ -1,9 +1,9 @@
|
|||||||
project(trnr-lib)
|
project(tlib)
|
||||||
|
|
||||||
add_library(trnr-lib INTERFACE)
|
add_library(tlib INTERFACE)
|
||||||
|
|
||||||
# Add include directories
|
# Add include directories
|
||||||
target_include_directories(trnr-lib INTERFACE
|
target_include_directories(tlib INTERFACE
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/clip
|
${CMAKE_CURRENT_SOURCE_DIR}/clip
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/companding
|
${CMAKE_CURRENT_SOURCE_DIR}/companding
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/dynamics
|
${CMAKE_CURRENT_SOURCE_DIR}/dynamics
|
||||||
|
|||||||
@@ -30,13 +30,14 @@ namespace trnr {
|
|||||||
struct pump {
|
struct pump {
|
||||||
double samplerate;
|
double samplerate;
|
||||||
float threshold_db = 0.f;
|
float threshold_db = 0.f;
|
||||||
float attack_ms = 10.f;
|
float attack_ms = 0.1f;
|
||||||
float release_ms = 100.f;
|
float release_ms = 200.f;
|
||||||
float hp_filter = 80.f;
|
float hp_filter = 80.f;
|
||||||
float ratio = 1000.f;
|
float ratio = 1000.f;
|
||||||
float filter_frq = 40000.f;
|
float filter_frq = 20000.f;
|
||||||
float filter_exp = 0.f;
|
float filter_exp = 1.f;
|
||||||
float treble_boost = 0.f;
|
float treble_boost = 0.f;
|
||||||
|
float makeup = 0.f;
|
||||||
|
|
||||||
float filtered = 0.f;
|
float filtered = 0.f;
|
||||||
float filtered_l = 0.f;
|
float filtered_l = 0.f;
|
||||||
@@ -93,6 +94,30 @@ inline void pump_set_param(pump& p, pump_param param, float value)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline float pump_get_param(const pump& p, pump_param param)
|
||||||
|
{
|
||||||
|
switch (param) {
|
||||||
|
case PUMP_THRESHOLD:
|
||||||
|
return p.threshold_db;
|
||||||
|
case PUMP_ATTACK:
|
||||||
|
return p.attack_ms;
|
||||||
|
case PUMP_RELEASE:
|
||||||
|
return p.release_ms;
|
||||||
|
case PUMP_HP_FILTER:
|
||||||
|
return p.hp_filter;
|
||||||
|
case PUMP_RATIO:
|
||||||
|
return p.ratio;
|
||||||
|
case PUMP_FILTER_FRQ:
|
||||||
|
return p.filter_frq;
|
||||||
|
case PUMP_FILTER_EXP:
|
||||||
|
return p.filter_exp;
|
||||||
|
case PUMP_TREBLE_BOOST:
|
||||||
|
return p.treble_boost;
|
||||||
|
default:
|
||||||
|
return -1.f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inline void pump_init(pump& p, double samplerate)
|
inline void pump_init(pump& p, double samplerate)
|
||||||
{
|
{
|
||||||
p.samplerate = samplerate;
|
p.samplerate = samplerate;
|
||||||
@@ -136,7 +161,8 @@ inline void pump_process_block(pump& p, sample** audio, sample** sidechain, int
|
|||||||
if (overshoot_db > p.envelope_db) {
|
if (overshoot_db > p.envelope_db) {
|
||||||
p.envelope_db = overshoot_db + p.attack_coef * (p.envelope_db - overshoot_db);
|
p.envelope_db = overshoot_db + p.attack_coef * (p.envelope_db - overshoot_db);
|
||||||
} else {
|
} else {
|
||||||
p.envelope_db = overshoot_db + p.release_coef * (p.envelope_db - overshoot_db);
|
p.envelope_db =
|
||||||
|
overshoot_db + p.release_coef * (p.envelope_db - overshoot_db);
|
||||||
}
|
}
|
||||||
|
|
||||||
float slope = 1.f / p.ratio;
|
float slope = 1.f / p.ratio;
|
||||||
@@ -150,7 +176,8 @@ inline void pump_process_block(pump& p, sample** audio, sample** sidechain, int
|
|||||||
sample output_r = input_r * gain_reduction_lin;
|
sample output_r = input_r * gain_reduction_lin;
|
||||||
|
|
||||||
if (p.filter_exp > 0.f) {
|
if (p.filter_exp > 0.f) {
|
||||||
// one pole lowpass filter with envelope applied to frequency for pumping effect
|
// one pole lowpass filter with envelope applied to frequency for pumping
|
||||||
|
// effect
|
||||||
float freq = p.filter_frq * pow(gain_reduction_lin, p.filter_exp);
|
float freq = p.filter_frq * pow(gain_reduction_lin, p.filter_exp);
|
||||||
float lp_x = exp(-2.0 * M_PI * freq / p.samplerate);
|
float lp_x = exp(-2.0 * M_PI * freq / p.samplerate);
|
||||||
float lp_a0 = 1.0 - lp_x;
|
float lp_a0 = 1.0 - lp_x;
|
||||||
@@ -166,7 +193,7 @@ inline void pump_process_block(pump& p, sample** audio, sample** sidechain, int
|
|||||||
output_r = p.filtered_r + (p.filtered_r - p.boosted_r) * p.treble_boost;
|
output_r = p.filtered_r + (p.filtered_r - p.boosted_r) * p.treble_boost;
|
||||||
|
|
||||||
// calculate makeup gain
|
// calculate makeup gain
|
||||||
float makeup_lin = trnr::db_2_lin(-p.threshold_db / 5.f);
|
float makeup_lin = trnr::db_2_lin(p.makeup);
|
||||||
|
|
||||||
audio[0][i] = input_l * gain_reduction_lin * makeup_lin;
|
audio[0][i] = input_l * gain_reduction_lin * makeup_lin;
|
||||||
audio[1][i] = input_r * gain_reduction_lin * makeup_lin;
|
audio[1][i] = input_r * gain_reduction_lin * makeup_lin;
|
||||||
|
|||||||
@@ -36,14 +36,14 @@ struct demo_noise {
|
|||||||
float noise_gain = 0.1f;
|
float noise_gain = 0.1f;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void demo_nose_init(demo_noise& d, double samplerate)
|
inline void demo_noise_init(demo_noise& d, double samplerate)
|
||||||
{
|
{
|
||||||
d.samplerate = samplerate;
|
d.samplerate = samplerate;
|
||||||
d.counter = 0;
|
d.counter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// overwrites the input buffer with noise in the specified time frame
|
// overwrites the input buffer with noise in the specified time frame
|
||||||
inline void process_block(demo_noise& d, float** samples, int blocksize)
|
inline void demo_noise_process_block(demo_noise& d, float** samples, int blocksize)
|
||||||
{
|
{
|
||||||
int noise_len_samples = d.noise_len_sec * d.samplerate;
|
int noise_len_samples = d.noise_len_sec * d.samplerate;
|
||||||
int pause_len_samples = d.pause_len_sec * d.samplerate;
|
int pause_len_samples = d.pause_len_sec * d.samplerate;
|
||||||
|
|||||||
Reference in New Issue
Block a user