zynaddsubfx

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

commit 491a80307fcbe962f155797bd4c04ace3f16375c
parent db1cec9e88db1c808fa8eaa7a53e9dfaa0b23068
Author: Friedolino <mkirchn@freenet.de>
Date:   Sun, 19 Apr 2020 01:22:25 +0200

performance improvements in distorsion and adnote

Diffstat:
Msrc/Effects/Distorsion.cpp | 8++++----
Msrc/Misc/WaveShapeSmps.cpp | 10+++++-----
Msrc/Synth/ADnote.cpp | 8++++----
3 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/src/Effects/Distorsion.cpp b/src/Effects/Distorsion.cpp @@ -135,11 +135,11 @@ void Distorsion::cleanup(void) //Apply the filters void Distorsion::applyfilters(float *efxoutl, float *efxoutr) { - lpfl->filterout(efxoutl); - hpfl->filterout(efxoutl); + if(Plpf!=127) lpfl->filterout(efxoutl); + if(Phpf!=0) hpfl->filterout(efxoutl); if(Pstereo != 0) { //stereo - lpfr->filterout(efxoutr); - hpfr->filterout(efxoutr); + if(Plpf!=127) lpfr->filterout(efxoutr); + if(Phpf!=0) hpfr->filterout(efxoutr); } } diff --git a/src/Misc/WaveShapeSmps.cpp b/src/Misc/WaveShapeSmps.cpp @@ -25,13 +25,13 @@ float polyblampres(float smp, float ws, float dMax) // [−T, 0] −d^5/40 + d^4/24 + d^3/12 + d^2/12 + d/24 + 1/120 // [0, T] d^5/40 − d^4/12 + d^2/3 − d/2 + 7/30 // [T, 2T] −d^5/120 + d^4/24 − d^3/12 + d^2/12 − d/24 + 1/120 - + if (dMax == 0) return 0.0; float dist = fabsf(smp) - ws; float res, d1, d2, d3, d4, d5; if(fabsf(dist) < dMax) { if(dist < -dMax/2.0f) { d1 = (dist + dMax)/dMax*2.0f; // [-dMax ... -dMax/2] -> [0 ... 1] - res = powf(d1, 5.0f) / 120.0f; + res = d1 * d1 * d1 * d1 * d1 / 120.0f; } else if(dist < 0.0f) { d1 = (dist + dMax/2.0f)/dMax*2.0f; // [-dMax/2 ... 0] -> [0 ... 1] @@ -100,7 +100,7 @@ void waveShapeSmps(int n, for(i = 0; i < n; ++i) { smps[i] *= ws; if(fabsf(smps[i]) < 1.0f) { - smps[i] = (smps[i] - powf(smps[i], 3.0f)) * 3.0f; + smps[i] = (smps[i] - smps[i] * smps[i] * smps[i]) * 3.0f; if(ws < 1.0f) smps[i] /= ws; } @@ -274,11 +274,11 @@ void waveShapeSmps(int n, smps[i] *= ws; // multiply signal to drive it in the saturation of the function smps[i] += offs; // add dc offset if(fabsf(smps[i]) < 1.0f) - smps[i] = 1.5 * (smps[i] - (powf(smps[i], 3.0) / 3.0) ); + smps[i] = 1.5 * (smps[i] - (smps[i]*smps[i]*smps[i] / 3.0) ); else smps[i] = (smps[i] > 0 ? 1.0f : -1.0f); //subtract offset with distorsion function applied - smps[i] -= 1.5 * (offs - (powf(offs, 3.0) / 3.0)); + smps[i] -= 1.5 * (offs - (offs*offs*offs / 3.0)); } break; case 17: diff --git a/src/Synth/ADnote.cpp b/src/Synth/ADnote.cpp @@ -1222,21 +1222,21 @@ inline void ADnote::ComputeVoiceOscillator_LinearInterpolation(int nvoice) Voice& vce = NoteVoicePar[nvoice]; for(int k = 0; k < vce.unison_size; ++k) { int poshi = vce.oscposhi[k]; - int poslo = (int)(vce.oscposlo[k] * (1<<24)); + int poslo = (int)(vce.oscposlo[k] * (0x01000000)); int freqhi = vce.oscfreqhi[k]; - int freqlo = (int)(vce.oscfreqlo[k] * (1<<24)); + int freqlo = (int)(vce.oscfreqlo[k] * (0x01000000)); float *smps = NoteVoicePar[nvoice].OscilSmp; float *tw = tmpwave_unison[k]; assert(vce.oscfreqlo[k] < 1.0f); for(int i = 0; i < synth.buffersize; ++i) { - tw[i] = (smps[poshi] * ((1<<24) - poslo) + smps[poshi + 1] * poslo)/(1.0f*(1<<24)); + tw[i] = (smps[poshi] * (0x01000000 - poslo) + smps[poshi + 1] * poslo)/(16777216.0f); poslo += freqlo; poshi += freqhi + (poslo>>24); poslo &= 0xffffff; poshi &= synth.oscilsize - 1; } vce.oscposhi[k] = poshi; - vce.oscposlo[k] = poslo/(1.0f*(1<<24)); + vce.oscposlo[k] = poslo/(16777216.0f); } }