0
1
mirror of https://github.com/radio95-rnt/fm95.git synced 2026-02-26 11:22:00 +01:00

optimize a bit the stereo encoder and in case of read error from the rds or mpx devices just disable them

This commit is contained in:
2025-06-27 10:42:02 +02:00
parent ee1a6f5c14
commit 9c7018132f
3 changed files with 23 additions and 24 deletions

View File

@@ -1,5 +1,5 @@
{ {
"port": 13452, "port": 13452,
"time": 1750505649575, "time": 1751012772726,
"version": "0.0.3" "version": "0.0.3"
} }

View File

@@ -13,14 +13,15 @@ void init_stereo_encoder(StereoEncoder* st, uint8_t multiplier, Oscillator* osc,
float stereo_encode(StereoEncoder* st, uint8_t enabled, float left, float right) { float stereo_encode(StereoEncoder* st, uint8_t enabled, float left, float right) {
float mid = (left+right) * 0.5f; float mid = (left+right) * 0.5f;
if(!enabled) return mid * st->mono_volume; if(!enabled) return mid * st->mono_volume;
float side = (left-right) * 0.5f; float side = (left-right) * 0.5f;
float signalx1 = get_oscillator_sin_multiplier_ni(st->osc, st->multiplier);
if(!st->polar) { if(!st->polar) {
float pilot = get_oscillator_sin_multiplier_ni(st->osc, st->multiplier); float signalx2 = get_oscillator_sin_multiplier_ni(st->osc, st->multiplier * 2.0f);
float carrier = get_oscillator_sin_multiplier_ni(st->osc, st->multiplier * 2.0f); return (mid*st->mono_volume) + (signalx1*st->pilot_volume) + ((side*signalx2) * st->stereo_volume);
return (mid*st->mono_volume) + (pilot*st->pilot_volume) + ((side*carrier) * st->stereo_volume);
} else { } else {
float carrier = get_oscillator_sin_multiplier_ni(st->osc, st->multiplier); return (mid*st->mono_volume) + (((side+0.2f)*signalx1) * st->stereo_volume); // Polar stereo does not contain a pilot, but it contains a -14 db carrier wave on the stereo subcarrier
return (mid*st->mono_volume) + (((side+0.2f)*carrier) * st->stereo_volume); // Polar stereo does not contain a pilot, but it contains a -14 db carrier wave on the stereo subcarrier
} }
} }

View File

@@ -46,9 +46,10 @@
static volatile sig_atomic_t to_run = 1; static volatile sig_atomic_t to_run = 1;
inline float hard_clip(float sample, float threshold) { static PulseInputDevice input_device, mpx_device, rds_device;
return fmaxf(-threshold, fminf(threshold, sample)); static PulseOutputDevice output_device;
}
inline float hard_clip(float sample, float threshold) { return fmaxf(-threshold, fminf(threshold, sample)); }
static void stop(int signum) { static void stop(int signum) {
(void)signum; (void)signum;
@@ -93,10 +94,7 @@ void show_help(char *name) {
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
printf("fm95 (an FM Processor by radio95) version 1.8\n"); printf("fm95 (an FM Processor by radio95) version 1.9\n");
PulseInputDevice input_device, mpx_device, rds_device;
PulseOutputDevice output_device;
float clipper_threshold = DEFAULT_CLIPPER_THRESHOLD; float clipper_threshold = DEFAULT_CLIPPER_THRESHOLD;
uint8_t stereo = DEFAULT_STEREO; uint8_t stereo = DEFAULT_STEREO;
@@ -292,8 +290,8 @@ int main(int argc, char **argv) {
init_oscillator(&osc, polar_stereo ? 7812.5 : 4750, sample_rate); init_oscillator(&osc, polar_stereo ? 7812.5 : 4750, sample_rate);
iirfilt_rrrf lpf_l, lpf_r; iirfilt_rrrf lpf_l, lpf_r;
lpf_l = iirfilt_rrrf_create_prototype(LIQUID_IIRDES_CHEBY2, LIQUID_IIRDES_LOWPASS, LIQUID_IIRDES_SOS, LPF_ORDER, (15000.0f/sample_rate), 0.0f, 1.0f, 40.0f); lpf_l = iirfilt_rrrf_create_prototype(LIQUID_IIRDES_CHEBY2, LIQUID_IIRDES_LOWPASS, LIQUID_IIRDES_SOS, LPF_ORDER, (15000.0f/sample_rate), 0.0f, 1.0f, 60.0f);
lpf_r = iirfilt_rrrf_create_prototype(LIQUID_IIRDES_CHEBY2, LIQUID_IIRDES_LOWPASS, LIQUID_IIRDES_SOS, LPF_ORDER, (15000.0f/sample_rate), 0.0f, 1.0f, 40.0f); lpf_r = iirfilt_rrrf_create_prototype(LIQUID_IIRDES_CHEBY2, LIQUID_IIRDES_LOWPASS, LIQUID_IIRDES_SOS, LPF_ORDER, (15000.0f/sample_rate), 0.0f, 1.0f, 60.0f);
ResistorCapacitor preemp_l, preemp_r; ResistorCapacitor preemp_l, preemp_r;
init_preemphasis(&preemp_l, preemphasis_tau, sample_rate, 15250.0f); init_preemphasis(&preemp_l, preemphasis_tau, sample_rate, 15250.0f);
@@ -335,16 +333,18 @@ int main(int argc, char **argv) {
if((pulse_error = read_PulseInputDevice(&mpx_device, mpx_in, sizeof(mpx_in)))) { if((pulse_error = read_PulseInputDevice(&mpx_device, mpx_in, sizeof(mpx_in)))) {
if(pulse_error == -1) fprintf(stderr, "MPX PulseInputDevice reported as uninitialized."); if(pulse_error == -1) fprintf(stderr, "MPX PulseInputDevice reported as uninitialized.");
else fprintf(stderr, "Error reading from MPX device: %s\n", pa_strerror(pulse_error)); else fprintf(stderr, "Error reading from MPX device: %s\n", pa_strerror(pulse_error));
to_run = 0; fprintf(stderr, "Disabling MPX.\n");
break; mpx_on = 0;
free_PulseInputDevice(&mpx_device);
} }
} }
if(rds_on) { if(rds_on) {
if((pulse_error = read_PulseInputDevice(&rds_device, rds_in, sizeof(float) * BUFFER_SIZE * rds_streams))) { if((pulse_error = read_PulseInputDevice(&rds_device, rds_in, sizeof(float) * BUFFER_SIZE * rds_streams))) {
if(pulse_error == -1) fprintf(stderr, "RDS95 PulseInputDevice reported as uninitialized."); if(pulse_error == -1) fprintf(stderr, "RDS95 PulseInputDevice reported as uninitialized.");
else fprintf(stderr, "Error reading from RDS95 device: %s\n", pa_strerror(pulse_error)); else fprintf(stderr, "Error reading from RDS95 device: %s\n", pa_strerror(pulse_error));
to_run = 0; fprintf(stderr, "Disabling RDS.\n");
break; rds_on = 0;
free_PulseInputDevice(&rds_device);
} }
} }
@@ -367,7 +367,7 @@ int main(int argc, char **argv) {
if(rds_on && !polar_stereo) { if(rds_on && !polar_stereo) {
for(uint8_t stream = 0; stream < rds_streams; stream++) { for(uint8_t stream = 0; stream < rds_streams; stream++) {
uint8_t osc_stream = 12+stream; uint8_t osc_stream = 12+stream; // If the osc is a 4750 sine wave, then doing this would mean that stream 0 is 12, so 57 khz
if(osc_stream == 13) osc_stream++; // 61.75 KHz is not used, idk why but would be cool if it was if(osc_stream == 13) osc_stream++; // 61.75 KHz is not used, idk why but would be cool if it was
mpx += (rds_in[rds_streams*i+stream]*get_oscillator_cos_multiplier_ni(&osc, osc_stream)) * (RDS_VOLUME * powf(RDS_VOLUME_STEP, stream)); mpx += (rds_in[rds_streams*i+stream]*get_oscillator_cos_multiplier_ni(&osc, osc_stream)) * (RDS_VOLUME * powf(RDS_VOLUME_STEP, stream));
} }
@@ -383,11 +383,9 @@ int main(int argc, char **argv) {
target_gain = fmaxf(target_gain, 0.1f); target_gain = fmaxf(target_gain, 0.1f);
target_gain = fminf(target_gain, 1.0f); target_gain = fminf(target_gain, 1.0f);
bs412_audio_gain = 0.85f * bs412_audio_gain + 0.15f * target_gain; bs412_audio_gain = 0.8f * bs412_audio_gain + 0.2f * target_gain;
} }
} else { } else bs412_audio_gain = fminf(1.5f, bs412_audio_gain + 0.001f);
bs412_audio_gain = fminf(1.0f, bs412_audio_gain + 0.001f);
}
mpx *= bs412_audio_gain; mpx *= bs412_audio_gain;