mirror of
https://github.com/radio95-rnt/fm95.git
synced 2026-02-27 11:33:54 +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
|
||||
|
||||
@@ -23,6 +23,15 @@ typedef struct {
|
||||
void init_lpf(BiquadFilter* filter, float cutoffFreq, float qFactor, float sampleRate);
|
||||
float apply_biquad(BiquadFilter* filter, float input);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int i;
|
||||
int ratio;
|
||||
BiquadFilter lpf;
|
||||
} Upsampler;
|
||||
void init_upsampler(Upsampler* up, int ratio, float sample_rate);
|
||||
float upsample(Upsampler *up, float sample);
|
||||
|
||||
float hard_clip(float sample, float threshold);
|
||||
float voltage_db_to_voltage(float db);
|
||||
float power_db_to_voltage(float db);
|
||||
|
||||
Reference in New Issue
Block a user