mirror of
https://github.com/radio95-rnt/fm95.git
synced 2026-02-26 19:23:51 +01:00
change bs412 gain reduction logic, still issue #2 should be unchanged
This commit is contained in:
12
dsp/bs412.c
12
dsp/bs412.c
@@ -1,5 +1,7 @@
|
|||||||
#include "bs412.h"
|
#include "bs412.h"
|
||||||
|
|
||||||
|
#define BS412_RMS
|
||||||
|
|
||||||
#define LOG2_19000 log2f(19000.0f)
|
#define LOG2_19000 log2f(19000.0f)
|
||||||
|
|
||||||
inline float dbr_to_deviation(float dbr) {
|
inline float dbr_to_deviation(float dbr) {
|
||||||
@@ -21,11 +23,19 @@ void init_modulation_power_measure(MPXPowerMeasurement* mpx, int sample_rate) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
float measure_mpx(MPXPowerMeasurement* mpx, float deviation) {
|
float measure_mpx(MPXPowerMeasurement* mpx, float deviation) {
|
||||||
|
#ifdef BS412_RMS
|
||||||
mpx->sample += deviation * deviation; // rmS
|
mpx->sample += deviation * deviation; // rmS
|
||||||
|
#else
|
||||||
|
mpx->sample += fabsf(deviation);
|
||||||
|
#endif
|
||||||
mpx->sample_counter++;
|
mpx->sample_counter++;
|
||||||
|
|
||||||
float inv_counter = 1.0f / mpx->sample_counter;
|
float inv_counter = 1.0f / mpx->sample_counter;
|
||||||
|
#ifdef BS412_RMS
|
||||||
float avg_deviation = sqrtf(mpx->sample * inv_counter); // RMs
|
float avg_deviation = sqrtf(mpx->sample * inv_counter); // RMs
|
||||||
|
#else
|
||||||
|
float avg_deviation = mpx->sample * inv_counter; // RMs
|
||||||
|
#endif
|
||||||
float modulation_power = deviation_to_dbr(avg_deviation);
|
float modulation_power = deviation_to_dbr(avg_deviation);
|
||||||
|
|
||||||
#ifdef BS412_DEBUG
|
#ifdef BS412_DEBUG
|
||||||
@@ -38,7 +48,7 @@ float measure_mpx(MPXPowerMeasurement* mpx, float deviation) {
|
|||||||
#ifdef BS412_DEBUG
|
#ifdef BS412_DEBUG
|
||||||
debug_printf("Resetting MPX power measurement\n");
|
debug_printf("Resetting MPX power measurement\n");
|
||||||
#endif
|
#endif
|
||||||
mpx->sample = avg_deviation * avg_deviation;
|
mpx->sample = deviation * deviation;
|
||||||
mpx->sample_counter = 1;
|
mpx->sample_counter = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
17
src/fm95.c
17
src/fm95.c
@@ -3,7 +3,7 @@
|
|||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <liquid/liquid.h>
|
#include <liquid/liquid.h>
|
||||||
|
|
||||||
#define LPF_ORDER 18
|
#define LPF_ORDER 17
|
||||||
|
|
||||||
#define buffer_maxlength 12288
|
#define buffer_maxlength 12288
|
||||||
#define buffer_tlength_fragsize 12288
|
#define buffer_tlength_fragsize 12288
|
||||||
@@ -518,11 +518,18 @@ int main(int argc, char **argv) {
|
|||||||
float mpower = measure_mpx(&power, (audio+mpx) * mpx_deviation); // Standard requires that the output is measured specifically
|
float mpower = measure_mpx(&power, (audio+mpx) * mpx_deviation); // Standard requires that the output is measured specifically
|
||||||
if (mpower > mpx_power) {
|
if (mpower > mpx_power) {
|
||||||
float excess_power = 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
|
excess_power = deviation_to_dbr(dbr_to_deviation(excess_power) - dbr_to_deviation(mpx_only));
|
||||||
|
|
||||||
float target_gain = dbr_to_deviation(-excess_power)/mpx_deviation;
|
if (excess_power > 0.0f && excess_power < 10.0f) {
|
||||||
bs412_audio_gain = 0.9f * bs412_audio_gain + 0.1f * target_gain;
|
float target_gain = dbr_to_deviation(-excess_power) / mpx_deviation;
|
||||||
audio *= bs412_audio_gain;
|
|
||||||
|
target_gain = fmaxf(target_gain, 0.1f);
|
||||||
|
target_gain = fminf(target_gain, 1.0f);
|
||||||
|
|
||||||
|
bs412_audio_gain = 0.9f * bs412_audio_gain + 0.1f * target_gain;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
bs412_audio_gain = fminf(1.0f, bs412_audio_gain + 0.001f);
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user