12
|
1 /*
|
|
2 * --> The Protracker Player Driver -> Part of the SPLAYER pack for MikMod
|
|
3 * 3.0
|
|
4 *
|
|
5 * The protracker driver supports all base Protracker 3.x commands and fea-
|
|
6 * tures.
|
|
7 */
|
|
8
|
|
9 #include <string.h>
|
|
10 #include <stdarg.h>
|
|
11 #include "mikmod.h"
|
|
12
|
|
13
|
|
14 static void DoNNAEffects(UBYTE dat);
|
|
15
|
|
16 /*
|
|
17 * Set forbid to 1 when you want to modify any of the pf->sngpos, pf->patpos
|
|
18 * etc. variables and clear it when you're done. This prevents getting
|
|
19 * strange results due to intermediate interrupts.
|
|
20 */
|
|
21
|
|
22 static UNIMOD *pf; /* <- this modfile is being played */
|
|
23 static SWORD mp_channel; /* channel it's working on */
|
|
24 static MP_CONTROL *a; /* current AUDTMP it's working on */
|
|
25 static int isfirst;
|
|
26
|
|
27 static MP_VOICE aout_dummy;
|
|
28
|
|
29 static UWORD mytab[12] =
|
|
30 {
|
|
31 1712 * 16, 1616 * 16, 1524 * 16, 1440 * 16, 1356 * 16, 1280 * 16,
|
|
32 1208 * 16, 1140 * 16, 1076 * 16, 1016 * 16, 960 * 16, 907 * 16
|
|
33 };
|
|
34
|
|
35 static UBYTE VibratoTable[32] =
|
|
36 {0, 24, 49, 74, 97, 120, 141, 161,
|
|
37 180, 197, 212, 224, 235, 244, 250, 253,
|
|
38 255, 253, 250, 244, 235, 224, 212, 197,
|
|
39 180, 161, 141, 120, 97, 74, 49, 24
|
|
40 };
|
|
41
|
|
42 static UBYTE avibtab[128] =
|
|
43 {
|
|
44 0, 1, 3, 4, 6, 7, 9, 10, 12, 14, 15, 17, 18, 20, 21, 23,
|
|
45 24, 25, 27, 28, 30, 31, 32, 34, 35, 36, 38, 39, 40, 41, 42, 44,
|
|
46 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 54, 55, 56, 57, 57, 58,
|
|
47 59, 59, 60, 60, 61, 61, 62, 62, 62, 63, 63, 63, 63, 63, 63, 63,
|
|
48 64, 63, 63, 63, 63, 63, 63, 63, 62, 62, 62, 61, 61, 60, 60, 59,
|
|
49 59, 58, 57, 57, 56, 55, 54, 54, 53, 52, 51, 50, 49, 48, 47, 46,
|
|
50 45, 44, 42, 41, 40, 39, 38, 36, 35, 34, 32, 31, 30, 28, 27, 25,
|
|
51 24, 23, 21, 20, 18, 17, 15, 14, 12, 10, 9, 7, 6, 4, 3, 1
|
|
52 };
|
|
53
|
|
54 /*
|
|
55 * * Triton's linear periods to frequency translation table (for * Fast
|
|
56 * Tracker 2 [XM] modules):
|
|
57 */
|
|
58
|
|
59 static ULONG lintab[768] =
|
|
60 {535232, 534749, 534266, 533784, 533303, 532822, 532341, 531861,
|
|
61 531381, 530902, 530423, 529944, 529466, 528988, 528511, 528034,
|
|
62 527558, 527082, 526607, 526131, 525657, 525183, 524709, 524236,
|
|
63 523763, 523290, 522818, 522346, 521875, 521404, 520934, 520464,
|
|
64 519994, 519525, 519057, 518588, 518121, 517653, 517186, 516720,
|
|
65 516253, 515788, 515322, 514858, 514393, 513929, 513465, 513002,
|
|
66 512539, 512077, 511615, 511154, 510692, 510232, 509771, 509312,
|
|
67 508852, 508393, 507934, 507476, 507018, 506561, 506104, 505647,
|
|
68 505191, 504735, 504280, 503825, 503371, 502917, 502463, 502010,
|
|
69 501557, 501104, 500652, 500201, 499749, 499298, 498848, 498398,
|
|
70 497948, 497499, 497050, 496602, 496154, 495706, 495259, 494812,
|
|
71 494366, 493920, 493474, 493029, 492585, 492140, 491696, 491253,
|
|
72 490809, 490367, 489924, 489482, 489041, 488600, 488159, 487718,
|
|
73 487278, 486839, 486400, 485961, 485522, 485084, 484647, 484210,
|
|
74 483773, 483336, 482900, 482465, 482029, 481595, 481160, 480726,
|
|
75 480292, 479859, 479426, 478994, 478562, 478130, 477699, 477268,
|
|
76 476837, 476407, 475977, 475548, 475119, 474690, 474262, 473834,
|
|
77 473407, 472979, 472553, 472126, 471701, 471275, 470850, 470425,
|
|
78 470001, 469577, 469153, 468730, 468307, 467884, 467462, 467041,
|
|
79 466619, 466198, 465778, 465358, 464938, 464518, 464099, 463681,
|
|
80 463262, 462844, 462427, 462010, 461593, 461177, 460760, 460345,
|
|
81 459930, 459515, 459100, 458686, 458272, 457859, 457446, 457033,
|
|
82 456621, 456209, 455797, 455386, 454975, 454565, 454155, 453745,
|
|
83 453336, 452927, 452518, 452110, 451702, 451294, 450887, 450481,
|
|
84 450074, 449668, 449262, 448857, 448452, 448048, 447644, 447240,
|
|
85 446836, 446433, 446030, 445628, 445226, 444824, 444423, 444022,
|
|
86 443622, 443221, 442821, 442422, 442023, 441624, 441226, 440828,
|
|
87 440430, 440033, 439636, 439239, 438843, 438447, 438051, 437656,
|
|
88 437261, 436867, 436473, 436079, 435686, 435293, 434900, 434508,
|
|
89 434116, 433724, 433333, 432942, 432551, 432161, 431771, 431382,
|
|
90 430992, 430604, 430215, 429827, 429439, 429052, 428665, 428278,
|
|
91 427892, 427506, 427120, 426735, 426350, 425965, 425581, 425197,
|
|
92 424813, 424430, 424047, 423665, 423283, 422901, 422519, 422138,
|
|
93 421757, 421377, 420997, 420617, 420237, 419858, 419479, 419101,
|
|
94 418723, 418345, 417968, 417591, 417214, 416838, 416462, 416086,
|
|
95 415711, 415336, 414961, 414586, 414212, 413839, 413465, 413092,
|
|
96 412720, 412347, 411975, 411604, 411232, 410862, 410491, 410121,
|
|
97 409751, 409381, 409012, 408643, 408274, 407906, 407538, 407170,
|
|
98 406803, 406436, 406069, 405703, 405337, 404971, 404606, 404241,
|
|
99 403876, 403512, 403148, 402784, 402421, 402058, 401695, 401333,
|
|
100 400970, 400609, 400247, 399886, 399525, 399165, 398805, 398445,
|
|
101 398086, 397727, 397368, 397009, 396651, 396293, 395936, 395579,
|
|
102 395222, 394865, 394509, 394153, 393798, 393442, 393087, 392733,
|
|
103 392378, 392024, 391671, 391317, 390964, 390612, 390259, 389907,
|
|
104 389556, 389204, 388853, 388502, 388152, 387802, 387452, 387102,
|
|
105 386753, 386404, 386056, 385707, 385359, 385012, 384664, 384317,
|
|
106 383971, 383624, 383278, 382932, 382587, 382242, 381897, 381552,
|
|
107 381208, 380864, 380521, 380177, 379834, 379492, 379149, 378807,
|
|
108
|
|
109 378466, 378124, 377783, 377442, 377102, 376762, 376422, 376082,
|
|
110 375743, 375404, 375065, 374727, 374389, 374051, 373714, 373377,
|
|
111 373040, 372703, 372367, 372031, 371695, 371360, 371025, 370690,
|
|
112 370356, 370022, 369688, 369355, 369021, 368688, 368356, 368023,
|
|
113 367691, 367360, 367028, 366697, 366366, 366036, 365706, 365376,
|
|
114 365046, 364717, 364388, 364059, 363731, 363403, 363075, 362747,
|
|
115 362420, 362093, 361766, 361440, 361114, 360788, 360463, 360137,
|
|
116 359813, 359488, 359164, 358840, 358516, 358193, 357869, 357547,
|
|
117 357224, 356902, 356580, 356258, 355937, 355616, 355295, 354974,
|
|
118 354654, 354334, 354014, 353695, 353376, 353057, 352739, 352420,
|
|
119 352103, 351785, 351468, 351150, 350834, 350517, 350201, 349885,
|
|
120 349569, 349254, 348939, 348624, 348310, 347995, 347682, 347368,
|
|
121 347055, 346741, 346429, 346116, 345804, 345492, 345180, 344869,
|
|
122 344558, 344247, 343936, 343626, 343316, 343006, 342697, 342388,
|
|
123 342079, 341770, 341462, 341154, 340846, 340539, 340231, 339924,
|
|
124 339618, 339311, 339005, 338700, 338394, 338089, 337784, 337479,
|
|
125 337175, 336870, 336566, 336263, 335959, 335656, 335354, 335051,
|
|
126 334749, 334447, 334145, 333844, 333542, 333242, 332941, 332641,
|
|
127 332341, 332041, 331741, 331442, 331143, 330844, 330546, 330247,
|
|
128 329950, 329652, 329355, 329057, 328761, 328464, 328168, 327872,
|
|
129 327576, 327280, 326985, 326690, 326395, 326101, 325807, 325513,
|
|
130 325219, 324926, 324633, 324340, 324047, 323755, 323463, 323171,
|
|
131 322879, 322588, 322297, 322006, 321716, 321426, 321136, 320846,
|
|
132 320557, 320267, 319978, 319690, 319401, 319113, 318825, 318538,
|
|
133 318250, 317963, 317676, 317390, 317103, 316817, 316532, 316246,
|
|
134 315961, 315676, 315391, 315106, 314822, 314538, 314254, 313971,
|
|
135 313688, 313405, 313122, 312839, 312557, 312275, 311994, 311712,
|
|
136 311431, 311150, 310869, 310589, 310309, 310029, 309749, 309470,
|
|
137 309190, 308911, 308633, 308354, 308076, 307798, 307521, 307243,
|
|
138 306966, 306689, 306412, 306136, 305860, 305584, 305308, 305033,
|
|
139 304758, 304483, 304208, 303934, 303659, 303385, 303112, 302838,
|
|
140 302565, 302292, 302019, 301747, 301475, 301203, 300931, 300660,
|
|
141 300388, 300117, 299847, 299576, 299306, 299036, 298766, 298497,
|
|
142 298227, 297958, 297689, 297421, 297153, 296884, 296617, 296349,
|
|
143 296082, 295815, 295548, 295281, 295015, 294749, 294483, 294217,
|
|
144 293952, 293686, 293421, 293157, 292892, 292628, 292364, 292100,
|
|
145 291837, 291574, 291311, 291048, 290785, 290523, 290261, 289999,
|
|
146 289737, 289476, 289215, 288954, 288693, 288433, 288173, 287913,
|
|
147 287653, 287393, 287134, 286875, 286616, 286358, 286099, 285841,
|
|
148 285583, 285326, 285068, 284811, 284554, 284298, 284041, 283785,
|
|
149 283529, 283273, 283017, 282762, 282507, 282252, 281998, 281743,
|
|
150 281489, 281235, 280981, 280728, 280475, 280222, 279969, 279716,
|
|
151 279464, 279212, 278960, 278708, 278457, 278206, 277955, 277704,
|
|
152 277453, 277203, 276953, 276703, 276453, 276204, 275955, 275706,
|
|
153 275457, 275209, 274960, 274712, 274465, 274217, 273970, 273722,
|
|
154 273476, 273229, 272982, 272736, 272490, 272244, 271999, 271753,
|
|
155 271508, 271263, 271018, 270774, 270530, 270286, 270042, 269798,
|
|
156 269555, 269312, 269069, 268826, 268583, 268341, 268099, 267857
|
|
157 };
|
|
158
|
|
159 #define LOGFAC 2*16
|
|
160
|
|
161 static UWORD logtab[104] =
|
|
162 {LOGFAC * 907, LOGFAC * 900, LOGFAC * 894, LOGFAC * 887, LOGFAC * 881, LOGFAC * 875, LOGFAC * 868, LOGFAC * 862,
|
|
163 LOGFAC * 856, LOGFAC * 850, LOGFAC * 844, LOGFAC * 838, LOGFAC * 832, LOGFAC * 826, LOGFAC * 820, LOGFAC * 814,
|
|
164 LOGFAC * 808, LOGFAC * 802, LOGFAC * 796, LOGFAC * 791, LOGFAC * 785, LOGFAC * 779, LOGFAC * 774, LOGFAC * 768,
|
|
165 LOGFAC * 762, LOGFAC * 757, LOGFAC * 752, LOGFAC * 746, LOGFAC * 741, LOGFAC * 736, LOGFAC * 730, LOGFAC * 725,
|
|
166 LOGFAC * 720, LOGFAC * 715, LOGFAC * 709, LOGFAC * 704, LOGFAC * 699, LOGFAC * 694, LOGFAC * 689, LOGFAC * 684,
|
|
167 LOGFAC * 678, LOGFAC * 675, LOGFAC * 670, LOGFAC * 665, LOGFAC * 660, LOGFAC * 655, LOGFAC * 651, LOGFAC * 646,
|
|
168 LOGFAC * 640, LOGFAC * 636, LOGFAC * 632, LOGFAC * 628, LOGFAC * 623, LOGFAC * 619, LOGFAC * 614, LOGFAC * 610,
|
|
169 LOGFAC * 604, LOGFAC * 601, LOGFAC * 597, LOGFAC * 592, LOGFAC * 588, LOGFAC * 584, LOGFAC * 580, LOGFAC * 575,
|
|
170 LOGFAC * 570, LOGFAC * 567, LOGFAC * 563, LOGFAC * 559, LOGFAC * 555, LOGFAC * 551, LOGFAC * 547, LOGFAC * 543,
|
|
171 LOGFAC * 538, LOGFAC * 535, LOGFAC * 532, LOGFAC * 528, LOGFAC * 524, LOGFAC * 520, LOGFAC * 516, LOGFAC * 513,
|
|
172 LOGFAC * 508, LOGFAC * 505, LOGFAC * 502, LOGFAC * 498, LOGFAC * 494, LOGFAC * 491, LOGFAC * 487, LOGFAC * 484,
|
|
173 LOGFAC * 480, LOGFAC * 477, LOGFAC * 474, LOGFAC * 470, LOGFAC * 467, LOGFAC * 463, LOGFAC * 460, LOGFAC * 457,
|
|
174 LOGFAC * 453, LOGFAC * 450, LOGFAC * 447, LOGFAC * 443, LOGFAC * 440, LOGFAC * 437, LOGFAC * 434, LOGFAC * 431
|
|
175 };
|
|
176
|
|
177 static SBYTE PanbrelloTable[256] =
|
|
178 {0, 2, 3, 5, 6, 8, 9, 11, 12, 14, 16, 17, 19, 20, 22, 23,
|
|
179 24, 26, 27, 29, 30, 32, 33, 34, 36, 37, 38, 39, 41, 42, 43, 44,
|
|
180 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59,
|
|
181 59, 60, 60, 61, 61, 62, 62, 62, 63, 63, 63, 64, 64, 64, 64, 64,
|
|
182 64, 64, 64, 64, 64, 64, 63, 63, 63, 62, 62, 62, 61, 61, 60, 60,
|
|
183 59, 59, 58, 57, 56, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46,
|
|
184 45, 44, 43, 42, 41, 39, 38, 37, 36, 34, 33, 32, 30, 29, 27, 26,
|
|
185 24, 23, 22, 20, 19, 17, 16, 14, 12, 11, 9, 8, 6, 5, 3, 2,
|
|
186 0, -2, -3, -5, -6, -8, -9, -11, -12, -14, -16, -17, -19, -20, -22, -23,
|
|
187 -24, -26, -27, -29, -30, -32, -33, -34, -36, -37, -38, -39, -41, -42, -43, -44,
|
|
188 -45, -46, -47, -48, -49, -50, -51, -52, -53, -54, -55, -56, -56, -57, -58, -59,
|
|
189 -59, -60, -60, -61, -61, -62, -62, -62, -63, -63, -63, -64, -64, -64, -64, -64,
|
|
190 -64, -64, -64, -64, -64, -64, -63, -63, -63, -62, -62, -62, -61, -61, -60, -60,
|
|
191 -59, -59, -58, -57, -56, -56, -55, -54, -53, -52, -51, -50, -49, -48, -47, -46,
|
|
192 -45, -44, -43, -42, -41, -39, -38, -37, -36, -34, -33, -32, -30, -29, -27, -26,
|
|
193 -24, -23, -22, -20, -19, -17, -16, -14, -12, -11, -9, -8, -6, -5, -3, -2
|
|
194 };
|
|
195
|
|
196
|
|
197 /*
|
|
198 * New Note Action Scoring System: --------------------------------- 1)
|
|
199 * total-volume (fadevol, chanvol, volume) is the main scorer. 2) a looping
|
|
200 * sample is a bonus x2 3) a forground channel is a bonus x4 4) an active
|
|
201 * envelope with keyoff is a handicap -x2
|
|
202 */
|
|
203
|
|
204 static int
|
|
205 MP_FindEmptyChannel(int curchan)
|
|
206 { /* returns mp_control index of free channel */
|
|
207 MP_VOICE *a;
|
|
208 ULONG t, k, tvol, p, pp;
|
|
209
|
|
210 /*
|
|
211 * for(t=md_sngchn; t; t--, audpool++) { if(audpool == md_sngchn)
|
|
212 * audpool = 0; if(!(pf->voice[audpool].kick) && Voice_Stopped(audpool))
|
|
213 * { audpool++; return audpool-1; } }
|
|
214 */
|
|
215
|
|
216 for (t = 0; t < md_sngchn; t++) {
|
|
217 if (!(pf->voice[t].kick) && Voice_Stopped(t)) {
|
|
218 return t;
|
|
219 }
|
|
220 }
|
|
221
|
17
|
222 tvol = 0xffffff;
|
12
|
223 t = 0;
|
|
224 p = 0;
|
|
225 a = pf->voice;
|
|
226 for (k = 0; k < md_sngchn; k++, a++) {
|
|
227 if (!a->kick) {
|
|
228 pp = a->totalvol << ((a->s->flags & SF_LOOP) ? 1 : 0);
|
|
229 if ((a->master != NULL) && (a == a->master->slave))
|
|
230 pp <<= 2;
|
|
231
|
|
232 /*
|
|
233 * if(a->volflg & EF_ON) { if(a->volflg & (EF_SUSTAIN |
|
|
234 * EF_LOOP)) { if(a->keyoff & KEY_OFF) { pp >>= 1;
|
|
235 * if(a->venv.env[a->venv.end].val < 32) pp>>=1; } else pp <<= 1;
|
|
236 * } else pp <<= 1; }
|
|
237 */
|
|
238
|
|
239 if (pp < tvol) {
|
|
240 tvol = pp;
|
|
241 t = k;
|
|
242 }
|
|
243 }
|
|
244 }
|
|
245
|
|
246 if (tvol > (8000 * 7))
|
|
247 return -1; /* mp_channel; */
|
|
248
|
|
249 return t;
|
|
250 }
|
|
251
|
|
252
|
|
253 static SWORD
|
|
254 Interpolate(SWORD p, SWORD p1, SWORD p2, SWORD v1, SWORD v2)
|
|
255 {
|
|
256 SWORD dp, dv, di;
|
|
257
|
|
258 if (p1 == p2)
|
|
259 return v1;
|
|
260
|
|
261 dv = v2 - v1;
|
|
262 dp = p2 - p1;
|
|
263 di = p - p1;
|
|
264
|
|
265 return v1 + ((SLONG) (di * dv) / dp);
|
|
266 }
|
|
267
|
|
268
|
|
269 UWORD
|
|
270 getlinearperiod(UBYTE note, ULONG fine)
|
|
271 {
|
|
272 return ((10L * 12 * 16 * 4) - ((ULONG) note * 16 * 4) - (fine / 2) + 64);
|
|
273 }
|
|
274
|
|
275
|
|
276 static UWORD
|
|
277 getlogperiod(UBYTE note, ULONG fine)
|
|
278 {
|
|
279 UBYTE n, o;
|
|
280 UWORD p1, p2;
|
|
281 ULONG i;
|
|
282
|
|
283 n = note % 12;
|
|
284 o = note / 12;
|
|
285 i = (n << 3) + (fine >> 4); /* n*8 + fine/16 */
|
|
286
|
|
287 p1 = logtab[i];
|
|
288 p2 = logtab[i + 1];
|
|
289
|
|
290 return (Interpolate(fine / 16, 0, 15, p1, p2) >> o);
|
|
291 }
|
|
292
|
|
293
|
|
294 static UWORD
|
|
295 getoldperiod(UBYTE note, ULONG speed)
|
|
296 {
|
|
297 UBYTE n, o;
|
|
298 ULONG period;
|
|
299
|
|
300 if (!speed)
|
|
301 return 4242; /* <- prevent divide overflow.. (42 eheh) */
|
|
302
|
|
303 n = note % 12;
|
|
304 o = note / 12;
|
|
305 period = ((8363l * (ULONG) mytab[n]) >> o) / speed;
|
|
306 return period;
|
|
307 }
|
|
308
|
|
309
|
|
310 static UWORD
|
|
311 GetPeriod(UBYTE note, ULONG speed)
|
|
312 {
|
|
313 if (pf->flags & UF_XMPERIODS) {
|
|
314 return (pf->flags & UF_LINEAR) ?
|
|
315 getlinearperiod(note, speed) : getlogperiod(note, speed);
|
|
316 }
|
|
317
|
|
318 return getoldperiod(note, speed);
|
|
319 }
|
|
320
|
|
321
|
|
322 static SWORD
|
|
323 InterpolateEnv(SWORD p, ENVPT * a, ENVPT * b)
|
|
324 {
|
|
325 return (Interpolate(p, a->pos, b->pos, a->val, b->val));
|
|
326 }
|
|
327
|
|
328
|
|
329 static SWORD
|
|
330 DoPan(SWORD envpan, SWORD pan)
|
|
331 {
|
|
332 return (pan + (((envpan - 128) * (128 - abs(pan - 128))) / 128));
|
|
333 }
|
|
334
|
|
335
|
|
336 static void
|
|
337 StartEnvelope(ENVPR * t, UBYTE flg, UBYTE pts, UBYTE susbeg, UBYTE susend, UBYTE beg, UBYTE end, ENVPT * p, UBYTE keyoff)
|
|
338 {
|
|
339 t->flg = flg;
|
|
340 t->pts = pts;
|
|
341 t->susbeg = susbeg;
|
|
342 t->susend = susend;
|
|
343 t->beg = beg;
|
|
344 t->end = end;
|
|
345 t->env = p;
|
|
346 t->p = 0;
|
|
347 t->a = 0;
|
|
348 t->b = ((t->flg & EF_SUSTAIN) && !(keyoff & KEY_OFF)) ? 0 : 1;
|
|
349 }
|
|
350
|
|
351
|
|
352 /*
|
|
353 * This procedure processes all envelope types, include volume, pitch, and
|
|
354 * panning. Envelopes are defined by a set of points, each with a magnitude
|
|
355 * [relating either to volume, panniong position, or pitch modifier] and a
|
|
356 * tick position.
|
|
357 *
|
|
358 * Envelopes work in the following manner:
|
|
359 *
|
|
360 * (a) Each tick the envelope is moved a point further in its progression. 1.
|
|
361 * For an accurate progression, magnitudes between two envelope points are
|
|
362 * interpolated.
|
|
363 *
|
|
364 * (b) When progression reaches a defined point on the envelope, values are
|
|
365 * shifted to interpolate between this point and the next, and checks for
|
|
366 * loops or envelope end are done.
|
|
367 *
|
|
368 * Misc: Sustain loops are loops that are only active as long as the keyoff flag
|
|
369 * is clear. When a volume envelope terminates, so does the current fadeout.
|
|
370 */
|
|
371 static SWORD
|
|
372 ProcessEnvelope(ENVPR * t, SWORD v, UBYTE keyoff)
|
|
373 {
|
|
374 if (t->flg & EF_ON) {
|
|
375 UBYTE a, b; /* actual points in the envelope */
|
|
376 UWORD p; /* the 'tick counter' - real point being
|
|
377 * played */
|
|
378
|
|
379 a = t->a;
|
|
380 b = t->b;
|
|
381 p = t->p;
|
|
382
|
|
383 /* compute the current envelope value between points a and b */
|
|
384
|
|
385 if (a == b)
|
|
386 v = t->env[a].val;
|
|
387 else
|
|
388 v = InterpolateEnv(p, &t->env[a], &t->env[b]);
|
|
389
|
|
390 p++;
|
|
391
|
|
392 /* pointer reached point b? */
|
|
393
|
|
394 if (p >= t->env[b].pos) {
|
|
395 a = b++; /* shift points a and b */
|
|
396
|
|
397 /* Check for loops, sustain loops, or end of envelope. */
|
|
398
|
|
399 if ((t->flg & EF_SUSTAIN) && !(keyoff & KEY_OFF) && (b > t->susend)) {
|
|
400 a = t->susbeg;
|
|
401 if (t->susbeg == t->susend)
|
|
402 b = a;
|
|
403 else
|
|
404 b = a + 1;
|
|
405 p = t->env[a].pos;
|
|
406 } else if ((t->flg & EF_LOOP) && (b > t->end)) {
|
|
407 a = t->beg;
|
|
408 if (t->beg == t->end)
|
|
409 b = a;
|
|
410 else
|
|
411 b = a + 1;
|
|
412 p = t->env[a].pos;
|
|
413 } else {
|
|
414 if (b >= t->pts) {
|
|
415 if ((t->flg & EF_VOLENV) && (mp_channel != -1)) {
|
|
416 pf->voice[mp_channel].keyoff |= KEY_FADE;
|
|
417 if (v == 0)
|
|
418 pf->voice[mp_channel].fadevol = 0;
|
|
419 }
|
|
420 b--;
|
|
421 p--;
|
|
422 }
|
|
423 }
|
|
424 }
|
|
425 t->a = a;
|
|
426 t->b = b;
|
|
427 t->p = p;
|
|
428 }
|
|
429 return v;
|
|
430 }
|
|
431
|
|
432
|
|
433 /* XM linear period to frequency conversion */
|
|
434 ULONG
|
|
435 getfrequency(UBYTE flags, ULONG period)
|
|
436 {
|
|
437 ULONG result;
|
|
438
|
|
439 if (flags & UF_LINEAR)
|
|
440 result = lintab[period % 768] >> (period / 768);
|
|
441 else
|
|
442 result = (8363L * 1712L) / period;
|
|
443
|
|
444 return result;
|
|
445 }
|
|
446
|
|
447
|
|
448 static void
|
|
449 DoEEffects(UBYTE dat)
|
|
450 {
|
|
451 UBYTE nib;
|
|
452
|
|
453 nib = dat & 0xf;
|
|
454
|
|
455 switch (dat >> 4) {
|
|
456 case 0x0: /* filter toggle, not supported */
|
|
457 break;
|
|
458
|
|
459 case 0x1: /* fineslide up */
|
|
460 if (!pf->vbtick)
|
|
461 a->tmpperiod -= (nib << 2);
|
|
462 break;
|
|
463
|
|
464 case 0x2: /* fineslide dn */
|
|
465 if (!pf->vbtick)
|
|
466 a->tmpperiod += (nib << 2);
|
|
467 break;
|
|
468
|
|
469 case 0x3: /* glissando ctrl */
|
|
470 a->glissando = nib;
|
|
471 break;
|
|
472
|
|
473 case 0x4: /* set vibrato waveform */
|
|
474 a->wavecontrol &= 0xf0;
|
|
475 a->wavecontrol |= nib;
|
|
476 break;
|
|
477
|
|
478 case 0x5: /* set finetune */
|
|
479 /* a->speed=finetune[nib]; */
|
|
480 /*
|
|
481 *
|
|
482 * a->tmpperiod=GetPeriod(a->note,pf->samples[a->sample].transpose,a->
|
|
483 * speed);
|
|
484 */
|
|
485 break;
|
|
486
|
|
487 case 0x6: /* set patternloop */
|
|
488 if (pf->vbtick)
|
|
489 break;
|
|
490 /*
|
|
491 * hmm.. this one is a real kludge. But now it works
|
|
492 */
|
|
493 if (nib) { /* set reppos or repcnt ? set repcnt, so
|
|
494 * check if repcnt already is set, which
|
|
495 * means we are already looping */
|
|
496
|
|
497 if (pf->pat_repcnt > 0)
|
|
498 pf->pat_repcnt--; /* already looping, decrease counter */
|
|
499 else
|
|
500 pf->pat_repcnt = nib; /* not yet looping, so set repcnt */
|
|
501
|
|
502 if (pf->pat_repcnt) /* jump to reppos if repcnt>0 */
|
|
503 pf->patpos = pf->pat_reppos;
|
|
504 } else {
|
|
505 pf->pat_reppos = pf->patpos - 1; /* set reppos */
|
|
506 }
|
|
507 break;
|
|
508
|
|
509 case 0x7: /* set tremolo waveform */
|
|
510 a->wavecontrol &= 0x0f;
|
|
511 a->wavecontrol |= nib << 4;
|
|
512 break;
|
|
513
|
|
514 case 0x8: /* set panning */
|
|
515 if (pf->panflag) {
|
|
516 if (nib <= 8)
|
|
517 nib *= 16;
|
|
518 else
|
|
519 nib *= 17;
|
|
520 a->panning = nib;
|
|
521 pf->panning[mp_channel] = nib;
|
|
522 }
|
|
523 break;
|
|
524
|
|
525 case 0x9: /* retrig note */
|
|
526 /*
|
|
527 * only retrigger if data nibble > 0
|
|
528 */
|
|
529
|
|
530 if (nib > 0) {
|
|
531 if (a->retrig == 0) { /* when retrig counter reaches 0,
|
|
532 * reset counter and restart the
|
|
533 * sample */
|
|
534 a->kick = 1;
|
|
535 a->retrig = nib;
|
|
536 }
|
|
537 a->retrig--; /* countdown */
|
|
538 }
|
|
539 break;
|
|
540
|
|
541 case 0xa: /* fine volume slide up */
|
|
542 if (pf->vbtick)
|
|
543 break;
|
|
544
|
|
545 a->tmpvolume += nib;
|
|
546 if (a->tmpvolume > 64)
|
|
547 a->tmpvolume = 64;
|
|
548 break;
|
|
549
|
|
550 case 0xb: /* fine volume slide dn */
|
|
551 if (pf->vbtick)
|
|
552 break;
|
|
553
|
|
554 a->tmpvolume -= nib;
|
|
555 if (a->tmpvolume < 0)
|
|
556 a->tmpvolume = 0;
|
|
557 break;
|
|
558
|
|
559 case 0xc: /* cut note */
|
|
560 /*
|
|
561 * When pf->vbtick reaches the cut-note value, turn the volume to
|
|
562 * zero ( Just like on the amiga)
|
|
563 */
|
|
564 if (pf->vbtick >= nib)
|
|
565 a->tmpvolume = 0; /* just turn the volume down */
|
|
566 break;
|
|
567
|
|
568 case 0xd: /* note delay */
|
|
569 /*
|
|
570 * delay the start of the sample until pf->vbtick==nib
|
|
571 */
|
|
572 if (pf->vbtick == nib) {/* a->kick = 1; */
|
|
573 a->notedelay = 0;
|
|
574 } else if (pf->vbtick == 0) { /* a->kick = 0; */
|
|
575 a->notedelay = 1;
|
|
576 }
|
|
577 break;
|
|
578
|
|
579 case 0xe: /* pattern delay */
|
|
580 if (pf->vbtick)
|
|
581 break;
|
|
582 if (!pf->patdly2)
|
|
583 pf->patdly = nib + 1; /* only once (when pf->vbtick = 0) */
|
|
584 break;
|
|
585
|
|
586 case 0xf: /* invert loop, not supported */
|
|
587 break;
|
|
588 }
|
|
589 }
|
|
590
|
|
591
|
|
592 static void
|
|
593 DoVibrato(void)
|
|
594 {
|
|
595 UBYTE q;
|
|
596 UWORD temp;
|
|
597
|
|
598 q = (a->vibpos >> 2) & 0x1f;
|
|
599
|
|
600 switch (a->wavecontrol & 3) {
|
|
601 case 0: /* sine */
|
|
602 temp = VibratoTable[q];
|
|
603 break;
|
|
604
|
|
605 case 1: /* ramp down */
|
|
606 q <<= 3;
|
|
607 if (a->vibpos < 0)
|
|
608 q = 255 - q;
|
|
609 temp = q;
|
|
610 break;
|
|
611
|
|
612 case 2: /* square wave */
|
|
613 temp = 255;
|
|
614 break;
|
|
615
|
|
616 case 3: /* Evil random wave */
|
|
617 temp = rand() & 255;
|
|
618 break;
|
|
619 }
|
|
620
|
|
621 temp *= a->vibdepth;
|
|
622 temp >>= 7;
|
|
623 temp <<= 2;
|
|
624
|
|
625 if (a->vibpos >= 0)
|
|
626 a->period = a->tmpperiod + temp;
|
|
627 else
|
|
628 a->period = a->tmpperiod - temp;
|
|
629
|
|
630 if (pf->vbtick)
|
|
631 a->vibpos += a->vibspd; /* do not update when pf->vbtick==0 */
|
|
632 }
|
|
633
|
|
634
|
|
635 static void
|
|
636 DoTremolo(void)
|
|
637 {
|
|
638 UBYTE q;
|
|
639 UWORD temp;
|
|
640
|
|
641 q = (a->trmpos >> 2) & 0x1f;
|
|
642
|
|
643 switch ((a->wavecontrol >> 4) & 3) {
|
|
644 case 0: /* sine */
|
|
645 temp = VibratoTable[q];
|
|
646 break;
|
|
647
|
|
648 case 1: /* ramp down */
|
|
649 q <<= 3;
|
|
650 if (a->trmpos < 0)
|
|
651 q = 255 - q;
|
|
652 temp = q;
|
|
653 break;
|
|
654
|
|
655 case 2: /* square wave */
|
|
656 temp = 255;
|
|
657 break;
|
|
658
|
|
659 case 3: /* Evil random wave */
|
|
660 temp = rand() & 255;
|
|
661 break;
|
|
662 }
|
|
663
|
|
664 temp *= a->trmdepth;
|
|
665 temp >>= 6;
|
|
666
|
|
667 if (a->trmpos >= 0) {
|
|
668 a->volume = a->tmpvolume + temp;
|
|
669 if (a->volume > 64)
|
|
670 a->volume = 64;
|
|
671 } else {
|
|
672 a->volume = a->tmpvolume - temp;
|
|
673 if (a->volume < 0)
|
|
674 a->volume = 0;
|
|
675 }
|
|
676
|
|
677 if (pf->vbtick)
|
|
678 a->trmpos += a->trmspd; /* do not update when pf->vbtick == 0 */
|
|
679 }
|
|
680
|
|
681
|
|
682 static void
|
|
683 DoVolSlide(UBYTE dat)
|
|
684 {
|
|
685 if (!pf->vbtick)
|
|
686 return; /* do not update when pf->vbtick == 0 */
|
|
687
|
|
688 a->tmpvolume += dat >> 4; /* volume slide */
|
|
689 a->tmpvolume -= dat & 0xf;
|
|
690 if (a->tmpvolume < 0)
|
|
691 a->tmpvolume = 0;
|
|
692 if (a->tmpvolume > 64)
|
|
693 a->tmpvolume = 64;
|
|
694 }
|
|
695
|
|
696
|
|
697 static void
|
|
698 DoToneSlide(void)
|
|
699 {
|
|
700 int dist;
|
|
701
|
|
702 if (a->period == 0)
|
|
703 return;
|
|
704
|
|
705 if (!pf->vbtick) {
|
|
706 a->tmpperiod = a->period;
|
|
707 return;
|
|
708 }
|
|
709 /*
|
|
710 * We have to slide a->period towards a->wantedperiod, so compute the
|
|
711 * difference between those two values
|
|
712 */
|
|
713
|
|
714 dist = a->period - a->wantedperiod;
|
|
715
|
|
716 if (dist == 0 || a->portspeed > abs(dist)) /* if they are equal or if
|
|
717 * portamentospeed is too big */
|
|
718 a->period = a->wantedperiod; /* make tmpperiod equal tperiod */
|
|
719 else if (dist > 0) /* dist > 0 ? */
|
|
720 a->period -= a->portspeed; /* then slide up */
|
|
721 else
|
|
722 a->period += a->portspeed; /* dist < 0 -> slide down */
|
|
723
|
|
724 a->tmpperiod = a->period;
|
|
725 }
|
|
726
|
|
727
|
|
728 static void
|
|
729 DoPTEffect0(UBYTE dat)
|
|
730 {
|
|
731 UBYTE note;
|
|
732
|
|
733 note = a->note;
|
|
734
|
|
735 if (dat != 0) {
|
|
736 switch (pf->vbtick % 3) {
|
|
737 case 1:
|
|
738 note += (dat >> 4);
|
|
739 break;
|
|
740 case 2:
|
|
741 note += (dat & 0xf);
|
|
742 break;
|
|
743 }
|
|
744 a->period = GetPeriod(note, a->speed);
|
|
745 a->ownper = 1;
|
|
746 }
|
|
747 }
|
|
748
|
|
749
|
|
750 /*
|
|
751 * ----------------------------------------- --> ScreamTreacker 3 Specific
|
|
752 * Effects <-- -----------------------------------------
|
|
753 */
|
|
754 static void
|
|
755 DoS3MVolSlide(UBYTE inf)
|
|
756 {
|
|
757 UBYTE lo, hi;
|
|
758
|
|
759 if (inf)
|
|
760 a->s3mvolslide = inf;
|
|
761
|
|
762 inf = a->s3mvolslide;
|
|
763 lo = inf & 0xf;
|
|
764 hi = inf >> 4;
|
|
765
|
|
766 if (hi == 0)
|
|
767 a->tmpvolume -= lo;
|
|
768 else if (lo == 0)
|
|
769 a->tmpvolume += hi;
|
|
770 else if (hi == 0xf) {
|
|
771 if (!pf->vbtick)
|
|
772 a->tmpvolume -= lo;
|
|
773 } else if (lo == 0xf) {
|
|
774 if (!pf->vbtick)
|
|
775 a->tmpvolume += hi;
|
|
776 }
|
|
777 if (a->tmpvolume < 0)
|
|
778 a->tmpvolume = 0;
|
|
779 if (a->tmpvolume > 64)
|
|
780 a->tmpvolume = 64;
|
|
781 }
|
|
782
|
|
783
|
|
784 static void
|
|
785 DoS3MSlideDn(UBYTE inf)
|
|
786 {
|
|
787 UBYTE hi, lo;
|
|
788
|
|
789 if (inf != 0)
|
|
790 a->slidespeed = inf;
|
|
791 else
|
|
792 inf = a->slidespeed;
|
|
793
|
|
794 hi = inf >> 4;
|
|
795 lo = inf & 0xf;
|
|
796
|
|
797 if (hi == 0xf) {
|
|
798 if (!pf->vbtick)
|
|
799 a->tmpperiod += (UWORD) lo << 2;
|
|
800 } else if (hi == 0xe) {
|
|
801 if (!pf->vbtick)
|
|
802 a->tmpperiod += lo;
|
|
803 } else {
|
|
804 if (pf->vbtick)
|
|
805 a->tmpperiod += (UWORD) inf << 2;
|
|
806 }
|
|
807 }
|
|
808
|
|
809
|
|
810 static void
|
|
811 DoS3MSlideUp(UBYTE inf)
|
|
812 {
|
|
813 UBYTE hi, lo;
|
|
814
|
|
815 if (inf != 0)
|
|
816 a->slidespeed = inf;
|
|
817 else
|
|
818 inf = a->slidespeed;
|
|
819
|
|
820 hi = inf >> 4;
|
|
821 lo = inf & 0xf;
|
|
822
|
|
823 if (hi == 0xf) {
|
|
824 if (!pf->vbtick)
|
|
825 a->tmpperiod -= (UWORD) lo << 2;
|
|
826 } else if (hi == 0xe) {
|
|
827 if (!pf->vbtick)
|
|
828 a->tmpperiod -= lo;
|
|
829 } else {
|
|
830 if (pf->vbtick)
|
|
831 a->tmpperiod -= (UWORD) inf << 2;
|
|
832 }
|
|
833 }
|
|
834
|
|
835
|
|
836 static void
|
|
837 DoS3MTremor(UBYTE inf)
|
|
838 {
|
|
839 UBYTE on, off;
|
|
840
|
|
841 if (inf != 0)
|
|
842 a->s3mtronof = inf;
|
|
843 else
|
|
844 inf = a->s3mtronof;
|
|
845
|
|
846 if (!pf->vbtick)
|
|
847 return;
|
|
848
|
|
849 on = (inf >> 4) + 1;
|
|
850 off = (inf & 0xf) + 1;
|
|
851
|
|
852 a->s3mtremor %= (on + off);
|
|
853 a->volume = (a->s3mtremor < on) ? a->tmpvolume : 0;
|
|
854 a->s3mtremor++;
|
|
855 }
|
|
856
|
|
857
|
|
858 static void
|
|
859 DoS3MRetrig(UBYTE inf)
|
|
860 {
|
|
861 UBYTE hi, lo;
|
|
862
|
|
863 hi = inf >> 4;
|
|
864 lo = inf & 0xf;
|
|
865
|
|
866 if (inf) {
|
|
867 a->s3mrtgslide = hi;
|
|
868 a->s3mrtgspeed = lo;
|
|
869 }
|
|
870 /*
|
|
871 * only retrigger if lo nibble > 0
|
|
872 */
|
|
873
|
|
874 if (a->s3mrtgspeed > 0) {
|
|
875 if (a->retrig == 0) { /* when retrig counter reaches 0, reset
|
|
876 * counter and restart the sample */
|
|
877
|
|
878 if (!a->kick)
|
|
879 a->kick = 2;
|
|
880 a->retrig = a->s3mrtgspeed;
|
|
881
|
|
882 if (pf->vbtick) { /* don't slide on first retrig */
|
|
883 switch (a->s3mrtgslide) {
|
|
884 case 1:
|
|
885 case 2:
|
|
886 case 3:
|
|
887 case 4:
|
|
888 case 5:
|
|
889 a->tmpvolume -= (1 << (a->s3mrtgslide - 1));
|
|
890 break;
|
|
891
|
|
892 case 6:
|
|
893 a->tmpvolume = (2 * a->tmpvolume) / 3;
|
|
894 break;
|
|
895
|
|
896 case 7:
|
|
897 a->tmpvolume = a->tmpvolume >> 1;
|
|
898 break;
|
|
899
|
|
900 case 9:
|
|
901 case 0xa:
|
|
902 case 0xb:
|
|
903 case 0xc:
|
|
904 case 0xd:
|
|
905 a->tmpvolume += (1 << (a->s3mrtgslide - 9));
|
|
906 break;
|
|
907
|
|
908 case 0xe:
|
|
909 a->tmpvolume = (3 * a->tmpvolume) / 2;
|
|
910 break;
|
|
911
|
|
912 case 0xf:
|
|
913 a->tmpvolume = a->tmpvolume << 1;
|
|
914 break;
|
|
915 }
|
|
916 if (a->tmpvolume < 0)
|
|
917 a->tmpvolume = 0;
|
|
918 if (a->tmpvolume > 64)
|
|
919 a->tmpvolume = 64;
|
|
920 }
|
|
921 }
|
|
922 a->retrig--; /* countdown */
|
|
923 }
|
|
924 }
|
|
925
|
|
926
|
|
927 static void
|
|
928 DoS3MSpeed(UBYTE speed)
|
|
929 {
|
|
930 if (pf->vbtick || pf->patdly2)
|
|
931 return;
|
|
932
|
|
933 if (speed) {
|
|
934 pf->sngspd = speed;
|
|
935 pf->vbtick = 0;
|
|
936 }
|
|
937 }
|
|
938
|
|
939
|
|
940 static void
|
|
941 DoS3MTempo(UBYTE tempo)
|
|
942 {
|
|
943 if (pf->vbtick || pf->patdly2)
|
|
944 return;
|
|
945 pf->bpm = tempo;
|
|
946 }
|
|
947
|
|
948
|
|
949 static void
|
|
950 DoS3MFineVibrato(void)
|
|
951 {
|
|
952 UBYTE q;
|
|
953 UWORD temp;
|
|
954
|
|
955 q = (a->vibpos >> 2) & 0x1f;
|
|
956
|
|
957 switch (a->wavecontrol & 3) {
|
|
958 case 0: /* sine */
|
|
959 temp = VibratoTable[q];
|
|
960 break;
|
|
961
|
|
962 case 1: /* ramp down */
|
|
963 q <<= 3;
|
|
964 if (a->vibpos < 0)
|
|
965 q = 255 - q;
|
|
966 temp = q;
|
|
967 break;
|
|
968
|
|
969 case 2: /* square wave */
|
|
970 temp = 255;
|
|
971 break;
|
|
972
|
|
973 case 3: /* evil random */
|
|
974 temp = rand() & 255; /* (range 0 to 255) */
|
|
975 }
|
|
976
|
|
977 temp *= a->vibdepth;
|
|
978 temp >>= 8;
|
|
979
|
|
980 if (a->vibpos >= 0)
|
|
981 a->period = a->tmpperiod + temp;
|
|
982 else
|
|
983 a->period = a->tmpperiod - temp;
|
|
984
|
|
985 a->vibpos += a->vibspd;
|
|
986 }
|
|
987
|
|
988
|
|
989 static void
|
|
990 DoS3MTremolo(void)
|
|
991 {
|
|
992 UBYTE q;
|
|
993 UWORD temp;
|
|
994
|
|
995 q = (a->trmpos >> 2) & 0x1f;
|
|
996
|
|
997 switch ((a->wavecontrol >> 4) & 3) {
|
|
998 case 0: /* sine */
|
|
999 temp = VibratoTable[q];
|
|
1000 break;
|
|
1001
|
|
1002 case 1: /* ramp down */
|
|
1003 q <<= 3;
|
|
1004 if (a->trmpos < 0)
|
|
1005 q = 255 - q;
|
|
1006 temp = q;
|
|
1007 break;
|
|
1008
|
|
1009 case 2: /* square wave */
|
|
1010 temp = 255;
|
|
1011 break;
|
|
1012
|
|
1013 case 3: /* evil random */
|
|
1014 temp = rand() & 255; /* (range 0 to 255) */
|
|
1015 }
|
|
1016
|
|
1017 temp *= a->trmdepth;
|
|
1018 temp >>= 7;
|
|
1019
|
|
1020 if (a->trmpos >= 0) {
|
|
1021 a->volume = a->tmpvolume + temp;
|
|
1022 if (a->volume > 64)
|
|
1023 a->volume = 64;
|
|
1024 } else {
|
|
1025 a->volume = a->tmpvolume - temp;
|
|
1026 if (a->volume < 0)
|
|
1027 a->volume = 0;
|
|
1028 }
|
|
1029
|
|
1030 if (pf->vbtick)
|
|
1031 a->trmpos += a->trmspd; /* do not update when pf->vbtick == 0 */
|
|
1032 }
|
|
1033
|
|
1034
|
|
1035 /*
|
|
1036 * -------------------------------------- --> FastTracker 2 Specific Effects
|
|
1037 * <-- --------------------------------------
|
|
1038 */
|
|
1039 static void
|
|
1040 DoXMVolSlide(UBYTE inf)
|
|
1041 {
|
|
1042 UBYTE lo, hi;
|
|
1043
|
|
1044 if (inf)
|
|
1045 a->s3mvolslide = inf;
|
|
1046
|
|
1047 inf = a->s3mvolslide;
|
|
1048 if (!pf->vbtick)
|
|
1049 return;
|
|
1050
|
|
1051 lo = inf & 0xf;
|
|
1052 hi = inf >> 4;
|
|
1053
|
|
1054 if (hi == 0)
|
|
1055 a->tmpvolume -= lo;
|
|
1056 else
|
|
1057 a->tmpvolume += hi;
|
|
1058
|
|
1059 if (a->tmpvolume < 0)
|
|
1060 a->tmpvolume = 0;
|
|
1061 else if (a->tmpvolume > 64)
|
|
1062 a->tmpvolume = 64;
|
|
1063 }
|
|
1064
|
|
1065
|
|
1066 static void
|
|
1067 DoXMGlobalSlide(UBYTE inf)
|
|
1068 {
|
|
1069 if (pf->vbtick) {
|
|
1070 if (inf)
|
|
1071 pf->globalslide = inf;
|
|
1072 else
|
|
1073 inf = pf->globalslide;
|
|
1074 if (inf & 0xf0)
|
|
1075 inf &= 0xf0;
|
|
1076 pf->volume = pf->volume + ((inf >> 4) - (inf & 0xf)) * 2;
|
|
1077
|
|
1078 if (pf->volume < 0)
|
|
1079 pf->volume = 0;
|
|
1080 else if (pf->volume > 128)
|
|
1081 pf->volume = 128;
|
|
1082 }
|
|
1083 }
|
|
1084
|
|
1085
|
|
1086 static void
|
|
1087 DoXMPanSlide(UBYTE inf)
|
|
1088 {
|
|
1089 UBYTE lo, hi;
|
|
1090 SWORD pan;
|
|
1091
|
|
1092
|
|
1093 if (inf != 0)
|
|
1094 a->pansspd = inf;
|
|
1095 else
|
|
1096 inf = a->pansspd;
|
|
1097
|
|
1098 if (!pf->vbtick)
|
|
1099 return;
|
|
1100
|
|
1101 lo = inf & 0xf;
|
|
1102 hi = inf >> 4;
|
|
1103
|
|
1104 /* slide right has absolute priority: */
|
|
1105
|
|
1106 if (hi)
|
|
1107 lo = 0;
|
|
1108
|
|
1109 pan = (a->panning == PAN_SURROUND) ? 128 : a->panning;
|
|
1110
|
|
1111 pan -= lo;
|
|
1112 pan += hi;
|
|
1113
|
|
1114 if (pan < 0)
|
|
1115 pan = 0;
|
|
1116 if (pan > 255)
|
|
1117 pan = 255;
|
|
1118
|
|
1119 a->panning = pan;
|
|
1120 }
|
|
1121
|
|
1122
|
|
1123 static void
|
|
1124 DoXMExtraFineSlideUp(UBYTE inf)
|
|
1125 {
|
|
1126 if (!pf->vbtick) {
|
|
1127 if (inf)
|
|
1128 a->ffportupspd = inf;
|
|
1129 else
|
|
1130 inf = a->ffportupspd;
|
|
1131 a->period -= inf;
|
|
1132 }
|
|
1133 a->tmpperiod = a->period;
|
|
1134 }
|
|
1135
|
|
1136
|
|
1137 static void
|
|
1138 DoXMExtraFineSlideDown(UBYTE inf)
|
|
1139 {
|
|
1140 if (!pf->vbtick) {
|
|
1141 if (inf)
|
|
1142 a->ffportdnspd = inf;
|
|
1143 else
|
|
1144 inf = a->ffportdnspd;
|
|
1145 a->period += inf;
|
|
1146 }
|
|
1147 a->tmpperiod = a->period;
|
|
1148 }
|
|
1149
|
|
1150
|
|
1151 /*
|
|
1152 * --------------------------------------- --> ImpulseTracker Player
|
|
1153 * Functions <-- ---------------------------------------
|
|
1154 */
|
|
1155 static void
|
|
1156 DoITChanVolSlide(UBYTE inf)
|
|
1157 {
|
|
1158 UBYTE lo, hi;
|
|
1159
|
|
1160 if (inf)
|
|
1161 a->chanvolslide = inf;
|
|
1162 inf = a->chanvolslide;
|
|
1163
|
|
1164 lo = inf & 0xf;
|
|
1165 hi = inf >> 4;
|
|
1166
|
|
1167 if (hi == 0) {
|
|
1168 a->chanvol -= lo;
|
|
1169 } else if (lo == 0) {
|
|
1170 a->chanvol += hi;
|
|
1171 } else if (hi == 0xf) {
|
|
1172 if (!pf->vbtick)
|
|
1173 a->chanvol -= lo;
|
|
1174 } else if (lo == 0xf) {
|
|
1175 if (!pf->vbtick)
|
|
1176 a->chanvol += hi;
|
|
1177 }
|
|
1178 if (a->chanvol < 0)
|
|
1179 a->chanvol = 0;
|
|
1180 if (a->chanvol > 64)
|
|
1181 a->chanvol = 64;
|
|
1182 }
|
|
1183
|
|
1184
|
|
1185 static void
|
|
1186 DoITGlobalSlide(UBYTE inf)
|
|
1187 {
|
|
1188 UBYTE lo, hi;
|
|
1189
|
|
1190 if (inf)
|
|
1191 pf->globalslide = inf;
|
|
1192 inf = pf->globalslide;
|
|
1193
|
|
1194 lo = inf & 0xf;
|
|
1195 hi = inf >> 4;
|
|
1196
|
|
1197 if (lo == 0) {
|
|
1198 pf->volume += hi;
|
|
1199 } else if (hi == 0) {
|
|
1200 pf->volume -= lo;
|
|
1201 } else if (lo == 0xf) {
|
|
1202 if (!pf->vbtick)
|
|
1203 pf->volume += hi;
|
|
1204 } else if (hi == 0xf) {
|
|
1205 if (!pf->vbtick)
|
|
1206 pf->volume -= lo;
|
|
1207 }
|
|
1208 if (pf->volume < 0)
|
|
1209 pf->volume = 0;
|
|
1210 if (pf->volume > 128)
|
|
1211 pf->volume = 128;
|
|
1212 }
|
|
1213
|
|
1214
|
|
1215 static void
|
|
1216 DoITPanSlide(UBYTE inf)
|
|
1217 {
|
|
1218 UBYTE lo, hi;
|
|
1219 SWORD pan;
|
|
1220
|
|
1221 if (inf)
|
|
1222 a->pansspd = inf;
|
|
1223 inf = a->pansspd;
|
|
1224
|
|
1225 lo = inf & 0xf;
|
|
1226 hi = inf >> 4;
|
|
1227
|
|
1228 pan = (a->panning == PAN_SURROUND) ? 128 : a->panning;
|
|
1229
|
|
1230 if (hi == 0) {
|
|
1231 pan += lo << 2;
|
|
1232 } else if (lo == 0) {
|
|
1233 pan -= hi << 2;
|
|
1234 } else if (hi == 0xf) {
|
|
1235 if (!pf->vbtick)
|
|
1236 pan += lo << 2;
|
|
1237 } else if (lo == 0xf) {
|
|
1238 if (!pf->vbtick)
|
|
1239 pan -= hi << 2;
|
|
1240 }
|
|
1241 if (pan > 255)
|
|
1242 pan = 255;
|
|
1243 if (pan < 0)
|
|
1244 pan = 0;
|
|
1245 a->panning = /* pf->panning[mp_channel] = */ pan;
|
|
1246 }
|
|
1247
|
|
1248
|
|
1249 static void
|
|
1250 DoITVibrato(void)
|
|
1251 {
|
|
1252 UBYTE q;
|
|
1253 UWORD temp;
|
|
1254
|
|
1255 q = (a->vibpos >> 2) & 0x1f;
|
|
1256
|
|
1257 switch (a->wavecontrol & 3) {
|
|
1258 case 0: /* sine */
|
|
1259 temp = VibratoTable[q];
|
|
1260 break;
|
|
1261
|
|
1262 case 1: /* ramp down */
|
|
1263 q <<= 3;
|
|
1264 if (a->vibpos < 0)
|
|
1265 q = 255 - q;
|
|
1266 temp = q;
|
|
1267 break;
|
|
1268
|
|
1269 case 2: /* square wave */
|
|
1270 temp = 255;
|
|
1271 break;
|
|
1272
|
|
1273 case 3: /* evil random */
|
|
1274 temp = rand() & 255; /* (range 0 to 255) */
|
|
1275 break;
|
|
1276 }
|
|
1277
|
|
1278 temp *= a->vibdepth;
|
|
1279 temp >>= 8;
|
|
1280 temp <<= 2;
|
|
1281
|
|
1282 if (a->vibpos >= 0)
|
|
1283 a->period = a->tmpperiod + temp;
|
|
1284 else
|
|
1285 a->period = a->tmpperiod - temp;
|
|
1286
|
|
1287 a->vibpos += a->vibspd;
|
|
1288 }
|
|
1289
|
|
1290
|
|
1291 static void
|
|
1292 DoITFineVibrato(void)
|
|
1293 {
|
|
1294 UBYTE q;
|
|
1295 UWORD temp;
|
|
1296
|
|
1297 q = (a->vibpos >> 2) & 0x1f;
|
|
1298
|
|
1299 switch (a->wavecontrol & 3) {
|
|
1300 case 0: /* sine */
|
|
1301 temp = VibratoTable[q];
|
|
1302 break;
|
|
1303
|
|
1304 case 1: /* ramp down */
|
|
1305 q <<= 3;
|
|
1306 if (a->vibpos < 0)
|
|
1307 q = 255 - q;
|
|
1308 temp = q;
|
|
1309 break;
|
|
1310
|
|
1311 case 2: /* square wave */
|
|
1312 temp = 255;
|
|
1313 break;
|
|
1314
|
|
1315 case 3: /* evil random */
|
|
1316 temp = rand() & 255; /* (range 0 to 255) */
|
|
1317 break;
|
|
1318 }
|
|
1319
|
|
1320 temp *= a->vibdepth;
|
|
1321 temp >>= 8;
|
|
1322
|
|
1323 if (a->vibpos >= 0)
|
|
1324 a->period = a->tmpperiod + temp;
|
|
1325 else
|
|
1326 a->period = a->tmpperiod - temp;
|
|
1327
|
|
1328 a->vibpos += a->vibspd;
|
|
1329 }
|
|
1330
|
|
1331
|
|
1332 static void
|
|
1333 DoITTremor(UBYTE inf)
|
|
1334 {
|
|
1335 UBYTE on, off;
|
|
1336
|
|
1337 if (inf != 0)
|
|
1338 a->s3mtronof = inf;
|
|
1339 else
|
|
1340 inf = a->s3mtronof;
|
|
1341
|
|
1342 if (!pf->vbtick)
|
|
1343 return;
|
|
1344
|
|
1345 on = (inf >> 4);
|
|
1346 off = (inf & 0xf);
|
|
1347
|
|
1348 a->s3mtremor %= (on + off);
|
|
1349 a->volume = (a->s3mtremor < on) ? a->tmpvolume : 0;
|
|
1350 a->s3mtremor++;
|
|
1351 }
|
|
1352
|
|
1353
|
|
1354 static void
|
|
1355 DoITPanbrello(void)
|
|
1356 {
|
|
1357 UBYTE q;
|
|
1358 static SLONG temp;
|
|
1359
|
|
1360 q = a->panbpos;
|
|
1361
|
|
1362 switch (a->panbwave) {
|
|
1363 case 0: /* sine */
|
|
1364 temp = PanbrelloTable[q];
|
|
1365 break;
|
|
1366
|
|
1367 /* only sinewave is correctly supported right now */
|
|
1368
|
|
1369 case 1: /* ramp down */
|
|
1370 q <<= 3;
|
|
1371 temp = q;
|
|
1372 break;
|
|
1373
|
|
1374 case 2: /* square wave */
|
|
1375 temp = 64;
|
|
1376 break;
|
|
1377
|
|
1378 case 3: /* evil random */
|
|
1379 if (a->panbpos >= a->panbspd) {
|
|
1380 a->panbpos = 0;
|
|
1381 temp = rand() & 255;
|
|
1382 }
|
|
1383 }
|
|
1384
|
|
1385 temp *= a->panbdepth;
|
|
1386 temp /= 8;
|
|
1387
|
|
1388 a->panning = pf->panning[mp_channel] + temp;
|
|
1389 a->panbpos += a->panbspd;
|
|
1390 }
|
|
1391
|
|
1392
|
|
1393 static void
|
|
1394 DoITToneSlide(void)
|
|
1395 {
|
|
1396 int dist;
|
|
1397
|
|
1398 if (a->period == 0)
|
|
1399 return;
|
|
1400
|
|
1401 if (!pf->vbtick) {
|
|
1402 a->tmpperiod = a->period;
|
|
1403 return;
|
|
1404 }
|
|
1405 /*
|
|
1406 * We have to slide a->period towards a->wantedperiod, compute the
|
|
1407 * difference between those two values
|
|
1408 */
|
|
1409
|
|
1410 dist = a->period - a->wantedperiod;
|
|
1411
|
|
1412 if ((dist == 0) || /* if they are equal */
|
|
1413 ((a->slidespeed << 2) > abs(dist))) { /* or if portamentospeed is
|
|
1414 * too big */
|
|
1415 a->period = a->wantedperiod; /* make tmpperiod equal tperiod */
|
|
1416 } else if (dist > 0) { /* dist > 0 ? */
|
|
1417 a->period -= a->slidespeed << 2; /* then slide up */
|
|
1418 } else {
|
|
1419 a->period += a->slidespeed << 2; /* dist<0 -> slide down */
|
|
1420 }
|
|
1421 a->tmpperiod = a->period;
|
|
1422 }
|
|
1423
|
|
1424
|
|
1425 /*
|
|
1426 * Impulse/Scream Tracker Sxx effects. All Sxx effects share the same memory
|
|
1427 * space.
|
|
1428 */
|
|
1429 static void
|
|
1430 DoSSEffects(UBYTE dat)
|
|
1431 {
|
|
1432 UBYTE inf, c;
|
|
1433
|
|
1434 inf = dat & 0xf;
|
|
1435 c = dat >> 4;
|
|
1436
|
|
1437 if (dat == 0) {
|
|
1438 c = a->sseffect;
|
|
1439 inf = a->ssdata;
|
|
1440 } else {
|
|
1441 a->sseffect = c;
|
|
1442 a->ssdata = inf;
|
|
1443 }
|
|
1444
|
|
1445 switch (c) {
|
|
1446 case SS_GLISSANDO: /* S1x set glissando voice */
|
|
1447 DoEEffects(0x30 | inf);
|
|
1448 break;
|
|
1449
|
|
1450 case SS_FINETUNE: /* S2x set finetune */
|
|
1451 DoEEffects(0x50 | inf);
|
|
1452 break;
|
|
1453
|
|
1454 case SS_VIBWAVE: /* S3x set vibrato waveform */
|
|
1455 DoEEffects(0x40 | inf);
|
|
1456 break;
|
|
1457
|
|
1458 case SS_TREMWAVE: /* S4x set tremolo waveform */
|
|
1459 DoEEffects(0x70 | inf);
|
|
1460 break;
|
|
1461
|
|
1462 case SS_PANWAVE: /* The Satanic Panbrello waveform */
|
|
1463 a->panbwave = (UniGetByte());
|
|
1464 break;
|
|
1465
|
|
1466 case SS_FRAMEDELAY: /* S6x Delay x number of frames (patdly) */
|
|
1467 DoEEffects(0xe0 | inf);
|
|
1468 break;
|
|
1469
|
|
1470 case SS_S7EFFECTS: /* S7x Instrument / NNA commands */
|
|
1471 DoNNAEffects(UniGetByte());
|
|
1472 break;
|
|
1473
|
|
1474 case SS_PANNING: /* S8x set panning position */
|
|
1475 DoEEffects(0x80 | inf);
|
|
1476 break;
|
|
1477
|
|
1478 case SS_SURROUND: /* S9x Set Surround Sound */
|
|
1479 a->panning = pf->panning[mp_channel] = PAN_SURROUND;
|
|
1480 break;
|
|
1481
|
|
1482 case SS_HIOFFSET: /* SAy Set high order sample offset yxx00h */
|
|
1483 a->hioffset |= UniGetByte() << 16;
|
|
1484 break;
|
|
1485
|
|
1486 case SS_PATLOOP: /* SBx pattern loop */
|
|
1487 DoEEffects(0x60 | inf);
|
|
1488 break;
|
|
1489
|
|
1490 case SS_NOTECUT: /* SCx notecut */
|
|
1491 DoEEffects(0xC0 | inf);
|
|
1492 break;
|
|
1493
|
|
1494 case SS_NOTEDELAY: /* SDx notedelay */
|
|
1495 DoEEffects(0xD0 | inf);
|
|
1496 break;
|
|
1497
|
|
1498 case SS_PATDELAY: /* SEx patterndelay */
|
|
1499 DoEEffects(0xE0 | inf);
|
|
1500 break;
|
|
1501 }
|
|
1502 }
|
|
1503
|
|
1504
|
|
1505 /*
|
|
1506 * Impulse Tracker Volume/Pan Column effects. All volume/pan column effects
|
|
1507 * share the same memory space.
|
|
1508 */
|
|
1509 static void
|
|
1510 DoVolEffects(UBYTE c)
|
|
1511 {
|
|
1512 UBYTE inf;
|
|
1513
|
|
1514 inf = UniGetByte();
|
|
1515
|
|
1516 if (c == 0 && inf == 0) {
|
|
1517 c = a->voleffect;
|
|
1518 inf = a->voldata;
|
|
1519 } else {
|
|
1520 a->voleffect = c;
|
|
1521 a->voldata = inf;
|
|
1522 }
|
|
1523
|
|
1524 switch (c) {
|
|
1525 case 0:
|
|
1526 break; /* do nothing */
|
|
1527 case VOL_VOLUME:
|
|
1528 if (pf->vbtick)
|
|
1529 break;
|
|
1530 if (inf > 64)
|
|
1531 inf = 64;
|
|
1532 a->tmpvolume = inf;
|
|
1533 break;
|
|
1534
|
|
1535 case VOL_PANNING:
|
|
1536 if (pf->panflag) {
|
|
1537 a->panning = inf;
|
|
1538 pf->panning[mp_channel] = inf;
|
|
1539 }
|
|
1540 break;
|
|
1541
|
|
1542 case VOL_VOLSLIDE:
|
|
1543 DoS3MVolSlide(inf);
|
|
1544 break;
|
|
1545
|
|
1546 case VOL_PITCHSLIDEDN:
|
|
1547 DoS3MSlideDn(UniGetByte());
|
|
1548 break;
|
|
1549
|
|
1550 case VOL_PITCHSLIDEUP:
|
|
1551 DoS3MSlideUp(UniGetByte());
|
|
1552 break;
|
|
1553
|
|
1554 case VOL_PORTAMENTO:
|
|
1555 if (inf != 0)
|
|
1556 a->slidespeed = inf;
|
|
1557
|
|
1558 if (a->period != 0) {
|
|
1559 if (!(pf->vbtick == pf->sngspd - 1) && (a->newsamp)) {
|
|
1560 a->kick = 1;
|
|
1561 a->start = -1;
|
|
1562 /* a->period *= a->speed * a->newsamp; */
|
|
1563 } else
|
|
1564 a->kick = 0;
|
|
1565
|
|
1566 DoITToneSlide();
|
|
1567 a->ownper = 1;
|
|
1568 }
|
|
1569 break;
|
|
1570
|
|
1571 case VOL_VIBRATO:
|
|
1572 if (inf & 0x0f)
|
|
1573 a->vibdepth = inf & 0xf;
|
|
1574 if (inf & 0xf0)
|
|
1575 a->vibspd = (inf & 0xf0) >> 2;
|
|
1576 DoITVibrato();
|
|
1577 a->ownper = 1;
|
|
1578 break;
|
|
1579 }
|
|
1580 }
|
|
1581
|
|
1582
|
|
1583
|
|
1584 /*
|
|
1585 * -------------------------------- --> General Player Functions <--
|
|
1586 * --------------------------------
|
|
1587 */
|
|
1588 static void
|
|
1589 pt_playeffects(void)
|
|
1590 {
|
|
1591 UBYTE dat, c;
|
|
1592
|
|
1593 while (c = UniGetByte())
|
|
1594 switch (c) {
|
|
1595 case UNI_NOTE:
|
|
1596 case UNI_INSTRUMENT:
|
|
1597 UniSkipOpcode(c);
|
|
1598 break;
|
|
1599
|
|
1600 case UNI_PTEFFECT0:
|
|
1601 DoPTEffect0(UniGetByte());
|
|
1602 break;
|
|
1603
|
|
1604 case UNI_PTEFFECT1:
|
|
1605 dat = UniGetByte();
|
|
1606 if (dat != 0)
|
|
1607 a->slidespeed = (UWORD) dat << 2;
|
|
1608 if (pf->vbtick)
|
|
1609 a->tmpperiod -= a->slidespeed;
|
|
1610 break;
|
|
1611
|
|
1612 case UNI_PTEFFECT2:
|
|
1613 dat = UniGetByte();
|
|
1614 if (dat != 0)
|
|
1615 a->slidespeed = (UWORD) dat << 2;
|
|
1616 if (pf->vbtick)
|
|
1617 a->tmpperiod += a->slidespeed;
|
|
1618 break;
|
|
1619
|
|
1620 case UNI_PTEFFECT3:
|
|
1621 dat = UniGetByte();
|
|
1622
|
|
1623 if (dat != 0) {
|
|
1624 a->portspeed = dat;
|
|
1625 a->portspeed <<= 2;
|
|
1626 }
|
|
1627 if (a->period != 0) {
|
|
1628 a->kick = 0; /* temp XM fix */
|
|
1629 DoToneSlide();
|
|
1630 a->ownper = 1;
|
|
1631 }
|
|
1632 break;
|
|
1633
|
|
1634 case UNI_PTEFFECT4:
|
|
1635 dat = UniGetByte();
|
|
1636 if (dat & 0x0f)
|
|
1637 a->vibdepth = dat & 0xf;
|
|
1638 if (dat & 0xf0)
|
|
1639 a->vibspd = (dat & 0xf0) >> 2;
|
|
1640 DoVibrato();
|
|
1641 a->ownper = 1;
|
|
1642 break;
|
|
1643
|
|
1644 case UNI_PTEFFECT5:
|
|
1645 dat = UniGetByte();
|
|
1646 a->kick = 0;
|
|
1647 DoToneSlide();
|
|
1648 DoVolSlide(dat);
|
|
1649 a->ownper = 1;
|
|
1650 break;
|
|
1651
|
|
1652 case UNI_PTEFFECT6:
|
|
1653 dat = UniGetByte();
|
|
1654 DoVibrato();
|
|
1655 DoVolSlide(dat);
|
|
1656 a->ownper = 1;
|
|
1657 break;
|
|
1658
|
|
1659 case UNI_PTEFFECT7:
|
|
1660 dat = UniGetByte();
|
|
1661 if (dat & 0x0f)
|
|
1662 a->trmdepth = dat & 0xf;
|
|
1663 if (dat & 0xf0)
|
|
1664 a->trmspd = (dat & 0xf0) >> 2;
|
|
1665 DoTremolo();
|
|
1666 a->ownvol = 1;
|
|
1667 break;
|
|
1668
|
|
1669 case UNI_PTEFFECT8:
|
|
1670 dat = UniGetByte();
|
|
1671 if (pf->panflag) {
|
|
1672 a->panning = dat;
|
|
1673 pf->panning[mp_channel] = dat;
|
|
1674 }
|
|
1675 break;
|
|
1676
|
|
1677 case UNI_PTEFFECT9:
|
|
1678 dat = UniGetByte();
|
|
1679 if (dat)
|
|
1680 a->soffset = (UWORD) dat << 8;
|
|
1681 a->start = a->hioffset | a->soffset;
|
|
1682 if ((a->s != NULL) && (a->start > a->s->length))
|
|
1683 a->start = a->s->loopstart;
|
|
1684 break;
|
|
1685
|
|
1686 case UNI_PTEFFECTA:
|
|
1687 DoVolSlide(UniGetByte());
|
|
1688 break;
|
|
1689
|
|
1690 case UNI_PTEFFECTB:
|
|
1691 dat = UniGetByte();
|
|
1692 if (pf->patdly2)
|
|
1693 break;
|
|
1694 pf->patbrk = 0;
|
|
1695 pf->sngpos = dat - 1;
|
|
1696 pf->posjmp = 3;
|
|
1697 break;
|
|
1698
|
|
1699 case UNI_PTEFFECTC:
|
|
1700 dat = UniGetByte();
|
|
1701 if (pf->vbtick)
|
|
1702 break;
|
|
1703 if (dat > 64)
|
|
1704 dat = 64;
|
|
1705 a->tmpvolume = dat;
|
|
1706 break;
|
|
1707
|
|
1708 case UNI_PTEFFECTD:
|
|
1709 dat = UniGetByte();
|
|
1710 if (pf->patdly2)
|
|
1711 break;
|
|
1712 pf->patbrk = dat;
|
|
1713 if (pf->patbrk > pf->pattrows[mp_channel])
|
|
1714 pf->patbrk = pf->pattrows[mp_channel];
|
|
1715 pf->posjmp = 3;
|
|
1716 break;
|
|
1717
|
|
1718 case UNI_PTEFFECTE:
|
|
1719 DoEEffects(UniGetByte());
|
|
1720 break;
|
|
1721
|
|
1722 case UNI_PTEFFECTF:
|
|
1723 dat = UniGetByte();
|
|
1724
|
|
1725 if (pf->vbtick || pf->patdly2)
|
|
1726 break;
|
|
1727
|
|
1728 if (pf->extspd && (dat >= 0x20))
|
|
1729 pf->bpm = dat;
|
|
1730 else {
|
|
1731 if (dat) {
|
|
1732 pf->sngspd = dat;
|
|
1733 pf->vbtick = 0;
|
|
1734 }
|
|
1735 }
|
|
1736 break;
|
|
1737
|
|
1738 case UNI_S3MEFFECTA:
|
|
1739 DoS3MSpeed(UniGetByte());
|
|
1740 break;
|
|
1741
|
|
1742 case UNI_S3MEFFECTD:
|
|
1743 DoS3MVolSlide(UniGetByte());
|
|
1744 break;
|
|
1745
|
|
1746 case UNI_S3MEFFECTE:
|
|
1747 DoS3MSlideDn(UniGetByte());
|
|
1748 break;
|
|
1749
|
|
1750 case UNI_S3MEFFECTF:
|
|
1751 DoS3MSlideUp(UniGetByte());
|
|
1752 break;
|
|
1753
|
|
1754 case UNI_S3MEFFECTI:
|
|
1755 DoS3MTremor(UniGetByte());
|
|
1756 a->ownvol = 1;
|
|
1757 break;
|
|
1758
|
|
1759 case UNI_S3MEFFECTQ:
|
|
1760 DoS3MRetrig(UniGetByte());
|
|
1761 break;
|
|
1762
|
|
1763 case UNI_S3MEFFECTR:
|
|
1764 dat = UniGetByte();
|
|
1765 if (dat & 0x0f)
|
|
1766 a->trmdepth = dat & 0xf;
|
|
1767 if (dat & 0xf0)
|
|
1768 a->trmspd = (dat & 0xf0) >> 2;
|
|
1769 DoS3MTremolo();
|
|
1770 a->ownvol = 1;
|
|
1771 break;
|
|
1772
|
|
1773 case UNI_S3MEFFECTT:
|
|
1774 DoS3MTempo(UniGetByte());
|
|
1775 break;
|
|
1776
|
|
1777 case UNI_S3MEFFECTU:
|
|
1778 dat = UniGetByte();
|
|
1779 if (dat & 0x0f)
|
|
1780 a->vibdepth = dat & 0xf;
|
|
1781 if (dat & 0xf0)
|
|
1782 a->vibspd = (dat & 0xf0) >> 2;
|
|
1783 DoS3MFineVibrato();
|
|
1784 a->ownper = 1;
|
|
1785 break;
|
|
1786
|
|
1787 case UNI_KEYOFF:
|
|
1788 a->keyoff |= KEY_OFF;
|
|
1789 if (a->i != NULL) {
|
|
1790 if (!(a->i->volflg & EF_ON) || (a->i->volflg & EF_LOOP))
|
|
1791 a->keyoff = KEY_KILL;
|
|
1792 }
|
|
1793 break;
|
|
1794
|
|
1795 case UNI_KEYFADE:
|
|
1796 if (pf->vbtick >= UniGetByte()) {
|
|
1797 a->keyoff = KEY_KILL;
|
|
1798 if ((a->i != NULL) && !(a->i->volflg & EF_ON))
|
|
1799 a->fadevol = 0;
|
|
1800 }
|
|
1801 break;
|
|
1802
|
|
1803 case UNI_VOLEFFECTS:
|
|
1804 DoVolEffects(UniGetByte());
|
|
1805 break;
|
|
1806
|
|
1807 case UNI_XMEFFECT4:
|
|
1808 dat = UniGetByte();
|
|
1809 if (pf->vbtick) {
|
|
1810 if (dat & 0x0f)
|
|
1811 a->vibdepth = dat & 0xf;
|
|
1812 if (dat & 0xf0)
|
|
1813 a->vibspd = (dat & 0xf0) >> 2;
|
|
1814 }
|
|
1815 DoVibrato();
|
|
1816 a->ownper = 1;
|
|
1817 break;
|
|
1818
|
|
1819 case UNI_XMEFFECTA:
|
|
1820 DoXMVolSlide(UniGetByte());
|
|
1821 break;
|
|
1822
|
|
1823 case UNI_XMEFFECTE1: /* xm fineslide up */
|
|
1824 dat = UniGetByte();
|
|
1825 if (!pf->vbtick) {
|
|
1826 if (dat)
|
|
1827 a->fportupspd = dat;
|
|
1828 else
|
|
1829 dat = a->fportupspd;
|
|
1830 a->tmpperiod -= (dat << 2);
|
|
1831 }
|
|
1832 break;
|
|
1833
|
|
1834 case UNI_XMEFFECTE2: /* xm fineslide dn */
|
|
1835 dat = UniGetByte();
|
|
1836 if (!pf->vbtick) {
|
|
1837 if (dat)
|
|
1838 a->fportdnspd = dat;
|
|
1839 else
|
|
1840 dat = a->fportdnspd;
|
|
1841 a->tmpperiod += (dat << 2);
|
|
1842 }
|
|
1843 break;
|
|
1844
|
|
1845 case UNI_XMEFFECTEA: /* fine volume slide up */
|
|
1846 dat = UniGetByte();
|
|
1847 if (pf->vbtick)
|
|
1848 break;
|
|
1849 if (dat)
|
|
1850 a->fslideupspd = dat;
|
|
1851 else
|
|
1852 dat = a->fslideupspd;
|
|
1853 a->tmpvolume += dat;
|
|
1854 if (a->tmpvolume > 64)
|
|
1855 a->tmpvolume = 64;
|
|
1856 break;
|
|
1857
|
|
1858 case UNI_XMEFFECTEB: /* fine volume slide dn */
|
|
1859 dat = UniGetByte();
|
|
1860 if (pf->vbtick)
|
|
1861 break;
|
|
1862 if (dat)
|
|
1863 a->fslidednspd = dat;
|
|
1864 else
|
|
1865 dat = a->fslidednspd;
|
|
1866 a->tmpvolume -= dat;
|
|
1867 if (a->tmpvolume < 0)
|
|
1868 a->tmpvolume = 0;
|
|
1869 break;
|
|
1870
|
|
1871 case UNI_XMEFFECTG:
|
|
1872 pf->volume = UniGetByte();
|
|
1873 break;
|
|
1874
|
|
1875 case UNI_XMEFFECTH:
|
|
1876 DoXMGlobalSlide(UniGetByte());
|
|
1877 break;
|
|
1878
|
|
1879 case UNI_XMEFFECTL:
|
|
1880 dat = UniGetByte();
|
|
1881 if (!pf->vbtick && a->i != NULL) {
|
|
1882 UWORD points;
|
|
1883 INSTRUMENT *i = a->i;
|
|
1884 MP_VOICE *aout;
|
|
1885
|
|
1886 if ((aout = a->slave) != NULL) {
|
|
1887 points = i->volenv[i->volpts - 1].pos;
|
|
1888 aout->venv.p = aout->venv.env[(dat > points) ? points : dat].pos;
|
|
1889
|
|
1890 points = i->panenv[i->panpts - 1].pos;
|
|
1891 aout->penv.p = aout->penv.env[(dat > points) ? points : dat].pos;
|
|
1892 }
|
|
1893 }
|
|
1894 break;
|
|
1895
|
|
1896 case UNI_XMEFFECTP:
|
|
1897 DoXMPanSlide(UniGetByte());
|
|
1898 break;
|
|
1899
|
|
1900 case UNI_XMEFFECTX1:
|
|
1901 DoXMExtraFineSlideUp(UniGetByte());
|
|
1902 a->ownper = 1;
|
|
1903 break;
|
|
1904
|
|
1905 case UNI_XMEFFECTX2:
|
|
1906 DoXMExtraFineSlideDown(UniGetByte());
|
|
1907 a->ownper = 1;
|
|
1908 break;
|
|
1909
|
|
1910 case UNI_ITEFFECTG:
|
|
1911 dat = UniGetByte();
|
|
1912 if (dat != 0)
|
|
1913 a->slidespeed = dat;
|
|
1914
|
|
1915 if (a->period != 0) {
|
|
1916 if ((pf->vbtick < 1) && (a->newsamp)) {
|
|
1917 a->kick = 1;
|
|
1918 a->start = -1;
|
|
1919 /* a->period *= a->speed * a->newsamp; */
|
|
1920 } else
|
|
1921 a->kick = 0;
|
|
1922
|
|
1923 DoITToneSlide();
|
|
1924 a->ownper = 1;
|
|
1925 }
|
|
1926 break;
|
|
1927
|
|
1928 case UNI_ITEFFECTH: /* it vibrato */
|
|
1929 dat = UniGetByte();
|
|
1930 if (dat & 0x0f)
|
|
1931 a->vibdepth = dat & 0xf;
|
|
1932 if (dat & 0xf0)
|
|
1933 a->vibspd = (dat & 0xf0) >> 2;
|
|
1934 DoITVibrato();
|
|
1935 a->ownper = 1;
|
|
1936 break;
|
|
1937
|
|
1938 case UNI_ITEFFECTI: /* it tremor */
|
|
1939 DoITTremor(UniGetByte());
|
|
1940 a->ownvol = 1;
|
|
1941 break;
|
|
1942
|
|
1943 case UNI_ITEFFECTM:
|
|
1944 a->chanvol = UniGetByte();
|
|
1945 if (a->chanvol > 64)
|
|
1946 a->chanvol = 64;
|
|
1947 else if (a->chanvol < 0)
|
|
1948 a->chanvol = 0;
|
|
1949 break;
|
|
1950
|
|
1951 case UNI_ITEFFECTN: /* Slide / Fineslide Channel Volume */
|
|
1952 DoITChanVolSlide(UniGetByte());
|
|
1953 break;
|
|
1954
|
|
1955 case UNI_ITEFFECTP: /* slide / fineslide channel panning */
|
|
1956 DoITPanSlide(UniGetByte());
|
|
1957 break;
|
|
1958
|
|
1959 case UNI_ITEFFECTU: /* fine vibrato */
|
|
1960 dat = UniGetByte();
|
|
1961 if (dat & 0x0f)
|
|
1962 a->vibdepth = dat & 0xf;
|
|
1963 if (dat & 0xf0)
|
|
1964 a->vibspd = (dat & 0xf0) >> 2;
|
|
1965 DoITFineVibrato();
|
|
1966 a->ownper = 1;
|
|
1967 break;
|
|
1968
|
|
1969 case UNI_ITEFFECTW: /* Slide / Fineslide Global volume */
|
|
1970 DoITGlobalSlide(UniGetByte());
|
|
1971 break;
|
|
1972
|
|
1973 case UNI_ITEFFECTY: /* The Satanic Panbrello */
|
|
1974 dat = UniGetByte();
|
|
1975 if (dat & 0x0f)
|
|
1976 a->panbdepth = (dat & 0xf);
|
|
1977 if (dat & 0xf0)
|
|
1978 a->panbspd = (dat & 0xf0) >> 4;
|
|
1979 DoITPanbrello();
|
|
1980 break;
|
|
1981
|
|
1982 case UNI_ITEFFECTS0:
|
|
1983 DoSSEffects(UniGetByte());
|
|
1984 break;
|
|
1985
|
|
1986 default:
|
|
1987 UniSkipOpcode(c);
|
|
1988 break;
|
|
1989 }
|
|
1990 }
|
|
1991
|
|
1992
|
|
1993 static void
|
|
1994 DoNNAEffects(UBYTE dat)
|
|
1995 {
|
|
1996 int t;
|
|
1997 MP_VOICE *aout;
|
|
1998
|
|
1999 dat &= 0xf;
|
|
2000 aout = (a->slave == NULL) ? &aout_dummy : a->slave;
|
|
2001
|
|
2002 switch (dat) {
|
|
2003 case 0x0: /* Past note cut */
|
|
2004 for (t = 0; t < md_sngchn; t++)
|
|
2005 if (pf->voice[t].master == a)
|
|
2006 pf->voice[t].fadevol = 0;
|
|
2007 break;
|
|
2008
|
|
2009 case 0x1: /* Past note off */
|
|
2010 for (t = 0; t < md_sngchn; t++)
|
|
2011 if (pf->voice[t].master == a) {
|
|
2012 pf->voice[t].keyoff |= KEY_OFF;
|
|
2013 if (!(pf->voice[t].venv.flg & EF_ON))
|
|
2014 pf->voice[t].keyoff = KEY_KILL;
|
|
2015 }
|
|
2016 break;
|
|
2017
|
|
2018 case 0x2: /* Past note fade */
|
|
2019 for (t = 0; t < md_sngchn; t++)
|
|
2020 if (pf->voice[t].master == a)
|
|
2021 pf->voice[t].keyoff |= KEY_FADE;
|
|
2022 break;
|
|
2023
|
|
2024 case 0x3: /* set NNA note cut */
|
|
2025 a->nna = (a->nna & ~0x3f) | NNA_CUT;
|
|
2026 break;
|
|
2027
|
|
2028 case 0x4: /* set NNA note continue */
|
|
2029 a->nna = (a->nna & ~0x3f) | NNA_CONTINUE;
|
|
2030 break;
|
|
2031
|
|
2032 case 0x5: /* set NNA note off */
|
|
2033 a->nna = (a->nna & ~0x3f) | NNA_OFF;
|
|
2034 break;
|
|
2035
|
|
2036 case 0x6: /* set NNA note fade */
|
|
2037 a->nna = (a->nna & ~0x3f) | NNA_FADE;
|
|
2038 break;
|
|
2039
|
|
2040 case 0x7: /* disable volume envelope */
|
|
2041 aout->volflg &= ~EF_ON;
|
|
2042 break;
|
|
2043
|
|
2044 case 0x8: /* enable volume envelope */
|
|
2045 aout->volflg |= EF_ON;
|
|
2046 break;
|
|
2047
|
|
2048 case 0x9: /* disable panning envelope */
|
|
2049 aout->panflg &= ~EF_ON;
|
|
2050 break;
|
|
2051
|
|
2052 case 0xa: /* enable panning envelope */
|
|
2053 aout->panflg |= EF_ON;
|
|
2054 break;
|
|
2055
|
|
2056 case 0xb: /* disable pitch envelope */
|
|
2057 aout->pitflg &= ~EF_ON;
|
|
2058 break;
|
|
2059
|
|
2060 case 0xc: /* enable pitch envelope */
|
|
2061 aout->pitflg |= EF_ON;
|
|
2062 break;
|
|
2063 }
|
|
2064 }
|
|
2065
|
|
2066
|
|
2067 void
|
|
2068 Player_HandleTick(void)
|
|
2069 {
|
|
2070 MP_VOICE *aout; /* current audout (slave of audtmp) it's
|
|
2071 * working on */
|
|
2072 int t, tr, t2, k;
|
|
2073 ULONG tmpvol, period;
|
|
2074 UBYTE c;
|
|
2075 BOOL funky;
|
|
2076 SAMPLE *s;
|
|
2077 INSTRUMENT *i;
|
|
2078
|
|
2079 if (isfirst) { /* don't handle the very first ticks, this
|
|
2080 * allows the other hardware to settle down
|
|
2081 * so we don't loose any starting notes */
|
|
2082 isfirst--;
|
|
2083 return;
|
|
2084 }
|
|
2085 if (pf == NULL || pf->forbid)
|
|
2086 return;
|
|
2087
|
|
2088 if (++pf->vbtick >= pf->sngspd) {
|
|
2089 pf->patpos++;
|
|
2090 pf->vbtick = 0;
|
|
2091
|
|
2092 /*
|
|
2093 * process pattern-delay. pf->patdly2 is the counter and pf->patdly
|
|
2094 * is the command memory.
|
|
2095 */
|
|
2096
|
|
2097 if (pf->patdly) {
|
|
2098 pf->patdly2 = pf->patdly;
|
|
2099 pf->patdly = 0;
|
|
2100 }
|
|
2101 if (pf->patdly2) { /* patterndelay active */
|
|
2102 if (--pf->patdly2)
|
|
2103 pf->patpos--; /* so turn back pf->patpos by 1 */
|
|
2104 }
|
|
2105 /*
|
|
2106 * Do we have to get a new patternpointer ? (when pf->patpos reaches
|
|
2107 * 64 or when a patternbreak is active)
|
|
2108 */
|
|
2109
|
|
2110 if (pf->patpos == pf->numrow)
|
|
2111 pf->posjmp = 3;
|
|
2112
|
|
2113 if (pf->posjmp) {
|
|
2114 pf->patpos = pf->patbrk;
|
|
2115 pf->sngpos += (pf->posjmp - 2);
|
|
2116 pf->patbrk = pf->posjmp = 0;
|
|
2117 if (pf->sngpos >= pf->numpos) {
|
|
2118 if (!pf->loop)
|
|
2119 return;
|
|
2120 if ((pf->sngpos = pf->reppos) == 0) {
|
|
2121 pf->volume = pf->initvolume;
|
|
2122 pf->sngspd = pf->initspeed;
|
|
2123 pf->bpm = pf->inittempo;
|
|
2124 }
|
|
2125 }
|
|
2126 if (pf->sngpos < 0)
|
|
2127 pf->sngpos = pf->numpos - 1;
|
|
2128 }
|
|
2129 if (!pf->patdly2) {
|
|
2130 for (t = 0; t < pf->numchn; t++) {
|
|
2131 UBYTE inst;
|
|
2132
|
|
2133 tr = pf->patterns[(pf->positions[pf->sngpos] * pf->numchn) + t];
|
|
2134 pf->numrow = pf->pattrows[pf->positions[pf->sngpos]];
|
|
2135
|
|
2136 mp_channel = t;
|
|
2137 a = &pf->control[t];
|
|
2138 a->row = (tr < pf->numtrk) ? UniFindRow(pf->tracks[tr], pf->patpos) : NULL;
|
|
2139 a->newsamp = 0;
|
|
2140
|
|
2141 if (a->row == NULL)
|
|
2142 continue;
|
|
2143 UniSetRow(a->row);
|
|
2144 funky = 0; /* Funky is set to indicate note or inst
|
|
2145 * change */
|
|
2146
|
|
2147 while (c = UniGetByte()) {
|
|
2148 switch (c) {
|
|
2149 case UNI_NOTE:
|
|
2150 funky |= 1;
|
|
2151 a->anote = UniGetByte();
|
|
2152 a->kick = 1;
|
|
2153 a->start = -1;
|
|
2154
|
|
2155 /* retrig tremolo and vibrato waves ? */
|
|
2156
|
|
2157 if (!(a->wavecontrol & 0x80))
|
|
2158 a->trmpos = 0;
|
|
2159 if (!(a->wavecontrol & 0x08))
|
|
2160 a->vibpos = 0;
|
|
2161 if (!a->panbwave)
|
|
2162 a->panbpos = 0;
|
|
2163 break;
|
|
2164
|
|
2165 case UNI_INSTRUMENT:
|
|
2166 funky |= 2;
|
|
2167 inst = UniGetByte();
|
|
2168 if (inst >= pf->numins)
|
|
2169 break; /* <- safety valve */
|
|
2170
|
|
2171 a->i = (pf->flags & UF_INST) ? &pf->instruments[inst] : NULL;
|
|
2172 a->retrig = 0;
|
|
2173 a->s3mtremor = 0;
|
|
2174 a->sample = inst;
|
|
2175 break;
|
|
2176
|
|
2177 default:
|
|
2178 UniSkipOpcode(c);
|
|
2179 break;
|
|
2180 }
|
|
2181 }
|
|
2182
|
|
2183 if (funky) {
|
|
2184 i = a->i;
|
|
2185 if (i != NULL) {
|
|
2186 if (i->samplenumber[a->anote] >= pf->numsmp)
|
|
2187 continue;
|
|
2188 s = &pf->samples[i->samplenumber[a->anote]];
|
|
2189 a->note = i->samplenote[a->anote];
|
|
2190 } else {
|
|
2191 a->note = a->anote;
|
|
2192 s = &pf->samples[a->sample];
|
|
2193 }
|
|
2194
|
|
2195 if (a->s != s) {
|
|
2196 a->s = s;
|
|
2197 a->newsamp = a->period;
|
|
2198 }
|
|
2199 /* channel or instrument determined panning ? */
|
|
2200
|
|
2201 a->panning = pf->panning[t];
|
|
2202 if (s->flags & SF_OWNPAN)
|
|
2203 a->panning = s->panning;
|
|
2204 else if ((i != NULL) && (i->flags & IF_OWNPAN))
|
|
2205 a->panning = i->panning;
|
|
2206
|
|
2207 a->handle = s->handle;
|
|
2208 a->speed = s->speed;
|
|
2209
|
|
2210 if (i != NULL) {
|
|
2211 if (i->flags & IF_PITCHPAN)
|
|
2212 a->panning += ((a->anote - i->pitpancenter) * i->pitpansep) / 8;
|
|
2213 a->pitflg = i->pitflg;
|
|
2214 a->volflg = i->volflg;
|
|
2215 a->panflg = i->panflg;
|
|
2216 a->nna = i->nnatype;
|
|
2217 a->dca = i->dca;
|
|
2218 a->dct = i->dct;
|
|
2219 } else {
|
|
2220 a->pitflg = 0;
|
|
2221 a->volflg = 0;
|
|
2222 a->panflg = 0;
|
|
2223 a->nna = 0;
|
|
2224 a->dca = 0;
|
|
2225 a->dct = 0;
|
|
2226 }
|
|
2227
|
|
2228 if (funky & 2) { /* IT's random volume variations: 0:8
|
|
2229 * bit fixed, and one bit for sign. */
|
|
2230 a->volume = s->volume;
|
|
2231 a->tmpvolume = s->volume;
|
|
2232 if ((s != NULL) && (i != NULL)) {
|
|
2233 a->volume = a->tmpvolume = s->volume + ((s->volume * ((SLONG) i->rvolvar * (SLONG) ((rand() & 511) - 255))) / 25600);
|
|
2234 if (a->panning != PAN_SURROUND)
|
|
2235 a->panning += ((a->panning * ((SLONG) i->rpanvar * (SLONG) ((rand() & 511) - 255))) / 25600);
|
|
2236 }
|
|
2237 }
|
|
2238 period = GetPeriod(a->note, a->speed);
|
|
2239 a->wantedperiod = period;
|
|
2240 a->tmpperiod = period;
|
|
2241 a->keyoff = KEY_KICK;
|
|
2242 }
|
|
2243 }
|
|
2244 }
|
|
2245 }
|
|
2246 /* Update effects */
|
|
2247
|
|
2248 for (t = 0; t < pf->numchn; t++) {
|
|
2249 mp_channel = t;
|
|
2250 a = &pf->control[t];
|
|
2251
|
|
2252 if ((aout = a->slave) != NULL) {
|
|
2253 a->fadevol = aout->fadevol;
|
|
2254 a->period = aout->period;
|
|
2255 if (a->kick != 1)
|
|
2256 a->keyoff = aout->keyoff;
|
|
2257 }
|
|
2258 if (a->row == NULL)
|
|
2259 continue;
|
|
2260 UniSetRow(a->row);
|
|
2261
|
|
2262 a->ownper = a->ownvol = 0;
|
|
2263 pt_playeffects();
|
|
2264 if (!a->ownper)
|
|
2265 a->period = a->tmpperiod;
|
|
2266 if (!a->ownvol)
|
|
2267 a->volume = a->tmpvolume;
|
|
2268
|
|
2269 if (a->s != NULL) {
|
|
2270 if (a->i != NULL)
|
|
2271 a->outvolume = (a->volume * a->s->globvol * a->i->globvol) / 1024; /* max val: 256 */
|
|
2272 else
|
|
2273 a->outvolume = (a->volume * a->s->globvol) / 16; /* max val: 256 */
|
|
2274 if (a->outvolume > 256)
|
|
2275 a->volume = 256;
|
|
2276 }
|
|
2277 }
|
|
2278
|
|
2279
|
|
2280 a = pf->control;
|
|
2281 if (pf->flags & UF_NNA) {
|
|
2282 for (t = 0; t < pf->numchn; t++, a++) {
|
|
2283 if (a->kick == 1) {
|
|
2284 if (a->slave != NULL) {
|
|
2285 aout = a->slave;
|
|
2286 if (aout->nna & 0x3f) { /* oh boy, we have to do an
|
|
2287 * NNA Make sure the old
|
|
2288 * MP_VOICE channel knows it
|
|
2289 * has no master now! */
|
|
2290
|
|
2291 a->slave = NULL; /* assume the channel is
|
|
2292 * taken by NNA */
|
|
2293 aout->mflag = 0;
|
|
2294
|
|
2295 switch (aout->nna) {
|
|
2296 case NNA_CONTINUE:
|
|
2297 break; /* continue note, do nothing */
|
|
2298
|
|
2299 case NNA_OFF: /* note off */
|
|
2300 aout->keyoff |= KEY_OFF;
|
|
2301 if (!(aout->volflg & EF_ON) || (aout->volflg & EF_LOOP))
|
|
2302 aout->keyoff = KEY_KILL;
|
|
2303 break;
|
|
2304
|
|
2305 case NNA_FADE:
|
|
2306 aout->keyoff |= KEY_FADE;
|
|
2307 break;
|
|
2308 }
|
|
2309 }
|
|
2310 }
|
|
2311 k = 0;
|
|
2312 if (a->dct != DCT_OFF) {
|
|
2313 for (t2 = 0; t2 < md_sngchn; t2++) {
|
|
2314 if (!(Voice_Stopped(t2)) && (pf->voice[t2].masterchn == t) && (a->sample == pf->voice[t2].sample)) {
|
|
2315 switch (a->dct) {
|
|
2316 case DCT_NOTE:
|
|
2317 if (a->note == pf->voice[t2].note)
|
|
2318 k = 1;
|
|
2319 break;
|
|
2320
|
|
2321 case DCT_SAMPLE:
|
|
2322 if (a->handle == pf->voice[t2].handle)
|
|
2323 k = 1;
|
|
2324 break;
|
|
2325
|
|
2326 case DCT_INST:
|
|
2327 k = 1;
|
|
2328 break;
|
|
2329 }
|
|
2330
|
|
2331 if (k == 1) {
|
|
2332 k = 0;
|
|
2333 switch (a->dca) {
|
|
2334 case DCA_CUT:
|
|
2335 pf->voice[t2].fadevol = 0;
|
|
2336 a->slave = &pf->voice[a->slavechn = t2];
|
|
2337 break;
|
|
2338
|
|
2339 case DCA_OFF:
|
|
2340 /* a->slave = &pf->voice[newchn]; */
|
|
2341 pf->voice[t2].keyoff |= KEY_OFF;
|
|
2342 if (!(pf->voice[t2].volflg & EF_ON) || (pf->voice[t2].volflg & EF_LOOP))
|
|
2343 pf->voice[t2].keyoff = KEY_KILL;
|
|
2344 break;
|
|
2345
|
|
2346 case DCA_FADE:
|
|
2347 /* a->slave = &pf->voice[newchn]; */
|
|
2348 pf->voice[t2].keyoff |= KEY_FADE;
|
|
2349 break;
|
|
2350 }
|
|
2351 }
|
|
2352 }
|
|
2353 }
|
|
2354 } /* DCT checking */
|
|
2355 } /* if a->kick */
|
|
2356 } /* for loop */
|
|
2357 }
|
|
2358 a = pf->control;
|
|
2359 for (t = 0; t < pf->numchn; t++, a++) {
|
|
2360 int newchn;
|
|
2361
|
|
2362 if (a->notedelay)
|
|
2363 continue;
|
|
2364
|
|
2365 if (a->kick == 1) { /* If no channel was cut above, find an empty
|
|
2366 * or quiet channel here */
|
|
2367 if (pf->flags & UF_NNA) {
|
|
2368 if (a->slave == NULL) {
|
|
2369 if ((newchn = MP_FindEmptyChannel(t)) != -1)
|
|
2370 a->slave = &pf->voice[a->slavechn = newchn];
|
|
2371 }
|
|
2372 } else
|
|
2373 a->slave = &pf->voice[a->slavechn = t];
|
|
2374
|
|
2375 /* Assign parts of MP_VOICE only done for a KICK! */
|
|
2376
|
|
2377 if ((aout = a->slave) != NULL) {
|
|
2378 if (aout->mflag && (aout->master != NULL))
|
|
2379 aout->master->slave = NULL;
|
|
2380 a->slave = aout;
|
|
2381 aout->master = a;
|
|
2382 aout->masterchn = t;
|
|
2383 aout->mflag = 1;
|
|
2384 }
|
|
2385 } else {
|
|
2386 aout = a->slave;
|
|
2387 }
|
|
2388
|
|
2389 if (aout != NULL) {
|
|
2390 aout->kick = a->kick;
|
|
2391 aout->i = a->i;
|
|
2392 aout->s = a->s;
|
|
2393 aout->sample = a->sample;
|
|
2394 aout->handle = a->handle;
|
|
2395 aout->period = a->period;
|
|
2396 aout->panning = a->panning;
|
|
2397 aout->chanvol = a->chanvol;
|
|
2398 aout->fadevol = a->fadevol;
|
|
2399 aout->start = a->start;
|
|
2400 aout->volflg = a->volflg;
|
|
2401 aout->panflg = a->panflg;
|
|
2402 aout->pitflg = a->pitflg;
|
|
2403 aout->volume = a->outvolume;
|
|
2404 aout->keyoff = a->keyoff;
|
|
2405 aout->note = a->note;
|
|
2406 aout->nna = a->nna;
|
|
2407 }
|
|
2408 a->kick = 0;
|
|
2409
|
|
2410 }
|
|
2411
|
|
2412 /* Now set up the actual hardware channel playback information */
|
|
2413
|
|
2414 for (t = 0; t < md_sngchn; t++) {
|
|
2415 SWORD envpan, envvol = 256, envpit = 0;
|
|
2416 SLONG vibval, vibdpt;
|
|
2417
|
|
2418 aout = &pf->voice[mp_channel = t];
|
|
2419 i = aout->i;
|
|
2420 s = aout->s;
|
|
2421
|
|
2422 if (s == NULL)
|
|
2423 continue;
|
|
2424
|
|
2425 if (aout->period < 40)
|
|
2426 aout->period = 40;
|
|
2427 if (aout->period > 50000)
|
|
2428 aout->period = 50000;
|
|
2429
|
|
2430 if (aout->kick) {
|
|
2431 Voice_Play(t, s, (aout->start == -1) ? ((s->flags & SF_UST_LOOP) ? s->loopstart : 0) : aout->start);
|
|
2432 /* aout->keyoff = KEY_KICK; */
|
|
2433 aout->fadevol = 32768;
|
|
2434 aout->aswppos = 0;
|
|
2435
|
|
2436 if ((i != NULL) && (aout->kick != 2)) {
|
|
2437 StartEnvelope(&aout->venv, aout->volflg, i->volpts, i->volsusbeg, i->volsusend, i->volbeg, i->volend, i->volenv, aout->keyoff);
|
|
2438 StartEnvelope(&aout->penv, aout->panflg, i->panpts, i->pansusbeg, i->pansusend, i->panbeg, i->panend, i->panenv, aout->keyoff);
|
|
2439 StartEnvelope(&aout->cenv, aout->pitflg, i->pitpts, i->pitsusbeg, i->pitsusend, i->pitbeg, i->pitend, i->pitenv, aout->keyoff);
|
|
2440 }
|
|
2441 aout->kick = 0;
|
|
2442 }
|
|
2443 if (i != NULL) {
|
|
2444 envvol = ProcessEnvelope(&aout->venv, 256, aout->keyoff);
|
|
2445 envpan = ProcessEnvelope(&aout->penv, 128, aout->keyoff);
|
|
2446 envpit = ProcessEnvelope(&aout->cenv, 32, aout->keyoff);
|
|
2447 }
|
|
2448 tmpvol = aout->fadevol; /* max 32768 */
|
|
2449 tmpvol *= aout->chanvol;/* * max 64 */
|
|
2450 tmpvol *= aout->volume; /* * max 256 */
|
|
2451 tmpvol /= 16384L; /* tmpvol is max 32768 */
|
|
2452 aout->totalvol = tmpvol >> 2; /* totalvolume used to determine
|
|
2453 * samplevolume */
|
|
2454 tmpvol *= envvol; /* * max 256 */
|
|
2455 tmpvol *= pf->volume; /* * max 128 */
|
17
|
2456 tmpvol /= 4194304;
|
12
|
2457
|
|
2458 if ((aout->masterchn != -1) && pf->control[aout->masterchn].muted) /* Channel Muting Line */
|
|
2459 Voice_SetVolume(t, 0);
|
|
2460 else
|
|
2461 Voice_SetVolume(t, tmpvol);
|
|
2462
|
|
2463
|
|
2464 if (aout->panning == PAN_SURROUND)
|
|
2465 Voice_SetPanning(t, PAN_SURROUND);
|
|
2466 else {
|
|
2467 if (aout->penv.flg & EF_ON)
|
|
2468 Voice_SetPanning(t, DoPan(envpan, aout->panning));
|
|
2469 else
|
|
2470 Voice_SetPanning(t, aout->panning);
|
|
2471 }
|
|
2472
|
|
2473 if (aout->period && s->vibdepth) {
|
|
2474 switch (s->vibtype) {
|
|
2475 case 0:
|
|
2476 vibval = avibtab[s->avibpos & 127];
|
|
2477 if (s->avibpos & 0x80)
|
|
2478 vibval = -vibval;
|
|
2479 break;
|
|
2480
|
|
2481 case 1:
|
|
2482 vibval = 64;
|
|
2483 if (s->avibpos & 0x80)
|
|
2484 vibval = -vibval;
|
|
2485 break;
|
|
2486
|
|
2487 case 2:
|
|
2488 vibval = 63 - (((s->avibpos + 128) & 255) >> 1);
|
|
2489 break;
|
|
2490
|
|
2491 case 3:
|
|
2492 vibval = (((s->avibpos + 128) & 255) >> 1) - 64;
|
|
2493 break;
|
|
2494 }
|
|
2495 }
|
|
2496 if (s->vibflags & AV_IT) {
|
|
2497 if ((aout->aswppos >> 8) < s->vibdepth) {
|
|
2498 aout->aswppos += s->vibsweep;
|
|
2499 vibdpt = aout->aswppos;
|
|
2500 } else
|
|
2501 vibdpt = s->vibdepth << 8;
|
|
2502 vibval = (vibval * vibdpt) >> 16;
|
|
2503 if (aout->mflag) {
|
|
2504 if (!(pf->flags & UF_LINEAR))
|
|
2505 vibval >>= 1;
|
|
2506 aout->period -= vibval;
|
|
2507 }
|
|
2508 } else { /* do XM style auto-vibrato */
|
|
2509 if (!(aout->keyoff & KEY_OFF)) {
|
|
2510 if (aout->aswppos < s->vibsweep) {
|
|
2511 vibdpt = (aout->aswppos * s->vibdepth) / s->vibsweep;
|
|
2512 aout->aswppos++;
|
|
2513 } else
|
|
2514 vibdpt = s->vibdepth;
|
|
2515 } else {
|
|
2516 /*
|
|
2517 * key-off -> depth becomes 0 if final depth wasn't reached
|
|
2518 * or stays at final level if depth WAS reached
|
|
2519 */
|
|
2520 if (aout->aswppos >= s->vibsweep)
|
|
2521 vibdpt = s->vibdepth;
|
|
2522 else
|
|
2523 vibdpt = 0;
|
|
2524 }
|
|
2525 vibval = (vibval * vibdpt) >> 8;
|
|
2526 aout->period -= vibval;
|
|
2527 }
|
|
2528
|
|
2529 /* update vibrato position */
|
|
2530 s->avibpos = (s->avibpos + s->vibrate) & 0xff;
|
|
2531
|
|
2532 if (aout->cenv.flg & EF_ON) {
|
|
2533 envpit = envpit - 32;
|
|
2534 aout->period -= envpit;
|
|
2535 }
|
|
2536 Voice_SetFrequency(t, getfrequency(pf->flags, aout->period));
|
|
2537
|
|
2538 if (aout->fadevol == 0) /* check for a dead note (fadevol = 0) */
|
|
2539 Voice_Stop(t);
|
|
2540 else { /* if keyfade, start substracting
|
|
2541 * fadeoutspeed from fadevol: */
|
|
2542
|
|
2543 if ((i != NULL) && (aout->keyoff & KEY_FADE)) {
|
|
2544 if (aout->fadevol >= i->volfade)
|
|
2545 aout->fadevol -= i->volfade;
|
|
2546 else
|
|
2547 aout->fadevol = 0;
|
|
2548 }
|
|
2549 }
|
|
2550
|
|
2551 MD_SetBPM(pf->bpm);
|
|
2552 }
|
|
2553 }
|
|
2554
|
|
2555
|
|
2556 BOOL
|
|
2557 Player_Init(UNIMOD * mf)
|
|
2558 {
|
|
2559 int t;
|
|
2560
|
|
2561 mf->extspd = 1;
|
|
2562 mf->panflag = 1;
|
|
2563 mf->loop = 0;
|
|
2564
|
|
2565 mf->pat_reppos = 0;
|
|
2566 mf->pat_repcnt = 0;
|
|
2567 mf->sngpos = 0;
|
|
2568 mf->sngspd = mf->initspeed;
|
|
2569 mf->volume = mf->initvolume;
|
|
2570
|
|
2571 mf->vbtick = mf->sngspd;
|
|
2572 mf->patdly = 0;
|
|
2573 mf->patdly2 = 0;
|
|
2574 mf->bpm = mf->inittempo;
|
|
2575
|
|
2576 mf->patpos = 0;
|
|
2577 mf->posjmp = 2; /* <- make sure the player fetches the first
|
|
2578 * note */
|
|
2579 mf->patbrk = 0;
|
|
2580
|
|
2581 /* Make sure the player doesn't start with garbage: */
|
|
2582
|
|
2583 if ((mf->control = (MP_CONTROL *) _mm_calloc(mf->numchn, sizeof(MP_CONTROL))) == NULL)
|
|
2584 return 1;
|
|
2585 if ((mf->voice = (MP_VOICE *) _mm_calloc(md_sngchn, sizeof(MP_VOICE))) == NULL)
|
|
2586 return 1;
|
|
2587
|
|
2588 for (t = 0; t < mf->numchn; t++) {
|
|
2589 mf->control[t].chanvol = mf->chanvol[t];
|
|
2590 mf->control[t].panning = mf->panning[t];
|
|
2591 }
|
|
2592
|
|
2593 return 0;
|
|
2594 }
|
|
2595
|
|
2596
|
|
2597 void
|
|
2598 Player_Exit(UNIMOD * mf)
|
|
2599 {
|
|
2600 if (mf == NULL)
|
|
2601 return;
|
|
2602 if (mf == pf) {
|
|
2603 Player_Stop();
|
|
2604 pf = NULL;
|
|
2605 }
|
|
2606 if (mf->control != NULL)
|
|
2607 free(mf->control);
|
|
2608 if (mf->voice != NULL)
|
|
2609 free(mf->voice);
|
|
2610 mf->control = NULL;
|
|
2611 mf->voice = NULL;
|
|
2612
|
|
2613 }
|
|
2614
|
|
2615
|
|
2616 void
|
|
2617 Player_SetVolume(int volume)
|
|
2618 {
|
|
2619 if (pf == NULL)
|
|
2620 return;
|
|
2621
|
|
2622 if (volume > 128)
|
|
2623 volume = 128;
|
|
2624 if (volume < 0)
|
|
2625 volume = 0;
|
|
2626
|
|
2627 pf->volume = volume;
|
|
2628 }
|
|
2629
|
|
2630
|
|
2631 UNIMOD *
|
|
2632 Player_GetUnimod(void)
|
|
2633 {
|
|
2634 return pf;
|
|
2635 }
|
|
2636
|
|
2637
|
|
2638 void
|
|
2639 Player_Start(UNIMOD * mf)
|
|
2640 {
|
|
2641 int t;
|
|
2642
|
|
2643 if (!MikMod_Active()) {
|
|
2644 isfirst = 2;
|
|
2645 MikMod_EnableOutput();
|
|
2646 }
|
|
2647 if (mf == NULL)
|
|
2648 return;
|
|
2649
|
|
2650 mf->forbid = 0;
|
|
2651 if (pf != mf) { /* new song is being started, so completely
|
|
2652 * stop out the old one. */
|
|
2653 if (pf != NULL)
|
|
2654 pf->forbid = 1;
|
|
2655 for (t = 0; t < md_sngchn; t++)
|
|
2656 Voice_Stop(t);
|
|
2657 }
|
|
2658 pf = mf;
|
|
2659 }
|
|
2660
|
|
2661
|
|
2662 void
|
|
2663 Player_Stop(void)
|
|
2664 {
|
|
2665 if (md_sfxchn == 0)
|
|
2666 MikMod_DisableOutput();
|
|
2667 if (pf != NULL)
|
|
2668 pf->forbid = 1;
|
|
2669 pf = NULL;
|
|
2670 }
|
|
2671
|
|
2672
|
|
2673 BOOL
|
|
2674 MP_Playing(UNIMOD * mf)
|
|
2675 {
|
|
2676 if ((mf == NULL) || (mf != pf))
|
|
2677 return 0;
|
|
2678 return (!(mf->sngpos >= mf->numpos));
|
|
2679 }
|
|
2680
|
|
2681
|
|
2682 BOOL
|
|
2683 Player_Active(void)
|
|
2684 {
|
|
2685 if (pf == NULL)
|
|
2686 return 0;
|
|
2687 return (!(pf->sngpos >= pf->numpos));
|
|
2688 }
|
|
2689
|
|
2690
|
|
2691 void
|
|
2692 MP_NextPosition(UNIMOD * mf)
|
|
2693 {
|
|
2694 int t;
|
|
2695
|
|
2696 if (mf == NULL)
|
|
2697 return;
|
|
2698 mf->forbid = 1;
|
|
2699 mf->posjmp = 3;
|
|
2700 mf->patbrk = 0;
|
|
2701 mf->vbtick = mf->sngspd;
|
|
2702
|
|
2703 for (t = 0; t < md_sngchn; t++) {
|
|
2704 Voice_Stop(t);
|
|
2705 mf->voice[t].i = NULL;
|
|
2706 mf->voice[t].s = NULL;
|
|
2707 }
|
|
2708
|
|
2709 for (t = 0; t < mf->numchn; t++) {
|
|
2710 mf->control[t].i = NULL;
|
|
2711 mf->control[t].s = NULL;
|
|
2712 }
|
|
2713 mf->forbid = 0;
|
|
2714 }
|
|
2715
|
|
2716
|
|
2717 void
|
|
2718 Player_NextPosition(void)
|
|
2719 {
|
|
2720 MP_NextPosition(pf);
|
|
2721 }
|
|
2722
|
|
2723
|
|
2724 void
|
|
2725 MP_PrevPosition(UNIMOD * mf)
|
|
2726 {
|
|
2727 int t;
|
|
2728
|
|
2729 if (mf == NULL)
|
|
2730 return;
|
|
2731 mf->forbid = 1;
|
|
2732 mf->posjmp = 1;
|
|
2733 mf->patbrk = 0;
|
|
2734 mf->vbtick = mf->sngspd;
|
|
2735
|
|
2736 for (t = 0; t < md_sngchn; t++) {
|
|
2737 Voice_Stop(t);
|
|
2738 mf->voice[t].i = NULL;
|
|
2739 mf->voice[t].s = NULL;
|
|
2740 }
|
|
2741
|
|
2742 for (t = 0; t < mf->numchn; t++) {
|
|
2743 mf->control[t].i = NULL;
|
|
2744 mf->control[t].s = NULL;
|
|
2745 }
|
|
2746
|
|
2747 mf->forbid = 0;
|
|
2748 }
|
|
2749
|
|
2750
|
|
2751 void
|
|
2752 Player_PrevPosition(void)
|
|
2753 {
|
|
2754 MP_PrevPosition(pf);
|
|
2755 }
|
|
2756
|
|
2757
|
|
2758 void
|
|
2759 MP_SetPosition(UNIMOD * mf, UWORD pos)
|
|
2760 {
|
|
2761 int t;
|
|
2762
|
|
2763 if (mf == NULL)
|
|
2764 return;
|
|
2765 mf->forbid = 1;
|
|
2766 if (pos >= mf->numpos)
|
|
2767 pos = mf->numpos;
|
|
2768 mf->posjmp = 2;
|
|
2769 mf->patbrk = 0;
|
|
2770 mf->sngpos = pos;
|
|
2771 mf->vbtick = mf->sngspd;
|
|
2772
|
|
2773 for (t = 0; t < md_sngchn; t++) {
|
|
2774 Voice_Stop(t);
|
|
2775 mf->voice[t].i = NULL;
|
|
2776 mf->voice[t].s = NULL;
|
|
2777 }
|
|
2778
|
|
2779 for (t = 0; t < mf->numchn; t++) {
|
|
2780 mf->control[t].i = NULL;
|
|
2781 mf->control[t].s = NULL;
|
|
2782 }
|
|
2783
|
|
2784 mf->forbid = 0;
|
|
2785 }
|
|
2786
|
|
2787
|
|
2788 void
|
|
2789 Player_SetPosition(UWORD pos)
|
|
2790 {
|
|
2791 MP_SetPosition(pf, pos);
|
|
2792 }
|
|
2793
|
|
2794
|
|
2795 void
|
|
2796 MP_Unmute(UNIMOD * mf, SLONG arg1,...)
|
|
2797 {
|
|
2798 va_list ap;
|
|
2799 SLONG t, arg2, arg3;
|
|
2800
|
|
2801 va_start(ap, arg1);
|
|
2802
|
|
2803 if (mf != NULL) {
|
|
2804 switch (arg1) {
|
|
2805 case MUTE_INCLUSIVE:
|
|
2806 if ((!(arg2 = va_arg(ap, SLONG))) && (!(arg3 = va_arg(ap, SLONG))) ||
|
|
2807 (arg2 > arg3) || (arg3 >= mf->numchn)) {
|
|
2808 va_end(ap);
|
|
2809 return;
|
|
2810 }
|
|
2811 for (; arg2 < mf->numchn && arg2 <= arg3; arg2++)
|
|
2812 mf->control[arg2].muted = 0;
|
|
2813 break;
|
|
2814
|
|
2815 case MUTE_EXCLUSIVE:
|
|
2816 if ((!(arg2 = va_arg(ap, SLONG))) && (!(arg3 = va_arg(ap, SLONG))) ||
|
|
2817 (arg2 > arg3) || (arg3 >= mf->numchn)) {
|
|
2818 va_end(ap);
|
|
2819 return;
|
|
2820 }
|
|
2821 for (t = 0; t < mf->numchn; t++) {
|
|
2822 if ((t >= arg2) && (t <= arg3))
|
|
2823 continue;
|
|
2824 mf->control[t].muted = 0;
|
|
2825 }
|
|
2826 break;
|
|
2827
|
|
2828 default:
|
|
2829 if (arg1 < mf->numchn)
|
|
2830 mf->control[arg1].muted = 0;
|
|
2831 break;
|
|
2832 }
|
|
2833 }
|
|
2834 va_end(ap);
|
|
2835
|
|
2836 return;
|
|
2837 }
|
|
2838
|
|
2839
|
|
2840 void
|
|
2841 Player_Unmute(SLONG arg1,...)
|
|
2842 {
|
|
2843 va_list argptr;
|
|
2844 MP_Unmute(pf, arg1, argptr);
|
|
2845 va_end(argptr);
|
|
2846 }
|
|
2847
|
|
2848
|
|
2849 void
|
|
2850 MP_Mute(UNIMOD * mf, SLONG arg1,...)
|
|
2851 {
|
|
2852 va_list ap;
|
|
2853 SLONG t, arg2, arg3;
|
|
2854
|
|
2855 va_start(ap, arg1);
|
|
2856
|
|
2857 if (mf != NULL) {
|
|
2858 switch (arg1) {
|
|
2859 case MUTE_INCLUSIVE:
|
|
2860 if ((!(arg2 = va_arg(ap, SLONG))) && (!(arg3 = va_arg(ap, SLONG))) ||
|
|
2861 (arg2 > arg3) || (arg3 >= mf->numchn)) {
|
|
2862 va_end(ap);
|
|
2863 return;
|
|
2864 }
|
|
2865 for (; arg2 < mf->numchn && arg2 <= arg3; arg2++)
|
|
2866 mf->control[arg2].muted = 1;
|
|
2867 break;
|
|
2868
|
|
2869 case MUTE_EXCLUSIVE:
|
|
2870 if ((!(arg2 = va_arg(ap, SLONG))) && (!(arg3 = va_arg(ap, SLONG))) ||
|
|
2871 (arg2 > arg3) || (arg3 >= mf->numchn)) {
|
|
2872 va_end(ap);
|
|
2873 return;
|
|
2874 }
|
|
2875 for (t = 0; t < mf->numchn; t++) {
|
|
2876 if ((t >= arg2) && (t <= arg3))
|
|
2877 continue;
|
|
2878 mf->control[t].muted = 1;
|
|
2879 }
|
|
2880 break;
|
|
2881
|
|
2882 default:
|
|
2883 if (arg1 < mf->numchn)
|
|
2884 mf->control[arg1].muted = 1;
|
|
2885 break;
|
|
2886 }
|
|
2887 }
|
|
2888 va_end(ap);
|
|
2889
|
|
2890 return;
|
|
2891 }
|
|
2892
|
|
2893
|
|
2894 void
|
|
2895 Player_Mute(SLONG arg1,...)
|
|
2896 {
|
|
2897 va_list argptr;
|
|
2898 MP_Mute(pf, arg1, argptr);
|
|
2899 va_end(argptr);
|
|
2900 }
|
|
2901
|
|
2902
|
|
2903 void
|
|
2904 MP_ToggleMute(UNIMOD * mf, SLONG arg1,...)
|
|
2905 {
|
|
2906 va_list ap;
|
|
2907 SLONG arg2, arg3;
|
|
2908 ULONG t;
|
|
2909
|
|
2910 va_start(ap, arg1);
|
|
2911
|
|
2912 if (mf != NULL) {
|
|
2913 switch (arg1) {
|
|
2914 case MUTE_INCLUSIVE:
|
|
2915 if ((!(arg2 = va_arg(ap, SLONG))) && (!(arg3 = va_arg(ap, SLONG))) ||
|
|
2916 (arg2 > arg3) || (arg3 >= mf->numchn)) {
|
|
2917 va_end(ap);
|
|
2918 return;
|
|
2919 }
|
|
2920 for (; arg2 < mf->numchn && arg2 <= arg3; arg2++)
|
|
2921 mf->control[arg2].muted = (mf->control[arg2].muted) ? 0 : 1;
|
|
2922
|
|
2923 break;
|
|
2924
|
|
2925 case MUTE_EXCLUSIVE:
|
|
2926 if ((!(arg2 = va_arg(ap, SLONG))) && (!(arg3 = va_arg(ap, SLONG))) ||
|
|
2927 (arg2 > arg3) || (arg3 >= mf->numchn)) {
|
|
2928 va_end(ap);
|
|
2929 return;
|
|
2930 }
|
|
2931 for (t = 0; t < mf->numchn; t++) {
|
|
2932 if ((t >= arg2) && (t <= arg3))
|
|
2933 continue;
|
|
2934 mf->control[t].muted = (mf->control[t].muted) ? 0 : 1;
|
|
2935 }
|
|
2936 break;
|
|
2937
|
|
2938 default:
|
|
2939 if (arg1 < mf->numchn)
|
|
2940 mf->control[arg1].muted = (mf->control[arg1].muted) ? 0 : 1;
|
|
2941 break;
|
|
2942 }
|
|
2943 }
|
|
2944 va_end(ap);
|
|
2945
|
|
2946 return;
|
|
2947 }
|
|
2948
|
|
2949
|
|
2950 void
|
|
2951 Player_ToggleMute(SLONG arg1,...)
|
|
2952 {
|
|
2953 va_list argptr;
|
|
2954 MP_ToggleMute(pf, arg1, argptr);
|
|
2955 va_end(argptr);
|
|
2956 }
|
|
2957
|
|
2958
|
|
2959 BOOL
|
|
2960 MP_Muted(UNIMOD * mf, int chan)
|
|
2961 {
|
|
2962 if (mf == NULL)
|
|
2963 return 1;
|
|
2964 return (chan < mf->numchn) ? mf->control[chan].muted : 1;
|
|
2965 }
|
|
2966
|
|
2967
|
|
2968 BOOL
|
|
2969 Player_Muted(int chan)
|
|
2970 {
|
|
2971 if (pf == NULL)
|
|
2972 return 1;
|
|
2973 return (chan < pf->numchn) ? pf->control[chan].muted : 1;
|
|
2974 }
|
|
2975
|
|
2976
|
|
2977 int
|
|
2978 MP_GetChannelVoice(UNIMOD * mf, int chan)
|
|
2979 {
|
|
2980 if (mf == NULL)
|
|
2981 return 0;
|
|
2982 return mf->control[chan].slavechn;
|
|
2983 }
|
|
2984
|
|
2985
|
|
2986 int
|
|
2987 Player_GetChannelVoice(int chan)
|
|
2988 {
|
|
2989 if (pf == NULL)
|
|
2990 return 0;
|
|
2991 return pf->control[chan].slavechn;
|
|
2992 }
|
|
2993
|
|
2994
|
|
2995 void
|
|
2996 Player_TogglePause(void)
|
|
2997 {
|
|
2998 if (pf == NULL)
|
|
2999 return;
|
|
3000 if (pf->forbid == 1)
|
|
3001 pf->forbid = 0;
|
|
3002 else
|
|
3003 pf->forbid = 1;
|
|
3004 }
|
|
3005
|
|
3006
|
|
3007 /*
|
|
3008 * --> The following procedures were taken from UNITRK because they -> are
|
|
3009 * ProTracker format specific.
|
|
3010 */
|
|
3011
|
|
3012 /* Appends UNI_INSTRUMENT opcode to the unitrk stream. */
|
|
3013 void
|
|
3014 UniInstrument(UBYTE ins)
|
|
3015 {
|
|
3016 UniWrite(UNI_INSTRUMENT);
|
|
3017 UniWrite(ins);
|
|
3018 }
|
|
3019
|
|
3020 /* Appends UNI_NOTE opcode to the unitrk stream. */
|
|
3021 void
|
|
3022 UniNote(UBYTE note)
|
|
3023 {
|
|
3024 UniWrite(UNI_NOTE);
|
|
3025 UniWrite(note);
|
|
3026 }
|
|
3027
|
|
3028 /* Appends UNI_PTEFFECTX opcode to the unitrk stream. */
|
|
3029 void
|
|
3030 UniPTEffect(UBYTE eff, UBYTE dat)
|
|
3031 {
|
|
3032 if (eff != 0 || dat != 0) { /* don't write empty effect */
|
|
3033 UniWrite(UNI_PTEFFECT0 + eff);
|
|
3034 UniWrite(dat);
|
|
3035 }
|
|
3036 }
|
|
3037
|
|
3038 /* Appends UNI_VOLEFFECT + effect/dat to unistream. */
|
|
3039 void
|
|
3040 UniVolEffect(UWORD eff, UBYTE dat)
|
|
3041 {
|
|
3042 if (eff != 0 || dat != 0) { /* don't write empty effect */
|
|
3043 UniWrite(UNI_VOLEFFECTS);
|
|
3044 UniWrite(eff);
|
|
3045 UniWrite(dat);
|
|
3046 }
|
|
3047 }
|