From 47efba8bbfd17cb6d95ce1039e0114dc24a9dc68 Mon Sep 17 00:00:00 2001 From: Stepan Moskovchenko Date: Wed, 3 May 2006 05:18:18 +0000 Subject: 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 --- apps/plugins/midi/midifile.c | 17 +++--- apps/plugins/midi/midiutil.c | 12 +++- apps/plugins/midi/sequencer.c | 18 +++++- apps/plugins/midi/synth.c | 10 +-- apps/plugins/midiplay.c | 138 +++++++++++++++++++++--------------------- 5 files changed, 111 insertions(+), 84 deletions(-) (limited to 'apps/plugins') 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) int track=0; - printf("\nnumTracks=%d div=%d\nBegin reading track data\n", mfload->numTracks, mfload->div); + printf("\nFile has %d tracks.", mfload->numTracks); + printf("Time division=%d\n", mfload->div); while(! eof(file) && track < mfload->numTracks) @@ -79,7 +80,7 @@ struct MIDIfile * loadFile(char * filename) { if(mfload->numTracks != track) { - printf("\nError: file claims to have %d tracks.\n I only see %d here.\n", mfload->numTracks, track); + printf("\nError: file claims to have %d tracks.\n I only see %d here.\n", mfload->numTracks, track); mfload->numTracks = track; } return mfload; @@ -88,7 +89,6 @@ struct MIDIfile * loadFile(char * filename) if(id == ID_MTRK) { mfload->tracks[track] = readTrack(file); - //exit(0); track++; } else { @@ -98,16 +98,19 @@ struct MIDIfile * loadFile(char * filename) readChar(file); } } + + rb->close(file); return mfload; } +/* Global again. Not static. What if track 1 ends on a running status event + * and then track 2 starts loading */ +int rStatus = 0; /* Returns 0 if done, 1 if keep going */ int readEvent(int file, void * dest) { - - static int rStatus = 0; struct Event dummy; struct Event * ev = (struct Event *) dest; @@ -136,7 +139,7 @@ int readEvent(int file, void * dest) else { /* - * Don't allocate anything, just see how much it would tale + * Don't allocate anything, just see how much it would take * To make memory usage efficient */ unsigned int a=0; @@ -201,7 +204,7 @@ struct Track * readTrack(int file) { if(trackSize < dataPtr-trk->dataBlock) { - printf("\nTrack parser memory out of bounds"); + printf("\nTrack parser memory out of bounds"); exit(1); } 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 @@ extern struct plugin_api * rb; +int printf(const char *fmt, ...); int chVol[16] IBSS_ATTR; /* Channel volume */ int chPanLeft[16] IBSS_ATTR; /* Channel panning */ @@ -156,6 +157,15 @@ void *alloc(int size) if (size + 4 > totalSize) { + printf("\nMALLOC BARF"); + printf("\nMALLOC BARF"); + printf("\nMALLOC BARF"); + printf("\nMALLOC BARF"); + printf("\nMALLOC BARF"); + printf("\nMALLOC BARF"); + printf("\nMALLOC BARF"); + /* We've made our point. */ + return NULL; } @@ -229,7 +239,7 @@ int eof(int fd) // Here is a hacked up printf command to get the output from the game. int printf(const char *fmt, ...) { - static int p_xtpt; + static int p_xtpt = 0; char p_buf[50]; bool ok; 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={ 72901,72934,72967,72999,73032,73065,73098,73131,73164,73197,73230,73264, 73297,73330,73363,73396,73429,73462,73495,73528 }; - +/* void findDelta(struct SynthObject * so, int ch, int note) { @@ -120,6 +120,22 @@ void findDelta(struct SynthObject * so, int ch, int note) so->delta = (((gustable[note]<<10) / (wf->rootFreq)) * wf->sampRate / (SAMPLE_RATE)); so->delta = (so->delta * pitchTbl[chPW[ch]])>> 16; } +*/ + + +void findDelta(struct SynthObject * so, int ch, int note) +{ + + struct GWaveform * wf = patchSet[chPat[ch]]->waveforms[patchSet[chPat[ch]]->noteTable[note]]; + so->wf=wf; // \|/ was 10 + + unsigned long delta= 0 ; + + delta = (((gustable[note]<rootFreq)) * wf->sampRate / (SAMPLE_RATE)); + delta = (delta * pitchTbl[chPW[ch]])>> 16; + + so->delta = delta; +} inline void setPW(int ch, int msb, int lsb) { 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) so->cp += so->delta; } - cpShifted = so->cp >> 10; //Was 10 + cpShifted = so->cp >> FRACTSIZE; //Was 10 if( (cpShifted > (wf->numSamples) && (so->state != STATE_RAMPDOWN))) { @@ -286,7 +286,7 @@ signed short int synthVoice(struct SynthObject * so) { if(wf->mode & LOOP_REVERSE) { - so->cp = (wf->endLoop)<<10; //Was 10 + so->cp = (wf->endLoop)<endLoop; s2=getSample((cpShifted), wf); } @@ -302,7 +302,7 @@ signed short int synthVoice(struct SynthObject * so) so->loopState = STATE_LOOPING; if((wf->mode & (24)) == 0) { - so->cp = (wf->startLoop)<<10; //Was 10 + so->cp = (wf->startLoop)<startLoop; s2=getSample((cpShifted), wf); } @@ -315,8 +315,8 @@ signed short int synthVoice(struct SynthObject * so) /* Better, working, linear interpolation */ s1=getSample((cpShifted), wf); //\|/ Was 1023)) >> 10 - s = s1 + ((signed)((s2 - s1) * (so->cp & 1023))>>10); //Was 10 - +// s = s1 + ((signed)((s2 - s1) * (so->cp & (1023)))>>10); //Was 10 + s = s1 + ((signed)((s2 - s1) * (so->cp & ((1<>FRACTSIZE); //Was 10 /* ADSR COMMENT WOULD GO FROM HERE.........*/ 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 @@ PLUGIN_HEADER +#define FRACTSIZE 10 #define SAMPLE_RATE 22050 // 44100 22050 11025 #define MAX_VOICES 12 // Note: 24 midi channels is the minimum general midi // spec implementation @@ -54,50 +55,54 @@ extern char iend[]; enum plugin_status plugin_start(struct plugin_api* api, void* parameter) { - rb = api; + int retval = 0; + rb = api; - if(parameter == NULL) - { - rb->splash(HZ*2, true, " Play .MID file "); - return PLUGIN_OK; - } - rb->lcd_setfont(0); + if(parameter == NULL) + { + rb->splash(HZ*2, true, " Play .MID file "); + return PLUGIN_OK; + } + rb->lcd_setfont(0); #ifdef USE_IRAM - rb->memcpy(iramstart, iramcopy, iramend-iramstart); - rb->memset(iedata, 0, iend - iedata); + printf("\nied = %d", iedata); + printf("\nied = %d", iend); + rb->memcpy(iramstart, iramcopy, iramend-iramstart); + rb->memset(iedata, 0, iend - iedata); #endif #if !defined(SIMULATOR) && defined(HAVE_ADJUSTABLE_CPU_FREQ) - rb->cpu_boost(true); + rb->cpu_boost(true); #endif - printf("\n%s", parameter); -/* rb->splash(HZ, true, parameter); */ + printf("\n%s", parameter); + /* rb->splash(HZ, true, parameter); */ #ifdef RB_PROFILE - rb->profile_thread(); + rb->profile_thread(); #endif - if(midimain(parameter) == -1) - return PLUGIN_ERROR; + retval = midimain(parameter); #ifdef RB_PROFILE - rb->profstop(); + rb->profstop(); #endif #ifndef SIMULATOR - rb->pcm_play_stop(); - rb->pcm_set_frequency(44100); // 44100 + rb->pcm_play_stop(); + rb->pcm_set_frequency(44100); // 44100 #endif #if !defined(SIMULATOR) && defined(HAVE_ADJUSTABLE_CPU_FREQ) - rb->cpu_boost(false); + rb->cpu_boost(false); #endif - rb->splash(HZ, true, "FINISHED PLAYING"); + rb->splash(HZ, true, "FINISHED PLAYING"); - return PLUGIN_OK; + if(retval == -1) + return PLUGIN_ERROR; + return PLUGIN_OK; } bool swap=0; @@ -138,80 +143,73 @@ inline void synthbuf(void) void get_more(unsigned char** start, size_t* size) { #ifndef SYNC - if(lastswap!=swap) - { - printf("Buffer miss!"); // Comment out the printf to make missses less noticable. -/* - int a=0; - for(a=0; asplash(HZ/5, true, "LOADING MIDI"); */ - printf("\nLoading file"); - mf= loadFile(filename); + /* rb->splash(HZ/5, true, "LOADING MIDI"); */ + printf("\nLoading file"); + mf= loadFile(filename); -/* rb->splash(HZ/5, true, "LOADING PATCHES"); */ - if (initSynth(mf, "/.rockbox/patchset/patchset.cfg", "/.rockbox/patchset/drums.cfg") == -1) - return -1; + /* rb->splash(HZ/5, true, "LOADING PATCHES"); */ + if (initSynth(mf, "/.rockbox/patchset/patchset.cfg", "/.rockbox/patchset/drums.cfg") == -1) + return -1; #ifndef SIMULATOR - rb->pcm_play_stop(); - rb->pcm_set_frequency(SAMPLE_RATE); // 44100 22050 11025 + rb->pcm_play_stop(); + rb->pcm_set_frequency(SAMPLE_RATE); // 44100 22050 11025 #endif - /* - * tick() will do one MIDI clock tick. Then, there's a loop here that - * will generate the right number of samples per MIDI tick. The whole - * MIDI playback is timed in terms of this value.. there are no forced - * delays or anything. It just produces enough samples for each tick, and - * the playback of these samples is what makes the timings right. - * - * This seems to work quite well. - */ + /* + * tick() will do one MIDI clock tick. Then, there's a loop here that + * will generate the right number of samples per MIDI tick. The whole + * MIDI playback is timed in terms of this value.. there are no forced + * delays or anything. It just produces enough samples for each tick, and + * the playback of these samples is what makes the timings right. + * + * This seems to work quite well. On a laptop, anyway. + */ - printf("\nOkay, starting sequencing"); + printf("\nOkay, starting sequencing"); - bpm=mf->div*1000000/tempo; - numberOfSamples=SAMPLE_RATE/bpm; + bpm=mf->div*1000000/tempo; + numberOfSamples=SAMPLE_RATE/bpm; - tick(); + tick(); - synthbuf(); + synthbuf(); #ifndef SIMULATOR - rb->pcm_play_data(&get_more, NULL, 0); + rb->pcm_play_data(&get_more, NULL, 0); #endif - button=rb->button_status(); + button=rb->button_status(); - while(!quit) - { -#ifndef SYNC - synthbuf(); -#endif - rb->yield(); - if(rb->button_status()!=button) quit=1; - } + while(!quit) + { + #ifndef SYNC + synthbuf(); + #endif + rb->yield(); + if(rb->button_status()!=button) quit=1; + } - return 0; + return 0; } -- cgit v1.2.3