Mercurial > audlegacy-plugins
comparison src/adplug/core/ksm.cxx @ 955:4709ce4e209e trunk
[svn] Run indent -ts4 -nut -bli0 -cdw on this messy lot. Upstream is not consistent with whitespace anyway, no loss there.
author | chainsaw |
---|---|
date | Sat, 14 Apr 2007 15:23:50 -0700 |
parents | cae46214b8bf |
children | fa9f85cebade |
comparison
equal
deleted
inserted
replaced
954:d7a6fd179cd2 | 955:4709ce4e209e |
---|---|
22 #include <string.h> | 22 #include <string.h> |
23 | 23 |
24 #include "ksm.h" | 24 #include "ksm.h" |
25 #include "debug.h" | 25 #include "debug.h" |
26 | 26 |
27 const unsigned int CksmPlayer::adlibfreq[63] = { | 27 const unsigned int |
28 0, | 28 CksmPlayer::adlibfreq[63] = { |
29 2390,2411,2434,2456,2480,2506,2533,2562,2592,2625,2659,2695, | 29 0, |
30 3414,3435,3458,3480,3504,3530,3557,3586,3616,3649,3683,3719, | 30 2390, 2411, 2434, 2456, 2480, 2506, 2533, 2562, 2592, 2625, 2659, 2695, |
31 4438,4459,4482,4504,4528,4554,4581,4610,4640,4673,4707,4743, | 31 3414, 3435, 3458, 3480, 3504, 3530, 3557, 3586, 3616, 3649, 3683, 3719, |
32 5462,5483,5506,5528,5552,5578,5605,5634,5664,5697,5731,5767, | 32 4438, 4459, 4482, 4504, 4528, 4554, 4581, 4610, 4640, 4673, 4707, 4743, |
33 6486,6507,6530,6552,6576,6602,6629,6658,6688,6721,6755,6791, | 33 5462, 5483, 5506, 5528, 5552, 5578, 5605, 5634, 5664, 5697, 5731, 5767, |
34 7510}; | 34 6486, 6507, 6530, 6552, 6576, 6602, 6629, 6658, 6688, 6721, 6755, 6791, |
35 7510 | |
36 }; | |
35 | 37 |
36 /*** public methods **************************************/ | 38 /*** public methods **************************************/ |
37 | 39 |
38 CPlayer *CksmPlayer::factory(Copl *newopl) | 40 CPlayer * |
39 { | 41 CksmPlayer::factory (Copl * newopl) |
40 return new CksmPlayer(newopl); | 42 { |
41 } | 43 return new CksmPlayer (newopl); |
42 | 44 } |
43 bool CksmPlayer::load(VFSFile *fd, const CFileProvider &fp) | 45 |
44 { | 46 bool |
45 binistream *f; | 47 CksmPlayer::load (VFSFile * fd, const CFileProvider & fp) |
46 int i; | 48 { |
47 std::string filename(fd->uri); | 49 binistream *f; |
48 char *fn = new char[filename.length() + 9]; | 50 int i; |
51 std::string filename (fd->uri); | |
52 char *fn = new char[filename.length () + 9]; | |
49 | 53 |
50 // file validation section | 54 // file validation section |
51 if(!fp.extension(filename, ".ksm")) { | 55 if (!fp.extension (filename, ".ksm")) |
52 AdPlug_LogWrite("CksmPlayer::load(,\"%s\"): File doesn't have '.ksm' " | 56 { |
53 "extension! Rejected!\n", filename.c_str()); | 57 AdPlug_LogWrite ("CksmPlayer::load(,\"%s\"): File doesn't have '.ksm' " |
58 "extension! Rejected!\n", filename.c_str ()); | |
54 return false; | 59 return false; |
55 } | 60 } |
56 AdPlug_LogWrite("*** CksmPlayer::load(,\"%s\") ***\n", filename.c_str()); | 61 AdPlug_LogWrite ("*** CksmPlayer::load(,\"%s\") ***\n", filename.c_str ()); |
57 | 62 |
58 // Load instruments from 'insts.dat' | 63 // Load instruments from 'insts.dat' |
59 strcpy(fn, filename.c_str()); | 64 strcpy (fn, filename.c_str ()); |
60 for(i = strlen(fn) - 1; i >= 0; i--) | 65 for (i = strlen (fn) - 1; i >= 0; i--) |
61 if(fn[i] == '/' || fn[i] == '\\') | 66 if (fn[i] == '/' || fn[i] == '\\') |
62 break; | 67 break; |
63 strcpy(fn + i + 1, "insts.dat"); | 68 strcpy (fn + i + 1, "insts.dat"); |
64 AdPlug_LogWrite("Instruments file: \"%s\"\n", fn); | 69 AdPlug_LogWrite ("Instruments file: \"%s\"\n", fn); |
65 VFSFile *instfd = vfs_fopen(fn, "rb"); | 70 VFSFile *instfd = vfs_fopen (fn, "rb"); |
66 f = fp.open(instfd); | 71 f = fp.open (instfd); |
67 delete [] fn; | 72 delete[]fn; |
68 if(!f) { | 73 if (!f) |
69 AdPlug_LogWrite("Couldn't open instruments file! Aborting!\n"); | 74 { |
70 AdPlug_LogWrite("--- CksmPlayer::load ---\n"); | 75 AdPlug_LogWrite ("Couldn't open instruments file! Aborting!\n"); |
76 AdPlug_LogWrite ("--- CksmPlayer::load ---\n"); | |
71 return false; | 77 return false; |
72 } | 78 } |
73 loadinsts(f); | 79 loadinsts (f); |
74 fp.close(f); | 80 fp.close (f); |
75 vfs_fclose(instfd); | 81 vfs_fclose (instfd); |
76 | 82 |
77 f = fp.open(fd); if(!f) return false; | 83 f = fp.open (fd); |
78 for(i = 0; i < 16; i++) trinst[i] = f->readInt(1); | 84 if (!f) |
79 for(i = 0; i < 16; i++) trquant[i] = f->readInt(1); | 85 return false; |
80 for(i = 0; i < 16; i++) trchan[i] = f->readInt(1); | 86 for (i = 0; i < 16; i++) |
81 f->ignore(16); | 87 trinst[i] = f->readInt (1); |
82 for(i = 0; i < 16; i++) trvol[i] = f->readInt(1); | 88 for (i = 0; i < 16; i++) |
83 numnotes = f->readInt(2); | 89 trquant[i] = f->readInt (1); |
84 note = new unsigned long [numnotes]; | 90 for (i = 0; i < 16; i++) |
85 for(i = 0; i < numnotes; i++) note[i] = f->readInt(4); | 91 trchan[i] = f->readInt (1); |
86 fp.close(f); | 92 f->ignore (16); |
87 | 93 for (i = 0; i < 16; i++) |
88 if(!trchan[11]) { | 94 trvol[i] = f->readInt (1); |
95 numnotes = f->readInt (2); | |
96 note = new unsigned long[numnotes]; | |
97 for (i = 0; i < numnotes; i++) | |
98 note[i] = f->readInt (4); | |
99 fp.close (f); | |
100 | |
101 if (!trchan[11]) | |
102 { | |
89 drumstat = 0; | 103 drumstat = 0; |
90 numchans = 9; | 104 numchans = 9; |
91 } else { | 105 } |
106 else | |
107 { | |
92 drumstat = 32; | 108 drumstat = 32; |
93 numchans = 6; | 109 numchans = 6; |
94 } | 110 } |
95 | 111 |
96 rewind(0); | 112 rewind (0); |
97 AdPlug_LogWrite("--- CksmPlayer::load ---\n"); | 113 AdPlug_LogWrite ("--- CksmPlayer::load ---\n"); |
98 return true; | 114 return true; |
99 } | 115 } |
100 | 116 |
101 bool CksmPlayer::update() | 117 bool |
102 { | 118 CksmPlayer::update () |
103 int quanter,chan,drumnum,freq,track,volevel,volval; | 119 { |
104 unsigned int i,j,bufnum; | 120 int quanter, chan, drumnum, freq, track, volevel, volval; |
105 unsigned long temp,templong; | 121 unsigned int i, j, bufnum; |
106 | 122 unsigned long temp, templong; |
107 count++; | 123 |
108 if (count >= countstop) | 124 count++; |
109 { | 125 if (count >= countstop) |
110 bufnum = 0; | 126 { |
111 while (count >= countstop) | 127 bufnum = 0; |
112 { | 128 while (count >= countstop) |
113 templong = note[nownote]; | 129 { |
114 track = (int)((templong>>8)&15); | 130 templong = note[nownote]; |
115 if ((templong&192) == 0) | 131 track = (int) ((templong >> 8) & 15); |
116 { | 132 if ((templong & 192) == 0) |
117 i = 0; | 133 { |
118 | 134 i = 0; |
119 while ((i < numchans) && | 135 |
120 ((chanfreq[i] != (templong&63)) || | 136 while ((i < numchans) && |
121 (chantrack[i] != ((templong>>8)&15)))) | 137 ((chanfreq[i] != (templong & 63)) || |
122 i++; | 138 (chantrack[i] != ((templong >> 8) & 15)))) |
123 if (i < numchans) | 139 i++; |
124 { | 140 if (i < numchans) |
125 databuf[bufnum] = (char)0; bufnum++; | 141 { |
126 databuf[bufnum] = (unsigned char)(0xb0+i); bufnum++; | 142 databuf[bufnum] = (char) 0; |
127 databuf[bufnum] = (unsigned char)((adlibfreq[templong&63]>>8)&223); bufnum++; | 143 bufnum++; |
128 chanfreq[i] = 0; | 144 databuf[bufnum] = (unsigned char) (0xb0 + i); |
129 chanage[i] = 0; | 145 bufnum++; |
130 } | 146 databuf[bufnum] = |
131 } | 147 (unsigned char) ((adlibfreq[templong & 63] >> 8) & 223); |
132 else | 148 bufnum++; |
133 { | 149 chanfreq[i] = 0; |
134 volevel = trvol[track]; | 150 chanage[i] = 0; |
135 if ((templong&192) == 128) | 151 } |
136 { | 152 } |
137 volevel -= 4; | 153 else |
138 if (volevel < 0) | 154 { |
139 volevel = 0; | 155 volevel = trvol[track]; |
140 } | 156 if ((templong & 192) == 128) |
141 if ((templong&192) == 192) | 157 { |
142 { | 158 volevel -= 4; |
143 volevel += 4; | 159 if (volevel < 0) |
144 if (volevel > 63) | 160 volevel = 0; |
145 volevel = 63; | 161 } |
146 } | 162 if ((templong & 192) == 192) |
147 if (track < 11) | 163 { |
148 { | 164 volevel += 4; |
149 temp = 0; | 165 if (volevel > 63) |
150 i = numchans; | 166 volevel = 63; |
151 for(j=0;j<numchans;j++) | 167 } |
152 if ((countstop - chanage[j] >= temp) && (chantrack[j] == track)) | 168 if (track < 11) |
153 { | 169 { |
154 temp = countstop - chanage[j]; | 170 temp = 0; |
155 i = j; | 171 i = numchans; |
156 } | 172 for (j = 0; j < numchans; j++) |
157 if (i < numchans) | 173 if ((countstop - chanage[j] >= temp) && (chantrack[j] == track)) |
158 { | 174 { |
159 databuf[bufnum] = (char)0, bufnum++; | 175 temp = countstop - chanage[j]; |
160 databuf[bufnum] = (unsigned char)(0xb0+i); bufnum++; | 176 i = j; |
161 databuf[bufnum] = (unsigned char)0; bufnum++; | 177 } |
162 volval = (inst[trinst[track]][1]&192)+(volevel^63); | 178 if (i < numchans) |
163 databuf[bufnum] = (char)0, bufnum++; | 179 { |
164 databuf[bufnum] = (unsigned char)(0x40+op_table[i]+3); bufnum++; | 180 databuf[bufnum] = (char) 0, bufnum++; |
165 databuf[bufnum] = (unsigned char)volval; bufnum++; | 181 databuf[bufnum] = (unsigned char) (0xb0 + i); |
166 databuf[bufnum] = (char)0, bufnum++; | 182 bufnum++; |
167 databuf[bufnum] = (unsigned char)(0xa0+i); bufnum++; | 183 databuf[bufnum] = (unsigned char) 0; |
168 databuf[bufnum] = (unsigned char)(adlibfreq[templong&63]&255); bufnum++; | 184 bufnum++; |
169 databuf[bufnum] = (char)0, bufnum++; | 185 volval = (inst[trinst[track]][1] & 192) + (volevel ^ 63); |
170 databuf[bufnum] = (unsigned char)(0xb0+i); bufnum++; | 186 databuf[bufnum] = (char) 0, bufnum++; |
171 databuf[bufnum] = (unsigned char)((adlibfreq[templong&63]>>8)|32); bufnum++; | 187 databuf[bufnum] = (unsigned char) (0x40 + op_table[i] + 3); |
172 chanfreq[i] = templong&63; | 188 bufnum++; |
173 chanage[i] = countstop; | 189 databuf[bufnum] = (unsigned char) volval; |
174 } | 190 bufnum++; |
175 } | 191 databuf[bufnum] = (char) 0, bufnum++; |
176 else if ((drumstat&32) > 0) | 192 databuf[bufnum] = (unsigned char) (0xa0 + i); |
177 { | 193 bufnum++; |
178 freq = adlibfreq[templong&63]; | 194 databuf[bufnum] = |
179 switch(track) | 195 (unsigned char) (adlibfreq[templong & 63] & 255); |
180 { | 196 bufnum++; |
181 case 11: drumnum = 16; chan = 6; freq -= 2048; break; | 197 databuf[bufnum] = (char) 0, bufnum++; |
182 case 12: drumnum = 8; chan = 7; freq -= 2048; break; | 198 databuf[bufnum] = (unsigned char) (0xb0 + i); |
183 case 13: drumnum = 4; chan = 8; break; | 199 bufnum++; |
184 case 14: drumnum = 2; chan = 8; break; | 200 databuf[bufnum] = |
185 case 15: drumnum = 1; chan = 7; freq -= 2048; break; | 201 (unsigned char) ((adlibfreq[templong & 63] >> 8) | 32); |
186 } | 202 bufnum++; |
187 databuf[bufnum] = (char)0, bufnum++; | 203 chanfreq[i] = templong & 63; |
188 databuf[bufnum] = (unsigned char)(0xa0+chan); bufnum++; | 204 chanage[i] = countstop; |
189 databuf[bufnum] = (unsigned char)(freq&255); bufnum++; | 205 } |
190 databuf[bufnum] = (char)0, bufnum++; | 206 } |
191 databuf[bufnum] = (unsigned char)(0xb0+chan); bufnum++; | 207 else if ((drumstat & 32) > 0) |
192 databuf[bufnum] = (unsigned char)((freq>>8)&223); bufnum++; | 208 { |
193 databuf[bufnum] = (char)0, bufnum++; | 209 freq = adlibfreq[templong & 63]; |
194 databuf[bufnum] = (unsigned char)(0xbd); bufnum++; | 210 switch (track) |
195 databuf[bufnum] = (unsigned char)(drumstat&(255-drumnum)); bufnum++; | 211 { |
196 drumstat |= drumnum; | 212 case 11: |
197 if ((track == 11) || (track == 12) || (track == 14)) | 213 drumnum = 16; |
198 { | 214 chan = 6; |
199 volval = (inst[trinst[track]][1]&192)+(volevel^63); | 215 freq -= 2048; |
200 databuf[bufnum] = (char)0, bufnum++; | 216 break; |
201 databuf[bufnum] = (unsigned char)(0x40+op_table[chan]+3); bufnum++; | 217 case 12: |
202 databuf[bufnum] = (unsigned char)(volval); bufnum++; | 218 drumnum = 8; |
203 } | 219 chan = 7; |
204 else | 220 freq -= 2048; |
205 { | 221 break; |
206 volval = (inst[trinst[track]][6]&192)+(volevel^63); | 222 case 13: |
207 databuf[bufnum] = (char)0, bufnum++; | 223 drumnum = 4; |
208 databuf[bufnum] = (unsigned char)(0x40+op_table[chan]); bufnum++; | 224 chan = 8; |
209 databuf[bufnum] = (unsigned char)(volval); bufnum++; | 225 break; |
210 } | 226 case 14: |
211 databuf[bufnum] = (char)0, bufnum++; | 227 drumnum = 2; |
212 databuf[bufnum] = (unsigned char)(0xbd); bufnum++; | 228 chan = 8; |
213 databuf[bufnum] = (unsigned char)(drumstat); bufnum++; | 229 break; |
214 } | 230 case 15: |
215 } | 231 drumnum = 1; |
216 nownote++; | 232 chan = 7; |
217 if (nownote >= numnotes) { | 233 freq -= 2048; |
218 nownote = 0; | 234 break; |
219 songend = true; | 235 } |
220 } | 236 databuf[bufnum] = (char) 0, bufnum++; |
221 templong = note[nownote]; | 237 databuf[bufnum] = (unsigned char) (0xa0 + chan); |
222 if (nownote == 0) | 238 bufnum++; |
223 count = (templong>>12)-1; | 239 databuf[bufnum] = (unsigned char) (freq & 255); |
224 quanter = (240/trquant[(templong>>8)&15]); | 240 bufnum++; |
225 countstop = (((templong>>12)+(quanter>>1)) / quanter) * quanter; | 241 databuf[bufnum] = (char) 0, bufnum++; |
226 } | 242 databuf[bufnum] = (unsigned char) (0xb0 + chan); |
227 for(i=0;i<bufnum;i+=3) | 243 bufnum++; |
228 opl->write(databuf[i+1],databuf[i+2]); | 244 databuf[bufnum] = (unsigned char) ((freq >> 8) & 223); |
229 } | 245 bufnum++; |
230 return !songend; | 246 databuf[bufnum] = (char) 0, bufnum++; |
231 } | 247 databuf[bufnum] = (unsigned char) (0xbd); |
232 | 248 bufnum++; |
233 void CksmPlayer::rewind(int subsong) | 249 databuf[bufnum] = (unsigned char) (drumstat & (255 - drumnum)); |
234 { | 250 bufnum++; |
235 unsigned int i,j,k; | 251 drumstat |= drumnum; |
236 unsigned char instbuf[11]; | 252 if ((track == 11) || (track == 12) || (track == 14)) |
237 unsigned long templong; | 253 { |
238 | 254 volval = (inst[trinst[track]][1] & 192) + (volevel ^ 63); |
239 songend = false; | 255 databuf[bufnum] = (char) 0, bufnum++; |
240 opl->init(); opl->write(1,32); opl->write(4,0); opl->write(8,0); opl->write(0xbd,drumstat); | 256 databuf[bufnum] = (unsigned char) (0x40 + op_table[chan] + 3); |
241 | 257 bufnum++; |
242 if (trchan[11] == 1) { | 258 databuf[bufnum] = (unsigned char) (volval); |
243 for(i=0;i<11;i++) | 259 bufnum++; |
244 instbuf[i] = inst[trinst[11]][i]; | 260 } |
245 instbuf[1] = ((instbuf[1]&192)|(trvol[11])^63); | 261 else |
246 setinst(6,instbuf[0],instbuf[1],instbuf[2],instbuf[3],instbuf[4],instbuf[5],instbuf[6],instbuf[7],instbuf[8],instbuf[9],instbuf[10]); | 262 { |
247 for(i=0;i<5;i++) | 263 volval = (inst[trinst[track]][6] & 192) + (volevel ^ 63); |
248 instbuf[i] = inst[trinst[12]][i]; | 264 databuf[bufnum] = (char) 0, bufnum++; |
249 for(i=5;i<11;i++) | 265 databuf[bufnum] = (unsigned char) (0x40 + op_table[chan]); |
250 instbuf[i] = inst[trinst[15]][i]; | 266 bufnum++; |
251 instbuf[1] = ((instbuf[1]&192)|(trvol[12])^63); | 267 databuf[bufnum] = (unsigned char) (volval); |
252 instbuf[6] = ((instbuf[6]&192)|(trvol[15])^63); | 268 bufnum++; |
253 setinst(7,instbuf[0],instbuf[1],instbuf[2],instbuf[3],instbuf[4],instbuf[5],instbuf[6],instbuf[7],instbuf[8],instbuf[9],instbuf[10]); | 269 } |
254 for(i=0;i<5;i++) | 270 databuf[bufnum] = (char) 0, bufnum++; |
255 instbuf[i] = inst[trinst[14]][i]; | 271 databuf[bufnum] = (unsigned char) (0xbd); |
256 for(i=5;i<11;i++) | 272 bufnum++; |
257 instbuf[i] = inst[trinst[13]][i]; | 273 databuf[bufnum] = (unsigned char) (drumstat); |
258 instbuf[1] = ((instbuf[1]&192)|(trvol[14])^63); | 274 bufnum++; |
259 instbuf[6] = ((instbuf[6]&192)|(trvol[13])^63); | 275 } |
260 setinst(8,instbuf[0],instbuf[1],instbuf[2],instbuf[3],instbuf[4],instbuf[5],instbuf[6],instbuf[7],instbuf[8],instbuf[9],instbuf[10]); | 276 } |
261 } | 277 nownote++; |
262 | 278 if (nownote >= numnotes) |
263 for(i=0;i<numchans;i++) | 279 { |
264 { | 280 nownote = 0; |
265 chantrack[i] = 0; | 281 songend = true; |
266 chanage[i] = 0; | 282 } |
267 } | 283 templong = note[nownote]; |
268 j = 0; | 284 if (nownote == 0) |
269 for(i=0;i<16;i++) | 285 count = (templong >> 12) - 1; |
270 if ((trchan[i] > 0) && (j < numchans)) | 286 quanter = (240 / trquant[(templong >> 8) & 15]); |
271 { | 287 countstop = (((templong >> 12) + (quanter >> 1)) / quanter) * quanter; |
272 k = trchan[i]; | 288 } |
273 while ((j < numchans) && (k > 0)) | 289 for (i = 0; i < bufnum; i += 3) |
274 { | 290 opl->write (databuf[i + 1], databuf[i + 2]); |
275 chantrack[j] = i; | 291 } |
276 k--; | 292 return !songend; |
277 j++; | 293 } |
278 } | 294 |
279 } | 295 void |
280 for(i=0;i<numchans;i++) | 296 CksmPlayer::rewind (int subsong) |
281 { | 297 { |
282 for(j=0;j<11;j++) | 298 unsigned int i, j, k; |
283 instbuf[j] = inst[trinst[chantrack[i]]][j]; | 299 unsigned char instbuf[11]; |
284 instbuf[1] = ((instbuf[1]&192)|(63-trvol[chantrack[i]])); | 300 unsigned long templong; |
285 setinst(i,instbuf[0],instbuf[1],instbuf[2],instbuf[3],instbuf[4],instbuf[5],instbuf[6],instbuf[7],instbuf[8],instbuf[9],instbuf[10]); | 301 |
286 chanfreq[i] = 0; | 302 songend = false; |
287 } | 303 opl->init (); |
288 k = 0; | 304 opl->write (1, 32); |
289 templong = *note; | 305 opl->write (4, 0); |
290 count = (templong>>12)-1; | 306 opl->write (8, 0); |
291 countstop = (templong>>12)-1; | 307 opl->write (0xbd, drumstat); |
292 nownote = 0; | 308 |
293 } | 309 if (trchan[11] == 1) |
294 | 310 { |
295 std::string CksmPlayer::getinstrument(unsigned int n) | 311 for (i = 0; i < 11; i++) |
296 { | 312 instbuf[i] = inst[trinst[11]][i]; |
297 if(trchan[n]) | 313 instbuf[1] = ((instbuf[1] & 192) | (trvol[11]) ^ 63); |
298 return std::string(instname[trinst[n]]); | 314 setinst (6, instbuf[0], instbuf[1], instbuf[2], instbuf[3], instbuf[4], |
299 else | 315 instbuf[5], instbuf[6], instbuf[7], instbuf[8], instbuf[9], |
300 return std::string(); | 316 instbuf[10]); |
317 for (i = 0; i < 5; i++) | |
318 instbuf[i] = inst[trinst[12]][i]; | |
319 for (i = 5; i < 11; i++) | |
320 instbuf[i] = inst[trinst[15]][i]; | |
321 instbuf[1] = ((instbuf[1] & 192) | (trvol[12]) ^ 63); | |
322 instbuf[6] = ((instbuf[6] & 192) | (trvol[15]) ^ 63); | |
323 setinst (7, instbuf[0], instbuf[1], instbuf[2], instbuf[3], instbuf[4], | |
324 instbuf[5], instbuf[6], instbuf[7], instbuf[8], instbuf[9], | |
325 instbuf[10]); | |
326 for (i = 0; i < 5; i++) | |
327 instbuf[i] = inst[trinst[14]][i]; | |
328 for (i = 5; i < 11; i++) | |
329 instbuf[i] = inst[trinst[13]][i]; | |
330 instbuf[1] = ((instbuf[1] & 192) | (trvol[14]) ^ 63); | |
331 instbuf[6] = ((instbuf[6] & 192) | (trvol[13]) ^ 63); | |
332 setinst (8, instbuf[0], instbuf[1], instbuf[2], instbuf[3], instbuf[4], | |
333 instbuf[5], instbuf[6], instbuf[7], instbuf[8], instbuf[9], | |
334 instbuf[10]); | |
335 } | |
336 | |
337 for (i = 0; i < numchans; i++) | |
338 { | |
339 chantrack[i] = 0; | |
340 chanage[i] = 0; | |
341 } | |
342 j = 0; | |
343 for (i = 0; i < 16; i++) | |
344 if ((trchan[i] > 0) && (j < numchans)) | |
345 { | |
346 k = trchan[i]; | |
347 while ((j < numchans) && (k > 0)) | |
348 { | |
349 chantrack[j] = i; | |
350 k--; | |
351 j++; | |
352 } | |
353 } | |
354 for (i = 0; i < numchans; i++) | |
355 { | |
356 for (j = 0; j < 11; j++) | |
357 instbuf[j] = inst[trinst[chantrack[i]]][j]; | |
358 instbuf[1] = ((instbuf[1] & 192) | (63 - trvol[chantrack[i]])); | |
359 setinst (i, instbuf[0], instbuf[1], instbuf[2], instbuf[3], instbuf[4], | |
360 instbuf[5], instbuf[6], instbuf[7], instbuf[8], instbuf[9], | |
361 instbuf[10]); | |
362 chanfreq[i] = 0; | |
363 } | |
364 k = 0; | |
365 templong = *note; | |
366 count = (templong >> 12) - 1; | |
367 countstop = (templong >> 12) - 1; | |
368 nownote = 0; | |
369 } | |
370 | |
371 std::string CksmPlayer::getinstrument (unsigned int n) | |
372 { | |
373 if (trchan[n]) | |
374 return std::string (instname[trinst[n]]); | |
375 else | |
376 return std::string (); | |
301 } | 377 } |
302 | 378 |
303 /*** private methods *************************************/ | 379 /*** private methods *************************************/ |
304 | 380 |
305 void CksmPlayer::loadinsts(binistream *f) | 381 void |
382 CksmPlayer::loadinsts (binistream * f) | |
306 { | 383 { |
307 int i, j; | 384 int i, j; |
308 | 385 |
309 for(i = 0; i < 256; i++) { | 386 for (i = 0; i < 256; i++) |
310 f->readString(instname[i], 20); | 387 { |
311 for(j = 0; j < 11; j++) inst[i][j] = f->readInt(1); | 388 f->readString (instname[i], 20); |
312 f->ignore(2); | 389 for (j = 0; j < 11; j++) |
313 } | 390 inst[i][j] = f->readInt (1); |
314 } | 391 f->ignore (2); |
315 | 392 } |
316 void CksmPlayer::setinst(int chan, | 393 } |
317 unsigned char v0,unsigned char v1,unsigned char v2, | 394 |
318 unsigned char v3,unsigned char v4,unsigned char v5, | 395 void |
319 unsigned char v6,unsigned char v7,unsigned char v8, | 396 CksmPlayer::setinst (int chan, |
320 unsigned char v9,unsigned char v10) | 397 unsigned char v0, unsigned char v1, unsigned char v2, |
321 { | 398 unsigned char v3, unsigned char v4, unsigned char v5, |
322 int offs; | 399 unsigned char v6, unsigned char v7, unsigned char v8, |
323 | 400 unsigned char v9, unsigned char v10) |
324 opl->write(0xa0+chan,0); | 401 { |
325 opl->write(0xb0+chan,0); | 402 int offs; |
326 opl->write(0xc0+chan,v10); | 403 |
327 offs = op_table[chan]; | 404 opl->write (0xa0 + chan, 0); |
328 opl->write(0x20+offs,v5); | 405 opl->write (0xb0 + chan, 0); |
329 opl->write(0x40+offs,v6); | 406 opl->write (0xc0 + chan, v10); |
330 opl->write(0x60+offs,v7); | 407 offs = op_table[chan]; |
331 opl->write(0x80+offs,v8); | 408 opl->write (0x20 + offs, v5); |
332 opl->write(0xe0+offs,v9); | 409 opl->write (0x40 + offs, v6); |
333 offs+=3; | 410 opl->write (0x60 + offs, v7); |
334 opl->write(0x20+offs,v0); | 411 opl->write (0x80 + offs, v8); |
335 opl->write(0x40+offs,v1); | 412 opl->write (0xe0 + offs, v9); |
336 opl->write(0x60+offs,v2); | 413 offs += 3; |
337 opl->write(0x80+offs,v3); | 414 opl->write (0x20 + offs, v0); |
338 opl->write(0xe0+offs,v4); | 415 opl->write (0x40 + offs, v1); |
339 } | 416 opl->write (0x60 + offs, v2); |
417 opl->write (0x80 + offs, v3); | |
418 opl->write (0xe0 + offs, v4); | |
419 } |