diff options
Diffstat (limited to 'apps/plugins/midi/synth.c')
-rw-r--r-- | apps/plugins/midi/synth.c | 70 |
1 files changed, 34 insertions, 36 deletions
diff --git a/apps/plugins/midi/synth.c b/apps/plugins/midi/synth.c index ca59c76a8b..b2efce1f7d 100644 --- a/apps/plugins/midi/synth.c +++ b/apps/plugins/midi/synth.c | |||
@@ -51,7 +51,7 @@ void resetControllers() | |||
51 | voices[a].cp=0; | 51 | voices[a].cp=0; |
52 | voices[a].vol=0; | 52 | voices[a].vol=0; |
53 | voices[a].ch=0; | 53 | voices[a].ch=0; |
54 | voices[a].isUsed=0; | 54 | voices[a].isUsed=false; |
55 | voices[a].note=0; | 55 | voices[a].note=0; |
56 | } | 56 | } |
57 | 57 | ||
@@ -271,7 +271,6 @@ inline void stopVoice(struct SynthObject * so) | |||
271 | static inline void synthVoice(struct SynthObject * so, int32_t * out, unsigned int samples) | 271 | static inline void synthVoice(struct SynthObject * so, int32_t * out, unsigned int samples) |
272 | { | 272 | { |
273 | struct GWaveform * wf; | 273 | struct GWaveform * wf; |
274 | register int s; | ||
275 | register int s1; | 274 | register int s1; |
276 | register int s2; | 275 | register int s2; |
277 | 276 | ||
@@ -279,6 +278,9 @@ static inline void synthVoice(struct SynthObject * so, int32_t * out, unsigned i | |||
279 | 278 | ||
280 | wf = so->wf; | 279 | wf = so->wf; |
281 | 280 | ||
281 | const unsigned int pan = chPan[so->ch]; | ||
282 | const int volscale = so->volscale; | ||
283 | |||
282 | const int mode_mask24 = wf->mode&24; | 284 | const int mode_mask24 = wf->mode&24; |
283 | const int mode_mask28 = wf->mode&28; | 285 | const int mode_mask28 = wf->mode&28; |
284 | const int mode_mask_looprev = wf->mode&LOOP_REVERSE; | 286 | const int mode_mask_looprev = wf->mode&LOOP_REVERSE; |
@@ -289,9 +291,8 @@ static inline void synthVoice(struct SynthObject * so, int32_t * out, unsigned i | |||
289 | const unsigned int start_loop = wf->startLoop << FRACTSIZE; | 291 | const unsigned int start_loop = wf->startLoop << FRACTSIZE; |
290 | const int diff_loop = end_loop-start_loop; | 292 | const int diff_loop = end_loop-start_loop; |
291 | 293 | ||
292 | while(samples > 0) | 294 | while(samples-- > 0) |
293 | { | 295 | { |
294 | samples--; | ||
295 | /* Is voice being ramped? */ | 296 | /* Is voice being ramped? */ |
296 | if(so->state == STATE_RAMPDOWN) | 297 | if(so->state == STATE_RAMPDOWN) |
297 | { | 298 | { |
@@ -300,12 +301,12 @@ static inline void synthVoice(struct SynthObject * so, int32_t * out, unsigned i | |||
300 | so->decay = so->decay / 2; | 301 | so->decay = so->decay / 2; |
301 | 302 | ||
302 | if(so->decay < 10 && so->decay > -10) | 303 | if(so->decay < 10 && so->decay > -10) |
303 | so->isUsed = 0; | 304 | so->isUsed = false; |
304 | 305 | ||
305 | s1=so->decay; | 306 | s1=so->decay; |
306 | s2 = s1*chPan[so->ch]; | 307 | s2 = s1*pan; |
307 | s1 = (s1<<7) -s2; | 308 | s1 = (s1<<7) -s2; |
308 | *(out++)+=(((s1&0x7FFF80) << 9) | ((s2&0x7FFF80) >> 7)); | 309 | *(out++)+=((s1 << 9) & 0xFFFF0000) | ((s2 >> 7) &0xFFFF); |
309 | continue; | 310 | continue; |
310 | } | 311 | } |
311 | } else /* OK to advance voice */ | 312 | } else /* OK to advance voice */ |
@@ -315,23 +316,8 @@ static inline void synthVoice(struct SynthObject * so, int32_t * out, unsigned i | |||
315 | 316 | ||
316 | s2 = getSample((cp_temp >> FRACTSIZE)+1, wf); | 317 | s2 = getSample((cp_temp >> FRACTSIZE)+1, wf); |
317 | 318 | ||
318 | /* LOOP_REVERSE|LOOP_PINGPONG = 24 */ | 319 | if(mode_mask28 && cp_temp >= end_loop) |
319 | if(mode_mask24 && so->loopState == STATE_LOOPING && (cp_temp < start_loop)) | ||
320 | { | 320 | { |
321 | if(mode_mask_looprev) | ||
322 | { | ||
323 | cp_temp += diff_loop; | ||
324 | s2=getSample((cp_temp >> FRACTSIZE), wf); | ||
325 | } | ||
326 | else | ||
327 | { | ||
328 | so->delta = -so->delta; /* At this point cp_temp is wrong. We need to take a step */ | ||
329 | } | ||
330 | } | ||
331 | |||
332 | if(mode_mask28 && (cp_temp >= end_loop)) | ||
333 | { | ||
334 | so->loopState = STATE_LOOPING; | ||
335 | if(!mode_mask24) | 321 | if(!mode_mask24) |
336 | { | 322 | { |
337 | cp_temp -= diff_loop; | 323 | cp_temp -= diff_loop; |
@@ -340,6 +326,20 @@ static inline void synthVoice(struct SynthObject * so, int32_t * out, unsigned i | |||
340 | else | 326 | else |
341 | { | 327 | { |
342 | so->delta = -so->delta; | 328 | so->delta = -so->delta; |
329 | |||
330 | /* LOOP_REVERSE|LOOP_PINGPONG = 24 */ | ||
331 | if(cp_temp < start_loop) /* this appears to never be true in here */ | ||
332 | { | ||
333 | if(mode_mask_looprev) | ||
334 | { | ||
335 | cp_temp += diff_loop; | ||
336 | s2=getSample((cp_temp >> FRACTSIZE), wf); | ||
337 | } | ||
338 | else | ||
339 | { | ||
340 | so->delta = -so->delta; /* At this point cp_temp is wrong. We need to take a step */ | ||
341 | } | ||
342 | } | ||
343 | } | 343 | } |
344 | } | 344 | } |
345 | 345 | ||
@@ -354,12 +354,12 @@ static inline void synthVoice(struct SynthObject * so, int32_t * out, unsigned i | |||
354 | /* Better, working, linear interpolation */ | 354 | /* Better, working, linear interpolation */ |
355 | s1=getSample((cp_temp >> FRACTSIZE), wf); | 355 | s1=getSample((cp_temp >> FRACTSIZE), wf); |
356 | 356 | ||
357 | s = s1 + ((signed)((s2 - s1) * (cp_temp & ((1<<FRACTSIZE)-1)))>>FRACTSIZE); | 357 | s1 +=((signed)((s2 - s1) * (cp_temp & ((1<<FRACTSIZE)-1)))>>FRACTSIZE); |
358 | 358 | ||
359 | if(so->curRate == 0) | 359 | if(so->curRate == 0) |
360 | { | 360 | { |
361 | stopVoice(so); | 361 | stopVoice(so); |
362 | // so->isUsed = 0; | 362 | // so->isUsed = false; |
363 | 363 | ||
364 | } | 364 | } |
365 | 365 | ||
@@ -404,25 +404,23 @@ static inline void synthVoice(struct SynthObject * so, int32_t * out, unsigned i | |||
404 | stopVoice(so); | 404 | stopVoice(so); |
405 | } | 405 | } |
406 | 406 | ||
407 | s = (s * (so->curOffset >> 22) >> 8); | 407 | s1 = s1 * (so->curOffset >> 22) >> 8; |
408 | |||
409 | /* Scaling by channel volume and note volume is done in sequencer.c */ | ||
410 | /* That saves us some multiplication and pointer operations */ | ||
411 | s1 = s1 * volscale >> 14; | ||
408 | 412 | ||
409 | /* need to set ramp beginning */ | 413 | /* need to set ramp beginning */ |
410 | if(so->state == STATE_RAMPDOWN && so->decay == 0) | 414 | if(so->state == STATE_RAMPDOWN && so->decay == 0) |
411 | { | 415 | { |
412 | so->decay = s*so->volscale>>14; | 416 | so->decay = s1; |
413 | if(so->decay == 0) | 417 | if(so->decay == 0) |
414 | so->decay = 1; /* stupid junk.. */ | 418 | so->decay = 1; /* stupid junk.. */ |
415 | } | 419 | } |
416 | 420 | ||
417 | 421 | s2 = s1*pan; | |
418 | /* Scaling by channel volume and note volume is done in sequencer.c */ | ||
419 | /* That saves us some multiplication and pointer operations */ | ||
420 | s1=s*so->volscale>>14; | ||
421 | |||
422 | s2 = s1*chPan[so->ch]; | ||
423 | s1 = (s1<<7) - s2; | 422 | s1 = (s1<<7) - s2; |
424 | *(out++)+=(((s1&0x7FFF80) << 9) | ((s2&0x7FFF80) >> 7)); | 423 | *(out++)+=((s1 << 9) & 0xFFFF0000) | ((s2 >> 7) &0xFFFF); |
425 | |||
426 | } | 424 | } |
427 | 425 | ||
428 | so->cp=cp_temp; /* store this again */ | 426 | so->cp=cp_temp; /* store this again */ |
@@ -451,7 +449,7 @@ void synthSamples(int32_t *buf_ptr, unsigned int num_samples) | |||
451 | for(i=0; i < MAX_VOICES; i++) | 449 | for(i=0; i < MAX_VOICES; i++) |
452 | { | 450 | { |
453 | voicept=&voices[i]; | 451 | voicept=&voices[i]; |
454 | if(voicept->isUsed==1) | 452 | if(voicept->isUsed) |
455 | { | 453 | { |
456 | synthVoice(voicept, samp_buf, num_samples); | 454 | synthVoice(voicept, samp_buf, num_samples); |
457 | } | 455 | } |