-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathzsm.c
executable file
·48 lines (42 loc) · 1.16 KB
/
zsm.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "zsm.h"
#include "utils.h"
#define min(x, y) (x < y ? x : y)
#define max(x, y) (x > y ? x : y)
void zsm_sinusoidal(volatile float *a, volatile float *b, volatile float *c)
{
*a = (SQRT3_BY_2 * (*a)) + 1.0f / 2;
*b = (SQRT3_BY_2 * (*b)) + 1.0f / 2;
*c = (SQRT3_BY_2 * (*c)) + 1.0f / 2;
}
void zsm_midpoint_clamp(volatile float *a, volatile float *b, volatile float *c)
{
float shift = (1 - (min(min(*a, *b), *c) + max(max(*a, *b), *c))) / 2.0;
*a += shift;
*b += shift;
*c += shift;
}
void zsm_top_clamp(volatile float *a, volatile float *b, volatile float *c)
{
float shift = 1 - max(max(*a, *b), *c);
*a += shift;
*b += shift;
*c += shift;
}
void zsm_bottom_clamp(volatile float *a, volatile float *b, volatile float *c)
{
float shift = min(min(*a, *b), *c);
*a -= shift;
*b -= shift;
*c -= shift;
}
void zsm_top_bottom_clamp(volatile float *a, volatile float *b, volatile float *c)
{
if ((*a) * (*b) * (*c) > 0) // Two negatives, largest amplitude positive
{
zsm_top_clamp(a, b, c);
}
else // Two positives, largest amplitude negative
{
zsm_bottom_clamp(a, b, c);
}
}