diff --git a/.vscode/.server-controller-port.log b/.vscode/.server-controller-port.log index b6d9663..efa116a 100644 --- a/.vscode/.server-controller-port.log +++ b/.vscode/.server-controller-port.log @@ -1,5 +1,5 @@ { "port": 13452, - "time": 1742673002809, + "time": 1742717063787, "version": "0.0.3" } \ No newline at end of file diff --git a/README.md b/README.md index 1e3adda..bee48a0 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,7 @@ FM95 is a audio processor for FM, it does: Supports these inputs: - Audio (via Pulse) - MPX (via Pulse) -- RDS (via Pulse, expects unmodulated RDS) -- RDS2 (via Pulse, expects unmodulated RDS, one stream on 66.5) +- RDS (via Pulse, expects unmodulated RDS, stereo, left channel on 57 KHz, right on 66.5) - SCA (via Pulse) and one output: diff --git a/lib/oscillator.c b/lib/oscillator.c index cffc1f5..8d3ab81 100644 --- a/lib/oscillator.c +++ b/lib/oscillator.c @@ -23,12 +23,15 @@ float get_oscillator_cos_sample(Oscillator *osc) { } float get_oscillator_sin_multiplier_ni(Oscillator *osc, float multiplier) { // ni = No Increment - return sinf(osc->phase*multiplier); + return sinf(fmodf(osc->phase * multiplier, M_2PI)); } float get_oscillator_cos_multiplier_ni(Oscillator *osc, float multiplier) { - return cosf(osc->phase*multiplier); + return cosf(fmodf(osc->phase * multiplier, M_2PI)); } void advance_oscillator(Oscillator *osc) { - osc->phase = fmodf(osc->phase + osc->phase_increment, M_2PI); + osc->phase += osc->phase_increment; + if (osc->phase >= M_2PI) { + osc->phase -= M_2PI; + } } \ No newline at end of file diff --git a/src/fm95.c b/src/fm95.c index a6acd4b..ea5b6cc 100644 --- a/src/fm95.c +++ b/src/fm95.c @@ -11,7 +11,7 @@ #define DEFAULT_CLIPPER_THRESHOLD 1.0f #define DEFAULT_SCA_FREQUENCY 67000.0f #define DEFAULT_SCA_DEVIATION 7000.0f -#define DEFAULT_SCA_CLIPPER_THRESHOLD 1.0f // Full deviation, if you set this to 0.5 then you may as well set the deviation to 3.5k +#define DEFAULT_SCA_CLIPPER_THRESHOLD 1.0f #define DEFAULT_PREEMPHASIS_TAU 50e-6 // Europe, the freedomers use 75µs #include "../lib/constants.h" @@ -39,7 +39,7 @@ #define PILOT_VOLUME 0.09f // 19 KHz Pilot #define STEREO_VOLUME 0.45f // L-R signal, should be same as MONO #define RDS_VOLUME 0.075f // RDS Volume, after dsb-sc -#define RDS2_VOLUME 0.05f // RDS2 Volume +#define RDS2_VOLUME 0.075f // RDS2 Volume #define SCA_VOLUME 0.1f // FM SCA signal, 10% #define MPX_VOLUME 1.0f // Passtrough #define MPX_CLIPPER_THRESHOLD 1.0f @@ -414,9 +414,6 @@ int main(int argc, char **argv) { ResistorCapacitor preemp_l, preemp_r; init_preemphasis(&preemp_l, preemphasis_tau, sample_rate); init_preemphasis(&preemp_r, preemphasis_tau, sample_rate); - - Oscillator rds2_osc; - init_oscillator(&rds2_osc, 66500, sample_rate); // #endregion signal(SIGINT, stop); @@ -425,6 +422,7 @@ int main(int argc, char **argv) { int pulse_error; float audio_stereo_input[BUFFER_SIZE*2]; + float rds1_rds2_in[BUFFER_SIZE*2] = {0}; float rds1_in[BUFFER_SIZE] = {0}; float rds2_in[BUFFER_SIZE] = {0}; @@ -494,7 +492,7 @@ int main(int argc, char **argv) { float rds_carrier = get_oscillator_sin_multiplier_ni(&osc, 3); output[i] += (current_rds_in*rds_carrier)*RDS_VOLUME; if(!sca_on) { - float rds2_carrier_66 = get_oscillator_sin_sample(&rds2_osc); + float rds2_carrier_66 = get_oscillator_cos_multiplier_ni(&osc, 3.5f); output[i] += (current_rds2_in*rds2_carrier_66)*RDS2_VOLUME; } }