mirror of
https://github.com/radio95-rnt/fm95.git
synced 2026-02-26 19:23:51 +01:00
some optimalizations
This commit is contained in:
@@ -10,15 +10,9 @@ float apply_preemphasis(ResistorCapacitor *filter, float sample) {
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
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 hard_clip_fast(float sample, float threshold) {
|
||||
// Branchless clipping
|
||||
return fmaxf(-threshold, fminf(threshold, sample));
|
||||
}
|
||||
|
||||
float voltage_db_to_voltage(float db) {
|
||||
|
||||
@@ -10,6 +10,7 @@ void init_fm_modulator(FMModulator *fm, float frequency, float deviation, float
|
||||
float modulate_fm(FMModulator *fm, float sample) {
|
||||
float inst_freq = fm->frequency+(sample*fm->deviation);
|
||||
if (inst_freq < 0.0f) inst_freq = 0.0f;
|
||||
float out = sinf(fm->osc_phase);
|
||||
fm->osc_phase += fmodf(fm->osc_phase + ((M_2PI * inst_freq) / fm->sample_rate), M_2PI);
|
||||
return sinf(fm->osc_phase);
|
||||
return out;
|
||||
}
|
||||
Reference in New Issue
Block a user