git ssb

0+

kode54 / syntrax-c



Tree: 7048945153747ca4d19035d8a769f8fa56e4076d

Files: 7048945153747ca4d19035d8a769f8fa56e4076d / src / syntrax / syntrax.c

76113 bytesRaw
1#include <stdint.h>
2#include <stdlib.h>
3#include <string.h>
4#define _USE_MATH_DEFINES
5#include <math.h>
6#include <time.h>
7
8#include "syntrax.h"
9#include "file.h"
10#include "resampler.h"
11
12static 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
28 tc->EQMIWERPIF = 0;
29 tc->LJHG = 0;
30 tc->insNum = -1;
31 tc->HFRLJCG = 0;
32 tc->ACKCWV = 0;
33 tc->ELPHLDR = 0;
34 tc->TVORFCC = 0;
35 tc->freq = 0;
36 tc->BNWIGU = 0;
37 tc->UHYDBDDI = 0;
38 tc->XESAWSO = 0;
39 tc->JOEEPJCI = 0;
40 tc->fmDelay = 0;
41 tc->sampleBuffer = NULL;
42 tc->smpLoopEnd = 0;
43 //tc->smpLength = 0;
44 tc->sampPos = 0;
45 tc->synthPos = 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 for (j = 0; j < 4; j++) {
57 VoiceEffect *ve = &tc->effects[j];
58
59 ve->QOMCBTRPXF = 0;
60 ve->TIPUANVVR = 0;
61 ve->MFATTMREMVP = 0;
62 ve->MDTMBBIQHRQ = 0;
63 ve->RKF = 0;
64 ve->DQVLFV = 0;
65 ve->ILHG = 0;
66 ve->YLKJB = 0;
67 ve->VMBNMTNBQU = 0;
68 ve->ABJGHAUY = 0;
69 ve->SPYK = 0;
70
71 }
72 memset(&tc->synthBuffers, 0, 0x100 * SE_MAXCHANS *2 + 2);
73 }
74 }
75}
76
77static int generateTables(Player *p)
78{
79 int i, j;
80
81 p->dynamorphTable = (int16_t *) malloc(0x100 *2);
82 if (!p->dynamorphTable) return -1;
83
84 for (i = 0; i < 0x0100; i++ ) {
85 p->dynamorphTable[i] = (sin(((M_PI * i) / 128)) * 32760);
86 }
87
88 //debug Asscilloscope says 0xF8 to 0x61FFB
89 //we probably don't have uint24_t at our disposal
90 //uint32_t it is, then
91 p->freqTable = (uint32_t *) malloc(SE_NROFFINETUNESTEPS * 128 *4);
92 if (!p->freqTable) return -1;
93 for (i = 0; i < SE_NROFFINETUNESTEPS; i++) {
94 double x;
95 for (j = 0; j < 128; j++) {
96 x = (((j + 3) * 16) - i);
97 x = (x / 192);
98 x = pow(2, x);
99 x = (x * 220) + 0.5;
100 p->freqTable[i* 128 + j] = (int)(x);
101 }
102 }
103
104 return 0;
105}
106
107void playerDestroy(Player *p)
108{
109 int i;
110
111 if (p) {
112 if (p->dynamorphTable) free(p->dynamorphTable);
113 if (p->freqTable) free(p->freqTable);
114 if (p->silentBuffer) free(p->silentBuffer);
115 if (p->overlapBuff) free(p->overlapBuff);
116 if (p->delayBufferL) free(p->delayBufferL);
117 if (p->delayBufferR) free(p->delayBufferR);
118 if (p->tuneChannels) free(p->tuneChannels);
119 if (p->voices) {
120 for (i = 0; i < SE_MAXCHANS; i++)
121 {
122 resampler_destroy(p->voices[i].resampler[0]);
123 resampler_destroy(p->voices[i].resampler[1]);
124 }
125 free(p->voices);
126 }
127
128 if (p->instruments) free(p->instruments);
129
130 free(p);
131 }
132}
133
134Player * playerCreate(int SAMPLEFREQUENCY)
135{
136 int i, j;
137
138 Player* p;
139
140 srand(time(NULL));
141
142 p = (Player *) calloc(1, sizeof(Player));
143 if (!p) return NULL;
144
145 p->bufflen = BUFFERLENGTH;
146 if (generateTables(p) < 0) goto FAIL;
147
148 p->SAMPLEFREQUENCY = SAMPLEFREQUENCY;
149
150 p->overlapPos = 0;
151
152 p->silentBuffer = malloc(0x0100 *2);
153 if (!p->silentBuffer) goto FAIL;
154 memset(p->silentBuffer, 0, 0x0100 *2);
155
156 p->ISWLKT = 0;
157 p->posCoarse = 0;
158 p->posFine = 0;
159 p->bkpDelayPos = 0;
160 p->DONGS = 0;
161 p->AMYGPFQCHSW = 0;
162 p->selectedSubsong = 0;
163 p->PQV = 0;
164 p->someCounter = 0;
165 p->WDTECTE = 0;
166 p->sePmSong = SE_PM_SONG;
167 p->AMVM = 0x0100;
168 p->channelNumber = 0;
169 p->delayPos = 0;
170
171 p->otherSamplesPerBeat = 2200;
172 p->samplesPerBeat = 2200;
173
174 p->overlapBuff = malloc(SE_OVERLAP * 2 *2 + 2);
175 if (!p->overlapBuff) goto FAIL;
176 p->delayBufferL = malloc(65536 *2);
177 if (!p->delayBufferL) goto FAIL;
178 p->delayBufferR = malloc(65536 *2);
179 if (!p->delayBufferR) goto FAIL;
180
181 p->tuneChannels = malloc(SE_MAXCHANS *sizeof(TuneChannel));
182 if (!p->tuneChannels) goto FAIL;
183 p->voices = malloc(SE_MAXCHANS *sizeof(Voice));
184 if (!p->voices) goto FAIL;
185
186 for (i = 0; i < SE_MAXCHANS; i++)
187 {
188 Voice *v = &p->voices[i];
189 memset(v, 0, sizeof(Voice));
190
191 v->resampler[0] = resampler_create();
192 v->resampler[1] = resampler_create();
193 if (!v->resampler[0] || !v->resampler[1]) goto FAIL;
194 }
195
196 reset(p);
197
198 return p;
199
200FAIL:
201 playerDestroy(p);
202 return NULL;
203}
204
205static void instrEffect(Player *p, int chanNum)
206{
207 //TODO: minimize all the vars
208 //too many of them
209 int i, j;
210 int _local3;
211 int destWave;
212 int16_t *destBuff;
213 int pos;
214 int srcWave1;
215 int _local10;
216 int srcWave2;
217 int16_t *srcBuff1;
218 int16_t *srcBuff2;
219 double _local16;
220 double _local17;
221 double _local18;
222 int oscWave;
223 int16_t *oscBuff;
224 int _local21;
225 int _local22;
226 int _local23;
227 int _local25;
228 int _local26;
229 int _local27;
230 int var1;
231 int var2;
232 double _local30;
233 double _local31;
234 int _local32;
235 int _local33;
236 int _local34;
237 int _local35;
238 int _local36;
239 int _local37;
240 int _local38;
241 int _local39;
242 int _local40;
243 int _local43;
244 int butt, ron, pat, buf2, buf1;
245
246 TuneChannel *tc = &p->tuneChannels[chanNum];
247 const Instrument *ins = &p->instruments[tc->insNum];
248
249 for (i = 0; i < 4; i++ ) {
250 const InstrumentEffect *ie = &ins->effects[i];
251 VoiceEffect *ve = &tc->effects[i];
252
253 ve->MFATTMREMVP = (ve->MFATTMREMVP + ie->oscSpeed);
254 ve->MFATTMREMVP = (ve->MFATTMREMVP & 0xFF);
255 switch (ie->effectType) {
256
257 //NONE
258 case 0:
259 break;
260
261 //NEGATE
262 case 1:
263 destWave = ie->destWave;
264 _local3 = ie->fxSpeed;
265 pos = ve->QOMCBTRPXF;
266 destBuff = tc->synthBuffers[destWave];
267
268 for (j = 0; j < _local3; j++ ) {
269 pos++;
270 pos = (pos & 0xFF);
271 destBuff[pos] = (0 - destBuff[pos]);
272
273 }
274 ve->QOMCBTRPXF = pos;
275 break;
276
277 //SWEEP
278 case 2:
279 destWave = ie->destWave;
280 _local3 = ie->fxSpeed;
281 destBuff = tc->synthBuffers[destWave];
282
283
284 for (pos = 0, j = 0; j < 0x0100; j++ ) {
285 destBuff[j] = (destBuff[j] + pos);
286 destBuff[j] = (destBuff[j] + 0x8000);
287 destBuff[j] = (destBuff[j] & 0xFFFF);
288 destBuff[j] = (destBuff[j] - 0x8000);
289 pos = (pos + _local3);
290
291 }
292 break;
293
294 //AVERAGER
295 case 3:
296 destWave = ie->destWave;
297 srcWave1 = ie->srcWave1;
298 destBuff = tc->synthBuffers[destWave];
299 srcBuff1 = tc->synthBuffers[srcWave1];
300 _local3 = ie->fxSpeed;
301 pos = 0;
302 if (_local3 > 12){
303 _local3 = 12;
304 }
305
306 for (_local10 = 0; _local10 < _local3; _local10++ ) {
307 destBuff[0] = ((srcBuff1[0xFF] + srcBuff1[1]) >> 1);
308
309 for (j = 1; j < 0xFF; j++ ) {
310 destBuff[j] = ((srcBuff1[j - 1] + srcBuff1[j + 1]) >> 1);
311
312 }
313 destBuff[0xFF] = ((srcBuff1[254] + srcBuff1[0]) >> 1);
314
315 }
316 break;
317
318 //WAVEMIX
319 case 4:
320 destWave = ie->destWave;
321 srcWave1 = ie->srcWave1;
322 srcWave2 = ie->srcWave2;
323 destBuff = tc->synthBuffers[destWave];
324 srcBuff1 = tc->synthBuffers[srcWave1];
325 srcBuff2 = tc->synthBuffers[srcWave2];
326 _local3 = ie->fxSpeed;
327 ve->QOMCBTRPXF = (ve->QOMCBTRPXF + _local3);
328 ve->QOMCBTRPXF = (ve->QOMCBTRPXF & 0xFF);
329 pos = ve->QOMCBTRPXF;
330
331 for (j = 0; j < 0x0100; j++ ) {
332 destBuff[j] = ((srcBuff1[j] + srcBuff2[pos]) >> 1);
333 pos++;
334 pos = (pos & 0xFF);
335
336 }
337 break;
338
339 //FILTER
340 case 5:
341 destWave = ie->destWave;
342 srcWave1 = ie->srcWave1;
343 srcWave2 = ie->oscWave - 1;
344 destBuff = tc->synthBuffers[destWave];
345
346 srcBuff1 = tc->synthBuffers[srcWave1];
347 srcBuff2 = srcWave2 >= 0 ? tc->synthBuffers[srcWave2] : NULL;
348 pos = ve->MFATTMREMVP;
349
350 if (ie->oscWave == 0){
351 _local16 = (double)((ie->variable1 * 20));
352 _local17 = (double)((ie->variable2 * 16));
353 } else {
354 if (ie->oscSelect){
355 _local16 = (double)((ie->variable1 * 20));
356 _local17 = ((double)((srcBuff2[pos] + 0x8000)) / 16);
357 } else {
358 _local16 = ((double)((srcBuff2[pos] + 0x8000)) / 13);
359 _local17 = (double)((ie->variable2 * 16));
360 }
361 }
362 ve->DQVLFV = exp((-((2 * M_PI)) * (_local17 / 22000)));
363 ve->RKF = (((-4 * ve->DQVLFV) / (1 + ve->DQVLFV)) * cos(((2 * M_PI) * (_local16 / 22000))));
364 ve->MDTMBBIQHRQ = ((1 - ve->DQVLFV) * sqrt((1 - ((ve->RKF * ve->RKF) / (4 * ve->DQVLFV)))));
365
366 for (j = 0; j < 0x0100; j++) {
367 _local18 = (((ve->MDTMBBIQHRQ * ((double)(srcBuff1[j]) / 0x8000)) - (ve->RKF * ve->ILHG)) - (ve->DQVLFV * ve->YLKJB));
368 ve->YLKJB = ve->ILHG;
369 ve->ILHG = _local18;
370 if (_local18 > 0.9999){
371 _local18 = 0.9999;
372 }
373 if (_local18 < -0.9999){
374 _local18 = -0.9999;
375 }
376 destBuff[j] = (_local18 * 0x8000);
377
378 }
379 break;
380
381 //FILTWHISTLE
382 case 6:
383 destWave = ie->destWave;
384 srcWave1 = ie->srcWave1;
385 srcWave2 = ie->oscWave - 1;
386 destBuff = tc->synthBuffers[destWave];
387
388 srcBuff1 = tc->synthBuffers[srcWave1];
389 srcBuff2 = srcWave2 >= 0 ? tc->synthBuffers[srcWave2] : NULL;
390 pos = ve->MFATTMREMVP;
391
392 if (ie->oscWave == 0){
393 _local16 = (double)((ie->variable1 * 20));
394 _local17 = (double)((ie->variable2 * 16));
395 } else {
396 if (ie->oscSelect){
397 _local16 = (double)((ie->variable1 * 20));
398 _local17 = ((double)((srcBuff2[pos] + 0x8000)) / 16);
399 } else {
400 _local16 = ((double)((srcBuff2[pos] + 0x8000)) / 13);
401 _local17 = (double)((ie->variable2 * 16));
402 }
403 }
404 ve->DQVLFV = exp((-((2 * M_PI)) * (_local17 / 22000)));
405 ve->RKF = (((-4 * ve->DQVLFV) / (1 + ve->DQVLFV)) * cos(((2 * M_PI) * (_local16 / 22000))));
406 ve->MDTMBBIQHRQ = ((1 - ve->DQVLFV) * sqrt((1 - ((ve->RKF * ve->RKF) / (4 * ve->DQVLFV)))));
407 ve->DQVLFV = (ve->DQVLFV * 1.2);
408
409 for (j = 0; j < 0x0100; j++ ) {
410 _local18 = (((ve->MDTMBBIQHRQ * ((double)(srcBuff1[j]) / 0x8000)) - (ve->RKF * ve->ILHG)) - (ve->DQVLFV * ve->YLKJB));
411 ve->YLKJB = ve->ILHG;
412 ve->ILHG = _local18;
413 if (_local18 > 0.9999){
414 _local18 = 0.9999;
415 }
416 if (_local18 < -0.9999){
417 _local18 = -0.9999;
418 }
419 destBuff[j] = (_local18 * 0x8000);
420
421 }
422 break;
423
424 //MORPH
425 case 7:
426 destWave = ie->destWave;
427 srcWave1 = ie->srcWave1;
428 srcWave2 = ie->srcWave2;
429 oscWave = ie->oscWave - 1;
430 destBuff = tc->synthBuffers[destWave];
431
432 srcBuff1 = tc->synthBuffers[srcWave1];
433 srcBuff2 = tc->synthBuffers[srcWave2];
434 oscBuff = oscWave >= 0 ? tc->synthBuffers[oscWave] : NULL;
435 pos = ve->MFATTMREMVP;
436
437 if (ie->oscWave == 0){
438 _local21 = ie->variable1;
439 } else {
440 if (ie->oscSelect){
441 _local21 = ie->variable1;
442 } else {
443 _local21 = ((oscBuff[pos] + 0x8000) / 0x0100);
444 }
445 }
446 _local22 = (0xFF - _local21);
447
448 for (j = 0; j < 0x0100; j++) {
449 _local23 = (((srcBuff1[j] * _local21) / 0x0100) + ((srcBuff2[j] * _local22) / 0x0100));
450 destBuff[j] = _local23;
451
452 }
453 break;
454
455 //DYNAMORPH
456 case 8:
457 destWave = ie->destWave;
458 srcWave1 = ie->srcWave1;
459 srcWave2 = ie->srcWave2;
460 oscWave = ie->oscWave - 1;
461 destBuff = tc->synthBuffers[destWave];
462
463 srcBuff1 = tc->synthBuffers[srcWave1];
464 srcBuff2 = tc->synthBuffers[srcWave2];
465 oscBuff = oscWave >= 0 ? tc->synthBuffers[oscWave] : NULL;
466 pos = ve->MFATTMREMVP;
467
468 if (ie->oscWave == 0){
469 _local25 = ie->variable1;
470 } else {
471 if (ie->oscSelect){
472 _local25 = ie->variable1;
473 } else {
474 _local25 = ((oscBuff[pos] + 0x8000) / 0x0100);
475 }
476 }
477
478 for (j = 0; j < 0x0100; j++) {
479 _local21 = ((p->dynamorphTable[_local25] >> 8) + 128);
480 _local22 = (0xFF - _local21);
481 _local23 = (((srcBuff1[j] * _local21) / 0x0100) + ((srcBuff2[j] * _local22) / 0x0100));
482 destBuff[j] = _local23;
483 _local25++;
484 _local25 = (_local25 & 0xFF);
485
486 }
487 break;
488
489 //DISTORTION
490 case 9:
491 destWave = ie->destWave;
492 srcWave1 = ie->srcWave1;
493 oscWave = ie->oscWave - 1;
494 destBuff = tc->synthBuffers[destWave];
495
496 srcBuff1 = tc->synthBuffers[srcWave1];
497 oscBuff = oscWave >= 0 ? tc->synthBuffers[oscWave] : NULL;
498 pos = ve->MFATTMREMVP;
499
500 if (ie->oscWave == 0){
501 _local21 = ie->variable1;
502 } else {
503 if (ie->oscSelect){
504 _local21 = ie->variable1;
505 } else {
506 _local21 = ((oscBuff[pos] + 0x8000) / 0x0100);
507 }
508 }
509
510 for (j = 0; j < 0x0100; j++) {
511 _local23 = ((srcBuff1[j] * _local21) / 16);
512 _local23 = (_local23 + 0x8000);
513 if (_local23 < 0){
514 _local23 = -(_local23);
515 }
516 _local23 = (_local23 % 131072);
517 if (_local23 > 0xFFFF){
518 _local23 = (131071 - _local23);
519 }
520 _local23 = (_local23 & 0xFFFF);
521 _local23 = (_local23 - 0x8000);
522 destBuff[j] = _local23;
523
524 }
525 break;
526
527 //SCROLL LEFT
528 case 10:
529 destWave = ie->destWave;
530 destBuff = tc->synthBuffers[destWave];
531 _local10 = destBuff[0];
532
533 for (j = 0; j < 0xFF; j++) {
534 destBuff[j] = destBuff[j + 1];
535
536 }
537 destBuff[0xFF] = _local10;
538 break;
539
540 //UPSAMPLE
541 case 11:
542 pos = ve->QOMCBTRPXF;
543 if (pos != 0){
544 ve->QOMCBTRPXF--;
545 break;
546 }
547 ve->QOMCBTRPXF = ie->variable1;
548 destWave = ie->destWave;
549 destBuff = tc->synthBuffers[destWave];
550
551 for (j = 0; j < 128; j++) {
552 destBuff[j] = destBuff[j * 2];
553
554 }
555
556 for (j = 0; j < 128; j++) {
557 destBuff[j + 128] = destBuff[j];
558
559 }
560 break;
561
562 //CLIPPER
563 case 12:
564 destWave = ie->destWave;
565 srcWave1 = ie->srcWave1;
566 oscWave = ie->oscWave - 1;
567 destBuff = tc->synthBuffers[destWave];
568
569 srcBuff1 = tc->synthBuffers[srcWave1];
570 oscBuff = oscWave >= 0 ? tc->synthBuffers[oscWave] : NULL;
571 pos = ve->MFATTMREMVP;
572
573 if (ie->oscWave == 0){
574 _local21 = ie->variable1;
575 } else {
576 if (ie->oscSelect){
577 _local21 = ie->variable1;
578 } else {
579 _local21 = ((oscBuff[pos] + 0x8000) / 0x0100);
580 }
581 }
582
583 for (j = 0; j < 0x0100; j++) {
584 _local23 = ((srcBuff1[j] * _local21) / 16);
585 if (_local23 < -32767){
586 _local23 = -32767;
587 }
588 if (_local23 > 32767){
589 _local23 = 32767;
590 }
591 destBuff[j] = _local23;
592
593 }
594 break;
595
596 //LOWPASS
597 case 13:
598 destWave = ie->destWave;
599 srcWave1 = ie->srcWave1;
600 srcWave2 = ie->oscWave - 1;
601 destBuff = tc->synthBuffers[destWave];
602
603 srcBuff1 = tc->synthBuffers[srcWave1];
604 srcBuff2 = srcWave2 >= 0 ? tc->synthBuffers[srcWave2] : NULL;
605 pos = ve->MFATTMREMVP;
606
607 if (ie->oscWave == 0){
608 var1 = ie->variable1;
609 var2 = ie->variable2;
610 var1 = var1 * 16;
611 } else {
612 if (ie->oscSelect){
613 var1 = ie->variable1;
614 var2 = ((srcBuff2[pos] + 0x8000) >> 8);
615 var1 = (var1 * 16);
616 } else {
617 //_local28 = ((_local14->data[_local7] + 0x8000) / 16);
618 var1 = ((srcBuff2[pos] + 0x8000) >> 4);
619 var2 = ie->variable2;
620 }
621 }
622 _local30 = (var1 - 920);
623 _local31 = (228 + var1);
624 _local26 = (int)(((2 * M_PI) * _local31));
625 _local27 = (707 + ((1000 * var2) / 128));
626 _local36 = ve->ABJGHAUY;
627 _local37 = ve->SPYK;
628 _local38 = ve->VMBNMTNBQU;
629 _local40 = 8;
630
631 for (j = 0; j < 0x0100; j++) {
632 _local32 = ((_local26 * _local40) / 100);
633 _local39 = srcBuff1[j];
634 _local33 = ((((_local36 * 1000) / _local27) - _local37) + _local39);
635 _local34 = (_local36 - ((_local32 * (_local38 / 100)) / 100));
636 _local35 = (_local37 - ((_local32 * (_local36 / 100)) / 100));
637 _local38 = _local33;
638 _local36 = _local34;
639 _local37 = _local35;
640 _local3 = _local37;
641 if (_local3 > 32767){
642 _local3 = 32767;
643 }
644 if (_local3 < -32767){
645 _local3 = -32767;
646 }
647 destBuff[j] = _local3;
648
649 }
650 ve->ABJGHAUY = _local36;
651 ve->SPYK = _local37;
652 ve->VMBNMTNBQU = _local38;
653 break;
654
655 //HIGHPASS
656 case 14:
657 destWave = ie->destWave;
658 srcWave1 = ie->srcWave1;
659 srcWave2 = ie->oscWave - 1;
660 destBuff = tc->synthBuffers[destWave];
661
662 srcBuff1 = tc->synthBuffers[srcWave1];
663 srcBuff2 = srcWave2 >= 0 ? tc->synthBuffers[srcWave2] : NULL;
664 pos = ve->MFATTMREMVP;
665
666 if (ie->oscWave == 0){
667 var1 = ie->variable1;
668 var2 = ie->variable2;
669 var1 = (var1 * 32);
670 } else {
671 if (ie->oscSelect) {
672 var1 = ie->variable1;
673 var2 = ((srcBuff2[pos] + 0x8000) >> 8);
674 var1 = (var1 * 32);
675 } else {
676 //checked with IDA against windows ver. of Syntrax(v1.03)
677 //It's possible that the effect has changed along the way(v2.xx)
678 //same for lowpass
679 //_local28 = ((_local14->data[_local7] + 0x8000) / 16);
680 var1 = ((srcBuff2[pos] + 0x8000) >> 3);
681 var2 = ie->variable2;
682 }
683 }
684 _local30 = (var1 - 920);
685 _local31 = (228 + var1);
686 _local26 = (int)(((2 * M_PI) * _local31));
687 _local27 = (707 + ((1000 * var2) / 128));
688 _local36 = ve->ABJGHAUY;
689 _local37 = ve->SPYK;
690 _local38 = ve->VMBNMTNBQU;
691 _local40 = 8;
692
693 for (j = 0; j < 0x0100; j++) {
694 _local32 = ((_local26 * _local40) / 100);
695 _local39 = srcBuff1[j];
696 _local33 = ((((_local36 * 1000) / _local27) - _local37) + _local39);
697 _local34 = (_local36 - ((_local32 * (_local38 / 100)) / 100));
698 _local35 = (_local37 - ((_local32 * (_local36 / 100)) / 100));
699 _local38 = _local33;
700 _local36 = _local34;
701 _local37 = _local35;
702 _local3 = _local38;
703 if (_local3 > 32767){
704 _local3 = 32767;
705 }
706 if (_local3 < -32767){
707 _local3 = -32767;
708 }
709 destBuff[j] = _local3;
710
711 }
712 ve->ABJGHAUY = _local36;
713 ve->SPYK = _local37;
714 ve->VMBNMTNBQU = _local38;
715 break;
716
717 //BANDPASS
718 case 15:
719 destWave = ie->destWave;
720 srcWave1 = ie->srcWave1;
721 srcWave2 = ie->oscWave - 1;
722 destBuff = tc->synthBuffers[destWave];
723
724 srcBuff1 = tc->synthBuffers[srcWave1];
725 srcBuff2 = srcWave2 >= 0 ? tc->synthBuffers[srcWave2] : NULL;
726 pos = ve->MFATTMREMVP;
727
728 if (ie->oscWave == 0){
729 var1 = ie->variable1;
730 var2 = ie->variable2;
731 var1 = var1 * 16;
732 } else {
733 if (ie->oscSelect){
734 var1 = ie->variable1;
735 var2 = ((srcBuff2[pos] + 0x8000) >> 8);
736 var1 = var1 * 16;
737 } else {
738 var1 = ((srcBuff2[pos] + 0x8000) / 16);
739 var2 = ie->variable2;
740 }
741 }
742 _local30 = (var1 - 920);
743 _local31 = (228 + var1);
744 _local26 = (int)(((2 * M_PI) * _local31));
745 _local27 = (707 + ((1000 * var2) / 128));
746 _local36 = ve->ABJGHAUY;
747 _local37 = ve->SPYK;
748 _local38 = ve->VMBNMTNBQU;
749 _local40 = 8;
750
751 for (j = 0; j < 0x0100; j++) {
752 _local32 = ((_local26 * _local40) / 100);
753 _local39 = srcBuff1[j];
754 _local33 = ((((_local36 * 1000) / _local27) - _local37) + _local39);
755 _local34 = (_local36 - ((_local32 * (_local38 / 100)) / 100));
756 _local35 = (_local37 - ((_local32 * (_local36 / 100)) / 100));
757 _local38 = _local33;
758 _local36 = _local34;
759 _local37 = _local35;
760 _local3 = _local36;
761 if (_local3 > 32767){
762 _local3 = 32767;
763 }
764 if (_local3 < -32767){
765 _local3 = -32767;
766 }
767 destBuff[j] = _local3;
768
769 }
770 ve->ABJGHAUY = _local36;
771 ve->SPYK = _local37;
772 ve->VMBNMTNBQU = _local38;
773 break;
774
775 //METALNOISE
776 case 16:
777 destWave = ie->destWave;
778 destBuff = tc->synthBuffers[destWave];
779 for (j = 0; j < 0x0100; j++ ) {
780 //Something very bad happens here
781 //I think it's fixed now.
782 destBuff[j] = (int)(((double)(rand()) / (double)(RAND_MAX)) * 65530 - 0x8000);
783 }
784 break;
785
786 //SQUASH
787 case 17:
788 destWave = ie->destWave;
789 srcWave1 = ie->srcWave1;
790 oscWave = ie->oscWave - 1;
791 destBuff = tc->synthBuffers[destWave];
792
793 srcBuff1 = tc->synthBuffers[srcWave1];
794
795 oscBuff = oscWave >= 0 ? tc->synthBuffers[oscWave] : NULL;
796 pos = ve->MFATTMREMVP;
797
798 if (ie->oscWave == 0){
799 var1 = ie->variable1;
800 var2 = ie->variable2;
801 } else {
802 if (ie->oscSelect){
803 var1 = ie->variable1;
804 var2 = ((oscBuff[pos] + 0x8000) >> 8);
805 } else {
806 var1 = ((oscBuff[pos] + 0x8000) >> 8);
807 var2 = ie->variable2;
808 }
809 }
810
811 var2 = (var2 << 8);
812 var1 = (var1 + var2);
813 _local22 = 0;
814
815 for (j = 0; j < 0x0100; j++ ) {
816 //Hex Rays decompiler is lovely tool.
817 //butt = (butt & 0xFFFF0000) | (_local22 & 0x0000FFFF);
818 butt = _local22 & 0xFFFF;
819 _local22 += var1;
820 //ron = (ron & 0xFFFFFF00) | ( butt & 0x000000FF);
821 ron = butt & 0xFF;
822 butt >>= 8;
823 buf1 = srcBuff1[butt];
824 //overflow warning
825 buf2 = srcBuff1[butt + 1];
826 pat = (255 - ron) * buf1;
827 destBuff[j] = (ron * buf2 >> 8) + (pat >> 8);
828 }
829 break;
830 }
831 }
832}
833
834static void channelSomethingElse(Player *p, int chanNum)
835{
836 int _local3;
837 int _local4;
838 int _local5;
839 int _local6;
840
841 TuneChannel *tc = &p->tuneChannels[chanNum];
842 const Instrument *ins = &p->instruments[tc->insNum];
843
844 if (ins->amWave == 0){
845 _local3 = 0;
846 } else {
847 tc->HFRLJCG = (tc->HFRLJCG + ins->amSpeed);
848 if (tc->HFRLJCG >= 0x0100){
849 tc->HFRLJCG = (tc->HFRLJCG - 0x0100);
850 tc->HFRLJCG = (tc->HFRLJCG + ins->amLoopPoint);
851 if (tc->HFRLJCG >= 0x0100){
852 tc->HFRLJCG = ins->amLoopPoint;
853 }
854 }
855 _local3 = tc->synthBuffers[ins->amWave - 1][tc->HFRLJCG];
856 _local3 = (_local3 + 0x8000);
857 _local3 = (_local3 / 6);
858 _local3 = -(_local3);
859 if (_local3 < -10000){
860 _local3 = -10000;
861 }
862 }
863 _local3 = (_local3 + 10000);
864 _local3 = (_local3 * ins->masterVolume);
865 _local3 = (_local3 >> 8);
866 _local3 = (_local3 * p->AMVM);
867 _local3 = (_local3 >> 8);
868 _local3 = (_local3 - 10000);
869 tc->volume = _local3;
870 if (ins->panWave == 0){
871 _local5 = 0;
872 } else {
873 tc->ELPHLDR = (tc->ELPHLDR + ins->panSpeed);
874 if (tc->ELPHLDR >= 0x0100){
875 tc->ELPHLDR = (tc->ELPHLDR - 0x0100);
876 tc->ELPHLDR = (tc->ELPHLDR + ins->panLoopPoint);
877 if (tc->ELPHLDR >= 0x0100){
878 tc->ELPHLDR = ins->panLoopPoint;
879 }
880 }
881 _local5 = tc->synthBuffers[ins->panWave - 1][tc->ELPHLDR];
882 _local5 = (_local5 >> 7);
883 }
884 tc->panning = _local5;
885 _local6 = 0;
886 _local6 = p->arpTable[(ins->arpIndex * 16) + tc->ACKCWV];
887 tc->ACKCWV++;
888 tc->ACKCWV = (tc->ACKCWV & 15);
889 _local4 = p->freqTable[ins->finetune*128 + (_local6 + tc->TVORFCC)];
890 if (tc->fmDelay){
891 tc->fmDelay--;
892 } else {
893 if (ins->fmWave != 0){
894 tc->JOEEPJCI = (tc->JOEEPJCI + ins->fmSpeed);
895 if (tc->JOEEPJCI >= 0x0100){
896 tc->JOEEPJCI = (tc->JOEEPJCI - 0x0100);
897 tc->JOEEPJCI = (tc->JOEEPJCI + ins->fmLoopPoint);
898 if (tc->JOEEPJCI >= 0x0100){
899 tc->JOEEPJCI = ins->fmLoopPoint;
900 }
901 }
902 _local4 = _local4 - tc->synthBuffers[ins->fmWave - 1][tc->JOEEPJCI];
903 }
904 }
905 _local4 = (_local4 + tc->BNWIGU);
906 tc->freq = _local4;
907 if (tc->XESAWSO != 0){
908 if (tc->XESAWSO > 0){
909 if (tc->BNWIGU < tc->UHYDBDDI){
910 tc->BNWIGU = (tc->BNWIGU + tc->XESAWSO);
911 if (tc->BNWIGU > tc->UHYDBDDI){
912 tc->BNWIGU = tc->UHYDBDDI;
913 }
914 }
915 } else {
916 if (tc->BNWIGU > tc->UHYDBDDI){
917 tc->BNWIGU = (tc->BNWIGU + tc->XESAWSO);
918 if (tc->BNWIGU < tc->UHYDBDDI){
919 tc->BNWIGU = tc->UHYDBDDI;
920 }
921 }
922 }
923 }
924}
925
926void playInstrument(Player *p, int chanNum, int instrNum, int note) //note: 1-112
927{
928 int j;
929 int i;
930 TuneChannel *tc;
931 Voice *v;
932 const Instrument *ins;
933
934 if (instrNum > p->synSong->h.instrNum){
935 return;
936 }
937 if ((((p->tuneChannels[chanNum].insNum == -1)) && ((instrNum == 0)))){
938 return;
939 }
940
941 tc = &p->tuneChannels[chanNum];
942 v = &p->voices[chanNum];
943
944 tc->ACKCWV = 0;
945 tc->HFRLJCG = 0;
946 tc->ELPHLDR = 0;
947 tc->JOEEPJCI = 0;
948 tc->TVORFCC = note;
949 tc->freq = 0;
950 tc->VNVJPDIWAJQ = note;
951 tc->BNWIGU = 0;
952 tc->UHYDBDDI = 0;
953 tc->XESAWSO = 0;
954 p->m_LastNotes[chanNum] = note;
955
956 if (instrNum != 0) {
957 ins = &p->instruments[instrNum - 1];
958
959 if (ins->shareSmpDataFromInstr == 0){
960 tc->sampleBuffer = p->samples[instrNum - 1];
961 } else {
962 tc->sampleBuffer = p->samples[ins->shareSmpDataFromInstr - 1];
963 }
964 tc->sampPos = ins->smpStartPoint;
965 tc->smpLoopStart = ins->smpLoopPoint;
966 tc->smpLoopEnd = ins->smpEndPoint;
967 tc->hasLoop = ins->hasLoop;
968 tc->hasBidiLoop = ins->hasBidiLoop;
969 tc->hasLooped = 0;
970 tc->isPlayingBackward = 0;
971 tc->EYRXAB = -1;
972 tc->fmDelay = ins->fmDelay;
973 tc->synthPos = 0;
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
1006static 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
1593static 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
1625static 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
1729void 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
1743void 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->synthPos = tc->synthPos;
1790 v->isSample = 0;
1791 }
1792 else
1793 {
1794 v->waveBuff = tc->sampleBuffer;
1795 v->sampPos = tc->sampPos;
1796 v->smpLoopStart = tc->smpLoopStart;
1797 v->smpLoopEnd = tc->smpLoopEnd;
1798 v->hasLoop = tc->hasLoop;
1799 v->hasBidiLoop = tc->hasBidiLoop;
1800 v->isPlayingBackward = tc->isPlayingBackward;
1801 v->hasLooped = tc->hasLooped;
1802 v->isSample = 1;
1803 }
1804
1805 if ( tc->freq < 10 )
1806 tc->freq = 10;
1807
1808 v->gain = (tc->volume + 10000) / 39;
1809 v->delta = (tc->freq << 8) / p->SAMPLEFREQUENCY;
1810 if (v->delta != v->last_delta)
1811 {
1812 double fdelta = (double)v->delta * (1.0 / (double)0x100);
1813 v->last_delta = v->delta;
1814 resampler_set_rate(v->resampler[0], fdelta);
1815 }
1816
1817 if ( v->gain > 0x100 )
1818 v->gain = 0x100;
1819 if ( tc->panning )
1820 {
1821 if ( tc->panning <= 0 )
1822 {
1823 v->gainRight = 0x100;
1824 v->gainLeft = 0x100 + tc->panning;
1825 }
1826 else
1827 {
1828 v->gainLeft = 0x100;
1829 v->gainRight = 0x100 - tc->panning;
1830 }
1831 }
1832 else
1833 {
1834 v->gainRight = 0x100;
1835 v->gainLeft = 0x100;
1836 }
1837 if ( dword_6632774C )
1838 {
1839 //v->gainDelay = word_6632B9F4[i];
1840 }
1841 else
1842 {
1843 v->gainDelay = p->curSubsong.chanDelayAmt[i];
1844 }
1845 v->gainRight = (v->gain * v->gainRight) >> 8;
1846 v->gainLeft = (v->gain * v->gainLeft) >> 8;
1847 v->gainDelayRight = (v->gainDelay * v->gainRight) >> 8;
1848 v->gainDelayLeft = (v->gainDelay * v->gainLeft) >> 8;
1849 }
1850 if ( dword_6632774C )
1851 {
1852 //amp = word_6632B964;
1853 //otherDelayTime = word_6632BB24;
1854 }
1855 else
1856 {
1857 amp = p->curSubsong.amplification;
1858 otherDelayTime = p->curSubsong.delayTime / (44100 / p->SAMPLEFREQUENCY);
1859 }
1860 if ( outBuff )
1861 {
1862 if ( sampleNum > 0 )
1863 {
1864 for(i = 0; i < sampleNum; i++)
1865 {
1866 audioMainR = 0;
1867 audioMainL = 0;
1868 audioDelayR = 0;
1869 audioDelayL = 0;
1870 if ( p->channelNumber > 0 )
1871 {
1872 for (j = 0; j < p->channelNumber; ++j)
1873 {
1874 v = &p->voices[j];
1875 if ( v->isSample == 1 )
1876 {
1877 if ( v->sampPos != -1 || resampler_get_avail(v->resampler[0]) )
1878 {
1879 //interpolation
1880 sample_t s;
1881 while ( v->sampPos != -1 && resampler_get_min_fill(v->resampler[0]) )
1882 {
1883 s = v->waveBuff[v->sampPos];
1884 resampler_write_pair(v->resampler[0], s, s);
1885 if ( v->isPlayingBackward )
1886 {
1887 v->sampPos--;
1888 if ( v->sampPos <= v->smpLoopStart )
1889 {
1890 v->isPlayingBackward = 0;
1891 v->sampPos++;
1892 }
1893 }
1894 else
1895 {
1896 v->sampPos++;
1897 if ( v->sampPos >= v->smpLoopEnd )
1898 {
1899 if ( v->hasLoop )
1900 {
1901 v->hasLooped = 1;
1902 if ( v->hasBidiLoop )
1903 {
1904 v->isPlayingBackward = 1;
1905 v->sampPos--;
1906 }
1907 else
1908 {
1909 v->sampPos += v->smpLoopStart - v->smpLoopEnd;
1910 }
1911 }
1912 else
1913 {
1914 v->sampPos = -1;
1915 }
1916 }
1917 }
1918 }
1919
1920 //smp = intp->interpSamp(v);
1921 resampler_read_pair(v->resampler[0], &s, &s);
1922 smp = s;
1923
1924 audioMainR += (smp * v->gainRight) >> 8;
1925 audioMainL += (smp * v->gainLeft) >> 8;
1926 audioDelayR += (smp * v->gainDelayRight) >> 8;
1927 audioDelayL += (smp * v->gainDelayLeft) >> 8;
1928 }
1929 }
1930 else
1931 {
1932 //interpolation
1933 //smp = intp->interpSynt(v);
1934 sample_t s;
1935 while ( resampler_get_min_fill(v->resampler[0]) )
1936 {
1937 s = v->waveBuff[v->synthPos];
1938 resampler_write_pair(v->resampler[0], s, s);
1939 v->synthPos++;
1940 v->synthPos &= v->wavelength;
1941 }
1942 resampler_read_pair(v->resampler[0], &s, &s);
1943 smp = s;
1944
1945 audioMainR += (smp * v->gainRight) >> 8;
1946 audioMainL += (smp * v->gainLeft) >> 8;
1947 audioDelayR += (smp * v->gainDelayRight) >> 8;
1948 audioDelayL += (smp * v->gainDelayLeft) >> 8;
1949 }
1950 }
1951 }
1952
1953 audioMainL = (p->delayBufferL[p->delayPos] + audioMainL / p->channelNumber) / 2;
1954 audioMainR = (p->delayBufferR[p->delayPos] + audioMainR / p->channelNumber) / 2;
1955 audioMainR = audioMainR * amp / 100;
1956 audioMainL = audioMainL * amp / 100;
1957 //clip audio
1958 if ( audioMainR < -32760 ) audioMainR = -32760;
1959 if ( audioMainR > 32760 ) audioMainR = 32760;
1960 if ( audioMainL < -32760 ) audioMainL = -32760;
1961 if ( audioMainL > 32760 ) audioMainL = 32760;
1962
1963 //interleaved buffer
1964 if ( p->overlapPos < SE_OVERLAP )
1965 {
1966 audioMainR = p->overlapPos * audioMainR / 100;
1967 audioMainR += (SE_OVERLAP - p->overlapPos) * p->overlapBuff[p->overlapPos*2] / 100;
1968 audioMainL = p->overlapPos * audioMainL / 100;
1969 audioMainL += (SE_OVERLAP - p->overlapPos) * p->overlapBuff[p->overlapPos*2+1] / 100;
1970 ++p->overlapPos;
1971 }
1972
1973 //output
1974 *outBuff++ = audioMainR;
1975 *outBuff++ = audioMainL;
1976
1977 p->delayBufferL[p->delayPos] = (((audioDelayL / p->channelNumber) + p->delayBufferL[p->delayPos]) / 2);
1978 p->delayBufferR[p->delayPos] = (((audioDelayR / p->channelNumber) + p->delayBufferR[p->delayPos]) / 2);
1979 p->delayPos = ++p->delayPos % otherDelayTime;
1980 }
1981 }
1982 }
1983
1984 if ( p->channelNumber > 0 )
1985 {
1986 for (i = 0; i < p->channelNumber; ++i)
1987 {
1988 v = &p->voices[i]; tc = &p->tuneChannels[i];
1989 if ( v->isSample )
1990 {
1991 tc->sampPos = v->sampPos;
1992 tc->isPlayingBackward = v->isPlayingBackward;
1993 tc->hasLooped = v->hasLooped;
1994 }
1995 else
1996 {
1997 tc->synthPos = v->synthPos;
1998 }
1999 }
2000 }
2001 if ( p->otherSamplesPerBeat == (p->samplesPerBeat * p->SAMPLEFREQUENCY) / 44100 )
2002 {
2003 p->bkpDelayPos = p->delayPos;
2004 for (i = 0; i < p->channelNumber; i++)
2005 resampler_dup_inplace(p->voices[i].resampler[1], p->voices[i].resampler[0]);
2006
2007 p->overlapPos = 0;
2008 if ( outBuff )
2009 {
2010 for (i = 0; i < SE_OVERLAP; i++)
2011 {
2012 audioMainR = 0;
2013 audioMainL = 0;
2014 audioDelayR = 0;
2015 audioDelayL = 0;
2016 if ( p->channelNumber > 0 )
2017 {
2018 for (j = 0; j < p->channelNumber; j++)
2019 {
2020 v = &p->voices[j];
2021 if ( v->isSample == 1 )
2022 {
2023 if ( v->sampPos != -1 || resampler_get_avail(v->resampler[1]) )
2024 {
2025 //interpolation
2026 //smp = intp->interpSamp(v);
2027 sample_t s;
2028 while ( v->sampPos != -1 && resampler_get_min_fill(v->resampler[1]) )
2029 {
2030 s = v->waveBuff[v->sampPos];
2031 resampler_write_pair(v->resampler[1], s, s);
2032 if ( v->isPlayingBackward )
2033 {
2034 v->sampPos--;
2035 if ( v->sampPos <= v->smpLoopStart )
2036 {
2037 v->isPlayingBackward = 0;
2038 v->sampPos++;
2039 }
2040 }
2041 else
2042 {
2043 v->sampPos++;
2044 if ( v->sampPos >= v->smpLoopEnd )
2045 {
2046 if ( v->hasLoop )
2047 {
2048 v->hasLooped = 1;
2049 if ( v->hasBidiLoop )
2050 {
2051 v->isPlayingBackward = 1;
2052 v->sampPos--;
2053 }
2054 else
2055 {
2056 v->sampPos += v->smpLoopStart - v->smpLoopEnd;
2057 }
2058 }
2059 else
2060 {
2061 v->sampPos = -1;
2062 }
2063 }
2064 }
2065 }
2066 resampler_read_pair(v->resampler[1], &s, &s);
2067 smp = s;
2068
2069 audioMainR += (smp * v->gainRight) >> 8;
2070 audioMainL += (smp * v->gainLeft) >> 8;
2071 audioDelayR += (smp * v->gainDelayRight) >> 8;
2072 audioDelayL += (smp * v->gainDelayLeft) >> 8;
2073 }
2074 }
2075 else
2076 {
2077 //interpolation
2078 //smp = intp->interpSynt(v);
2079 sample_t s;
2080 while ( resampler_get_min_fill(v->resampler[1]) )
2081 {
2082 s = v->waveBuff[v->synthPos];
2083 resampler_write_pair(v->resampler[1], s, s);
2084 v->synthPos++;
2085 v->synthPos &= v->wavelength;
2086 }
2087 resampler_read_pair(v->resampler[1], &s, &s);
2088 smp = s;
2089
2090 audioMainR += (smp * v->gainRight) >> 8;
2091 audioMainL += (smp * v->gainLeft) >> 8;
2092 audioDelayR += (smp * v->gainDelayRight) >> 8;
2093 audioDelayL += (smp * v->gainDelayLeft) >> 8;
2094 }
2095 }
2096 }
2097
2098 audioMainL = (p->delayBufferL[p->delayPos] + audioMainL / p->channelNumber) / 2;
2099 audioMainR = (p->delayBufferR[p->delayPos] + audioMainR / p->channelNumber) / 2;
2100 audioMainR = audioMainR * amp / 100;
2101 audioMainL = audioMainL * amp / 100;
2102 //clip audio
2103 if ( audioMainR < -32760 ) audioMainR = -32760;
2104 if ( audioMainR > 32760 ) audioMainR = 32760;
2105 if ( audioMainL < -32760 ) audioMainL = -32760;
2106 if ( audioMainL > 32760 ) audioMainL = 32760;
2107
2108 p->overlapBuff[i * 2] = audioMainR;
2109 p->overlapBuff[i*2+1] = audioMainL;
2110
2111 p->delayPos = ++p->delayPos % otherDelayTime;
2112 }
2113 }
2114 p->delayPos = p->bkpDelayPos;
2115
2116 //dword_66327200 = 2 * sampleNum;
2117 advanceTick(p);
2118 }
2119 }
2120 return;
2121 }
2122 memset(outBuff, 0, playbackBufferSize * 2 *2);
2123}
2124
2125 /*void newSong(void)
2126 {
2127 var _local1:int;
2128 var i:int;
2129 var j:int;
2130 var _local4:Order;
2131 var _local6:Vector.<Order>;
2132 var _local7:Row;
2133
2134 reset();
2135 AMYGPFQCHSW = 1;
2136 selectedSubsong = 0;
2137 WDTECTE = 8;
2138 AMVM = 0x100;
2139 synSong.h.subsongNum = 1;
2140 synSong.h.version = 3457;
2141 subsongs = new Vector.<Subsong>();
2142 subsongs.push(new Subsong());
2143 var subs0:Subsong = subsongs[0];
2144 curSubsong = subsongs[selectedSubsong];
2145
2146 subs0.tempo = 120;
2147 subs0.groove = 0;
2148 subs0.startPosCoarse = 0;
2149 subs0.startPosFine = 0;
2150 subs0.loopPosCoarse = 0;
2151 subs0.loopPosFine = 0;
2152 subs0.endPosCoarse = 1;
2153 subs0.endPosFine = 0;
2154 subs0.channelNumber = 4;
2155 subs0.delayTime = 0x8000;
2156 subs0.amplification = 400;
2157 subs0.chanDelayAmt = new Vector.<int>(SE_MAXCHANS, true);
2158
2159 subs0.m_Name = "Empty";
2160 subs0.mutedChans = new Vector.<int>(SE_MAXCHANS, true);
2161
2162
2163 subs0.orders = Tools.malloc_2DVector(Order, SE_MAXCHANS, 0x0100, true, true);
2164 for (i = 0; i < SE_MAXCHANS; i++) {
2165 _local6 = subs0.orders[i];
2166 for (j = 0; j < 0x0100; j++) {
2167 _local6[j].patIndex = 0;
2168 _local6[j].patLen = 0;
2169 }
2170 }
2171
2172 synSong.h.patNum = 2;
2173 synSong.rows = Tools.malloc_1DVector(Row, 64 * synSong.h.patNum);
2174
2175 for (i = 0; i < (64 * synSong.h.patNum); i++) {
2176 rows[i].dest = 0;
2177 rows[i].note = 0;
2178 rows[i].instr = 0;
2179 rows[i].command = 0;
2180 rows[i].spd = 0;
2181
2182 }
2183 patternNames = new Vector.<String>();
2184 patternNames.push("Empty");
2185 patternNames.push("Pat1");
2186 synSong.h.instrNum = 1;
2187 synSong.instruments = new Vector.<Instrument>();
2188 synSong.instruments.push(new Instrument());
2189
2190 mutedChans = new Vector.<int>(SE_MAXCHANS, true);
2191 }*/
2192
2193static void AAUCAPQW(Player *p)
2194{
2195 //What is this even for?
2196
2197 p->PQV = 0;
2198 p->sePmSong = SE_PM_SONG;
2199 if (p->subsongs){
2200 p->posCoarse = p->curSubsong.startPosCoarse;
2201 p->posFine = p->curSubsong.startPosFine;
2202 }
2203}
2204
2205static void IMXFLSSMB(Player *p, int _arg1)
2206{
2207 p->PQV = 1;
2208 p->AMYGPFQCHSW = _arg1;
2209 p->ISWLKT = 63;
2210 p->someCounter = 1;
2211 p->sePmSong = SE_PM_PATTERN;
2212 p->WDTECTE = p->subsongs[0].tempo - p->subsongs[0].groove;
2213}
2214
2215void initSubsong(Player *p, int num)
2216{
2217 int _local2;
2218 int i, j;
2219 Order *_local5;
2220 bool _local6;
2221 int _local7;
2222 int _local8;
2223 double tempo;
2224
2225 //reset instruments
2226 memcpy(p->instruments, p->synSong->instruments, p->synSong->h.instrNum * sizeof(Instrument));
2227
2228 p->loopCount = 0;
2229
2230 if (num >= p->synSong->h.subsongNum) return;
2231
2232 p->selectedSubsong = num;
2233 p->curSubsong = p->subsongs[p->selectedSubsong];
2234 p->channelNumber = p->curSubsong.channelNumber;
2235 reset(p);
2236 _local6 = false;
2237
2238 for (i = 0; i < SE_MAXCHANS; i++) {
2239 p->m_LastNotes[i] = 0;
2240 _local2 = 0;
2241
2242 _local8 = 0;
2243 _local5 = p->curSubsong.orders[i];
2244 _local7 = (((p->curSubsong.startPosCoarse * 64) + p->curSubsong.startPosFine) - 1);
2245 for (j = 0; j < 0x0100; j++) {
2246 if (_local2 >= _local7){
2247 if (j != _local7){
2248 j--;
2249 }
2250 break;
2251 }
2252 _local8 = _local2;
2253 _local2 = (_local2 + _local5[j].patLen);
2254
2255 }
2256 if (j == 0x0100){
2257 _local6 = true;
2258 break;
2259 }
2260 _local7 = (_local7 - _local8);
2261 _local7 = (_local7 & 63);
2262 p->tuneChannels[i].EQMIWERPIF = j;
2263 p->tuneChannels[i].LJHG = _local7;
2264 p->curSubsong.mutedChans[i] = p->mutedChans[i];
2265
2266 }
2267 if (_local6 == false){
2268 p->someCounter = 1;
2269 p->sePmSong = SE_PM_SONG;
2270 p->PQV = 1;
2271 p->WDTECTE = (8 + p->curSubsong.groove);
2272 if (p->curSubsong.tempo){
2273 tempo = (double)(p->curSubsong.tempo);
2274 tempo = (tempo / 60);
2275 tempo = (tempo * 32);
2276 p->samplesPerBeat = (int)((44100 / tempo));
2277 p->otherSamplesPerBeat = p->samplesPerBeat;
2278 }
2279 if (p->curSubsong.startPosFine == 0){
2280 p->posCoarse = p->curSubsong.startPosCoarse - 1;
2281 } else {
2282 p->posCoarse = p->curSubsong.startPosCoarse;
2283 }
2284 p->posFine = p->curSubsong.startPosFine - 1;
2285 p->posFine = p->posFine & 63;
2286 }
2287}
2288
2289int loadSong(Player *p, const Song *synSong)
2290{
2291 int i;
2292 void *ptr;
2293
2294 AAUCAPQW(p);
2295 reset(p);
2296 //clearSongData();
2297 p->synSong = synSong;
2298
2299 //pass things locally
2300 //not much purpouse here
2301 //nor in AS3
2302 //why did I do it
2303 p->rows = synSong->rows;
2304 p->patternNames = (const char **) synSong->patternNames;
2305
2306 ptr = realloc(p->instruments, synSong->h.instrNum * sizeof(Instrument));
2307 if (!ptr) return -1;
2308 p->instruments = (Instrument *) ptr;
2309
2310 p->subsongs = synSong->subsongs;
2311 p->arpTable = synSong->arpTable;
2312 p->samples = (const int16_t **) synSong->samples;
2313
2314 for (i = 0; i < SE_MAXCHANS; i++) {
2315 p->mutedChans[i] = synSong->subsongs[0].mutedChans[i];
2316 }
2317 initSubsong(p, 0);
2318
2319 return 0;
2320}
2321
2322bool playerGetSongEnded(Player *p)
2323{
2324 return p->PQV == 0;
2325}
2326
2327uint playerGetLoopCount(Player *p)
2328{
2329 return p->loopCount;
2330}
2331
2332void playerGetInfo(Player *p, syntrax_info *info)
2333{
2334 int i, j;
2335 info->coarse = p->posCoarse;
2336 info->fine = p->posFine;
2337 for (i = 0, j = 0; i < p->channelNumber; i++)
2338 {
2339 Voice *v = &p->voices[i];
2340 if (v->waveBuff != p->silentBuffer)
2341 {
2342 if (v->isSample)
2343 {
2344 if (v->sampPos != -1) j++;
2345 }
2346 else j++;
2347 }
2348 }
2349 info->channelsPlaying = j;
2350}
2351

Built with git-ssb-web