-
Notifications
You must be signed in to change notification settings - Fork 5
/
oscillators.c
34 lines (29 loc) · 1.21 KB
/
oscillators.c
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
#include <stdint.h>
#include <math.h>
void ondaTriangular(uint32_t from, uint32_t to, uint32_t counter, float* buffer, float subperiod, float vol, float env){
uint32_t i;
for (i = from; i < to; ++i, counter++) {
buffer[i] += vol * (4. * (fabs(fmod(((counter) + subperiod/4.), subperiod) / subperiod - .5)-.25)) * env;
}
}
void ondaSierra(uint32_t from, uint32_t to, uint32_t counter, float* buffer, float subperiod, float vol, float env){
uint32_t i;
for (i = from; i < to; ++i, counter++) {
buffer[i] += vol * (2. * fmod(counter, subperiod) / subperiod - 1) * env;
}
}
void ondaCuadrada(uint32_t from, uint32_t to, uint32_t counter, float* buffer, float subperiod, float vol, float env){
uint32_t i;
for (i = from; i < to; ++i, counter++) {
buffer[i] += vol * (2. * ((fmod(counter, subperiod) / subperiod - .5) < 0)-1) * env;
}
}
void ondaPulso(uint32_t from, uint32_t to, uint32_t counter, float* buffer, float subperiod, float vol, float env){
uint32_t i;
for (i = from; i < to; ++i, counter++) {
buffer[i] += vol * (2. * ((fmod(counter, subperiod) / subperiod - .2) < 0)-1) * env;
}
}
void limpiarBuffer(uint32_t from, uint32_t to, float* buffer){
for (uint32_t i = from; i < to; ++i) buffer[i] = 0;
}