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
74 float idx;74 float idx;
75 float inc;75 float inc;
76 int8_t dir;76 int8_t dir;
77 uint8_t flip;77 int8_t flip;
78 78
79 int32_t start;79 int32_t start;
80 int32_t end;80 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
120 p->idx = 0.f;120 p->idx = 0.f;
121 p->inc = 1.f;121 p->inc = 1.f;
122 p->dir = 1;122 p->dir = 1;
123 p->flip = 0;123 p->flip = 1;
124 124
125 p->mode = Normal;125 p->mode = Normal;
126 126
@@ -143,22 +143,30 @@ float tSamplePlayer_tick (tSamplePlayer* const p) · 16 unmodified lines
143 143
144 float* buff = p->samp->buff;144 float* buff = p->samp->buff;
145 145
146 int dir = p->dir * p->flip;
147
146 int idx = (int) p->idx;148 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 }
147 157
148 // Check dir (direction bit) to interpolate properly158 // Check dir (direction) to interpolate properly
149 if (p->dir > 0)159 if (dir > 0)
150 {160 {
151 // FORWARD161 // FORWARD
152 float alpha = p->idx - idx;
153
154 int i1 = idx-1;162 int i1 = idx-1;
155 int i3 = idx+1;163 int i3 = idx+1;
156 int i4 = idx+2;164 int i4 = idx+2;
157 165
158 if (i1 < p->start) i1 += p->len;166 if (i1 < start) i1 += p->len;
159 if (i3 > p->end) i3 -= p->len;167 if (i3 > end) i3 -= p->len;
160 if (i4 > p->end) i4 -= p->len;168 if (i4 > end) i4 -= p->len;
161 169
162 sample = LEAF_interpolate_hermite (buff[i1],170 sample = LEAF_interpolate_hermite (buff[i1],
163 buff[idx],171 buff[idx],
164 buff[i3],172 buff[i3],
@@ -168,16 +176,14 @@ float tSamplePlayer_tick (tSamplePlayer* const p) · 3 unmodified lines
168 else176 else
169 {177 {
170 // REVERSE178 // REVERSE
171 float alpha = 1.0f - (p->idx - idx);
172
173 int i1 = idx+1;179 int i1 = idx+1;
174 int i3 = idx-1;180 int i3 = idx-1;
175 int i4 = idx-2;181 int i4 = idx-2;
176 182
177 if (i1 > p->start) i1 -= p->len;183 if (i1 > end) i1 -= p->len;
178 if (i3 < p->end) i3 += p->len;184 if (i3 < start) i3 += p->len;
179 if (i4 < p->end) i4 += p->len;185 if (i4 < start) i4 += p->len;
180 186
181 sample = LEAF_interpolate_hermite (buff[i1],187 sample = LEAF_interpolate_hermite (buff[i1],
182 buff[idx],188 buff[idx],
183 buff[i3],189 buff[i3],
@@ -185,60 +191,33 @@ float tSamplePlayer_tick (tSamplePlayer* const p) · 1 unmodified line
185 alpha);191 alpha);
186 }192 }
187 193
188 194 p->idx += (dir * p->inc);
189 p->idx += (p->dir * p->inc);
190 195
191 if (p->mode != BackAndForth)196 if (p->mode != BackAndForth)
192 {197 {
193 // Check flip bit to change loop test198 // Check flip bit to change loop test
194 if (p->flip > 0)199 if (idx <= start)
195 {200 {
196 if (idx <= p->end)201 // -inc
197 {202 p->idx += (float)(p->len);
198 p->idx += (float)(p->len);203 p->cnt++;
199 p->cnt++;
200 }
201 else if (idx >= p->start)
202 {
203 p->idx -= (float)(p->len);
204 p->cnt++;
205 }
206 }204 }
207 else205 else if (idx >= end)
208 {206 {
209 if (idx <= p->start)207 // +inc
210 {208 p->idx -= (float)(p->len);
211 p->idx += (float)(p->len);209 p->cnt++;
212 p->cnt++;
213 }
214 else if (idx >= p->end)
215 {
216 p->idx -= (float)(p->len);
217 p->cnt++;
218 }
219 }210 }
211
220 }212 }
221 else // BackAndForth213 else // BackAndForth
222 {214 {
223 if (p->flip > 0)215 if ((idx < start) || (idx > end))
224 {216 {
225 if ((idx < p->start) || (idx > p->end))217 p->dir = -p->dir;
226 {218 p->idx += (2*p->inc);
227 p->dir = -p->dir;219 p->cnt++;
228 p->idx += (2*p->inc);
229 p->cnt++;
230 }
231 }220 }
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
242 }221 }
243 222
244 223
@@ -270,13 +249,11 @@ static void handleStartEndChange(tSamplePlayer* const p) · 25 unmodified lines
270{249{
271 if (p->start > p->end)250 if (p->start > p->end)
272 {251 {
273 p->dir = -1;252 p->flip = -1;
274 p->flip = 1;
275 }253 }
276 else254 else
277 {255 {
278 p->dir = 1;256 p->flip = 1;
279 p->flip = 0;
280 }257 }
281}258}
282 259
LEAF_JUCEPlugin/Source/MyTest.cpp+4−2
@@ -42,7 +42,7 @@ float LEAFTest_tick (float input) · 41 unmodified lines
42 42
43 timer++;43 timer++;
44 44
45 if (timer >= leaf.sampleRate * 4)45 if (player.active == 0 && timer >= leaf.sampleRate * 4)
46 {46 {
47 tSamplePlayer_play(&player);47 tSamplePlayer_play(&player);
48 }48 }
@@ -55,7 +55,9 @@ void LEAFTest_block (void) · 6 unmodified lines
55{55{
56 float val = getSliderValue("rate");56 float val = getSliderValue("rate");
57 57
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));
59 61
60 val = getSliderValue("start");62 val = getSliderValue("start");
61 float start = val * sample.length;63 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