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