mirror of
https://github.com/radio95-rnt/fm95.git
synced 2026-02-26 19:23:51 +01:00
delay rds
This commit is contained in:
32
dsp/delay.c
32
dsp/delay.c
@@ -1,21 +1,25 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include "delay.h"
|
#include "delay.h"
|
||||||
|
|
||||||
void init_delay_line(delay_line_t *delay_line, uint32_t sample_rate) {
|
void init_delay_line(delay_line_t *dl, uint32_t delay_samples) {
|
||||||
delay_line->buffer = malloc(sample_rate * sizeof(float));
|
dl->delay = delay_samples;
|
||||||
memset(delay_line->buffer, 0, sample_rate * sizeof(float));
|
dl->idx = 0;
|
||||||
|
dl->buffer = calloc(delay_samples, sizeof(float));
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_delay_line(delay_line_t *delay_line, uint32_t new_delay) {
|
float delay_line(delay_line_t *dl, float in) {
|
||||||
delay_line->delay = new_delay;
|
float out = dl->buffer[dl->idx]; // read delayed sample
|
||||||
|
|
||||||
|
dl->buffer[dl->idx] = in; // write new input
|
||||||
|
|
||||||
|
dl->idx++;
|
||||||
|
if (dl->idx >= dl->delay) dl->idx = 0;
|
||||||
|
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
float delay_line(delay_line_t *delay_line, float in) {
|
void exit_delay_line(delay_line_t *dl) {
|
||||||
delay_line->buffer[delay_line->idx++] = in;
|
if(dl->buffer != NULL) free(dl->buffer);
|
||||||
if (delay_line->idx >= delay_line->delay) delay_line->idx = 0;
|
dl->buffer = NULL;
|
||||||
return delay_line->buffer[delay_line->idx];
|
|
||||||
}
|
|
||||||
|
|
||||||
void exit_delay_line(delay_line_t *delay_line) {
|
|
||||||
if(delay_line->buffer != NULL) free(delay_line->buffer);
|
|
||||||
delay_line->buffer = NULL;
|
|
||||||
}
|
}
|
||||||
@@ -8,7 +8,6 @@ typedef struct delay_line_t {
|
|||||||
uint32_t idx;
|
uint32_t idx;
|
||||||
} delay_line_t;
|
} delay_line_t;
|
||||||
|
|
||||||
void init_delay_line(delay_line_t *delay_line, uint32_t sample_rate);
|
void init_delay_line(delay_line_t *dl, uint32_t delay_samples);
|
||||||
void set_delay_line(delay_line_t *delay_line, uint32_t new_delay);
|
float delay_line(delay_line_t *dl, float in);
|
||||||
float delay_line(delay_line_t *delay_line, float in);
|
void exit_delay_line(delay_line_t *dl);
|
||||||
void exit_delay_line(delay_line_t *delay_line);
|
|
||||||
|
|||||||
@@ -7,10 +7,8 @@ void init_stereo_encoder(StereoEncoder* st, uint8_t multiplier, Oscillator* osc,
|
|||||||
st->pilot_volume = pilot_volume;
|
st->pilot_volume = pilot_volume;
|
||||||
st->audio_volume = audio_volume;
|
st->audio_volume = audio_volume;
|
||||||
#ifdef STEREO_SSB
|
#ifdef STEREO_SSB
|
||||||
init_delay_line(&st->delay_pilot, osc->sample_rate);
|
init_delay_line(&st->delay_pilot, STEREO_SSB*2+1);
|
||||||
init_delay_line(&st->delay, osc->sample_rate);
|
init_delay_line(&st->delay, STEREO_SSB*2+1);
|
||||||
set_delay_line(&st->delay_pilot, STEREO_SSB*2+1);
|
|
||||||
set_delay_line(&st->delay, STEREO_SSB*2+1);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
13
src/fm95.c
13
src/fm95.c
@@ -83,13 +83,12 @@ typedef struct
|
|||||||
float* rds_in;
|
float* rds_in;
|
||||||
Oscillator osc;
|
Oscillator osc;
|
||||||
iirfilt_rrrf lpf_l, lpf_r;
|
iirfilt_rrrf lpf_l, lpf_r;
|
||||||
#ifdef STEREO_SSB
|
|
||||||
firhilbf stereo_hilbert;
|
firhilbf stereo_hilbert;
|
||||||
#endif
|
|
||||||
ResistorCapacitor preemp_l, preemp_r;
|
ResistorCapacitor preemp_l, preemp_r;
|
||||||
BS412Compressor bs412;
|
BS412Compressor bs412;
|
||||||
StereoEncoder stencode;
|
StereoEncoder stencode;
|
||||||
AGC agc;
|
AGC agc;
|
||||||
|
delay_line_t rds_delays[4];
|
||||||
} FM95_Runtime;
|
} FM95_Runtime;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -238,11 +237,7 @@ int run_fm95(const FM95_Config config, FM95_Runtime* runtime) {
|
|||||||
mod_r = apply_preemphasis(&runtime->preemp_r, mod_r);
|
mod_r = apply_preemphasis(&runtime->preemp_r, mod_r);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef STEREO_SSB
|
|
||||||
mpx = stereo_encode(&runtime->stencode, config.stereo, mod_l, mod_r, &runtime->stereo_hilbert);
|
mpx = stereo_encode(&runtime->stencode, config.stereo, mod_l, mod_r, &runtime->stereo_hilbert);
|
||||||
#else
|
|
||||||
mpx = stereo_encode(&runtime->stencode, config.stereo, mod_l, mod_r);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if(rds_on) {
|
if(rds_on) {
|
||||||
float rds_level = config.volumes.rds;
|
float rds_level = config.volumes.rds;
|
||||||
@@ -250,7 +245,11 @@ int run_fm95(const FM95_Config config, FM95_Runtime* runtime) {
|
|||||||
uint8_t osc_stream = 12 + stream;
|
uint8_t osc_stream = 12 + stream;
|
||||||
if(osc_stream >= 13) osc_stream++;
|
if(osc_stream >= 13) osc_stream++;
|
||||||
|
|
||||||
|
#ifdef STEREO_SSB
|
||||||
|
mpx += (runtime->rds_in[config.rds_streams * i + stream] * delay_line(&runtime->rds_delays[stream], get_oscillator_cos_multiplier_ni(&runtime->osc, osc_stream))) * rds_level;
|
||||||
|
#else
|
||||||
mpx += (runtime->rds_in[config.rds_streams * i + stream] * get_oscillator_cos_multiplier_ni(&runtime->osc, osc_stream)) * rds_level;
|
mpx += (runtime->rds_in[config.rds_streams * i + stream] * get_oscillator_cos_multiplier_ni(&runtime->osc, osc_stream)) * rds_level;
|
||||||
|
#endif
|
||||||
|
|
||||||
rds_level *= config.volumes.rds_step; // Prepare level for the next stream
|
rds_level *= config.volumes.rds_step; // Prepare level for the next stream
|
||||||
}
|
}
|
||||||
@@ -494,6 +493,8 @@ void init_runtime(FM95_Runtime* runtime, const FM95_Config config) {
|
|||||||
|
|
||||||
#ifdef STEREO_SSB
|
#ifdef STEREO_SSB
|
||||||
runtime->stereo_hilbert = firhilbf_create(STEREO_SSB, 80);
|
runtime->stereo_hilbert = firhilbf_create(STEREO_SSB, 80);
|
||||||
|
|
||||||
|
for(int i = 0; i < config.rds_streams; i++) init_delay_line(&runtime->rds_delays[i], STEREO_SSB*2+1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(config.preemphasis != 0) {
|
if(config.preemphasis != 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user