Skip to content

File chorus.h

File List > DaisySP > Source > Effects > chorus.h

Go to the documentation of this file

Source Code

/*
Copyright (c) 2020 Electrosmith, Corp

Use of this source code is governed by an MIT-style
license that can be found in the LICENSE file or at
https://opensource.org/licenses/MIT.
*/

#pragma once
#ifndef DSY_CHORUS_H
#define DSY_CHORUS_H
#ifdef __cplusplus

#include <stdint.h>
#include "Utility/delayline.h"

namespace daisysp
{
class ChorusEngine
{
  public:
    ChorusEngine() {}
    ~ChorusEngine() {}

    void Init(float sample_rate);

    float Process(float in);

    void SetLfoDepth(float depth);

    void SetLfoFreq(float freq);

    void SetDelay(float delay);

    void SetDelayMs(float ms);

    void SetFeedback(float feedback);

  private:
    float                    sample_rate_;
    static constexpr int32_t kDelayLength
        = 2400; // 50 ms at 48kHz = .05 * 48000

    //triangle lfos
    float lfo_phase_;
    float lfo_freq_;
    float lfo_amp_;

    float feedback_;

    float delay_;

    DelayLine<float, kDelayLength> del_;

    float ProcessLfo();
};

//wraps up all of the chorus engines
class Chorus
{
  public:
    Chorus() {}
    ~Chorus() {}

    void Init(float sample_rate);

    float Process(float in);

    float GetLeft();

    float GetRight();

    void SetPan(float panl, float panr);

    void SetPan(float pan);

    void SetLfoDepth(float depthl, float depthr);

    void SetLfoDepth(float depth);

    void SetLfoFreq(float freql, float freqr);

    void SetLfoFreq(float freq);

    void SetDelay(float delayl, float delayr);

    void SetDelay(float delay);

    void SetDelayMs(float msl, float msr);

    void SetDelayMs(float ms);

    void SetFeedback(float feedbackl, float feedbackr);

    void SetFeedback(float feedback);

  private:
    ChorusEngine engines_[2];
    float        gain_frac_;
    float        pan_[2];

    float sigl_, sigr_;
};
} //namespace daisysp
#endif
#endif