zynaddsubfx

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

commit 33ff1071bdbdc6a1a94968d089a134df178345ec
parent 891ab8f87bcf1fe0db084988e3cbb79487d43f01
Author: fundamental <[email protected]>
Date:   Sun, 11 Jul 2010 16:45:12 -0400

Legato: moving common structure to SynthNote

Diffstat:
Msrc/Synth/ADnote.cpp | 122++++++++++++++++++++++++++++++++++++-------------------------------------------
Msrc/Synth/ADnote.h | 16----------------
Msrc/Synth/CMakeLists.txt | 1+
Msrc/Synth/PADnote.cpp | 124++++++++++++++++++++++++++++++++++++-------------------------------------------
Msrc/Synth/PADnote.h | 16----------------
Msrc/Synth/SUBnote.cpp | 122++++++++++++++++++++++++++++++++++++-------------------------------------------
Msrc/Synth/SUBnote.h | 16----------------
Asrc/Synth/SynthNote.cpp | 23+++++++++++++++++++++++
Msrc/Synth/SynthNote.h | 29++++++++++++++++++++++++-----
9 files changed, 214 insertions(+), 255 deletions(-)

diff --git a/src/Synth/ADnote.cpp b/src/Synth/ADnote.cpp @@ -37,6 +37,7 @@ ADnote::ADnote(ADnoteParameters *pars, int portamento_, int midinote_, bool besilent) +:SynthNote(freq, velocity, portamento_, midinote, besilent) { ready = false; @@ -45,19 +46,6 @@ ADnote::ADnote(ADnoteParameters *pars, bypassl = new REALTYPE [SOUND_BUFFER_SIZE]; bypassr = new REALTYPE [SOUND_BUFFER_SIZE]; - // Initialise some legato-specific vars - Legato.msg = LM_Norm; - Legato.fade.length = (int)(SAMPLE_RATE * 0.005); // 0.005 seems ok. - if(Legato.fade.length < 1) - Legato.fade.length = 1; // (if something's fishy) - Legato.fade.step = (1.0 / Legato.fade.length); - Legato.decounter = -10; - Legato.param.freq = freq; - Legato.param.vel = velocity; - Legato.param.portamento = portamento_; - Legato.param.midinote = midinote_; - Legato.silent = besilent; - partparams = pars; ctl = ctl_; portamento = portamento_; @@ -428,26 +416,26 @@ void ADnote::legatonote(REALTYPE freq, REALTYPE velocity, int portamento_, // Manage legato stuff if(externcall) - Legato.msg = LM_Norm; - if(Legato.msg != LM_CatchUp) { - Legato.lastfreq = Legato.param.freq; - Legato.param.freq = freq; - Legato.param.vel = velocity; - Legato.param.portamento = portamento_; - Legato.param.midinote = midinote_; - if(Legato.msg == LM_Norm) { - if(Legato.silent) { - Legato.fade.m = 0.0; - Legato.msg = LM_FadeIn; + legato.msg = LM_Norm; + if(legato.msg != LM_CatchUp) { + legato.lastfreq = legato.param.freq; + legato.param.freq = freq; + legato.param.vel = velocity; + legato.param.portamento = portamento_; + legato.param.midinote = midinote_; + if(legato.msg == LM_Norm) { + if(legato.silent) { + legato.fade.m = 0.0; + legato.msg = LM_FadeIn; } else { - Legato.fade.m = 1.0; - Legato.msg = LM_FadeOut; + legato.fade.m = 1.0; + legato.msg = LM_FadeOut; return; } } - if(Legato.msg == LM_ToNorm) - Legato.msg = LM_Norm; + if(legato.msg == LM_ToNorm) + legato.msg = LM_Norm; } portamento = portamento_; @@ -1863,74 +1851,74 @@ int ADnote::noteout(REALTYPE *outl, REALTYPE *outr) // Apply legato-specific sound signal modifications - if(Legato.silent) // Silencer - if(Legato.msg != LM_FadeIn) { + if(legato.silent) // Silencer + if(legato.msg != LM_FadeIn) { memset(outl, 0, SOUND_BUFFER_SIZE * sizeof(REALTYPE)); memset(outr, 0, SOUND_BUFFER_SIZE * sizeof(REALTYPE)); } - switch(Legato.msg) { + switch(legato.msg) { case LM_CatchUp: // Continue the catch-up... - if(Legato.decounter == -10) - Legato.decounter = Legato.fade.length; + if(legato.decounter == -10) + legato.decounter = legato.fade.length; for(i = 0; i < SOUND_BUFFER_SIZE; i++) { //Yea, could be done without the loop... - Legato.decounter--; - if(Legato.decounter < 1) { + legato.decounter--; + if(legato.decounter < 1) { // Catching-up done, we can finally set // the note to the actual parameters. - Legato.decounter = -10; - Legato.msg = LM_ToNorm; - legatonote(Legato.param.freq, - Legato.param.vel, - Legato.param.portamento, - Legato.param.midinote, + legato.decounter = -10; + legato.msg = LM_ToNorm; + legatonote(legato.param.freq, + legato.param.vel, + legato.param.portamento, + legato.param.midinote, false); break; } } break; case LM_FadeIn: // Fade-in - if(Legato.decounter == -10) - Legato.decounter = Legato.fade.length; - Legato.silent = false; + if(legato.decounter == -10) + legato.decounter = legato.fade.length; + legato.silent = false; for(i = 0; i < SOUND_BUFFER_SIZE; i++) { - Legato.decounter--; - if(Legato.decounter < 1) { - Legato.decounter = -10; - Legato.msg = LM_Norm; + legato.decounter--; + if(legato.decounter < 1) { + legato.decounter = -10; + legato.msg = LM_Norm; break; } - Legato.fade.m += Legato.fade.step; - outl[i] *= Legato.fade.m; - outr[i] *= Legato.fade.m; + legato.fade.m += legato.fade.step; + outl[i] *= legato.fade.m; + outr[i] *= legato.fade.m; } break; case LM_FadeOut: // Fade-out, then set the catch-up - if(Legato.decounter == -10) - Legato.decounter = Legato.fade.length; + if(legato.decounter == -10) + legato.decounter = legato.fade.length; for(i = 0; i < SOUND_BUFFER_SIZE; i++) { - Legato.decounter--; - if(Legato.decounter < 1) { + legato.decounter--; + if(legato.decounter < 1) { for(int j = i; j < SOUND_BUFFER_SIZE; j++) { outl[j] = 0.0; outr[j] = 0.0; } - Legato.decounter = -10; - Legato.silent = true; + legato.decounter = -10; + legato.silent = true; // Fading-out done, now set the catch-up : - Legato.decounter = Legato.fade.length; - Legato.msg = LM_CatchUp; - REALTYPE catchupfreq = Legato.param.freq - * (Legato.param.freq / Legato.lastfreq); //This freq should make this now silent note to catch-up (or should I say resync ?) with the heard note for the same length it stayed at the previous freq during the fadeout. + legato.decounter = legato.fade.length; + legato.msg = LM_CatchUp; + REALTYPE catchupfreq = legato.param.freq + * (legato.param.freq / legato.lastfreq); //This freq should make this now silent note to catch-up (or should I say resync ?) with the heard note for the same length it stayed at the previous freq during the fadeout. legatonote(catchupfreq, - Legato.param.vel, - Legato.param.portamento, - Legato.param.midinote, + legato.param.vel, + legato.param.portamento, + legato.param.midinote, false); break; } - Legato.fade.m -= Legato.fade.step; - outl[i] *= Legato.fade.m; - outr[i] *= Legato.fade.m; + legato.fade.m -= legato.fade.step; + outl[i] *= legato.fade.m; + outr[i] *= legato.fade.m; } break; default: diff --git a/src/Synth/ADnote.h b/src/Synth/ADnote.h @@ -315,22 +315,6 @@ class ADnote :public SynthNote //how the fine detunes are made bigger or smaller REALTYPE bandwidthDetuneMultiplier; - - // Legato vars - struct { - bool silent; - REALTYPE lastfreq; - LegatoMsg msg; - int decounter; - struct { // Fade In/Out vars - int length; - REALTYPE m, step; - } fade; - struct { // Note parameters - REALTYPE freq, vel; - int portamento, midinote; - } param; - } Legato; }; #endif diff --git a/src/Synth/CMakeLists.txt b/src/Synth/CMakeLists.txt @@ -1,4 +1,5 @@ set(zynaddsubfx_synth_SRCS + SynthNote.cpp ADnote.cpp Envelope.cpp LFO.cpp diff --git a/src/Synth/PADnote.cpp b/src/Synth/PADnote.cpp @@ -1,7 +1,7 @@ /* ZynAddSubFX - a software synthesizer - PADnote.cpp - The "pad" synthesizer + pADnote.cpp - The "pad" synthesizer Copyright (C) 2002-2005 Nasca Octavian Paul Author: Nasca Octavian Paul @@ -29,22 +29,10 @@ PADnote::PADnote(PADnoteParameters *parameters, int portamento_, int midinote, bool besilent) +:SynthNote(freq, velocity, portamento_, midinote, besilent) { ready = false; - // Initialise some legato-specific vars - Legato.msg = LM_Norm; - Legato.fade.length = (int)(SAMPLE_RATE * 0.005); // 0.005 seems ok. - if(Legato.fade.length < 1) - Legato.fade.length = 1; // (if something's fishy) - Legato.fade.step = (1.0 / Legato.fade.length); - Legato.decounter = -10; - Legato.param.freq = freq; - Legato.param.vel = velocity; - Legato.param.portamento = portamento_; - Legato.param.midinote = midinote; - Legato.silent = besilent; - pars = parameters; portamento = portamento_; ctl = ctl_; @@ -181,26 +169,26 @@ void PADnote::legatonote(REALTYPE freq, // Manage legato stuff if(externcall) - Legato.msg = LM_Norm; - if(Legato.msg != LM_CatchUp) { - Legato.lastfreq = Legato.param.freq; - Legato.param.freq = freq; - Legato.param.vel = velocity; - Legato.param.portamento = portamento_; - Legato.param.midinote = midinote; - if(Legato.msg == LM_Norm) { - if(Legato.silent) { - Legato.fade.m = 0.0; - Legato.msg = LM_FadeIn; + legato.msg = LM_Norm; + if(legato.msg != LM_CatchUp) { + legato.lastfreq = legato.param.freq; + legato.param.freq = freq; + legato.param.vel = velocity; + legato.param.portamento = portamento_; + legato.param.midinote = midinote; + if(legato.msg == LM_Norm) { + if(legato.silent) { + legato.fade.m = 0.0; + legato.msg = LM_FadeIn; } else { - Legato.fade.m = 1.0; - Legato.msg = LM_FadeOut; + legato.fade.m = 1.0; + legato.msg = LM_FadeOut; return; } } - if(Legato.msg == LM_ToNorm) - Legato.msg = LM_Norm; + if(legato.msg == LM_ToNorm) + legato.msg = LM_Norm; } portamento = portamento_; @@ -505,75 +493,75 @@ int PADnote::noteout(REALTYPE *outl, REALTYPE *outr) // Apply legato-specific sound signal modifications - if(Legato.silent) // Silencer - if(Legato.msg != LM_FadeIn) + if(legato.silent) // Silencer + if(legato.msg != LM_FadeIn) for(int i = 0; i < SOUND_BUFFER_SIZE; i++) { outl[i] = 0.0; outr[i] = 0.0; } - switch(Legato.msg) { + switch(legato.msg) { case LM_CatchUp: // Continue the catch-up... - if(Legato.decounter == -10) - Legato.decounter = Legato.fade.length; + if(legato.decounter == -10) + legato.decounter = legato.fade.length; for(int i = 0; i < SOUND_BUFFER_SIZE; i++) { //Yea, could be done without the loop... - Legato.decounter--; - if(Legato.decounter < 1) { + legato.decounter--; + if(legato.decounter < 1) { // Catching-up done, we can finally set // the note to the actual parameters. - Legato.decounter = -10; - Legato.msg = LM_ToNorm; - legatonote(Legato.param.freq, - Legato.param.vel, - Legato.param.portamento, - Legato.param.midinote, + legato.decounter = -10; + legato.msg = LM_ToNorm; + legatonote(legato.param.freq, + legato.param.vel, + legato.param.portamento, + legato.param.midinote, false); break; } } break; case LM_FadeIn: // Fade-in - if(Legato.decounter == -10) - Legato.decounter = Legato.fade.length; - Legato.silent = false; + if(legato.decounter == -10) + legato.decounter = legato.fade.length; + legato.silent = false; for(int i = 0; i < SOUND_BUFFER_SIZE; i++) { - Legato.decounter--; - if(Legato.decounter < 1) { - Legato.decounter = -10; - Legato.msg = LM_Norm; + legato.decounter--; + if(legato.decounter < 1) { + legato.decounter = -10; + legato.msg = LM_Norm; break; } - Legato.fade.m += Legato.fade.step; - outl[i] *= Legato.fade.m; - outr[i] *= Legato.fade.m; + legato.fade.m += legato.fade.step; + outl[i] *= legato.fade.m; + outr[i] *= legato.fade.m; } break; case LM_FadeOut: // Fade-out, then set the catch-up - if(Legato.decounter == -10) - Legato.decounter = Legato.fade.length; + if(legato.decounter == -10) + legato.decounter = legato.fade.length; for(int i = 0; i < SOUND_BUFFER_SIZE; i++) { - Legato.decounter--; - if(Legato.decounter < 1) { + legato.decounter--; + if(legato.decounter < 1) { for(int j = i; j < SOUND_BUFFER_SIZE; j++) { outl[j] = 0.0; outr[j] = 0.0; } - Legato.decounter = -10; - Legato.silent = true; + legato.decounter = -10; + legato.silent = true; // Fading-out done, now set the catch-up : - Legato.decounter = Legato.fade.length; - Legato.msg = LM_CatchUp; - REALTYPE catchupfreq = Legato.param.freq - * (Legato.param.freq / Legato.lastfreq); //This freq should make this now silent note to catch-up (or should I say resync ?) with the heard note for the same length it stayed at the previous freq during the fadeout. + legato.decounter = legato.fade.length; + legato.msg = LM_CatchUp; + REALTYPE catchupfreq = legato.param.freq + * (legato.param.freq / legato.lastfreq); //This freq should make this now silent note to catch-up (or should I say resync ?) with the heard note for the same length it stayed at the previous freq during the fadeout. legatonote(catchupfreq, - Legato.param.vel, - Legato.param.portamento, - Legato.param.midinote, + legato.param.vel, + legato.param.portamento, + legato.param.midinote, false); break; } - Legato.fade.m -= Legato.fade.step; - outl[i] *= Legato.fade.m; - outr[i] *= Legato.fade.m; + legato.fade.m -= legato.fade.step; + outl[i] *= legato.fade.m; + outr[i] *= legato.fade.m; } break; default: diff --git a/src/Synth/PADnote.h b/src/Synth/PADnote.h @@ -114,22 +114,6 @@ class PADnote :public SynthNote REALTYPE globaloldamplitude, globalnewamplitude, velocity, realfreq; Controller *ctl; - - // Legato vars - struct { - bool silent; - REALTYPE lastfreq; - LegatoMsg msg; - int decounter; - struct { // Fade In/Out vars - int length; - REALTYPE m, step; - } fade; - struct { // Note parameters - REALTYPE freq, vel; - int portamento, midinote; - } param; - } Legato; }; diff --git a/src/Synth/SUBnote.cpp b/src/Synth/SUBnote.cpp @@ -34,25 +34,13 @@ SUBnote::SUBnote(SUBnoteParameters *parameters, int portamento_, int midinote, bool besilent) +:SynthNote(freq, velocity, portamento_, midinote, besilent) { ready = false; tmpsmp = new REALTYPE[SOUND_BUFFER_SIZE]; tmprnd = new REALTYPE[SOUND_BUFFER_SIZE]; - // Initialise some legato-specific vars - Legato.msg = LM_Norm; - Legato.fade.length = (int)(SAMPLE_RATE * 0.005); // 0.005 seems ok. - if(Legato.fade.length < 1) - Legato.fade.length = 1; // (if something's fishy) - Legato.fade.step = (1.0 / Legato.fade.length); - Legato.decounter = -10; - Legato.param.freq = freq; - Legato.param.vel = velocity; - Legato.param.portamento = portamento_; - Legato.param.midinote = midinote; - Legato.silent = besilent; - pars = parameters; ctl = ctl_; portamento = portamento_; @@ -207,26 +195,26 @@ void SUBnote::legatonote(REALTYPE freq, // Manage legato stuff if(externcall) - Legato.msg = LM_Norm; - if(Legato.msg != LM_CatchUp) { - Legato.lastfreq = Legato.param.freq; - Legato.param.freq = freq; - Legato.param.vel = velocity; - Legato.param.portamento = portamento_; - Legato.param.midinote = midinote; - if(Legato.msg == LM_Norm) { - if(Legato.silent) { - Legato.fade.m = 0.0; - Legato.msg = LM_FadeIn; + legato.msg = LM_Norm; + if(legato.msg != LM_CatchUp) { + legato.lastfreq = legato.param.freq; + legato.param.freq = freq; + legato.param.vel = velocity; + legato.param.portamento = portamento_; + legato.param.midinote = midinote; + if(legato.msg == LM_Norm) { + if(legato.silent) { + legato.fade.m = 0.0; + legato.msg = LM_FadeIn; } else { - Legato.fade.m = 1.0; - Legato.msg = LM_FadeOut; + legato.fade.m = 1.0; + legato.msg = LM_FadeOut; return; } } - if(Legato.msg == LM_ToNorm) - Legato.msg = LM_Norm; + if(legato.msg == LM_ToNorm) + legato.msg = LM_Norm; } portamento = portamento_; @@ -676,74 +664,74 @@ int SUBnote::noteout(REALTYPE *outl, REALTYPE *outr) computecurrentparameters(); // Apply legato-specific sound signal modifications - if(Legato.silent) // Silencer - if(Legato.msg != LM_FadeIn) { + if(legato.silent) // Silencer + if(legato.msg != LM_FadeIn) { memset(outl, 0, SOUND_BUFFER_SIZE * sizeof(REALTYPE)); memset(outr, 0, SOUND_BUFFER_SIZE * sizeof(REALTYPE)); } - switch(Legato.msg) { + switch(legato.msg) { case LM_CatchUp: // Continue the catch-up... - if(Legato.decounter == -10) - Legato.decounter = Legato.fade.length; + if(legato.decounter == -10) + legato.decounter = legato.fade.length; for(i = 0; i < SOUND_BUFFER_SIZE; i++) { //Yea, could be done without the loop... - Legato.decounter--; - if(Legato.decounter < 1) { + legato.decounter--; + if(legato.decounter < 1) { // Catching-up done, we can finally set // the note to the actual parameters. - Legato.decounter = -10; - Legato.msg = LM_ToNorm; - legatonote(Legato.param.freq, - Legato.param.vel, - Legato.param.portamento, - Legato.param.midinote, + legato.decounter = -10; + legato.msg = LM_ToNorm; + legatonote(legato.param.freq, + legato.param.vel, + legato.param.portamento, + legato.param.midinote, false); break; } } break; case LM_FadeIn: // Fade-in - if(Legato.decounter == -10) - Legato.decounter = Legato.fade.length; - Legato.silent = false; + if(legato.decounter == -10) + legato.decounter = legato.fade.length; + legato.silent = false; for(i = 0; i < SOUND_BUFFER_SIZE; i++) { - Legato.decounter--; - if(Legato.decounter < 1) { - Legato.decounter = -10; - Legato.msg = LM_Norm; + legato.decounter--; + if(legato.decounter < 1) { + legato.decounter = -10; + legato.msg = LM_Norm; break; } - Legato.fade.m += Legato.fade.step; - outl[i] *= Legato.fade.m; - outr[i] *= Legato.fade.m; + legato.fade.m += legato.fade.step; + outl[i] *= legato.fade.m; + outr[i] *= legato.fade.m; } break; case LM_FadeOut: // Fade-out, then set the catch-up - if(Legato.decounter == -10) - Legato.decounter = Legato.fade.length; + if(legato.decounter == -10) + legato.decounter = legato.fade.length; for(i = 0; i < SOUND_BUFFER_SIZE; i++) { - Legato.decounter--; - if(Legato.decounter < 1) { + legato.decounter--; + if(legato.decounter < 1) { for(int j = i; j < SOUND_BUFFER_SIZE; j++) { outl[j] = 0.0; outr[j] = 0.0; } - Legato.decounter = -10; - Legato.silent = true; + legato.decounter = -10; + legato.silent = true; // Fading-out done, now set the catch-up : - Legato.decounter = Legato.fade.length; - Legato.msg = LM_CatchUp; - REALTYPE catchupfreq = Legato.param.freq - * (Legato.param.freq / Legato.lastfreq); //This freq should make this now silent note to catch-up (or should I say resync ?) with the heard note for the same length it stayed at the previous freq during the fadeout. + legato.decounter = legato.fade.length; + legato.msg = LM_CatchUp; + REALTYPE catchupfreq = legato.param.freq + * (legato.param.freq / legato.lastfreq); //This freq should make this now silent note to catch-up (or should I say resync ?) with the heard note for the same length it stayed at the previous freq during the fadeout. legatonote(catchupfreq, - Legato.param.vel, - Legato.param.portamento, - Legato.param.midinote, + legato.param.vel, + legato.param.portamento, + legato.param.midinote, false); break; } - Legato.fade.m -= Legato.fade.step; - outl[i] *= Legato.fade.m; - outr[i] *= Legato.fade.m; + legato.fade.m -= legato.fade.step; + outl[i] *= legato.fade.m; + outr[i] *= legato.fade.m; } break; default: diff --git a/src/Synth/SUBnote.h b/src/Synth/SUBnote.h @@ -105,22 +105,6 @@ class SUBnote :public SynthNote Controller *ctl; int oldpitchwheel, oldbandwidth; REALTYPE globalfiltercenterq; - - // Legato vars - struct { - bool silent; - REALTYPE lastfreq; - LegatoMsg msg; - int decounter; - struct { // Fade In/Out vars - int length; - REALTYPE m, step; - } fade; - struct { // Note parameters - REALTYPE freq, vel; - int portamento, midinote; - } param; - } Legato; }; diff --git a/src/Synth/SynthNote.cpp b/src/Synth/SynthNote.cpp @@ -0,0 +1,23 @@ +#include "SynthNote.h" +#include "../globals.h" + +SynthNote::SynthNote(REALTYPE freq, REALTYPE vel, int port, int note, bool quiet) + :legato(freq,vel,port,note,quiet) +{} + +SynthNote::Legato::Legato(REALTYPE freq, REALTYPE vel, int port, + int note, bool quiet) +{ + // Initialise some legato-specific vars + msg = LM_Norm; + fade.length = (int)(SAMPLE_RATE * 0.005); // 0.005 seems ok. + if(fade.length < 1) + fade.length = 1; // (if something's fishy) + fade.step = (1.0 / fade.length); + decounter = -10; + param.freq = freq; + param.vel = vel; + param.portamento = port; + param.midinote = note; + silent = quiet; +} diff --git a/src/Synth/SynthNote.h b/src/Synth/SynthNote.h @@ -26,25 +26,44 @@ class SynthNote { public: + SynthNote(REALTYPE freq, REALTYPE vel, int port, int note, bool quiet); virtual ~SynthNote() {} - + /**Compute Output Samples * @return 0 if note is finished*/ virtual int noteout(REALTYPE *outl, REALTYPE *outr) = 0; - + //TODO fix this spelling error [noisey commit] /**Release the key for the note and start release portion of envelopes.*/ virtual void relasekey() = 0; - + /**Return if note is finished. * @return finished=1 unfinished=0*/ virtual int finished() const = 0; - - virtual void legatonote(REALTYPE freq, REALTYPE velocity, + + virtual void legatonote(REALTYPE freq, REALTYPE velocity, int portamento_, int midinote_, bool externcall) = 0; /**true when ready for output(the parameters has been computed) * false when parameters need to be computed.*/ bool ready; + protected: + // Legato vars + struct Legato{ + Legato(REALTYPE freq, REALTYPE vel, int port, + int note, bool quiet); + bool silent; + REALTYPE lastfreq; + LegatoMsg msg; + int decounter; + struct { // Fade In/Out vars + int length; + REALTYPE m, step; + } fade; + struct { // Note parameters + REALTYPE freq, vel; + int portamento, midinote; + } param; + } legato; }; #endif