~pbatch/soundpipe

soundpipe/tangled/phasor.c -rw-r--r-- 802 bytes
49c52318Paul Batchelor fix talkbox typos 6 days ago
                                                                                
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
#line 49 "phasor.org"
#define SK_PHASOR_PRIV
#include "phasor.h"
#line 84 "phasor.org"
void sk_phasor_init(sk_phasor *ph, int sr, SKFLT iphs)
{
    ph->phs = iphs;
    ph->onedsr = 1.0 / sr;
    sk_phasor_freq(ph, 440);
}
#line 102 "phasor.org"
void sk_phasor_freq(sk_phasor *ph, SKFLT freq)
{
    ph->freq = freq;
}
#line 128 "phasor.org"
SKFLT sk_phasor_tick(sk_phasor *ph)
{
    SKFLT phs;
    SKFLT incr;
    SKFLT out;

    phs = ph->phs;
    incr = ph->freq * ph->onedsr;

    out = phs;

    phs += incr;

    if (phs >= 1.0) {
        phs -= 1.0;
    } else if (phs < 0.0) {
        phs += 1.0;
    }

    ph->phs = phs;

    return out;
}
#line 164 "phasor.org"
void sk_phasor_reset(sk_phasor *phs, SKFLT val)
{
    if (val >= 0) phs->phs = val;
    else phs->phs = 0;
}
#line 49 "phasor.org"