diff options
author | Stepan Moskovchenko <stevenm@rockbox.org> | 2006-10-03 21:09:47 +0000 |
---|---|---|
committer | Stepan Moskovchenko <stevenm@rockbox.org> | 2006-10-03 21:09:47 +0000 |
commit | c84461fb8f9404b2b32d90a649b63b669e1a6bb8 (patch) | |
tree | 4b9e5b78b1abb5bfc6eccb61a86236427cb32bf4 /apps/plugins/midi/synth.c | |
parent | f5a356989980aeabdfb6446d65d54cf8ec7928ab (diff) | |
download | rockbox-c84461fb8f9404b2b32d90a649b63b669e1a6bb8.tar.gz rockbox-c84461fb8f9404b2b32d90a649b63b669e1a6bb8.zip |
More adsr related nonsense, argh! Fix adsr related problem on some notes being stopped instead of
looped. Ramping code still not quite right, but dont want to lose this.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11117 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/midi/synth.c')
-rw-r--r-- | apps/plugins/midi/synth.c | 50 |
1 files changed, 35 insertions, 15 deletions
diff --git a/apps/plugins/midi/synth.c b/apps/plugins/midi/synth.c index d844cc05ad..95bb88f8c6 100644 --- a/apps/plugins/midi/synth.c +++ b/apps/plugins/midi/synth.c | |||
@@ -238,7 +238,7 @@ void setPoint(struct SynthObject * so, int pt) | |||
238 | * | 238 | * |
239 | * Or just move the 1 up one line to optimize a tiny bit. | 239 | * Or just move the 1 up one line to optimize a tiny bit. |
240 | */ | 240 | */ |
241 | /* so->curRate = so->curRate << 1;*/ | 241 | so->curRate = so->curRate << 1; |
242 | 242 | ||
243 | 243 | ||
244 | so->targetOffset = so->wf->envOffset[pt]<<(20); | 244 | so->targetOffset = so->wf->envOffset[pt]<<(20); |
@@ -251,9 +251,9 @@ inline void stopVoice(struct SynthObject * so) | |||
251 | { | 251 | { |
252 | if(so->state == STATE_RAMPDOWN) | 252 | if(so->state == STATE_RAMPDOWN) |
253 | return; | 253 | return; |
254 | // so->isUsed = 0; | ||
254 | so->state = STATE_RAMPDOWN; | 255 | so->state = STATE_RAMPDOWN; |
255 | so->decay = 0; | 256 | so->decay = 0; |
256 | |||
257 | } | 257 | } |
258 | 258 | ||
259 | signed short int synthVoice(struct SynthObject * so) | 259 | signed short int synthVoice(struct SynthObject * so) |
@@ -277,7 +277,7 @@ signed short int synthVoice(struct SynthObject * so) | |||
277 | if(so->decay < 10 && so->decay > -10) | 277 | if(so->decay < 10 && so->decay > -10) |
278 | so->isUsed = 0; | 278 | so->isUsed = 0; |
279 | 279 | ||
280 | return so->decay*so->volscale>>14; | 280 | return so->decay; |
281 | } | 281 | } |
282 | } else /* OK to advance voice */ | 282 | } else /* OK to advance voice */ |
283 | { | 283 | { |
@@ -287,13 +287,7 @@ signed short int synthVoice(struct SynthObject * so) | |||
287 | 287 | ||
288 | cpShifted = so->cp >> FRACTSIZE; //Was 10 | 288 | cpShifted = so->cp >> FRACTSIZE; //Was 10 |
289 | 289 | ||
290 | /* Have we overrun? */ | 290 | |
291 | if( (cpShifted >= (wf->numSamples-1))) | ||
292 | { | ||
293 | so->cp -= so->delta; | ||
294 | cpShifted = so->cp >> FRACTSIZE; | ||
295 | stopVoice(so); | ||
296 | } | ||
297 | 291 | ||
298 | s2 = getSample((cpShifted)+1, wf); | 292 | s2 = getSample((cpShifted)+1, wf); |
299 | 293 | ||
@@ -307,8 +301,8 @@ signed short int synthVoice(struct SynthObject * so) | |||
307 | s2=getSample((cpShifted), wf); | 301 | s2=getSample((cpShifted), wf); |
308 | } | 302 | } |
309 | else | 303 | else |
310 | { | 304 | { |
311 | so->delta = -so->delta; | 305 | so->delta = -so->delta; |
312 | so->loopDir = LOOPDIR_FORWARD; | 306 | so->loopDir = LOOPDIR_FORWARD; |
313 | } | 307 | } |
314 | } | 308 | } |
@@ -329,6 +323,20 @@ signed short int synthVoice(struct SynthObject * so) | |||
329 | } | 323 | } |
330 | } | 324 | } |
331 | 325 | ||
326 | |||
327 | /* Have we overrun? */ | ||
328 | if( (cpShifted >= (wf->numSamples-1))) | ||
329 | { | ||
330 | so->cp -= so->delta; | ||
331 | |||
332 | cpShifted = so->cp >> FRACTSIZE; | ||
333 | s2 = getSample((cpShifted)+1, wf); | ||
334 | // if((wf->mode & (28))) | ||
335 | // printf("OV1 (loop 2)"); | ||
336 | stopVoice(so); | ||
337 | } | ||
338 | |||
339 | |||
332 | /* Better, working, linear interpolation */ | 340 | /* Better, working, linear interpolation */ |
333 | s1=getSample((cpShifted), wf); | 341 | s1=getSample((cpShifted), wf); |
334 | 342 | ||
@@ -337,8 +345,10 @@ signed short int synthVoice(struct SynthObject * so) | |||
337 | /* ADSR COMMENT WOULD GO FROM HERE.........*/ | 345 | /* ADSR COMMENT WOULD GO FROM HERE.........*/ |
338 | 346 | ||
339 | if(so->curRate == 0) | 347 | if(so->curRate == 0) |
348 | { | ||
340 | stopVoice(so); | 349 | stopVoice(so); |
341 | 350 | // printf("OV2"); | |
351 | } | ||
342 | 352 | ||
343 | if(so->ch != 9 && so->state != STATE_RAMPDOWN) /* Stupid ADSR code... and don't do ADSR for drums */ | 353 | if(so->ch != 9 && so->state != STATE_RAMPDOWN) /* Stupid ADSR code... and don't do ADSR for drums */ |
344 | { | 354 | { |
@@ -350,7 +360,10 @@ signed short int synthVoice(struct SynthObject * so) | |||
350 | if(so->curPoint != 5) | 360 | if(so->curPoint != 5) |
351 | setPoint(so, so->curPoint+1); | 361 | setPoint(so, so->curPoint+1); |
352 | else | 362 | else |
363 | { | ||
353 | stopVoice(so); | 364 | stopVoice(so); |
365 | // printf("OV3"); | ||
366 | } | ||
354 | } | 367 | } |
355 | } else | 368 | } else |
356 | { | 369 | { |
@@ -361,22 +374,29 @@ signed short int synthVoice(struct SynthObject * so) | |||
361 | if(so->curPoint != 5) | 374 | if(so->curPoint != 5) |
362 | setPoint(so, so->curPoint+1); | 375 | setPoint(so, so->curPoint+1); |
363 | else | 376 | else |
377 | { | ||
364 | stopVoice(so); | 378 | stopVoice(so); |
379 | // printf("OV4"); | ||
380 | } | ||
365 | 381 | ||
366 | } | 382 | } |
367 | } | 383 | } |
368 | } | 384 | } |
369 | 385 | ||
370 | if(so->curOffset < 0) | 386 | if(so->curOffset < 0) |
387 | { | ||
371 | stopVoice(so); | 388 | stopVoice(so); |
372 | 389 | // printf("OV5"); | |
390 | } | ||
373 | s = (s * (so->curOffset >> 22) >> 8); | 391 | s = (s * (so->curOffset >> 22) >> 8); |
374 | 392 | ||
375 | 393 | ||
376 | /* need to set ramp beginning */ | 394 | /* need to set ramp beginning */ |
377 | if(so->state == STATE_RAMPDOWN && so->decay == 0) | 395 | if(so->state == STATE_RAMPDOWN && so->decay == 0) |
378 | { | 396 | { |
379 | so->decay = s; | 397 | so->decay = s*so->volscale>>14; |
398 | if(so->decay == 0) | ||
399 | so->decay = 1; /* stupid junk.. */ | ||
380 | } | 400 | } |
381 | 401 | ||
382 | 402 | ||