summaryrefslogtreecommitdiff
path: root/apps/plugins/midi/synth.c
diff options
context:
space:
mode:
authorNils Wallménius <nils@rockbox.org>2007-10-08 19:28:41 +0000
committerNils Wallménius <nils@rockbox.org>2007-10-08 19:28:41 +0000
commitf619f8167646632d6eab10f529638eebbdda6af6 (patch)
tree119a1f4051d59808a25612421f613cb09ee1e9d5 /apps/plugins/midi/synth.c
parentd712e252fecf814a48814034a55ba60a1b194598 (diff)
downloadrockbox-f619f8167646632d6eab10f529638eebbdda6af6.tar.gz
rockbox-f619f8167646632d6eab10f529638eebbdda6af6.zip
Change loop structure for sample synthesizing. Gives a nice speedup on both coldfire and arm targets.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15036 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/midi/synth.c')
-rw-r--r--apps/plugins/midi/synth.c46
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
258int synthVoice(struct SynthObject * so) ICODE_ATTR; 258static inline int synthVoice(struct SynthObject * so)
259int 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 */
408void synthSamples(int32_t *buf_ptr, unsigned int num_samples) ICODE_ATTR;
409void 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