~pbatch/soundpipe

soundpipe/tangled/modalres.c -rw-r--r-- 1.5 KiB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#line 19 "modalres.org"
#include <math.h>
#define SK_MODALRES_PRIV
#include "modalres.h"

#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif

#line 58 "modalres.org"
void sk_modalres_init(sk_modalres *mr, int sr)
{
#line 92 "modalres.org"
mr->x = 0;
mr->y[0] = 0;
mr->y[1] = 0;
#line 110 "modalres.org"
mr->b1 = 0;
mr->a1 = 0;
mr->a2 = 0;
#line 125 "modalres.org"
mr->sr = sr;
#line 140 "modalres.org"
mr->s = 0;
#line 172 "modalres.org"
sk_modalres_freq(mr, 1000);
mr->pfreq = -1;
#line 204 "modalres.org"
sk_modalres_q(mr, 1);
mr->pq = -1;
#line 61 "modalres.org"
}
#line 153 "modalres.org"
void sk_modalres_freq(sk_modalres *mr, SKFLT freq)
{
    mr->freq = freq;
}
#line 185 "modalres.org"
void sk_modalres_q(sk_modalres *mr, SKFLT q)
{
    mr->q = q;
}
#line 217 "modalres.org"
SKFLT sk_modalres_tick(sk_modalres *mr, SKFLT in)
{
    SKFLT out;

    out = 0;
#line 246 "modalres.org"
if (mr->freq != mr->pfreq || mr->q != mr->pq) {
    SKFLT w;
    SKFLT a, b, d;

    w = mr->freq * 2.0 * M_PI;

    a = mr->sr / w;
    b = a*a;
    d = 0.5*a;

    mr->pfreq = mr->freq;
    mr->pq = mr->q;

    mr->b1 = 1.0 / (b + d/mr->q);
    mr->a1 = (1.0 - 2.0*b) * mr->b1;
    mr->a2 = (b - d/mr->q) * mr->b1;
    mr->s = d;
}
#line 217 "modalres.org"
#line 285 "modalres.org"
out = mr->b1*mr->x - mr->a1*mr->y[0] - mr->a2*mr->y[1];
#line 217 "modalres.org"
#line 295 "modalres.org"
mr->y[1] = mr->y[0];
mr->y[0] = out;
mr->x = in;
#line 217 "modalres.org"
#line 305 "modalres.org"
out *= mr->s;
#line 226 "modalres.org"
    return out;
}
#line 19 "modalres.org"