Skip to content

File grainlet.h

File List > DaisySP > Source > Noise > grainlet.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_GRAINLET_H
#define DSY_GRAINLET_H

#include <stdint.h>
#ifdef __cplusplus

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

    void Init(float sample_rate);

    float Process();

    void SetFreq(float freq);

    void SetFormantFreq(float freq);

    void SetShape(float shape);

    void SetBleed(float bleed);

  private:
    float Sine(float phase);

    float Carrier(float phase, float shape);

    float Grainlet(float carrier_phase,
                   float formant_phase,
                   float shape,
                   float bleed);

    // Oscillator state.
    float carrier_phase_;
    float formant_phase_;
    float next_sample_;

    // For interpolation of parameters.
    float carrier_frequency_;
    float formant_frequency_;
    float carrier_shape_;
    float carrier_bleed_;

    float new_carrier_shape_;
    float new_carrier_bleed_;

    float sample_rate_;
};
} // namespace daisysp
#endif
#endif