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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user