summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
authorStepan Moskovchenko <stevenm@rockbox.org>2006-05-03 05:18:18 +0000
committerStepan Moskovchenko <stevenm@rockbox.org>2006-05-03 05:18:18 +0000
commit47efba8bbfd17cb6d95ce1039e0114dc24a9dc68 (patch)
tree4d42a46b6c0d66d7b53ec82dfc7a0ce826b5ba98 /apps/plugins
parent224b0bf1ffe3d5ec0f61dd2df20c13c48d1644b4 (diff)
downloadrockbox-47efba8bbfd17cb6d95ce1039e0114dc24a9dc68.tar.gz
rockbox-47efba8bbfd17cb6d95ce1039e0114dc24a9dc68.zip
Fix file descriptor leak that would cause a hard lockup every 7 files
played. A few other cosmetic changes. please, please no red build =) git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9865 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins')
-rw-r--r--apps/plugins/midi/midifile.c17
-rw-r--r--apps/plugins/midi/midiutil.c12
-rw-r--r--apps/plugins/midi/sequencer.c18
-rw-r--r--apps/plugins/midi/synth.c10
-rw-r--r--apps/plugins/midiplay.c138
5 files changed, 111 insertions, 84 deletions
diff --git a/apps/plugins/midi/midifile.c b/apps/plugins/midi/midifile.c
index 61168f9d39..13887e4a98 100644
--- a/apps/plugins/midi/midifile.c
+++ b/apps/plugins/midi/midifile.c
@@ -67,7 +67,8 @@ struct MIDIfile * loadFile(char * filename)
67 67
68 int track=0; 68 int track=0;
69 69
70 printf("\nnumTracks=%d div=%d\nBegin reading track data\n", mfload->numTracks, mfload->div); 70 printf("\nFile has %d tracks.", mfload->numTracks);
71 printf("Time division=%d\n", mfload->div);
71 72
72 73
73 while(! eof(file) && track < mfload->numTracks) 74 while(! eof(file) && track < mfload->numTracks)
@@ -79,7 +80,7 @@ struct MIDIfile * loadFile(char * filename)
79 { 80 {
80 if(mfload->numTracks != track) 81 if(mfload->numTracks != track)
81 { 82 {
82 printf("\nError: file claims to have %d tracks.\n I only see %d here.\n", mfload->numTracks, track); 83 printf("\nError: file claims to have %d tracks.\n I only see %d here.\n", mfload->numTracks, track);
83 mfload->numTracks = track; 84 mfload->numTracks = track;
84 } 85 }
85 return mfload; 86 return mfload;
@@ -88,7 +89,6 @@ struct MIDIfile * loadFile(char * filename)
88 if(id == ID_MTRK) 89 if(id == ID_MTRK)
89 { 90 {
90 mfload->tracks[track] = readTrack(file); 91 mfload->tracks[track] = readTrack(file);
91 //exit(0);
92 track++; 92 track++;
93 } else 93 } else
94 { 94 {
@@ -98,16 +98,19 @@ struct MIDIfile * loadFile(char * filename)
98 readChar(file); 98 readChar(file);
99 } 99 }
100 } 100 }
101
102 rb->close(file);
101 return mfload; 103 return mfload;
102 104
103} 105}
104 106
107/* Global again. Not static. What if track 1 ends on a running status event
108 * and then track 2 starts loading */
105 109
110int rStatus = 0;
106/* Returns 0 if done, 1 if keep going */ 111/* Returns 0 if done, 1 if keep going */
107int readEvent(int file, void * dest) 112int readEvent(int file, void * dest)
108{ 113{
109
110 static int rStatus = 0;
111 struct Event dummy; 114 struct Event dummy;
112 struct Event * ev = (struct Event *) dest; 115 struct Event * ev = (struct Event *) dest;
113 116
@@ -136,7 +139,7 @@ int readEvent(int file, void * dest)
136 else 139 else
137 { 140 {
138 /* 141 /*
139 * Don't allocate anything, just see how much it would tale 142 * Don't allocate anything, just see how much it would take
140 * To make memory usage efficient 143 * To make memory usage efficient
141 */ 144 */
142 unsigned int a=0; 145 unsigned int a=0;
@@ -201,7 +204,7 @@ struct Track * readTrack(int file)
201 { 204 {
202 if(trackSize < dataPtr-trk->dataBlock) 205 if(trackSize < dataPtr-trk->dataBlock)
203 { 206 {
204 printf("\nTrack parser memory out of bounds"); 207 printf("\nTrack parser memory out of bounds");
205 exit(1); 208 exit(1);
206 } 209 }
207 dataPtr+=sizeof(struct Event); 210 dataPtr+=sizeof(struct Event);
diff --git a/apps/plugins/midi/midiutil.c b/apps/plugins/midi/midiutil.c
index 8e27e739e7..daadae8a4f 100644
--- a/apps/plugins/midi/midiutil.c
+++ b/apps/plugins/midi/midiutil.c
@@ -62,6 +62,7 @@
62 62
63extern struct plugin_api * rb; 63extern struct plugin_api * rb;
64 64
65int printf(const char *fmt, ...);
65 66
66int chVol[16] IBSS_ATTR; /* Channel volume */ 67int chVol[16] IBSS_ATTR; /* Channel volume */
67int chPanLeft[16] IBSS_ATTR; /* Channel panning */ 68int chPanLeft[16] IBSS_ATTR; /* Channel panning */
@@ -156,6 +157,15 @@ void *alloc(int size)
156 157
157 if (size + 4 > totalSize) 158 if (size + 4 > totalSize)
158 { 159 {
160 printf("\nMALLOC BARF");
161 printf("\nMALLOC BARF");
162 printf("\nMALLOC BARF");
163 printf("\nMALLOC BARF");
164 printf("\nMALLOC BARF");
165 printf("\nMALLOC BARF");
166 printf("\nMALLOC BARF");
167 /* We've made our point. */
168
159 return NULL; 169 return NULL;
160 } 170 }
161 171
@@ -229,7 +239,7 @@ int eof(int fd)
229// Here is a hacked up printf command to get the output from the game. 239// Here is a hacked up printf command to get the output from the game.
230int printf(const char *fmt, ...) 240int printf(const char *fmt, ...)
231{ 241{
232 static int p_xtpt; 242 static int p_xtpt = 0;
233 char p_buf[50]; 243 char p_buf[50];
234 bool ok; 244 bool ok;
235 va_list ap; 245 va_list ap;
diff --git a/apps/plugins/midi/sequencer.c b/apps/plugins/midi/sequencer.c
index 3c026276c2..b6fb592294 100644
--- a/apps/plugins/midi/sequencer.c
+++ b/apps/plugins/midi/sequencer.c
@@ -111,7 +111,7 @@ long pitchTbl[] ICONST_ATTR={
111 72901,72934,72967,72999,73032,73065,73098,73131,73164,73197,73230,73264, 111 72901,72934,72967,72999,73032,73065,73098,73131,73164,73197,73230,73264,
112 73297,73330,73363,73396,73429,73462,73495,73528 112 73297,73330,73363,73396,73429,73462,73495,73528
113}; 113};
114 114/*
115void findDelta(struct SynthObject * so, int ch, int note) 115void findDelta(struct SynthObject * so, int ch, int note)
116{ 116{
117 117
@@ -120,6 +120,22 @@ void findDelta(struct SynthObject * so, int ch, int note)
120 so->delta = (((gustable[note]<<10) / (wf->rootFreq)) * wf->sampRate / (SAMPLE_RATE)); 120 so->delta = (((gustable[note]<<10) / (wf->rootFreq)) * wf->sampRate / (SAMPLE_RATE));
121 so->delta = (so->delta * pitchTbl[chPW[ch]])>> 16; 121 so->delta = (so->delta * pitchTbl[chPW[ch]])>> 16;
122} 122}
123*/
124
125
126void findDelta(struct SynthObject * so, int ch, int note)
127{
128
129 struct GWaveform * wf = patchSet[chPat[ch]]->waveforms[patchSet[chPat[ch]]->noteTable[note]];
130 so->wf=wf; // \|/ was 10
131
132 unsigned long delta= 0 ;
133
134 delta = (((gustable[note]<<FRACTSIZE) / (wf->rootFreq)) * wf->sampRate / (SAMPLE_RATE));
135 delta = (delta * pitchTbl[chPW[ch]])>> 16;
136
137 so->delta = delta;
138}
123 139
124inline void setPW(int ch, int msb, int lsb) 140inline void setPW(int ch, int msb, int lsb)
125{ 141{
diff --git a/apps/plugins/midi/synth.c b/apps/plugins/midi/synth.c
index 44417b2583..a364889ea0 100644
--- a/apps/plugins/midi/synth.c
+++ b/apps/plugins/midi/synth.c
@@ -272,7 +272,7 @@ signed short int synthVoice(struct SynthObject * so)
272 so->cp += so->delta; 272 so->cp += so->delta;
273 } 273 }
274 274
275 cpShifted = so->cp >> 10; //Was 10 275 cpShifted = so->cp >> FRACTSIZE; //Was 10
276 276
277 if( (cpShifted > (wf->numSamples) && (so->state != STATE_RAMPDOWN))) 277 if( (cpShifted > (wf->numSamples) && (so->state != STATE_RAMPDOWN)))
278 { 278 {
@@ -286,7 +286,7 @@ signed short int synthVoice(struct SynthObject * so)
286 { 286 {
287 if(wf->mode & LOOP_REVERSE) 287 if(wf->mode & LOOP_REVERSE)
288 { 288 {
289 so->cp = (wf->endLoop)<<10; //Was 10 289 so->cp = (wf->endLoop)<<FRACTSIZE; //Was 10
290 cpShifted = wf->endLoop; 290 cpShifted = wf->endLoop;
291 s2=getSample((cpShifted), wf); 291 s2=getSample((cpShifted), wf);
292 } 292 }
@@ -302,7 +302,7 @@ signed short int synthVoice(struct SynthObject * so)
302 so->loopState = STATE_LOOPING; 302 so->loopState = STATE_LOOPING;
303 if((wf->mode & (24)) == 0) 303 if((wf->mode & (24)) == 0)
304 { 304 {
305 so->cp = (wf->startLoop)<<10; //Was 10 305 so->cp = (wf->startLoop)<<FRACTSIZE; //Was 10
306 cpShifted = wf->startLoop; 306 cpShifted = wf->startLoop;
307 s2=getSample((cpShifted), wf); 307 s2=getSample((cpShifted), wf);
308 } 308 }
@@ -315,8 +315,8 @@ signed short int synthVoice(struct SynthObject * so)
315 315
316 /* Better, working, linear interpolation */ 316 /* Better, working, linear interpolation */
317 s1=getSample((cpShifted), wf); //\|/ Was 1023)) >> 10 317 s1=getSample((cpShifted), wf); //\|/ Was 1023)) >> 10
318 s = s1 + ((signed)((s2 - s1) * (so->cp & 1023))>>10); //Was 10 318// s = s1 + ((signed)((s2 - s1) * (so->cp & (1023)))>>10); //Was 10
319 319 s = s1 + ((signed)((s2 - s1) * (so->cp & ((1<<FRACTSIZE)-1)))>>FRACTSIZE); //Was 10
320 320
321/* ADSR COMMENT WOULD GO FROM HERE.........*/ 321/* ADSR COMMENT WOULD GO FROM HERE.........*/
322 322
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}