naspro
view permafrost/examples/funcgen.pmf @ 178:7169a8909d53
Added Permafrost + small changes
| author | Stefano D'Angelo <zanga.mail@gmail.com> |
|---|---|
| date | Sun May 02 14:19:58 2010 +0300 (2010-05-02) |
| parents | |
| children |
line source
1 # Permafrost - Physical modelling framework
2 #
3 # Copyright (C) 2009, 2010 Stefano D'Angelo <zanga.mail@gmail.com>
4 #
5 # See the COPYING file for license conditions.
7 import m;
8 import common;
10 block step
11 {
12 input prev;
13 input step;
14 output o;
16 o = m_fmod(prev + step, 1);
17 }
19 macro sawtooth
20 {
21 output o;
22 input frequency; # ratio between frequency and sample rate
24 step s;
25 delay_1_sample d;
27 o = s.o;
28 d.i = s.o;
29 s.prev = d.o;
30 s.step = frequency;
31 }
33 macro center_gain_offset
34 {
35 input i;
36 input center;
37 input gain;
38 input offset;
39 output o;
41 sum off_c;
42 mul m;
43 sum off_o;
45 off_c.i1 = i;
46 off_c.i2 = center;
47 m.i1 = off_c.o;
48 m.i2 = gain;
49 off_o.i1 = m.o;
50 off_o.i2 = offset;
51 o = off_o.o;
52 }
54 system Sawtooth
55 {
56 sync output o;
57 async input frequency;
58 async input offset;
59 async input amplitude;
61 sawtooth saw;
62 center_gain_offset cgo;
64 o = cgo.o;
65 saw.frequency = frequency;
66 cgo.i = saw.o;
67 cgo.center = -0.5;
68 cgo.gain = amplitude;
69 cgo.offset = offset;
70 }
72 block sin
73 {
74 input i;
75 output o;
77 o = m_sin(2 * m_pi * i);
78 }
80 system Oscillator
81 {
82 sync output o;
83 async input frequency;
84 async input offset;
85 async input amplitude;
87 sawtooth saw;
88 sin s;
89 center_gain_offset cgo;
91 o = cgo.o;
92 saw.frequency = frequency;
93 s.i = saw.o;
94 cgo.i = s.o;
95 cgo.center = 0;
96 cgo.gain = amplitude;
97 cgo.offset = offset;
98 }
