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
7373
7474 float idx;
7575 float inc;
76− int dir;
76+ int8_t dir;
77+ uint8_t flip;
7778
7879 int32_t start;
7980 int32_t end;
8081 uint32_t len;
82+ uint32_t cnt;
8183
8284 Mode mode;
8385
LEAF/Src/leaf-sample.c+105−32
@@ -119,6 +119,8 @@ void tSamplePlayer_init (tSamplePlayer* const p, tSample* s) · 118 unmodified lines
119119
120120 p->idx = 0.f;
121121 p->inc = 1.f;
122+ p->dir = 1;
123+ p->flip = 0;
122124
123125 p->mode = Normal;
124126
@@ -133,52 +135,110 @@ void tSamplePlayer_free (tSamplePlayer* const p) · 8 unmodified lines
133135
134136 float tSamplePlayer_tick (tSamplePlayer* const p)
135137 {
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;
137141
138142 float sample = 0.f;
139143
140144 float* buff = p->samp->buff;
141145
142146 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;
148147
149− if (i1 < p->start) i1 += p->len;
150− if (i3 > p->end) i3 -= p->len;
151− if (i4 > p->end) i4 -= p->len;
148+ // Check dir (direction bit) to interpolate properly
149+ if (p->dir > 0)
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+ }
152187
153− sample = LEAF_interpolate_hermite (buff[i1],
154− buff[idx],
155− buff[i3],
156− buff[i4],
157− alpha);
158188
159189 p->idx += (p->dir * p->inc);
160190
161− if (p->mode == Normal)
191+ if (p->mode != BackAndForth)
162192 {
163− // FIX THIS: NORMAL MODE NOT IMPLEMENTED YET
164− if ((p->dir == 1) && (idx > p->end))
193+ // Check flip bit to change loop test
194+ if (p->flip > 0)
165195 {
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+ }
167219 }
168220 }
169− else if (p->mode == Loop)
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)
221+ else // BackAndForth
176222 {
177− if ((idx < p->start) || (idx > p->end))
223+ if (p->flip > 0)
178224 {
179− p->dir = -p->dir;
180− p->idx += (2*p->inc);
225+ if ((idx < p->start) || (idx > p->end))
226+ {
227+ p->dir = -p->dir;
228+ p->idx += (2*p->inc);
229+ p->cnt++;
230+ }
181231 }
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+
182242 }
183243
184244
@@ -198,6 +258,7 @@ void tSamplePlayer_setMode (tSamplePlayer* const p, Mode mode) · 13 unmodified lines
198258 void tSamplePlayer_play (tSamplePlayer* const p)
199259 {
200260 p->active = 1;
261+ p->cnt = 0;
201262 }
202263
203264 void tSamplePlayer_stop (tSamplePlayer* const p)
@@ -205,14 +266,27 @@ void tSamplePlayer_stop (tSamplePlayer* const p) · 1 unmodified line
205266 p->active = 0;
206267 }
207268
269+static 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+
208283 void tSamplePlayer_setStart (tSamplePlayer* const p, int32_t start)
209284 {
210285 p->start = LEAF_clipInt(0, start, (p->samp->length - 1));
211286
212287 p->len = abs(p->end - p->start);
213288
214− if (p->start > p->end) p->dir = -1;
215− else p->dir = 1;
289+ handleStartEndChange(p);
216290 }
217291
218292 void tSamplePlayer_setEnd (tSamplePlayer* const p, int32_t end)
@@ -221,8 +295,7 @@ void tSamplePlayer_setEnd (tSamplePlayer* const p, int32_t end) · 2 unmodified lines
221295
222296 p->len = abs(p->end - p->start);
223297
224− if (p->start > p->end) p->dir = -1;
225− else p->dir = 1;
298+ handleStartEndChange(p);
226299 }
227300
228301 void tSamplePlayer_setRate (tSamplePlayer* const p, float rate)
LEAF_JUCEPlugin/Source/LEAFLink.cpp+2−1
@@ -15,7 +15,8 @@ · 14 unmodified lines
1515
1616 std::vector<juce::String> cButtonNames = std::vector<juce::String>
1717 {
18− "sample"
18+ "sample",
19+ "play"
1920 };
2021
2122 std::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