summaryrefslogtreecommitdiff
path: root/apps/plugins/midi/guspat.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/midi/guspat.c')
-rw-r--r--apps/plugins/midi/guspat.c327
1 files changed, 153 insertions, 174 deletions
diff --git a/apps/plugins/midi/guspat.c b/apps/plugins/midi/guspat.c
index 2172072eb1..23b6811542 100644
--- a/apps/plugins/midi/guspat.c
+++ b/apps/plugins/midi/guspat.c
@@ -21,197 +21,176 @@ extern struct plugin_api * rb;
21 21
22unsigned int readWord(int file) 22unsigned int readWord(int file)
23{ 23{
24 return (readChar(file)<<0) | (readChar(file)<<8); // | (readChar(file)<<8) | (readChar(file)<<0); 24 return (readChar(file)<<0) | (readChar(file)<<8); // | (readChar(file)<<8) | (readChar(file)<<0);
25} 25}
26 26
27unsigned int readDWord(int file) 27unsigned int readDWord(int file)
28{ 28{
29 return (readChar(file)<<0) | (readChar(file)<<8) | (readChar(file)<<16) | (readChar(file)<<24); 29 return (readChar(file)<<0) | (readChar(file)<<8) | (readChar(file)<<16) | (readChar(file)<<24);
30} 30}
31 31
32struct GWaveform * loadWaveform(int file) 32struct GWaveform * loadWaveform(int file)
33{ 33{
34 struct GWaveform * wav = (struct GWaveform *)allocate(sizeof(struct GWaveform)); 34 struct GWaveform * wav = (struct GWaveform *)allocate(sizeof(struct GWaveform));
35 rb->memset(wav, 0, sizeof(struct GWaveform)); 35 rb->memset(wav, 0, sizeof(struct GWaveform));
36 36
37 wav->name=readData(file, 7); 37 wav->name=readData(file, 7);
38 printf("\nWAVE NAME = [%s]", wav->name); 38 printf("\nWAVE NAME = [%s]", wav->name);
39 wav->fractions=readChar(file); 39 wav->fractions=readChar(file);
40 wav->wavSize=readDWord(file); 40 wav->wavSize=readDWord(file);
41 wav->startLoop=readDWord(file); 41 wav->startLoop=readDWord(file);
42 wav->endLoop=readDWord(file); 42 wav->endLoop=readDWord(file);
43 wav->sampRate=readWord(file); 43 wav->sampRate=readWord(file);
44 44
45 wav->lowFreq=readDWord(file); 45 wav->lowFreq=readDWord(file);
46 wav->highFreq=readDWord(file); 46 wav->highFreq=readDWord(file);
47 wav->rootFreq=readDWord(file); 47 wav->rootFreq=readDWord(file);
48 48
49 wav->tune=readWord(file); 49 wav->tune=readWord(file);
50 50
51 wav->balance=readChar(file); 51 wav->balance=readChar(file);
52 wav->envRate=readData(file, 6); 52 wav->envRate=readData(file, 6);
53 wav->envOffset=readData(file, 6); 53 wav->envOffset=readData(file, 6);
54 54
55 wav->tremSweep=readChar(file); 55 wav->tremSweep=readChar(file);
56 wav->tremRate==readChar(file); 56 wav->tremRate==readChar(file);
57 wav->tremDepth=readChar(file); 57 wav->tremDepth=readChar(file);
58 wav->vibSweep=readChar(file); 58 wav->vibSweep=readChar(file);
59 wav->vibRate=readChar(file); 59 wav->vibRate=readChar(file);
60 wav->vibDepth=readChar(file); 60 wav->vibDepth=readChar(file);
61 wav->mode=readChar(file); 61 wav->mode=readChar(file);
62 62
63 wav->scaleFreq=readWord(file); 63 wav->scaleFreq=readWord(file);
64 wav->scaleFactor=readWord(file); 64 wav->scaleFactor=readWord(file);
65 printf("\nScaleFreq = %d ScaleFactor = %d RootFreq = %d", wav->scaleFreq, wav->scaleFactor, wav->rootFreq); 65 printf("\nScaleFreq = %d ScaleFactor = %d RootFreq = %d", wav->scaleFreq, wav->scaleFactor, wav->rootFreq);
66 wav->res=readData(file, 36); 66 wav->res=readData(file, 36);
67 wav->data=readData(file, wav->wavSize); 67 wav->data=readData(file, wav->wavSize);
68 68
69 wav->numSamples = wav->wavSize / 2; 69 wav->numSamples = wav->wavSize / 2;
70 int a=0; 70 wav->startLoop = wav->startLoop >> 1;
71 71 wav->endLoop = wav->endLoop >> 1;
72 return wav; 72 unsigned int a=0;
73 if(wav->mode & 1 == 0) //Whoops, 8 bit 73
74 { 74 /* half baked 8 bit conversion UNFINISHED*/
75 wav->numSamples = wav->wavSize; 75 /*
76 76 if(wav->mode & 1 == 0) //Whoops, 8 bit
77 //Allocate a block for the rest of it 77 {
78 //It should end up right after the previous one. 78 wav->numSamples = wav->wavSize;
79 wav->wavSize = wav->wavSize * 2; 79
80 void * foo = allocate(wav->wavSize); 80 //Allocate a block for the rest of it
81 81 //It should end up right after the previous one.
82 82 wav->wavSize = wav->wavSize * 2;
83 for(a=0; a<1000; a++) 83 void * foo = allocate(wav->wavSize);
84 printf("\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); 84
85 85
86 86 for(a=0; a<1000; a++)
87 for(a=wav->wavSize-1; a>0; a-=2) 87 printf("\n!!!!!!!!!!!!!!!!!!!!!!!!!!!");
88 { 88
89 89
90 } 90 for(a=wav->wavSize-1; a>0; a-=2)
91 // int b1=wf->data[s]+((wf->mode & 2) << 6); 91 {
92 // return b1<<8; 92
93 } 93 }
94 94 // int b1=wf->data[s]+((wf->mode & 2) << 6);
95 /* 95 // return b1<<8;
96//#if !defined(SIMULATOR) 96 }
97 for(a=0; a<wav->wavSize; a+=2) 97 */
98 { 98
99 unsigned char tmp; 99
100 tmp = wav->data[2*a]; 100 /* Iriver needs byteswapping.. big endian, go figure. Gus files are little endian */
101 wav->data[2*a] = wav->data[2*a+1]; 101
102 wav->data[2*a+1] = tmp; 102#if !defined(SIMULATOR)
103 } 103 for(a=0; a<wav->numSamples; a++)
104//#endif 104 {
105 105 ((unsigned short *) wav->data)[a] = SWAB16(((unsigned short *) wav->data)[a]);
106 if(wav->mode & 2) 106 }
107 { 107#endif
108 for(a=0; a<wav->wavSize/2; a++) 108
109 { 109 /* Convert unsigned to signed by subtracting 32768 */
110 ((short *) wav->data)[a] = ((short *) wav->data)[a] - 32767; 110 if(wav->mode & 2)
111 } 111 {
112 } 112 for(a=0; a<wav->numSamples; a++)
113*/ 113 ((short *) wav->data)[a] = ((unsigned short *) wav->data)[a] - 32768;
114 114
115 115 }
116 116
117 //If we have a 16 bit waveform 117 return wav;
118/* if(wav->mode & 1 && (wav->mode & 2))
119 {
120 for(a=0; a<wav->wavSize; a+=2) //Convert it to
121 {
122 wav->data[a]=wav->data[a]+(1 << 7);
123 wav->data[a|1]=wav->data[(a)|1]+(1 << 7);
124 }
125 }
126*/
127 return wav;
128} 118}
129 119
130 120
131 121
132int selectWaveform(struct GPatch * pat, int midiNote) 122int selectWaveform(struct GPatch * pat, int midiNote)
133{ 123{
134 int tabFreq = gustable[midiNote]/100; //Comparison 124 /* We divide by 100 here because everyone's freq formula is slightly different */
135 int a=0; 125 unsigned int tabFreq = gustable[midiNote]/100; /* Comparison */
136 for(a=0; a<pat->numWaveforms; a++) 126 unsigned int a=0;
137 { 127 for(a=0; a<pat->numWaveforms; a++)
138 if(pat->waveforms[a]->lowFreq/100 <= tabFreq && 128 {
139 pat->waveforms[a]->highFreq/100 >= tabFreq) 129 if(pat->waveforms[a]->lowFreq/100 <= tabFreq &&
140 { 130 pat->waveforms[a]->highFreq/100 >= tabFreq)
141 return a; 131 {
142 } 132 return a;
143 } 133 }
144 return 0; 134 }
135 return 0;
145} 136}
146 137
147 138
148struct GPatch * gusload(char * filename) 139struct GPatch * gusload(char * filename)
149{ 140{
150 struct GPatch * gp = (struct GPatch *)allocate(sizeof(struct GPatch)); 141 struct GPatch * gp = (struct GPatch *)allocate(sizeof(struct GPatch));
151 rb->memset(gp, 0, sizeof(struct GPatch)); 142 rb->memset(gp, 0, sizeof(struct GPatch));
152 143
153 int file = rb->open(filename, O_RDONLY); 144 int file = rb->open(filename, O_RDONLY);
154 145
155 if(file == -1) 146 if(file == -1)
156 { 147 {
157 char message[50]; 148 char message[50];
158 rb->snprintf(message, 50, "Error opening %s", filename); 149 rb->snprintf(message, 50, "Error opening %s", filename);
159 rb->splash(HZ*2, true, message); 150 rb->splash(HZ*2, true, message);
160 return NULL; 151 return NULL;
161 } 152 }
162 153
163 gp->header=readData(file, 12); 154 gp->header=readData(file, 12);
164 gp->gravisid=readData(file, 10); 155 gp->gravisid=readData(file, 10);
165 gp->desc=readData(file, 60); 156 gp->desc=readData(file, 60);
166 gp->inst=readChar(file); 157 gp->inst=readChar(file);
167 gp->voc=readChar(file); 158 gp->voc=readChar(file);
168 gp->chan=readChar(file); 159 gp->chan=readChar(file);
169 gp->numWaveforms=readWord(file); //readWord(file); 160 gp->numWaveforms=readWord(file);
170 gp->vol=readWord(file); 161 gp->vol=readWord(file);
171 gp->datSize=readDWord(file); 162 gp->datSize=readDWord(file);
172 gp->res=readData(file, 36); 163 gp->res=readData(file, 36);
173 164
174 gp->instrID=readWord(file); 165 gp->instrID=readWord(file);
175 gp->instrName=readData(file,16); 166 gp->instrName=readData(file,16);
176 gp->instrSize=readDWord(file); 167 gp->instrSize=readDWord(file);
177 gp->layers=readChar(file); 168 gp->layers=readChar(file);
178 gp->instrRes=readData(file,40); 169 gp->instrRes=readData(file,40);
179 170
180 171
181 gp->layerDup=readChar(file); 172 gp->layerDup=readChar(file);
182 gp->layerID=readChar(file); 173 gp->layerID=readChar(file);
183 gp->layerSize=readDWord(file); 174 gp->layerSize=readDWord(file);
184 gp->numWaves=readChar(file); 175 gp->numWaves=readChar(file);
185 gp->layerRes=readData(file,40); 176 gp->layerRes=readData(file,40);
186 177
187/* printf("\n%s\n%s\n%s", gp->header, gp->gravisid, gp->desc); 178
188 printf("\nInst = %d", gp->inst); 179 printf("\nFILE: %s", filename);
189 printf("\nVoc = %d", gp->voc); 180 printf("\nlayerSamples=%d", gp->numWaves);
190 printf("\nChan = %d", gp->chan); 181
191 printf("\nWav = %d", gp->numWaveforms); 182 int a=0;
192 printf("\nVol = %d", gp->vol); 183 for(a=0; a<gp->numWaves; a++)
193 printf("\nSize = %d", gp->datSize); 184 gp->waveforms[a] = loadWaveform(file);
194 185
195 printf("\n\ninstrID = %d", gp->instrID); 186
196 printf("\ninstrName = %s", gp->instrName); 187 printf("\nPrecomputing note table");
197// printf("\ninstrSize = %d", gp->instrSize); 188
198// printf("\nlayers = %d", gp->layers); 189 for(a=0; a<128; a++)
199*/ 190 {
200 printf("\nFILE: %s", filename); 191 gp->noteTable[a] = selectWaveform(gp, a);
201 printf("\nlayerSamples=%d", gp->numWaves); 192 }
202 193 rb->close(file);
203 int a=0; 194
204 for(a=0; a<gp->numWaves; a++) 195 return gp;
205 gp->waveforms[a] = loadWaveform(file);
206
207
208 printf("\nPrecomputing note table");
209
210 for(a=0; a<128; a++)
211 {
212 gp->noteTable[a] = selectWaveform(gp, a);
213 }
214 rb->close(file);
215
216 return gp;
217} 196}