History

Wavetables generated by oscillators.

mulshine committed 7 years ago

Commit cf2bb371 parent 127a11311 files · +674 −795Browse files

Showing the changes to LEAF/Src_cpp/leaf-math.cpp (1 of 11 files). Show all

Unified · Split

LEAF/Src_cpp/leaf-math.cpp+87−2
@@ -18,13 +18,98 @@ · 17 unmodified lines
1818 #include "../Inc/leaf-math.h"
1919 #include "../Inc/leaf-wavetables.h"
2020
21−#endif
21+#endif
22+
23+//#include "../JuceLibraryCode/JuceHeader.h"
24+
2225
2326 // The C-embedded Audio Library.
2427 #define TWO_TO_16 65536.f
2528
2629 #define EXPONENTIAL_TABLE_SIZE 65536
27−
30+
31+void LEAF_generate_sine(float* buffer, int size)
32+{
33+ float phase;
34+ for (int i = 0; i < size; i++)
35+ {
36+ phase = (float) i / (float) size;
37+ buffer[i] = sinf(phase * TWO_PI);
38+ }
39+}
40+
41+void LEAF_generate_sawtooth(float* buffer, float basefreq, int size)
42+{
43+ int harmonic = 1;
44+ float phase = 0.0f;
45+ float freq = harmonic * basefreq;
46+ float amp;
47+
48+ while (freq < (leaf.sampleRate * 0.5))
49+ {
50+ amp = 1.0f / harmonic;
51+ for (int i = 0; i < size; i++)
52+ {
53+ phase = (float) i / (float) size;
54+ buffer[i] += (amp * sinf(harmonic * phase * TWO_PI));
55+ }
56+
57+ harmonic++;
58+ freq = harmonic * basefreq;
59+ }
60+}
61+
62+
63+void LEAF_generate_triangle(float* buffer, float basefreq, int size)
64+{
65+ int harmonic = 1;
66+ float phase = 0.0f;
67+ float freq = harmonic * basefreq;
68+ float amp = 1.0f;
69+
70+ int count = 0;
71+ float mult = 1.0f;
72+
73+ while (freq < (leaf.sampleRate * 0.5))
74+ {
75+ amp = 1.0f / (float)(harmonic * harmonic);
76+
77+ if (count % 2) mult = -1.0f;
78+ else mult = 1.0f;
79+
80+ for (int i = 0; i < size; i++)
81+ {
82+ phase = (float) i / (float) size;
83+ buffer[i] += (mult * amp * sinf(harmonic * phase * TWO_PI));
84+ }
85+
86+ count++;
87+ harmonic += 2;
88+ freq = harmonic * basefreq;
89+ }
90+}
91+
92+void LEAF_generate_square(float* buffer, float basefreq, int size)
93+{
94+ int harmonic = 1;
95+ float phase = 0.0f;
96+ float freq = harmonic * basefreq;
97+ float amp = 1.0f;
98+
99+ while (freq < (leaf.sampleRate * 0.5))
100+ {
101+ amp = 1.0f / (float)(harmonic);
102+
103+ for (int i = 0; i < size; i++)
104+ {
105+ phase = (float) i / (float) size;
106+ buffer[i] += (amp * sinf(harmonic * phase * TWO_PI));
107+ }
108+
109+ harmonic += 2;
110+ freq = harmonic * basefreq;
111+ }
112+}
28113
29114
30115

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t