DaisySP
Loading...
Searching...
No Matches
fractal_noise.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_FRACTAL_H
11#define DSY_FRACTAL_H
12
13#include <stdint.h>
14#ifdef __cplusplus
15
18namespace daisysp
19{
31template <typename T, int order>
33{
34 public:
37
41 void Init(float sample_rate)
42 {
43 sample_rate_ = sample_rate;
44
45 SetColor(.5f);
46 SetFreq(440.f);
47 for(int i = 0; i < order; ++i)
48 {
49 generator_[i].Init(sample_rate_);
50 }
51 }
52
54 float Process()
55 {
56 float gain = 0.5f;
57 float sum = 0.0f;
58 float frequency = frequency_;
59
60 for(int i = 0; i < order; ++i)
61 {
62 generator_[i].SetFreq(frequency);
63 sum += generator_[i].Process() * gain;
64 gain *= decay_;
65 frequency *= 2.0f;
66 }
67
68 return sum;
69 }
70
74 void SetFreq(float freq) { frequency_ = fclamp(freq, 0.f, sample_rate_); }
75
79 void SetColor(float color) { decay_ = fclamp(color, 0.f, 1.f); }
80
81 private:
82 float sample_rate_;
83 float frequency_;
84 float decay_;
85
86 T generator_[order];
87};
88} // namespace daisysp
89#endif
90#endif
Definition delayline.h:29
Fractal Noise, stacks octaves of a noise source.
Definition fractal_noise.h:33
float Process()
Definition fractal_noise.h:54
void SetFreq(float freq)
Definition fractal_noise.h:74
void SetColor(float color)
Definition fractal_noise.h:79
void Init(float sample_rate)
Definition fractal_noise.h:41
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