DaisySP
Loading...
Searching...
No Matches
dust.h
Go to the documentation of this file.
1/*
2Copyright (c) 2020 Electrosmith, Corp, Emilie Gillet
3
4Use of this source code is governed by an MIT-style
5license that can be found in the LICENSE file or at
6https://opensource.org/licenses/MIT.
7*/
8
9#pragma once
10#ifndef DSY_DUST_H
11#define DSY_DUST_H
12#include <cstdlib>
13#include <random>
14#include "Utility/dsp.h"
15#ifdef __cplusplus
16
19namespace daisysp
20{
31class Dust
32{
33 public:
34 Dust() {}
35 ~Dust() {}
36
37 void Init() { SetDensity(.5f); }
38
39 float Process()
40 {
41 float inv_density = 1.0f / density_;
42 float u = rand() * kRandFrac;
43 if(u < density_)
44 {
45 return u * inv_density;
46 }
47 return 0.0f;
48 }
49
50 void SetDensity(float density)
51 {
52 density_ = fclamp(density, 0.f, 1.f);
53 density_ = density_ * .3f;
54 }
55
56 private:
57 float density_;
58 static constexpr float kRandFrac = 1.f / (float)RAND_MAX;
59};
60} // namespace daisysp
61#endif
62#endif
Definition delayline.h:29
Dust Module.
Definition dust.h:32
FIR Filter implementation, generic and ARM CMSIS DSP based.
Definition adenv.h:16
float fclamp(float in, float min, float max)
Definition dsp.h:64