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:
2
.vscode/.server-controller-port.log
vendored
2
.vscode/.server-controller-port.log
vendored
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"port": 13452,
|
||||
"time": 1750505649575,
|
||||
"time": 1751012772726,
|
||||
"version": "0.0.3"
|
||||
}
|
||||
@@ -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 mid = (left+right) * 0.5f;
|
||||
if(!enabled) return mid * st->mono_volume;
|
||||
|
||||
float side = (left-right) * 0.5f;
|
||||
|
||||
float signalx1 = get_oscillator_sin_multiplier_ni(st->osc, st->multiplier);
|
||||
|
||||
if(!st->polar) {
|
||||
float pilot = get_oscillator_sin_multiplier_ni(st->osc, st->multiplier);
|
||||
float carrier = get_oscillator_sin_multiplier_ni(st->osc, st->multiplier * 2.0f);
|
||||
return (mid*st->mono_volume) + (pilot*st->pilot_volume) + ((side*carrier) * st->stereo_volume);
|
||||
float signalx2 = 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);
|
||||
} else {
|
||||
float carrier = get_oscillator_sin_multiplier_ni(st->osc, st->multiplier);
|
||||
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
|
||||
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
|
||||
}
|
||||
}
|
||||
34
src/fm95.c
34
src/fm95.c
@@ -46,9 +46,10 @@
|
||||
|
||||
static volatile sig_atomic_t to_run = 1;
|
||||
|
||||
inline float hard_clip(float sample, float threshold) {
|
||||
return fmaxf(-threshold, fminf(threshold, sample));
|
||||
}
|
||||
static PulseInputDevice input_device, mpx_device, rds_device;
|
||||
static PulseOutputDevice output_device;
|
||||
|
||||
inline float hard_clip(float sample, float threshold) { return fmaxf(-threshold, fminf(threshold, sample)); }
|
||||
|
||||
static void stop(int signum) {
|
||||
(void)signum;
|
||||
@@ -93,10 +94,7 @@ void show_help(char *name) {
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
printf("fm95 (an FM Processor by radio95) version 1.8\n");
|
||||
|
||||
PulseInputDevice input_device, mpx_device, rds_device;
|
||||
PulseOutputDevice output_device;
|
||||
printf("fm95 (an FM Processor by radio95) version 1.9\n");
|
||||
|
||||
float clipper_threshold = DEFAULT_CLIPPER_THRESHOLD;
|
||||
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);
|
||||
|
||||
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_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_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, 60.0f);
|
||||
|
||||
ResistorCapacitor preemp_l, preemp_r;
|
||||
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 == -1) fprintf(stderr, "MPX PulseInputDevice reported as uninitialized.");
|
||||
else fprintf(stderr, "Error reading from MPX device: %s\n", pa_strerror(pulse_error));
|
||||
to_run = 0;
|
||||
break;
|
||||
fprintf(stderr, "Disabling MPX.\n");
|
||||
mpx_on = 0;
|
||||
free_PulseInputDevice(&mpx_device);
|
||||
}
|
||||
}
|
||||
if(rds_on) {
|
||||
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.");
|
||||
else fprintf(stderr, "Error reading from RDS95 device: %s\n", pa_strerror(pulse_error));
|
||||
to_run = 0;
|
||||
break;
|
||||
fprintf(stderr, "Disabling RDS.\n");
|
||||
rds_on = 0;
|
||||
free_PulseInputDevice(&rds_device);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -367,7 +367,7 @@ int main(int argc, char **argv) {
|
||||
|
||||
if(rds_on && !polar_stereo) {
|
||||
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
|
||||
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 = 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 {
|
||||
bs412_audio_gain = fminf(1.0f, bs412_audio_gain + 0.001f);
|
||||
}
|
||||
} else bs412_audio_gain = fminf(1.5f, bs412_audio_gain + 0.001f);
|
||||
|
||||
mpx *= bs412_audio_gain;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user