mirror of
https://github.com/radio95-rnt/fm95.git
synced 2026-02-26 19:23:51 +01:00
add soft clipping
This commit is contained in:
@@ -74,7 +74,7 @@ void init_hpf(FrequencyFilter* filter, float cutoffFreq, float sampleRate) {
|
||||
filter->index = 0;
|
||||
}
|
||||
|
||||
float apply_freqeuncy_filter(FrequencyFilter* filter, float input) {
|
||||
float apply_frequency_filter(FrequencyFilter* filter, float input) {
|
||||
// Shift delay line
|
||||
filter->delay[filter->index] = input;
|
||||
|
||||
@@ -92,6 +92,24 @@ float apply_freqeuncy_filter(FrequencyFilter* filter, float input) {
|
||||
return output;
|
||||
}
|
||||
|
||||
float hard_clip(float sample, float threshold) {
|
||||
if (sample > threshold) {
|
||||
return threshold; // Clip to the upper threshold
|
||||
} else if (sample < -threshold) {
|
||||
return -threshold; // Clip to the lower threshold
|
||||
} else {
|
||||
return sample; // No clipping
|
||||
}
|
||||
}
|
||||
float soft_clip(float sample, float threshold) {
|
||||
if (fabs(sample) <= threshold) {
|
||||
return sample; // Linear region
|
||||
} else {
|
||||
float sign = (sample > 0) ? 1.0f : -1.0f;
|
||||
return sign * (threshold + (1.0f - threshold) * pow(fabs(sample) - threshold, 0.5f));
|
||||
}
|
||||
}
|
||||
|
||||
void init_delay_line(DelayLine *delay_line, int max_delay) {
|
||||
delay_line->buffer = (float *)calloc(max_delay, sizeof(float));
|
||||
delay_line->size = max_delay;
|
||||
|
||||
Reference in New Issue
Block a user