tracktion-engine
3.0-10-g034fdde4aa5
Tracktion Engine — High level data model for audio applications
« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_engine
utilities
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
10
namespace
tracktion
{
inline
namespace
engine
11
{
12
13
//==============================================================================
14
class
BandlimitedWaveLookupTables
:
public
juce::ReferenceCountedObject
15
{
16
public
:
17
~BandlimitedWaveLookupTables
();
18
19
using
Ptr =
juce::ReferenceCountedObjectPtr<BandlimitedWaveLookupTables>
;
20
21
static
Ptr getLookupTables (
double
sampleRate);
22
23
double
sampleRate = 44100.0;
24
25
//==============================================================================
26
juce::dsp::LookupTableTransform<float>
sineFunction;
27
28
juce::OwnedArray<juce::dsp::LookupTableTransform<float>
> triangleFunctions, sawUpFunctions, sawDownFunctions;
29
30
const
int
tablePerNumNotes = 3;
31
32
private
:
33
BandlimitedWaveLookupTables
(
double
sampleRate,
int
tableSize);
34
};
35
36
//==============================================================================
37
class
Oscillator
38
{
39
public
:
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
65
private
:
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,
72
const
juce::OwnedArray
<
juce::dsp::LookupTableTransform<float>
>& tableSet);
73
74
//==============================================================================
75
Waves wave = sine;
76
float
phase = 0, gain = 1, note = 69, pulseWidth = 0.5;
77
double
sampleRate = 44100.0;
78
79
BandlimitedWaveLookupTables::Ptr
lookupTables;
80
81
std::default_random_engine
generator;
82
std::normal_distribution<float>
normalDistribution {0.0f, 0.1f};
83
};
84
85
//==============================================================================
86
class
MultiVoiceOscillator
87
{
88
public
:
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
105
private
:
106
juce::OwnedArray<Oscillator>
oscillators;
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
juce::AudioBuffer
juce::OwnedArray
juce::ReferenceCountedObjectPtr
juce::ReferenceCountedObject
juce::dsp::LookupTableTransform
tracktion::BandlimitedWaveLookupTables
Definition
tracktion_Oscillators.h:15
tracktion::engine::MultiVoiceOscillator
Definition
tracktion_Oscillators.h:87
tracktion::engine::Oscillator
Definition
tracktion_Oscillators.h:38
tracktion
Definition
tracktion_AudioReader.h:23
std::normal_distribution
std::default_random_engine
« « « Anklang Documentation