- // Apply a level compressor to get the general level right.
- // Basically, if it's over about -40 dBFS, we squeeze it down to that level
- // (or more precisely, near it, since we don't use infinite ratio),
- // then apply a makeup gain to get it to -14 dBFS. -14 dBFS is, of course,
- // entirely arbitrary, but from practical tests with speech, it seems to
- // put ut around -23 LUFS, so it's a reasonable starting point for later use.
- {
- if (level_compressor_enabled) {
- float threshold = 0.01f; // -40 dBFS.
- float ratio = 20.0f;
- float attack_time = 0.5f;
- float release_time = 20.0f;
- float makeup_gain = from_db(ref_level_dbfs - (-40.0f)); // +26 dB.
- level_compressor.process(samples_out.data(), samples_out.size() / 2, threshold, ratio, attack_time, release_time, makeup_gain);
- gain_staging_db = to_db(level_compressor.get_attenuation() * makeup_gain);
- } else {
- // Just apply the gain we already had.
- float g = from_db(gain_staging_db);
- for (size_t i = 0; i < samples_out.size(); ++i) {
- samples_out[i] *= g;
- }
- }
- }
-
- #if 0
- printf("level=%f (%+5.2f dBFS) attenuation=%f (%+5.2f dB) end_result=%+5.2f dB\n",
- level_compressor.get_level(), to_db(level_compressor.get_level()),
- level_compressor.get_attenuation(), to_db(level_compressor.get_attenuation()),
- to_db(level_compressor.get_level() * level_compressor.get_attenuation() * makeup_gain));
- #endif
-
- // float limiter_att, compressor_att;
-
- // The real compressor.
- if (compressor_enabled) {
- float threshold = from_db(compressor_threshold_dbfs);
- float ratio = 20.0f;
- float attack_time = 0.005f;
- float release_time = 0.040f;
- float makeup_gain = 2.0f; // +6 dB.
- compressor.process(samples_out.data(), samples_out.size() / 2, threshold, ratio, attack_time, release_time, makeup_gain);
- // compressor_att = compressor.get_attenuation();
- }
-