Skip to content

File analogsnaredrum.h

File List > DaisySP > Source > Drums > analogsnaredrum.h

Go to the documentation of this file

Source Code

/*
Copyright (c) 2020 Electrosmith, Corp, Emilie Gillet

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_ANALOG_SNARE_H
#define DSY_ANALOG_SNARE_H

#include "Filters/svf.h"

#include <stdint.h>
#ifdef __cplusplus

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

    static const int kNumModes = 5;

    void Init(float sample_rate);

    float Process(bool trigger = false);

    void Trig();

    void SetSustain(bool sustain);

    void SetAccent(float accent);

    void SetFreq(float f0);

    void SetTone(float tone);

    void SetDecay(float decay);

    void SetSnappy(float snappy);

  private:
    float sample_rate_;

    float f0_, tone_, accent_, snappy_, decay_;
    bool  sustain_;
    bool  trig_;

    inline float SoftLimit(float x);
    inline float SoftClip(float x);

    int   pulse_remaining_samples_;
    float pulse_;
    float pulse_height_;
    float pulse_lp_;
    float noise_envelope_;
    float sustain_gain_;

    Svf resonator_[kNumModes];
    Svf noise_filter_;

    // Replace the resonators in "free running" (sustain) mode.
    float phase_[kNumModes];
};
} // namespace daisysp
#endif
#endif