0
1
mirror of https://github.com/radio95-rnt/fm95.git synced 2026-02-26 19:23:51 +01:00

small changes

This commit is contained in:
2025-03-02 09:25:50 +01:00
parent 3cf6c4ef82
commit 1d2bedb06b
4 changed files with 31 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
{
"port": 13452,
"time": 1740856477215,
"time": 1740903386827,
"version": "0.0.3"
}

View File

@@ -60,6 +60,32 @@ void init_hpf(BiquadFilter* filter, float cutoffFreq, float qFactor, float sampl
filter->a2 = -_a2/_a0;
}
void init_bpf(BiquadFilter* filter, float centerFreq, float qFactor, float sampleRate) {
float x = (centerFreq * M_2PI) / sampleRate;
float sinX = sin(x);
float cosX = cos(x);
float alpha = sinX / (2.0f * qFactor);
float _a0 = 1.0f + alpha;
float _a1 = -2.0f * cosX;
float _a2 = 1.0f - alpha;
float _b0 = alpha;
float _b1 = 0.0f;
float _b2 = -alpha;
filter->y2 = 0;
filter->y1 = 0;
filter->x2 = 0;
filter->x1 = 0;
filter->b0 = _b0 / _a0;
filter->b1 = _b1 / _a0;
filter->b2 = _b2 / _a0;
filter->a1 = -_a1 / _a0;
filter->a2 = -_a2 / _a0;
}
float apply_frequency_filter(BiquadFilter* filter, float input) {
float out = input*filter->b0+filter->x1*filter->b1+filter->x2*filter->b2+filter->y1*filter->a1+filter->y2*filter->a2;
filter->y2 = filter->y1;

View File

@@ -22,6 +22,7 @@ typedef struct {
} BiquadFilter;
void init_lpf(BiquadFilter* filter, float cutoffFreq, float qFactor, float sampleRate);
void init_hpf(BiquadFilter* filter, float cutoffFreq, float qFactor, float sampleRate);
void init_bpf(BiquadFilter* filter, float centerFreq, float qFactor, float sampleRate);
float apply_frequency_filter(BiquadFilter* filter, float input);
float hard_clip(float sample, float threshold);

View File

@@ -40,6 +40,7 @@
#define STEREO_VOLUME 0.45f // L-R signal, should be same as MONO
#define SCA_VOLUME 0.1f // FM SCA signal, 10%
#define MPX_VOLUME 1.0f // Passtrough
#define MPX_CLIPPER_THRESHOLD 1.0f
#define LPF_CUTOFF 15000 // Should't need to be changed
@@ -375,7 +376,7 @@ int main(int argc, char **argv) {
init_lpf(&lpf_r, LPF_CUTOFF, 1.25f, SAMPLE_RATE);
StereoCompressor comp;
init_compressor_stereo(&comp, -2.5f, 20.0f, 8.0f, 3.0f, 0.02f, 0.4f, 0.015f, SAMPLE_RATE);
init_compressor_stereo(&comp, -2.0f, 24.0f, 2.0f, 0.0f, 0.025f, 0.4f, 0.04f, SAMPLE_RATE);
// #endregion
signal(SIGINT, stop);
@@ -439,7 +440,7 @@ int main(int argc, char **argv) {
}
advance_oscillator(&osc);
}
if(strlen(audio_mpx_device) != 0) output[i] += hard_clip(current_mpx_in, 1.0f)*MPX_VOLUME;
if(strlen(audio_mpx_device) != 0) output[i] += hard_clip(current_mpx_in, MPX_CLIPPER_THRESHOLD)*MPX_VOLUME;
if(strlen(audio_sca_device) != 0) output[i] += modulate_fm(&sca_mod, hard_clip(current_sca_in, sca_clipper_threshold))*SCA_VOLUME;
output[i] *= master_volume;
}