summaryrefslogtreecommitdiff
path: root/apps/plugins/midi
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/midi')
-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
4 files changed, 43 insertions, 14 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