summaryrefslogtreecommitdiffstats
path: root/apps/plugins/midi/midiutil.c
diff options
context:
space:
mode:
authorSolomon Peachy <pizza@shaftnet.org>2019-08-04 16:58:20 -0400
committerSolomon Peachy <pizza@shaftnet.org>2019-08-05 20:48:40 +0200
commited724fecb15d90d8075ed1edb963f455cb91b0a1 (patch)
tree6b72250278e5170bc7ed4b8263f48eb8e8dc1c61 /apps/plugins/midi/midiutil.c
parenteea5bfc9aec35686406296641b37bcc2c731fbbb (diff)
downloadrockbox-ed724fecb15d90d8075ed1edb963f455cb91b0a1.tar.gz
rockbox-ed724fecb15d90d8075ed1edb963f455cb91b0a1.tar.bz2
rockbox-ed724fecb15d90d8075ed1edb963f455cb91b0a1.zip
Midiplay plugin ehancements
- Improved robustness - Improved sound quality - Use mixer and DSP Patch by Igor Poretsky Change-Id: I6fa617158cbaa53ae842295cdbdbe3a478e49ded
Diffstat (limited to 'apps/plugins/midi/midiutil.c')
-rw-r--r--apps/plugins/midi/midiutil.c38
1 files changed, 21 insertions, 17 deletions
diff --git a/apps/plugins/midi/midiutil.c b/apps/plugins/midi/midiutil.c
index bfac1d5244..b9e57a405b 100644
--- a/apps/plugins/midi/midiutil.c
+++ b/apps/plugins/midi/midiutil.c
@@ -39,37 +39,40 @@ struct SynthObject voices[MAX_VOICES] IBSS_ATTR;
static void *alloc(int size)
{
- static char *offset = NULL;
- static size_t totalSize = 0;
+ static char *offset[2] = {NULL};
+ static size_t totalSize[2] = {0};
char *ret;
+ int n;
int remainder = size % 4;
size = size + 4-remainder;
- if (offset == NULL)
+ if (offset[0] == NULL)
{
- offset = rb->plugin_get_audio_buffer(&totalSize);
+ offset[0] = rb->plugin_get_buffer(&totalSize[0]);
}
- if (size + 4 > (int)totalSize)
+ if (offset[1] == NULL)
{
- midi_debug("Out of Memory");
- midi_debug("MALLOC BARF");
- midi_debug("MALLOC BARF");
- midi_debug("MALLOC BARF");
- midi_debug("MALLOC BARF");
- midi_debug("MALLOC BARF");
- /* We've made our point. */
+ offset[1] = rb->plugin_get_audio_buffer(&totalSize[1]);
+ }
+
+ n = (totalSize[0] > totalSize[1]) ? 1 : 0;
+ if (size + 4 > (int)totalSize[n])
+ n ^= 1;
+ if (size + 4 > (int)totalSize[n])
+ {
+ midi_debug("Out of Memory");
return NULL;
}
- ret = offset + 4;
- *((unsigned int *)offset) = size;
+ ret = offset[n] + 4;
+ *((unsigned int *)offset[n]) = size;
- offset += size + 4;
- totalSize -= size + 4;
+ offset[n] += size + 4;
+ totalSize[n] -= size + 4;
return ret;
}
@@ -117,7 +120,8 @@ unsigned char readChar(int file)
void * readData(int file, int len)
{
void * dat = malloc(len);
- rb->read(file, dat, len);
+ if (dat)
+ rb->read(file, dat, len);
return dat;
}