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

add a upsampler

This commit is contained in:
2025-03-08 21:19:15 +01:00
parent 2c97f9c8f9
commit 568f8194ee
3 changed files with 47 additions and 5 deletions

View File

@@ -31,6 +31,28 @@ float apply_biquad(BiquadFilter* filter, float input) {
return out;
}
void init_upsampler(Upsampler* up, int ratio, float sample_rate) {
up->i = 0;
up->ratio = ratio;
init_lpf(&up->lpf, sample_rate*ratio, 0.70710678f, sample_rate);
}
float upsample(Upsampler* up, float sample) {
float output = 0.0f;
if (up->i == 0) {
output = sample * up->ratio;
} else {
output = 0.0f;
}
output = apply_biquad(&up->lpf, output);
up->i = (up->i + 1) % up->ratio;
return output;
}
float hard_clip(float sample, float threshold) {
if (sample > threshold) {
return threshold; // Clip to the upper threshold