From 2d91cf3ea39e409bc72fd687aa7638cc34191bd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20Wallm=C3=A9nius?= Date: Sun, 21 Oct 2007 22:50:10 +0000 Subject: [PATCH] Increase temp buffer size to fit more samples, put in simple safeguard to avoid memory corruption when writing to the temp buffer git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15253 a1c6a512-1295-4272-9138-f99709370657 --- apps/plugins/midi/synth.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/apps/plugins/midi/synth.c b/apps/plugins/midi/synth.c index 3c60d9bd82..4e04975e0b 100644 --- a/apps/plugins/midi/synth.c +++ b/apps/plugins/midi/synth.c @@ -424,29 +424,33 @@ static inline void synthVoice(struct SynthObject * so, int32_t * out, unsigned i /* buffer to hold all the samples for the current tick, this is a hack neccesary for coldfire targets as pcm_play_data uses the dma which cannot access iram */ -int32_t samp_buf[256] IBSS_ATTR; +int32_t samp_buf[512] IBSS_ATTR; /* synth num_samples samples and write them to the */ /* buffer pointed to by buf_ptr */ void synthSamples(int32_t *buf_ptr, unsigned int num_samples) ICODE_ATTR; void synthSamples(int32_t *buf_ptr, unsigned int num_samples) { - int i; - struct SynthObject *voicept; - - rb->memset(samp_buf, 0, num_samples*4); - - for(i=0; i < MAX_VOICES; i++) + if (num_samples > 512) + DEBUGF("num_samples is too big!\n"); + else { - voicept=&voices[i]; - if(voicept->isUsed==1) + int i; + struct SynthObject *voicept; + + rb->memset(samp_buf, 0, num_samples*4); + + for(i=0; i < MAX_VOICES; i++) { - synthVoice(voicept, samp_buf, num_samples); + voicept=&voices[i]; + if(voicept->isUsed==1) + { + synthVoice(voicept, samp_buf, num_samples); + } } + + rb->memcpy(buf_ptr, samp_buf, num_samples*4); } - - rb->memcpy(buf_ptr, samp_buf, num_samples*4); - /* TODO: Automatic Gain Control, anyone? */ /* Or, should this be implemented on the DSP's output volume instead? */