1 #ifndef NOISE_GENERATOR_HPP
2 #define NOISE_GENERATOR_HPP
40 #define CTZ(x) (__builtin_ctz(x))
42 int inline CTZ(
int num){
44 while (((num>>i)&1)==0 && i<
sizeof(
int)) i++;
53 NumPinkBins1 = NumPinkBins-1
59 for (
int i=0; i<NumPinkBins; i++)
61 m_pinkStore[i] = 0.0f;
69 unsigned long k =
CTZ(m_count);
72 prevr = m_pinkStore[k];
80 if (m_pink <-4.0f || m_pink > 4.0f)
97 unsigned long m_count;
99 float m_pinkStore[NumPinkBins];
117 if (m_brown<-8.0f || m_brown>8.0f)
122 return m_brown*0.0625f;
148 const static int q = 15;
149 const static float c1 = (1 << q) - 1;
150 const static float c2 = ((int)(c1 / 3)) + 1;
151 const static float c3 = 1.f / c1;
156 for(
int i = 0; i < gn->noise.
getSize(); i++){
157 random = ((float)rand() / (float)RAND_MAX);
158 gn->noise[i] = (2.f * ((random * c2) + (random * c2) + (random * c2)) - 3.f * (c2 - 1.f)) * c3;
159 if(fabs(gn->noise[i]) >
max)
160 max = fabs(gn->noise[i]);
162 for (
int i = 0; i < gn->noise.
getSize(); i++){
164 gn->noise[i] = gn->noise[i] /
max;
171 float sample = noise[phase];
182 TrueNoiseGenerator() {
183 RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG,ENABLE);
187 while(RNG_GetFlagStatus(RNG_FLAG_DRDY) == RESET);
188 uint32_t data = RNG_GetRandomNumber();
189 return data/float(UINT32_MAX);
float randf()
generate a random number between 0 and 1
uint32_t arm_rand32()
Generate an unsigned 32bit pseudo-random number using xorshifter algorithm.
Generator that produces Brownian noise (aka red noise)
float generate()
Produce the next consecutive sample.
static BrownNoiseGenerator * create()
static void destroy(BrownNoiseGenerator *osc)
This class contains useful methods for manipulating arrays of floats.
static void destroy(FloatArray array)
Destroys a FloatArray created with the create() method.
static FloatArray create(int size)
Creates a new FloatArray.
static GaussianNoiseGenerator * create(int size)
static void destroy(GaussianNoiseGenerator *gn)
float generate()
Produce the next consecutive sample.
GaussianNoiseGenerator(FloatArray ns)
static void destroy(PinkNoiseGenerator *osc)
static PinkNoiseGenerator * create()
float generate()
Produce the next consecutive sample.
Base class for signal generators such as Oscillators.
virtual float generate()
Produce the next consecutive sample.
static void destroy(WhiteNoiseGenerator *osc)
static WhiteNoiseGenerator * create()
virtual float generate()
Produce the next consecutive sample.