-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSubOscillator.cpp
40 lines (36 loc) · 1014 Bytes
/
SubOscillator.cpp
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
/*
MINI VIRTUAL ANALOG SYNTHESIZER
Copyright 2014 Kenneth D. Miller III
Sub-Oscillator
*/
#include "StdAfx.h"
#include "SubOscillator.h"
#include "OscillatorNote.h"
#include "PolyBLEP.h"
// sub-oscillator mode names
const char * const sub_osc_name[SUBOSC_COUNT] =
{
"None",
"\xDF\xDC",
"\xDF\xDF\xDC\xDC",
"\xDF\xDC\xDC\xDC",
};
// sub-oscillator
float SubOscillator(NoteOscillatorConfig const &config, OscillatorState const &state, float step)
{
float sub_value = (state.index & config.sub_osc_mode) ? -1.0f : 1.0f;
float const w = step * POLYBLEP_WIDTH;
if (state.phase < 0.5f)
{
float sub_prev = ((state.index - 1) & config.sub_osc_mode) ? -1.0f : 1.0f;
if (sub_value != sub_prev)
sub_value += PolyBLEP(state.phase, w, sub_value - sub_prev);
}
else
{
float sub_next = ((state.index + 1) & config.sub_osc_mode) ? -1.0f : 1.0f;
if (sub_value != sub_next)
sub_value += PolyBLEP(state.phase - 1, w, sub_next - sub_value);
}
return sub_value;
}