Files: ccbcc93b4e2df83c81f0bf9633f3ab416908e84b / src / syntrax / syntrax.c
76367 bytesRaw
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | static void reset(Player *p) |
13 | { |
14 | int i, j; |
15 | |
16 | if (p->overlapBuff){ |
17 | memset(p->overlapBuff, 0, SE_OVERLAP * 2 *2 + 2); |
18 | } |
19 | |
20 | if (p->delayBufferL && p->delayBufferR){ |
21 | memset(p->delayBufferL, 0, 65536 *2); |
22 | memset(p->delayBufferR, 0, 65536 *2); |
23 | } |
24 | if (p->tuneChannels){ |
25 | for (i = 0; i < SE_MAXCHANS; i++) { |
26 | TuneChannel *tc = &p->tuneChannels[i]; |
27 | Voice *v = &p->voices[i]; |
28 | |
29 | tc->EQMIWERPIF = 0; |
30 | tc->LJHG = 0; |
31 | tc->insNum = -1; |
32 | tc->HFRLJCG = 0; |
33 | tc->ACKCWV = 0; |
34 | tc->ELPHLDR = 0; |
35 | tc->TVORFCC = 0; |
36 | tc->freq = 0; |
37 | tc->BNWIGU = 0; |
38 | tc->UHYDBDDI = 0; |
39 | tc->XESAWSO = 0; |
40 | tc->JOEEPJCI = 0; |
41 | tc->fmDelay = 0; |
42 | tc->sampleBuffer = NULL; |
43 | tc->smpLoopEnd = 0; |
44 | //tc->smpLength = 0; |
45 | tc->sampPos = 0; |
46 | tc->EYRXAB = 0; |
47 | tc->volume = 0; |
48 | tc->panning = 0; |
49 | tc->VNVJPDIWAJQ = 0; |
50 | tc->smpLoopStart = 0; |
51 | tc->hasLoop = 0; |
52 | tc->hasBidiLoop = 0; |
53 | tc->isPlayingBackward = 0; |
54 | tc->hasLooped = 0; |
55 | |
56 | v->waveBuff = p->silentBuffer; |
57 | for (j = 0; j < 4; j++) { |
58 | VoiceEffect *ve = &tc->effects[j]; |
59 | |
60 | ve->QOMCBTRPXF = 0; |
61 | ve->TIPUANVVR = 0; |
62 | ve->MFATTMREMVP = 0; |
63 | ve->MDTMBBIQHRQ = 0; |
64 | ve->RKF = 0; |
65 | ve->DQVLFV = 0; |
66 | ve->ILHG = 0; |
67 | ve->YLKJB = 0; |
68 | ve->VMBNMTNBQU = 0; |
69 | ve->ABJGHAUY = 0; |
70 | ve->SPYK = 0; |
71 | |
72 | } |
73 | memset(&tc->synthBuffers, 0, 0x100 * SE_MAXCHANS *2 + 2); |
74 | } |
75 | } |
76 | } |
77 | |
78 | static int generateTables(Player *p) |
79 | { |
80 | int i, j; |
81 | |
82 | p->dynamorphTable = (int16_t *) malloc(0x100 *2); |
83 | if (!p->dynamorphTable) return -1; |
84 | |
85 | for (i = 0; i < 0x0100; i++ ) { |
86 | p->dynamorphTable[i] = (sin(((M_PI * i) / 128)) * 32760); |
87 | } |
88 | |
89 | //debug Asscilloscope says 0xF8 to 0x61FFB |
90 | //we probably don't have uint24_t at our disposal |
91 | //uint32_t it is, then |
92 | p->freqTable = (uint32_t *) malloc(SE_NROFFINETUNESTEPS * 128 *4); |
93 | if (!p->freqTable) return -1; |
94 | for (i = 0; i < SE_NROFFINETUNESTEPS; i++) { |
95 | double x; |
96 | for (j = 0; j < 128; j++) { |
97 | x = (((j + 3) * 16) - i); |
98 | x = (x / 192); |
99 | x = pow(2, x); |
100 | x = (x * 220) + 0.5; |
101 | p->freqTable[i* 128 + j] = (int)(x); |
102 | } |
103 | } |
104 | |
105 | return 0; |
106 | } |
107 | |
108 | void playerDestroy(Player *p) |
109 | { |
110 | int i; |
111 | |
112 | if (p) { |
113 | if (p->dynamorphTable) free(p->dynamorphTable); |
114 | if (p->freqTable) free(p->freqTable); |
115 | if (p->silentBuffer) free(p->silentBuffer); |
116 | if (p->overlapBuff) free(p->overlapBuff); |
117 | if (p->delayBufferL) free(p->delayBufferL); |
118 | if (p->delayBufferR) free(p->delayBufferR); |
119 | if (p->tuneChannels) free(p->tuneChannels); |
120 | if (p->voices) { |
121 | for (i = 0; i < SE_MAXCHANS; i++) |
122 | { |
123 | resampler_destroy(p->voices[i].resampler[0]); |
124 | resampler_destroy(p->voices[i].resampler[1]); |
125 | } |
126 | free(p->voices); |
127 | } |
128 | |
129 | if (p->instruments) free(p->instruments); |
130 | |
131 | free(p); |
132 | } |
133 | } |
134 | |
135 | Player * playerCreate(int SAMPLEFREQUENCY) |
136 | { |
137 | int i, j; |
138 | |
139 | Player* p; |
140 | |
141 | srand(time(NULL)); |
142 | |
143 | p = (Player *) calloc(1, sizeof(Player)); |
144 | if (!p) return NULL; |
145 | |
146 | p->bufflen = BUFFERLENGTH; |
147 | if (generateTables(p) < 0) goto FAIL; |
148 | |
149 | p->SAMPLEFREQUENCY = SAMPLEFREQUENCY; |
150 | |
151 | p->overlapPos = 0; |
152 | |
153 | p->silentBuffer = malloc(0x0100 *2); |
154 | if (!p->silentBuffer) goto FAIL; |
155 | memset(p->silentBuffer, 0, 0x0100 *2); |
156 | |
157 | p->ISWLKT = 0; |
158 | p->posCoarse = 0; |
159 | p->posFine = 0; |
160 | p->bkpDelayPos = 0; |
161 | p->DONGS = 0; |
162 | p->AMYGPFQCHSW = 0; |
163 | p->selectedSubsong = 0; |
164 | p->PQV = 0; |
165 | p->someCounter = 0; |
166 | p->WDTECTE = 0; |
167 | p->sePmSong = SE_PM_SONG; |
168 | p->AMVM = 0x0100; |
169 | p->channelNumber = 0; |
170 | p->delayPos = 0; |
171 | |
172 | p->otherSamplesPerBeat = 2200; |
173 | p->samplesPerBeat = 2200; |
174 | |
175 | p->overlapBuff = malloc(SE_OVERLAP * 2 *2 + 2); |
176 | if (!p->overlapBuff) goto FAIL; |
177 | p->delayBufferL = malloc(65536 *2); |
178 | if (!p->delayBufferL) goto FAIL; |
179 | p->delayBufferR = malloc(65536 *2); |
180 | if (!p->delayBufferR) goto FAIL; |
181 | |
182 | p->tuneChannels = malloc(SE_MAXCHANS *sizeof(TuneChannel)); |
183 | if (!p->tuneChannels) goto FAIL; |
184 | p->voices = malloc(SE_MAXCHANS *sizeof(Voice)); |
185 | if (!p->voices) goto FAIL; |
186 | |
187 | for (i = 0; i < SE_MAXCHANS; i++) |
188 | { |
189 | Voice *v = &p->voices[i]; |
190 | memset(v, 0, sizeof(Voice)); |
191 | |
192 | v->resampler[0] = resampler_create(); |
193 | v->resampler[1] = resampler_create(); |
194 | if (!v->resampler[0] || !v->resampler[1]) goto FAIL; |
195 | } |
196 | |
197 | reset(p); |
198 | |
199 | return p; |
200 | |
201 | FAIL: |
202 | playerDestroy(p); |
203 | return NULL; |
204 | } |
205 | |
206 | static void instrEffect(Player *p, int chanNum) |
207 | { |
208 | //TODO: minimize all the vars |
209 | //too many of them |
210 | int i, j; |
211 | int _local3; |
212 | int destWave; |
213 | int16_t *destBuff; |
214 | int pos; |
215 | int srcWave1; |
216 | int _local10; |
217 | int srcWave2; |
218 | int16_t *srcBuff1; |
219 | int16_t *srcBuff2; |
220 | double _local16; |
221 | double _local17; |
222 | double _local18; |
223 | int oscWave; |
224 | int16_t *oscBuff; |
225 | int _local21; |
226 | int _local22; |
227 | int _local23; |
228 | int _local25; |
229 | int _local26; |
230 | int _local27; |
231 | int var1; |
232 | int var2; |
233 | double _local30; |
234 | double _local31; |
235 | int _local32; |
236 | int _local33; |
237 | int _local34; |
238 | int _local35; |
239 | int _local36; |
240 | int _local37; |
241 | int _local38; |
242 | int _local39; |
243 | int _local40; |
244 | int _local43; |
245 | int butt, ron, pat, buf2, buf1; |
246 | |
247 | TuneChannel *tc = &p->tuneChannels[chanNum]; |
248 | const Instrument *ins = &p->instruments[tc->insNum]; |
249 | |
250 | for (i = 0; i < 4; i++ ) { |
251 | const InstrumentEffect *ie = &ins->effects[i]; |
252 | VoiceEffect *ve = &tc->effects[i]; |
253 | |
254 | ve->MFATTMREMVP = (ve->MFATTMREMVP + ie->oscSpeed); |
255 | ve->MFATTMREMVP = (ve->MFATTMREMVP & 0xFF); |
256 | switch (ie->effectType) { |
257 | |
258 | //NONE |
259 | case 0: |
260 | break; |
261 | |
262 | //NEGATE |
263 | case 1: |
264 | destWave = ie->destWave; |
265 | _local3 = ie->fxSpeed; |
266 | pos = ve->QOMCBTRPXF; |
267 | destBuff = tc->synthBuffers[destWave]; |
268 | |
269 | for (j = 0; j < _local3; j++ ) { |
270 | pos++; |
271 | pos = (pos & 0xFF); |
272 | destBuff[pos] = (0 - destBuff[pos]); |
273 | |
274 | } |
275 | ve->QOMCBTRPXF = pos; |
276 | break; |
277 | |
278 | //SWEEP |
279 | case 2: |
280 | destWave = ie->destWave; |
281 | _local3 = ie->fxSpeed; |
282 | destBuff = tc->synthBuffers[destWave]; |
283 | |
284 | |
285 | for (pos = 0, j = 0; j < 0x0100; j++ ) { |
286 | destBuff[j] = (destBuff[j] + pos); |
287 | destBuff[j] = (destBuff[j] + 0x8000); |
288 | destBuff[j] = (destBuff[j] & 0xFFFF); |
289 | destBuff[j] = (destBuff[j] - 0x8000); |
290 | pos = (pos + _local3); |
291 | |
292 | } |
293 | break; |
294 | |
295 | //AVERAGER |
296 | case 3: |
297 | destWave = ie->destWave; |
298 | srcWave1 = ie->srcWave1; |
299 | destBuff = tc->synthBuffers[destWave]; |
300 | srcBuff1 = tc->synthBuffers[srcWave1]; |
301 | _local3 = ie->fxSpeed; |
302 | pos = 0; |
303 | if (_local3 > 12){ |
304 | _local3 = 12; |
305 | } |
306 | |
307 | for (_local10 = 0; _local10 < _local3; _local10++ ) { |
308 | destBuff[0] = ((srcBuff1[0xFF] + srcBuff1[1]) >> 1); |
309 | |
310 | for (j = 1; j < 0xFF; j++ ) { |
311 | destBuff[j] = ((srcBuff1[j - 1] + srcBuff1[j + 1]) >> 1); |
312 | |
313 | } |
314 | destBuff[0xFF] = ((srcBuff1[254] + srcBuff1[0]) >> 1); |
315 | |
316 | } |
317 | break; |
318 | |
319 | //WAVEMIX |
320 | case 4: |
321 | destWave = ie->destWave; |
322 | srcWave1 = ie->srcWave1; |
323 | srcWave2 = ie->srcWave2; |
324 | destBuff = tc->synthBuffers[destWave]; |
325 | srcBuff1 = tc->synthBuffers[srcWave1]; |
326 | srcBuff2 = tc->synthBuffers[srcWave2]; |
327 | _local3 = ie->fxSpeed; |
328 | ve->QOMCBTRPXF = (ve->QOMCBTRPXF + _local3); |
329 | ve->QOMCBTRPXF = (ve->QOMCBTRPXF & 0xFF); |
330 | pos = ve->QOMCBTRPXF; |
331 | |
332 | for (j = 0; j < 0x0100; j++ ) { |
333 | destBuff[j] = ((srcBuff1[j] + srcBuff2[pos]) >> 1); |
334 | pos++; |
335 | pos = (pos & 0xFF); |
336 | |
337 | } |
338 | break; |
339 | |
340 | //FILTER |
341 | case 5: |
342 | destWave = ie->destWave; |
343 | srcWave1 = ie->srcWave1; |
344 | srcWave2 = ie->oscWave - 1; |
345 | destBuff = tc->synthBuffers[destWave]; |
346 | |
347 | srcBuff1 = tc->synthBuffers[srcWave1]; |
348 | srcBuff2 = srcWave2 >= 0 ? tc->synthBuffers[srcWave2] : NULL; |
349 | pos = ve->MFATTMREMVP; |
350 | |
351 | if (ie->oscWave == 0){ |
352 | _local16 = (double)((ie->variable1 * 20)); |
353 | _local17 = (double)((ie->variable2 * 16)); |
354 | } else { |
355 | if (ie->oscSelect){ |
356 | _local16 = (double)((ie->variable1 * 20)); |
357 | _local17 = ((double)((srcBuff2[pos] + 0x8000)) / 16); |
358 | } else { |
359 | _local16 = ((double)((srcBuff2[pos] + 0x8000)) / 13); |
360 | _local17 = (double)((ie->variable2 * 16)); |
361 | } |
362 | } |
363 | ve->DQVLFV = exp((-((2 * M_PI)) * (_local17 / 22000))); |
364 | ve->RKF = (((-4 * ve->DQVLFV) / (1 + ve->DQVLFV)) * cos(((2 * M_PI) * (_local16 / 22000)))); |
365 | ve->MDTMBBIQHRQ = ((1 - ve->DQVLFV) * sqrt((1 - ((ve->RKF * ve->RKF) / (4 * ve->DQVLFV))))); |
366 | |
367 | for (j = 0; j < 0x0100; j++) { |
368 | _local18 = (((ve->MDTMBBIQHRQ * ((double)(srcBuff1[j]) / 0x8000)) - (ve->RKF * ve->ILHG)) - (ve->DQVLFV * ve->YLKJB)); |
369 | ve->YLKJB = ve->ILHG; |
370 | ve->ILHG = _local18; |
371 | if (_local18 > 0.9999){ |
372 | _local18 = 0.9999; |
373 | } |
374 | if (_local18 < -0.9999){ |
375 | _local18 = -0.9999; |
376 | } |
377 | destBuff[j] = (_local18 * 0x8000); |
378 | |
379 | } |
380 | break; |
381 | |
382 | //FILTWHISTLE |
383 | case 6: |
384 | destWave = ie->destWave; |
385 | srcWave1 = ie->srcWave1; |
386 | srcWave2 = ie->oscWave - 1; |
387 | destBuff = tc->synthBuffers[destWave]; |
388 | |
389 | srcBuff1 = tc->synthBuffers[srcWave1]; |
390 | srcBuff2 = srcWave2 >= 0 ? tc->synthBuffers[srcWave2] : NULL; |
391 | pos = ve->MFATTMREMVP; |
392 | |
393 | if (ie->oscWave == 0){ |
394 | _local16 = (double)((ie->variable1 * 20)); |
395 | _local17 = (double)((ie->variable2 * 16)); |
396 | } else { |
397 | if (ie->oscSelect){ |
398 | _local16 = (double)((ie->variable1 * 20)); |
399 | _local17 = ((double)((srcBuff2[pos] + 0x8000)) / 16); |
400 | } else { |
401 | _local16 = ((double)((srcBuff2[pos] + 0x8000)) / 13); |
402 | _local17 = (double)((ie->variable2 * 16)); |
403 | } |
404 | } |
405 | ve->DQVLFV = exp((-((2 * M_PI)) * (_local17 / 22000))); |
406 | ve->RKF = (((-4 * ve->DQVLFV) / (1 + ve->DQVLFV)) * cos(((2 * M_PI) * (_local16 / 22000)))); |
407 | ve->MDTMBBIQHRQ = ((1 - ve->DQVLFV) * sqrt((1 - ((ve->RKF * ve->RKF) / (4 * ve->DQVLFV))))); |
408 | ve->DQVLFV = (ve->DQVLFV * 1.2); |
409 | |
410 | for (j = 0; j < 0x0100; j++ ) { |
411 | _local18 = (((ve->MDTMBBIQHRQ * ((double)(srcBuff1[j]) / 0x8000)) - (ve->RKF * ve->ILHG)) - (ve->DQVLFV * ve->YLKJB)); |
412 | ve->YLKJB = ve->ILHG; |
413 | ve->ILHG = _local18; |
414 | if (_local18 > 0.9999){ |
415 | _local18 = 0.9999; |
416 | } |
417 | if (_local18 < -0.9999){ |
418 | _local18 = -0.9999; |
419 | } |
420 | destBuff[j] = (_local18 * 0x8000); |
421 | |
422 | } |
423 | break; |
424 | |
425 | //MORPH |
426 | case 7: |
427 | destWave = ie->destWave; |
428 | srcWave1 = ie->srcWave1; |
429 | srcWave2 = ie->srcWave2; |
430 | oscWave = ie->oscWave - 1; |
431 | destBuff = tc->synthBuffers[destWave]; |
432 | |
433 | srcBuff1 = tc->synthBuffers[srcWave1]; |
434 | srcBuff2 = tc->synthBuffers[srcWave2]; |
435 | oscBuff = oscWave >= 0 ? tc->synthBuffers[oscWave] : NULL; |
436 | pos = ve->MFATTMREMVP; |
437 | |
438 | if (ie->oscWave == 0){ |
439 | _local21 = ie->variable1; |
440 | } else { |
441 | if (ie->oscSelect){ |
442 | _local21 = ie->variable1; |
443 | } else { |
444 | _local21 = ((oscBuff[pos] + 0x8000) / 0x0100); |
445 | } |
446 | } |
447 | _local22 = (0xFF - _local21); |
448 | |
449 | for (j = 0; j < 0x0100; j++) { |
450 | _local23 = (((srcBuff1[j] * _local21) / 0x0100) + ((srcBuff2[j] * _local22) / 0x0100)); |
451 | destBuff[j] = _local23; |
452 | |
453 | } |
454 | break; |
455 | |
456 | //DYNAMORPH |
457 | case 8: |
458 | destWave = ie->destWave; |
459 | srcWave1 = ie->srcWave1; |
460 | srcWave2 = ie->srcWave2; |
461 | oscWave = ie->oscWave - 1; |
462 | destBuff = tc->synthBuffers[destWave]; |
463 | |
464 | srcBuff1 = tc->synthBuffers[srcWave1]; |
465 | srcBuff2 = tc->synthBuffers[srcWave2]; |
466 | oscBuff = oscWave >= 0 ? tc->synthBuffers[oscWave] : NULL; |
467 | pos = ve->MFATTMREMVP; |
468 | |
469 | if (ie->oscWave == 0){ |
470 | _local25 = ie->variable1; |
471 | } else { |
472 | if (ie->oscSelect){ |
473 | _local25 = ie->variable1; |
474 | } else { |
475 | _local25 = ((oscBuff[pos] + 0x8000) / 0x0100); |
476 | } |
477 | } |
478 | |
479 | for (j = 0; j < 0x0100; j++) { |
480 | _local21 = ((p->dynamorphTable[_local25] >> 8) + 128); |
481 | _local22 = (0xFF - _local21); |
482 | _local23 = (((srcBuff1[j] * _local21) / 0x0100) + ((srcBuff2[j] * _local22) / 0x0100)); |
483 | destBuff[j] = _local23; |
484 | _local25++; |
485 | _local25 = (_local25 & 0xFF); |
486 | |
487 | } |
488 | break; |
489 | |
490 | //DISTORTION |
491 | case 9: |
492 | destWave = ie->destWave; |
493 | srcWave1 = ie->srcWave1; |
494 | oscWave = ie->oscWave - 1; |
495 | destBuff = tc->synthBuffers[destWave]; |
496 | |
497 | srcBuff1 = tc->synthBuffers[srcWave1]; |
498 | oscBuff = oscWave >= 0 ? tc->synthBuffers[oscWave] : NULL; |
499 | pos = ve->MFATTMREMVP; |
500 | |
501 | if (ie->oscWave == 0){ |
502 | _local21 = ie->variable1; |
503 | } else { |
504 | if (ie->oscSelect){ |
505 | _local21 = ie->variable1; |
506 | } else { |
507 | _local21 = ((oscBuff[pos] + 0x8000) / 0x0100); |
508 | } |
509 | } |
510 | |
511 | for (j = 0; j < 0x0100; j++) { |
512 | _local23 = ((srcBuff1[j] * _local21) / 16); |
513 | _local23 = (_local23 + 0x8000); |
514 | if (_local23 < 0){ |
515 | _local23 = -(_local23); |
516 | } |
517 | _local23 = (_local23 % 131072); |
518 | if (_local23 > 0xFFFF){ |
519 | _local23 = (131071 - _local23); |
520 | } |
521 | _local23 = (_local23 & 0xFFFF); |
522 | _local23 = (_local23 - 0x8000); |
523 | destBuff[j] = _local23; |
524 | |
525 | } |
526 | break; |
527 | |
528 | //SCROLL LEFT |
529 | case 10: |
530 | destWave = ie->destWave; |
531 | destBuff = tc->synthBuffers[destWave]; |
532 | _local10 = destBuff[0]; |
533 | |
534 | for (j = 0; j < 0xFF; j++) { |
535 | destBuff[j] = destBuff[j + 1]; |
536 | |
537 | } |
538 | destBuff[0xFF] = _local10; |
539 | break; |
540 | |
541 | //UPSAMPLE |
542 | case 11: |
543 | pos = ve->QOMCBTRPXF; |
544 | if (pos != 0){ |
545 | ve->QOMCBTRPXF--; |
546 | break; |
547 | } |
548 | ve->QOMCBTRPXF = ie->variable1; |
549 | destWave = ie->destWave; |
550 | destBuff = tc->synthBuffers[destWave]; |
551 | |
552 | for (j = 0; j < 128; j++) { |
553 | destBuff[j] = destBuff[j * 2]; |
554 | |
555 | } |
556 | |
557 | for (j = 0; j < 128; j++) { |
558 | destBuff[j + 128] = destBuff[j]; |
559 | |
560 | } |
561 | break; |
562 | |
563 | //CLIPPER |
564 | case 12: |
565 | destWave = ie->destWave; |
566 | srcWave1 = ie->srcWave1; |
567 | oscWave = ie->oscWave - 1; |
568 | destBuff = tc->synthBuffers[destWave]; |
569 | |
570 | srcBuff1 = tc->synthBuffers[srcWave1]; |
571 | oscBuff = oscWave >= 0 ? tc->synthBuffers[oscWave] : NULL; |
572 | pos = ve->MFATTMREMVP; |
573 | |
574 | if (ie->oscWave == 0){ |
575 | _local21 = ie->variable1; |
576 | } else { |
577 | if (ie->oscSelect){ |
578 | _local21 = ie->variable1; |
579 | } else { |
580 | _local21 = ((oscBuff[pos] + 0x8000) / 0x0100); |
581 | } |
582 | } |
583 | |
584 | for (j = 0; j < 0x0100; j++) { |
585 | _local23 = ((srcBuff1[j] * _local21) / 16); |
586 | if (_local23 < -32767){ |
587 | _local23 = -32767; |
588 | } |
589 | if (_local23 > 32767){ |
590 | _local23 = 32767; |
591 | } |
592 | destBuff[j] = _local23; |
593 | |
594 | } |
595 | break; |
596 | |
597 | //LOWPASS |
598 | case 13: |
599 | destWave = ie->destWave; |
600 | srcWave1 = ie->srcWave1; |
601 | srcWave2 = ie->oscWave - 1; |
602 | destBuff = tc->synthBuffers[destWave]; |
603 | |
604 | srcBuff1 = tc->synthBuffers[srcWave1]; |
605 | srcBuff2 = srcWave2 >= 0 ? tc->synthBuffers[srcWave2] : NULL; |
606 | pos = ve->MFATTMREMVP; |
607 | |
608 | if (ie->oscWave == 0){ |
609 | var1 = ie->variable1; |
610 | var2 = ie->variable2; |
611 | var1 = var1 * 16; |
612 | } else { |
613 | if (ie->oscSelect){ |
614 | var1 = ie->variable1; |
615 | var2 = ((srcBuff2[pos] + 0x8000) >> 8); |
616 | var1 = (var1 * 16); |
617 | } else { |
618 | //_local28 = ((_local14->data[_local7] + 0x8000) / 16); |
619 | var1 = ((srcBuff2[pos] + 0x8000) >> 4); |
620 | var2 = ie->variable2; |
621 | } |
622 | } |
623 | _local30 = (var1 - 920); |
624 | _local31 = (228 + var1); |
625 | _local26 = (int)(((2 * M_PI) * _local31)); |
626 | _local27 = (707 + ((1000 * var2) / 128)); |
627 | _local36 = ve->ABJGHAUY; |
628 | _local37 = ve->SPYK; |
629 | _local38 = ve->VMBNMTNBQU; |
630 | _local40 = 8; |
631 | |
632 | for (j = 0; j < 0x0100; j++) { |
633 | _local32 = ((_local26 * _local40) / 100); |
634 | _local39 = srcBuff1[j]; |
635 | _local33 = ((((_local36 * 1000) / _local27) - _local37) + _local39); |
636 | _local34 = (_local36 - ((_local32 * (_local38 / 100)) / 100)); |
637 | _local35 = (_local37 - ((_local32 * (_local36 / 100)) / 100)); |
638 | _local38 = _local33; |
639 | _local36 = _local34; |
640 | _local37 = _local35; |
641 | _local3 = _local37; |
642 | if (_local3 > 32767){ |
643 | _local3 = 32767; |
644 | } |
645 | if (_local3 < -32767){ |
646 | _local3 = -32767; |
647 | } |
648 | destBuff[j] = _local3; |
649 | |
650 | } |
651 | ve->ABJGHAUY = _local36; |
652 | ve->SPYK = _local37; |
653 | ve->VMBNMTNBQU = _local38; |
654 | break; |
655 | |
656 | //HIGHPASS |
657 | case 14: |
658 | destWave = ie->destWave; |
659 | srcWave1 = ie->srcWave1; |
660 | srcWave2 = ie->oscWave - 1; |
661 | destBuff = tc->synthBuffers[destWave]; |
662 | |
663 | srcBuff1 = tc->synthBuffers[srcWave1]; |
664 | srcBuff2 = srcWave2 >= 0 ? tc->synthBuffers[srcWave2] : NULL; |
665 | pos = ve->MFATTMREMVP; |
666 | |
667 | if (ie->oscWave == 0){ |
668 | var1 = ie->variable1; |
669 | var2 = ie->variable2; |
670 | var1 = (var1 * 32); |
671 | } else { |
672 | if (ie->oscSelect) { |
673 | var1 = ie->variable1; |
674 | var2 = ((srcBuff2[pos] + 0x8000) >> 8); |
675 | var1 = (var1 * 32); |
676 | } else { |
677 | //checked with IDA against windows ver. of Syntrax(v1.03) |
678 | //It's possible that the effect has changed along the way(v2.xx) |
679 | //same for lowpass |
680 | //_local28 = ((_local14->data[_local7] + 0x8000) / 16); |
681 | var1 = ((srcBuff2[pos] + 0x8000) >> 3); |
682 | var2 = ie->variable2; |
683 | } |
684 | } |
685 | _local30 = (var1 - 920); |
686 | _local31 = (228 + var1); |
687 | _local26 = (int)(((2 * M_PI) * _local31)); |
688 | _local27 = (707 + ((1000 * var2) / 128)); |
689 | _local36 = ve->ABJGHAUY; |
690 | _local37 = ve->SPYK; |
691 | _local38 = ve->VMBNMTNBQU; |
692 | _local40 = 8; |
693 | |
694 | for (j = 0; j < 0x0100; j++) { |
695 | _local32 = ((_local26 * _local40) / 100); |
696 | _local39 = srcBuff1[j]; |
697 | _local33 = ((((_local36 * 1000) / _local27) - _local37) + _local39); |
698 | _local34 = (_local36 - ((_local32 * (_local38 / 100)) / 100)); |
699 | _local35 = (_local37 - ((_local32 * (_local36 / 100)) / 100)); |
700 | _local38 = _local33; |
701 | _local36 = _local34; |
702 | _local37 = _local35; |
703 | _local3 = _local38; |
704 | if (_local3 > 32767){ |
705 | _local3 = 32767; |
706 | } |
707 | if (_local3 < -32767){ |
708 | _local3 = -32767; |
709 | } |
710 | destBuff[j] = _local3; |
711 | |
712 | } |
713 | ve->ABJGHAUY = _local36; |
714 | ve->SPYK = _local37; |
715 | ve->VMBNMTNBQU = _local38; |
716 | break; |
717 | |
718 | //BANDPASS |
719 | case 15: |
720 | destWave = ie->destWave; |
721 | srcWave1 = ie->srcWave1; |
722 | srcWave2 = ie->oscWave - 1; |
723 | destBuff = tc->synthBuffers[destWave]; |
724 | |
725 | srcBuff1 = tc->synthBuffers[srcWave1]; |
726 | srcBuff2 = srcWave2 >= 0 ? tc->synthBuffers[srcWave2] : NULL; |
727 | pos = ve->MFATTMREMVP; |
728 | |
729 | if (ie->oscWave == 0){ |
730 | var1 = ie->variable1; |
731 | var2 = ie->variable2; |
732 | var1 = var1 * 16; |
733 | } else { |
734 | if (ie->oscSelect){ |
735 | var1 = ie->variable1; |
736 | var2 = ((srcBuff2[pos] + 0x8000) >> 8); |
737 | var1 = var1 * 16; |
738 | } else { |
739 | var1 = ((srcBuff2[pos] + 0x8000) / 16); |
740 | var2 = ie->variable2; |
741 | } |
742 | } |
743 | _local30 = (var1 - 920); |
744 | _local31 = (228 + var1); |
745 | _local26 = (int)(((2 * M_PI) * _local31)); |
746 | _local27 = (707 + ((1000 * var2) / 128)); |
747 | _local36 = ve->ABJGHAUY; |
748 | _local37 = ve->SPYK; |
749 | _local38 = ve->VMBNMTNBQU; |
750 | _local40 = 8; |
751 | |
752 | for (j = 0; j < 0x0100; j++) { |
753 | _local32 = ((_local26 * _local40) / 100); |
754 | _local39 = srcBuff1[j]; |
755 | _local33 = ((((_local36 * 1000) / _local27) - _local37) + _local39); |
756 | _local34 = (_local36 - ((_local32 * (_local38 / 100)) / 100)); |
757 | _local35 = (_local37 - ((_local32 * (_local36 / 100)) / 100)); |
758 | _local38 = _local33; |
759 | _local36 = _local34; |
760 | _local37 = _local35; |
761 | _local3 = _local36; |
762 | if (_local3 > 32767){ |
763 | _local3 = 32767; |
764 | } |
765 | if (_local3 < -32767){ |
766 | _local3 = -32767; |
767 | } |
768 | destBuff[j] = _local3; |
769 | |
770 | } |
771 | ve->ABJGHAUY = _local36; |
772 | ve->SPYK = _local37; |
773 | ve->VMBNMTNBQU = _local38; |
774 | break; |
775 | |
776 | //METALNOISE |
777 | case 16: |
778 | destWave = ie->destWave; |
779 | destBuff = tc->synthBuffers[destWave]; |
780 | for (j = 0; j < 0x0100; j++ ) { |
781 | //Something very bad happens here |
782 | //I think it's fixed now. |
783 | destBuff[j] = (int)(((double)(rand()) / (double)(RAND_MAX)) * 65530 - 0x8000); |
784 | } |
785 | break; |
786 | |
787 | //SQUASH |
788 | case 17: |
789 | destWave = ie->destWave; |
790 | srcWave1 = ie->srcWave1; |
791 | oscWave = ie->oscWave - 1; |
792 | destBuff = tc->synthBuffers[destWave]; |
793 | |
794 | srcBuff1 = tc->synthBuffers[srcWave1]; |
795 | |
796 | oscBuff = oscWave >= 0 ? tc->synthBuffers[oscWave] : NULL; |
797 | pos = ve->MFATTMREMVP; |
798 | |
799 | if (ie->oscWave == 0){ |
800 | var1 = ie->variable1; |
801 | var2 = ie->variable2; |
802 | } else { |
803 | if (ie->oscSelect){ |
804 | var1 = ie->variable1; |
805 | var2 = ((oscBuff[pos] + 0x8000) >> 8); |
806 | } else { |
807 | var1 = ((oscBuff[pos] + 0x8000) >> 8); |
808 | var2 = ie->variable2; |
809 | } |
810 | } |
811 | |
812 | var2 = (var2 << 8); |
813 | var1 = (var1 + var2); |
814 | _local22 = 0; |
815 | |
816 | for (j = 0; j < 0x0100; j++ ) { |
817 | //Hex Rays decompiler is lovely tool. |
818 | //butt = (butt & 0xFFFF0000) | (_local22 & 0x0000FFFF); |
819 | butt = _local22 & 0xFFFF; |
820 | _local22 += var1; |
821 | //ron = (ron & 0xFFFFFF00) | ( butt & 0x000000FF); |
822 | ron = butt & 0xFF; |
823 | butt >>= 8; |
824 | buf1 = srcBuff1[butt]; |
825 | //overflow warning |
826 | buf2 = srcBuff1[butt + 1]; |
827 | pat = (255 - ron) * buf1; |
828 | destBuff[j] = (ron * buf2 >> 8) + (pat >> 8); |
829 | } |
830 | break; |
831 | } |
832 | } |
833 | } |
834 | |
835 | static void channelSomethingElse(Player *p, int chanNum) |
836 | { |
837 | int _local3; |
838 | int _local4; |
839 | int _local5; |
840 | int _local6; |
841 | |
842 | TuneChannel *tc = &p->tuneChannels[chanNum]; |
843 | const Instrument *ins = &p->instruments[tc->insNum]; |
844 | |
845 | if (ins->amWave == 0){ |
846 | _local3 = 0; |
847 | } else { |
848 | tc->HFRLJCG = (tc->HFRLJCG + ins->amSpeed); |
849 | if (tc->HFRLJCG >= 0x0100){ |
850 | tc->HFRLJCG = (tc->HFRLJCG - 0x0100); |
851 | tc->HFRLJCG = (tc->HFRLJCG + ins->amLoopPoint); |
852 | if (tc->HFRLJCG >= 0x0100){ |
853 | tc->HFRLJCG = ins->amLoopPoint; |
854 | } |
855 | } |
856 | _local3 = tc->synthBuffers[ins->amWave - 1][tc->HFRLJCG]; |
857 | _local3 = (_local3 + 0x8000); |
858 | _local3 = (_local3 / 6); |
859 | _local3 = -(_local3); |
860 | if (_local3 < -10000){ |
861 | _local3 = -10000; |
862 | } |
863 | } |
864 | _local3 = (_local3 + 10000); |
865 | _local3 = (_local3 * ins->masterVolume); |
866 | _local3 = (_local3 >> 8); |
867 | _local3 = (_local3 * p->AMVM); |
868 | _local3 = (_local3 >> 8); |
869 | _local3 = (_local3 - 10000); |
870 | tc->volume = _local3; |
871 | if (ins->panWave == 0){ |
872 | _local5 = 0; |
873 | } else { |
874 | tc->ELPHLDR = (tc->ELPHLDR + ins->panSpeed); |
875 | if (tc->ELPHLDR >= 0x0100){ |
876 | tc->ELPHLDR = (tc->ELPHLDR - 0x0100); |
877 | tc->ELPHLDR = (tc->ELPHLDR + ins->panLoopPoint); |
878 | if (tc->ELPHLDR >= 0x0100){ |
879 | tc->ELPHLDR = ins->panLoopPoint; |
880 | } |
881 | } |
882 | _local5 = tc->synthBuffers[ins->panWave - 1][tc->ELPHLDR]; |
883 | _local5 = (_local5 >> 7); |
884 | } |
885 | tc->panning = _local5; |
886 | _local6 = 0; |
887 | _local6 = p->arpTable[(ins->arpIndex * 16) + tc->ACKCWV]; |
888 | tc->ACKCWV++; |
889 | tc->ACKCWV = (tc->ACKCWV & 15); |
890 | _local4 = p->freqTable[ins->finetune*128 + (_local6 + tc->TVORFCC)]; |
891 | if (tc->fmDelay){ |
892 | tc->fmDelay--; |
893 | } else { |
894 | if (ins->fmWave != 0){ |
895 | tc->JOEEPJCI = (tc->JOEEPJCI + ins->fmSpeed); |
896 | if (tc->JOEEPJCI >= 0x0100){ |
897 | tc->JOEEPJCI = (tc->JOEEPJCI - 0x0100); |
898 | tc->JOEEPJCI = (tc->JOEEPJCI + ins->fmLoopPoint); |
899 | if (tc->JOEEPJCI >= 0x0100){ |
900 | tc->JOEEPJCI = ins->fmLoopPoint; |
901 | } |
902 | } |
903 | _local4 = _local4 - tc->synthBuffers[ins->fmWave - 1][tc->JOEEPJCI]; |
904 | } |
905 | } |
906 | _local4 = (_local4 + tc->BNWIGU); |
907 | tc->freq = _local4; |
908 | if (tc->XESAWSO != 0){ |
909 | if (tc->XESAWSO > 0){ |
910 | if (tc->BNWIGU < tc->UHYDBDDI){ |
911 | tc->BNWIGU = (tc->BNWIGU + tc->XESAWSO); |
912 | if (tc->BNWIGU > tc->UHYDBDDI){ |
913 | tc->BNWIGU = tc->UHYDBDDI; |
914 | } |
915 | } |
916 | } else { |
917 | if (tc->BNWIGU > tc->UHYDBDDI){ |
918 | tc->BNWIGU = (tc->BNWIGU + tc->XESAWSO); |
919 | if (tc->BNWIGU < tc->UHYDBDDI){ |
920 | tc->BNWIGU = tc->UHYDBDDI; |
921 | } |
922 | } |
923 | } |
924 | } |
925 | } |
926 | |
927 | void playInstrument(Player *p, int chanNum, int instrNum, int note) //note: 1-112 |
928 | { |
929 | int j; |
930 | int i; |
931 | TuneChannel *tc; |
932 | Voice *v; |
933 | const Instrument *ins; |
934 | |
935 | if (instrNum > p->synSong->h.instrNum){ |
936 | return; |
937 | } |
938 | if ((((p->tuneChannels[chanNum].insNum == -1)) && ((instrNum == 0)))){ |
939 | return; |
940 | } |
941 | |
942 | tc = &p->tuneChannels[chanNum]; |
943 | v = &p->voices[chanNum]; |
944 | |
945 | tc->ACKCWV = 0; |
946 | tc->HFRLJCG = 0; |
947 | tc->ELPHLDR = 0; |
948 | tc->JOEEPJCI = 0; |
949 | tc->TVORFCC = note; |
950 | tc->freq = 0; |
951 | tc->VNVJPDIWAJQ = note; |
952 | tc->BNWIGU = 0; |
953 | tc->UHYDBDDI = 0; |
954 | tc->XESAWSO = 0; |
955 | p->m_LastNotes[chanNum] = note; |
956 | |
957 | if (instrNum != 0) { |
958 | ins = &p->instruments[instrNum - 1]; |
959 | |
960 | if (ins->shareSmpDataFromInstr == 0){ |
961 | tc->sampleBuffer = p->samples[instrNum - 1]; |
962 | } else { |
963 | tc->sampleBuffer = p->samples[ins->shareSmpDataFromInstr - 1]; |
964 | } |
965 | tc->sampPos = ins->smpStartPoint; |
966 | tc->smpLoopStart = ins->smpLoopPoint; |
967 | tc->smpLoopEnd = ins->smpEndPoint; |
968 | tc->hasLoop = ins->hasLoop; |
969 | tc->hasBidiLoop = ins->hasBidiLoop; |
970 | tc->hasLooped = 0; |
971 | tc->isPlayingBackward = 0; |
972 | tc->EYRXAB = -1; |
973 | tc->fmDelay = ins->fmDelay; |
974 | |
975 | for (i = 0; i < 16; i++) { |
976 | if (ins->m_ResetWave[i]){ |
977 | //ins->synthBuffers[i].copyTo(tc.synthBuffers[i]); |
978 | memcpy(&tc->synthBuffers[i], &ins->synthBuffers[i], 0x100 *2); |
979 | } |
980 | } |
981 | tc->insNum = instrNum - 1; |
982 | |
983 | resampler_clear(v->resampler[0]); |
984 | v->last_delta = 0; |
985 | } |
986 | ins = &p->instruments[tc->insNum]; |
987 | |
988 | for (j = 0; j < 4; j++) { |
989 | if (ins->effects[j].effectType != 0){ |
990 | if (ins->effects[j].resetEffect) { |
991 | VoiceEffect *ve = &tc->effects[j]; |
992 | |
993 | ve->MFATTMREMVP = 0; |
994 | ve->QOMCBTRPXF = 0; |
995 | ve->TIPUANVVR = 0; |
996 | ve->YLKJB = 0; |
997 | ve->ILHG = 0; |
998 | ve->VMBNMTNBQU = 0; |
999 | ve->ABJGHAUY = 0; |
1000 | ve->SPYK = 0; |
1001 | } |
1002 | } |
1003 | } |
1004 | } |
1005 | |
1006 | static void patEffect(Player *p, int note, int command, int dest, int spd, int chanNum) |
1007 | { |
1008 | TuneChannel *tc = &p->tuneChannels[chanNum]; |
1009 | Instrument *ins = &p->instruments[tc->insNum]; |
1010 | int off; |
1011 | double tempo; |
1012 | |
1013 | if (tc->insNum == -1) return; |
1014 | switch (command) { |
1015 | |
1016 | //NONE |
1017 | case 0: |
1018 | default: |
1019 | return; |
1020 | |
1021 | //PITCHBEND |
1022 | case 1: |
1023 | if (tc->VNVJPDIWAJQ){ |
1024 | off = p->freqTable[ins->finetune*128 + tc->VNVJPDIWAJQ]; |
1025 | tc->TVORFCC = tc->VNVJPDIWAJQ; |
1026 | } else { |
1027 | off = p->freqTable[ins->finetune*128 + note]; |
1028 | } |
1029 | tc->BNWIGU = 0; |
1030 | tc->UHYDBDDI = (p->freqTable[ins->finetune*128 + dest] - off); |
1031 | tc->XESAWSO = (spd * 20); |
1032 | tc->VNVJPDIWAJQ = dest; |
1033 | break; |
1034 | |
1035 | //CHNG WAVEFORM |
1036 | case 2: |
1037 | if (dest > 15){ |
1038 | dest = 15; |
1039 | } |
1040 | ins->waveform = dest; |
1041 | break; |
1042 | |
1043 | //CHNG WAVELENGTH |
1044 | case 3: |
1045 | if (dest > 192){ |
1046 | dest = 0x0100; |
1047 | } else { |
1048 | if (dest > 96){ |
1049 | dest = 128; |
1050 | } else { |
1051 | if (dest > 48){ |
1052 | dest = 64; |
1053 | } else { |
1054 | dest = 32; |
1055 | } |
1056 | } |
1057 | } |
1058 | ins->wavelength = dest; |
1059 | break; |
1060 | |
1061 | //CHNG MASTER VOL |
1062 | case 4: |
1063 | ins->masterVolume = dest; |
1064 | break; |
1065 | |
1066 | //CHNG AMWAVE |
1067 | case 5: |
1068 | if (dest > 15){ |
1069 | dest = 15; |
1070 | } |
1071 | ins->amWave = dest; |
1072 | break; |
1073 | |
1074 | //CHNG AMSPD |
1075 | case 6: |
1076 | ins->amSpeed = dest; |
1077 | break; |
1078 | |
1079 | //CHNG AMLPPOINT |
1080 | case 7: |
1081 | ins->amLoopPoint = dest; |
1082 | break; |
1083 | |
1084 | //CHNG FINETUNE |
1085 | case 8: |
1086 | if (dest > 15){ |
1087 | dest = 15; |
1088 | } |
1089 | ins->finetune = dest; |
1090 | break; |
1091 | |
1092 | //CHNG FMWAVE |
1093 | case 9: |
1094 | if (dest > 15){ |
1095 | dest = 15; |
1096 | } |
1097 | ins->fmWave = dest; |
1098 | break; |
1099 | |
1100 | //CHNG FMSPD |
1101 | case 10: |
1102 | ins->fmSpeed = dest; |
1103 | break; |
1104 | |
1105 | //CHNG FMLPPOINT |
1106 | case 11: |
1107 | ins->fmLoopPoint = dest; |
1108 | break; |
1109 | |
1110 | //CHNG FMDELAY |
1111 | case 12: |
1112 | ins->fmDelay = dest; |
1113 | break; |
1114 | |
1115 | //CHNG ARPEGGIO |
1116 | case 13: |
1117 | if (dest > 15){ |
1118 | dest = 15; |
1119 | } |
1120 | ins->arpIndex = dest; |
1121 | break; |
1122 | |
1123 | //CHNG EFF#1 DESTWAVE |
1124 | case 14: |
1125 | if (dest > 15){ |
1126 | dest = 15; |
1127 | } |
1128 | ins->effects[0].destWave = dest; |
1129 | break; |
1130 | |
1131 | //CHNG EFF#1 SRCWAVE1 |
1132 | case 15: |
1133 | if (dest > 15){ |
1134 | dest = 15; |
1135 | } |
1136 | ins->effects[0].srcWave1 = dest; |
1137 | break; |
1138 | |
1139 | //CHNG EFF#1 SRCWAVE2 |
1140 | case 16: |
1141 | if (dest > 15){ |
1142 | dest = 15; |
1143 | } |
1144 | ins->effects[0].srcWave2 = dest; |
1145 | break; |
1146 | |
1147 | //CHNG EFF#1 OSCWAVE |
1148 | case 17: |
1149 | if (dest > 15){ |
1150 | dest = 15; |
1151 | } |
1152 | ins->effects[0].oscWave = dest; |
1153 | break; |
1154 | |
1155 | //CHNG EFF#1 VARIABLE1 |
1156 | case 18: |
1157 | ins->effects[0].variable1 = dest; |
1158 | break; |
1159 | |
1160 | //CHNG EFF#1 VARIABLE2 |
1161 | case 19: |
1162 | ins->effects[0].variable2 = dest; |
1163 | break; |
1164 | |
1165 | //CHNG EFF#1 FXSPEED |
1166 | case 20: |
1167 | ins->effects[0].fxSpeed = dest; |
1168 | break; |
1169 | |
1170 | //CHNG EFF#1 OSCSPEED |
1171 | case 21: |
1172 | ins->effects[0].oscSpeed = dest; |
1173 | break; |
1174 | |
1175 | //CHNG EFF#1 OSCSELECT |
1176 | case 22: |
1177 | if (dest > 1){ |
1178 | dest = 1; |
1179 | } |
1180 | ins->effects[0].oscSelect = dest; |
1181 | break; |
1182 | |
1183 | //CHNG EFF#1 TYPE |
1184 | case 23: |
1185 | if (dest >= SE_NROFEFFECTS){ |
1186 | dest = (SE_NROFEFFECTS - 1); |
1187 | } |
1188 | ins->effects[0].effectType = dest; |
1189 | break; |
1190 | |
1191 | //CHNG EFF#1 RESETEFFECT |
1192 | case 24: |
1193 | if (dest > 1){ |
1194 | dest = 1; |
1195 | } |
1196 | ins->effects[0].resetEffect = dest; |
1197 | break; |
1198 | |
1199 | //CHNG EFF#2 DESTWAVE |
1200 | case 25: |
1201 | if (dest > 15){ |
1202 | dest = 15; |
1203 | } |
1204 | ins->effects[1].destWave = dest; |
1205 | break; |
1206 | |
1207 | //CHNG EFF#2 SRCWAVE1 |
1208 | case 26: |
1209 | if (dest > 15){ |
1210 | dest = 15; |
1211 | } |
1212 | ins->effects[1].srcWave1 = dest; |
1213 | break; |
1214 | |
1215 | //CHNG EFF#2 SRCWAVE2 |
1216 | case 27: |
1217 | if (dest > 15){ |
1218 | dest = 15; |
1219 | } |
1220 | //Good god! SrcEffect2 is left unplugged. I could guess what it was. |
1221 | //Luckly, I'm saved by one of the later effects. |
1222 | ins->effects[1].srcWave2 = dest; |
1223 | break; |
1224 | |
1225 | //CHNG EFF#2 OSCWAVE |
1226 | case 28: |
1227 | if (dest > 15){ |
1228 | dest = 15; |
1229 | } |
1230 | ins->effects[1].oscWave = dest; |
1231 | break; |
1232 | |
1233 | //CHNG EFF#2 VARIABLE1 |
1234 | case 29: |
1235 | ins->effects[1].variable1 = dest; |
1236 | break; |
1237 | |
1238 | //CHNG EFF#2 VARIABLE2 |
1239 | case 30: |
1240 | ins->effects[1].variable2 = dest; |
1241 | break; |
1242 | |
1243 | //CHNG EFF#2 FXSPEED |
1244 | case 31: |
1245 | ins->effects[1].fxSpeed = dest; |
1246 | break; |
1247 | |
1248 | //CHNG EFF#2 OSCSPEED |
1249 | case 32: |
1250 | ins->effects[1].oscSpeed = dest; |
1251 | break; |
1252 | |
1253 | //CHNG EFF#2 OSCSELECT |
1254 | case 33: |
1255 | if (dest > 1){ |
1256 | dest = 1; |
1257 | } |
1258 | ins->effects[1].oscSelect = dest; |
1259 | break; |
1260 | |
1261 | //CHNG EFF#2 TYPE |
1262 | case 34: |
1263 | if (dest >= SE_NROFEFFECTS){ |
1264 | dest = (SE_NROFEFFECTS - 1); |
1265 | } |
1266 | ins->effects[1].effectType = dest; |
1267 | break; |
1268 | |
1269 | //CHNG EFF#2 RESETEFFECT |
1270 | case 35: |
1271 | if (dest > 1){ |
1272 | dest = 1; |
1273 | } |
1274 | ins->effects[1].resetEffect = dest; |
1275 | break; |
1276 | |
1277 | //CHNG EFF#3 DESTWAVE |
1278 | case 36: |
1279 | if (dest > 15){ |
1280 | dest = 15; |
1281 | } |
1282 | ins->effects[2].destWave = dest; |
1283 | break; |
1284 | |
1285 | //CHNG EFF#3 SRCWAVE1 |
1286 | case 37: |
1287 | if (dest > 15){ |
1288 | dest = 15; |
1289 | } |
1290 | ins->effects[2].srcWave1 = dest; |
1291 | break; |
1292 | |
1293 | //CHNG EFF#3 SRCWAVE2 |
1294 | case 38: |
1295 | if (dest > 15){ |
1296 | dest = 15; |
1297 | } |
1298 | ins->effects[2].srcWave2 = dest; |
1299 | break; |
1300 | |
1301 | //CHNG EFF#3 OSCWAVE |
1302 | case 39: |
1303 | if (dest > 15){ |
1304 | dest = 15; |
1305 | } |
1306 | ins->effects[2].oscWave = dest; |
1307 | break; |
1308 | |
1309 | //CHNG EFF#3 VARIABLE1 |
1310 | case 40: |
1311 | ins->effects[2].variable1 = dest; |
1312 | break; |
1313 | |
1314 | //CHNG EFF#3 VARIABLE2 |
1315 | case 41: |
1316 | ins->effects[2].variable2 = dest; |
1317 | break; |
1318 | |
1319 | //CHNG EFF#3 FXSPEED |
1320 | case 42: |
1321 | ins->effects[2].fxSpeed = dest; |
1322 | break; |
1323 | |
1324 | //CHNG EFF#3 OSCSPEED |
1325 | case 43: |
1326 | ins->effects[2].oscSpeed = dest; |
1327 | break; |
1328 | |
1329 | //CHNG EFF#3 OSCSELECT |
1330 | case 44: |
1331 | if (dest > 1){ |
1332 | dest = 1; |
1333 | } |
1334 | ins->effects[2].oscSelect = dest; |
1335 | break; |
1336 | |
1337 | //CHNG EFF#3 TYPE |
1338 | case 45: |
1339 | if (dest >= SE_NROFEFFECTS){ |
1340 | dest = (SE_NROFEFFECTS - 1); |
1341 | } |
1342 | ins->effects[2].effectType = dest; |
1343 | break; |
1344 | |
1345 | //CHNG EFF#3 RESETEFFECT |
1346 | case 46: |
1347 | if (dest > 1){ |
1348 | dest = 1; |
1349 | } |
1350 | ins->effects[2].resetEffect = dest; |
1351 | break; |
1352 | |
1353 | //CHNG EFF#4 DESTWAVE |
1354 | case 47: |
1355 | if (dest > 15){ |
1356 | dest = 15; |
1357 | } |
1358 | ins->effects[3].destWave = dest; |
1359 | break; |
1360 | |
1361 | //CHNG EFF#4 SRCWAVE1 |
1362 | case 48: |
1363 | if (dest > 15){ |
1364 | dest = 15; |
1365 | } |
1366 | ins->effects[3].srcWave1 = dest; |
1367 | break; |
1368 | |
1369 | //CHNG EFF#4 SRCWAVE2 |
1370 | case 49: |
1371 | if (dest > 15){ |
1372 | dest = 15; |
1373 | } |
1374 | ins->effects[3].srcWave2 = dest; |
1375 | break; |
1376 | |
1377 | //CHNG EFF#4 OSCWAVE |
1378 | case 50: |
1379 | if (dest > 15){ |
1380 | dest = 15; |
1381 | } |
1382 | ins->effects[3].oscWave = dest; |
1383 | break; |
1384 | |
1385 | //CHNG EFF#4 VARIABLE1 |
1386 | case 51: |
1387 | ins->effects[3].variable1 = dest; |
1388 | break; |
1389 | |
1390 | //CHNG EFF#4 VARIABLE2 |
1391 | case 52: |
1392 | ins->effects[3].variable2 = dest; |
1393 | break; |
1394 | |
1395 | //CHNG EFF#4 FXSPEED |
1396 | case 53: |
1397 | ins->effects[3].fxSpeed = dest; |
1398 | break; |
1399 | |
1400 | //CHNG EFF#4 OSCSPEED |
1401 | case 54: |
1402 | ins->effects[3].oscSpeed = dest; |
1403 | break; |
1404 | |
1405 | //CHNG EFF#4 OSCSELECT |
1406 | case 55: |
1407 | if (dest > 1){ |
1408 | dest = 1; |
1409 | } |
1410 | ins->effects[3].oscSelect = dest; |
1411 | break; |
1412 | |
1413 | //CHNG EFF#4 TYPE |
1414 | case 56: |
1415 | if (dest >= SE_NROFEFFECTS){ |
1416 | dest = (SE_NROFEFFECTS - 1); |
1417 | } |
1418 | ins->effects[3].effectType = dest; |
1419 | break; |
1420 | |
1421 | //CHNG EFF#4 RESETEFFECT |
1422 | case 57: |
1423 | if (dest > 1){ |
1424 | dest = 1; |
1425 | } |
1426 | ins->effects[3].resetEffect = dest; |
1427 | break; |
1428 | |
1429 | //CHNG RESET WAVE #1 |
1430 | case 58: |
1431 | if (dest > 1){ |
1432 | dest = 1; |
1433 | } |
1434 | ins->m_ResetWave[0] = dest; |
1435 | break; |
1436 | |
1437 | //CHNG RESET WAVE #2 |
1438 | case 59: |
1439 | if (dest > 1){ |
1440 | dest = 1; |
1441 | } |
1442 | ins->m_ResetWave[1] = dest; |
1443 | break; |
1444 | |
1445 | //CHNG RESET WAVE #3 |
1446 | case 60: |
1447 | if (dest > 1){ |
1448 | dest = 1; |
1449 | } |
1450 | ins->m_ResetWave[2] = dest; |
1451 | break; |
1452 | |
1453 | //CHNG RESET WAVE #4 |
1454 | case 61: |
1455 | if (dest > 1){ |
1456 | dest = 1; |
1457 | } |
1458 | ins->m_ResetWave[3] = dest; |
1459 | break; |
1460 | |
1461 | //CHNG RESET WAVE #5 |
1462 | case 62: |
1463 | if (dest > 1){ |
1464 | dest = 1; |
1465 | } |
1466 | ins->m_ResetWave[4] = dest; |
1467 | break; |
1468 | |
1469 | //CHNG RESET WAVE #6 |
1470 | case 63: |
1471 | if (dest > 1){ |
1472 | dest = 1; |
1473 | } |
1474 | ins->m_ResetWave[5] = dest; |
1475 | break; |
1476 | |
1477 | //CHNG RESET WAVE #7 |
1478 | case 64: |
1479 | if (dest > 1){ |
1480 | dest = 1; |
1481 | } |
1482 | ins->m_ResetWave[6] = dest; |
1483 | break; |
1484 | |
1485 | //CHNG RESET WAVE #8 |
1486 | case 65: |
1487 | if (dest > 1){ |
1488 | dest = 1; |
1489 | } |
1490 | ins->m_ResetWave[7] = dest; |
1491 | break; |
1492 | |
1493 | //CHNG RESET WAVE #9 |
1494 | case 66: |
1495 | if (dest > 1){ |
1496 | dest = 1; |
1497 | } |
1498 | ins->m_ResetWave[8] = dest; |
1499 | break; |
1500 | |
1501 | //CHNG RESET WAVE #10 |
1502 | case 67: |
1503 | if (dest > 1){ |
1504 | dest = 1; |
1505 | } |
1506 | ins->m_ResetWave[9] = dest; |
1507 | break; |
1508 | |
1509 | //CHNG RESET WAVE #11 |
1510 | case 68: |
1511 | if (dest > 1){ |
1512 | dest = 1; |
1513 | } |
1514 | ins->m_ResetWave[10] = dest; |
1515 | break; |
1516 | |
1517 | //CHNG RESET WAVE #12 |
1518 | case 69: |
1519 | if (dest > 1){ |
1520 | dest = 1; |
1521 | } |
1522 | ins->m_ResetWave[11] = dest; |
1523 | break; |
1524 | |
1525 | //CHNG RESET WAVE #13 |
1526 | case 70: |
1527 | if (dest > 1){ |
1528 | dest = 1; |
1529 | } |
1530 | ins->m_ResetWave[12] = dest; |
1531 | break; |
1532 | |
1533 | //CHNG RESET WAVE #14 |
1534 | case 71: |
1535 | if (dest > 1){ |
1536 | dest = 1; |
1537 | } |
1538 | ins->m_ResetWave[13] = dest; |
1539 | break; |
1540 | |
1541 | //CHNG RESET WAVE #15 |
1542 | case 72: |
1543 | if (dest > 1){ |
1544 | dest = 1; |
1545 | } |
1546 | ins->m_ResetWave[14] = dest; |
1547 | break; |
1548 | |
1549 | //CHNG RESET WAVE #16 |
1550 | case 73: |
1551 | if (dest > 1){ |
1552 | dest = 1; |
1553 | } |
1554 | ins->m_ResetWave[15] = dest; |
1555 | break; |
1556 | |
1557 | //CHNG BPM |
1558 | case 74: |
1559 | if (dest <= 10){ |
1560 | dest = 10; |
1561 | } |
1562 | if (dest > 220){ |
1563 | dest = 220; |
1564 | } |
1565 | p->curSubsong.tempo = dest; |
1566 | tempo = (double)(p->curSubsong.tempo); |
1567 | tempo = (tempo / 60); |
1568 | tempo = (tempo * 32); |
1569 | p->samplesPerBeat = (int)(44100 / tempo); |
1570 | break; |
1571 | |
1572 | //CHNG GROOVE |
1573 | case 75: |
1574 | if (dest > 3){ |
1575 | dest = 3; |
1576 | } |
1577 | p->curSubsong.groove = dest; |
1578 | break; |
1579 | |
1580 | //FIRE EXTERNAL EVENT |
1581 | case 76: |
1582 | //this effect is for controlling external code |
1583 | //like animation and whatnot |
1584 | //similar to how 8xx is used in Travolta's 'testlast' .mod |
1585 | |
1586 | //do take note of audio latency when dealing with this. |
1587 | |
1588 | //This is called UserEvent in ocx player doc, I think |
1589 | break; |
1590 | } |
1591 | } |
1592 | |
1593 | static void channelSomething(Player *p, int chanNum) |
1594 | { |
1595 | int _local2; |
1596 | int _local3; |
1597 | int note; |
1598 | int dest; |
1599 | int contrScript; |
1600 | int spd; |
1601 | |
1602 | if (!p->PQV) return; |
1603 | if (p->someCounter != p->WDTECTE) return; |
1604 | |
1605 | if (p->sePmSong == SE_PM_PATTERN){ |
1606 | if (chanNum > 0) return; |
1607 | _local2 = p->AMYGPFQCHSW; |
1608 | _local3 = p->ISWLKT; |
1609 | } else { |
1610 | if (p->curSubsong.mutedChans[chanNum] == 1) return; |
1611 | |
1612 | _local3 = p->tuneChannels[chanNum].LJHG; |
1613 | _local2 = p->curSubsong.orders[chanNum][p->tuneChannels[chanNum].EQMIWERPIF].patIndex; |
1614 | } |
1615 | note = p->rows[(_local2 * 64) + _local3].note; |
1616 | if (note != 0) { |
1617 | playInstrument(p, chanNum, p->rows[(_local2 * 64) + _local3].instr, note); |
1618 | } |
1619 | contrScript = p->rows[(_local2 * 64) + _local3].command; |
1620 | dest = p->rows[(_local2 * 64) + _local3].dest; |
1621 | spd = p->rows[(_local2 * 64) + _local3].spd; |
1622 | patEffect(p, note, contrScript, dest, spd, chanNum); |
1623 | } |
1624 | |
1625 | static void ABH(Player *p) |
1626 | { |
1627 | int i, j0, j1; |
1628 | int _local2; |
1629 | Order *_local3; |
1630 | int _local4; |
1631 | bool _local5; |
1632 | int _local6; |
1633 | Order *_local9; |
1634 | int _local10; |
1635 | int _local11; |
1636 | |
1637 | if (!p->PQV) return; |
1638 | |
1639 | p->someCounter--; |
1640 | if (p->someCounter == 0){ |
1641 | if (p->sePmSong == SE_PM_PATTERN){ |
1642 | if (!(p->ISWLKT & 1)){ |
1643 | p->WDTECTE = (8 - p->curSubsong.groove); |
1644 | } else { |
1645 | p->WDTECTE = (8 + p->curSubsong.groove); |
1646 | } |
1647 | } else { |
1648 | if (!(p->posFine & 1)){ |
1649 | p->WDTECTE = (8 - p->curSubsong.groove); |
1650 | } else { |
1651 | p->WDTECTE = (8 + p->curSubsong.groove); |
1652 | } |
1653 | } |
1654 | p->someCounter = p->WDTECTE; |
1655 | if (p->sePmSong == SE_PM_PATTERN){ |
1656 | p->ISWLKT++; |
1657 | p->ISWLKT = (p->ISWLKT % p->DONGS); |
1658 | } else { |
1659 | for (i = 0; i < p->channelNumber; i++) { |
1660 | TuneChannel *tc = &p->tuneChannels[i]; |
1661 | |
1662 | tc->LJHG++; |
1663 | _local3 = p->curSubsong.orders[i]; |
1664 | _local4 = tc->EQMIWERPIF; |
1665 | if (_local4 == -1){ |
1666 | _local4 = 0; |
1667 | } |
1668 | _local2 = _local3[_local4].patLen; |
1669 | if ((((tc->LJHG == _local2)) || ((tc->EQMIWERPIF == -1)))){ |
1670 | tc->LJHG = 0; |
1671 | tc->EQMIWERPIF++; |
1672 | p->curSubsong.mutedChans[i] = p->mutedChans[i]; |
1673 | } |
1674 | |
1675 | } |
1676 | p->posFine++; |
1677 | if (p->posFine == 64){ |
1678 | p->posFine = 0; |
1679 | p->posCoarse++; |
1680 | } |
1681 | if ((((p->posCoarse == p->curSubsong.endPosCoarse)) && ((p->posFine == p->curSubsong.endPosFine)))){ |
1682 | if (p->curSubsong.isLooping){ |
1683 | _local5 = false; |
1684 | |
1685 | for (j0 = 0; j0 < SE_MAXCHANS; j0++) { |
1686 | _local6 = 0; |
1687 | |
1688 | _local11 = 0; |
1689 | _local9 = p->curSubsong.orders[j0]; |
1690 | _local10 = ((p->curSubsong.loopPosCoarse * 64) + p->curSubsong.loopPosFine); |
1691 | for (j1 = 0; j1 < 0x0100; j1++) { |
1692 | if (_local6 > _local10){ |
1693 | if (j1 != _local10){ |
1694 | j1--; |
1695 | } |
1696 | break; |
1697 | } |
1698 | _local11 = _local6; |
1699 | _local6 = (_local6 + _local9[j1].patLen); |
1700 | |
1701 | } |
1702 | if (j1 == 0x0100){ |
1703 | p->PQV = 0; |
1704 | _local5 = true; |
1705 | break; |
1706 | } |
1707 | _local10 = (_local10 - _local11); |
1708 | _local10 = (_local10 & 63); |
1709 | p->tuneChannels[j0].EQMIWERPIF = j1; |
1710 | p->tuneChannels[j0].LJHG = _local10; |
1711 | |
1712 | } |
1713 | if (_local5 == false){ |
1714 | p->posCoarse = p->curSubsong.loopPosCoarse; |
1715 | p->posFine = p->curSubsong.loopPosFine; |
1716 | p->loopCount++; |
1717 | } |
1718 | } else { |
1719 | p->PQV = 0; |
1720 | p->sePmSong = SE_PM_SONG; |
1721 | p->posCoarse = p->curSubsong.startPosCoarse; |
1722 | p->posFine = p->curSubsong.startPosFine; |
1723 | } |
1724 | } |
1725 | } |
1726 | } |
1727 | } |
1728 | |
1729 | void advanceTick(Player *p) |
1730 | { |
1731 | int i; |
1732 | ABH(p); |
1733 | |
1734 | for (i = 0; i < p->channelNumber; i++) { |
1735 | channelSomething(p, i); |
1736 | if (p->tuneChannels[i].insNum != -1) { |
1737 | channelSomethingElse(p, i); |
1738 | instrEffect(p, i); |
1739 | } |
1740 | } |
1741 | } |
1742 | |
1743 | void mixChunk(Player *p, int16_t *outBuff, uint playbackBufferSize) |
1744 | { |
1745 | int i, j; |
1746 | uint sampleNum; |
1747 | int amp, smp, pos; |
1748 | int32_t audioMainR, audioMainL; |
1749 | int32_t audioDelayR, audioDelayL; |
1750 | uint otherDelayTime; |
1751 | Voice *v; |
1752 | TuneChannel *tc; |
1753 | int insNum; |
1754 | |
1755 | //We just don't know! |
1756 | uint dword_6632774C = 0; |
1757 | |
1758 | if ( p->channelNumber > 0 ) |
1759 | { |
1760 | while ( playbackBufferSize > 0 ) |
1761 | { |
1762 | if ( p->otherSamplesPerBeat >= playbackBufferSize ) |
1763 | { |
1764 | p->otherSamplesPerBeat = p->otherSamplesPerBeat - playbackBufferSize; |
1765 | sampleNum = playbackBufferSize; |
1766 | } |
1767 | else |
1768 | { |
1769 | sampleNum = p->otherSamplesPerBeat; |
1770 | p->otherSamplesPerBeat = p->samplesPerBeat * p->SAMPLEFREQUENCY / 44100; |
1771 | } |
1772 | playbackBufferSize -= sampleNum; |
1773 | |
1774 | for (i=0; i < p->channelNumber; ++i ) |
1775 | { |
1776 | v = &p->voices[i]; tc = &p->tuneChannels[i]; |
1777 | |
1778 | insNum = tc->insNum; |
1779 | if ( insNum == -1 ) |
1780 | { |
1781 | v->waveBuff = p->silentBuffer; |
1782 | v->isSample = 0; |
1783 | } |
1784 | else if ( !tc->sampleBuffer ) |
1785 | { |
1786 | int waveNum = p->instruments[insNum].waveform; |
1787 | v->wavelength = (p->instruments[insNum].wavelength) - 1; |
1788 | v->waveBuff = tc->synthBuffers[waveNum]; |
1789 | v->isSample = 0; |
1790 | } |
1791 | else |
1792 | { |
1793 | v->waveBuff = tc->sampleBuffer; |
1794 | v->sampPos = tc->sampPos; |
1795 | v->smpLoopStart = tc->smpLoopStart; |
1796 | v->smpLoopEnd = tc->smpLoopEnd; |
1797 | v->hasLoop = tc->hasLoop; |
1798 | v->hasBidiLoop = tc->hasBidiLoop; |
1799 | v->isPlayingBackward = tc->isPlayingBackward; |
1800 | v->hasLooped = tc->hasLooped; |
1801 | v->isSample = 1; |
1802 | } |
1803 | |
1804 | if ( tc->freq < 10 ) |
1805 | tc->freq = 10; |
1806 | |
1807 | v->gain = (tc->volume + 10000) / 39; |
1808 | v->delta = (tc->freq << 8) / p->SAMPLEFREQUENCY; |
1809 | if (v->delta != v->last_delta) |
1810 | { |
1811 | double fdelta = (double)v->delta * (1.0 / (double)0x100); |
1812 | v->last_delta = v->delta; |
1813 | resampler_set_rate(v->resampler[0], fdelta); |
1814 | } |
1815 | |
1816 | if ( v->gain > 0x100 ) |
1817 | v->gain = 0x100; |
1818 | if ( tc->panning ) |
1819 | { |
1820 | if ( tc->panning <= 0 ) |
1821 | { |
1822 | v->gainRight = 0x100; |
1823 | v->gainLeft = 0x100 + tc->panning; |
1824 | } |
1825 | else |
1826 | { |
1827 | v->gainLeft = 0x100; |
1828 | v->gainRight = 0x100 - tc->panning; |
1829 | } |
1830 | } |
1831 | else |
1832 | { |
1833 | v->gainRight = 0x100; |
1834 | v->gainLeft = 0x100; |
1835 | } |
1836 | if ( dword_6632774C ) |
1837 | { |
1838 | //v->gainDelay = word_6632B9F4[i]; |
1839 | } |
1840 | else |
1841 | { |
1842 | v->gainDelay = p->curSubsong.chanDelayAmt[i]; |
1843 | } |
1844 | v->gainRight = (v->gain * v->gainRight) >> 8; |
1845 | v->gainLeft = (v->gain * v->gainLeft) >> 8; |
1846 | v->gainDelayRight = (v->gainDelay * v->gainRight) >> 8; |
1847 | v->gainDelayLeft = (v->gainDelay * v->gainLeft) >> 8; |
1848 | } |
1849 | if ( dword_6632774C ) |
1850 | { |
1851 | //amp = word_6632B964; |
1852 | //otherDelayTime = word_6632BB24; |
1853 | } |
1854 | else |
1855 | { |
1856 | amp = p->curSubsong.amplification; |
1857 | otherDelayTime = p->curSubsong.delayTime / (44100 / p->SAMPLEFREQUENCY); |
1858 | } |
1859 | if ( outBuff ) |
1860 | { |
1861 | if ( sampleNum > 0 ) |
1862 | { |
1863 | for(i = 0; i < sampleNum; i++) |
1864 | { |
1865 | audioMainR = 0; |
1866 | audioMainL = 0; |
1867 | audioDelayR = 0; |
1868 | audioDelayL = 0; |
1869 | if ( p->channelNumber > 0 ) |
1870 | { |
1871 | for (j = 0; j < p->channelNumber; ++j) |
1872 | { |
1873 | v = &p->voices[j]; |
1874 | if ( v->isSample == 1 ) |
1875 | { |
1876 | if ( v->sampPos != -1 || resampler_get_avail(v->resampler[0]) ) |
1877 | { |
1878 | //interpolation |
1879 | sample_t s; |
1880 | while ( v->sampPos != -1 && resampler_get_min_fill(v->resampler[0]) ) |
1881 | { |
1882 | s = v->waveBuff[v->sampPos]; |
1883 | resampler_write_pair(v->resampler[0], s, s); |
1884 | if ( v->isPlayingBackward ) |
1885 | { |
1886 | v->sampPos--; |
1887 | if ( v->sampPos <= v->smpLoopStart ) |
1888 | { |
1889 | v->isPlayingBackward = 0; |
1890 | v->sampPos++; |
1891 | } |
1892 | } |
1893 | else |
1894 | { |
1895 | v->sampPos++; |
1896 | if ( v->sampPos >= v->smpLoopEnd ) |
1897 | { |
1898 | if ( v->hasLoop ) |
1899 | { |
1900 | v->hasLooped = 1; |
1901 | if ( v->hasBidiLoop ) |
1902 | { |
1903 | v->isPlayingBackward = 1; |
1904 | v->sampPos--; |
1905 | } |
1906 | else |
1907 | { |
1908 | v->sampPos += v->smpLoopStart - v->smpLoopEnd; |
1909 | } |
1910 | } |
1911 | else |
1912 | { |
1913 | v->sampPos = -1; |
1914 | } |
1915 | } |
1916 | } |
1917 | } |
1918 | |
1919 | //smp = intp->interpSamp(v); |
1920 | resampler_read_pair(v->resampler[0], &s, &s); |
1921 | smp = s; |
1922 | |
1923 | audioMainR += (smp * v->gainRight) >> 8; |
1924 | audioMainL += (smp * v->gainLeft) >> 8; |
1925 | audioDelayR += (smp * v->gainDelayRight) >> 8; |
1926 | audioDelayL += (smp * v->gainDelayLeft) >> 8; |
1927 | } |
1928 | } |
1929 | else |
1930 | { |
1931 | //interpolation |
1932 | //smp = intp->interpSynt(v); |
1933 | sample_t s; |
1934 | while ( resampler_get_min_fill(v->resampler[0]) ) |
1935 | { |
1936 | s = v->waveBuff[v->synthPos]; |
1937 | resampler_write_pair(v->resampler[0], s, s); |
1938 | v->synthPos++; |
1939 | v->synthPos &= v->wavelength; |
1940 | } |
1941 | resampler_read_pair(v->resampler[0], &s, &s); |
1942 | smp = s; |
1943 | |
1944 | audioMainR += (smp * v->gainRight) >> 8; |
1945 | audioMainL += (smp * v->gainLeft) >> 8; |
1946 | audioDelayR += (smp * v->gainDelayRight) >> 8; |
1947 | audioDelayL += (smp * v->gainDelayLeft) >> 8; |
1948 | } |
1949 | } |
1950 | } |
1951 | |
1952 | audioMainL = (p->delayBufferL[p->delayPos] + audioMainL / p->channelNumber) / 2; |
1953 | audioMainR = (p->delayBufferR[p->delayPos] + audioMainR / p->channelNumber) / 2; |
1954 | audioMainR = audioMainR * amp / 100; |
1955 | audioMainL = audioMainL * amp / 100; |
1956 | //clip audio |
1957 | if ( audioMainR < -32760 ) audioMainR = -32760; |
1958 | if ( audioMainR > 32760 ) audioMainR = 32760; |
1959 | if ( audioMainL < -32760 ) audioMainL = -32760; |
1960 | if ( audioMainL > 32760 ) audioMainL = 32760; |
1961 | |
1962 | //interleaved buffer |
1963 | if ( p->overlapPos < SE_OVERLAP ) |
1964 | { |
1965 | audioMainR = p->overlapPos * audioMainR / 100; |
1966 | audioMainR += (SE_OVERLAP - p->overlapPos) * p->overlapBuff[p->overlapPos*2] / 100; |
1967 | audioMainL = p->overlapPos * audioMainL / 100; |
1968 | audioMainL += (SE_OVERLAP - p->overlapPos) * p->overlapBuff[p->overlapPos*2+1] / 100; |
1969 | ++p->overlapPos; |
1970 | } |
1971 | |
1972 | //output |
1973 | *outBuff++ = audioMainR; |
1974 | *outBuff++ = audioMainL; |
1975 | |
1976 | p->delayBufferL[p->delayPos] = (((audioDelayL / p->channelNumber) + p->delayBufferL[p->delayPos]) / 2); |
1977 | p->delayBufferR[p->delayPos] = (((audioDelayR / p->channelNumber) + p->delayBufferR[p->delayPos]) / 2); |
1978 | p->delayPos = ++p->delayPos % otherDelayTime; |
1979 | } |
1980 | } |
1981 | } |
1982 | |
1983 | if ( p->channelNumber > 0 ) |
1984 | { |
1985 | for (i = 0; i < p->channelNumber; ++i) |
1986 | { |
1987 | v = &p->voices[i]; tc = &p->tuneChannels[i]; |
1988 | if ( v->isSample ) |
1989 | { |
1990 | tc->sampPos = v->sampPos; |
1991 | tc->isPlayingBackward = v->isPlayingBackward; |
1992 | tc->hasLooped = v->hasLooped; |
1993 | } |
1994 | } |
1995 | } |
1996 | if ( p->otherSamplesPerBeat == (p->samplesPerBeat * p->SAMPLEFREQUENCY) / 44100 ) |
1997 | { |
1998 | p->bkpDelayPos = p->delayPos; |
1999 | for (i = 0; i < p->channelNumber; i++) |
2000 | { |
2001 | p->voices[i].bkpSynthPos = p->voices[i].synthPos; |
2002 | resampler_dup_inplace(p->voices[i].resampler[1], p->voices[i].resampler[0]); |
2003 | } |
2004 | |
2005 | p->overlapPos = 0; |
2006 | if ( outBuff ) |
2007 | { |
2008 | for (i = 0; i < SE_OVERLAP; i++) |
2009 | { |
2010 | audioMainR = 0; |
2011 | audioMainL = 0; |
2012 | audioDelayR = 0; |
2013 | audioDelayL = 0; |
2014 | if ( p->channelNumber > 0 ) |
2015 | { |
2016 | for (j = 0; j < p->channelNumber; j++) |
2017 | { |
2018 | v = &p->voices[j]; |
2019 | if ( v->isSample == 1 ) |
2020 | { |
2021 | if ( v->sampPos != -1 || resampler_get_avail(v->resampler[1]) ) |
2022 | { |
2023 | //interpolation |
2024 | //smp = intp->interpSamp(v); |
2025 | sample_t s; |
2026 | while ( v->sampPos != -1 && resampler_get_min_fill(v->resampler[1]) ) |
2027 | { |
2028 | s = v->waveBuff[v->sampPos]; |
2029 | resampler_write_pair(v->resampler[1], s, s); |
2030 | if ( v->isPlayingBackward ) |
2031 | { |
2032 | v->sampPos--; |
2033 | if ( v->sampPos <= v->smpLoopStart ) |
2034 | { |
2035 | v->isPlayingBackward = 0; |
2036 | v->sampPos++; |
2037 | } |
2038 | } |
2039 | else |
2040 | { |
2041 | v->sampPos++; |
2042 | if ( v->sampPos >= v->smpLoopEnd ) |
2043 | { |
2044 | if ( v->hasLoop ) |
2045 | { |
2046 | v->hasLooped = 1; |
2047 | if ( v->hasBidiLoop ) |
2048 | { |
2049 | v->isPlayingBackward = 1; |
2050 | v->sampPos--; |
2051 | } |
2052 | else |
2053 | { |
2054 | v->sampPos += v->smpLoopStart - v->smpLoopEnd; |
2055 | } |
2056 | } |
2057 | else |
2058 | { |
2059 | v->sampPos = -1; |
2060 | } |
2061 | } |
2062 | } |
2063 | } |
2064 | resampler_read_pair(v->resampler[1], &s, &s); |
2065 | smp = s; |
2066 | |
2067 | audioMainR += (smp * v->gainRight) >> 8; |
2068 | audioMainL += (smp * v->gainLeft) >> 8; |
2069 | audioDelayR += (smp * v->gainDelayRight) >> 8; |
2070 | audioDelayL += (smp * v->gainDelayLeft) >> 8; |
2071 | } |
2072 | } |
2073 | else |
2074 | { |
2075 | //interpolation |
2076 | //smp = intp->interpSynt(v); |
2077 | sample_t s; |
2078 | while ( resampler_get_min_fill(v->resampler[1]) ) |
2079 | { |
2080 | s = v->waveBuff[v->synthPos]; |
2081 | resampler_write_pair(v->resampler[1], s, s); |
2082 | v->synthPos++; |
2083 | v->synthPos &= v->wavelength; |
2084 | } |
2085 | resampler_read_pair(v->resampler[1], &s, &s); |
2086 | smp = s; |
2087 | |
2088 | audioMainR += (smp * v->gainRight) >> 8; |
2089 | audioMainL += (smp * v->gainLeft) >> 8; |
2090 | audioDelayR += (smp * v->gainDelayRight) >> 8; |
2091 | audioDelayL += (smp * v->gainDelayLeft) >> 8; |
2092 | } |
2093 | } |
2094 | } |
2095 | |
2096 | audioMainL = (p->delayBufferL[p->delayPos] + audioMainL / p->channelNumber) / 2; |
2097 | audioMainR = (p->delayBufferR[p->delayPos] + audioMainR / p->channelNumber) / 2; |
2098 | audioMainR = audioMainR * amp / 100; |
2099 | audioMainL = audioMainL * amp / 100; |
2100 | //clip audio |
2101 | if ( audioMainR < -32760 ) audioMainR = -32760; |
2102 | if ( audioMainR > 32760 ) audioMainR = 32760; |
2103 | if ( audioMainL < -32760 ) audioMainL = -32760; |
2104 | if ( audioMainL > 32760 ) audioMainL = 32760; |
2105 | |
2106 | p->overlapBuff[i * 2] = audioMainR; |
2107 | p->overlapBuff[i*2+1] = audioMainL; |
2108 | |
2109 | p->delayPos = ++p->delayPos % otherDelayTime; |
2110 | } |
2111 | } |
2112 | p->delayPos = p->bkpDelayPos; |
2113 | for (i = 0; i < p->channelNumber; i++) p->voices[i].synthPos = p->voices[i].bkpSynthPos; |
2114 | |
2115 | //dword_66327200 = 2 * sampleNum; |
2116 | advanceTick(p); |
2117 | } |
2118 | } |
2119 | return; |
2120 | } |
2121 | memset(outBuff, 0, playbackBufferSize * 2 *2); |
2122 | } |
2123 | |
2124 | /*void newSong(void) |
2125 | { |
2126 | var _local1:int; |
2127 | var i:int; |
2128 | var j:int; |
2129 | var _local4:Order; |
2130 | var _local6:Vector.<Order>; |
2131 | var _local7:Row; |
2132 | |
2133 | reset(); |
2134 | AMYGPFQCHSW = 1; |
2135 | selectedSubsong = 0; |
2136 | WDTECTE = 8; |
2137 | AMVM = 0x100; |
2138 | synSong.h.subsongNum = 1; |
2139 | synSong.h.version = 3457; |
2140 | subsongs = new Vector.<Subsong>(); |
2141 | subsongs.push(new Subsong()); |
2142 | var subs0:Subsong = subsongs[0]; |
2143 | curSubsong = subsongs[selectedSubsong]; |
2144 | |
2145 | subs0.tempo = 120; |
2146 | subs0.groove = 0; |
2147 | subs0.startPosCoarse = 0; |
2148 | subs0.startPosFine = 0; |
2149 | subs0.loopPosCoarse = 0; |
2150 | subs0.loopPosFine = 0; |
2151 | subs0.endPosCoarse = 1; |
2152 | subs0.endPosFine = 0; |
2153 | subs0.channelNumber = 4; |
2154 | subs0.delayTime = 0x8000; |
2155 | subs0.amplification = 400; |
2156 | subs0.chanDelayAmt = new Vector.<int>(SE_MAXCHANS, true); |
2157 | |
2158 | subs0.m_Name = "Empty"; |
2159 | subs0.mutedChans = new Vector.<int>(SE_MAXCHANS, true); |
2160 | |
2161 | |
2162 | subs0.orders = Tools.malloc_2DVector(Order, SE_MAXCHANS, 0x0100, true, true); |
2163 | for (i = 0; i < SE_MAXCHANS; i++) { |
2164 | _local6 = subs0.orders[i]; |
2165 | for (j = 0; j < 0x0100; j++) { |
2166 | _local6[j].patIndex = 0; |
2167 | _local6[j].patLen = 0; |
2168 | } |
2169 | } |
2170 | |
2171 | synSong.h.patNum = 2; |
2172 | synSong.rows = Tools.malloc_1DVector(Row, 64 * synSong.h.patNum); |
2173 | |
2174 | for (i = 0; i < (64 * synSong.h.patNum); i++) { |
2175 | rows[i].dest = 0; |
2176 | rows[i].note = 0; |
2177 | rows[i].instr = 0; |
2178 | rows[i].command = 0; |
2179 | rows[i].spd = 0; |
2180 | |
2181 | } |
2182 | patternNames = new Vector.<String>(); |
2183 | patternNames.push("Empty"); |
2184 | patternNames.push("Pat1"); |
2185 | synSong.h.instrNum = 1; |
2186 | synSong.instruments = new Vector.<Instrument>(); |
2187 | synSong.instruments.push(new Instrument()); |
2188 | |
2189 | mutedChans = new Vector.<int>(SE_MAXCHANS, true); |
2190 | }*/ |
2191 | |
2192 | static void AAUCAPQW(Player *p) |
2193 | { |
2194 | //What is this even for? |
2195 | |
2196 | p->PQV = 0; |
2197 | p->sePmSong = SE_PM_SONG; |
2198 | if (p->subsongs){ |
2199 | p->posCoarse = p->curSubsong.startPosCoarse; |
2200 | p->posFine = p->curSubsong.startPosFine; |
2201 | } |
2202 | } |
2203 | |
2204 | static void IMXFLSSMB(Player *p, int _arg1) |
2205 | { |
2206 | p->PQV = 1; |
2207 | p->AMYGPFQCHSW = _arg1; |
2208 | p->ISWLKT = 63; |
2209 | p->someCounter = 1; |
2210 | p->sePmSong = SE_PM_PATTERN; |
2211 | p->WDTECTE = p->subsongs[0].tempo - p->subsongs[0].groove; |
2212 | } |
2213 | |
2214 | void initSubsong(Player *p, int num) |
2215 | { |
2216 | int _local2; |
2217 | int i, j; |
2218 | Order *_local5; |
2219 | bool _local6; |
2220 | int _local7; |
2221 | int _local8; |
2222 | double tempo; |
2223 | |
2224 | //reset instruments |
2225 | memcpy(p->instruments, p->synSong->instruments, p->synSong->h.instrNum * sizeof(Instrument)); |
2226 | |
2227 | p->loopCount = 0; |
2228 | |
2229 | if (num >= p->synSong->h.subsongNum) return; |
2230 | |
2231 | p->selectedSubsong = num; |
2232 | p->curSubsong = p->subsongs[p->selectedSubsong]; |
2233 | p->channelNumber = p->curSubsong.channelNumber; |
2234 | reset(p); |
2235 | _local6 = false; |
2236 | |
2237 | for (i = 0; i < SE_MAXCHANS; i++) { |
2238 | p->m_LastNotes[i] = 0; |
2239 | _local2 = 0; |
2240 | |
2241 | _local8 = 0; |
2242 | _local5 = p->curSubsong.orders[i]; |
2243 | _local7 = (((p->curSubsong.startPosCoarse * 64) + p->curSubsong.startPosFine) - 1); |
2244 | for (j = 0; j < 0x0100; j++) { |
2245 | if (_local2 >= _local7){ |
2246 | if (j != _local7){ |
2247 | j--; |
2248 | } |
2249 | break; |
2250 | } |
2251 | _local8 = _local2; |
2252 | _local2 = (_local2 + _local5[j].patLen); |
2253 | |
2254 | } |
2255 | if (j == 0x0100){ |
2256 | _local6 = true; |
2257 | break; |
2258 | } |
2259 | _local7 = (_local7 - _local8); |
2260 | _local7 = (_local7 & 63); |
2261 | p->tuneChannels[i].EQMIWERPIF = j; |
2262 | p->tuneChannels[i].LJHG = _local7; |
2263 | p->curSubsong.mutedChans[i] = p->mutedChans[i]; |
2264 | |
2265 | } |
2266 | if (_local6 == false){ |
2267 | p->someCounter = 1; |
2268 | p->sePmSong = SE_PM_SONG; |
2269 | p->PQV = 1; |
2270 | p->WDTECTE = (8 + p->curSubsong.groove); |
2271 | if (p->curSubsong.tempo){ |
2272 | tempo = (double)(p->curSubsong.tempo); |
2273 | tempo = (tempo / 60); |
2274 | tempo = (tempo * 32); |
2275 | p->samplesPerBeat = (int)((44100 / tempo)); |
2276 | p->otherSamplesPerBeat = p->samplesPerBeat; |
2277 | } |
2278 | if (p->curSubsong.startPosFine == 0){ |
2279 | p->posCoarse = p->curSubsong.startPosCoarse - 1; |
2280 | } else { |
2281 | p->posCoarse = p->curSubsong.startPosCoarse; |
2282 | } |
2283 | p->posFine = p->curSubsong.startPosFine - 1; |
2284 | p->posFine = p->posFine & 63; |
2285 | } |
2286 | } |
2287 | |
2288 | int loadSong(Player *p, const Song *synSong) |
2289 | { |
2290 | int i; |
2291 | void *ptr; |
2292 | |
2293 | AAUCAPQW(p); |
2294 | reset(p); |
2295 | //clearSongData(); |
2296 | p->synSong = synSong; |
2297 | |
2298 | //pass things locally |
2299 | //not much purpouse here |
2300 | //nor in AS3 |
2301 | //why did I do it |
2302 | p->rows = synSong->rows; |
2303 | p->patternNames = (const char **) synSong->patternNames; |
2304 | |
2305 | ptr = realloc(p->instruments, synSong->h.instrNum * sizeof(Instrument)); |
2306 | if (!ptr) return -1; |
2307 | p->instruments = (Instrument *) ptr; |
2308 | |
2309 | p->subsongs = synSong->subsongs; |
2310 | p->arpTable = synSong->arpTable; |
2311 | p->samples = (const int16_t **) synSong->samples; |
2312 | |
2313 | //Do we really need to? |
2314 | //What would Syntrax do? |
2315 | for (i = 0; i < SE_MAXCHANS; i++) { |
2316 | p->mutedChans[i] = synSong->subsongs[0].mutedChans[i]; |
2317 | } |
2318 | initSubsong(p, 0); |
2319 | |
2320 | return 0; |
2321 | } |
2322 | |
2323 | bool playerGetSongEnded(Player *p) |
2324 | { |
2325 | return p->PQV == 0; |
2326 | } |
2327 | |
2328 | uint playerGetLoopCount(Player *p) |
2329 | { |
2330 | return p->loopCount; |
2331 | } |
2332 | |
2333 | void playerGetInfo(Player *p, syntrax_info *info) |
2334 | { |
2335 | int i, j; |
2336 | info->coarse = p->posCoarse; |
2337 | info->fine = p->posFine; |
2338 | info->subsongName = p->curSubsong.m_Name; |
2339 | info->selectedSubs = p->selectedSubsong; |
2340 | info->totalSubs = p->synSong->h.subsongNum; |
2341 | for (i = 0, j = 0; i < p->channelNumber; i++) |
2342 | { |
2343 | Voice *v = &p->voices[i]; |
2344 | if (v->waveBuff != p->silentBuffer) |
2345 | { |
2346 | if (v->isSample) |
2347 | { |
2348 | if (v->sampPos != -1) j++; |
2349 | } |
2350 | else j++; |
2351 | } |
2352 | } |
2353 | info->channelsPlaying = j; |
2354 | } |
2355 |
Built with git-ssb-web