| @@ -19,6 +19,7 @@ · 18 unmodified lines |
| 19 | #include "../Inc/leaf-sampling.h" | 19 | #include "../Inc/leaf-sampling.h" |
| 20 | #include "../leaf.h" | 20 | #include "../leaf.h" |
| 21 | | 21 | |
| | 22 | |
| 22 | #endif | 23 | #endif |
| 23 | | 24 | |
| 24 | //============================================================================== | 25 | //============================================================================== |
| @@ -188,27 +189,60 @@ float tSampler_tick (tSampler* const sp) · 163 unmodified lines |
| 188 | _tSampler* p = *sp; | 189 | _tSampler* p = *sp; |
| 189 | | 190 | |
| 190 | if (p->active == 0) return 0.f; | 191 | if (p->active == 0) return 0.f; |
| 191 | | 192 | |
| 192 | if ((p->inc == 0.0f) || (p->len < 4)) | 193 | if ((p->inc == 0.0f) || (p->len == 0)) |
| 193 | { | 194 | { |
| 194 | updateStartEnd(sp); | | |
| 195 | return p->last; | 195 | return p->last; |
| 196 | } | 196 | } |
| 197 | | 197 | |
| 198 | // attemptStartEndChange(sp); | 198 | attemptStartEndChange(sp); |
| 199 | | 199 | |
| 200 | float sample = 0.f; | 200 | float sample = 0.f; |
| 201 | float cfxsample = 0.f; | 201 | float cfxsample = 0.f; |
| 202 | float numticks; | 202 | float numticks; |
| 203 | float g1 = 1.f, g2 = 0.f; | 203 | float g1 = 1.f, g2 = 0.f; |
| 204 | | 204 | |
| 205 | float* buff = p->samp->buff; | 205 | float* buff = p->samp->buff; |
| 206 | | 206 | |
| 207 | int dir = p->bnf * p->dir * p->flip; | 207 | int dir = p->bnf * p->dir * p->flip; |
| 208 | | 208 | |
| 209 | int idx, revidx; | 209 | int idx, revidx; |
| 210 | float alpha, revalpha; | 210 | float alpha, revalpha; |
| 211 | | 211 | |
| | 212 | int32_t start = p->start, end = p->end; |
| | 213 | if (p->flip < 0) |
| | 214 | { |
| | 215 | start = p->end; |
| | 216 | end = p->start; |
| | 217 | } |
| | 218 | if (p->mode == PlayLoop) |
| | 219 | { |
| | 220 | |
| | 221 | while((int)p->idx < start) |
| | 222 | { |
| | 223 | p->idx += (float)(p->len); |
| | 224 | } |
| | 225 | while((int)p->idx > end) |
| | 226 | { |
| | 227 | |
| | 228 | p->idx -= (float)(p->len); |
| | 229 | } |
| | 230 | } |
| | 231 | else // == PlayBackAndForth |
| | 232 | { |
| | 233 | if (p->idx < start) |
| | 234 | { |
| | 235 | p->bnf = -p->bnf; |
| | 236 | p->idx = start; |
| | 237 | } |
| | 238 | else if (p->idx > end) |
| | 239 | { |
| | 240 | p->bnf = -p->bnf; |
| | 241 | p->idx = end; |
| | 242 | } |
| | 243 | } |
| | 244 | |
| | 245 | |
| 212 | | 246 | |
| 213 | idx = (int) p->idx; | 247 | idx = (int) p->idx; |
| 214 | alpha = p->idx - idx; | 248 | alpha = p->idx - idx; |
| @@ -217,157 +251,151 @@ float tSampler_tick (tSampler* const sp) · 2 unmodified lines |
| 217 | revalpha = 1.f - alpha; | 251 | revalpha = 1.f - alpha; |
| 218 | | 252 | |
| 219 | | 253 | |
| 220 | int32_t start = p->start, end = p->end; | 254 | |
| 221 | if (p->flip < 0) | 255 | |
| 222 | { | | |
| 223 | start = p->end; | | |
| 224 | end = p->start; | | |
| 225 | } | | |
| 226 | | 256 | |
| 227 | uint32_t cfxlen = p->cfxlen; | 257 | uint32_t cfxlen = p->cfxlen; |
| 228 | if (p->len < cfxlen) cfxlen = 0;//p->len; | 258 | if (p->len < cfxlen) cfxlen = p->len * 0.25f;//p->len; |
| 229 | | 259 | |
| 230 | int length = p->samp->length; | 260 | int length = p->samp->length; |
| 231 | | 261 | |
| 232 | // Check dir (direction) to interpolate properly | | |
| 233 | if (dir > 0) | 262 | if (dir > 0) |
| | 263 | { // num samples (hopping the increment size) to end of loop |
| | 264 | numticks = (end-idx) * p->iinc; |
| | 265 | } |
| | 266 | else |
| 234 | { | 267 | { |
| 235 | // FORWARD NORMAL SAMPLE | 268 | numticks = (revidx-start) * p->iinc; |
| 236 | int i1 = ((idx-1) < 0) ? 0 : idx-1; | | |
| 237 | int i3 = ((idx+1) >= length) ? (idx) : (idx+1); | | |
| 238 | int i4 = ((idx+2) >= length) ? (length-1) : (idx+2); | | |
| 239 | | | |
| 240 | sample = LEAF_interpolate_hermite (buff[i1], | | |
| 241 | buff[idx], | | |
| 242 | buff[i3], | | |
| 243 | buff[i4], | | |
| 244 | alpha); | | |
| 245 | | | |
| 246 | // num samples to end of loop | | |
| 247 | numticks = (end-idx) * p->iinc; | | |
| 248 | // if (numticks > cfxlen) | | |
| 249 | // { | | |
| 250 | // updateStartEnd(sp); | | |
| 251 | // start = p->start; | | |
| 252 | // end = p->end; | | |
| 253 | // if (p->flip < 0) | | |
| 254 | // { | | |
| 255 | // start = p->end; | | |
| 256 | // end = p->start; | | |
| 257 | // } | | |
| 258 | // numticks = (end-idx) * p->iinc; | | |
| 259 | // } | | |
| 260 | //numsamps = (dir > 0) ? (end - idx) : (idx - start); | | |
| 261 | //numsamps *= p->iinc; | | |
| 262 | | | |
| 263 | if (p->mode == PlayLoop) | | |
| 264 | { | | |
| 265 | if (numticks <= (float) cfxlen) | | |
| 266 | { | | |
| 267 | // CROSSFADE SAMPLE | | |
| 268 | int cdx = start - numticks * p->inc; | | |
| 269 | if (cdx < 1) | | |
| 270 | { | | |
| 271 | cdx = -cdx; | | |
| 272 | | | |
| 273 | i1 = ((cdx+1) >= length) ? (length-1) : cdx+1; | | |
| 274 | i3 = ((cdx-1) < 0) ? cdx : (cdx-1); | | |
| 275 | i4 = ((cdx-2) < 0) ? 0 : (cdx-2); | | |
| 276 | | | |
| 277 | cfxsample = LEAF_interpolate_hermite (buff[i1], | | |
| 278 | buff[cdx], | | |
| 279 | buff[i3], | | |
| 280 | buff[i4], | | |
| 281 | revalpha); | | |
| 282 | } | | |
| 283 | else | | |
| 284 | { | | |
| 285 | i1 = ((cdx-1) < 0) ? 0 : cdx-1; | | |
| 286 | i3 = ((cdx+1) >= length) ? (cdx) : (cdx+1); | | |
| 287 | i4 = ((cdx+2) >= length) ? (length-1) : (cdx+2); | | |
| 288 | | | |
| 289 | cfxsample = LEAF_interpolate_hermite (buff[i1], | | |
| 290 | buff[cdx], | | |
| 291 | buff[i3], | | |
| 292 | buff[i4], | | |
| 293 | alpha); | | |
| 294 | } | | |
| 295 | g2 = (float) (cfxlen - numticks) / (float) cfxlen; | | |
| 296 | } | | |
| 297 | } | | |
| 298 | } | 269 | } |
| | 270 | |
| | 271 | |
| | 272 | |
| | 273 | if (cfxlen > 0) // necessary to avoid divide by zero, also a waste of computation otherwise |
| | 274 | { |
| | 275 | |
| | 276 | // Check dir (direction) to interpolate properly |
| | 277 | if (dir > 0) |
| | 278 | { |
| | 279 | // FORWARD NORMAL SAMPLE |
| | 280 | int i1 = ((idx-1) < 0) ? 0 : idx-1; |
| | 281 | int i3 = ((idx+1) >= length) ? (idx) : (idx+1); |
| | 282 | int i4 = ((idx+2) >= length) ? (length-1) : (idx+2); |
| | 283 | |
| | 284 | sample = LEAF_interpolate_hermite (buff[i1], |
| | 285 | buff[idx], |
| | 286 | buff[i3], |
| | 287 | buff[i4], |
| | 288 | alpha); |
| | 289 | |
| | 290 | if (p->mode == PlayLoop) |
| | 291 | { |
| | 292 | |
| | 293 | |
| | 294 | |
| | 295 | if (numticks <= (float) cfxlen) |
| | 296 | { |
| | 297 | // CROSSFADE SAMPLE |
| | 298 | int cdx = start - (numticks * p->inc); |
| | 299 | if (cdx < 1) |
| | 300 | { |
| | 301 | cdx = -cdx; |
| | 302 | |
| | 303 | i1 = ((cdx+1) >= length) ? (length-1) : cdx+1; |
| | 304 | i3 = ((cdx-1) < 0) ? cdx : (cdx-1); |
| | 305 | i4 = ((cdx-2) < 0) ? 0 : (cdx-2); |
| | 306 | |
| | 307 | cfxsample = LEAF_interpolate_hermite_x (buff[i1], |
| | 308 | buff[cdx], |
| | 309 | buff[i3], |
| | 310 | buff[i4], |
| | 311 | revalpha); |
| | 312 | } |
| | 313 | else |
| | 314 | { |
| | 315 | i1 = ((cdx-1) < 0) ? 0 : cdx-1; |
| | 316 | i3 = ((cdx+1) >= length) ? (cdx) : (cdx+1); |
| | 317 | i4 = ((cdx+2) >= length) ? (length-1) : (cdx+2); |
| | 318 | |
| | 319 | cfxsample = LEAF_interpolate_hermite_x (buff[i1], |
| | 320 | buff[cdx], |
| | 321 | buff[i3], |
| | 322 | buff[i4], |
| | 323 | alpha); |
| | 324 | } |
| | 325 | |
| | 326 | g2 = (float) (cfxlen - numticks) / (float) cfxlen; |
| | 327 | |
| | 328 | } |
| | 329 | |
| | 330 | } |
| | 331 | |
| | 332 | } |
| | 333 | else |
| | 334 | { |
| | 335 | // REVERSE |
| | 336 | int i1 = ((revidx+1) >= length) ? (length-1) : revidx+1; |
| | 337 | int i3 = ((revidx-1) < 0) ? revidx : (revidx-1); |
| | 338 | int i4 = ((revidx-2) < 0) ? 0 : (revidx-2); |
| | 339 | |
| | 340 | sample = LEAF_interpolate_hermite_x (buff[i1], |
| | 341 | buff[revidx], |
| | 342 | buff[i3], |
| | 343 | buff[i4], |
| | 344 | revalpha); |
| | 345 | |
| | 346 | |
| | 347 | |
| | 348 | |
| | 349 | if (p->mode == PlayLoop) |
| | 350 | { |
| | 351 | if (numticks <= (float) cfxlen) |
| | 352 | { |
| | 353 | // CROSSFADE SAMPLE |
| | 354 | int cdx = end + (numticks * p->inc); |
| | 355 | if (cdx > p->samp->length - 2) |
| | 356 | { |
| | 357 | cdx = end - (numticks * p->inc); |
| | 358 | |
| | 359 | i1 = ((cdx-1) < 0) ? 0 : cdx-1; |
| | 360 | i3 = ((cdx+1) >= length) ? (cdx) : (cdx+1); |
| | 361 | i4 = ((cdx+2) >= length) ? (length-1) : (cdx+2); |
| | 362 | |
| | 363 | cfxsample = LEAF_interpolate_hermite_x (buff[i1], |
| | 364 | buff[cdx], |
| | 365 | buff[i3], |
| | 366 | buff[i4], |
| | 367 | revalpha); |
| | 368 | } |
| | 369 | else |
| | 370 | { |
| | 371 | i1 = ((cdx+1) >= length) ? (length-1) : cdx+1; |
| | 372 | i3 = ((cdx-1) < 0) ? cdx : (cdx-1); |
| | 373 | i4 = ((cdx-2) < 0) ? 0 : (cdx-2); |
| | 374 | |
| | 375 | cfxsample = LEAF_interpolate_hermite_x (buff[i1], |
| | 376 | buff[cdx], |
| | 377 | buff[i3], |
| | 378 | buff[i4], |
| | 379 | alpha); |
| | 380 | } |
| | 381 | g2 = (float) (cfxlen - numticks) / (float) cfxlen; |
| | 382 | } |
| | 383 | } |
| | 384 | } |
| | 385 | } |
| 299 | else | 386 | else |
| 300 | { | 387 | { |
| 301 | // REVERSE | 388 | g2 = 0.0f; |
| 302 | int i1 = ((revidx+1) >= length) ? (length-1) : revidx+1; | | |
| 303 | int i3 = ((revidx-1) < 0) ? revidx : (revidx-1); | | |
| 304 | int i4 = ((revidx-2) < 0) ? 0 : (revidx-2); | | |
| 305 | | | |
| 306 | sample = LEAF_interpolate_hermite (buff[i1], | | |
| 307 | buff[revidx], | | |
| 308 | buff[i3], | | |
| 309 | buff[i4], | | |
| 310 | revalpha); | | |
| 311 | | | |
| 312 | numticks = (revidx-start) * p->iinc; | | |
| 313 | | | |
| 314 | // still get clicks i think because updating start/end can put us in the middle of a crossfade | | |
| 315 | // if (numticks > cfxlen) | | |
| 316 | // { | | |
| 317 | // updateStartEnd(sp); | | |
| 318 | // start = p->start; | | |
| 319 | // end = p->end; | | |
| 320 | // if (p->flip < 0) | | |
| 321 | // { | | |
| 322 | // start = p->end; | | |
| 323 | // end = p->start; | | |
| 324 | // } | | |
| 325 | // numticks = (revidx-start) * p->iinc; | | |
| 326 | // } | | |
| 327 | | | |
| 328 | if (p->mode == PlayLoop) | | |
| 329 | { | | |
| 330 | if (numticks <= (float) cfxlen) | | |
| 331 | { | | |
| 332 | // CROSSFADE SAMPLE | | |
| 333 | int cdx = end + numticks * p->inc; | | |
| 334 | if (cdx > p->samp->length - 2) | | |
| 335 | { | | |
| 336 | cdx = end - numticks * p->inc; | | |
| 337 | | | |
| 338 | i1 = ((cdx-1) < 0) ? 0 : cdx-1; | | |
| 339 | i3 = ((cdx+1) >= length) ? (cdx) : (cdx+1); | | |
| 340 | i4 = ((cdx+2) >= length) ? (length-1) : (cdx+2); | | |
| 341 | | | |
| 342 | cfxsample = LEAF_interpolate_hermite (buff[i1], | | |
| 343 | buff[cdx], | | |
| 344 | buff[i3], | | |
| 345 | buff[i4], | | |
| 346 | alpha); | | |
| 347 | } | | |
| 348 | else | | |
| 349 | { | | |
| 350 | i1 = ((cdx+1) >= length) ? (length-1) : cdx+1; | | |
| 351 | i3 = ((cdx-1) < 0) ? cdx : (cdx-1); | | |
| 352 | i4 = ((cdx-2) < 0) ? 0 : (cdx-2); | | |
| 353 | | | |
| 354 | cfxsample = LEAF_interpolate_hermite (buff[i1], | | |
| 355 | buff[cdx], | | |
| 356 | buff[i3], | | |
| 357 | buff[i4], | | |
| 358 | revalpha); | | |
| 359 | } | | |
| 360 | g2 = (float) (cfxlen - numticks) / (float) cfxlen; | | |
| 361 | } | | |
| 362 | } | | |
| 363 | } | 389 | } |
| 364 | | 390 | |
| 365 | | 391 | |
| 366 | float inc = fmod(p->inc, p->len); | 392 | float inc = fmod(p->inc, p->len); |
| 367 | p->idx += (dir * inc); | 393 | p->idx += (dir * inc); |
| 368 | | 394 | |
| | 395 | |
| | 396 | |
| 369 | // attemptStartEndChange(sp); | 397 | // attemptStartEndChange(sp); |
| 370 | | 398 | |
| 371 | if (p->mode == PlayNormal) | 399 | if (p->mode == PlayNormal) |
| 372 | { | 400 | { |
| 373 | if (numticks < (0.007f * leaf.sampleRate)) | 401 | if (numticks < (0.007f * leaf.sampleRate)) |
| @@ -376,36 +404,7 @@ float tSampler_tick (tSampler* const sp) · 2 unmodified lines |
| 376 | p->active = -1; | 404 | p->active = -1; |
| 377 | } | 405 | } |
| 378 | } | 406 | } |
| 379 | else if (p->mode == PlayLoop) | 407 | |
| 380 | { | | |
| 381 | // mike's suggestion: make sure idx is within bounds of start and end (instead of targetstart/targetend stuff) | | |
| 382 | if (idx < start) | | |
| 383 | { | | |
| 384 | updateStartEnd(sp); | | |
| 385 | p->idx += (float)(p->len); | | |
| 386 | } | | |
| 387 | else if (idx > end) | | |
| 388 | { | | |
| 389 | updateStartEnd(sp); | | |
| 390 | p->idx -= (float)(p->len); | | |
| 391 | } | | |
| 392 | } | | |
| 393 | else // == PlayBackAndForth | | |
| 394 | { | | |
| 395 | if (p->idx < start) | | |
| 396 | { | | |
| 397 | updateStartEnd(sp); | | |
| 398 | p->bnf = -p->bnf; | | |
| 399 | p->idx = start; | | |
| 400 | } | | |
| 401 | else if (p->idx > end) | | |
| 402 | { | | |
| 403 | updateStartEnd(sp); | | |
| 404 | p->bnf = -p->bnf; | | |
| 405 | p->idx = end; | | |
| 406 | } | | |
| 407 | } | | |
| 408 | | | |
| 409 | g1 = 1.f - g2; | 408 | g1 = 1.f - g2; |
| 410 | | 409 | |
| 411 | sample = sample * g1 + cfxsample * g2; | 410 | sample = sample * g1 + cfxsample * g2; |
| @@ -440,9 +439,12 @@ float tSampler_tick (tSampler* const sp) · 28 unmodified lines |
| 440 | | 439 | |
| 441 | } | 440 | } |
| 442 | } | 441 | } |
| 443 | | 442 | |
| | 443 | |
| 444 | p->last = sample; | 444 | p->last = sample; |
| 445 | | 445 | |
| | 446 | |
| | 447 | |
| 446 | return p->last; | 448 | return p->last; |
| 447 | } | 449 | } |
| 448 | | 450 | |
| @@ -458,7 +460,7 @@ void tSampler_setCrossfadeLength (tSampler* const sp, uint32_t length) · 9 unmodified lines |
| 458 | | 460 | |
| 459 | uint32_t cfxlen = LEAF_clip(0, length, 1000); | 461 | uint32_t cfxlen = LEAF_clip(0, length, 1000); |
| 460 | | 462 | |
| 461 | //if (cfxlen > p->len) cfxlen = p->len * 0.25f; | 463 | if (cfxlen > (p->len * 0.25f)) cfxlen = p->len * 0.25f; |
| 462 | | 464 | |
| 463 | p->cfxlen = cfxlen; | 465 | p->cfxlen = cfxlen; |
| 464 | } | 466 | } |
| @@ -491,6 +493,7 @@ void tSampler_play (tSampler* const sp) · 26 unmodified lines |
| 491 | if (p->flip > 0) p->idx = p->end; | 493 | if (p->flip > 0) p->idx = p->end; |
| 492 | else p->idx = p->start; | 494 | else p->idx = p->start; |
| 493 | } | 495 | } |
| | 496 | handleStartEndChange(&p); |
| 494 | } | 497 | } |
| 495 | } | 498 | } |
| 496 | | 499 | |
| @@ -508,8 +511,8 @@ static void handleStartEndChange(tSampler* const sp) · 11 unmodified lines |
| 508 | _tSampler* p = *sp; | 511 | _tSampler* p = *sp; |
| 509 | | 512 | |
| 510 | p->len = abs(p->end - p->start); | 513 | p->len = abs(p->end - p->start); |
| 511 | | 514 | |
| 512 | //if (p->len < p->cfxlen) p->cfxlen = p->len * 0.9f; | 515 | if (p->len < (p->cfxlen * 0.25f)) p->cfxlen = p->len * 0.25f; |
| 513 | | 516 | |
| 514 | if (p->start > p->end) | 517 | if (p->start > p->end) |
| 515 | { | 518 | { |
| @@ -539,77 +542,117 @@ static void attemptStartEndChange(tSampler* const sp) · 23 unmodified lines |
| 539 | static void updateStartEnd(tSampler* const sp) | 542 | static void updateStartEnd(tSampler* const sp) |
| 540 | { | 543 | { |
| 541 | _tSampler* p = *sp; | 544 | _tSampler* p = *sp; |
| | 545 | |
| | 546 | |
| | 547 | |
| 542 | if (p->targetstart >= 0) | 548 | if (p->targetstart >= 0) |
| 543 | { | 549 | { |
| 544 | p->start = p->targetstart; | 550 | if (p->targetstart != p->end) |
| 545 | handleStartEndChange(sp); | 551 | { |
| 546 | p->targetstart = -1; | 552 | p->start = p->targetstart; |
| | 553 | handleStartEndChange(sp); |
| | 554 | p->targetstart = -1; |
| | 555 | } |
| 547 | } | 556 | } |
| 548 | if (p->targetend >= 0) | 557 | if (p->targetend >= 0) |
| 549 | { | 558 | { |
| 550 | p->end = p->targetend; | 559 | if (p->targetend != p->start) |
| 551 | handleStartEndChange(sp); | 560 | { |
| 552 | p->targetend = -1; | 561 | p->end = p->targetend; |
| | 562 | handleStartEndChange(sp); |
| | 563 | p->targetend = -1; |
| | 564 | } |
| 553 | } | 565 | } |
| 554 | } | 566 | } |
| 555 | | 567 | |
| 556 | void tSampler_setStart (tSampler* const sp, int32_t start) | 568 | void tSampler_setStart (tSampler* const sp, int32_t start) |
| 557 | { | 569 | { |
| 558 | _tSampler* p = *sp; | 570 | _tSampler* p = *sp; |
| 559 | | 571 | |
| 560 | if (p->active) | 572 | int tempflip; |
| | 573 | if (start == p->end) |
| 561 | { | 574 | { |
| 562 | int dir = p->bnf * p->dir * p->flip; | 575 | return; |
| | 576 | } |
| | 577 | // if (p->active) |
| | 578 | { |
| | 579 | |
| | 580 | if (start > p->end) |
| | 581 | { |
| | 582 | tempflip = -1; |
| | 583 | } |
| | 584 | else |
| | 585 | { |
| | 586 | tempflip = 1; |
| | 587 | } |
| | 588 | |
| | 589 | int dir = p->bnf * p->dir * tempflip; |
| 563 | uint32_t cfxlen = (p->len < p->cfxlen) ? 0 : p->cfxlen; | 590 | uint32_t cfxlen = (p->len < p->cfxlen) ? 0 : p->cfxlen; |
| 564 | if (p->flip > 0 && dir > 0) // start is start and we're playing forward | 591 | if (tempflip > 0 && dir > 0) // start is start and we're playing forward |
| 565 | { | 592 | { |
| 566 | if ((start > p->idx) || (p->end-p->idx <= cfxlen)) // start given is after current index or we're in a crossfade | 593 | if (((start > p->idx) || (p->end-p->idx <= cfxlen)) && (start > p->end))// start given is after current index or we're in a crossfade |
| 567 | { | 594 | { |
| 568 | p->targetstart = start; | 595 | p->targetstart = start; |
| 569 | return; | 596 | return; |
| 570 | } | 597 | } |
| 571 | } | 598 | } |
| 572 | else if (p->flip < 0 && dir < 0) // start is end and we're playing in reverse | 599 | else if (tempflip < 0 && dir < 0) // start is end and we're playing in reverse |
| 573 | { | 600 | { |
| 574 | if ((start < p->idx) || (p->idx-p->end <= cfxlen)) // start given is before current index or we're in a crossfade | 601 | if (((start < p->idx) || (p->idx-p->end <= cfxlen)) && (start < p->end))// start given is before current index or we're in a crossfade |
| 575 | { | 602 | { |
| 576 | p->targetstart = start; | 603 | p->targetstart = start; |
| 577 | return; | 604 | return; |
| 578 | } | 605 | } |
| 579 | } | 606 | } |
| 580 | } | 607 | } |
| 581 | | 608 | |
| 582 | p->start = LEAF_clipInt(0, start, p->samp->length - 1); | 609 | p->start = LEAF_clipInt(0, start, p->samp->length - 1); |
| 583 | handleStartEndChange(sp); | 610 | handleStartEndChange(sp); |
| 584 | p->targetstart = -1; | 611 | p->targetstart = -1; |
| | 612 | |
| 585 | } | 613 | } |
| 586 | | 614 | |
| 587 | void tSampler_setEnd (tSampler* const sp, int32_t end) | 615 | void tSampler_setEnd (tSampler* const sp, int32_t end) |
| 588 | { | 616 | { |
| 589 | _tSampler* p = *sp; | 617 | _tSampler* p = *sp; |
| 590 | | 618 | |
| 591 | if (p->active) | 619 | int tempflip; |
| | 620 | |
| | 621 | if (end == p->start) |
| 592 | { | 622 | { |
| 593 | int dir = p->bnf * p->dir * p->flip; | 623 | return; |
| | 624 | } |
| | 625 | //if (p->active) |
| | 626 | { |
| | 627 | |
| | 628 | |
| | 629 | if (p->start > end) |
| | 630 | { |
| | 631 | tempflip = -1; |
| | 632 | } |
| | 633 | else |
| | 634 | { |
| | 635 | tempflip = 1; |
| | 636 | } |
| | 637 | int dir = p->bnf * p->dir * tempflip; |
| 594 | uint32_t cfxlen = (p->len < p->cfxlen) ? 0 : p->cfxlen; | 638 | uint32_t cfxlen = (p->len < p->cfxlen) ? 0 : p->cfxlen; |
| 595 | if (p->flip > 0 && dir < 0) // end is end and we're playing in reverse | 639 | if (tempflip > 0 && dir < 0) // end is end and we're playing in reverse |
| 596 | { | 640 | { |
| 597 | if ((end < p->idx) || (p->idx-p->start <= cfxlen)) // end given is before current index or we're in a crossfade | 641 | if (((end < p->idx) || (p->idx-p->start <= cfxlen)) && (end < p->start)) // end given is before current index or we're in a crossfade |
| 598 | { | 642 | { |
| 599 | p->targetend = end; | 643 | p->targetend = end; |
| 600 | return; | 644 | return; |
| 601 | } | 645 | } |
| 602 | } | 646 | } |
| 603 | else if (p->flip < 0 && dir > 0) // end is start and we're playing forward | 647 | else if (tempflip < 0 && dir > 0) // end is start and we're playing forward |
| 604 | { | 648 | { |
| 605 | if ((end > p->idx) || (p->start-p->idx <= cfxlen)) // end given is after current index or we're in a crossfade | 649 | if (((end > p->idx) || (p->start-p->idx <= cfxlen)) && (end > p->start)) // end given is after current index or we're in a crossfade |
| 606 | { | 650 | { |
| 607 | p->targetend = end; | 651 | p->targetend = end; |
| 608 | return; | 652 | return; |
| 609 | } | 653 | } |
| 610 | } | 654 | } |
| 611 | } | 655 | } |
| 612 | | | |
| 613 | p->end = LEAF_clipInt(0, end, (p->samp->length - 1)); | 656 | p->end = LEAF_clipInt(0, end, (p->samp->length - 1)); |
| 614 | handleStartEndChange(sp); | 657 | handleStartEndChange(sp); |
| 615 | p->targetend = -1; | 658 | p->targetend = -1; |
| @@ -628,8 +671,8 @@ void tSampler_setRate (tSampler* const sp, float rate) · 12 unmodified lines |
| 628 | { | 671 | { |
| 629 | p->dir = 1; | 672 | p->dir = 1; |
| 630 | } | 673 | } |
| 631 | | 674 | |
| 632 | p->inc = rate; //LEAF_clip(0.f, rate, 8.0f); any reason to clip this? | 675 | p->inc = rate; |
| 633 | p->iinc = 1.f / p->inc; | 676 | p->iinc = 1.f / p->inc; |
| 634 | } | 677 | } |
| 635 | | 678 | |