-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoscillator.h
More file actions
99 lines (79 loc) · 2.57 KB
/
oscillator.h
File metadata and controls
99 lines (79 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#pragma once
#include "neuron/core/base.h"
#include "neuron/core/context.h"
#include "neuron/core/parameter.h"
#include "neuron/dsp/generators/generator.h"
#include "neuron/utils/arithmetic.h"
#include "neuron/utils/waveform.h"
namespace neuron {
const size_t WAVETABLE_SIZE = 256;
enum OscillatorParameter {
OSC_FREQUENCY,
};
/**
* The Oscillator class creates an audio signal
* with a basic waveform.
*/
class Oscillator : public Generator<Oscillator>, public Neuron<Oscillator, OscillatorParameter> {
public:
/**
* Creates an oscillator generator.
*
* @param context The DSP context to be used by the oscillator.
* @param frequency The initial frequency of the oscillator.
* @return Oscillator
*/
explicit Oscillator(Context& context = DEFAULT_CONTEXT, float frequency = 440.0f, Waveform waveform = Waveform::SINE);
/**
* Frees any memory allocated by the oscillator.
*/
~Oscillator();
/**
* Resets the phase of the oscillator, starting it at the beginning
* waveform position.
*
* @param
*/
void Reset(float phase = 0.0f);
/**
* Sets the frequency of the oscillator.
*
* @param frequency The new oscillator output frequency.
*/
void SetFrequency(float frequency);
/**
* Sets the waveform of the oscillator.
*
* @param waveform The new oscillator output waveform.
*/
void SetWaveform(Waveform waveform);
/**
* Attaches a follower oscillator to be synced to this one.
*
* @param oscillator The oscillator that will be synced to this one.
*/
void AttachFollower(Oscillator* oscillator);
/**
* Detaches the follower oscillator from this one.
*/
void DetachFollower();
protected:
friend class Generator<Oscillator>;
Sample GenerateImpl();
#ifdef NEO_PLUGIN_SUPPORT
friend class Neuron<Oscillator, OscillatorParameter>;
void AttachParameterToSourceImpl(OscillatorParameter parameter, std::atomic<float>* source);
#endif
private:
void PopulateWavetable();
void IncrementPhase();
Sample Lerp();
Context& m_context;
Sample m_wavetable[WAVETABLE_SIZE];
Waveform m_waveform;
Parameter<float> p_frequency;
float m_phase = 0.0f;
float m_phaseIncrement = 0.0f;
Oscillator* m_follower = nullptr;
};
}