comparison playercode/mplayer.c @ 12:437e8455d862

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