History

Sampler working great, besides crossfade.

mulshine committed 7 years ago

Commit 58869ea1 parent 9902cb93 files · +42 −63Browse files

Unified · Split

3 files
  1. LEAF/Inc/leaf-sample.h +1 −1
  2. LEAF/Src/leaf-sample.c +37 −60
  3. LEAF_JUCEPlugin/Source/MyTest.cpp +4 −2
LEAF/Inc/leaf-sample.h+1−1
@@ -74,7 +74,7 @@ extern "C" { · 73 unmodified lines
7474 float idx;
7575 float inc;
7676 int8_t dir;
77− uint8_t flip;
77+ int8_t flip;
7878
7979 int32_t start;
8080 int32_t end;
LEAF/Src/leaf-sample.c+37−60
@@ -120,7 +120,7 @@ void tSamplePlayer_init (tSamplePlayer* const p, tSample* s) · 119 unmodified lines
120120 p->idx = 0.f;
121121 p->inc = 1.f;
122122 p->dir = 1;
123− p->flip = 0;
123+ p->flip = 1;
124124
125125 p->mode = Normal;
126126
@@ -143,22 +143,30 @@ float tSamplePlayer_tick (tSamplePlayer* const p) · 16 unmodified lines
143143
144144 float* buff = p->samp->buff;
145145
146+ int dir = p->dir * p->flip;
147+
146148 int idx = (int) p->idx;
149+ float alpha = p->idx - idx;
150+
151+ uint32_t start = p->start, end = p->end;
152+ if (p->flip < 0)
153+ {
154+ start = p->end;
155+ end = p->start;
156+ }
147157
148− // Check dir (direction bit) to interpolate properly
149− if (p->dir > 0)
158+ // Check dir (direction) to interpolate properly
159+ if (dir > 0)
150160 {
151161 // FORWARD
152− float alpha = p->idx - idx;
153−
154162 int i1 = idx-1;
155163 int i3 = idx+1;
156164 int i4 = idx+2;
157165
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−
166+ if (i1 < start) i1 += p->len;
167+ if (i3 > end) i3 -= p->len;
168+ if (i4 > end) i4 -= p->len;
169+
162170 sample = LEAF_interpolate_hermite (buff[i1],
163171 buff[idx],
164172 buff[i3],
@@ -168,16 +176,14 @@ float tSamplePlayer_tick (tSamplePlayer* const p) · 3 unmodified lines
168176 else
169177 {
170178 // REVERSE
171− float alpha = 1.0f - (p->idx - idx);
172−
173179 int i1 = idx+1;
174180 int i3 = idx-1;
175181 int i4 = idx-2;
176182
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−
183+ if (i1 > end) i1 -= p->len;
184+ if (i3 < start) i3 += p->len;
185+ if (i4 < start) i4 += p->len;
186+
181187 sample = LEAF_interpolate_hermite (buff[i1],
182188 buff[idx],
183189 buff[i3],
@@ -185,60 +191,33 @@ float tSamplePlayer_tick (tSamplePlayer* const p) · 1 unmodified line
185191 alpha);
186192 }
187193
188−
189− p->idx += (p->dir * p->inc);
194+ p->idx += (dir * p->inc);
190195
191196 if (p->mode != BackAndForth)
192197 {
193198 // Check flip bit to change loop test
194− if (p->flip > 0)
199+ if (idx <= start)
195200 {
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− }
201+ // -inc
202+ p->idx += (float)(p->len);
203+ p->cnt++;
206204 }
207− else
205+ else if (idx >= end)
208206 {
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− }
207+ // +inc
208+ p->idx -= (float)(p->len);
209+ p->cnt++;
219210 }
211+
220212 }
221213 else // BackAndForth
222214 {
223− if (p->flip > 0)
215+ if ((idx < start) || (idx > end))
224216 {
225− if ((idx < p->start) || (idx > p->end))
226− {
227− p->dir = -p->dir;
228− p->idx += (2*p->inc);
229− p->cnt++;
230− }
217+ p->dir = -p->dir;
218+ p->idx += (2*p->inc);
219+ p->cnt++;
231220 }
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−
242221 }
243222
244223
@@ -270,13 +249,11 @@ static void handleStartEndChange(tSamplePlayer* const p) · 25 unmodified lines
270249 {
271250 if (p->start > p->end)
272251 {
273− p->dir = -1;
274− p->flip = 1;
252+ p->flip = -1;
275253 }
276254 else
277255 {
278− p->dir = 1;
279− p->flip = 0;
256+ p->flip = 1;
280257 }
281258 }
282259
LEAF_JUCEPlugin/Source/MyTest.cpp+4−2
@@ -42,7 +42,7 @@ float LEAFTest_tick (float input) · 41 unmodified lines
4242
4343 timer++;
4444
45− if (timer >= leaf.sampleRate * 4)
45+ if (player.active == 0 && timer >= leaf.sampleRate * 4)
4646 {
4747 tSamplePlayer_play(&player);
4848 }
@@ -55,7 +55,9 @@ void LEAFTest_block (void) · 6 unmodified lines
5555 {
5656 float val = getSliderValue("rate");
5757
58− tSamplePlayer_setRate(&player, val * 16.0f - 8.0f);
58+ float rate = val * 16.0f - 8.0f;
59+ tSamplePlayer_setRate(&player, rate);
60+ DBG("rate: " + String(rate));
5961
6062 val = getSliderValue("start");
6163 float start = val * sample.length;

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