0
1
mirror of https://github.com/radio95-rnt/fm95.git synced 2026-02-27 03:23:54 +01:00
This commit is contained in:
2025-03-25 16:03:19 +01:00
parent ad1856f255
commit 2a8aefb26d
3 changed files with 4 additions and 7 deletions

View File

@@ -14,21 +14,19 @@ float hard_clip(float sample, float threshold) {
return fmaxf(-threshold, fminf(threshold, sample)); return fmaxf(-threshold, fminf(threshold, sample));
} }
void init_pll(PLL *pll, float freq, float loop_filter_bandwidth, float damping, int quadrature_mode, int sample_rate) { void init_pll(PLL *pll, float freq, float loop_filter_bandwidth, float damping, int sample_rate) {
pll->phase = 0.0f; pll->phase = 0.0f;
pll->freq = freq; pll->freq = freq;
pll->loop_filter_state = 0.0f; pll->loop_filter_state = 0.0f;
pll->kp = M_2PI * loop_filter_bandwidth; pll->kp = M_2PI * loop_filter_bandwidth;
pll->ki = (4.0f*damping*damping) * pll->kp * pll->kp; pll->ki = (4.0f*damping*damping) * pll->kp * pll->kp;
pll->sample_rate = sample_rate; pll->sample_rate = sample_rate;
pll->quadrature_mode = quadrature_mode;
} }
float apply_pll(PLL *pll, float ref_sample) { float apply_pll(PLL *pll, float ref_sample) {
float phase_error; float phase_error;
float vco_output = sinf(pll->phase); float vco_output = sinf(pll->phase);
if (pll->quadrature_mode) vco_output = sinf(pll->phase + (M_PI / 2.0f));
phase_error = atan2f(ref_sample, vco_output);; phase_error = atan2f(ref_sample, vco_output);;

View File

@@ -23,7 +23,6 @@ typedef struct {
float kp; float kp;
float ki; float ki;
int sample_rate; int sample_rate;
int quadrature_mode;
} PLL; } PLL;
void init_pll(PLL *pll, float freq, float loop_filter_bandwidth, float damping, int quadrature_mode, int sample_rate); void init_pll(PLL *pll, float freq, float loop_filter_bandwidth, float damping, int sample_rate);
float apply_pll(PLL *pll, float ref_sample); float apply_pll(PLL *pll, float ref_sample);

View File

@@ -416,7 +416,7 @@ int main(int argc, char **argv) {
init_preemphasis(&preemp_r, preemphasis_tau, sample_rate); init_preemphasis(&preemp_r, preemphasis_tau, sample_rate);
PLL rds2_pll; PLL rds2_pll;
init_pll(&rds2_pll, 66500, 1, 2, 1, sample_rate); init_pll(&rds2_pll, 66500, 1, 0.25f, sample_rate);
// #endregion // #endregion
signal(SIGINT, stop); signal(SIGINT, stop);
@@ -492,7 +492,7 @@ int main(int argc, char **argv) {
} }
} }
if(rds_on && polar_stereo == 0) { if(rds_on && polar_stereo == 0) {
float rds_carrier = get_oscillator_cos_multiplier_ni(&osc, 3); float rds_carrier = get_oscillator_sin_multiplier_ni(&osc, 3);
output[i] += (current_rds_in*rds_carrier)*RDS_VOLUME; output[i] += (current_rds_in*rds_carrier)*RDS_VOLUME;
if(!sca_on) { if(!sca_on) {
float rds2_carrier_66 = apply_pll(&rds2_pll, get_oscillator_sin_multiplier_ni(&osc, 1)); float rds2_carrier_66 = apply_pll(&rds2_pll, get_oscillator_sin_multiplier_ni(&osc, 1));