Skip to content

File whitenoise.h

File List > DaisySP > Source > Noise > whitenoise.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_WHITENOISE_H
#define DSY_WHITENOISE_H
#include <stdint.h>
#ifdef __cplusplus
namespace daisysp
{
class WhiteNoise
{
  public:
    WhiteNoise() {}
    ~WhiteNoise() {}
    void Init()
    {
        amp_      = 1.0f;
        randseed_ = 1;
    }

    inline void SetAmp(float a) { amp_ = a; }
    inline float Process()
    {
        randseed_ *= 16807;
        return (randseed_ * coeff_) * amp_;
    }

    inline void SetSeed(int32_t s) { randseed_ = s == 0 ? 1 : s; }

  private:
    static constexpr float coeff_ = 4.6566129e-010f;
    float                  amp_;
    int32_t                randseed_;
};
} // namespace daisysp
#endif
#endif