summaryrefslogtreecommitdiff
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.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;
39 39
40static void *alloc(int size) 40static void *alloc(int size)
41{ 41{
42 static char *offset = NULL; 42 static char *offset[2] = {NULL};
43 static size_t totalSize = 0; 43 static size_t totalSize[2] = {0};
44 char *ret; 44 char *ret;
45 int n;
45 46
46 int remainder = size % 4; 47 int remainder = size % 4;
47 48
48 size = size + 4-remainder; 49 size = size + 4-remainder;
49 50
50 if (offset == NULL) 51 if (offset[0] == NULL)
51 { 52 {
52 offset = rb->plugin_get_audio_buffer(&totalSize); 53 offset[0] = rb->plugin_get_buffer(&totalSize[0]);
53 } 54 }
54 55
55 if (size + 4 > (int)totalSize) 56 if (offset[1] == NULL)
56 { 57 {
57 midi_debug("Out of Memory"); 58 offset[1] = rb->plugin_get_audio_buffer(&totalSize[1]);
58 midi_debug("MALLOC BARF"); 59 }
59 midi_debug("MALLOC BARF"); 60
60 midi_debug("MALLOC BARF"); 61 n = (totalSize[0] > totalSize[1]) ? 1 : 0;
61 midi_debug("MALLOC BARF");
62 midi_debug("MALLOC BARF");
63 /* We've made our point. */
64 62
63 if (size + 4 > (int)totalSize[n])
64 n ^= 1;
65 if (size + 4 > (int)totalSize[n])
66 {
67 midi_debug("Out of Memory");
65 return NULL; 68 return NULL;
66 } 69 }
67 70
68 ret = offset + 4; 71 ret = offset[n] + 4;
69 *((unsigned int *)offset) = size; 72 *((unsigned int *)offset[n]) = size;
70 73
71 offset += size + 4; 74 offset[n] += size + 4;
72 totalSize -= size + 4; 75 totalSize[n] -= size + 4;
73 return ret; 76 return ret;
74} 77}
75 78
@@ -117,7 +120,8 @@ unsigned char readChar(int file)
117void * readData(int file, int len) 120void * readData(int file, int len)
118{ 121{
119 void * dat = malloc(len); 122 void * dat = malloc(len);
120 rb->read(file, dat, len); 123 if (dat)
124 rb->read(file, dat, len);
121 return dat; 125 return dat;
122} 126}
123 127