summaryrefslogtreecommitdiff
path: root/apps/plugins/midi/midifile.c
diff options
context:
space:
mode:
authorStepan Moskovchenko <stevenm@rockbox.org>2006-05-01 23:22:59 +0000
committerStepan Moskovchenko <stevenm@rockbox.org>2006-05-01 23:22:59 +0000
commitb2f1b5dd183b1171c81796946c868f2df8df9647 (patch)
tree3f2fcd3bdf2e2f9e00ad253d671b5c27a52280ad /apps/plugins/midi/midifile.c
parent9e3da0d6d5bc9d02b939dedd62e05f8893940c1a (diff)
downloadrockbox-b2f1b5dd183b1171c81796946c868f2df8df9647.tar.gz
rockbox-b2f1b5dd183b1171c81796946c868f2df8df9647.zip
----------------------------------------------------------------------
Added Karl Kurbjun's sound output patch, cleaned up some output. Main file is now midiplay.c, midi2wav is still in there for anyone who wants it. Set sampling rate to 22k, and increased note decay time. Reduced number of concurrent active voices and made new notes replace used voices if none are available. This makes lag less apparent. I really hope this wont go red. (turns around and runs) git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9858 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/midi/midifile.c')
-rw-r--r--apps/plugins/midi/midifile.c40
1 files changed, 19 insertions, 21 deletions
diff --git a/apps/plugins/midi/midifile.c b/apps/plugins/midi/midifile.c
index 412cc6104d..61168f9d39 100644
--- a/apps/plugins/midi/midifile.c
+++ b/apps/plugins/midi/midifile.c
@@ -26,7 +26,7 @@ void bail(const char *);
26 26
27struct MIDIfile * loadFile(char * filename) 27struct MIDIfile * loadFile(char * filename)
28{ 28{
29 struct MIDIfile * mf; 29 struct MIDIfile * mfload;
30 int file = rb->open (filename, O_RDONLY); 30 int file = rb->open (filename, O_RDONLY);
31 31
32 if(file==-1) 32 if(file==-1)
@@ -34,15 +34,15 @@ struct MIDIfile * loadFile(char * filename)
34 bail("Could not open file\n"); 34 bail("Could not open file\n");
35 } 35 }
36 36
37 mf = (struct MIDIfile*)allocate(sizeof(struct MIDIfile)); 37 mfload = (struct MIDIfile*)malloc(sizeof(struct MIDIfile));
38 38
39 if(mf==NULL) 39 if(mfload==NULL)
40 { 40 {
41 rb->close(file); 41 rb->close(file);
42 bail("Could not allocate memory for MIDIfile struct\n"); 42 bail("Could not allocate memory for MIDIfile struct\n");
43 } 43 }
44 44
45 rb->memset(mf, 0, sizeof(struct MIDIfile)); 45 rb->memset(mfload, 0, sizeof(struct MIDIfile));
46 46
47 if(readID(file) != ID_MTHD) 47 if(readID(file) != ID_MTHD)
48 { 48 {
@@ -62,32 +62,32 @@ struct MIDIfile * loadFile(char * filename)
62 bail("MIDI file type not supported"); 62 bail("MIDI file type not supported");
63 } 63 }
64 64
65 mf->numTracks = readTwoBytes(file); 65 mfload->numTracks = readTwoBytes(file);
66 mf->div = readTwoBytes(file); 66 mfload->div = readTwoBytes(file);
67 67
68 int track=0; 68 int track=0;
69 69
70 printf("\nnumTracks=%d div=%d\nBegin reading track data\n", mf->numTracks, mf->div); 70 printf("\nnumTracks=%d div=%d\nBegin reading track data\n", mfload->numTracks, mfload->div);
71 71
72 72
73 while(! eof(file) && track < mf->numTracks) 73 while(! eof(file) && track < mfload->numTracks)
74 { 74 {
75 unsigned char id = readID(file); 75 unsigned char id = readID(file);
76 76
77 77
78 if(id == ID_EOF) 78 if(id == ID_EOF)
79 { 79 {
80 if(mf->numTracks != track) 80 if(mfload->numTracks != track)
81 { 81 {
82 printf("\nError: file claims to have %d tracks.\n I only see %d here.\n", mf->numTracks, track); 82 printf("\nError: file claims to have %d tracks.\n I only see %d here.\n", mfload->numTracks, track);
83 mf->numTracks = track; 83 mfload->numTracks = track;
84 } 84 }
85 return mf; 85 return mfload;
86 } 86 }
87 87
88 if(id == ID_MTRK) 88 if(id == ID_MTRK)
89 { 89 {
90 mf->tracks[track] = readTrack(file); 90 mfload->tracks[track] = readTrack(file);
91 //exit(0); 91 //exit(0);
92 track++; 92 track++;
93 } else 93 } else
@@ -98,16 +98,16 @@ struct MIDIfile * loadFile(char * filename)
98 readChar(file); 98 readChar(file);
99 } 99 }
100 } 100 }
101 return mf; 101 return mfload;
102 102
103} 103}
104 104
105 105
106int rStatus = 0;
107
108/* Returns 0 if done, 1 if keep going */ 106/* Returns 0 if done, 1 if keep going */
109int readEvent(int file, void * dest) 107int readEvent(int file, void * dest)
110{ 108{
109
110 static int rStatus = 0;
111 struct Event dummy; 111 struct Event dummy;
112 struct Event * ev = (struct Event *) dest; 112 struct Event * ev = (struct Event *) dest;
113 113
@@ -131,7 +131,7 @@ int readEvent(int file, void * dest)
131 if(dest != NULL) 131 if(dest != NULL)
132 { 132 {
133 ev->evData = readData(file, ev->len); 133 ev->evData = readData(file, ev->len);
134 printf("\nDATA: <%s>", ev->evData); 134/* printf("\nDATA: <%s>", ev->evData); */
135 } 135 }
136 else 136 else
137 { 137 {
@@ -173,11 +173,9 @@ int readEvent(int file, void * dest)
173 return 1; 173 return 1;
174} 174}
175 175
176
177
178struct Track * readTrack(int file) 176struct Track * readTrack(int file)
179{ 177{
180 struct Track * trk = (struct Track *)allocate(sizeof(struct Track)); 178 struct Track * trk = (struct Track *)malloc(sizeof(struct Track));
181 rb->memset(trk, 0, sizeof(struct Track)); 179 rb->memset(trk, 0, sizeof(struct Track));
182 180
183 trk->size = readFourBytes(file); 181 trk->size = readFourBytes(file);
@@ -194,7 +192,7 @@ struct Track * readTrack(int file)
194 rb->lseek(file, pos, SEEK_SET); 192 rb->lseek(file, pos, SEEK_SET);
195 193
196 int trackSize = (numEvents+1) * sizeof(struct Event); 194 int trackSize = (numEvents+1) * sizeof(struct Event);
197 void * dataPtr = allocate(trackSize); 195 void * dataPtr = malloc(trackSize);
198 trk->dataBlock = dataPtr; 196 trk->dataBlock = dataPtr;
199 197
200 numEvents=0; 198 numEvents=0;