diff options
Diffstat (limited to 'apps/plugins/midi/synth.c')
-rw-r--r-- | apps/plugins/midi/synth.c | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/apps/plugins/midi/synth.c b/apps/plugins/midi/synth.c index 327f32e288..568c7bb1ce 100644 --- a/apps/plugins/midi/synth.c +++ b/apps/plugins/midi/synth.c | |||
@@ -255,8 +255,7 @@ inline void stopVoice(struct SynthObject * so) | |||
255 | so->decay = 0; | 255 | so->decay = 0; |
256 | } | 256 | } |
257 | 257 | ||
258 | int synthVoice(struct SynthObject * so) ICODE_ATTR; | 258 | static inline int synthVoice(struct SynthObject * so) |
259 | int synthVoice(struct SynthObject * so) | ||
260 | { | 259 | { |
261 | struct GWaveform * wf; | 260 | struct GWaveform * wf; |
262 | register int s; | 261 | register int s; |
@@ -404,3 +403,46 @@ int synthVoice(struct SynthObject * so) | |||
404 | return s*so->volscale>>14; | 403 | return s*so->volscale>>14; |
405 | } | 404 | } |
406 | 405 | ||
406 | /* synth num_samples samples and write them to the */ | ||
407 | /* buffer pointed to by buf_ptr */ | ||
408 | void synthSamples(int32_t *buf_ptr, unsigned int num_samples) ICODE_ATTR; | ||
409 | void synthSamples(int32_t *buf_ptr, unsigned int num_samples) | ||
410 | { | ||
411 | int i; | ||
412 | register int dL; | ||
413 | register int dR; | ||
414 | register int sample; | ||
415 | register struct SynthObject *voicept; | ||
416 | while(num_samples>0) | ||
417 | { | ||
418 | dL=0; | ||
419 | dR=0; | ||
420 | voicept=&voices[0]; | ||
421 | |||
422 | for(i=MAX_VOICES; i > 0; i--) | ||
423 | { | ||
424 | if(voicept->isUsed==1) | ||
425 | { | ||
426 | sample = synthVoice(voicept); | ||
427 | dL += sample; | ||
428 | sample *= chPan[voicept->ch]; | ||
429 | dR += sample; | ||
430 | } | ||
431 | voicept++; | ||
432 | } | ||
433 | |||
434 | dL = (dL << 7) - dR; | ||
435 | |||
436 | /* combine the left and right 16 bit samples into 32 bits and write */ | ||
437 | /* to the buffer, left sample in the high word and right in the low word */ | ||
438 | *buf_ptr=(((dL&0x7FFF80) << 9) | ((dR&0x7FFF80) >> 7)); | ||
439 | |||
440 | buf_ptr++; | ||
441 | num_samples--; | ||
442 | } | ||
443 | /* TODO: Automatic Gain Control, anyone? */ | ||
444 | /* Or, should this be implemented on the DSP's output volume instead? */ | ||
445 | |||
446 | return; /* No more ghetto lowpass filter. Linear interpolation works well. */ | ||
447 | } | ||
448 | |||