You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

43 lines
870 B

#pragma once
#ifndef DSY_WHITENOISE_H
#define DSY_WHITENOISE_H
#include <stdint.h>
#ifdef __cplusplus
namespace daisysp
{
/** fast white noise generator
I think this came from musicdsp.org at some point
*/
class WhiteNoise
{
public:
WhiteNoise() {}
~WhiteNoise() {}
/** Initializes the WhiteNoise object
*/
void Init()
{
amp_ = 1.0f;
randseed_ = 1;
}
/** sets the amplitude of the noise output
*/
inline void SetAmp(float a) { amp_ = a; }
/** returns a new sample of noise in the range of -amp_ to amp_
*/
inline float Process()
{
randseed_ *= 16807;
return (randseed_ * coeff_) * amp_;
}
private:
static constexpr float coeff_ = 4.6566129e-010f;
float amp_;
int32_t randseed_;
};
} // namespace daisysp
#endif
#endif