History

added biramp

Paul Batchelor committed 5 years ago

Commit 34663ba1 parent 0459c914 files · +157 −0Browse files

Unified · Split

4 files
  1. Makefile +1 −0
  2. algos.org +3 −0
  3. biramp.org +152 −0
  4. mkdb.janet +1 −0
Makefile+1−0
@@ -22,6 +22,7 @@ oscf.c oscf.h \ · 21 unmodified lines
22bezier.c bezier.h \22bezier.c bezier.h \
23phasor.c phasor.h \23phasor.c phasor.h \
24swell.c swell.h \24swell.c swell.h \
25biramp.c biramp.h \
25 26
26.SUFFIX: .org .c27.SUFFIX: .org .c
27 28
algos.org+3−0
@@ -41,3 +41,6 @@ signal. · 40 unmodified lines
41 41
42@!(ref "swell")!@ is a smoothing filter for control signals42@!(ref "swell")!@ is a smoothing filter for control signals
43whose smoothing amount changes based on the direction.43whose smoothing amount changes based on the direction.
44
45@!(ref "biramp")!@ converts a phasor ramp signal into a ramp
46that goes up and down.
biramp.org+152−0
@@ -0,0 +1,152 @@
1#+TITLE: Biramp
2* Overview
3Produces an up-and-down ramp signal from an input phasor
4ramp signal. Things like this are useful for creating quick
5time-synced LFO signals. Because it ramps down to 0, it
6won't clip.
7
8A few flavors of biramp will be created: a stateless
9version with position control, a stateful version with
10position that only updates at the beginnig of the phasor,
11and a stateful version with no position contorl that
12inverts the direction of the phasor at the beginning of
13each phase.
14* Tangled Files
15Tangles into =biramp.c= and =biramp.h=.
16
17#+NAME: biramp.h
18#+BEGIN_SRC c :tangle biramp.h
19#ifndef SK_BIRAMP_H
20#define SK_BIRAMP_H
21
22#ifndef SKFLT
23#define SKFLT float
24#endif
25
26<<funcdefs>>
27#endif
28#+END_SRC
29
30#+NAME: biramp.c
31#+BEGIN_SRC c :tangle biramp.c
32#define SK_BIRAMP_PRIV
33#include "biramp.h"
34<<funcs>>
35#+END_SRC
36* Version 1: Stateless
37The stateless version of biramp is called
38=sk_biramp_stateless=.
39
40#+NAME: funcdefs
41#+BEGIN_SRC c
42SKFLT sk_biramp_stateless(SKFLT phs, SKFLT pos);
43#+END_SRC
44
45The stateless version needs only the input phasor signal
46and split position (expected to be a normalized value).
47
48When the phasor is less than the position, the output is
49=phasor/position=.
50
51When the phasor is greater than or equal to the position,
52the output is =1 - phasor/1 - position=.
53
54The position cannot be 0 or 1 exactly. Instead of throwing
55an error, these will just return themselves.
56
57#+NAME: funcs
58#+BEGIN_SRC c
59SKFLT sk_biramp_stateless(SKFLT phs, SKFLT pos)
60{
61 SKFLT out;
62 out = 0;
63
64 if (pos == 0 || pos == 1) return pos;
65
66 if (phs < pos) out = phs / pos;
67 else out = (1 - phs) / (1 - pos);
68
69 return out;
70}
71#+END_SRC
72* Version 2: Stateful
73The function =sk_biramp_stateful= is a variation of the
74stateless biramp with some managed internal state.
75
76#+NAME: funcdefs
77#+BEGIN_SRC c
78SKFLT sk_biramp_stateful(SKFLT phs, SKFLT pos,
79 SKFLT *lphs, SKFLT *lpos);
80#+END_SRC
81
82The stateful version of this functionality can be used so
83that the position only updates when the phasor resets back
84to zero. To do this, two additional pointer values are
85given: the previous phase, and the used cached position
86parameter.
87
88This will use the cached position value instead of the
89immediation position value to compute the biramp. The
90cached value will update itself if it is less than 0, or if
91it finds the phasor has reset. The phasor resets when the
92last phasor value is greater than the current phasor value.
93
94The cached phasor value is updated here as well.
95
96#+NAME: funcs
97#+BEGIN_SRC c
98SKFLT sk_biramp_stateful(SKFLT phs, SKFLT pos,
99 SKFLT *lphs, SKFLT *lpos)
100{
101 SKFLT out;
102 out = 0;
103
104 if (*lphs > phs || *lpos < 0) {
105 *lpos = pos;
106 }
107
108 out = sk_biramp_stateless(phs, *lpos);
109
110 *lphs = phs;
111 return out;
112}
113#+END_SRC
114* Version 3: Flipper
115The final variation, called a =flipper=, will
116produce a phasor signal whose direction is flipped when the
117phase is reset. The stateful variables here include the
118cached phasor signal from the previous signal, and an
119integer storing the direction. When the direction is 0, it
120is normal. Non-zero is a flip.
121
122The direction state is updated on a phase reset, when the
123cached phasor is greater than the current phasor.
124
125It's important that the cached last phase value is stored
126pre-flipped. That way, the phasor consistently stays in one
127direction and makes the reset checker very straight-forward.
128
129#+NAME: funcdefs
130#+BEGIN_SRC c
131SKFLT sk_biramp_flipper(SKFLT phs, SKFLT *lphs, int *flipit);
132#+END_SRC
133
134#+NAME: funcs
135#+BEGIN_SRC c
136SKFLT sk_biramp_flipper(SKFLT phs, SKFLT *lphs, int *flipit)
137{
138 SKFLT out;
139 out = 0;
140
141 if (*lphs > phs) {
142 (*flipit) = ~(*flipit);
143 }
144
145 out = phs;
146 *lphs = phs;
147
148 if (*flipit) out = 1 - out;
149
150 return out;
151}
152#+END_SRC
mkdb.janet+1−0
@@ -31,6 +31,7 @@ · 30 unmodified lines
31(ww-add-link "phsclk" "phsclk.org")31(ww-add-link "phsclk" "phsclk.org")
32(ww-add-link "phasor" "phasor.org")32(ww-add-link "phasor" "phasor.org")
33(ww-add-link "swell" "swell.org")33(ww-add-link "swell" "swell.org")
34(ww-add-link "biramp" "biramp.org")
34 35
35# sync and close36# sync and close
36 37

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t