zynaddsubfx

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

commit 4b26b6456e011740f4efb2c10ff6f8c46395c622
parent f7e6d67242ee2a8ee8761a62c94079c67432a6bb
Author: dancesWithBugs <[email protected]>
Date:   Wed,  4 May 2022 11:45:56 +0200

fixed misspelling of "distortion"

Diffstat:
MNEWS.txt | 2+-
Mdoc/nrpn.txt | 2+-
Msrc/Effects/CMakeLists.txt | 2+-
Dsrc/Effects/Distorsion.cpp | 331-------------------------------------------------------------------------------
Dsrc/Effects/Distorsion.h | 60------------------------------------------------------------
Asrc/Effects/Distortion.cpp | 331+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/Effects/Distortion.h | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/Effects/EffectMgr.cpp | 12++++++------
Msrc/Misc/WaveShapeSmps.cpp | 4++--
Msrc/Misc/WaveShapeSmps.h | 2+-
Msrc/Plugin/Distortion/Distortion.cpp | 4++--
Msrc/UI/EffUI.fl | 30+++++++++++++++---------------
12 files changed, 420 insertions(+), 420 deletions(-)

diff --git a/NEWS.txt b/NEWS.txt @@ -370,7 +370,7 @@ 1.0.7 (7 Feb 2003) - some settings (like samplerate) are set at runtime (by comand line) - - added Distorsion effect + - added Distortion effect - added controllers, and NRPNs for changing all effects parameters by midi - bugs removed and other improvements diff --git a/doc/nrpn.txt b/doc/nrpn.txt @@ -121,7 +121,7 @@ AlienWah [orange]#09 - Left/Right Crossing (FC)# 10 - Phase+ -Distorsion +Distortion ~~~~~~~~~~ [verse] diff --git a/src/Effects/CMakeLists.txt b/src/Effects/CMakeLists.txt @@ -1,7 +1,7 @@ set(zynaddsubfx_effect_SRCS Effects/Alienwah.cpp Effects/Chorus.cpp - Effects/Distorsion.cpp + Effects/Distortion.cpp Effects/DynamicFilter.cpp Effects/Echo.cpp Effects/Effect.cpp diff --git a/src/Effects/Distorsion.cpp b/src/Effects/Distorsion.cpp @@ -1,331 +0,0 @@ -/* - ZynAddSubFX - a software synthesizer - - Distorsion.cpp - Distorsion effect - Copyright (C) 2002-2005 Nasca Octavian Paul - Author: Nasca Octavian Paul - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. -*/ - -#include "Distorsion.h" -#include "../DSP/AnalogFilter.h" -#include "../Misc/WaveShapeSmps.h" -#include "../Misc/Allocator.h" -#include <cmath> -#include <rtosc/ports.h> -#include <rtosc/port-sugar.h> - -namespace zyn { - -#define rObject Distorsion -#define rBegin [](const char *msg, rtosc::RtData &d) { -#define rEnd } - -rtosc::Ports Distorsion::ports = { - {"preset::i", rProp(parameter) - rOptions(Overdrive 1, Overdrive 2, A. Exciter 1, A. Exciter 2, Guitar Amp, - Quantisize) - rDoc("Instrument Presets"), 0, - rBegin; - rObject *o = (rObject*)d.obj; - if(rtosc_narguments(msg)) - o->setpreset(rtosc_argument(msg, 0).i); - else - d.reply(d.loc, "i", o->Ppreset); - rEnd}, - rEffParVol(rDefault(127), rPresetsAt(2, 64, 64)), - rEffParPan(), - rEffPar(Plrcross, 2, rShort("l/r"), rDefault(35), "Left/Right Crossover"), - rEffPar(Pdrive, 3, rShort("drive"), - rLinear(0, 127), rPresets(56, 29, 75, 85, 63, 88), - "Input amplification"), - rEffPar(Plevel, 4, rShort("output"), rPresets(70, 75, 80, 62, 75, 75), - "Output amplification"), - rEffParOpt(Ptype, 5, rShort("type"), - rOptions(Arctangent, Asymmetric, Pow, Sine, Quantisize, - Zigzag, Limiter, Upper Limiter, Lower Limiter, - Inverse Limiter, Clip, Asym2, Pow2, Sigmoid, Tanh, - Cubic, Square), rLinear(0,127), - rPresets(Arctangent, Asymmetric, Zigzag, - Asymmetric, Pow, Quantisize), - "Distortion Shape"), - rEffParTF(Pnegate, 6, rShort("neg"), rDefault(false), "Negate Signal"), - rEffPar(Plpf, 7, rShort("lpf"), - rPreset(0, 96), rPreset(4, 55), rDefault(127), "Low Pass Cutoff"), - rEffPar(Phpf, 8, rShort("hpf"), - rPreset(2, 105), rPreset(3, 118), rDefault(0), "High Pass Cutoff"), - rEffParTF(Pstereo, 9, rShort("stereo"), - rPresets(false, false, true, true, false, true), "Stereo"), - rEffParTF(Pprefiltering, 10, rShort("p.filt"), rDefault(false), - "Filtering before/after non-linearity"), - rEffPar(Pfuncpar, 11, rShort("shape"), rDefault(32), - rLinear(0, 127), "Shape of the wave shaping function"), - rEffPar(Poffset, 12, rShort("offset"), rDefault(64), - rLinear(0, 127), "Input DC Offset"), - {"waveform:", 0, 0, [](const char *, rtosc::RtData &d) - { - Distorsion &dd = *(Distorsion*)d.obj; - float buffer[128], orig[128]; - rtosc_arg_t args[128]; - char arg_str[128+1] = {}; - - for(int i=0; i<128; ++i) - buffer[i] = 2*(i/128.0)-1; - memcpy(orig, buffer, sizeof(float_t)*128); - - waveShapeSmps(sizeof(buffer)/sizeof(buffer[0]), buffer, - dd.Ptype + 1, dd.Pdrive, dd.Poffset, dd.Pfuncpar); - - for(int i=0; i<128; ++i) { - arg_str[i] = 'f'; - args[i].f = (dd.Pvolume * buffer[i] + (127 - dd.Pvolume) * orig[i]) / 127.0f; - } - - d.replyArray(d.loc, arg_str, args); - }}, -}; -#undef rBegin -#undef rEnd -#undef rObject - -Distorsion::Distorsion(EffectParams pars) - :Effect(pars), - Pvolume(50), - Pdrive(90), - Plevel(64), - Ptype(0), - Pnegate(0), - Plpf(127), - Phpf(0), - Pstereo(0), - Pprefiltering(0), - Pfuncpar(32), - Poffset(64) -{ - lpfl = memory.alloc<AnalogFilter>(2, 22000, 1, 0, pars.srate, pars.bufsize); - lpfr = memory.alloc<AnalogFilter>(2, 22000, 1, 0, pars.srate, pars.bufsize); - hpfl = memory.alloc<AnalogFilter>(3, 20, 1, 0, pars.srate, pars.bufsize); - hpfr = memory.alloc<AnalogFilter>(3, 20, 1, 0, pars.srate, pars.bufsize); - setpreset(Ppreset); - cleanup(); -} - -Distorsion::~Distorsion() -{ - memory.dealloc(lpfl); - memory.dealloc(lpfr); - memory.dealloc(hpfl); - memory.dealloc(hpfr); -} - -//Cleanup the effect -void Distorsion::cleanup(void) -{ - lpfl->cleanup(); - hpfl->cleanup(); - lpfr->cleanup(); - hpfr->cleanup(); -} - - -//Apply the filters -void Distorsion::applyfilters(float *efxoutl, float *efxoutr) -{ - if(Plpf!=127) lpfl->filterout(efxoutl); - if(Phpf!=0) hpfl->filterout(efxoutl); - if(Pstereo != 0) { //stereo - if(Plpf!=127) lpfr->filterout(efxoutr); - if(Phpf!=0) hpfr->filterout(efxoutr); - } -} - - -//Effect output -void Distorsion::out(const Stereo<float *> &smp) -{ - float inputvol = powf(5.0f, (Pdrive - 32.0f) / 127.0f); - if(Pnegate) - inputvol *= -1.0f; - - if(Pstereo) //Stereo - for(int i = 0; i < buffersize; ++i) { - efxoutl[i] = smp.l[i] * inputvol * pangainL; - efxoutr[i] = smp.r[i] * inputvol * pangainR; - } - else //Mono - for(int i = 0; i < buffersize; ++i) - efxoutl[i] = (smp.l[i] * pangainL + smp.r[i] * pangainR) * inputvol; - - if(Pprefiltering) - applyfilters(efxoutl, efxoutr); - - waveShapeSmps(buffersize, efxoutl, Ptype + 1, Pdrive, Poffset, Pfuncpar); - if(Pstereo) - waveShapeSmps(buffersize, efxoutr, Ptype + 1, Pdrive, Poffset, Pfuncpar); - - if(!Pprefiltering) - applyfilters(efxoutl, efxoutr); - - if(!Pstereo) - memcpy(efxoutr, efxoutl, bufferbytes); - - float level = dB2rap(60.0f * Plevel / 127.0f - 40.0f); - for(int i = 0; i < buffersize; ++i) { - float lout = efxoutl[i]; - float rout = efxoutr[i]; - float l = lout * (1.0f - lrcross) + rout * lrcross; - float r = rout * (1.0f - lrcross) + lout * lrcross; - lout = l; - rout = r; - - efxoutl[i] = lout * 2.0f * level; - efxoutr[i] = rout * 2.0f * level; - } -} - - -//Parameter control -void Distorsion::setvolume(unsigned char _Pvolume) -{ - Pvolume = _Pvolume; - - if(insertion == 0) { - outvolume = powf(0.01f, (1.0f - Pvolume / 127.0f)) * 4.0f; - volume = 1.0f; - } - else - volume = outvolume = Pvolume / 127.0f; - if(Pvolume == 0) - cleanup(); -} - -void Distorsion::setlpf(unsigned char _Plpf) -{ - Plpf = _Plpf; - float fr = expf(sqrtf(Plpf / 127.0f) * logf(25000.0f)) + 40.0f; - lpfl->setfreq(fr); - lpfr->setfreq(fr); -} - -void Distorsion::sethpf(unsigned char _Phpf) -{ - Phpf = _Phpf; - float fr = expf(sqrtf(Phpf / 127.0f) * logf(25000.0f)) + 20.0f; - hpfl->setfreq(fr); - hpfr->setfreq(fr); -} - -unsigned char Distorsion::getpresetpar(unsigned char npreset, unsigned int npar) -{ -#define PRESET_SIZE 13 -#define NUM_PRESETS 6 - static const unsigned char presets[NUM_PRESETS][PRESET_SIZE] = { - //Overdrive 1 - {127, 64, 35, 56, 70, 0, 0, 96, 0, 0, 0, 32, 64}, - //Overdrive 2 - {127, 64, 35, 29, 75, 1, 0, 127, 0, 0, 0, 32, 64}, - //A. Exciter 1 - {64, 64, 35, 75, 80, 5, 0, 127, 105, 1, 0, 32, 64}, - //A. Exciter 2 - {64, 64, 35, 85, 62, 1, 0, 127, 118, 1, 0, 32, 64}, - //Guitar Amp - {127, 64, 35, 63, 75, 2, 0, 55, 0, 0, 0, 32, 64}, - //Quantisize - {127, 64, 35, 88, 75, 4, 0, 127, 0, 1, 0, 32, 64} - }; - if(npreset < NUM_PRESETS && npar < PRESET_SIZE) { - if(npar == 0 && insertion == 0) { - /* lower the volume if this is system effect */ - return (3 * presets[npreset][npar]) / 2; - } - return presets[npreset][npar]; - } - return 0; -} - -void Distorsion::setpreset(unsigned char npreset) -{ - if(npreset >= NUM_PRESETS) - npreset = NUM_PRESETS - 1; - for(int n = 0; n != 128; n++) - changepar(n, getpresetpar(npreset, n)); - Ppreset = npreset; - cleanup(); -} - -void Distorsion::changepar(int npar, unsigned char value) -{ - switch(npar) { - case 0: - setvolume(value); - break; - case 1: - setpanning(value); - break; - case 2: - setlrcross(value); - break; - case 3: - Pdrive = value; - break; - case 4: - Plevel = value; - break; - case 5: - if(value > 16) - Ptype = 16; //this must be increased if more distorsion types are added - else - Ptype = value; - break; - case 6: - if(value > 1) - Pnegate = 1; - else - Pnegate = value; - break; - case 7: - setlpf(value); - break; - case 8: - sethpf(value); - break; - case 9: - Pstereo = (value > 1) ? 1 : value; - break; - case 10: - Pprefiltering = value; - break; - case 11: - Pfuncpar = value; - break; - case 12: - Poffset = value; - break; - } -} - -unsigned char Distorsion::getpar(int npar) const -{ - switch(npar) { - case 0: return Pvolume; - case 1: return Ppanning; - case 2: return Plrcross; - case 3: return Pdrive; - case 4: return Plevel; - case 5: return Ptype; - case 6: return Pnegate; - case 7: return Plpf; - case 8: return Phpf; - case 9: return Pstereo; - case 10: return Pprefiltering; - case 11: return Pfuncpar; - case 12: return Poffset; - default: return 0; //in case of bogus parameter number - } -} - -} diff --git a/src/Effects/Distorsion.h b/src/Effects/Distorsion.h @@ -1,60 +0,0 @@ -/* - ZynAddSubFX - a software synthesizer - - Distorsion.h - Distorsion Effect - Copyright (C) 2002-2005 Nasca Octavian Paul - Author: Nasca Octavian Paul - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. -*/ - -#ifndef DISTORSION_H -#define DISTORSION_H - -#include "Effect.h" - -namespace zyn { - -/**Distortion Effect*/ -class Distorsion:public Effect -{ - public: - Distorsion(EffectParams pars); - ~Distorsion(); - void out(const Stereo<float *> &smp); - unsigned char getpresetpar(unsigned char npreset, unsigned int npar); - void setpreset(unsigned char npreset); - void changepar(int npar, unsigned char value); - unsigned char getpar(int npar) const; - void cleanup(void); - void applyfilters(float *efxoutl, float *efxoutr); - - static rtosc::Ports ports; - private: - //Parameters - unsigned char Pvolume; //Volume or E/R - unsigned char Pdrive; //the input amplification - unsigned char Plevel; //the output amplification - unsigned char Ptype; //Distorsion type - unsigned char Pnegate; //if the input is negated - unsigned char Plpf; //lowpass filter - unsigned char Phpf; //highpass filter - unsigned char Pstereo; //0=mono, 1=stereo - unsigned char Pprefiltering; //if you want to do the filtering before the distorsion - unsigned char Pfuncpar; //for parametric functions - unsigned char Poffset; //the input offset - - void setvolume(unsigned char _Pvolume); - void setlpf(unsigned char _Plpf); - void sethpf(unsigned char _Phpf); - - //Real Parameters - class AnalogFilter * lpfl, *lpfr, *hpfl, *hpfr; -}; - -} - -#endif diff --git a/src/Effects/Distortion.cpp b/src/Effects/Distortion.cpp @@ -0,0 +1,331 @@ +/* + ZynAddSubFX - a software synthesizer + + Distortion.cpp - Distortion effect + Copyright (C) 2002-2005 Nasca Octavian Paul + Author: Nasca Octavian Paul + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. +*/ + +#include "Distortion.h" +#include "../DSP/AnalogFilter.h" +#include "../Misc/WaveShapeSmps.h" +#include "../Misc/Allocator.h" +#include <cmath> +#include <rtosc/ports.h> +#include <rtosc/port-sugar.h> + +namespace zyn { + +#define rObject Distortion +#define rBegin [](const char *msg, rtosc::RtData &d) { +#define rEnd } + +rtosc::Ports Distortion::ports = { + {"preset::i", rProp(parameter) + rOptions(Overdrive 1, Overdrive 2, A. Exciter 1, A. Exciter 2, Guitar Amp, + Quantisize) + rDoc("Instrument Presets"), 0, + rBegin; + rObject *o = (rObject*)d.obj; + if(rtosc_narguments(msg)) + o->setpreset(rtosc_argument(msg, 0).i); + else + d.reply(d.loc, "i", o->Ppreset); + rEnd}, + rEffParVol(rDefault(127), rPresetsAt(2, 64, 64)), + rEffParPan(), + rEffPar(Plrcross, 2, rShort("l/r"), rDefault(35), "Left/Right Crossover"), + rEffPar(Pdrive, 3, rShort("drive"), + rLinear(0, 127), rPresets(56, 29, 75, 85, 63, 88), + "Input amplification"), + rEffPar(Plevel, 4, rShort("output"), rPresets(70, 75, 80, 62, 75, 75), + "Output amplification"), + rEffParOpt(Ptype, 5, rShort("type"), + rOptions(Arctangent, Asymmetric, Pow, Sine, Quantisize, + Zigzag, Limiter, Upper Limiter, Lower Limiter, + Inverse Limiter, Clip, Asym2, Pow2, Sigmoid, Tanh, + Cubic, Square), rLinear(0,127), + rPresets(Arctangent, Asymmetric, Zigzag, + Asymmetric, Pow, Quantisize), + "Distortion Shape"), + rEffParTF(Pnegate, 6, rShort("neg"), rDefault(false), "Negate Signal"), + rEffPar(Plpf, 7, rShort("lpf"), + rPreset(0, 96), rPreset(4, 55), rDefault(127), "Low Pass Cutoff"), + rEffPar(Phpf, 8, rShort("hpf"), + rPreset(2, 105), rPreset(3, 118), rDefault(0), "High Pass Cutoff"), + rEffParTF(Pstereo, 9, rShort("stereo"), + rPresets(false, false, true, true, false, true), "Stereo"), + rEffParTF(Pprefiltering, 10, rShort("p.filt"), rDefault(false), + "Filtering before/after non-linearity"), + rEffPar(Pfuncpar, 11, rShort("shape"), rDefault(32), + rLinear(0, 127), "Shape of the wave shaping function"), + rEffPar(Poffset, 12, rShort("offset"), rDefault(64), + rLinear(0, 127), "Input DC Offset"), + {"waveform:", 0, 0, [](const char *, rtosc::RtData &d) + { + Distortion &dd = *(Distortion*)d.obj; + float buffer[128], orig[128]; + rtosc_arg_t args[128]; + char arg_str[128+1] = {}; + + for(int i=0; i<128; ++i) + buffer[i] = 2*(i/128.0)-1; + memcpy(orig, buffer, sizeof(float_t)*128); + + waveShapeSmps(sizeof(buffer)/sizeof(buffer[0]), buffer, + dd.Ptype + 1, dd.Pdrive, dd.Poffset, dd.Pfuncpar); + + for(int i=0; i<128; ++i) { + arg_str[i] = 'f'; + args[i].f = (dd.Pvolume * buffer[i] + (127 - dd.Pvolume) * orig[i]) / 127.0f; + } + + d.replyArray(d.loc, arg_str, args); + }}, +}; +#undef rBegin +#undef rEnd +#undef rObject + +Distortion::Distortion(EffectParams pars) + :Effect(pars), + Pvolume(50), + Pdrive(90), + Plevel(64), + Ptype(0), + Pnegate(0), + Plpf(127), + Phpf(0), + Pstereo(0), + Pprefiltering(0), + Pfuncpar(32), + Poffset(64) +{ + lpfl = memory.alloc<AnalogFilter>(2, 22000, 1, 0, pars.srate, pars.bufsize); + lpfr = memory.alloc<AnalogFilter>(2, 22000, 1, 0, pars.srate, pars.bufsize); + hpfl = memory.alloc<AnalogFilter>(3, 20, 1, 0, pars.srate, pars.bufsize); + hpfr = memory.alloc<AnalogFilter>(3, 20, 1, 0, pars.srate, pars.bufsize); + setpreset(Ppreset); + cleanup(); +} + +Distortion::~Distortion() +{ + memory.dealloc(lpfl); + memory.dealloc(lpfr); + memory.dealloc(hpfl); + memory.dealloc(hpfr); +} + +//Cleanup the effect +void Distortion::cleanup(void) +{ + lpfl->cleanup(); + hpfl->cleanup(); + lpfr->cleanup(); + hpfr->cleanup(); +} + + +//Apply the filters +void Distortion::applyfilters(float *efxoutl, float *efxoutr) +{ + if(Plpf!=127) lpfl->filterout(efxoutl); + if(Phpf!=0) hpfl->filterout(efxoutl); + if(Pstereo != 0) { //stereo + if(Plpf!=127) lpfr->filterout(efxoutr); + if(Phpf!=0) hpfr->filterout(efxoutr); + } +} + + +//Effect output +void Distortion::out(const Stereo<float *> &smp) +{ + float inputvol = powf(5.0f, (Pdrive - 32.0f) / 127.0f); + if(Pnegate) + inputvol *= -1.0f; + + if(Pstereo) //Stereo + for(int i = 0; i < buffersize; ++i) { + efxoutl[i] = smp.l[i] * inputvol * pangainL; + efxoutr[i] = smp.r[i] * inputvol * pangainR; + } + else //Mono + for(int i = 0; i < buffersize; ++i) + efxoutl[i] = (smp.l[i] * pangainL + smp.r[i] * pangainR) * inputvol; + + if(Pprefiltering) + applyfilters(efxoutl, efxoutr); + + waveShapeSmps(buffersize, efxoutl, Ptype + 1, Pdrive, Poffset, Pfuncpar); + if(Pstereo) + waveShapeSmps(buffersize, efxoutr, Ptype + 1, Pdrive, Poffset, Pfuncpar); + + if(!Pprefiltering) + applyfilters(efxoutl, efxoutr); + + if(!Pstereo) + memcpy(efxoutr, efxoutl, bufferbytes); + + float level = dB2rap(60.0f * Plevel / 127.0f - 40.0f); + for(int i = 0; i < buffersize; ++i) { + float lout = efxoutl[i]; + float rout = efxoutr[i]; + float l = lout * (1.0f - lrcross) + rout * lrcross; + float r = rout * (1.0f - lrcross) + lout * lrcross; + lout = l; + rout = r; + + efxoutl[i] = lout * 2.0f * level; + efxoutr[i] = rout * 2.0f * level; + } +} + + +//Parameter control +void Distortion::setvolume(unsigned char _Pvolume) +{ + Pvolume = _Pvolume; + + if(insertion == 0) { + outvolume = powf(0.01f, (1.0f - Pvolume / 127.0f)) * 4.0f; + volume = 1.0f; + } + else + volume = outvolume = Pvolume / 127.0f; + if(Pvolume == 0) + cleanup(); +} + +void Distortion::setlpf(unsigned char _Plpf) +{ + Plpf = _Plpf; + float fr = expf(sqrtf(Plpf / 127.0f) * logf(25000.0f)) + 40.0f; + lpfl->setfreq(fr); + lpfr->setfreq(fr); +} + +void Distortion::sethpf(unsigned char _Phpf) +{ + Phpf = _Phpf; + float fr = expf(sqrtf(Phpf / 127.0f) * logf(25000.0f)) + 20.0f; + hpfl->setfreq(fr); + hpfr->setfreq(fr); +} + +unsigned char Distortion::getpresetpar(unsigned char npreset, unsigned int npar) +{ +#define PRESET_SIZE 13 +#define NUM_PRESETS 6 + static const unsigned char presets[NUM_PRESETS][PRESET_SIZE] = { + //Overdrive 1 + {127, 64, 35, 56, 70, 0, 0, 96, 0, 0, 0, 32, 64}, + //Overdrive 2 + {127, 64, 35, 29, 75, 1, 0, 127, 0, 0, 0, 32, 64}, + //A. Exciter 1 + {64, 64, 35, 75, 80, 5, 0, 127, 105, 1, 0, 32, 64}, + //A. Exciter 2 + {64, 64, 35, 85, 62, 1, 0, 127, 118, 1, 0, 32, 64}, + //Guitar Amp + {127, 64, 35, 63, 75, 2, 0, 55, 0, 0, 0, 32, 64}, + //Quantisize + {127, 64, 35, 88, 75, 4, 0, 127, 0, 1, 0, 32, 64} + }; + if(npreset < NUM_PRESETS && npar < PRESET_SIZE) { + if(npar == 0 && insertion == 0) { + /* lower the volume if this is system effect */ + return (3 * presets[npreset][npar]) / 2; + } + return presets[npreset][npar]; + } + return 0; +} + +void Distortion::setpreset(unsigned char npreset) +{ + if(npreset >= NUM_PRESETS) + npreset = NUM_PRESETS - 1; + for(int n = 0; n != 128; n++) + changepar(n, getpresetpar(npreset, n)); + Ppreset = npreset; + cleanup(); +} + +void Distortion::changepar(int npar, unsigned char value) +{ + switch(npar) { + case 0: + setvolume(value); + break; + case 1: + setpanning(value); + break; + case 2: + setlrcross(value); + break; + case 3: + Pdrive = value; + break; + case 4: + Plevel = value; + break; + case 5: + if(value > 16) + Ptype = 16; //this must be increased if more distortion types are added + else + Ptype = value; + break; + case 6: + if(value > 1) + Pnegate = 1; + else + Pnegate = value; + break; + case 7: + setlpf(value); + break; + case 8: + sethpf(value); + break; + case 9: + Pstereo = (value > 1) ? 1 : value; + break; + case 10: + Pprefiltering = value; + break; + case 11: + Pfuncpar = value; + break; + case 12: + Poffset = value; + break; + } +} + +unsigned char Distortion::getpar(int npar) const +{ + switch(npar) { + case 0: return Pvolume; + case 1: return Ppanning; + case 2: return Plrcross; + case 3: return Pdrive; + case 4: return Plevel; + case 5: return Ptype; + case 6: return Pnegate; + case 7: return Plpf; + case 8: return Phpf; + case 9: return Pstereo; + case 10: return Pprefiltering; + case 11: return Pfuncpar; + case 12: return Poffset; + default: return 0; //in case of bogus parameter number + } +} + +} diff --git a/src/Effects/Distortion.h b/src/Effects/Distortion.h @@ -0,0 +1,60 @@ +/* + ZynAddSubFX - a software synthesizer + + Distortion.h - Distortion Effect + Copyright (C) 2002-2005 Nasca Octavian Paul + Author: Nasca Octavian Paul + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. +*/ + +#ifndef DISTORTION_H +#define DISTORTION_H + +#include "Effect.h" + +namespace zyn { + +/**Distortion Effect*/ +class Distortion:public Effect +{ + public: + Distortion(EffectParams pars); + ~Distortion(); + void out(const Stereo<float *> &smp); + unsigned char getpresetpar(unsigned char npreset, unsigned int npar); + void setpreset(unsigned char npreset); + void changepar(int npar, unsigned char value); + unsigned char getpar(int npar) const; + void cleanup(void); + void applyfilters(float *efxoutl, float *efxoutr); + + static rtosc::Ports ports; + private: + //Parameters + unsigned char Pvolume; //Volume or E/R + unsigned char Pdrive; //the input amplification + unsigned char Plevel; //the output amplification + unsigned char Ptype; //Distortion type + unsigned char Pnegate; //if the input is negated + unsigned char Plpf; //lowpass filter + unsigned char Phpf; //highpass filter + unsigned char Pstereo; //0=mono, 1=stereo + unsigned char Pprefiltering; //if you want to do the filtering before the distortion + unsigned char Pfuncpar; //for parametric functions + unsigned char Poffset; //the input offset + + void setvolume(unsigned char _Pvolume); + void setlpf(unsigned char _Plpf); + void sethpf(unsigned char _Phpf); + + //Real Parameters + class AnalogFilter * lpfl, *lpfr, *hpfl, *hpfr; +}; + +} + +#endif diff --git a/src/Effects/EffectMgr.cpp b/src/Effects/EffectMgr.cpp @@ -22,7 +22,7 @@ #include "Reverb.h" #include "Echo.h" #include "Chorus.h" -#include "Distorsion.h" +#include "Distortion.h" #include "EQ.h" #include "DynamicFilter.h" #include "Phaser.h" @@ -153,7 +153,7 @@ static const rtosc::Ports local_ports = { eff->seteffectparrt(2, Pfreq); break; case 1: // Reverb - case 6: // Distorsion + case 6: // Distortion case 7: // EQ default: break; @@ -200,7 +200,7 @@ static const rtosc::Ports local_ports = { eff->seteffectparrt(2, Pfreq); break; case 1: // Reverb - case 6: // Distorsion + case 6: // Distortion case 7: // EQ default: break; @@ -249,7 +249,7 @@ static const rtosc::Ports local_ports = { }}, rSubtype(Alienwah), rSubtype(Chorus), - rSubtype(Distorsion), + rSubtype(Distortion), rSubtype(DynamicFilter), rSubtype(Echo), rSubtype(EQ), @@ -327,7 +327,7 @@ void EffectMgr::changeeffectrt(int _nefx, bool avoidSmash) efx = memory.alloc<Alienwah>(pars); break; case 6: - efx = memory.alloc<Distorsion>(pars); + efx = memory.alloc<Distortion>(pars); break; case 7: efx = memory.alloc<EQ>(pars); @@ -368,7 +368,7 @@ void EffectMgr::changeeffectrt(int _nefx, bool avoidSmash) seteffectparrt(2, Pfreq); break; case 1: // Reverb - case 6: // Distorsion + case 6: // Distortion case 7: // EQ default: break; diff --git a/src/Misc/WaveShapeSmps.cpp b/src/Misc/WaveShapeSmps.cpp @@ -277,7 +277,7 @@ void waveShapeSmps(int n, 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 + //subtract offset with distortion function applied smps[i] -= 1.5 * (offs - (offs*offs*offs / 3.0)); } break; @@ -292,7 +292,7 @@ void waveShapeSmps(int n, smps[i] = smps[i]*(2-fabsf(smps[i])); else smps[i] = (smps[i] > 0 ? 1.0f : -1.0f); - //subtract offset with distorsion function applied + //subtract offset with distortion function applied smps[i] -= offs*(2-fabsf(offs)); } break; diff --git a/src/Misc/WaveShapeSmps.h b/src/Misc/WaveShapeSmps.h @@ -15,7 +15,7 @@ namespace zyn { -//Waveshaping(called by Distorsion effect and waveshape from OscilGen) +//Waveshaping(called by Distortion effect and waveshape from OscilGen) void waveShapeSmps(int n, float *smps, unsigned char type, diff --git a/src/Plugin/Distortion/Distortion.cpp b/src/Plugin/Distortion/Distortion.cpp @@ -15,12 +15,12 @@ #include "../AbstractFX.hpp" // ZynAddSubFX includes -#include "Effects/Distorsion.h" +#include "Effects/Distortion.h" /* ------------------------------------------------------------------------------------------------------------ * Distortion plugin class */ -class DistortionPlugin : public AbstractPluginFX<zyn::Distorsion> +class DistortionPlugin : public AbstractPluginFX<zyn::Distortion> { public: DistortionPlugin() diff --git a/src/UI/EffUI.fl b/src/UI/EffUI.fl @@ -71,7 +71,7 @@ effechowindow->hide();//delete (effechowindow); effchoruswindow->hide();//delete (effchoruswindow); effphaserwindow->hide();//delete (effphaserwindow); effalienwahwindow->hide();//delete (effalienwahwindow); -effdistorsionwindow->hide();//delete (effdistorsionwindow); +effdistortionwindow->hide();//delete (effdistortionwindow); effeqwindow->hide();//delete (effeqwindow); effdynamicfilterwindow->hide();//delete (effdynamicfilterwindow); @@ -740,8 +740,8 @@ if (filterwindow!=NULL){ } } } - Function {make_distorsion_window()} {} { - Fl_Window effdistorsionwindow { + Function {make_distortion_window()} {} { + Fl_Window effdistortionwindow { xywh {553 286 380 100} type Double box UP_BOX color 221 labelfont 1 labelsize 19 code0 {set_module_parameters(o);} class Fl_Group visible @@ -920,7 +920,7 @@ if (filterwindow!=NULL){ } Fl_Check_Button distp10 { label PF - tooltip {Applies the filters(before or after) the distorsion} xywh {355 44 15 15} down_box DOWN_BOX labelfont 1 labelsize 11 align 1 + tooltip {Applies the filters(before or after) the distortion} xywh {355 44 15 15} down_box DOWN_BOX labelfont 1 labelsize 11 align 1 code0 {o->init("parameter10");} class Fl_Osc_Check } @@ -1188,7 +1188,7 @@ make_echo_window(); make_chorus_window(); make_phaser_window(); make_alienwah_window(); -make_distorsion_window(); +make_distortion_window(); make_eq_window(); make_dynamicfilter_window(); @@ -1201,7 +1201,7 @@ effechowindow->position(px,py); effchoruswindow->position(px,py); effphaserwindow->position(px,py); effalienwahwindow->position(px,py); -effdistorsionwindow->position(px,py); +effdistortionwindow->position(px,py); effeqwindow->position(px,py); effdynamicfilterwindow->position(px,py); @@ -1219,7 +1219,7 @@ effechowindow->hide(); effchoruswindow->hide(); effphaserwindow->hide(); effalienwahwindow->hide(); -effdistorsionwindow->hide(); +effdistortionwindow->hide(); effeqwindow->hide(); effdynamicfilterwindow->hide(); @@ -1258,7 +1258,7 @@ switch(efftype){ effalienwahwindow->show(); break; case 6: - effdistorsionwindow->show(); + effdistortionwindow->show(); break; case 7:eqband=0; bandcounter->value(eqband); @@ -1297,7 +1297,7 @@ effechowindow->hide();//delete (effechowindow); effchoruswindow->hide();//delete (effchoruswindow); effphaserwindow->hide();//delete (effphaserwindow); effalienwahwindow->hide();//delete (effalienwahwindow); -effdistorsionwindow->hide();//delete (effdistorsionwindow); +effdistortionwindow->hide();//delete (effdistortionwindow); effeqwindow->hide();//delete (effeqwindow); effdynamicfilterwindow->hide();//delete (effdynamicfilterwindow);} {} } @@ -1691,8 +1691,8 @@ effdynamicfilterwindow->hide();//delete (effdynamicfilterwindow);} {} } } } - Function {make_distorsion_window()} {} { - Fl_Window effdistorsionwindow { + Function {make_distortion_window()} {} { + Fl_Window effdistortionwindow { xywh {88 881 230 100} type Double box UP_BOX color 51 labelfont 1 labelsize 19 code3 {set_module_parameters(o);} class Fl_Group visible @@ -2031,7 +2031,7 @@ make_echo_window(); make_chorus_window(); make_phaser_window(); make_alienwah_window(); -make_distorsion_window(); +make_distortion_window(); make_eq_window(); make_dynamicfilter_window(); @@ -2044,7 +2044,7 @@ effechowindow->position(px,py); effchoruswindow->position(px,py); effphaserwindow->position(px,py); effalienwahwindow->position(px,py); -effdistorsionwindow->position(px,py); +effdistortionwindow->position(px,py); effeqwindow->position(px,py); effdynamicfilterwindow->position(px,py);} {} } @@ -2061,7 +2061,7 @@ effechowindow->hide(); effchoruswindow->hide(); effphaserwindow->hide(); effalienwahwindow->hide(); -effdistorsionwindow->hide(); +effdistortionwindow->hide(); effeqwindow->hide(); effdynamicfilterwindow->hide(); @@ -2094,7 +2094,7 @@ switch(efftype){ effalienwahwindow->show(); break; case 6: - effdistorsionwindow->show(); + effdistortionwindow->show(); break; case 7: bandcounter->value(eqband);