Skip to content

File synthbassdrum.h

File List > DaisySP > Source > Drums > synthbassdrum.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_SYNTHBD_H
#define DSY_SYNTHBD_H

#include "Filters/svf.h"
#include "Utility/dsp.h"

#include <stdint.h>
#ifdef __cplusplus

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

    void Init(float sample_rate);

    float Process(float in);

  private:
    float lp_;
    float hp_;
    Svf   filter_;
};

class SyntheticBassDrumAttackNoise
{
  public:
    SyntheticBassDrumAttackNoise() {}
    ~SyntheticBassDrumAttackNoise() {}

    void Init();

    float Process();

  private:
    float lp_;
    float hp_;
};

class SyntheticBassDrum
{
  public:
    SyntheticBassDrum() {}
    ~SyntheticBassDrum() {}

    void Init(float sample_rate);

    inline float DistortedSine(float phase, float phase_noise, float dirtiness);

    inline float TransistorVCA(float s, float gain);

    float Process(bool trigger = false);

    void Trig();

    void SetSustain(bool sustain);

    void SetAccent(float accent);

    void SetFreq(float freq);

    void SetTone(float tone);

    void SetDecay(float decay);

    void SetDirtiness(float dirtiness);

    void SetFmEnvelopeAmount(float fm_envelope_amount);

    void SetFmEnvelopeDecay(float fm_envelope_decay);

  private:
    float sample_rate_;

    bool  trig_;
    bool  sustain_;
    float accent_, new_f0_, tone_, decay_;
    float dirtiness_, fm_envelope_amount_, fm_envelope_decay_;

    float f0_;
    float phase_;
    float phase_noise_;

    float fm_;
    float fm_lp_;
    float body_env_;
    float body_env_lp_;
    float transient_env_;
    float transient_env_lp_;

    float sustain_gain_;

    float tone_lp_;

    SyntheticBassDrumClick       click_;
    SyntheticBassDrumAttackNoise noise_;

    int body_env_pulse_width_;
    int fm_pulse_width_;
};

} // namespace daisysp
#endif
#endif