zynaddsubfx

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

LFO.h (2975B)


      1 /*
      2   ZynAddSubFX - a software synthesizer
      3 
      4   LFO.h - LFO implementation
      5   Copyright (C) 2002-2005 Nasca Octavian Paul
      6   Author: Nasca Octavian Paul
      7 
      8   This program is free software; you can redistribute it and/or
      9   modify it under the terms of the GNU General Public License
     10   as published by the Free Software Foundation; either version 2
     11   of the License, or (at your option) any later version.
     12 */
     13 
     14 #ifndef LFO_H
     15 #define LFO_H
     16 
     17 #include "../globals.h"
     18 #include "../Misc/Time.h"
     19 #include "WatchPoint.h"
     20 
     21 
     22 
     23 namespace zyn {
     24 
     25 /**Class for creating Low Frequency Oscillators*/
     26 class LFO
     27 {
     28     public:
     29         /**Constructor
     30          *
     31          * @param lfopars pointer to a LFOParams object
     32          * @param basefreq base frequency of LFO
     33          */
     34         LFO(const LFOParams &lfopars_, float basefreq_, const AbsTime &t, WatchManager *m=0,
     35                 const char *watch_prefix=0);
     36         ~LFO();
     37 
     38         float lfoout();
     39         float amplfoout();
     40         void releasekey();
     41     private:
     42         typedef enum lfo_state_type{
     43             delaying,
     44             fadingIn,
     45             running,
     46             fadingOut
     47         } lfo_state_type;
     48 
     49         float baseOut(const char waveShape, const float phase);
     50         float biquad(float input);
     51         void updatePars();
     52 
     53         lfo_state_type lfo_state;
     54 
     55         //tempo stored to detect changes
     56         unsigned int tempo;
     57         //Phase of Oscillator
     58         float phase;
     59         //Phase Increment Per Frame
     60         float phaseInc;
     61         //Frequency Randomness
     62         float incrnd, nextincrnd;
     63         //Amplitude Randomness
     64         float amp1, amp2;
     65 
     66         // RND mode
     67         int first_half;
     68         float last_random;
     69         float z1, z2;
     70 
     71         //Intensity of the wave
     72         float lfointensity;
     73         //Amount Randomness
     74         float lfornd, lfofreqrnd;
     75         // Ref to AbsTime object for time.tempo
     76         const AbsTime &time;
     77         //Delay before starting
     78         RelTime delayTime;
     79 
     80         int64_t fadeInDuration;
     81         //Timestamp of begin fadein
     82         int64_t fadeInTimestamp;
     83         //Timestamp of noteoff
     84         int64_t releaseTimestamp;
     85         //Time to ramp out
     86 
     87         int64_t fadeOutDuration;
     88         float rampUp, rampDown, rampOnRelease;
     89         // store the constant out value before oscillating starts
     90         float outStartValue = 0.0;
     91 
     92         char  waveShape;
     93 
     94         //If After initialization there are no calls to random number gen.
     95         bool  deterministic;
     96 
     97         const float     dt;
     98         const LFOParams &lfopars;
     99         const float basefreq;
    100 
    101         float FcAbs, K, norm;
    102 
    103         //biquad coefficients for lp filtering in noise-LFO
    104         float a0 = 0.0007508914611009499;
    105         float a1 = 0.0015017829222018998;
    106         float a2 = 0.0007508914611009499;
    107         float b1 = -1.519121359805288;
    108         float b2 =  0.5221249256496917;
    109 
    110         char cutoff = 127;
    111 
    112         VecWatchPoint watchOut;
    113 
    114         void computeNextFreqRnd(void);
    115 };
    116 
    117 }
    118 
    119 #endif