History

Another gitignore update.

mulshine committed 7 years ago

Commit 6e8f4631 parent c27e1976 files · +202 −9Browse files

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

Unified · Split

LEAF/Src_cpp/leaf-math.cpp+85−0
@@ -136,6 +136,91 @@ float LEAF_tanh(float x) · 135 unmodified lines
136136 else
137137 return x * ( 27 + x * x ) / ( 27 + 9 * x * x );
138138 }
139+
140+
141+void LEAF_generate_sine(float* buffer, int size)
142+{
143+ float phase;
144+ for (int i = 0; i < size; i++)
145+ {
146+ phase = (float) i / (float) size;
147+ buffer[i] = sinf(phase * TWO_PI);
148+ }
149+}
150+
151+void LEAF_generate_sawtooth(float* buffer, float basefreq, int size)
152+{
153+ int harmonic = 1;
154+ float phase = 0.0f;
155+ float freq = harmonic * basefreq;
156+ float amp;
157+
158+ while (freq < (leaf.sampleRate * 0.5))
159+ {
160+ amp = 1.0f / harmonic;
161+ for (int i = 0; i < size; i++)
162+ {
163+ phase = (float) i / (float) size;
164+ buffer[i] += (amp * sinf(harmonic * phase * TWO_PI));
165+ }
166+
167+ harmonic++;
168+ freq = harmonic * basefreq;
169+ }
170+}
171+
172+
173+void LEAF_generate_triangle(float* buffer, float basefreq, int size)
174+{
175+ int harmonic = 1;
176+ float phase = 0.0f;
177+ float freq = harmonic * basefreq;
178+ float amp = 1.0f;
179+
180+ int count = 0;
181+ float mult = 1.0f;
182+
183+ while (freq < (leaf.sampleRate * 0.5))
184+ {
185+ amp = 1.0f / (float)(harmonic * harmonic);
186+
187+ if (count % 2) mult = -1.0f;
188+ else mult = 1.0f;
189+
190+ for (int i = 0; i < size; i++)
191+ {
192+ phase = (float) i / (float) size;
193+ buffer[i] += (mult * amp * sinf(harmonic * phase * TWO_PI));
194+ }
195+
196+ count++;
197+ harmonic += 2;
198+ freq = harmonic * basefreq;
199+ }
200+}
201+
202+void LEAF_generate_square(float* buffer, float basefreq, int size)
203+{
204+ int harmonic = 1;
205+ float phase = 0.0f;
206+ float freq = harmonic * basefreq;
207+ float amp = 1.0f;
208+
209+ while (freq < (leaf.sampleRate * 0.5))
210+ {
211+ amp = 1.0f / (float)(harmonic);
212+
213+ for (int i = 0; i < size; i++)
214+ {
215+ phase = (float) i / (float) size;
216+ buffer[i] += (amp * sinf(harmonic * phase * TWO_PI));
217+ }
218+
219+ harmonic += 2;
220+ freq = harmonic * basefreq;
221+ }
222+}
223+
139224
140225 //-----------------------------------------------------------------------------
141226 // name: mtof()

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