mirror of
https://github.com/radio95-rnt/fm95.git
synced 2026-02-26 19:23:51 +01:00
turn lpf and emphasis into a common rc
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": 1735989625302,
|
||||
"time": 1737462229390,
|
||||
"version": "0.0.3"
|
||||
}
|
||||
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
@@ -9,6 +9,8 @@
|
||||
"stdlib.h": "c",
|
||||
"error.h": "c",
|
||||
"math.h": "c",
|
||||
"options.h": "c"
|
||||
"options.h": "c",
|
||||
"random": "c",
|
||||
"__locale": "c"
|
||||
}
|
||||
}
|
||||
@@ -1,25 +1,23 @@
|
||||
#include "filters.h"
|
||||
|
||||
void init_emphasis(Emphasis *pe, float tau, float sample_rate) {
|
||||
pe->prev_sample = 0.0f;
|
||||
pe->alpha = exp(-1 / (tau * sample_rate));
|
||||
void init_rc(ResistorCapacitor *rc, float tau, float sample_rate) {
|
||||
rc->prev_sample = 0.0f;
|
||||
rc->alpha = exp(-1 / (tau * sample_rate));
|
||||
}
|
||||
|
||||
float apply_pre_emphasis(Emphasis *pe, float sample) {
|
||||
float audio = sample-pe->alpha*pe->prev_sample;
|
||||
pe->prev_sample = audio;
|
||||
float apply_pre_emphasis(ResistorCapacitor *rc, float sample) {
|
||||
float audio = sample-rc->alpha*rc->prev_sample;
|
||||
rc->prev_sample = audio;
|
||||
return audio*2;
|
||||
}
|
||||
|
||||
void init_low_pass_filter(LowPassFilter *lp, float cutoff_frequency, float sample_rate) {
|
||||
float rc = 1/(M_2PI*cutoff_frequency);
|
||||
lp->alpha = sample_rate/(sample_rate+rc);
|
||||
lp->prev_sample = 0.0f;
|
||||
void init_low_pass_filter(ResistorCapacitor *rc, float cutoff_frequency, float sample_rate) {
|
||||
init_rc(&rc, (-1 / (sample_rate * log(sample_rate/(sample_rate+(1/(M_2PI*cutoff_frequency)))))), sample_rate);
|
||||
}
|
||||
|
||||
float apply_low_pass_filter(LowPassFilter *lp, float sample) {
|
||||
float output = lp->alpha*sample+(1-lp->alpha)*lp->prev_sample;
|
||||
lp->prev_sample = output;
|
||||
float apply_low_pass_filter(ResistorCapacitor *rc, float sample) {
|
||||
float output = rc->alpha*sample+(1-rc->alpha)*rc->prev_sample;
|
||||
rc->prev_sample = output;
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,18 +11,13 @@
|
||||
typedef struct {
|
||||
float alpha;
|
||||
float prev_sample;
|
||||
} Emphasis;
|
||||
} ResistorCapacitor;
|
||||
|
||||
void init_emphasis(Emphasis *pe, float tau, float sample_rate);
|
||||
float apply_pre_emphasis(Emphasis *pe, float sample);
|
||||
void init_rc(ResistorCapacitor *pe, float tau, float sample_rate);
|
||||
float apply_pre_emphasis(ResistorCapacitor *pe, float sample);
|
||||
|
||||
typedef struct {
|
||||
float alpha;
|
||||
float prev_sample;
|
||||
} LowPassFilter;
|
||||
|
||||
void init_low_pass_filter(LowPassFilter *lp, float cutoff_frequency, float sample_rate);
|
||||
float apply_low_pass_filter(LowPassFilter *lp, float sample);
|
||||
void init_low_pass_filter(ResistorCapacitor *lp, float cutoff_frequency, float sample_rate);
|
||||
float apply_low_pass_filter(ResistorCapacitor *lp, float sample);
|
||||
|
||||
|
||||
typedef struct {
|
||||
|
||||
@@ -122,9 +122,9 @@ int main() {
|
||||
Oscillator osc;
|
||||
init_oscillator(&osc, 50000.0, SAMPLE_RATE);
|
||||
#ifdef PREEMPHASIS
|
||||
Emphasis preemp_l, preemp_r;
|
||||
init_emphasis(&preemp_l, PREEMPHASIS_TAU, SAMPLE_RATE);
|
||||
init_emphasis(&preemp_r, PREEMPHASIS_TAU, SAMPLE_RATE);
|
||||
ResistorCapacitor preemp_l, preemp_r;
|
||||
init_rc(&preemp_l, PREEMPHASIS_TAU, SAMPLE_RATE);
|
||||
init_rc(&preemp_r, PREEMPHASIS_TAU, SAMPLE_RATE);
|
||||
#endif
|
||||
#ifdef LPF
|
||||
LowPassFilter lpf_l, lpf_r;
|
||||
|
||||
@@ -104,8 +104,8 @@ int main() {
|
||||
}
|
||||
|
||||
#ifdef PREEMPHASIS
|
||||
Emphasis preemp;
|
||||
init_emphasis(&preemp, PREEMPHASIS_TAU, SAMPLE_RATE);
|
||||
ResistorCapacitor preemp;
|
||||
init_rc(&preemp, PREEMPHASIS_TAU, SAMPLE_RATE);
|
||||
#endif
|
||||
#ifdef LPF
|
||||
LowPassFilter lpf;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// #define PREEMPHASIS
|
||||
#define PREEMPHASIS
|
||||
// #define LPF
|
||||
|
||||
#define buffer_maxlength 12288
|
||||
|
||||
@@ -121,9 +121,9 @@ int main() {
|
||||
Oscillator stereo_osc;
|
||||
init_oscillator(&stereo_osc, 31250.0, SAMPLE_RATE);
|
||||
#ifdef PREEMPHASIS
|
||||
Emphasis preemp_l, preemp_r;
|
||||
init_emphasis(&preemp_l, PREEMPHASIS_TAU, SAMPLE_RATE);
|
||||
init_emphasis(&preemp_r, PREEMPHASIS_TAU, SAMPLE_RATE);
|
||||
ResistorCapacitor preemp_l, preemp_r;
|
||||
init_rc(&preemp_l, PREEMPHASIS_TAU, SAMPLE_RATE);
|
||||
init_rc(&preemp_r, PREEMPHASIS_TAU, SAMPLE_RATE);
|
||||
#endif
|
||||
#ifdef LPF
|
||||
LowPassFilter lpf_l, lpf_r;
|
||||
|
||||
@@ -112,8 +112,8 @@ int main() {
|
||||
FMModulator mod;
|
||||
init_fm_modulator(&mod, FREQUENCY, DEVIATION, SAMPLE_RATE);
|
||||
#ifdef PREEMPHASIS
|
||||
Emphasis preemp;
|
||||
init_emphasis(&preemp, PREEMPHASIS_TAU, SAMPLE_RATE);
|
||||
ResistorCapacitor preemp;
|
||||
init_rc(&preemp, PREEMPHASIS_TAU, SAMPLE_RATE);
|
||||
#endif
|
||||
#ifdef LPF
|
||||
LowPassFilter lpf;
|
||||
|
||||
@@ -128,9 +128,9 @@ int main() {
|
||||
DelayLine monoDelay;
|
||||
init_delay_line(&monoDelay, 99);
|
||||
#ifdef PREEMPHASIS
|
||||
Emphasis preemp_l, preemp_r;
|
||||
init_emphasis(&preemp_l, PREEMPHASIS_TAU, SAMPLE_RATE);
|
||||
init_emphasis(&preemp_r, PREEMPHASIS_TAU, SAMPLE_RATE);
|
||||
ResistorCapacitor preemp_l, preemp_r;
|
||||
init_rc(&preemp_l, PREEMPHASIS_TAU, SAMPLE_RATE);
|
||||
init_rc(&preemp_r, PREEMPHASIS_TAU, SAMPLE_RATE);
|
||||
#endif
|
||||
#ifdef LPF
|
||||
LowPassFilter lpf_l, lpf_r;
|
||||
|
||||
@@ -122,9 +122,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
|
||||
Emphasis preemp_l, preemp_r;
|
||||
init_emphasis(&preemp_l, PREEMPHASIS_TAU, SAMPLE_RATE);
|
||||
init_emphasis(&preemp_r, PREEMPHASIS_TAU, SAMPLE_RATE);
|
||||
ResistorCapacitor preemp_l, preemp_r;
|
||||
init_rc(&preemp_l, PREEMPHASIS_TAU, SAMPLE_RATE);
|
||||
init_rc(&preemp_r, PREEMPHASIS_TAU, SAMPLE_RATE);
|
||||
#endif
|
||||
#ifdef LPF
|
||||
LowPassFilter lpf_l, lpf_r;
|
||||
|
||||
@@ -124,9 +124,9 @@ int main() {
|
||||
init_fm_modulator(&mod_mono, 67000, 6000, SAMPLE_RATE);
|
||||
init_fm_modulator(&mod_stereo, 80000, 6000, SAMPLE_RATE);
|
||||
#ifdef PREEMPHASIS
|
||||
Emphasis preemp_l, preemp_r;
|
||||
init_emphasis(&preemp_l, PREEMPHASIS_TAU, SAMPLE_RATE);
|
||||
init_emphasis(&preemp_r, PREEMPHASIS_TAU, SAMPLE_RATE);
|
||||
ResistorCapacitor preemp_l, preemp_r;
|
||||
init_rc(&preemp_l, PREEMPHASIS_TAU, SAMPLE_RATE);
|
||||
init_rc(&preemp_r, PREEMPHASIS_TAU, SAMPLE_RATE);
|
||||
#endif
|
||||
#ifdef LPF
|
||||
LowPassFilter lpf_l, lpf_r;
|
||||
|
||||
Reference in New Issue
Block a user