Skip to content

File pluck.h

File List > DaisySP > DaisySP-LGPL > Source > PhysicalModeling > pluck.h

Go to the documentation of this file

Source Code

/*
Copyright (c) 2023 Electrosmith, Corp, Barry Vercoe, John ffitch

Use of this source code is governed by the LGPL V2.1
license that can be found in the LICENSE file or at
https://opensource.org/license/lgpl-2-1/
*/

#pragma once
#ifndef DSY_PLUCK_H
#define DSY_PLUCK_H

#include <stdint.h>
#ifdef __cplusplus

namespace daisysp
{
enum
{
    PLUCK_MODE_RECURSIVE,
    PLUCK_MODE_WEIGHTED_AVERAGE,
    PLUCK_LAST,
};

class Pluck
{
  public:
    Pluck() {}
    ~Pluck() {}
    void Init(float sample_rate, float *buf, int32_t npt, int32_t mode);


    float Process(float &trig);

    inline void SetAmp(float amp) { amp_ = amp; }
    inline void SetFreq(float freq) { freq_ = freq; }
    inline void SetDecay(float decay) { decay_ = decay; }
    inline void SetDamp(float damp) { damp_ = damp; }
    inline void SetMode(int32_t mode) { mode_ = mode; }
    inline float GetAmp() { return amp_; }
    inline float GetFreq() { return freq_; }
    inline float GetDecay() { return decay_; }
    inline float GetDamp() { return damp_; }
    inline int32_t GetMode() { return mode_; }

  private:
    void    Reinit();
    float   amp_, freq_, decay_, damp_, ifreq_;
    float   sicps_;
    int32_t phs256_, npts_, maxpts_;
    float * buf_;
    float   sample_rate_;
    char    init_;
    int32_t mode_;
};
} // namespace daisysp
#endif
#endif