Skip to content
Snippets Groups Projects
Select Git revision
  • 93d590284873e1f59f7a9adf50992423c0ed12a2
  • main default protected
2 results

Envelopes.h

Blame
  • Envelopes.h 2.27 KiB
    // ---- A simple linear falling envelope -------
    class EnvelopeSimpleLinear {
      public:
        float counter = 1.0;
        float value;
        float speed = 0.001;
        float amount = 1.0;
        void update();
        void reset();
        void setAmount(float speed);
        void setSpeed(float speed);
    };
    
    void EnvelopeSimpleLinear::update() {
      this->counter -= this->speed;
      if (this->counter <= 0.0) {
        this->counter = 0.0;
      }
      this->value = this->counter * this->amount;
    }
    
    void EnvelopeSimpleLinear::reset() {
      this->counter = 1.0;
      this->value = 0.0;
    }
    
    void EnvelopeSimpleLinear::setSpeed(float speed) {
      this->speed = speed;
    }
    
    void EnvelopeSimpleLinear::setAmount(float amount) {
      this->amount = amount;
    }
    
    // ---- A simple logarithmic falling envelope -------
    class EnvelopeSimpleLog {
      public:
        float counter = 1.0;
        float value;
        float speed = 0.001;
        float amount = 1.0;
        void update();
        void reset();
        void setAmount(float speed);
        void setSpeed(float speed);
    };
    
    void EnvelopeSimpleLog::update() {
      this->counter -= this->speed;
      if (this->counter <= 0.0) {
        this->counter = 0.0;
      }
      this->value = max(0.0, (log10(0.005 + 1.0 - this->counter)*-1.0))/2.3 * this->amount;
    }
    
    void EnvelopeSimpleLog::reset() {
      this->counter = 1.0;
      this->value = 0.0;
    }
    
    void EnvelopeSimpleLog::setSpeed(float speed) {
      this->speed = speed;
    }
    
    void EnvelopeSimpleLog::setAmount(float amount) {
      this->amount = amount;
    }
    
    // // ---- A simple logarithmic falling envelope -------
    // class EnvelopeSigh {
    //   public:
    //     float counter = 0.0;
    //     float value;
    //     float speed = 0.001;
    //     float delay = 300;
    //     float amount = 1.0;
    //     void update();
    //     void reset();
    //     void setAmount(float speed);
    //     void setSpeed(float speed);
    //     void setDelay(float speed);
    // };
    
    // void EnvelopeSimpleLog::update() {
    //   this->counter -= this->speed;
    //   if (this->counter <= 0.0) {
    //     this->counter = 0.0;
    //   }
    //   this->value = max(0.0, (log10(0.005 + 1.0 - this->counter)*-1.0))/2.3 * this->amount;
    // }
    
    // void EnvelopeSimpleLog::reset() {
    //   this->counter = 1.0;
    //   this->value = 0.0;
    // }
    
    // void EnvelopeSimpleLog::setSpeed(float speed) {
    //   this->speed = speed;
    // }
    
    // void EnvelopeSimpleLog::setAmount(float amount) {
    //   this->amount = amount;
    // }