History

Looperworking well, have to handle flip and dir different.

mulshine committed 7 years ago

Commit 9902cb91 parent c84e0da3 files · +110 −34Browse files

Unified · Split

3 files
  1. LEAF/Inc/leaf-sample.h +3 −1
  2. LEAF/Src/leaf-sample.c +105 −32
  3. LEAF_JUCEPlugin/Source/LEAFLink.cpp +2 −1
LEAF/Inc/leaf-sample.h+3−1
@@ -73,11 +73,13 @@ extern "C" { · 72 unmodified lines
73 73
74 float idx;74 float idx;
75 float inc;75 float inc;
76 int dir;76 int8_t dir;
77 uint8_t flip;
77 78
78 int32_t start;79 int32_t start;
79 int32_t end;80 int32_t end;
80 uint32_t len;81 uint32_t len;
82 uint32_t cnt;
81 83
82 Mode mode;84 Mode mode;
83 85
LEAF/Src/leaf-sample.c+105−32
@@ -119,6 +119,8 @@ void tSamplePlayer_init (tSamplePlayer* const p, tSample* s) · 118 unmodified lines
119 119
120 p->idx = 0.f;120 p->idx = 0.f;
121 p->inc = 1.f;121 p->inc = 1.f;
122 p->dir = 1;
123 p->flip = 0;
122 124
123 p->mode = Normal;125 p->mode = Normal;
124 126
@@ -133,52 +135,110 @@ void tSamplePlayer_free (tSamplePlayer* const p) · 8 unmodified lines
133 135
134float tSamplePlayer_tick (tSamplePlayer* const p)136float tSamplePlayer_tick (tSamplePlayer* const p)
135{137{
136 if (p->active == 0 || (p->len < 4)) return 0.f;138 if ((p->mode == Normal) && (p->cnt > 0)) p->active = 0;
139
140 if (p->active == 0 || (p->len < 4)) return 0.f;
137 141
138 float sample = 0.f;142 float sample = 0.f;
139 143
140 float* buff = p->samp->buff;144 float* buff = p->samp->buff;
141 145
142 int idx = (int) p->idx;146 int idx = (int) p->idx;
143 float alpha = p->idx - idx;
144
145 int i1 = idx-1;
146 int i3 = idx+1;
147 int i4 = idx+2;
148 147
149 if (i1 < p->start) i1 += p->len;148 // Check dir (direction bit) to interpolate properly
150 if (i3 > p->end) i3 -= p->len;149 if (p->dir > 0)
151 if (i4 > p->end) i4 -= p->len;150 {
151 // FORWARD
152 float alpha = p->idx - idx;
153
154 int i1 = idx-1;
155 int i3 = idx+1;
156 int i4 = idx+2;
157
158 if (i1 < p->start) i1 += p->len;
159 if (i3 > p->end) i3 -= p->len;
160 if (i4 > p->end) i4 -= p->len;
161
162 sample = LEAF_interpolate_hermite (buff[i1],
163 buff[idx],
164 buff[i3],
165 buff[i4],
166 alpha);
167 }
168 else
169 {
170 // REVERSE
171 float alpha = 1.0f - (p->idx - idx);
172
173 int i1 = idx+1;
174 int i3 = idx-1;
175 int i4 = idx-2;
176
177 if (i1 > p->start) i1 -= p->len;
178 if (i3 < p->end) i3 += p->len;
179 if (i4 < p->end) i4 += p->len;
180
181 sample = LEAF_interpolate_hermite (buff[i1],
182 buff[idx],
183 buff[i3],
184 buff[i4],
185 alpha);
186 }
152 187
153 sample = LEAF_interpolate_hermite (buff[i1],
154 buff[idx],
155 buff[i3],
156 buff[i4],
157 alpha);
158 188
159 p->idx += (p->dir * p->inc);189 p->idx += (p->dir * p->inc);
160 190
161 if (p->mode == Normal)191 if (p->mode != BackAndForth)
162 {192 {
163 // FIX THIS: NORMAL MODE NOT IMPLEMENTED YET193 // Check flip bit to change loop test
164 if ((p->dir == 1) && (idx > p->end))194 if (p->flip > 0)
165 {195 {
166 p->active = 0;196 if (idx <= p->end)
197 {
198 p->idx += (float)(p->len);
199 p->cnt++;
200 }
201 else if (idx >= p->start)
202 {
203 p->idx -= (float)(p->len);
204 p->cnt++;
205 }
206 }
207 else
208 {
209 if (idx <= p->start)
210 {
211 p->idx += (float)(p->len);
212 p->cnt++;
213 }
214 else if (idx >= p->end)
215 {
216 p->idx -= (float)(p->len);
217 p->cnt++;
218 }
167 }219 }
168 }220 }
169 else if (p->mode == Loop)221 else // BackAndForth
170 {
171 if (idx < p->start) p->idx += (float)(p->len);
172
173 if (idx > p->end) p->idx -= (float)(p->len);
174 }
175 else if (p->mode == BackAndForth)
176 {222 {
177 if ((idx < p->start) || (idx > p->end))223 if (p->flip > 0)
178 {224 {
179 p->dir = -p->dir;225 if ((idx < p->start) || (idx > p->end))
180 p->idx += (2*p->inc);226 {
227 p->dir = -p->dir;
228 p->idx += (2*p->inc);
229 p->cnt++;
230 }
181 }231 }
232 else
233 {
234 if ((idx > p->start) || (idx < p->end))
235 {
236 p->dir = -p->dir;
237 p->idx += (2*p->inc);
238 p->cnt++;
239 }
240 }
241
182 }242 }
183 243
184 244
@@ -198,6 +258,7 @@ void tSamplePlayer_setMode (tSamplePlayer* const p, Mode mode) · 13 unmodified lines
198void tSamplePlayer_play (tSamplePlayer* const p)258void tSamplePlayer_play (tSamplePlayer* const p)
199{259{
200 p->active = 1;260 p->active = 1;
261 p->cnt = 0;
201}262}
202 263
203void tSamplePlayer_stop (tSamplePlayer* const p)264void tSamplePlayer_stop (tSamplePlayer* const p)
@@ -205,14 +266,27 @@ void tSamplePlayer_stop (tSamplePlayer* const p) · 1 unmodified line
205 p->active = 0;266 p->active = 0;
206}267}
207 268
269static void handleStartEndChange(tSamplePlayer* const p)
270{
271 if (p->start > p->end)
272 {
273 p->dir = -1;
274 p->flip = 1;
275 }
276 else
277 {
278 p->dir = 1;
279 p->flip = 0;
280 }
281}
282
208void tSamplePlayer_setStart (tSamplePlayer* const p, int32_t start)283void tSamplePlayer_setStart (tSamplePlayer* const p, int32_t start)
209{284{
210 p->start = LEAF_clipInt(0, start, (p->samp->length - 1));285 p->start = LEAF_clipInt(0, start, (p->samp->length - 1));
211 286
212 p->len = abs(p->end - p->start);287 p->len = abs(p->end - p->start);
213 288
214 if (p->start > p->end) p->dir = -1;289 handleStartEndChange(p);
215 else p->dir = 1;
216}290}
217 291
218void tSamplePlayer_setEnd (tSamplePlayer* const p, int32_t end)292void tSamplePlayer_setEnd (tSamplePlayer* const p, int32_t end)
@@ -221,8 +295,7 @@ void tSamplePlayer_setEnd (tSamplePlayer* const p, int32_t end) · 2 unmodified lines
221 295
222 p->len = abs(p->end - p->start);296 p->len = abs(p->end - p->start);
223 297
224 if (p->start > p->end) p->dir = -1;298 handleStartEndChange(p);
225 else p->dir = 1;
226}299}
227 300
228void tSamplePlayer_setRate (tSamplePlayer* const p, float rate)301void tSamplePlayer_setRate (tSamplePlayer* const p, float rate)
LEAF_JUCEPlugin/Source/LEAFLink.cpp+2−1
@@ -15,7 +15,8 @@ · 14 unmodified lines
15 15
16std::vector<juce::String> cButtonNames = std::vector<juce::String>16std::vector<juce::String> cButtonNames = std::vector<juce::String>
17{17{
18 "sample"18 "sample",
19 "play"
19};20};
20 21
21std::vector<juce::String> cSliderNames = std::vector<juce::String>22std::vector<juce::String> cSliderNames = std::vector<juce::String>

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