mirror of
https://github.com/radio95-rnt/fm95.git
synced 2026-02-26 19:23:51 +01:00
optimize the osclillator
This commit is contained in:
2
.vscode/.server-controller-port.log
vendored
2
.vscode/.server-controller-port.log
vendored
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"port": 13452,
|
"port": 13452,
|
||||||
"time": 1742920067458,
|
"time": 1742991617814,
|
||||||
"version": "0.0.3"
|
"version": "0.0.3"
|
||||||
}
|
}
|
||||||
@@ -22,16 +22,20 @@ float get_oscillator_cos_sample(Oscillator *osc) {
|
|||||||
return sample;
|
return sample;
|
||||||
}
|
}
|
||||||
|
|
||||||
float get_oscillator_sin_multiplier_ni(Oscillator *osc, float multiplier) { // ni = No Increment
|
float get_oscillator_sin_multiplier_ni(Oscillator *osc, float multiplier) {
|
||||||
return sinf(fmodf(osc->phase * multiplier, M_2PI));
|
float new_phase = osc->phase * multiplier;
|
||||||
|
new_phase -= (new_phase >= M_2PI) ? M_2PI : 0.0f;
|
||||||
|
return sinf(new_phase);
|
||||||
}
|
}
|
||||||
|
|
||||||
float get_oscillator_cos_multiplier_ni(Oscillator *osc, float multiplier) {
|
float get_oscillator_cos_multiplier_ni(Oscillator *osc, float multiplier) {
|
||||||
return cosf(fmodf(osc->phase * multiplier, M_2PI));
|
float new_phase = osc->phase * multiplier;
|
||||||
|
new_phase -= (new_phase >= M_2PI) ? M_2PI : 0.0f;
|
||||||
|
return cosf(new_phase);
|
||||||
}
|
}
|
||||||
|
|
||||||
void advance_oscillator(Oscillator *osc) {
|
void advance_oscillator(Oscillator *osc) {
|
||||||
osc->phase += osc->phase_increment;
|
osc->phase += osc->phase_increment;
|
||||||
if (osc->phase >= M_2PI) {
|
osc->phase -= (osc->phase >= M_2PI) ? M_2PI : 0.0f;
|
||||||
osc->phase -= M_2PI;
|
osc->phase = (fabsf(osc->phase) < 1e-10f) ? 0.0f : osc->phase;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user