summaryrefslogtreecommitdiff
path: root/apps/plugins/midiplay.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/midiplay.c')
-rw-r--r--apps/plugins/midiplay.c138
1 files changed, 68 insertions, 70 deletions
diff --git a/apps/plugins/midiplay.c b/apps/plugins/midiplay.c
index f279e72e4e..a03e1345aa 100644
--- a/apps/plugins/midiplay.c
+++ b/apps/plugins/midiplay.c
@@ -20,6 +20,7 @@
20 20
21PLUGIN_HEADER 21PLUGIN_HEADER
22 22
23#define FRACTSIZE 10
23#define SAMPLE_RATE 22050 // 44100 22050 11025 24#define SAMPLE_RATE 22050 // 44100 22050 11025
24#define MAX_VOICES 12 // Note: 24 midi channels is the minimum general midi 25#define MAX_VOICES 12 // Note: 24 midi channels is the minimum general midi
25 // spec implementation 26 // spec implementation
@@ -54,50 +55,54 @@ extern char iend[];
54 55
55enum plugin_status plugin_start(struct plugin_api* api, void* parameter) 56enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
56{ 57{
57 rb = api; 58 int retval = 0;
59 rb = api;
58 60
59 if(parameter == NULL) 61 if(parameter == NULL)
60 { 62 {
61 rb->splash(HZ*2, true, " Play .MID file "); 63 rb->splash(HZ*2, true, " Play .MID file ");
62 return PLUGIN_OK; 64 return PLUGIN_OK;
63 } 65 }
64 rb->lcd_setfont(0); 66 rb->lcd_setfont(0);
65 67
66#ifdef USE_IRAM 68#ifdef USE_IRAM
67 rb->memcpy(iramstart, iramcopy, iramend-iramstart); 69 printf("\nied = %d", iedata);
68 rb->memset(iedata, 0, iend - iedata); 70 printf("\nied = %d", iend);
71 rb->memcpy(iramstart, iramcopy, iramend-iramstart);
72 rb->memset(iedata, 0, iend - iedata);
69#endif 73#endif
70 74
71#if !defined(SIMULATOR) && defined(HAVE_ADJUSTABLE_CPU_FREQ) 75#if !defined(SIMULATOR) && defined(HAVE_ADJUSTABLE_CPU_FREQ)
72 rb->cpu_boost(true); 76 rb->cpu_boost(true);
73#endif 77#endif
74 78
75 printf("\n%s", parameter); 79 printf("\n%s", parameter);
76/* rb->splash(HZ, true, parameter); */ 80 /* rb->splash(HZ, true, parameter); */
77 81
78#ifdef RB_PROFILE 82#ifdef RB_PROFILE
79 rb->profile_thread(); 83 rb->profile_thread();
80#endif 84#endif
81 85
82 if(midimain(parameter) == -1) 86 retval = midimain(parameter);
83 return PLUGIN_ERROR;
84 87
85#ifdef RB_PROFILE 88#ifdef RB_PROFILE
86 rb->profstop(); 89 rb->profstop();
87#endif 90#endif
88 91
89#ifndef SIMULATOR 92#ifndef SIMULATOR
90 rb->pcm_play_stop(); 93 rb->pcm_play_stop();
91 rb->pcm_set_frequency(44100); // 44100 94 rb->pcm_set_frequency(44100); // 44100
92#endif 95#endif
93 96
94#if !defined(SIMULATOR) && defined(HAVE_ADJUSTABLE_CPU_FREQ) 97#if !defined(SIMULATOR) && defined(HAVE_ADJUSTABLE_CPU_FREQ)
95 rb->cpu_boost(false); 98 rb->cpu_boost(false);
96#endif 99#endif
97 100
98 rb->splash(HZ, true, "FINISHED PLAYING"); 101 rb->splash(HZ, true, "FINISHED PLAYING");
99 102
100 return PLUGIN_OK; 103 if(retval == -1)
104 return PLUGIN_ERROR;
105 return PLUGIN_OK;
101} 106}
102 107
103bool swap=0; 108bool swap=0;
@@ -138,80 +143,73 @@ inline void synthbuf(void)
138void get_more(unsigned char** start, size_t* size) 143void get_more(unsigned char** start, size_t* size)
139{ 144{
140#ifndef SYNC 145#ifndef SYNC
141 if(lastswap!=swap) 146 if(lastswap!=swap)
142 { 147 {
143 printf("Buffer miss!"); // Comment out the printf to make missses less noticable. 148 printf("Buffer miss!"); // Comment out the printf to make missses less noticable.
144/*
145 int a=0;
146 for(a=0; a<MAX_VOICES; a++)
147 {
148 voices[a].isUsed=0;
149 }
150*/
151 } 149 }
152 150
153#else 151#else
154 synthbuf(); // For some reason midiplayer crashes when an update is forced 152 synthbuf(); // For some reason midiplayer crashes when an update is forced
155#endif 153#endif
156 154
157 *size = BUF_SIZE*sizeof(short); 155 *size = BUF_SIZE*sizeof(short);
158#ifndef SYNC 156#ifndef SYNC
159 *start = (unsigned char*)((swap ? gmbuf : gmbuf + BUF_SIZE)); 157 *start = (unsigned char*)((swap ? gmbuf : gmbuf + BUF_SIZE));
160 swap=!swap; 158 swap=!swap;
161#else 159#else
162 *start = (unsigned char*)(gmbuf); 160 *start = (unsigned char*)(gmbuf);
163#endif 161#endif
164} 162}
165 163
166int midimain(void * filename) 164int midimain(void * filename)
167{ 165{
168 int button; 166 int button;
169 167
170/* rb->splash(HZ/5, true, "LOADING MIDI"); */ 168 /* rb->splash(HZ/5, true, "LOADING MIDI"); */
171 printf("\nLoading file"); 169 printf("\nLoading file");
172 mf= loadFile(filename); 170 mf= loadFile(filename);
173 171
174/* rb->splash(HZ/5, true, "LOADING PATCHES"); */ 172 /* rb->splash(HZ/5, true, "LOADING PATCHES"); */
175 if (initSynth(mf, "/.rockbox/patchset/patchset.cfg", "/.rockbox/patchset/drums.cfg") == -1) 173 if (initSynth(mf, "/.rockbox/patchset/patchset.cfg", "/.rockbox/patchset/drums.cfg") == -1)
176 return -1; 174 return -1;
177 175
178#ifndef SIMULATOR 176#ifndef SIMULATOR
179 rb->pcm_play_stop(); 177 rb->pcm_play_stop();
180 rb->pcm_set_frequency(SAMPLE_RATE); // 44100 22050 11025 178 rb->pcm_set_frequency(SAMPLE_RATE); // 44100 22050 11025
181#endif 179#endif
182 180
183 /* 181 /*
184 * tick() will do one MIDI clock tick. Then, there's a loop here that 182 * tick() will do one MIDI clock tick. Then, there's a loop here that
185 * will generate the right number of samples per MIDI tick. The whole 183 * will generate the right number of samples per MIDI tick. The whole
186 * MIDI playback is timed in terms of this value.. there are no forced 184 * MIDI playback is timed in terms of this value.. there are no forced
187 * delays or anything. It just produces enough samples for each tick, and 185 * delays or anything. It just produces enough samples for each tick, and
188 * the playback of these samples is what makes the timings right. 186 * the playback of these samples is what makes the timings right.
189 * 187 *
190 * This seems to work quite well. 188 * This seems to work quite well. On a laptop, anyway.
191 */ 189 */
192 190
193 printf("\nOkay, starting sequencing"); 191 printf("\nOkay, starting sequencing");
194 192
195 bpm=mf->div*1000000/tempo; 193 bpm=mf->div*1000000/tempo;
196 numberOfSamples=SAMPLE_RATE/bpm; 194 numberOfSamples=SAMPLE_RATE/bpm;
197 195
198 tick(); 196 tick();
199 197
200 synthbuf(); 198 synthbuf();
201#ifndef SIMULATOR 199#ifndef SIMULATOR
202 rb->pcm_play_data(&get_more, NULL, 0); 200 rb->pcm_play_data(&get_more, NULL, 0);
203#endif 201#endif
204 202
205 button=rb->button_status(); 203 button=rb->button_status();
206 204
207 while(!quit) 205 while(!quit)
208 { 206 {
209#ifndef SYNC 207 #ifndef SYNC
210 synthbuf(); 208 synthbuf();
211#endif 209 #endif
212 rb->yield(); 210 rb->yield();
213 if(rb->button_status()!=button) quit=1; 211 if(rb->button_status()!=button) quit=1;
214 } 212 }
215 213
216 return 0; 214 return 0;
217} 215}