mirror of
https://github.com/radio95-rnt/fm95.git
synced 2026-02-26 19:23:51 +01:00
correct the fm mod
This commit is contained in:
@@ -13,20 +13,4 @@ float apply_preemphasis(ResistorCapacitor *filter, float sample) {
|
|||||||
float hard_clip(float sample, float threshold) {
|
float hard_clip(float sample, float threshold) {
|
||||||
// Branchless clipping
|
// Branchless clipping
|
||||||
return fmaxf(-threshold, fminf(threshold, sample));
|
return fmaxf(-threshold, fminf(threshold, sample));
|
||||||
}
|
}
|
||||||
|
|
||||||
float voltage_db_to_voltage(float db) {
|
|
||||||
return powf(10.0f, db / 20.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
float power_db_to_voltage(float db) {
|
|
||||||
return powf(10.0f, db / 10.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
float voltage_to_voltage_db(float linear) {
|
|
||||||
return 20.0f * log10f(fmaxf(linear, 1e-10f)); // Avoid log(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
float voltage_to_power_db(float linear) {
|
|
||||||
return 10.0f * log10f(fmaxf(linear, 1e-10f)); // Avoid log(0)
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#define FILTER_TAPS 256
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -14,8 +13,4 @@ typedef struct
|
|||||||
void init_preemphasis(ResistorCapacitor *filter, float tau, float sample_rate);
|
void init_preemphasis(ResistorCapacitor *filter, float tau, float sample_rate);
|
||||||
float apply_preemphasis(ResistorCapacitor *filter, float sample);
|
float apply_preemphasis(ResistorCapacitor *filter, float sample);
|
||||||
|
|
||||||
float hard_clip(float sample, float threshold);
|
float hard_clip(float sample, float threshold);
|
||||||
float voltage_db_to_voltage(float db);
|
|
||||||
float power_db_to_voltage(float db);
|
|
||||||
float voltage_to_voltage_db(float linear);
|
|
||||||
float voltage_to_power_db(float linear);
|
|
||||||
@@ -11,6 +11,6 @@ float modulate_fm(FMModulator *fm, float sample) {
|
|||||||
float inst_freq = fm->frequency+(sample*fm->deviation);
|
float inst_freq = fm->frequency+(sample*fm->deviation);
|
||||||
if (inst_freq < 0.0f) inst_freq = 0.0f;
|
if (inst_freq < 0.0f) inst_freq = 0.0f;
|
||||||
float out = sinf(fm->osc_phase);
|
float out = sinf(fm->osc_phase);
|
||||||
fm->osc_phase += fmodf(fm->osc_phase + ((M_2PI * inst_freq) / fm->sample_rate), M_2PI);
|
fm->osc_phase = fmodf(fm->osc_phase + ((M_2PI * inst_freq) / fm->sample_rate), M_2PI);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user