0
1
mirror of https://github.com/radio95-rnt/fm95.git synced 2026-02-26 19:23:51 +01:00
This commit is contained in:
2024-12-31 14:23:26 +01:00
parent 64538478e4
commit c96fe78618
4 changed files with 324 additions and 12 deletions

View File

@@ -79,14 +79,14 @@ float get_next_sample(Oscillator *osc) {
typedef struct {
float alpha;
float prev_sample;
} PreEmphasis;
} Emphasis;
void init_pre_emphasis(PreEmphasis *pe, float sample_rate) {
void init_emphasis(Emphasis *pe, float sample_rate) {
pe->prev_sample = 0.0f;
pe->alpha = exp(-1 / (PREEMPHASIS_TAU * sample_rate));
}
float apply_pre_emphasis(PreEmphasis *pe, float sample) {
float apply_pre_emphasis(Emphasis *pe, float sample) {
float audio = sample-pe->alpha*pe->prev_sample;
pe->prev_sample = audio;
return audio*2;
@@ -200,9 +200,9 @@ int main() {
Oscillator pilot_osc;
init_oscillator(&pilot_osc, 19000.0, SAMPLE_RATE); // Pilot, it's there to indicate stereo and as a refrence signal with the stereo carrier
#ifdef PREEMPHASIS
PreEmphasis preemp_l, preemp_r;
init_pre_emphasis(&preemp_l, SAMPLE_RATE);
init_pre_emphasis(&preemp_r, SAMPLE_RATE);
Emphasis preemp_l, preemp_r;
init_emphasis(&preemp_l, SAMPLE_RATE);
init_emphasis(&preemp_r, SAMPLE_RATE);
#endif
#ifdef LPF
LowPassFilter lpf_l, lpf_r;
@@ -224,7 +224,7 @@ int main() {
uninterleave(input, left, right, BUFFER_SIZE*2);
for (int i = 0; i < BUFFER_SIZE; i++) {
float stereo_carrier = sinf(pilot_osc.phase*2); // Stereo carrier should be a harmonic of the pilot which is in phase, best way to generate the harmonic is to multiply the pilot's phase by two
float stereo_carrier = sinf(pilot_osc.phase*2); // Stereo carrier should be a harmonic of the pilot which is in phase, best way to generate the harmonic is to multiply the pilot's phase by two, so it is mathematically impossible for them to not be in phase
float pilot = get_next_sample(&pilot_osc); // This is after because if it was before then the stereo would be out of phase by one increment, so [GET STEREO] ([GET PILOT] [INCREMENT PHASE])
float l_in = left[i];
float r_in = right[i];