-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathWave.cpp
113 lines (105 loc) · 3.33 KB
/
Wave.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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
MINI VIRTUAL ANALOG SYNTHESIZER
Copyright 2014 Kenneth D. Miller III
Wave Types
*/
#include "StdAfx.h"
#include "Wave.h"
#include "WaveSine.h"
#include "WavePulse.h"
#include "WaveSawtooth.h"
#include "WaveTriangle.h"
#include "WaveNoise.h"
#include "WavePoly.h"
#include "WaveHold.h"
// waveform antialiasing
bool use_antialias = true;
// map wave type enumeration to oscillator function
WaveEvaluate const wave_evaluate[WAVE_COUNT] =
{
OscillatorSine, // WAVE_SINE,
OscillatorPulse, // WAVE_PULSE,
OscillatorSawtooth, // WAVE_SAWTOOTH,
OscillatorTriangle, // WAVE_TRIANGLE,
OscillatorNoise, // WAVE_NOISE,
OscillatorNoiseHold, // WAVE_NOISE_HOLD
OscillatorNoiseLinear, // WAVE_NOISE_LINEAR
OscillatorNoiseCubic, // WAVE_NOISE_CUBIC
OscillatorPoly, // WAVE_POLY4,
OscillatorPoly, // WAVE_POLY5,
OscillatorPoly, // WAVE_PERIOD93,
OscillatorPoly, // WAVE_POLY9,
OscillatorPoly, // WAVE_POLY17,
OscillatorPoly, // WAVE_PULSE_POLY5,
OscillatorPoly, // WAVE_POLY4_POLY5,
OscillatorPoly, // WAVE_POLY17_POLY5,
};
// names for wave types
char const * const wave_name[WAVE_COUNT] =
{
"Sine", // WAVE_SINE,
"Pulse", // WAVE_PULSE,
"Sawtooth", // WAVE_SAWTOOTH,
"Triangle", // WAVE_TRIANGLE,
"Noise", // WAVE_NOISE,
"Noise Hold", // WAVE_NOISE_HOLD
"Noise Linear", // WAVE_NOISE_LINEAR
"Noise Cubic", // WAVE_NOISE_CUBIC
"Poly4", // WAVE_POLY4,
"Poly5", // WAVE_POLY5,
"Period-93", // WAVE_PERIOD93,
"Poly9", // WAVE_POLY9,
"Poly17", // WAVE_POLY17,
"Pulse/Poly5", // WAVE_PULSE_POLY5,
"Poly4/Poly5", // WAVE_POLY4_POLY5,
"Poly17/Poly5" // WAVE_POLY17_POLY5,
};
// multiply oscillator time scale based on wave type
// - tune the pitch of short-period poly oscillators
// - raise the pitch of poly oscillators by a factor of two
// - Atari POKEY pitch 255 corresponds to key 9 (N) in octave 2
float const wave_adjust_frequency[WAVE_COUNT] =
{
1.0f, // WAVE_SINE,
1.0f, // WAVE_PULSE,
1.0f, // WAVE_SAWTOOTH,
1.0f, // WAVE_TRIANGLE,
1.0f, // WAVE_NOISE,
1.0f, // WAVE_NOISE_HOLD,
1.0f, // WAVE_NOISE_LINEAR,
1.0f, // WAVE_NOISE_CUBIC,
2.0f * 15.0f / 16.0f, // WAVE_POLY4,
2.0f * 31.0f / 32.0f, // WAVE_POLY5,
2.0f * 93.0f / 128.0f, // WAVE_PERIOD93,
2.0f * 511.0f / 512.0f, // WAVE_POLY9,
2.0f, // WAVE_POLY17,
2.0f * 31.0f / 32.0f, // WAVE_PULSE_POLY5,
2.0f * 465.0f / 512.0f, // WAVE_POLY4_POLY5,
2.0f, // WAVE_POLY17_POLY5,
};
// restart the oscillator loop index after this many phase cycles
// - poly oscillators using the loop index to look up precomputed values
int const wave_loop_cycle[WAVE_COUNT] =
{
INT_MAX, // WAVE_SINE,
INT_MAX, // WAVE_PULSE,
INT_MAX, // WAVE_SAWTOOTH,
INT_MAX, // WAVE_TRIANGLE,
INT_MAX, // WAVE_NOISE,
ARRAY_SIZE(noise), // WAVE_NOISE_HOLD
ARRAY_SIZE(noise), // WAVE_NOISE_LINEAR
ARRAY_SIZE(noise), // WAVE_NOISE_CUBIC
ARRAY_SIZE(poly4), // WAVE_POLY4,
ARRAY_SIZE(poly5), // WAVE_POLY5,
ARRAY_SIZE(period93), // WAVE_PERIOD93,
ARRAY_SIZE(poly9), // WAVE_POLY9,
ARRAY_SIZE(poly17), // WAVE_POLY17,
ARRAY_SIZE(pulsepoly5), // WAVE_PULSE_POLY5,
ARRAY_SIZE(poly4poly5), // WAVE_POLY4_POLY5,
ARRAY_SIZE(poly17poly5), // WAVE_POLY17_POLY5,
};
void InitWave()
{
InitPoly();
InitNoise();
}