blob: 2172072eb15742f8fd80cfda2d4be3f2197386ab [file] [log] [blame]
Stepan Moskovchenko215e4922005-04-15 06:08:55 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2005 Stepan Moskovchenko
10 *
11 * All files in this archive are subject to the GNU General Public License.
12 * See the file COPYING in the source tree root for full license agreement.
13 *
14 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
15 * KIND, either express or implied.
16 *
17 ****************************************************************************/
18
19
20extern struct plugin_api * rb;
21
22unsigned int readWord(int file)
23{
24 return (readChar(file)<<0) | (readChar(file)<<8); // | (readChar(file)<<8) | (readChar(file)<<0);
25}
26
27unsigned int readDWord(int file)
28{
29 return (readChar(file)<<0) | (readChar(file)<<8) | (readChar(file)<<16) | (readChar(file)<<24);
30}
31
32struct GWaveform * loadWaveform(int file)
33{
34 struct GWaveform * wav = (struct GWaveform *)allocate(sizeof(struct GWaveform));
35 rb->memset(wav, 0, sizeof(struct GWaveform));
36
37 wav->name=readData(file, 7);
38 printf("\nWAVE NAME = [%s]", wav->name);
39 wav->fractions=readChar(file);
40 wav->wavSize=readDWord(file);
41 wav->startLoop=readDWord(file);
42 wav->endLoop=readDWord(file);
43 wav->sampRate=readWord(file);
44
45 wav->lowFreq=readDWord(file);
46 wav->highFreq=readDWord(file);
47 wav->rootFreq=readDWord(file);
48
49 wav->tune=readWord(file);
50
51 wav->balance=readChar(file);
52 wav->envRate=readData(file, 6);
53 wav->envOffset=readData(file, 6);
54
55 wav->tremSweep=readChar(file);
56 wav->tremRate==readChar(file);
57 wav->tremDepth=readChar(file);
58 wav->vibSweep=readChar(file);
59 wav->vibRate=readChar(file);
60 wav->vibDepth=readChar(file);
61 wav->mode=readChar(file);
62
63 wav->scaleFreq=readWord(file);
64 wav->scaleFactor=readWord(file);
65 printf("\nScaleFreq = %d ScaleFactor = %d RootFreq = %d", wav->scaleFreq, wav->scaleFactor, wav->rootFreq);
66 wav->res=readData(file, 36);
67 wav->data=readData(file, wav->wavSize);
68
Stepan Moskovchenko1f5fb992005-04-19 15:57:07 +000069 wav->numSamples = wav->wavSize / 2;
Stepan Moskovchenko4b773c02005-04-16 03:35:20 +000070 int a=0;
71
Stepan Moskovchenko1f5fb992005-04-19 15:57:07 +000072 return wav;
73 if(wav->mode & 1 == 0) //Whoops, 8 bit
74 {
75 wav->numSamples = wav->wavSize;
76
77 //Allocate a block for the rest of it
78 //It should end up right after the previous one.
79 wav->wavSize = wav->wavSize * 2;
80 void * foo = allocate(wav->wavSize);
81
82
83 for(a=0; a<1000; a++)
84 printf("\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
85
86
87 for(a=wav->wavSize-1; a>0; a-=2)
88 {
89
90 }
91 // int b1=wf->data[s]+((wf->mode & 2) << 6);
92 // return b1<<8;
93 }
94
95 /*
96//#if !defined(SIMULATOR)
97 for(a=0; a<wav->wavSize; a+=2)
98 {
99 unsigned char tmp;
100 tmp = wav->data[2*a];
101 wav->data[2*a] = wav->data[2*a+1];
102 wav->data[2*a+1] = tmp;
103 }
104//#endif
105
106 if(wav->mode & 2)
107 {
108 for(a=0; a<wav->wavSize/2; a++)
109 {
110 ((short *) wav->data)[a] = ((short *) wav->data)[a] - 32767;
111 }
112 }
113*/
114
115
116
Stepan Moskovchenko4b773c02005-04-16 03:35:20 +0000117 //If we have a 16 bit waveform
Stepan Moskovchenko1f5fb992005-04-19 15:57:07 +0000118/* if(wav->mode & 1 && (wav->mode & 2))
Stepan Moskovchenko4b773c02005-04-16 03:35:20 +0000119 {
120 for(a=0; a<wav->wavSize; a+=2) //Convert it to
121 {
Stepan Moskovchenko1f5fb992005-04-19 15:57:07 +0000122 wav->data[a]=wav->data[a]+(1 << 7);
Stepan Moskovchenko4b773c02005-04-16 03:35:20 +0000123 wav->data[a|1]=wav->data[(a)|1]+(1 << 7);
124 }
125 }
Stepan Moskovchenko1f5fb992005-04-19 15:57:07 +0000126*/
Stepan Moskovchenko215e4922005-04-15 06:08:55 +0000127 return wav;
128}
129
130
131
132int selectWaveform(struct GPatch * pat, int midiNote)
133{
134 int tabFreq = gustable[midiNote]/100; //Comparison
135 int a=0;
136 for(a=0; a<pat->numWaveforms; a++)
137 {
138 if(pat->waveforms[a]->lowFreq/100 <= tabFreq &&
139 pat->waveforms[a]->highFreq/100 >= tabFreq)
140 {
141 return a;
142 }
143 }
144 return 0;
145}
146
147
148struct GPatch * gusload(char * filename)
149{
150 struct GPatch * gp = (struct GPatch *)allocate(sizeof(struct GPatch));
151 rb->memset(gp, 0, sizeof(struct GPatch));
152
153 int file = rb->open(filename, O_RDONLY);
154
Stepan Moskovchenko58112142005-04-15 20:27:04 +0000155 if(file == -1)
156 {
157 char message[50];
Daniel Stenbergcdd35ba2005-04-15 21:17:01 +0000158 rb->snprintf(message, 50, "Error opening %s", filename);
Stepan Moskovchenko58112142005-04-15 20:27:04 +0000159 rb->splash(HZ*2, true, message);
160 return NULL;
161 }
162
Stepan Moskovchenko215e4922005-04-15 06:08:55 +0000163 gp->header=readData(file, 12);
164 gp->gravisid=readData(file, 10);
165 gp->desc=readData(file, 60);
166 gp->inst=readChar(file);
167 gp->voc=readChar(file);
168 gp->chan=readChar(file);
169 gp->numWaveforms=readWord(file); //readWord(file);
170 gp->vol=readWord(file);
171 gp->datSize=readDWord(file);
172 gp->res=readData(file, 36);
173
174 gp->instrID=readWord(file);
175 gp->instrName=readData(file,16);
176 gp->instrSize=readDWord(file);
177 gp->layers=readChar(file);
178 gp->instrRes=readData(file,40);
179
180
181 gp->layerDup=readChar(file);
182 gp->layerID=readChar(file);
183 gp->layerSize=readDWord(file);
184 gp->numWaves=readChar(file);
185 gp->layerRes=readData(file,40);
186
187/* printf("\n%s\n%s\n%s", gp->header, gp->gravisid, gp->desc);
188 printf("\nInst = %d", gp->inst);
189 printf("\nVoc = %d", gp->voc);
190 printf("\nChan = %d", gp->chan);
191 printf("\nWav = %d", gp->numWaveforms);
192 printf("\nVol = %d", gp->vol);
193 printf("\nSize = %d", gp->datSize);
194
195 printf("\n\ninstrID = %d", gp->instrID);
196 printf("\ninstrName = %s", gp->instrName);
197// printf("\ninstrSize = %d", gp->instrSize);
198// printf("\nlayers = %d", gp->layers);
199*/
200 printf("\nFILE: %s", filename);
201 printf("\nlayerSamples=%d", gp->numWaves);
202
203 int a=0;
204 for(a=0; a<gp->numWaves; a++)
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}