summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins')
-rw-r--r--apps/plugins/midi/synth.c55
1 files changed, 39 insertions, 16 deletions
diff --git a/apps/plugins/midi/synth.c b/apps/plugins/midi/synth.c
index 2ec263da60..1b7145a372 100644
--- a/apps/plugins/midi/synth.c
+++ b/apps/plugins/midi/synth.c
@@ -252,7 +252,7 @@ inline void stopVoice(struct SynthObject * so)
252 if(so->state == STATE_RAMPDOWN) 252 if(so->state == STATE_RAMPDOWN)
253 return; 253 return;
254 so->state = STATE_RAMPDOWN; 254 so->state = STATE_RAMPDOWN;
255 so->decay = 255; 255 so->decay = 0;
256 256
257} 257}
258 258
@@ -267,16 +267,41 @@ signed short int synthVoice(struct SynthObject * so)
267 wf = so->wf; 267 wf = so->wf;
268 268
269 269
270 if(so->state != STATE_RAMPDOWN) 270 /* Is voice being ramped? */
271 if(so->state == STATE_RAMPDOWN)
272 {
273 if(so->decay != 0) /* Ramp has been started */
274 {
275 so->decay = so->decay / 2;
276
277 if(so->decay < 10 && so->decay > -10)
278 so->isUsed = 0;
279
280 if(so->state == STATE_RAMPDOWN)
281 {
282 so->decay-=5;
283 if(so->decay < 5)
284 so->isUsed=0;
285 s = (s * so->decay) >> 8;
286 }
287
288
289 return so->decay*so->volscale>>14;
290 }
291 } else /* OK to advance voice */
271 { 292 {
272 so->cp += so->delta; 293 so->cp += so->delta;
273 } 294 }
274 295
296
275 cpShifted = so->cp >> FRACTSIZE; //Was 10 297 cpShifted = so->cp >> FRACTSIZE; //Was 10
276 298
277 if( (cpShifted > (wf->numSamples) && (so->state != STATE_RAMPDOWN))) 299 /* Have we overrun? */
300 if( (cpShifted >= (wf->numSamples-1)))
278 { 301 {
279 stopVoice(so); 302 so->cp -= so->delta;
303 cpShifted = so->cp >> FRACTSIZE;
304 stopVoice(so);
280 } 305 }
281 306
282 s2 = getSample((cpShifted)+1, wf); 307 s2 = getSample((cpShifted)+1, wf);
@@ -314,8 +339,8 @@ signed short int synthVoice(struct SynthObject * so)
314 } 339 }
315 340
316 /* Better, working, linear interpolation */ 341 /* Better, working, linear interpolation */
317 s1=getSample((cpShifted), wf); //\|/ Was 1023)) >> 10 342 s1=getSample((cpShifted), wf);
318// s = s1 + ((signed)((s2 - s1) * (so->cp & (1023)))>>10); //Was 10 343
319 s = s1 + ((signed)((s2 - s1) * (so->cp & ((1<<FRACTSIZE)-1)))>>FRACTSIZE); //Was 10 344 s = s1 + ((signed)((s2 - s1) * (so->cp & ((1<<FRACTSIZE)-1)))>>FRACTSIZE); //Was 10
320 345
321/* ADSR COMMENT WOULD GO FROM HERE.........*/ 346/* ADSR COMMENT WOULD GO FROM HERE.........*/
@@ -324,7 +349,7 @@ signed short int synthVoice(struct SynthObject * so)
324 stopVoice(so); 349 stopVoice(so);
325 350
326 351
327 if(so->ch != 9) /* Stupid ADSR code... and don't do ADSR for drums */ 352 if(so->ch != 9 && so->state != STATE_RAMPDOWN) /* Stupid ADSR code... and don't do ADSR for drums */
328 { 353 {
329 if(so->curOffset < so->targetOffset) 354 if(so->curOffset < so->targetOffset)
330 { 355 {
@@ -352,22 +377,20 @@ signed short int synthVoice(struct SynthObject * so)
352 } 377 }
353 378
354 if(so->curOffset < 0) 379 if(so->curOffset < 0)
355 so->isUsed=0; /* This is OK because offset faded it out already */ 380 stopVoice(so);
356
357 381
358 s = (s * (so->curOffset >> 22) >> 8); 382 s = (s * (so->curOffset >> 22) >> 8);
359 383
360/* ............. TO HERE */
361
362 384
363 if(so->state == STATE_RAMPDOWN) 385 /* need to set ramp beginning */
386 if(so->state == STATE_RAMPDOWN && so->decay == 0)
364 { 387 {
365 so->decay-=5; 388 so->decay = s;
366 if(so->decay < 5)
367 so->isUsed=0;
368 s = (s * so->decay) >> 8;
369 } 389 }
370 390
391
392/* ............. TO HERE */
393
371 /* Scaling by channel volume and note volume is done in sequencer.c */ 394 /* Scaling by channel volume and note volume is done in sequencer.c */
372 /* That saves us some multiplication and pointer operations */ 395 /* That saves us some multiplication and pointer operations */
373 return s*so->volscale>>14; 396 return s*so->volscale>>14;