/[svn]/linuxsampler/trunk/src/engines/common/SignalUnit.h
ViewVC logotype

Diff of /linuxsampler/trunk/src/engines/common/SignalUnit.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2205 by iliev, Mon Jul 11 17:52:01 2011 UTC revision 2207 by iliev, Fri Jul 15 15:43:49 2011 UTC
# Line 32  namespace LinuxSampler { Line 32  namespace LinuxSampler {
32       * A signal unit consist of internal signal generator (like envelope generator,       * A signal unit consist of internal signal generator (like envelope generator,
33       * low frequency oscillator, etc) with a number of generator parameters which       * low frequency oscillator, etc) with a number of generator parameters which
34       * influence/modulate/dynamically change the generator's signal in some manner.       * influence/modulate/dynamically change the generator's signal in some manner.
35       * The generators' parameters (also called signal unit parameters) can receive       * Each generator parameter (also called signal unit parameter) can receive
36       * the signal of one or more signal units (through modulators if need)       * signal from another signal unit and use this signal to dynamically change the
37       * and use the (modulated) signals of those units to dynamically change the       * behavior of the signal generator. In turn, the signal of this unit can be fed
      * behavior of the signal generator. In turn, the signal of those unit can be fed  
38       * to another unit(s) and influence its parameters.       * to another unit(s) and influence its parameters.
39       */       */
40      class SignalUnit {      class SignalUnit {
41          public:          public:
42    
43          /**          /**
          * Used as an intermediate link between a source signal unit and  
          * a destination unit parameter. Modulates the received signal from the  
          * source unit and feed it to the unit parameter to which it is connected.  
          */  
         class Modulator {  
             public:  
                 SignalUnit* pUnit; /* The signal source which will be used for modulation.  
                                     * If pUnit is NULL the level is considered to be 1!  
                                     */  
                 float Coeff; // The modulation coefficient  
                   
                 Modulator() : pUnit(NULL) { }  
                 Modulator(SignalUnit* Unit) { pUnit = Unit; }  
                 Modulator(const Modulator& Mod) { Copy(Mod); }  
                 void operator=(const Modulator& Mod) { Copy(Mod); }  
               
                 virtual void Copy(const Modulator& Mod) {  
                     if (this == &Mod) return;  
   
                     pUnit = Mod.pUnit;  
                     Coeff = Mod.Coeff;  
                 }  
                   
                 /**  
                  * Gets the normalized level of the signal source for the current  
                  * time step (sample point). Returns 1 if source unit is NULL or  
                  * if the source unit is inactive.  
                  */  
                 virtual float GetLevel() {  
                     if (pUnit == NULL) return 1.0f;  
                     return pUnit->Active() ? pUnit->GetLevel() : 1.0f;  
                 }  
                   
                 /**  
                  * Gets the modulated level of the source signal  
                  * for the current time step (sample point).  
                  */  
                 virtual float GetValue() {  
                     return Transform(GetLevel());  
                 }  
                   
                 /**  
                  * Calculates the transformation that should be applied  
                  * to the signal of the source unit and multiplies by Coeff.  
                  * This implementation of the method just multiplies by Coeff,  
                  * or returns 1 if the source unit is inactive.  
                  */  
                 virtual float Transform(float val) {  
                     if (pUnit != NULL && !pUnit->Active()) return 1;  
                     return val * Coeff;  
                 }  
         };  
           
         /**  
44           * This class represents a parameter which will influence the signal           * This class represents a parameter which will influence the signal
45           * unit to which it belongs in certain way.           * unit to which it belongs in certain way.
46           * For example, let's say the signal unit is a low frequency oscillator           * For example, let's say the signal unit is a low frequency oscillator
47           * with frequency 1Hz. If we want to modulate the LFO to start with 1Hz           * with frequency 1Hz. If we want to modulate the LFO to start with 1Hz
48           * and increment its frequency to 5Hz in 1 second, we can add           * and increment its frequency to 5Hz in 1 second, we can add
49           * a parameter with one modulator which signal source is an envelope           * a parameter which signal source is an envelope
50           * generator with attack time of 1 second and coefficient 4. Thus, the           * generator with attack time of 1 second and coefficient 4. Thus, the
51           * normalized level of the EG will move from 0 to 1 in one second.           * normalized level of the EG will move from 0 to 1 in one second.
52           * On every time step (sample point) the normalized level           * On every time step (sample point) the normalized level
# Line 113  namespace LinuxSampler { Line 58  namespace LinuxSampler {
58           */           */
59          class Parameter {          class Parameter {
60              public:              public:
61                  ArrayList<Modulator> Modulators; // A list of signal units which will modulate this parameter                  SignalUnit* pUnit; /* The source unit whose output signal
62                                                        * will modulate the parameter.
                 SignalUnit* pUnit; /* If pUnit is not NULL, the modulators are ignored and  
                                     * this unit is used as only source.  
                                     * This is done for efficiency reasons.  
63                                      */                                      */
64                                    
65                  float Coeff; // The global modulation coefficient                  float Coeff; // The modulation coefficient
66                                    
67                                    
68                  Parameter() : Coeff(1), pUnit(NULL) { }                  Parameter() : Coeff(1), pUnit(NULL) { }
69    
70                  /**                  /**
                  * Most often we just need to directly feed the signal of single unit  
                  * to a unit parameter without any additional modulation.  
                  * This constructor creates a parameter with only a single source  
                  * unit without additional modulation, optimized for efficiency.  
71                   * @param unit The source unit used to influence this parameter.                   * @param unit The source unit used to influence this parameter.
72                   * @param coeff The coefficient by which the normalized signal                   * @param coeff The coefficient by which the normalized signal
73                   * received from the source unit should be multiplied when a                   * received from the source unit should be multiplied when a
# Line 146  namespace LinuxSampler { Line 84  namespace LinuxSampler {
84                  virtual void Copy(const Parameter& Prm) {                  virtual void Copy(const Parameter& Prm) {
85                      if (this == &Prm) return;                      if (this == &Prm) return;
86    
                     Modulators = Prm.Modulators;  
87                      pUnit = Prm.pUnit;                      pUnit = Prm.pUnit;
88                      Coeff = Prm.Coeff;                      Coeff = Prm.Coeff;
89                  }                  }
90                                    
91                                    
92                  /**                  /**
93                   * Calculates the global transformation for this parameter                   * Calculates the transformation for this parameter
94                   * which should be applied to the parameter's value                   * which should be applied to the parameter's value
95                   * and multiplies by Coeff.                   * and multiplies by Coeff.
96                   * This implementation of the method just multiplies by Coeff.                   * This implementation of the method just multiplies by Coeff.
# Line 163  namespace LinuxSampler { Line 100  namespace LinuxSampler {
100                  }                  }
101                                    
102                  /**                  /**
103                   * Gets the current value of the parameter (without transformation).                   * Gets the current value of the parameter.
104                   * This implementation just sum the modulators values.                   * This implementation returns the current signal level of the
105                   * If only a single unit is used without additional modulation                   * source unit with applied transformation if the source unit is
106                   * returns the source unit's level or 1 if the unit is not active.                   * active, otherwise returns 1.
107                     * Note that this method assume that pUnit is not NULL.
108                   */                   */
109                  virtual float GetValue() {                  virtual float GetValue() {
110                      if (pUnit != NULL) {                      return pUnit->Active() ? Transform(pUnit->GetLevel()) : 1.0f;
                         return pUnit->Active() ? pUnit->GetLevel() : 1.0f;  
                     }  
   
                     float val = 0;  
                     for(int i = 0; i < Modulators.size(); i++) {  
                         val += Modulators[i].GetValue();  
                     }  
                       
                     return val;  
                 }  
                   
                 /** Gets the final value - with applied transformation. */  
                 virtual float GetFinalValue() {  
                     return Transform(GetValue());  
111                  }                  }
112          };          };
113    
# Line 258  namespace LinuxSampler { Line 182  namespace LinuxSampler {
182               */               */
183              virtual void Increment() { bRecalculate = true; }              virtual void Increment() { bRecalculate = true; }
184    
185              /** Initializes and triggers the unit. */              /**
186                 * Initializes and triggers the unit.
187                 * Note that when a voice is the owner of a unit rack, all settings
188                 * should be reset when this method is called, because the sampler
189                 * is reusing the voice objects.
190                 */
191              virtual void Trigger() = 0;              virtual void Trigger() = 0;
192                            
193              /**              /**
# Line 401  namespace LinuxSampler { Line 330  namespace LinuxSampler {
330          public:          public:
331    
332              virtual float CalculateFilterCutoff(float cutoff) {              virtual float CalculateFilterCutoff(float cutoff) {
333                  return GetFilterCutoff() * cutoff;                  cutoff *= GetFilterCutoff();
334                    return cutoff > 13500 ? 13500 : cutoff;
335              }              }
336                            
337              virtual float CalculatePitch(float pitch) {              virtual float CalculatePitch(float pitch) {

Legend:
Removed from v.2205  
changed lines
  Added in v.2207

  ViewVC Help
Powered by ViewVC