| @@ -126,6 +126,9 @@ void tSampler_init (tSampler* const p, tBuffer* s) · 125 unmodified lines |
| 126 | p->mode = Normal; | 126 | p->mode = Normal; |
| 127 | | 127 | |
| 128 | p->cfxlen = 300; // default 300 sample crossfade | 128 | p->cfxlen = 300; // default 300 sample crossfade |
| | 129 | |
| | 130 | tRamp_init(&p->gain, 7.0f, 1); |
| | 131 | tRamp_setVal(&p->gain, 0.f); |
| 129 | } | 132 | } |
| 130 | | 133 | |
| 131 | void tSampler_free (tSampler* const p) | 134 | void tSampler_free (tSampler* const p) |
| @@ -186,25 +189,27 @@ float tSampler_tick (tSampler* const p) · 54 unmodified lines |
| 186 | numsamps = (dir > 0) ? (end - idx) : (idx - start); | 189 | numsamps = (dir > 0) ? (end - idx) : (idx - start); |
| 187 | numsamps *= p->iinc; | 190 | numsamps *= p->iinc; |
| 188 | | 191 | |
| 189 | if (numsamps <= p->cfxlen) | 192 | if (p->mode == Loop) |
| 190 | { | 193 | { |
| 191 | // CROSSFADE SAMPLE | 194 | if (numsamps <= p->cfxlen) |
| 192 | float idxx = p->idx - p->len; | 195 | { |
| 193 | int cdx = (int)(idxx); | 196 | // CROSSFADE SAMPLE |
| 194 | | 197 | float idxx = p->idx - p->len; |
| 195 | i1 = cdx-1; | 198 | int cdx = (int)(idxx); |
| 196 | i3 = cdx+1; | 199 | |
| 197 | i4 = cdx+2; | 200 | i1 = cdx-1; |
| 198 | | 201 | i3 = cdx+1; |
| 199 | cfxsample = LEAF_interpolate_hermite (buff[i1], | 202 | i4 = cdx+2; |
| 200 | buff[cdx], | 203 | |
| 201 | buff[i3], | 204 | cfxsample = LEAF_interpolate_hermite (buff[i1], |
| 202 | buff[i4], | 205 | buff[cdx], |
| 203 | alpha); | 206 | buff[i3], |
| 204 | | 207 | buff[i4], |
| 205 | g2 = (float) (p->cfxlen - numsamps) / (float) p->cfxlen; | 208 | alpha); |
| | 209 | |
| | 210 | g2 = (float) (p->cfxlen - numsamps) / (float) p->cfxlen; |
| | 211 | } |
| 206 | } | 212 | } |
| 207 | else g2 = 0.f; | | |
| 208 | } | 213 | } |
| 209 | else | 214 | else |
| 210 | { | 215 | { |
| @@ -221,31 +226,37 @@ float tSampler_tick (tSampler* const p) · 10 unmodified lines |
| 221 | | 226 | |
| 222 | numsamps = (idx - start) / p->inc; | 227 | numsamps = (idx - start) / p->inc; |
| 223 | | 228 | |
| 224 | if (numsamps <= p->cfxlen) | 229 | if (p->mode == Loop) |
| 225 | { | 230 | { |
| 226 | // CROSSFADE SAMPLE | 231 | if (numsamps <= p->cfxlen) |
| 227 | float idxx = p->idx + p->len + 1.f; | 232 | { |
| 228 | int cdx = (int)(idxx); | 233 | // CROSSFADE SAMPLE |
| 229 | alpha = idxx - cdx; | 234 | float idxx = p->idx + p->len + 1.f; |
| 230 | | 235 | int cdx = (int)(idxx); |
| 231 | i1 = cdx+1; | 236 | alpha = idxx - cdx; |
| 232 | i3 = cdx-1; | 237 | |
| 233 | i4 = cdx-2; | 238 | i1 = cdx+1; |
| 234 | | 239 | i3 = cdx-1; |
| 235 | cfxsample = LEAF_interpolate_hermite (buff[i1], | 240 | i4 = cdx-2; |
| 236 | buff[cdx], | 241 | |
| 237 | buff[i3], | 242 | cfxsample = LEAF_interpolate_hermite (buff[i1], |
| 238 | buff[i4], | 243 | buff[cdx], |
| 239 | 1.f-alpha); | 244 | buff[i3], |
| 240 | | 245 | buff[i4], |
| 241 | g2 = (float) (p->cfxlen - numsamps) / (float) p->cfxlen; | 246 | 1.f-alpha); |
| | 247 | |
| | 248 | g2 = (float) (p->cfxlen - numsamps) / (float) p->cfxlen; |
| | 249 | } |
| 242 | } | 250 | } |
| 243 | else g2 = 0.f; | | |
| 244 | } | 251 | } |
| 245 | | 252 | |
| 246 | p->idx += (dir * p->inc); | 253 | p->idx += (dir * p->inc); |
| 247 | | 254 | |
| 248 | if (p->mode != BackAndForth ) // == Normal or Loop | 255 | if (p->mode == Normal) |
| | 256 | { |
| | 257 | if (numsamps == 0) p->active = 0; |
| | 258 | } |
| | 259 | else if (p->mode == Loop ) // == Normal or Loop |
| 249 | { | 260 | { |
| 250 | if (idx <= start) | 261 | if (idx <= start) |
| 251 | { | 262 | { |
| @@ -261,12 +272,24 @@ float tSampler_tick (tSampler* const p) · 9 unmodified lines |
| 261 | if ((idx <= start) || (idx >= end)) | 272 | if ((idx <= start) || (idx >= end)) |
| 262 | { | 273 | { |
| 263 | p->dir = -p->dir; | 274 | p->dir = -p->dir; |
| | 275 | p->idx += (p->dir * p->flip * p->inc); |
| 264 | } | 276 | } |
| 265 | } | 277 | } |
| 266 | | 278 | |
| 267 | g1 = 1.f - g2; | 279 | g1 = 1.f - g2; |
| | 280 | |
| 268 | sample = sample * g1 + cfxsample * g2; | 281 | sample = sample * g1 + cfxsample * g2; |
| 269 | | 282 | |
| | 283 | sample = sample * tRamp_tick(&p->gain); |
| | 284 | |
| | 285 | if (p->active < 0) |
| | 286 | { |
| | 287 | if (tRamp_sample(&p->gain) <= 0.00001f) |
| | 288 | { |
| | 289 | p->active = 0; |
| | 290 | } |
| | 291 | } |
| | 292 | |
| 270 | return sample; | 293 | return sample; |
| 271 | } | 294 | } |
| 272 | | 295 | |
| @@ -303,11 +326,16 @@ void tSampler_play (tSampler* const p) · 30 unmodified lines |
| 303 | if (p->flip > 0) p->idx = p->end; | 326 | if (p->flip > 0) p->idx = p->end; |
| 304 | else p->idx = p->start; | 327 | else p->idx = p->start; |
| 305 | } | 328 | } |
| | 329 | |
| | 330 | tRamp_setVal(&p->gain, 0.f); |
| | 331 | tRamp_setDest(&p->gain, 1.f); |
| 306 | } | 332 | } |
| 307 | | 333 | |
| 308 | void tSampler_stop (tSampler* const p) | 334 | void tSampler_stop (tSampler* const p) |
| 309 | { | 335 | { |
| 310 | p->active = 0; | 336 | p->active = -1; |
| | 337 | |
| | 338 | tRamp_setDest(&p->gain, 0.f); |
| 311 | } | 339 | } |
| 312 | | 340 | |
| 313 | static void handleStartEndChange(tSampler* const p) | 341 | static void handleStartEndChange(tSampler* const p) |