New upstream version 24.0.1+dfsg1
This commit is contained in:
parent
b14f9eae6d
commit
5a730d6ec3
842 changed files with 42245 additions and 33385 deletions
|
|
@ -10,21 +10,23 @@
|
|||
|
||||
/* -------------------------------------------------------- */
|
||||
|
||||
#define do_log(level, format, ...) \
|
||||
#define do_log(level, format, ...) \
|
||||
blog(level, "[expander: '%s'] " format, \
|
||||
obs_source_get_name(cd->context), ##__VA_ARGS__)
|
||||
obs_source_get_name(cd->context), ##__VA_ARGS__)
|
||||
|
||||
#define warn(format, ...) do_log(LOG_WARNING, format, ##__VA_ARGS__)
|
||||
#define info(format, ...) do_log(LOG_INFO, format, ##__VA_ARGS__)
|
||||
#define warn(format, ...) do_log(LOG_WARNING, format, ##__VA_ARGS__)
|
||||
#define info(format, ...) do_log(LOG_INFO, format, ##__VA_ARGS__)
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define debug(format, ...) do_log(LOG_DEBUG, format, ##__VA_ARGS__)
|
||||
#define debug(format, ...) do_log(LOG_DEBUG, format, ##__VA_ARGS__)
|
||||
#else
|
||||
#define debug(format, ...)
|
||||
#endif
|
||||
|
||||
/* -------------------------------------------------------- */
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
#define S_RATIO "ratio"
|
||||
#define S_THRESHOLD "threshold"
|
||||
#define S_ATTACK_TIME "attack_time"
|
||||
|
|
@ -61,6 +63,8 @@
|
|||
#define MS_IN_S 1000
|
||||
#define MS_IN_S_F ((float)MS_IN_S)
|
||||
|
||||
/* clang-format on */
|
||||
|
||||
/* -------------------------------------------------------- */
|
||||
|
||||
struct expander_data {
|
||||
|
|
@ -78,7 +82,7 @@ struct expander_data {
|
|||
size_t sample_rate;
|
||||
float envelope[MAX_AUDIO_CHANNELS];
|
||||
float slope;
|
||||
int detector;
|
||||
int detector;
|
||||
float runave[MAX_AUDIO_CHANNELS];
|
||||
bool is_gate;
|
||||
float *runaverage[MAX_AUDIO_CHANNELS];
|
||||
|
|
@ -90,11 +94,10 @@ struct expander_data {
|
|||
size_t env_in_len;
|
||||
};
|
||||
|
||||
enum {
|
||||
RMS_DETECT,
|
||||
RMS_STILLWELL_DETECT,
|
||||
PEAK_DETECT,
|
||||
NO_DETECT,
|
||||
enum { RMS_DETECT,
|
||||
RMS_STILLWELL_DETECT,
|
||||
PEAK_DETECT,
|
||||
NO_DETECT,
|
||||
};
|
||||
/* -------------------------------------------------------- */
|
||||
|
||||
|
|
@ -102,16 +105,17 @@ static void resize_env_buffer(struct expander_data *cd, size_t len)
|
|||
{
|
||||
cd->envelope_buf_len = len;
|
||||
for (int i = 0; i < MAX_AUDIO_CHANNELS; i++)
|
||||
cd->envelope_buf[i] = brealloc(cd->envelope_buf[i],
|
||||
cd->envelope_buf_len * sizeof(float));
|
||||
cd->envelope_buf[i] =
|
||||
brealloc(cd->envelope_buf[i],
|
||||
cd->envelope_buf_len * sizeof(float));
|
||||
}
|
||||
|
||||
static void resize_runaverage_buffer(struct expander_data *cd, size_t len)
|
||||
{
|
||||
cd->runaverage_len = len;
|
||||
for (int i = 0; i < MAX_AUDIO_CHANNELS; i++)
|
||||
cd->runaverage[i] = brealloc(cd->runaverage[i],
|
||||
cd->runaverage_len * sizeof(float));
|
||||
cd->runaverage[i] = brealloc(
|
||||
cd->runaverage[i], cd->runaverage_len * sizeof(float));
|
||||
}
|
||||
|
||||
static void resize_env_in_buffer(struct expander_data *cd, size_t len)
|
||||
|
|
@ -124,8 +128,8 @@ static void resize_gaindB_buffer(struct expander_data *cd, size_t len)
|
|||
{
|
||||
cd->gaindB_len = len;
|
||||
for (int i = 0; i < MAX_AUDIO_CHANNELS; i++)
|
||||
cd->gaindB[i] = brealloc(cd->gaindB[i],
|
||||
cd->gaindB_len * sizeof(float));
|
||||
cd->gaindB[i] =
|
||||
brealloc(cd->gaindB[i], cd->gaindB_len * sizeof(float));
|
||||
}
|
||||
|
||||
static inline float gain_coefficient(uint32_t sample_rate, float time)
|
||||
|
|
@ -145,14 +149,14 @@ static void expander_defaults(obs_data_t *s)
|
|||
bool is_expander_preset = true;
|
||||
if (strcmp(presets, "gate") == 0)
|
||||
is_expander_preset = false;
|
||||
obs_data_set_default_string(s, S_PRESETS, is_expander_preset ?
|
||||
"expander" : "gate");
|
||||
obs_data_set_default_double(s, S_RATIO, is_expander_preset ?
|
||||
2.0 : 10.0);
|
||||
obs_data_set_default_string(s, S_PRESETS,
|
||||
is_expander_preset ? "expander" : "gate");
|
||||
obs_data_set_default_double(s, S_RATIO,
|
||||
is_expander_preset ? 2.0 : 10.0);
|
||||
obs_data_set_default_double(s, S_THRESHOLD, -40.0f);
|
||||
obs_data_set_default_int(s, S_ATTACK_TIME, 10);
|
||||
obs_data_set_default_int(s, S_RELEASE_TIME, is_expander_preset ?
|
||||
50 : 125);
|
||||
obs_data_set_default_int(s, S_RELEASE_TIME,
|
||||
is_expander_preset ? 50 : 125);
|
||||
obs_data_set_default_double(s, S_OUTPUT_GAIN, 0.0);
|
||||
obs_data_set_default_string(s, S_DETECTOR, "RMS");
|
||||
}
|
||||
|
|
@ -175,23 +179,21 @@ static void expander_update(void *data, obs_data_t *s)
|
|||
}
|
||||
|
||||
const uint32_t sample_rate =
|
||||
audio_output_get_sample_rate(obs_get_audio());
|
||||
const size_t num_channels =
|
||||
audio_output_get_channels(obs_get_audio());
|
||||
const float attack_time_ms =
|
||||
(float)obs_data_get_int(s, S_ATTACK_TIME);
|
||||
audio_output_get_sample_rate(obs_get_audio());
|
||||
const size_t num_channels = audio_output_get_channels(obs_get_audio());
|
||||
const float attack_time_ms = (float)obs_data_get_int(s, S_ATTACK_TIME);
|
||||
const float release_time_ms =
|
||||
(float)obs_data_get_int(s, S_RELEASE_TIME);
|
||||
(float)obs_data_get_int(s, S_RELEASE_TIME);
|
||||
const float output_gain_db =
|
||||
(float)obs_data_get_double(s, S_OUTPUT_GAIN);
|
||||
(float)obs_data_get_double(s, S_OUTPUT_GAIN);
|
||||
|
||||
cd->ratio = (float)obs_data_get_double(s, S_RATIO);
|
||||
|
||||
cd->threshold = (float)obs_data_get_double(s, S_THRESHOLD);
|
||||
cd->attack_gain = gain_coefficient(sample_rate,
|
||||
attack_time_ms / MS_IN_S_F);
|
||||
cd->release_gain = gain_coefficient(sample_rate,
|
||||
release_time_ms / MS_IN_S_F);
|
||||
cd->attack_gain =
|
||||
gain_coefficient(sample_rate, attack_time_ms / MS_IN_S_F);
|
||||
cd->release_gain =
|
||||
gain_coefficient(sample_rate, release_time_ms / MS_IN_S_F);
|
||||
cd->output_gain = db_to_mul(output_gain_db);
|
||||
cd->num_channels = num_channels;
|
||||
cd->sample_rate = sample_rate;
|
||||
|
|
@ -246,8 +248,8 @@ static void expander_destroy(void *data)
|
|||
}
|
||||
|
||||
// detection stage
|
||||
static void analyze_envelope(struct expander_data *cd,
|
||||
float **samples, const uint32_t num_samples)
|
||||
static void analyze_envelope(struct expander_data *cd, float **samples,
|
||||
const uint32_t num_samples)
|
||||
{
|
||||
if (cd->envelope_buf_len < num_samples)
|
||||
resize_env_buffer(cd, num_samples);
|
||||
|
|
@ -261,9 +263,9 @@ static void analyze_envelope(struct expander_data *cd,
|
|||
|
||||
for (int i = 0; i < MAX_AUDIO_CHANNELS; i++) {
|
||||
memset(cd->envelope_buf[i], 0,
|
||||
num_samples * sizeof(cd->envelope_buf[i][0]));
|
||||
num_samples * sizeof(cd->envelope_buf[i][0]));
|
||||
memset(cd->runaverage[i], 0,
|
||||
num_samples * sizeof(cd->runaverage[i][0]));
|
||||
num_samples * sizeof(cd->runaverage[i][0]));
|
||||
}
|
||||
memset(cd->env_in, 0, num_samples * sizeof(cd->env_in[0]));
|
||||
|
||||
|
|
@ -276,13 +278,15 @@ static void analyze_envelope(struct expander_data *cd,
|
|||
float *env_in = cd->env_in;
|
||||
|
||||
if (cd->detector == RMS_DETECT) {
|
||||
runave[0] = rmscoef * cd->runave[chan] +
|
||||
runave[0] =
|
||||
rmscoef * cd->runave[chan] +
|
||||
(1 - rmscoef) * powf(samples[chan][0], 2.0f);
|
||||
env_in[0] = sqrtf(fmaxf(runave[0], 0));
|
||||
for (uint32_t i = 1; i < num_samples; ++i) {
|
||||
runave[i] = rmscoef * runave[i - 1] +
|
||||
runave[i] =
|
||||
rmscoef * runave[i - 1] +
|
||||
(1 - rmscoef) *
|
||||
powf(samples[chan][i], 2.0f);
|
||||
powf(samples[chan][i], 2.0f);
|
||||
env_in[i] = sqrtf(runave[i]);
|
||||
}
|
||||
} else if (cd->detector == PEAK_DETECT) {
|
||||
|
|
@ -292,7 +296,7 @@ static void analyze_envelope(struct expander_data *cd,
|
|||
}
|
||||
}
|
||||
|
||||
cd->runave[chan] = runave[num_samples-1];
|
||||
cd->runave[chan] = runave[num_samples - 1];
|
||||
for (uint32_t i = 0; i < num_samples; ++i)
|
||||
envelope_buf[i] = fmaxf(envelope_buf[i], env_in[i]);
|
||||
cd->envelope[chan] = cd->envelope_buf[chan][num_samples - 1];
|
||||
|
|
@ -300,8 +304,8 @@ static void analyze_envelope(struct expander_data *cd,
|
|||
}
|
||||
|
||||
// gain stage and ballistics in dB domain
|
||||
static inline void process_expansion(struct expander_data *cd,
|
||||
float **samples, uint32_t num_samples)
|
||||
static inline void process_expansion(struct expander_data *cd, float **samples,
|
||||
uint32_t num_samples)
|
||||
{
|
||||
const float attack_gain = cd->attack_gain;
|
||||
const float release_gain = cd->release_gain;
|
||||
|
|
@ -309,35 +313,42 @@ static inline void process_expansion(struct expander_data *cd,
|
|||
if (cd->gaindB_len < num_samples)
|
||||
resize_gaindB_buffer(cd, num_samples);
|
||||
for (int i = 0; i < MAX_AUDIO_CHANNELS; i++)
|
||||
memset(cd->gaindB[i], 0, num_samples * sizeof(cd->gaindB[i][0]));
|
||||
memset(cd->gaindB[i], 0,
|
||||
num_samples * sizeof(cd->gaindB[i][0]));
|
||||
|
||||
for (size_t chan = 0; chan < cd->num_channels; chan++) {
|
||||
for (size_t i = 0; i < num_samples; ++i) {
|
||||
// gain stage of expansion
|
||||
float env_db = mul_to_db(cd->envelope_buf[chan][i]);
|
||||
float gain = cd->threshold - env_db > 0.0f ?
|
||||
fmaxf(cd->slope *
|
||||
(cd->threshold - env_db), -60.0f) :
|
||||
0.0f;
|
||||
float gain =
|
||||
cd->threshold - env_db > 0.0f
|
||||
? fmaxf(cd->slope * (cd->threshold -
|
||||
env_db),
|
||||
-60.0f)
|
||||
: 0.0f;
|
||||
// ballistics (attack/release)
|
||||
if (i > 0) {
|
||||
if (gain > cd->gaindB[chan][i - 1])
|
||||
cd->gaindB[chan][i] = attack_gain *
|
||||
cd->gaindB[chan][i - 1] +
|
||||
(1.0f - attack_gain) * gain;
|
||||
cd->gaindB[chan][i] =
|
||||
attack_gain *
|
||||
cd->gaindB[chan][i - 1] +
|
||||
(1.0f - attack_gain) * gain;
|
||||
else
|
||||
cd->gaindB[chan][i] = release_gain *
|
||||
cd->gaindB[chan][i - 1] +
|
||||
(1.0f - release_gain) * gain;
|
||||
cd->gaindB[chan][i] =
|
||||
release_gain *
|
||||
cd->gaindB[chan][i - 1] +
|
||||
(1.0f - release_gain) * gain;
|
||||
} else {
|
||||
if (gain > cd->gaindB_buf[chan])
|
||||
cd->gaindB[chan][i] = attack_gain *
|
||||
cd->gaindB_buf[chan] +
|
||||
(1.0f - attack_gain) * gain;
|
||||
cd->gaindB[chan][i] =
|
||||
attack_gain *
|
||||
cd->gaindB_buf[chan] +
|
||||
(1.0f - attack_gain) * gain;
|
||||
else
|
||||
cd->gaindB[chan][i] = release_gain *
|
||||
cd->gaindB_buf[chan] +
|
||||
(1.0f - release_gain) * gain;
|
||||
cd->gaindB[chan][i] =
|
||||
release_gain *
|
||||
cd->gaindB_buf[chan] +
|
||||
(1.0f - release_gain) * gain;
|
||||
}
|
||||
|
||||
gain = db_to_mul(fminf(0, cd->gaindB[chan][i]));
|
||||
|
|
@ -348,8 +359,8 @@ static inline void process_expansion(struct expander_data *cd,
|
|||
}
|
||||
}
|
||||
|
||||
static struct obs_audio_data *expander_filter_audio(void *data,
|
||||
struct obs_audio_data *audio)
|
||||
static struct obs_audio_data *
|
||||
expander_filter_audio(void *data, struct obs_audio_data *audio)
|
||||
{
|
||||
struct expander_data *cd = data;
|
||||
|
||||
|
|
@ -357,7 +368,7 @@ static struct obs_audio_data *expander_filter_audio(void *data,
|
|||
if (num_samples == 0)
|
||||
return audio;
|
||||
|
||||
float **samples = (float**)audio->data;
|
||||
float **samples = (float **)audio->data;
|
||||
|
||||
analyze_envelope(cd, samples, num_samples);
|
||||
process_expansion(cd, samples, num_samples);
|
||||
|
|
@ -365,7 +376,7 @@ static struct obs_audio_data *expander_filter_audio(void *data,
|
|||
}
|
||||
|
||||
static bool presets_changed(obs_properties_t *props, obs_property_t *prop,
|
||||
obs_data_t *settings)
|
||||
obs_data_t *settings)
|
||||
{
|
||||
UNUSED_PARAMETER(props);
|
||||
UNUSED_PARAMETER(prop);
|
||||
|
|
@ -376,28 +387,37 @@ static bool presets_changed(obs_properties_t *props, obs_property_t *prop,
|
|||
static obs_properties_t *expander_properties(void *data)
|
||||
{
|
||||
obs_properties_t *props = obs_properties_create();
|
||||
obs_property_t *p;
|
||||
|
||||
obs_property_t *presets = obs_properties_add_list(props, S_PRESETS,
|
||||
TEXT_PRESETS, OBS_COMBO_TYPE_LIST,
|
||||
OBS_COMBO_FORMAT_STRING);
|
||||
obs_property_t *presets = obs_properties_add_list(
|
||||
props, S_PRESETS, TEXT_PRESETS, OBS_COMBO_TYPE_LIST,
|
||||
OBS_COMBO_FORMAT_STRING);
|
||||
obs_property_list_add_string(presets, TEXT_PRESETS_EXP, "expander");
|
||||
obs_property_list_add_string(presets, TEXT_PRESETS_GATE, "gate");
|
||||
obs_property_set_modified_callback(presets, presets_changed);
|
||||
obs_properties_add_float_slider(props, S_RATIO,
|
||||
TEXT_RATIO, MIN_RATIO, MAX_RATIO, 0.1);
|
||||
obs_properties_add_float_slider(props, S_THRESHOLD,
|
||||
TEXT_THRESHOLD, MIN_THRESHOLD_DB, MAX_THRESHOLD_DB,
|
||||
0.1);
|
||||
obs_properties_add_int_slider(props, S_ATTACK_TIME,
|
||||
TEXT_ATTACK_TIME, MIN_ATK_RLS_MS, MAX_ATK_MS, 1);
|
||||
obs_properties_add_int_slider(props, S_RELEASE_TIME,
|
||||
TEXT_RELEASE_TIME, MIN_ATK_RLS_MS, MAX_RLS_MS, 1);
|
||||
obs_properties_add_float_slider(props, S_OUTPUT_GAIN,
|
||||
TEXT_OUTPUT_GAIN, MIN_OUTPUT_GAIN_DB,
|
||||
MAX_OUTPUT_GAIN_DB, 0.1);
|
||||
obs_property_t *detect = obs_properties_add_list(props, S_DETECTOR,
|
||||
TEXT_DETECTOR, OBS_COMBO_TYPE_LIST,
|
||||
OBS_COMBO_FORMAT_STRING);
|
||||
p = obs_properties_add_float_slider(props, S_RATIO, TEXT_RATIO,
|
||||
MIN_RATIO, MAX_RATIO, 0.1);
|
||||
obs_property_float_set_suffix(p, ":1");
|
||||
p = obs_properties_add_float_slider(props, S_THRESHOLD, TEXT_THRESHOLD,
|
||||
MIN_THRESHOLD_DB, MAX_THRESHOLD_DB,
|
||||
0.1);
|
||||
obs_property_float_set_suffix(p, " dB");
|
||||
p = obs_properties_add_int_slider(props, S_ATTACK_TIME,
|
||||
TEXT_ATTACK_TIME, MIN_ATK_RLS_MS,
|
||||
MAX_ATK_MS, 1);
|
||||
obs_property_int_set_suffix(p, " ms");
|
||||
p = obs_properties_add_int_slider(props, S_RELEASE_TIME,
|
||||
TEXT_RELEASE_TIME, MIN_ATK_RLS_MS,
|
||||
MAX_RLS_MS, 1);
|
||||
obs_property_int_set_suffix(p, " ms");
|
||||
p = obs_properties_add_float_slider(props, S_OUTPUT_GAIN,
|
||||
TEXT_OUTPUT_GAIN,
|
||||
MIN_OUTPUT_GAIN_DB,
|
||||
MAX_OUTPUT_GAIN_DB, 0.1);
|
||||
obs_property_float_set_suffix(p, " dB");
|
||||
obs_property_t *detect = obs_properties_add_list(
|
||||
props, S_DETECTOR, TEXT_DETECTOR, OBS_COMBO_TYPE_LIST,
|
||||
OBS_COMBO_FORMAT_STRING);
|
||||
obs_property_list_add_string(detect, TEXT_RMS, "RMS");
|
||||
obs_property_list_add_string(detect, TEXT_PEAK, "peak");
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue