zynaddsubfx

ZynAddSubFX open source synthesizer
Log | Files | Refs | Submodules | LICENSE

commit 89839176b4fea3301d493364ea026d902a47179d
parent d7ebd07043e46807e5a3a387296231077567d6f9
Author: Christopher A. Oliver <[email protected]>
Date:   Sun,  8 Nov 2015 01:46:29 -0500

Use x-floor(x) rather than fmodf(x,1.0) in audio.

This gives the positive fractional part more reliably.
fmodf() has a number of edge cases that floor avoids.

Diffstat:
Msrc/DSP/FormantFilter.cpp | 13++++---------
Msrc/Effects/Chorus.cpp | 5++---
Msrc/Effects/EffectLFO.cpp | 3++-
Msrc/Effects/Phaser.cpp | 6++++--
Msrc/Misc/Microtonal.cpp | 2+-
Msrc/Params/PADnoteParameters.cpp | 5+++--
6 files changed, 16 insertions(+), 18 deletions(-)

diff --git a/src/DSP/FormantFilter.cpp b/src/DSP/FormantFilter.cpp @@ -115,21 +115,16 @@ void FormantFilter::setpos(float frequency) else oldinput = input; - float pos = fmodf(input * sequencestretch, 1.0f); - if(pos < 0.0f) - pos += 1.0f; + float pos = input * sequencestretch; + pos -= floorf(pos); F2I(pos * sequencesize, p2); p1 = p2 - 1; if(p1 < 0) p1 += sequencesize; - pos = fmodf(pos * sequencesize, 1.0f); - if(pos < 0.0f) - pos = 0.0f; - else - if(pos > 1.0f) - pos = 1.0f; + pos = pos * sequencesize; + pos -= floorf(pos); pos = (atanf((pos * 2.0f - 1.0f) diff --git a/src/Effects/Chorus.cpp b/src/Effects/Chorus.cpp @@ -69,7 +69,6 @@ float Chorus::getdelay(float xlfo) //Apply the effect void Chorus::out(const Stereo<float *> &input) { - const float one = 1.0f; dl1 = dl2; dr1 = dr2; lfo.effectlfoout(&lfol, &lfor); @@ -98,7 +97,7 @@ void Chorus::out(const Stereo<float *> &input) dlhi %= maxdelay; float dlhi2 = (dlhi - 1 + maxdelay) % maxdelay; - float dllo = 1.0f - fmod(tmp, one); + float dllo = 1.0f + floorf(tmp) - tmp; efxoutl[i] = cinterpolate(delaySample.l, maxdelay, dlhi2) * dllo + cinterpolate(delaySample.l, maxdelay, dlhi) * (1.0f - dllo); @@ -116,7 +115,7 @@ void Chorus::out(const Stereo<float *> &input) dlhi %= maxdelay; dlhi2 = (dlhi - 1 + maxdelay) % maxdelay; - dllo = 1.0f - fmodf(tmp, one); + dllo = 1.0f + floorf(tmp) - tmp; efxoutr[i] = cinterpolate(delaySample.r, maxdelay, dlhi2) * dllo + cinterpolate(delaySample.r, maxdelay, dlhi) * (1.0f - dllo); diff --git a/src/Effects/EffectLFO.cpp b/src/Effects/EffectLFO.cpp @@ -60,7 +60,8 @@ void EffectLFO::updateparams(void) if(PLFOtype > 1) PLFOtype = 1; //this has to be updated if more lfo's are added lfotype = PLFOtype; - xr = fmodf(xl + (Pstereo - 64.0f) / 127.0f + 1.0f, 1.0f); + xr = xl + (Pstereo - 64.0f) / 127.0f + 1.0f; + xr -= floorf(xr); } diff --git a/src/Effects/Phaser.cpp b/src/Effects/Phaser.cpp @@ -135,8 +135,10 @@ void Phaser::AnalogPhase(const Stereo<float *> &input) Stereo<float> xn(input.l[i] * pangainL, input.r[i] * pangainR); if(barber) { - g.l = fmodf((g.l + 0.25f), ONE_); - g.r = fmodf((g.r + 0.25f), ONE_); + g.l += 0.25; + g.l -= floorf(g.l); + g.r += 0.25; + g.r -= floorf(g.r); } xn.l = applyPhase(xn.l, g.l, fb.l, hpf.l, yn1.l, xn1.l); diff --git a/src/Misc/Microtonal.cpp b/src/Misc/Microtonal.cpp @@ -655,7 +655,7 @@ void Microtonal::getfromXML(XMLwrapper *xml) //populate fields for display float x = logf(octave[i].tuning) / LOG_2 * 1200.0f; octave[i].x1 = (int) floor(x); - octave[i].x2 = (int) (floor(fmodf(x, 1.0f) * 1e6)); + octave[i].x2 = (int) (floor((x-octave[i].x1) * 1.0e6)); } diff --git a/src/Params/PADnoteParameters.cpp b/src/Params/PADnoteParameters.cpp @@ -684,8 +684,9 @@ void PADnoteParameters::generatespectrum_bandwidthMode(float *spectrum, const float ibasefreq = realfreq / (synth.samplerate_f * 0.5f) * size; for(int i = 0; i < profilesize; ++i) { const float idfreq = (i / (float)profilesize - 0.5f) * ibw; - const int spfreq = (int) (idfreq + ibasefreq); - const float fspfreq = fmodf((float)idfreq + ibasefreq, 1.0f); + const float freqsum = idfreq + ibasefreq; + const int spfreq = (int)freqsum; + const float fspfreq = freqsum - spfreq; if(spfreq <= 0) continue; if(spfreq >= size - 1)