From b3015772278dbf588a950c109da6f2f008b4d260 Mon Sep 17 00:00:00 2001 From: KubaPro010 Date: Sat, 31 May 2025 11:18:12 +0200 Subject: [PATCH] add peak power limit to bs412 --- src/fm95.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/fm95.c b/src/fm95.c index ee67c77..18c4c9f 100644 --- a/src/fm95.c +++ b/src/fm95.c @@ -569,6 +569,8 @@ int main(int argc, char **argv) { float mpx_only = measure_mpx(&mpx_only_power, mpx * mpx_deviation); float mpower = measure_mpx(&power, (audio+mpx) * mpx_deviation); // Standard requires that the output is measured specifically + float peak_mpx_only = deviation_to_dbr(mpx * mpx_deviation); + float peak_mpower = deviation_to_dbr((audio+mpx) * mpx_deviation); if (mpower > mpx_power) { float excess_power = mpower - mpx_power; excess_power = deviation_to_dbr(dbr_to_deviation(excess_power) - dbr_to_deviation(mpx_only)); // make sure mpx is not included in the power to attenuate, because we'd be attuating the mpx signal for audio @@ -576,6 +578,9 @@ int main(int argc, char **argv) { float target_gain = dbr_to_deviation(-excess_power)/mpx_deviation; bs412_audio_gain = 0.9f * bs412_audio_gain + 0.1f * target_gain; audio *= bs412_audio_gain; + } else if (peak_mpower > (mpx_power + 0.1f)) { + float target_gain = dbr_to_deviation(mpx_power - mpower)/mpx_deviation; + bs412_audio_gain = 0.8f * bs412_audio_gain + 0.2f * target_gain; } iirfilt_rrrf_execute(mpx_lpf, audio, &audio); // Should have no effect, as audio should be 0-15, and 23-53, this is a filter for 53, assuming the filter is good, this is precaution and recomendation