| 1 | /* |
| 2 | * OpenTyrian: A modern cross-platform port of Tyrian |
| 3 | * Copyright (C) 2007-2009 The OpenTyrian Development Team |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation; either version 2 |
| 8 | * of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 18 | */ |
| 19 | #include "lds_play.h"cxx . . $ `<file>/src/lds_play.h`/ |
| 20 | |
| 21 | #include "file.h"cxx . . $ `<file>/src/file.h`/ |
| 22 | #include "loudness.h"cxx . . $ `<file>/src/loudness.h`/ |
| 23 | #include "opentyr.h"cxx . . $ `<file>/src/opentyr.h`/ |
| 24 | |
| 25 | #include <assert.h> |
| 26 | #include <string.h> |
| 27 | #include <stdlib.h> |
| 28 | |
| 29 | const unsigned char op_tablecxx . . $ op_table.[9] = {0x00, 0x01, 0x02, 0x08, 0x09, 0x0a, 0x10, 0x11, 0x12}; |
| 30 | |
| 31 | /* A substantial amount of this code has been copied and adapted from adplug. |
| 32 | Thanks, guys! Adplug is awesome! :D */ |
| 33 | |
| 34 | /* Note frequency table (16 notes / octave) */ |
| 35 | static const Uint16cxx . . $ Uint16# frequencycxx . . $ frequency.[(13 * 15) - 3] = { |
| 36 | 343, 344, 345, 347, 348, 349, 350, 352, 353, 354, 356, 357, 358, |
| 37 | 359, 361, 362, 363, 365, 366, 367, 369, 370, 371, 373, 374, 375, |
| 38 | 377, 378, 379, 381, 382, 384, 385, 386, 388, 389, 391, 392, 393, |
| 39 | 395, 396, 398, 399, 401, 402, 403, 405, 406, 408, 409, 411, 412, |
| 40 | 414, 415, 417, 418, 420, 421, 423, 424, 426, 427, 429, 430, 432, |
| 41 | 434, 435, 437, 438, 440, 442, 443, 445, 446, 448, 450, 451, 453, |
| 42 | 454, 456, 458, 459, 461, 463, 464, 466, 468, 469, 471, 473, 475, |
| 43 | 476, 478, 480, 481, 483, 485, 487, 488, 490, 492, 494, 496, 497, |
| 44 | 499, 501, 503, 505, 506, 508, 510, 512, 514, 516, 518, 519, 521, |
| 45 | 523, 525, 527, 529, 531, 533, 535, 537, 538, 540, 542, 544, 546, |
| 46 | 548, 550, 552, 554, 556, 558, 560, 562, 564, 566, 568, 571, 573, |
| 47 | 575, 577, 579, 581, 583, 585, 587, 589, 591, 594, 596, 598, 600, |
| 48 | 602, 604, 607, 609, 611, 613, 615, 618, 620, 622, 624, 627, 629, |
| 49 | 631, 633, 636, 638, 640, 643, 645, 647, 650, 652, 654, 657, 659, |
| 50 | 662, 664, 666, 669, 671, 674, 676, 678, 681, 683 |
| 51 | }; |
| 52 | |
| 53 | /* Vibrato (sine) table */ |
| 54 | static const Uint8cxx . . $ Uint8# vibtabcxx . . $ vibtab.[25 + (13 * 3)] = { |
| 55 | 0, 13, 25, 37, 50, 62, 74, 86, 98, 109, 120, 131, 142, 152, 162, |
| 56 | 171, 180, 189, 197, 205, 212, 219, 225, 231, 236, 240, 244, 247, |
| 57 | 250, 252, 254, 255, 255, 255, 254, 252, 250, 247, 244, 240, 236, |
| 58 | 231, 225, 219, 212, 205, 197, 189, 180, 171, 162, 152, 142, 131, |
| 59 | 120, 109, 98, 86, 74, 62, 50, 37, 25, 13 |
| 60 | }; |
| 61 | |
| 62 | /* Tremolo (sine * sine) table */ |
| 63 | static const Uint8cxx . . $ Uint8# tremtabcxx . . $ tremtab.[128] = { |
| 64 | 0, 0, 1, 1, 2, 4, 5, 7, 10, 12, 15, 18, 21, 25, 29, 33, 37, 42, 47, |
| 65 | 52, 57, 62, 67, 73, 79, 85, 90, 97, 103, 109, 115, 121, 128, 134, |
| 66 | 140, 146, 152, 158, 165, 170, 176, 182, 188, 193, 198, 203, 208, |
| 67 | 213, 218, 222, 226, 230, 234, 237, 240, 243, 245, 248, 250, 251, |
| 68 | 253, 254, 254, 255, 255, 255, 254, 254, 253, 251, 250, 248, 245, |
| 69 | 243, 240, 237, 234, 230, 226, 222, 218, 213, 208, 203, 198, 193, |
| 70 | 188, 182, 176, 170, 165, 158, 152, 146, 140, 134, 127, 121, 115, |
| 71 | 109, 103, 97, 90, 85, 79, 73, 67, 62, 57, 52, 47, 42, 37, 33, 29, |
| 72 | 25, 21, 18, 15, 12, 10, 7, 5, 4, 2, 1, 1, 0 |
| 73 | }; |
| 74 | |
| 75 | static const Uint16cxx . . $ Uint16# maxsoundcxx . . $ maxsound. = 0x3f, maxposcxx . . $ maxpos. = 0xff; |
| 76 | |
| 77 | static SoundBankcxx . . $ SoundBank# *soundbankcxx . . $ soundbank. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 78 | static Channelcxx . . $ Channel# channelcxx . . $ channel.[9]; |
| 79 | static Positioncxx . . $ Position# *positionscxx . . $ positions. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 80 | |
| 81 | static Uint8cxx . . $ Uint8# fmchipcxx . . $ fmchip.[0xff], jumpingcxx . . $ jumping., fadeonoffcxx . . $ fadeonoff., allvolumecxx . . $ allvolume., hardfadecxx . . $ hardfade., tempo_nowcxx . . $ tempo_now., pattplaycxx . . $ pattplay., tempocxx . . $ tempo., regbdcxx . . $ regbd., chandelaycxx . . $ chandelay.[9], modecxx . . $ mode., pattlencxx . . $ pattlen.; |
| 82 | static Uint16cxx . . $ Uint16# posplaycxx . . $ posplay., jumpposcxx . . $ jumppos., speedcxx . . $ speed.; |
| 83 | static Uint16cxx . . $ Uint16# *patternscxx . . $ patterns. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 84 | static Uint16cxx . . $ Uint16# numpatchcxx . . $ numpatch., numposicxx . . $ numposi., mainvolumecxx . . $ mainvolume.; |
| 85 | |
| 86 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! playingcxx . . $ playing., songloopedcxx . . $ songlooped.; |
| 87 | |
| 88 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! lds_loadcxx . . $ lds_load(38255538a6a87b10).(FILEcxx . . $ FILE# *f, unsigned int music_offset, unsigned int music_size) |
| 89 | { |
| 90 | SoundBankcxx . . $ SoundBank# *sb; |
| 91 | |
| 92 | fseekcxx . . $ fseek(543fae30d249f6b1).(f, music_offset, SEEK_SETcxx . . $ `<external>/232824719582829767/stdio.h:110:9`!); |
| 93 | |
| 94 | /* load header */ |
| 95 | fread_u8_diecxx . . $ fread_u8_die(77ebc59a7bf9f340).(&modecxx . . $ mode., 1, f); |
| 96 | if (modecxx . . $ mode. > 2) |
| 97 | { |
| 98 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "error: failed to load music\n"); |
| 99 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 100 | } |
| 101 | fread_u16_diecxx . . $ fread_u16_die(c6228d4965a46ad0).(&speedcxx . . $ speed., 1, f); |
| 102 | fread_u8_diecxx . . $ fread_u8_die(77ebc59a7bf9f340).(&tempocxx . . $ tempo., 1, f); |
| 103 | fread_u8_diecxx . . $ fread_u8_die(77ebc59a7bf9f340).(&pattlencxx . . $ pattlen., 1, f); |
| 104 | fread_u8_diecxx . . $ fread_u8_die(77ebc59a7bf9f340).(chandelaycxx . . $ chandelay., 9, f); |
| 105 | fread_u8_diecxx . . $ fread_u8_die(77ebc59a7bf9f340).(®bdcxx . . $ regbd., 1, f); |
| 106 | |
| 107 | /* load patches */ |
| 108 | fread_u16_diecxx . . $ fread_u16_die(c6228d4965a46ad0).(&numpatchcxx . . $ numpatch., 1, f); |
| 109 | |
| 110 | freecxx . . $ free(5d22bdacc48458e8).(soundbankcxx . . $ soundbank.); |
| 111 | soundbankcxx . . $ soundbank. = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(SoundBankcxx . . $ SoundBank#) * numpatchcxx . . $ numpatch.); |
| 112 | |
| 113 | for (unsigned int i = 0; i < numpatchcxx . . $ numpatch.; i++) |
| 114 | { |
| 115 | sb = &soundbankcxx . . $ soundbank.[i]; |
| 116 | fread_u8_diecxx . . $ fread_u8_die(77ebc59a7bf9f340).( &sb->mod_misccxx . . $ $anonymous_type_2a03d4771abf7e14_0#mod_misc., 1, f); |
| 117 | fread_u8_diecxx . . $ fread_u8_die(77ebc59a7bf9f340).( &sb->mod_volcxx . . $ $anonymous_type_2a03d4771abf7e14_0#mod_vol., 1, f); |
| 118 | fread_u8_diecxx . . $ fread_u8_die(77ebc59a7bf9f340).( &sb->mod_adcxx . . $ $anonymous_type_2a03d4771abf7e14_0#mod_ad., 1, f); |
| 119 | fread_u8_diecxx . . $ fread_u8_die(77ebc59a7bf9f340).( &sb->mod_srcxx . . $ $anonymous_type_2a03d4771abf7e14_0#mod_sr., 1, f); |
| 120 | fread_u8_diecxx . . $ fread_u8_die(77ebc59a7bf9f340).( &sb->mod_wavecxx . . $ $anonymous_type_2a03d4771abf7e14_0#mod_wave., 1, f); |
| 121 | fread_u8_diecxx . . $ fread_u8_die(77ebc59a7bf9f340).( &sb->car_misccxx . . $ $anonymous_type_2a03d4771abf7e14_0#car_misc., 1, f); |
| 122 | fread_u8_diecxx . . $ fread_u8_die(77ebc59a7bf9f340).( &sb->car_volcxx . . $ $anonymous_type_2a03d4771abf7e14_0#car_vol., 1, f); |
| 123 | fread_u8_diecxx . . $ fread_u8_die(77ebc59a7bf9f340).( &sb->car_adcxx . . $ $anonymous_type_2a03d4771abf7e14_0#car_ad., 1, f); |
| 124 | fread_u8_diecxx . . $ fread_u8_die(77ebc59a7bf9f340).( &sb->car_srcxx . . $ $anonymous_type_2a03d4771abf7e14_0#car_sr., 1, f); |
| 125 | fread_u8_diecxx . . $ fread_u8_die(77ebc59a7bf9f340).( &sb->car_wavecxx . . $ $anonymous_type_2a03d4771abf7e14_0#car_wave., 1, f); |
| 126 | fread_u8_diecxx . . $ fread_u8_die(77ebc59a7bf9f340).( &sb->feedbackcxx . . $ $anonymous_type_2a03d4771abf7e14_0#feedback., 1, f); |
| 127 | fread_u8_diecxx . . $ fread_u8_die(77ebc59a7bf9f340).( &sb->keyoffcxx . . $ $anonymous_type_2a03d4771abf7e14_0#keyoff., 1, f); |
| 128 | fread_u8_diecxx . . $ fread_u8_die(77ebc59a7bf9f340).( &sb->portamentocxx . . $ $anonymous_type_2a03d4771abf7e14_0#portamento., 1, f); |
| 129 | fread_u8_diecxx . . $ fread_u8_die(77ebc59a7bf9f340).( &sb->glidecxx . . $ $anonymous_type_2a03d4771abf7e14_0#glide., 1, f); |
| 130 | fread_u8_diecxx . . $ fread_u8_die(77ebc59a7bf9f340).( &sb->finetunecxx . . $ $anonymous_type_2a03d4771abf7e14_0#finetune., 1, f); |
| 131 | fread_u8_diecxx . . $ fread_u8_die(77ebc59a7bf9f340).( &sb->vibratocxx . . $ $anonymous_type_2a03d4771abf7e14_0#vibrato., 1, f); |
| 132 | fread_u8_diecxx . . $ fread_u8_die(77ebc59a7bf9f340).( &sb->vibdelaycxx . . $ $anonymous_type_2a03d4771abf7e14_0#vibdelay., 1, f); |
| 133 | fread_u8_diecxx . . $ fread_u8_die(77ebc59a7bf9f340).( &sb->mod_tremcxx . . $ $anonymous_type_2a03d4771abf7e14_0#mod_trem., 1, f); |
| 134 | fread_u8_diecxx . . $ fread_u8_die(77ebc59a7bf9f340).( &sb->car_tremcxx . . $ $anonymous_type_2a03d4771abf7e14_0#car_trem., 1, f); |
| 135 | fread_u8_diecxx . . $ fread_u8_die(77ebc59a7bf9f340).( &sb->tremwaitcxx . . $ $anonymous_type_2a03d4771abf7e14_0#tremwait., 1, f); |
| 136 | fread_u8_diecxx . . $ fread_u8_die(77ebc59a7bf9f340).( &sb->arpeggiocxx . . $ $anonymous_type_2a03d4771abf7e14_0#arpeggio., 1, f); |
| 137 | fread_u8_diecxx . . $ fread_u8_die(77ebc59a7bf9f340).( sb->arp_tabcxx . . $ $anonymous_type_2a03d4771abf7e14_0#arp_tab., 12, f); |
| 138 | fread_u16_diecxx . . $ fread_u16_die(c6228d4965a46ad0).(&sb->startcxx . . $ $anonymous_type_2a03d4771abf7e14_0#start., 1, f); |
| 139 | fread_u16_diecxx . . $ fread_u16_die(c6228d4965a46ad0).(&sb->sizecxx . . $ $anonymous_type_2a03d4771abf7e14_0#size., 1, f); |
| 140 | fread_u8_diecxx . . $ fread_u8_die(77ebc59a7bf9f340).( &sb->fmscxx . . $ $anonymous_type_2a03d4771abf7e14_0#fms., 1, f); |
| 141 | fread_u16_diecxx . . $ fread_u16_die(c6228d4965a46ad0).(&sb->transpcxx . . $ $anonymous_type_2a03d4771abf7e14_0#transp., 1, f); |
| 142 | fread_u8_diecxx . . $ fread_u8_die(77ebc59a7bf9f340).( &sb->midinstcxx . . $ $anonymous_type_2a03d4771abf7e14_0#midinst., 1, f); |
| 143 | fread_u8_diecxx . . $ fread_u8_die(77ebc59a7bf9f340).( &sb->midvelocxx . . $ $anonymous_type_2a03d4771abf7e14_0#midvelo., 1, f); |
| 144 | fread_u8_diecxx . . $ fread_u8_die(77ebc59a7bf9f340).( &sb->midkeycxx . . $ $anonymous_type_2a03d4771abf7e14_0#midkey., 1, f); |
| 145 | fread_u8_diecxx . . $ fread_u8_die(77ebc59a7bf9f340).( &sb->midtranscxx . . $ $anonymous_type_2a03d4771abf7e14_0#midtrans., 1, f); |
| 146 | fread_u8_diecxx . . $ fread_u8_die(77ebc59a7bf9f340).( &sb->middum1cxx . . $ $anonymous_type_2a03d4771abf7e14_0#middum1., 1, f); |
| 147 | fread_u8_diecxx . . $ fread_u8_die(77ebc59a7bf9f340).( &sb->middum2cxx . . $ $anonymous_type_2a03d4771abf7e14_0#middum2., 1, f); |
| 148 | } |
| 149 | |
| 150 | /* load positions */ |
| 151 | fread_u16_diecxx . . $ fread_u16_die(c6228d4965a46ad0).(&numposicxx . . $ numposi., 1, f); |
| 152 | |
| 153 | freecxx . . $ free(5d22bdacc48458e8).(positionscxx . . $ positions.); |
| 154 | positionscxx . . $ positions. = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(Positioncxx . . $ Position#) * 9 * numposicxx . . $ numposi.); |
| 155 | |
| 156 | for (unsigned int i = 0; i < numposicxx . . $ numposi.; i++) |
| 157 | { |
| 158 | for (unsigned int j = 0; j < 9; j++) |
| 159 | { |
| 160 | /* |
| 161 | * patnum is a pointer inside the pattern space, but patterns are 16bit |
| 162 | * word fields anyway, so it ought to be an even number (hopefully) and |
| 163 | * we can just divide it by 2 to get our array index of 16bit words. |
| 164 | */ |
| 165 | fread_u16_diecxx . . $ fread_u16_die(c6228d4965a46ad0).(&positionscxx . . $ positions.[i * 9 + j].patnumcxx . . $ $anonymous_type_2a03d4771abf7e14_3#patnum., 1, f); |
| 166 | fread_u8_diecxx . . $ fread_u8_die(77ebc59a7bf9f340).( &positionscxx . . $ positions.[i * 9 + j].transposecxx . . $ $anonymous_type_2a03d4771abf7e14_3#transpose., 1, f); |
| 167 | positionscxx . . $ positions.[i * 9 + j].patnumcxx . . $ $anonymous_type_2a03d4771abf7e14_3#patnum. /= 2; |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | /* load patterns */ |
| 172 | fseekcxx . . $ fseek(543fae30d249f6b1).(f, 2, SEEK_CURcxx . . $ `<external>/232824719582829767/stdio.h:111:9`!); /* ignore # of digital sounds (dunno what this is for) */ |
| 173 | |
| 174 | unsigned int remaining = music_size - (ftellcxx . . $ ftell(1dcafcd8ef4c6e6c).(f) - music_offset); |
| 175 | size_t numpatterns = remaining / 2; |
| 176 | |
| 177 | freecxx . . $ free(5d22bdacc48458e8).(patternscxx . . $ patterns.); |
| 178 | patternscxx . . $ patterns. = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(Uint16cxx . . $ Uint16#) * numpatterns); |
| 179 | |
| 180 | fread_u16_diecxx . . $ fread_u16_die(c6228d4965a46ad0).(patternscxx . . $ patterns., numpatterns, f); |
| 181 | |
| 182 | lds_rewindcxx . . $ lds_rewind(49f6e7a06ebc5aa8).(); |
| 183 | |
| 184 | return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 185 | } |
| 186 | |
| 187 | void lds_freecxx . . $ lds_free(49f6e7a06ebc5aa8).(void) |
| 188 | { |
| 189 | freecxx . . $ free(5d22bdacc48458e8).(soundbankcxx . . $ soundbank.); |
| 190 | soundbankcxx . . $ soundbank. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 191 | |
| 192 | freecxx . . $ free(5d22bdacc48458e8).(positionscxx . . $ positions.); |
| 193 | positionscxx . . $ positions. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 194 | |
| 195 | freecxx . . $ free(5d22bdacc48458e8).(patternscxx . . $ patterns.); |
| 196 | patternscxx . . $ patterns. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 197 | } |
| 198 | |
| 199 | void lds_rewindcxx . . $ lds_rewind(49f6e7a06ebc5aa8).(void) |
| 200 | { |
| 201 | int i; |
| 202 | |
| 203 | /* init all with 0 */ |
| 204 | tempo_nowcxx . . $ tempo_now. = 3; |
| 205 | playingcxx . . $ playing. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; songloopedcxx . . $ songlooped. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 206 | jumpingcxx . . $ jumping. = fadeonoffcxx . . $ fadeonoff. = allvolumecxx . . $ allvolume. = hardfadecxx . . $ hardfade. = pattplaycxx . . $ pattplay. = posplaycxx . . $ posplay. = jumpposcxx . . $ jumppos. = mainvolumecxx . . $ mainvolume. = 0; |
| 207 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(channelcxx . . $ channel., 0, sizeof(channelcxx . . $ channel.)); |
| 208 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(fmchipcxx . . $ fmchip., 0, sizeof(fmchipcxx . . $ fmchip.)); |
| 209 | |
| 210 | /* OPL2 init */ |
| 211 | opl_initcxx . . $ `src/opl.h:47:9`!(); /* Reset OPL chip */ |
| 212 | opl_writecxx . . $ `src/opl.h:48:9`!(1, 0x20); |
| 213 | opl_writecxx . . $ `src/opl.h:48:9`!(8, 0); |
| 214 | opl_writecxx . . $ `src/opl.h:48:9`!(0xbd, regbd); |
| 215 | |
| 216 | for(i = 0; i < 9; i++) { |
| 217 | opl_writecxx . . $ `src/opl.h:48:9`!(0x20 + op_table[i], 0); |
| 218 | opl_writecxx . . $ `src/opl.h:48:9`!(0x23 + op_table[i], 0); |
| 219 | opl_writecxx . . $ `src/opl.h:48:9`!(0x40 + op_table[i], 0x3f); |
| 220 | opl_writecxx . . $ `src/opl.h:48:9`!(0x43 + op_table[i], 0x3f); |
| 221 | opl_writecxx . . $ `src/opl.h:48:9`!(0x60 + op_table[i], 0xff); |
| 222 | opl_writecxx . . $ `src/opl.h:48:9`!(0x63 + op_table[i], 0xff); |
| 223 | opl_writecxx . . $ `src/opl.h:48:9`!(0x80 + op_table[i], 0xff); |
| 224 | opl_writecxx . . $ `src/opl.h:48:9`!(0x83 + op_table[i], 0xff); |
| 225 | opl_writecxx . . $ `src/opl.h:48:9`!(0xe0 + op_table[i], 0); |
| 226 | opl_writecxx . . $ `src/opl.h:48:9`!(0xe3 + op_table[i], 0); |
| 227 | opl_writecxx . . $ `src/opl.h:48:9`!(0xa0 + i, 0); |
| 228 | opl_writecxx . . $ `src/opl.h:48:9`!(0xb0 + i, 0); |
| 229 | opl_writecxx . . $ `src/opl.h:48:9`!(0xc0 + i, 0); |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | void lds_fadecxx . . $ lds_fade(ac50b47256ae7414).(Uint8cxx . . $ Uint8# speed) |
| 234 | { |
| 235 | fadeonoffcxx . . $ fadeonoff. = speed; |
| 236 | } |
| 237 | |
| 238 | void lds_setregscxx . . $ lds_setregs(8fbe6856f5410d23).(Uint8cxx . . $ Uint8# reg, Uint8cxx . . $ Uint8# val) |
| 239 | { |
| 240 | if(fmchipcxx . . $ fmchip.[reg] == val) return; |
| 241 | |
| 242 | fmchipcxx . . $ fmchip.[reg] = val; |
| 243 | opl_writecxx . . $ `src/opl.h:48:9`!(reg, val); |
| 244 | } |
| 245 | |
| 246 | void lds_setregs_advcxx . . $ lds_setregs_adv(684ed43ade99b32e).(Uint8cxx . . $ Uint8# reg, Uint8cxx . . $ Uint8# mask, Uint8cxx . . $ Uint8# val) |
| 247 | { |
| 248 | lds_setregscxx . . $ lds_setregs(8fbe6856f5410d23).(reg, (fmchipcxx . . $ fmchip.[reg] & mask) | val); |
| 249 | } |
| 250 | |
| 251 | int lds_updatecxx . . $ lds_update(b126dc7c1de90089).(void) |
| 252 | { |
| 253 | Uint16cxx . . $ Uint16# comword, freq, octave, chan, tune, wibc, tremc, arpreg; |
| 254 | int vbreak; |
| 255 | Uint8cxx . . $ Uint8# level, regnum, comhi, comlo; |
| 256 | int i; |
| 257 | Channelcxx . . $ Channel# *c; |
| 258 | |
| 259 | if(!playingcxx . . $ playing.) return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 260 | |
| 261 | /* handle fading */ |
| 262 | if(fadeonoffcxx . . $ fadeonoff.) |
| 263 | { |
| 264 | if(fadeonoffcxx . . $ fadeonoff. <= 128) { |
| 265 | if(allvolumecxx . . $ allvolume. > fadeonoffcxx . . $ fadeonoff. || allvolumecxx . . $ allvolume. == 0) |
| 266 | { |
| 267 | allvolumecxx . . $ allvolume. -= fadeonoffcxx . . $ fadeonoff.; |
| 268 | } else { |
| 269 | allvolumecxx . . $ allvolume. = 1; |
| 270 | fadeonoffcxx . . $ fadeonoff. = 0; |
| 271 | if(hardfadecxx . . $ hardfade. != 0) { |
| 272 | playingcxx . . $ playing. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 273 | hardfadecxx . . $ hardfade. = 0; |
| 274 | for(i = 0; i < 9; i++) |
| 275 | { |
| 276 | channelcxx . . $ channel.[i].keycountcxx . . $ $anonymous_type_2a03d4771abf7e14_1#keycount. = 1; |
| 277 | } |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | } else { |
| 282 | if( (Uint8cxx . . $ Uint8#) ((allvolumecxx . . $ allvolume. + (0x100 - fadeonoffcxx . . $ fadeonoff.)) & 0xff) <= mainvolumecxx . . $ mainvolume.) |
| 283 | { |
| 284 | allvolumecxx . . $ allvolume. += 0x100 - fadeonoffcxx . . $ fadeonoff.; |
| 285 | } else { |
| 286 | allvolumecxx . . $ allvolume. = mainvolumecxx . . $ mainvolume.; |
| 287 | fadeonoffcxx . . $ fadeonoff. = 0; |
| 288 | } |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | /* handle channel delay */ |
| 293 | for(chan = 0; chan < 9; chan++) { |
| 294 | c = &channelcxx . . $ channel.[chan]; |
| 295 | if(c->chancheatcxx . . $ $anonymous_type_2a03d4771abf7e14_1#chancheat..chandelaycxx . . $ $anonymous_type_2a03d4771abf7e14_1#$anonymous_type_2#chandelay.) { |
| 296 | if(!(--c->chancheatcxx . . $ $anonymous_type_2a03d4771abf7e14_1#chancheat..chandelaycxx . . $ $anonymous_type_2a03d4771abf7e14_1#$anonymous_type_2#chandelay.)) { |
| 297 | lds_playsoundcxx . . $ lds_playsound(b1146eedae1e1d0b).(c->chancheatcxx . . $ $anonymous_type_2a03d4771abf7e14_1#chancheat..soundcxx . . $ $anonymous_type_2a03d4771abf7e14_1#$anonymous_type_2#sound., chan, c->chancheatcxx . . $ $anonymous_type_2a03d4771abf7e14_1#chancheat..highcxx . . $ $anonymous_type_2a03d4771abf7e14_1#$anonymous_type_2#high.); |
| 298 | } |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | /* handle notes */ |
| 303 | if(!tempo_nowcxx . . $ tempo_now. && positionscxx . . $ positions.) |
| 304 | { |
| 305 | vbreak = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 306 | for(chan = 0; chan < 9; chan++) |
| 307 | { |
| 308 | c = &channelcxx . . $ channel.[chan]; |
| 309 | if(!c->packwaitcxx . . $ $anonymous_type_2a03d4771abf7e14_1#packwait.) { |
| 310 | Uint16cxx . . $ Uint16# patnum = positionscxx . . $ positions.[posplaycxx . . $ posplay. * 9 + chan].patnumcxx . . $ $anonymous_type_2a03d4771abf7e14_3#patnum.; |
| 311 | Uint8cxx . . $ Uint8# transpose = positionscxx . . $ positions.[posplaycxx . . $ posplay. * 9 + chan].transposecxx . . $ $anonymous_type_2a03d4771abf7e14_3#transpose.; |
| 312 | /*printf("> %p", positions);*/ |
| 313 | |
| 314 | comword = patternscxx . . $ patterns.[patnum + c->packposcxx . . $ $anonymous_type_2a03d4771abf7e14_1#packpos.]; |
| 315 | comhi = comword >> 8; comlo = comword & 0xff; |
| 316 | if(comword) { |
| 317 | if(comhi == 0x80) |
| 318 | { |
| 319 | c->packwaitcxx . . $ $anonymous_type_2a03d4771abf7e14_1#packwait. = comlo; |
| 320 | } else { |
| 321 | if(comhi >= 0x80) |
| 322 | { |
| 323 | switch(comhi) |
| 324 | { |
| 325 | case 0xff: |
| 326 | c->volcarcxx . . $ $anonymous_type_2a03d4771abf7e14_1#volcar. = (((c->volcarcxx . . $ $anonymous_type_2a03d4771abf7e14_1#volcar. & 0x3f) * comlo) >> 6) & 0x3f; |
| 327 | if(fmchipcxx . . $ fmchip.[0xc0 + chan] & 1) |
| 328 | c->volmodcxx . . $ $anonymous_type_2a03d4771abf7e14_1#volmod. = (((c->volmodcxx . . $ $anonymous_type_2a03d4771abf7e14_1#volmod. & 0x3f) * comlo) >> 6) & 0x3f; |
| 329 | break; |
| 330 | |
| 331 | case 0xfe: |
| 332 | tempocxx . . $ tempo. = comword & 0x3f; |
| 333 | break; |
| 334 | |
| 335 | case 0xfd: |
| 336 | c->nextvolcxx . . $ $anonymous_type_2a03d4771abf7e14_1#nextvol. = comlo; |
| 337 | break; |
| 338 | |
| 339 | case 0xfc: |
| 340 | playingcxx . . $ playing. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 341 | /* in real player there's also full keyoff here, but we don't need it */ |
| 342 | break; |
| 343 | |
| 344 | case 0xfb: |
| 345 | c->keycountcxx . . $ $anonymous_type_2a03d4771abf7e14_1#keycount. = 1; |
| 346 | break; |
| 347 | |
| 348 | case 0xfa: |
| 349 | vbreak = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 350 | jumpposcxx . . $ jumppos. = (posplaycxx . . $ posplay. + 1) & maxposcxx . . $ maxpos.; |
| 351 | break; |
| 352 | |
| 353 | case 0xf9: |
| 354 | vbreak = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 355 | jumpposcxx . . $ jumppos. = comlo & maxposcxx . . $ maxpos.; |
| 356 | jumpingcxx . . $ jumping. = 1; |
| 357 | if(jumpposcxx . . $ jumppos. < posplaycxx . . $ posplay.) |
| 358 | { |
| 359 | songloopedcxx . . $ songlooped. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 360 | } |
| 361 | break; |
| 362 | |
| 363 | case 0xf8: |
| 364 | c->lasttunecxx . . $ $anonymous_type_2a03d4771abf7e14_1#lasttune. = 0; |
| 365 | break; |
| 366 | |
| 367 | case 0xf7: |
| 368 | c->vibwaitcxx . . $ $anonymous_type_2a03d4771abf7e14_1#vibwait. = 0; |
| 369 | /* PASCAL: c->vibspeed = ((comlo >> 4) & 15) + 2; */ |
| 370 | c->vibspeedcxx . . $ $anonymous_type_2a03d4771abf7e14_1#vibspeed. = (comlo >> 4) + 2; |
| 371 | c->vibratecxx . . $ $anonymous_type_2a03d4771abf7e14_1#vibrate. = (comlo & 15) + 1; |
| 372 | break; |
| 373 | |
| 374 | case 0xf6: |
| 375 | c->glidetocxx . . $ $anonymous_type_2a03d4771abf7e14_1#glideto. = comlo; |
| 376 | break; |
| 377 | |
| 378 | case 0xf5: |
| 379 | c->finetunecxx . . $ $anonymous_type_2a03d4771abf7e14_1#finetune. = comlo; |
| 380 | break; |
| 381 | |
| 382 | case 0xf4: |
| 383 | if(!hardfadecxx . . $ hardfade.) |
| 384 | { |
| 385 | allvolumecxx . . $ allvolume. = mainvolumecxx . . $ mainvolume. = comlo; |
| 386 | fadeonoffcxx . . $ fadeonoff. = 0; |
| 387 | } |
| 388 | break; |
| 389 | |
| 390 | case 0xf3: |
| 391 | if(!hardfadecxx . . $ hardfade.) |
| 392 | { |
| 393 | fadeonoffcxx . . $ fadeonoff. = comlo; |
| 394 | } |
| 395 | break; |
| 396 | |
| 397 | case 0xf2: |
| 398 | c->trmstaycxx . . $ $anonymous_type_2a03d4771abf7e14_1#trmstay. = comlo; |
| 399 | break; |
| 400 | |
| 401 | case 0xf1: /* panorama */ |
| 402 | |
| 403 | case 0xf0: /* progch */ |
| 404 | /* MIDI commands (unhandled) */ |
| 405 | /*AdPlug_LogWrite("CldsPlayer(): not handling MIDI command 0x%x, " |
| 406 | "value = 0x%x\n", comhi);*/ |
| 407 | break; |
| 408 | |
| 409 | default: |
| 410 | if(comhi < 0xa0) |
| 411 | { |
| 412 | c->glidetocxx . . $ $anonymous_type_2a03d4771abf7e14_1#glideto. = comhi & 0x1f; |
| 413 | } else { |
| 414 | /*AdPlug_LogWrite("CldsPlayer(): unknown command 0x%x encountered!" |
| 415 | " value = 0x%x\n", comhi, comlo);*/ |
| 416 | } |
| 417 | break; |
| 418 | } |
| 419 | } else { |
| 420 | Uint8cxx . . $ Uint8# sound; |
| 421 | Uint16cxx . . $ Uint16# high; |
| 422 | Sint8cxx . . $ Sint8# transp = transpose & 127; |
| 423 | /* |
| 424 | * Originally, in assembler code, the player first shifted |
| 425 | * logically left the transpose byte by 1 and then shifted |
| 426 | * arithmetically right the same byte to achieve the final, |
| 427 | * signed transpose value. Since we can't do arithmetic shifts |
| 428 | * in C, we just duplicate the 7th bit into the 8th one and |
| 429 | * discard the 8th one completely. |
| 430 | */ |
| 431 | |
| 432 | if(transpose & 64) |
| 433 | { |
| 434 | transp |= 128; |
| 435 | } |
| 436 | |
| 437 | if(transpose & 128) |
| 438 | { |
| 439 | sound = (comlo + transp) & maxsoundcxx . . $ maxsound.; |
| 440 | high = comhi << 4; |
| 441 | } else { |
| 442 | sound = comlo & maxsoundcxx . . $ maxsound.; |
| 443 | high = (comhi + transp) << 4; |
| 444 | } |
| 445 | |
| 446 | /* |
| 447 | PASCAL: |
| 448 | sound = comlo & maxsound; |
| 449 | high = (comhi + (((transpose + 0x24) & 0xff) - 0x24)) << 4; |
| 450 | */ |
| 451 | |
| 452 | if(!chandelaycxx . . $ chandelay.[chan]) { |
| 453 | lds_playsoundcxx . . $ lds_playsound(b1146eedae1e1d0b).(sound, chan, high); |
| 454 | } else { |
| 455 | c->chancheatcxx . . $ $anonymous_type_2a03d4771abf7e14_1#chancheat..chandelaycxx . . $ $anonymous_type_2a03d4771abf7e14_1#$anonymous_type_2#chandelay. = chandelaycxx . . $ chandelay.[chan]; |
| 456 | c->chancheatcxx . . $ $anonymous_type_2a03d4771abf7e14_1#chancheat..soundcxx . . $ $anonymous_type_2a03d4771abf7e14_1#$anonymous_type_2#sound. = sound; |
| 457 | c->chancheatcxx . . $ $anonymous_type_2a03d4771abf7e14_1#chancheat..highcxx . . $ $anonymous_type_2a03d4771abf7e14_1#$anonymous_type_2#high. = high; |
| 458 | } |
| 459 | } |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | c->packposcxx . . $ $anonymous_type_2a03d4771abf7e14_1#packpos.++; |
| 464 | } else { |
| 465 | c->packwaitcxx . . $ $anonymous_type_2a03d4771abf7e14_1#packwait.--; |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | tempo_nowcxx . . $ tempo_now. = tempocxx . . $ tempo.; |
| 470 | /* |
| 471 | The continue table is updated here, but this is only used in the |
| 472 | original player, which can be paused in the middle of a song and then |
| 473 | unpaused. Since AdPlug does all this for us automatically, we don't |
| 474 | have a continue table here. The continue table update code is noted |
| 475 | here for reference only. |
| 476 | |
| 477 | if(!pattplay) { |
| 478 | conttab[speed & maxcont].position = posplay & 0xff; |
| 479 | conttab[speed & maxcont].tempo = tempo; |
| 480 | } |
| 481 | */ |
| 482 | pattplaycxx . . $ pattplay.++; |
| 483 | if(vbreak) |
| 484 | { |
| 485 | pattplaycxx . . $ pattplay. = 0; |
| 486 | for(i = 0; i < 9; i++) |
| 487 | { |
| 488 | channelcxx . . $ channel.[i].packposcxx . . $ $anonymous_type_2a03d4771abf7e14_1#packpos. = channelcxx . . $ channel.[i].packwaitcxx . . $ $anonymous_type_2a03d4771abf7e14_1#packwait. = 0; |
| 489 | } |
| 490 | posplaycxx . . $ posplay. = jumpposcxx . . $ jumppos.; |
| 491 | } else { |
| 492 | if(pattplaycxx . . $ pattplay. >= pattlencxx . . $ pattlen.) { |
| 493 | pattplaycxx . . $ pattplay. = 0; |
| 494 | for(i = 0; i < 9; i++) |
| 495 | { |
| 496 | channelcxx . . $ channel.[i].packposcxx . . $ $anonymous_type_2a03d4771abf7e14_1#packpos. = channelcxx . . $ channel.[i].packwaitcxx . . $ $anonymous_type_2a03d4771abf7e14_1#packwait. = 0; |
| 497 | } |
| 498 | posplaycxx . . $ posplay. = (posplaycxx . . $ posplay. + 1) & maxposcxx . . $ maxpos.; |
| 499 | } |
| 500 | } |
| 501 | } else { |
| 502 | tempo_nowcxx . . $ tempo_now.--; |
| 503 | } |
| 504 | |
| 505 | /* make effects */ |
| 506 | for(chan = 0; chan < 9; chan++) { |
| 507 | c = &channelcxx . . $ channel.[chan]; |
| 508 | regnum = op_tablecxx . . $ op_table.[chan]; |
| 509 | if(c->keycountcxx . . $ $anonymous_type_2a03d4771abf7e14_1#keycount. > 0) { |
| 510 | if(c->keycountcxx . . $ $anonymous_type_2a03d4771abf7e14_1#keycount. == 1) |
| 511 | lds_setregs_advcxx . . $ lds_setregs_adv(684ed43ade99b32e).(0xb0 + chan, 0xdf, 0); |
| 512 | c->keycountcxx . . $ $anonymous_type_2a03d4771abf7e14_1#keycount.--; |
| 513 | } |
| 514 | |
| 515 | /* arpeggio */ |
| 516 | if(c->arp_sizecxx . . $ $anonymous_type_2a03d4771abf7e14_1#arp_size. == 0) |
| 517 | arpreg = 0; |
| 518 | else { |
| 519 | arpreg = c->arp_tabcxx . . $ $anonymous_type_2a03d4771abf7e14_1#arp_tab.[c->arp_poscxx . . $ $anonymous_type_2a03d4771abf7e14_1#arp_pos.] << 4; |
| 520 | if(arpreg == 0x800) { |
| 521 | if(c->arp_poscxx . . $ $anonymous_type_2a03d4771abf7e14_1#arp_pos. > 0) c->arp_tabcxx . . $ $anonymous_type_2a03d4771abf7e14_1#arp_tab.[0] = c->arp_tabcxx . . $ $anonymous_type_2a03d4771abf7e14_1#arp_tab.[c->arp_poscxx . . $ $anonymous_type_2a03d4771abf7e14_1#arp_pos. - 1]; |
| 522 | c->arp_sizecxx . . $ $anonymous_type_2a03d4771abf7e14_1#arp_size. = 1; c->arp_poscxx . . $ $anonymous_type_2a03d4771abf7e14_1#arp_pos. = 0; |
| 523 | arpreg = c->arp_tabcxx . . $ $anonymous_type_2a03d4771abf7e14_1#arp_tab.[0] << 4; |
| 524 | } |
| 525 | |
| 526 | if(c->arp_countcxx . . $ $anonymous_type_2a03d4771abf7e14_1#arp_count. == c->arp_speedcxx . . $ $anonymous_type_2a03d4771abf7e14_1#arp_speed.) { |
| 527 | c->arp_poscxx . . $ $anonymous_type_2a03d4771abf7e14_1#arp_pos.++; |
| 528 | if(c->arp_poscxx . . $ $anonymous_type_2a03d4771abf7e14_1#arp_pos. >= c->arp_sizecxx . . $ $anonymous_type_2a03d4771abf7e14_1#arp_size.) c->arp_poscxx . . $ $anonymous_type_2a03d4771abf7e14_1#arp_pos. = 0; |
| 529 | c->arp_countcxx . . $ $anonymous_type_2a03d4771abf7e14_1#arp_count. = 0; |
| 530 | } else |
| 531 | c->arp_countcxx . . $ $anonymous_type_2a03d4771abf7e14_1#arp_count.++; |
| 532 | } |
| 533 | |
| 534 | /* glide & portamento */ |
| 535 | if(c->lasttunecxx . . $ $anonymous_type_2a03d4771abf7e14_1#lasttune. && (c->lasttunecxx . . $ $anonymous_type_2a03d4771abf7e14_1#lasttune. != c->gototunecxx . . $ $anonymous_type_2a03d4771abf7e14_1#gototune.)) { |
| 536 | if(c->lasttunecxx . . $ $anonymous_type_2a03d4771abf7e14_1#lasttune. > c->gototunecxx . . $ $anonymous_type_2a03d4771abf7e14_1#gototune.) { |
| 537 | if(c->lasttunecxx . . $ $anonymous_type_2a03d4771abf7e14_1#lasttune. - c->gototunecxx . . $ $anonymous_type_2a03d4771abf7e14_1#gototune. < c->portspeedcxx . . $ $anonymous_type_2a03d4771abf7e14_1#portspeed.) |
| 538 | c->lasttunecxx . . $ $anonymous_type_2a03d4771abf7e14_1#lasttune. = c->gototunecxx . . $ $anonymous_type_2a03d4771abf7e14_1#gototune.; |
| 539 | else |
| 540 | c->lasttunecxx . . $ $anonymous_type_2a03d4771abf7e14_1#lasttune. -= c->portspeedcxx . . $ $anonymous_type_2a03d4771abf7e14_1#portspeed.; |
| 541 | } else { |
| 542 | if(c->gototunecxx . . $ $anonymous_type_2a03d4771abf7e14_1#gototune. - c->lasttunecxx . . $ $anonymous_type_2a03d4771abf7e14_1#lasttune. < c->portspeedcxx . . $ $anonymous_type_2a03d4771abf7e14_1#portspeed.) |
| 543 | c->lasttunecxx . . $ $anonymous_type_2a03d4771abf7e14_1#lasttune. = c->gototunecxx . . $ $anonymous_type_2a03d4771abf7e14_1#gototune.; |
| 544 | else |
| 545 | c->lasttunecxx . . $ $anonymous_type_2a03d4771abf7e14_1#lasttune. += c->portspeedcxx . . $ $anonymous_type_2a03d4771abf7e14_1#portspeed.; |
| 546 | } |
| 547 | |
| 548 | if(arpreg >= 0x800) |
| 549 | arpreg = c->lasttunecxx . . $ $anonymous_type_2a03d4771abf7e14_1#lasttune. - (arpreg ^ 0xff0) - 16; |
| 550 | else |
| 551 | arpreg += c->lasttunecxx . . $ $anonymous_type_2a03d4771abf7e14_1#lasttune.; |
| 552 | |
| 553 | freq = frequencycxx . . $ frequency.[arpreg % (12 * 16)]; |
| 554 | octave = arpreg / (12 * 16) - 1; |
| 555 | lds_setregscxx . . $ lds_setregs(8fbe6856f5410d23).(0xa0 + chan, freq & 0xff); |
| 556 | lds_setregs_advcxx . . $ lds_setregs_adv(684ed43ade99b32e).(0xb0 + chan, 0x20, ((octave << 2) + (freq >> 8)) & 0xdf); |
| 557 | } else { |
| 558 | /* vibrato */ |
| 559 | if(!c->vibwaitcxx . . $ $anonymous_type_2a03d4771abf7e14_1#vibwait.) { |
| 560 | if(c->vibratecxx . . $ $anonymous_type_2a03d4771abf7e14_1#vibrate.) { |
| 561 | wibc = vibtabcxx . . $ vibtab.[c->vibcountcxx . . $ $anonymous_type_2a03d4771abf7e14_1#vibcount. & 0x3f] * c->vibratecxx . . $ $anonymous_type_2a03d4771abf7e14_1#vibrate.; |
| 562 | |
| 563 | if((c->vibcountcxx . . $ $anonymous_type_2a03d4771abf7e14_1#vibcount. & 0x40) == 0) |
| 564 | tune = c->lasttunecxx . . $ $anonymous_type_2a03d4771abf7e14_1#lasttune. + (wibc >> 8); |
| 565 | else |
| 566 | tune = c->lasttunecxx . . $ $anonymous_type_2a03d4771abf7e14_1#lasttune. - (wibc >> 8); |
| 567 | |
| 568 | if(arpreg >= 0x800) |
| 569 | tune = tune - (arpreg ^ 0xff0) - 16; |
| 570 | else |
| 571 | tune += arpreg; |
| 572 | |
| 573 | freq = frequencycxx . . $ frequency.[tune % (12 * 16)]; |
| 574 | octave = tune / (12 * 16) - 1; |
| 575 | lds_setregscxx . . $ lds_setregs(8fbe6856f5410d23).(0xa0 + chan, freq & 0xff); |
| 576 | lds_setregs_advcxx . . $ lds_setregs_adv(684ed43ade99b32e).(0xb0 + chan, 0x20, ((octave << 2) + (freq >> 8)) & 0xdf); |
| 577 | c->vibcountcxx . . $ $anonymous_type_2a03d4771abf7e14_1#vibcount. += c->vibspeedcxx . . $ $anonymous_type_2a03d4771abf7e14_1#vibspeed.; |
| 578 | } else if(c->arp_sizecxx . . $ $anonymous_type_2a03d4771abf7e14_1#arp_size. != 0) { /* no vibrato, just arpeggio */ |
| 579 | if(arpreg >= 0x800) |
| 580 | tune = c->lasttunecxx . . $ $anonymous_type_2a03d4771abf7e14_1#lasttune. - (arpreg ^ 0xff0) - 16; |
| 581 | else |
| 582 | tune = c->lasttunecxx . . $ $anonymous_type_2a03d4771abf7e14_1#lasttune. + arpreg; |
| 583 | |
| 584 | freq = frequencycxx . . $ frequency.[tune % (12 * 16)]; |
| 585 | octave = tune / (12 * 16) - 1; |
| 586 | lds_setregscxx . . $ lds_setregs(8fbe6856f5410d23).(0xa0 + chan, freq & 0xff); |
| 587 | lds_setregs_advcxx . . $ lds_setregs_adv(684ed43ade99b32e).(0xb0 + chan, 0x20, ((octave << 2) + (freq >> 8)) & 0xdf); |
| 588 | } |
| 589 | } else { /* no vibrato, just arpeggio */ |
| 590 | c->vibwaitcxx . . $ $anonymous_type_2a03d4771abf7e14_1#vibwait.--; |
| 591 | |
| 592 | if(c->arp_sizecxx . . $ $anonymous_type_2a03d4771abf7e14_1#arp_size. != 0) { |
| 593 | if(arpreg >= 0x800) |
| 594 | tune = c->lasttunecxx . . $ $anonymous_type_2a03d4771abf7e14_1#lasttune. - (arpreg ^ 0xff0) - 16; |
| 595 | else |
| 596 | tune = c->lasttunecxx . . $ $anonymous_type_2a03d4771abf7e14_1#lasttune. + arpreg; |
| 597 | |
| 598 | freq = frequencycxx . . $ frequency.[tune % (12 * 16)]; |
| 599 | octave = tune / (12 * 16) - 1; |
| 600 | lds_setregscxx . . $ lds_setregs(8fbe6856f5410d23).(0xa0 + chan, freq & 0xff); |
| 601 | lds_setregs_advcxx . . $ lds_setregs_adv(684ed43ade99b32e).(0xb0 + chan, 0x20, ((octave << 2) + (freq >> 8)) & 0xdf); |
| 602 | } |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | /* tremolo (modulator) */ |
| 607 | if(!c->trmwaitcxx . . $ $anonymous_type_2a03d4771abf7e14_1#trmwait.) { |
| 608 | if(c->trmratecxx . . $ $anonymous_type_2a03d4771abf7e14_1#trmrate.) { |
| 609 | tremc = tremtabcxx . . $ tremtab.[c->trmcountcxx . . $ $anonymous_type_2a03d4771abf7e14_1#trmcount. & 0x7f] * c->trmratecxx . . $ $anonymous_type_2a03d4771abf7e14_1#trmrate.; |
| 610 | if((tremc >> 8) <= (c->volmodcxx . . $ $anonymous_type_2a03d4771abf7e14_1#volmod. & 0x3f)) |
| 611 | level = (c->volmodcxx . . $ $anonymous_type_2a03d4771abf7e14_1#volmod. & 0x3f) - (tremc >> 8); |
| 612 | else |
| 613 | level = 0; |
| 614 | |
| 615 | if(allvolumecxx . . $ allvolume. != 0 && (fmchipcxx . . $ fmchip.[0xc0 + chan] & 1)) |
| 616 | lds_setregs_advcxx . . $ lds_setregs_adv(684ed43ade99b32e).(0x40 + regnum, 0xc0, ((level * allvolumecxx . . $ allvolume.) >> 8) ^ 0x3f); |
| 617 | else |
| 618 | lds_setregs_advcxx . . $ lds_setregs_adv(684ed43ade99b32e).(0x40 + regnum, 0xc0, level ^ 0x3f); |
| 619 | |
| 620 | c->trmcountcxx . . $ $anonymous_type_2a03d4771abf7e14_1#trmcount. += c->trmspeedcxx . . $ $anonymous_type_2a03d4771abf7e14_1#trmspeed.; |
| 621 | } else if(allvolumecxx . . $ allvolume. != 0 && (fmchipcxx . . $ fmchip.[0xc0 + chan] & 1)) |
| 622 | lds_setregs_advcxx . . $ lds_setregs_adv(684ed43ade99b32e).(0x40 + regnum, 0xc0, ((((c->volmodcxx . . $ $anonymous_type_2a03d4771abf7e14_1#volmod. & 0x3f) * allvolumecxx . . $ allvolume.) >> 8) ^ 0x3f) & 0x3f); |
| 623 | else |
| 624 | lds_setregs_advcxx . . $ lds_setregs_adv(684ed43ade99b32e).(0x40 + regnum, 0xc0, (c->volmodcxx . . $ $anonymous_type_2a03d4771abf7e14_1#volmod. ^ 0x3f) & 0x3f); |
| 625 | } else { |
| 626 | c->trmwaitcxx . . $ $anonymous_type_2a03d4771abf7e14_1#trmwait.--; |
| 627 | if(allvolumecxx . . $ allvolume. != 0 && (fmchipcxx . . $ fmchip.[0xc0 + chan] & 1)) |
| 628 | lds_setregs_advcxx . . $ lds_setregs_adv(684ed43ade99b32e).(0x40 + regnum, 0xc0, ((((c->volmodcxx . . $ $anonymous_type_2a03d4771abf7e14_1#volmod. & 0x3f) * allvolumecxx . . $ allvolume.) >> 8) ^ 0x3f) & 0x3f); |
| 629 | } |
| 630 | |
| 631 | /* tremolo (carrier) */ |
| 632 | if(!c->trcwaitcxx . . $ $anonymous_type_2a03d4771abf7e14_1#trcwait.) { |
| 633 | if(c->trcratecxx . . $ $anonymous_type_2a03d4771abf7e14_1#trcrate.) { |
| 634 | tremc = tremtabcxx . . $ tremtab.[c->trccountcxx . . $ $anonymous_type_2a03d4771abf7e14_1#trccount. & 0x7f] * c->trcratecxx . . $ $anonymous_type_2a03d4771abf7e14_1#trcrate.; |
| 635 | if((tremc >> 8) <= (c->volcarcxx . . $ $anonymous_type_2a03d4771abf7e14_1#volcar. & 0x3f)) |
| 636 | level = (c->volcarcxx . . $ $anonymous_type_2a03d4771abf7e14_1#volcar. & 0x3f) - (tremc >> 8); |
| 637 | else |
| 638 | level = 0; |
| 639 | |
| 640 | if(allvolumecxx . . $ allvolume. != 0) |
| 641 | lds_setregs_advcxx . . $ lds_setregs_adv(684ed43ade99b32e).(0x43 + regnum, 0xc0, ((level * allvolumecxx . . $ allvolume.) >> 8) ^ 0x3f); |
| 642 | else |
| 643 | lds_setregs_advcxx . . $ lds_setregs_adv(684ed43ade99b32e).(0x43 + regnum, 0xc0, level ^ 0x3f); |
| 644 | c->trccountcxx . . $ $anonymous_type_2a03d4771abf7e14_1#trccount. += c->trcspeedcxx . . $ $anonymous_type_2a03d4771abf7e14_1#trcspeed.; |
| 645 | } else if(allvolumecxx . . $ allvolume. != 0) |
| 646 | lds_setregs_advcxx . . $ lds_setregs_adv(684ed43ade99b32e).(0x43 + regnum, 0xc0, ((((c->volcarcxx . . $ $anonymous_type_2a03d4771abf7e14_1#volcar. & 0x3f) * allvolumecxx . . $ allvolume.) >> 8) ^ 0x3f) & 0x3f); |
| 647 | else |
| 648 | lds_setregs_advcxx . . $ lds_setregs_adv(684ed43ade99b32e).(0x43 + regnum, 0xc0, (c->volcarcxx . . $ $anonymous_type_2a03d4771abf7e14_1#volcar. ^ 0x3f) & 0x3f); |
| 649 | } else { |
| 650 | c->trcwaitcxx . . $ $anonymous_type_2a03d4771abf7e14_1#trcwait.--; |
| 651 | if(allvolumecxx . . $ allvolume. != 0) |
| 652 | lds_setregs_advcxx . . $ lds_setregs_adv(684ed43ade99b32e).(0x43 + regnum, 0xc0, ((((c->volcarcxx . . $ $anonymous_type_2a03d4771abf7e14_1#volcar. & 0x3f) * allvolumecxx . . $ allvolume.) >> 8) ^ 0x3f) & 0x3f); |
| 653 | } |
| 654 | } |
| 655 | |
| 656 | return (!playingcxx . . $ playing. || songloopedcxx . . $ songlooped.) ? falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`! : truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 657 | } |
| 658 | |
| 659 | void lds_playsoundcxx . . $ lds_playsound(b1146eedae1e1d0b).(int inst_number, int channel_number, int tunehigh) |
| 660 | { |
| 661 | Channelcxx . . $ Channel# *c = &channelcxx . . $ channel.[channel_number]; /* current channel */ |
| 662 | SoundBankcxx . . $ SoundBank# *i = &soundbankcxx . . $ soundbank.[inst_number]; /* current instrument */ |
| 663 | Uint32cxx . . $ Uint32# regnum = op_tablecxx . . $ op_table.[channel_number]; /* channel's OPL2 register */ |
| 664 | Uint8cxx . . $ Uint8# volcalc, octave; |
| 665 | Uint16cxx . . $ Uint16# freq; |
| 666 | |
| 667 | /* set fine tune */ |
| 668 | tunehigh += ((i->finetunecxx . . $ $anonymous_type_2a03d4771abf7e14_0#finetune. + c->finetunecxx . . $ $anonymous_type_2a03d4771abf7e14_1#finetune. + 0x80) & 0xff) - 0x80; |
| 669 | |
| 670 | /* arpeggio handling */ |
| 671 | if(!i->arpeggiocxx . . $ $anonymous_type_2a03d4771abf7e14_0#arpeggio.) { |
| 672 | Uint16cxx . . $ Uint16# arpcalc = i->arp_tabcxx . . $ $anonymous_type_2a03d4771abf7e14_0#arp_tab.[0] << 4; |
| 673 | |
| 674 | if(arpcalc > 0x800) |
| 675 | tunehigh = tunehigh - (arpcalc ^ 0xff0) - 16; |
| 676 | else |
| 677 | tunehigh += arpcalc; |
| 678 | } |
| 679 | |
| 680 | /* glide handling */ |
| 681 | if(c->glidetocxx . . $ $anonymous_type_2a03d4771abf7e14_1#glideto. != 0) { |
| 682 | c->gototunecxx . . $ $anonymous_type_2a03d4771abf7e14_1#gototune. = tunehigh; |
| 683 | c->portspeedcxx . . $ $anonymous_type_2a03d4771abf7e14_1#portspeed. = c->glidetocxx . . $ $anonymous_type_2a03d4771abf7e14_1#glideto.; |
| 684 | c->glidetocxx . . $ $anonymous_type_2a03d4771abf7e14_1#glideto. = c->finetunecxx . . $ $anonymous_type_2a03d4771abf7e14_1#finetune. = 0; |
| 685 | return; |
| 686 | } |
| 687 | |
| 688 | /* set modulator registers */ |
| 689 | lds_setregscxx . . $ lds_setregs(8fbe6856f5410d23).(0x20 + regnum, i->mod_misccxx . . $ $anonymous_type_2a03d4771abf7e14_0#mod_misc.); |
| 690 | volcalc = i->mod_volcxx . . $ $anonymous_type_2a03d4771abf7e14_0#mod_vol.; |
| 691 | if(!c->nextvolcxx . . $ $anonymous_type_2a03d4771abf7e14_1#nextvol. || !(i->feedbackcxx . . $ $anonymous_type_2a03d4771abf7e14_0#feedback. & 1)) |
| 692 | c->volmodcxx . . $ $anonymous_type_2a03d4771abf7e14_1#volmod. = volcalc; |
| 693 | else |
| 694 | c->volmodcxx . . $ $anonymous_type_2a03d4771abf7e14_1#volmod. = (volcalc & 0xc0) | ((((volcalc & 0x3f) * c->nextvolcxx . . $ $anonymous_type_2a03d4771abf7e14_1#nextvol.) >> 6)); |
| 695 | |
| 696 | if((i->feedbackcxx . . $ $anonymous_type_2a03d4771abf7e14_0#feedback. & 1) == 1 && allvolumecxx . . $ allvolume. != 0) |
| 697 | lds_setregscxx . . $ lds_setregs(8fbe6856f5410d23).(0x40 + regnum, ((c->volmodcxx . . $ $anonymous_type_2a03d4771abf7e14_1#volmod. & 0xc0) | (((c->volmodcxx . . $ $anonymous_type_2a03d4771abf7e14_1#volmod. & 0x3f) * allvolumecxx . . $ allvolume.) >> 8)) ^ 0x3f); |
| 698 | else |
| 699 | lds_setregscxx . . $ lds_setregs(8fbe6856f5410d23).(0x40 + regnum, c->volmodcxx . . $ $anonymous_type_2a03d4771abf7e14_1#volmod. ^ 0x3f); |
| 700 | lds_setregscxx . . $ lds_setregs(8fbe6856f5410d23).(0x60 + regnum, i->mod_adcxx . . $ $anonymous_type_2a03d4771abf7e14_0#mod_ad.); |
| 701 | lds_setregscxx . . $ lds_setregs(8fbe6856f5410d23).(0x80 + regnum, i->mod_srcxx . . $ $anonymous_type_2a03d4771abf7e14_0#mod_sr.); |
| 702 | lds_setregscxx . . $ lds_setregs(8fbe6856f5410d23).(0xe0 + regnum, i->mod_wavecxx . . $ $anonymous_type_2a03d4771abf7e14_0#mod_wave.); |
| 703 | |
| 704 | /* Set carrier registers */ |
| 705 | lds_setregscxx . . $ lds_setregs(8fbe6856f5410d23).(0x23 + regnum, i->car_misccxx . . $ $anonymous_type_2a03d4771abf7e14_0#car_misc.); |
| 706 | volcalc = i->car_volcxx . . $ $anonymous_type_2a03d4771abf7e14_0#car_vol.; |
| 707 | if(!c->nextvolcxx . . $ $anonymous_type_2a03d4771abf7e14_1#nextvol.) |
| 708 | c->volcarcxx . . $ $anonymous_type_2a03d4771abf7e14_1#volcar. = volcalc; |
| 709 | else |
| 710 | c->volcarcxx . . $ $anonymous_type_2a03d4771abf7e14_1#volcar. = (volcalc & 0xc0) | ((((volcalc & 0x3f) * c->nextvolcxx . . $ $anonymous_type_2a03d4771abf7e14_1#nextvol.) >> 6)); |
| 711 | |
| 712 | if(allvolumecxx . . $ allvolume.) |
| 713 | lds_setregscxx . . $ lds_setregs(8fbe6856f5410d23).(0x43 + regnum, ((c->volcarcxx . . $ $anonymous_type_2a03d4771abf7e14_1#volcar. & 0xc0) | (((c->volcarcxx . . $ $anonymous_type_2a03d4771abf7e14_1#volcar. & 0x3f) * allvolumecxx . . $ allvolume.) >> 8)) ^ 0x3f); |
| 714 | else |
| 715 | lds_setregscxx . . $ lds_setregs(8fbe6856f5410d23).(0x43 + regnum, c->volcarcxx . . $ $anonymous_type_2a03d4771abf7e14_1#volcar. ^ 0x3f); |
| 716 | lds_setregscxx . . $ lds_setregs(8fbe6856f5410d23).(0x63 + regnum, i->car_adcxx . . $ $anonymous_type_2a03d4771abf7e14_0#car_ad.); |
| 717 | lds_setregscxx . . $ lds_setregs(8fbe6856f5410d23).(0x83 + regnum, i->car_srcxx . . $ $anonymous_type_2a03d4771abf7e14_0#car_sr.); |
| 718 | lds_setregscxx . . $ lds_setregs(8fbe6856f5410d23).(0xe3 + regnum, i->car_wavecxx . . $ $anonymous_type_2a03d4771abf7e14_0#car_wave.); |
| 719 | lds_setregscxx . . $ lds_setregs(8fbe6856f5410d23).(0xc0 + channel_number, i->feedbackcxx . . $ $anonymous_type_2a03d4771abf7e14_0#feedback.); |
| 720 | lds_setregs_advcxx . . $ lds_setregs_adv(684ed43ade99b32e).(0xb0 + channel_number, 0xdf, 0); /* key off */ |
| 721 | |
| 722 | freq = frequencycxx . . $ frequency.[tunehigh % (12 * 16)]; |
| 723 | octave = tunehigh / (12 * 16) - 1; |
| 724 | if(!i->glidecxx . . $ $anonymous_type_2a03d4771abf7e14_0#glide.) { |
| 725 | if(!i->portamentocxx . . $ $anonymous_type_2a03d4771abf7e14_0#portamento. || !c->lasttunecxx . . $ $anonymous_type_2a03d4771abf7e14_1#lasttune.) { |
| 726 | lds_setregscxx . . $ lds_setregs(8fbe6856f5410d23).(0xa0 + channel_number, freq & 0xff); |
| 727 | lds_setregscxx . . $ lds_setregs(8fbe6856f5410d23).(0xb0 + channel_number, (octave << 2) + 0x20 + (freq >> 8)); |
| 728 | c->lasttunecxx . . $ $anonymous_type_2a03d4771abf7e14_1#lasttune. = c->gototunecxx . . $ $anonymous_type_2a03d4771abf7e14_1#gototune. = tunehigh; |
| 729 | } else { |
| 730 | c->gototunecxx . . $ $anonymous_type_2a03d4771abf7e14_1#gototune. = tunehigh; |
| 731 | c->portspeedcxx . . $ $anonymous_type_2a03d4771abf7e14_1#portspeed. = i->portamentocxx . . $ $anonymous_type_2a03d4771abf7e14_0#portamento.; |
| 732 | lds_setregs_advcxx . . $ lds_setregs_adv(684ed43ade99b32e).(0xb0 + channel_number, 0xdf, 0x20); /* key on */ |
| 733 | } |
| 734 | } else { |
| 735 | lds_setregscxx . . $ lds_setregs(8fbe6856f5410d23).(0xa0 + channel_number, freq & 0xff); |
| 736 | lds_setregscxx . . $ lds_setregs(8fbe6856f5410d23).(0xb0 + channel_number, (octave << 2) + 0x20 + (freq >> 8)); |
| 737 | c->lasttunecxx . . $ $anonymous_type_2a03d4771abf7e14_1#lasttune. = tunehigh; |
| 738 | c->gototunecxx . . $ $anonymous_type_2a03d4771abf7e14_1#gototune. = tunehigh + ((i->glidecxx . . $ $anonymous_type_2a03d4771abf7e14_0#glide. + 0x80) & 0xff) - 0x80; /* set destination */ |
| 739 | c->portspeedcxx . . $ $anonymous_type_2a03d4771abf7e14_1#portspeed. = i->portamentocxx . . $ $anonymous_type_2a03d4771abf7e14_0#portamento.; |
| 740 | } |
| 741 | |
| 742 | if(!i->vibratocxx . . $ $anonymous_type_2a03d4771abf7e14_0#vibrato.) |
| 743 | c->vibwaitcxx . . $ $anonymous_type_2a03d4771abf7e14_1#vibwait. = c->vibspeedcxx . . $ $anonymous_type_2a03d4771abf7e14_1#vibspeed. = c->vibratecxx . . $ $anonymous_type_2a03d4771abf7e14_1#vibrate. = 0; |
| 744 | else { |
| 745 | c->vibwaitcxx . . $ $anonymous_type_2a03d4771abf7e14_1#vibwait. = i->vibdelaycxx . . $ $anonymous_type_2a03d4771abf7e14_0#vibdelay.; |
| 746 | /* PASCAL: c->vibspeed = ((i->vibrato >> 4) & 15) + 1; */ |
| 747 | c->vibspeedcxx . . $ $anonymous_type_2a03d4771abf7e14_1#vibspeed. = (i->vibratocxx . . $ $anonymous_type_2a03d4771abf7e14_0#vibrato. >> 4) + 2; |
| 748 | c->vibratecxx . . $ $anonymous_type_2a03d4771abf7e14_1#vibrate. = (i->vibratocxx . . $ $anonymous_type_2a03d4771abf7e14_0#vibrato. & 15) + 1; |
| 749 | } |
| 750 | |
| 751 | if(!(c->trmstaycxx . . $ $anonymous_type_2a03d4771abf7e14_1#trmstay. & 0xf0)) { |
| 752 | c->trmwaitcxx . . $ $anonymous_type_2a03d4771abf7e14_1#trmwait. = (i->tremwaitcxx . . $ $anonymous_type_2a03d4771abf7e14_0#tremwait. & 0xf0) >> 3; |
| 753 | /* PASCAL: c->trmspeed = (i->mod_trem >> 4) & 15; */ |
| 754 | c->trmspeedcxx . . $ $anonymous_type_2a03d4771abf7e14_1#trmspeed. = i->mod_tremcxx . . $ $anonymous_type_2a03d4771abf7e14_0#mod_trem. >> 4; |
| 755 | c->trmratecxx . . $ $anonymous_type_2a03d4771abf7e14_1#trmrate. = i->mod_tremcxx . . $ $anonymous_type_2a03d4771abf7e14_0#mod_trem. & 15; |
| 756 | c->trmcountcxx . . $ $anonymous_type_2a03d4771abf7e14_1#trmcount. = 0; |
| 757 | } |
| 758 | |
| 759 | if(!(c->trmstaycxx . . $ $anonymous_type_2a03d4771abf7e14_1#trmstay. & 0x0f)) { |
| 760 | c->trcwaitcxx . . $ $anonymous_type_2a03d4771abf7e14_1#trcwait. = (i->tremwaitcxx . . $ $anonymous_type_2a03d4771abf7e14_0#tremwait. & 15) << 1; |
| 761 | /* PASCAL: c->trcspeed = (i->car_trem >> 4) & 15; */ |
| 762 | c->trcspeedcxx . . $ $anonymous_type_2a03d4771abf7e14_1#trcspeed. = i->car_tremcxx . . $ $anonymous_type_2a03d4771abf7e14_0#car_trem. >> 4; |
| 763 | c->trcratecxx . . $ $anonymous_type_2a03d4771abf7e14_1#trcrate. = i->car_tremcxx . . $ $anonymous_type_2a03d4771abf7e14_0#car_trem. & 15; |
| 764 | c->trccountcxx . . $ $anonymous_type_2a03d4771abf7e14_1#trccount. = 0; |
| 765 | } |
| 766 | |
| 767 | c->arp_sizecxx . . $ $anonymous_type_2a03d4771abf7e14_1#arp_size. = i->arpeggiocxx . . $ $anonymous_type_2a03d4771abf7e14_0#arpeggio. & 15; |
| 768 | c->arp_speedcxx . . $ $anonymous_type_2a03d4771abf7e14_1#arp_speed. = i->arpeggiocxx . . $ $anonymous_type_2a03d4771abf7e14_0#arpeggio. >> 4; |
| 769 | memcpycxx . . $ memcpy(cc817cb175f282d).(c->arp_tabcxx . . $ $anonymous_type_2a03d4771abf7e14_1#arp_tab., i->arp_tabcxx . . $ $anonymous_type_2a03d4771abf7e14_0#arp_tab., 12); |
| 770 | c->keycountcxx . . $ $anonymous_type_2a03d4771abf7e14_1#keycount. = i->keyoffcxx . . $ $anonymous_type_2a03d4771abf7e14_0#keyoff.; |
| 771 | c->nextvolcxx . . $ $anonymous_type_2a03d4771abf7e14_1#nextvol. = c->glidetocxx . . $ $anonymous_type_2a03d4771abf7e14_1#glideto. = c->finetunecxx . . $ $anonymous_type_2a03d4771abf7e14_1#finetune. = c->vibcountcxx . . $ $anonymous_type_2a03d4771abf7e14_1#vibcount. = c->arp_poscxx . . $ $anonymous_type_2a03d4771abf7e14_1#arp_pos. = c->arp_countcxx . . $ $anonymous_type_2a03d4771abf7e14_1#arp_count. = 0; |
| 772 | } |