tracktion-engine 3.0-10-g034fdde4aa5
Tracktion Engine — High level data model for audio applications

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_Oscillators.h
Go to the documentation of this file.
1 /*
2 ,--. ,--. ,--. ,--.
3 ,-' '-.,--.--.,--,--.,---.| |,-.,-' '-.`--' ,---. ,--,--, Copyright 2018
4 '-. .-'| .--' ,-. | .--'| /'-. .-',--.| .-. || \ Tracktion Software
5 | | | | \ '-' \ `--.| \ \ | | | |' '-' '| || | Corporation
6 `---' `--' `--`--'`---'`--'`--' `---' `--' `---' `--''--' www.tracktion.com
7*/
8
9
10namespace tracktion { inline namespace engine
11{
12
13//==============================================================================
15{
16public:
18
20
21 static Ptr getLookupTables (double sampleRate);
22
23 double sampleRate = 44100.0;
24
25 //==============================================================================
27
28 juce::OwnedArray<juce::dsp::LookupTableTransform<float>> triangleFunctions, sawUpFunctions, sawDownFunctions;
29
30 const int tablePerNumNotes = 3;
31
32private:
33 BandlimitedWaveLookupTables (double sampleRate, int tableSize);
34};
35
36//==============================================================================
38{
39public:
40 //==============================================================================
41 enum Waves
42 {
43 none = 0,
44 sine,
45 square,
46 saw,
47 triangle,
48 noise,
49 };
50
51 //==============================================================================
52 Oscillator() = default;
53
54 void start();
55 void start (float p) { phase = p; }
56
57 void setSampleRate (double sr);
58 void setWave (Waves w) { wave = w; }
59 void setNote (float n) { note = n; }
60 void setGain (float g) { gain = g; }
61 void setPulseWidth (float p) { pulseWidth = p; }
62
63 void process (juce::AudioBuffer<float>& buffer, int startSample, int numSamples);
64
65private:
66 //==============================================================================
67 void processSine (juce::AudioBuffer<float>& buffer, int startSample, int numSamples);
68 void processSquare (juce::AudioBuffer<float>& buffer, int startSample, int numSamples);
69 void processNoise (juce::AudioBuffer<float>& buffer, int startSample, int numSamples);
70
71 void processLookup (juce::AudioBuffer<float>& buffer, int startSample, int numSamples,
73
74 //==============================================================================
75 Waves wave = sine;
76 float phase = 0, gain = 1, note = 69, pulseWidth = 0.5;
77 double sampleRate = 44100.0;
78
80
82 std::normal_distribution<float> normalDistribution {0.0f, 0.1f};
83};
84
85//==============================================================================
87{
88public:
89 MultiVoiceOscillator (int maxVoices = 8);
90
91 void start();
92 void setSampleRate (double sr);
93 void setWave (Oscillator::Waves w);
94 void setNote (float n);
95 void setGain (float g);
96 void setPan (float p);
97 void setPulseWidth (float p);
98
99 void setNumVoices (int n);
100 void setDetune (float d);
101 void setSpread (float s);
102
103 void process (juce::AudioBuffer<float>& buffer, int startSample, int numSamples);
104
105private:
107
108 int voices = 1;
109 float detune = 0, spread = 0, gain = 1.0f, note = 69.0f, pan = 0.0f;
110};
111
112}} // namespace tracktion { inline namespace engine