| 1 | /* |
| 2 | * Copyright (C) 2002-2010 The DOSBox Team |
| 3 | * OPL2/OPL3 emulation library |
| 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Lesser General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2.1 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library 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 GNU |
| 13 | * Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Lesser General Public |
| 16 | * License along with this library; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | |
| 21 | /* |
| 22 | * Originally based on ADLIBEMU.C, an AdLib/OPL2 emulation library by Ken Silverman |
| 23 | * Copyright (C) 1998-2001 Ken Silverman |
| 24 | * Ken Silverman's official web site: "http://www.advsys.net/ken" |
| 25 | */ |
| 26 | #include "opl.h"cxx . . $ `<file>/src/opl.h`/ |
| 27 | |
| 28 | #include <math.h> |
| 29 | #include <stdbool.h> |
| 30 | #include <stdlib.h> // rand() |
| 31 | #include <string.h> // memset() |
| 32 | |
| 33 | #define fltypecxx . . $ `src/opl.c:33:9`! double |
| 34 | |
| 35 | /* |
| 36 | define attribution that inlines/forces inlining of a function (optional) |
| 37 | */ |
| 38 | #define OPL_INLINEcxx . . $ `src/opl.c:38:9`! inline |
| 39 | |
| 40 | |
| 41 | #undef NUM_CHANNELS |
| 42 | #if defined(OPLTYPE_IS_OPL3) |
| 43 | #define NUM_CHANNELS 18 |
| 44 | #else |
| 45 | #define NUM_CHANNELScxx . . $ `src/opl.c:45:9`! 9 |
| 46 | #endif |
| 47 | |
| 48 | #define MAXOPERATORScxx . . $ `src/opl.c:48:9`! (NUM_CHANNELScxx . . $ `src/opl.c:45:9`!*2) |
| 49 | |
| 50 | |
| 51 | #define FL05cxx . . $ `src/opl.c:51:9`! ((fltypecxx . . $ `src/opl.c:33:9`!)0.5) |
| 52 | #define FL2cxx . . $ `src/opl.c:52:9`! ((fltypecxx . . $ `src/opl.c:33:9`!)2.0) |
| 53 | #define PIcxx . . $ `src/opl.c:53:9`! ((fltypecxx . . $ `src/opl.c:33:9`!)3.1415926535897932384626433832795) |
| 54 | |
| 55 | |
| 56 | #define FIXEDPTcxx . . $ `src/opl.c:56:9`! 0x10000 // fixed-point calculations using 16+16 |
| 57 | #define FIXEDPT_LFOcxx . . $ `src/opl.c:57:9`! 0x1000000 // fixed-point calculations using 8+24 |
| 58 | |
| 59 | #define WAVEPRECcxx . . $ `src/opl.c:59:9`! 1024 // waveform precision (10 bits) |
| 60 | |
| 61 | #define INTFREQUcxx . . $ `src/opl.c:61:9`! ((fltypecxx . . $ `src/opl.c:33:9`!)(14318180.0 / 288.0)) // clocking of the chip |
| 62 | |
| 63 | |
| 64 | #define OF_TYPE_ATTcxx . . $ `src/opl.c:64:9`! 0 |
| 65 | #define OF_TYPE_DECcxx . . $ `src/opl.c:65:9`! 1 |
| 66 | #define OF_TYPE_RELcxx . . $ `src/opl.c:66:9`! 2 |
| 67 | #define OF_TYPE_SUScxx . . $ `src/opl.c:67:9`! 3 |
| 68 | #define OF_TYPE_SUS_NOKEEPcxx . . $ `src/opl.c:68:9`! 4 |
| 69 | #define OF_TYPE_OFFcxx . . $ `src/opl.c:69:9`! 5 |
| 70 | |
| 71 | #define ARC_CONTROLcxx . . $ `src/opl.c:71:9`! 0x00 |
| 72 | #define ARC_TVS_KSR_MULcxx . . $ `src/opl.c:72:9`! 0x20 |
| 73 | #define ARC_KSL_OUTLEVcxx . . $ `src/opl.c:73:9`! 0x40 |
| 74 | #define ARC_ATTR_DECRcxx . . $ `src/opl.c:74:9`! 0x60 |
| 75 | #define ARC_SUSL_RELRcxx . . $ `src/opl.c:75:9`! 0x80 |
| 76 | #define ARC_FREQ_NUMcxx . . $ `src/opl.c:76:9`! 0xa0 |
| 77 | #define ARC_KON_BNUMcxx . . $ `src/opl.c:77:9`! 0xb0 |
| 78 | #define ARC_PERC_MODEcxx . . $ `src/opl.c:78:9`! 0xbd |
| 79 | #define ARC_FEEDBACKcxx . . $ `src/opl.c:79:9`! 0xc0 |
| 80 | #define ARC_WAVE_SELcxx . . $ `src/opl.c:80:9`! 0xe0 |
| 81 | |
| 82 | #define ARC_SECONDSETcxx . . $ `src/opl.c:82:9`! 0x100 // second operator set for OPL3 |
| 83 | |
| 84 | |
| 85 | #define OP_ACT_OFFcxx . . $ `src/opl.c:85:9`! 0x00 |
| 86 | #define OP_ACT_NORMALcxx . . $ `src/opl.c:86:9`! 0x01 // regular channel activated (bitmasked) |
| 87 | #define OP_ACT_PERCcxx . . $ `src/opl.c:87:9`! 0x02 // percussion channel activated (bitmasked) |
| 88 | |
| 89 | #define BLOCKBUF_SIZEcxx . . $ `src/opl.c:89:9`! 512 |
| 90 | |
| 91 | |
| 92 | // vibrato constants |
| 93 | #define VIBTAB_SIZEcxx . . $ `src/opl.c:93:9`! 8 |
| 94 | #define VIBFACcxx . . $ `src/opl.c:94:9`! 70/50000 // no braces, integer mul/div |
| 95 | |
| 96 | // tremolo constants and table |
| 97 | #define TREMTAB_SIZEcxx . . $ `src/opl.c:97:9`! 53 |
| 98 | #define TREM_FREQcxx . . $ `src/opl.c:98:9`! ((fltypecxx . . $ `src/opl.c:33:9`!)(3.7)) // tremolo at 3.7hz |
| 99 | |
| 100 | |
| 101 | /* operator struct definition |
| 102 | For OPL2 all 9 channels consist of two operators each, carrier and modulator. |
| 103 | Channel x has operators x as modulator and operators (9+x) as carrier. |
| 104 | For OPL3 all 18 channels consist either of two operators (2op mode) or four |
| 105 | operators (4op mode) which is determined through register4 of the second |
| 106 | adlib register set. |
| 107 | Only the channels 0,1,2 (first set) and 9,10,11 (second set) can act as |
| 108 | 4op channels. The two additional operators for a channel y come from the |
| 109 | 2op channel y+3 so the operators y, (9+y), y+3, (9+y)+3 make up a 4op |
| 110 | channel. |
| 111 | */ |
| 112 | typedef struct operator_structcxx . . $ operator_struct# { |
| 113 | Bit32scxx . . $ Bit32s# cvalcxx . . $ operator_struct#cval., lastcvalcxx . . $ operator_struct#lastcval.; // current output/last output (used for feedback) |
| 114 | Bit32ucxx . . $ Bit32u# tcountcxx . . $ operator_struct#tcount., wfposcxx . . $ operator_struct#wfpos., tinccxx . . $ operator_struct#tinc.; // time (position in waveform) and time increment |
| 115 | fltypecxx . . $ `src/opl.c:33:9`! ampcxx . . $ operator_struct#amp., step_ampcxx . . $ operator_struct#step_amp.; // and amplification (envelope) |
| 116 | fltypecxx . . $ `src/opl.c:33:9`! volcxx . . $ operator_struct#vol.; // volume |
| 117 | fltypecxx . . $ `src/opl.c:33:9`! sustain_levelcxx . . $ operator_struct#sustain_level.; // sustain level |
| 118 | Bit32scxx . . $ Bit32s# mfbicxx . . $ operator_struct#mfbi.; // feedback amount |
| 119 | fltypecxx . . $ `src/opl.c:33:9`! a0cxx . . $ operator_struct#a0., a1cxx . . $ operator_struct#a1., a2cxx . . $ operator_struct#a2., a3cxx . . $ operator_struct#a3.; // attack rate function coefficients |
| 120 | fltypecxx . . $ `src/opl.c:33:9`! decaymulcxx . . $ operator_struct#decaymul., releasemulcxx . . $ operator_struct#releasemul.; // decay/release rate functions |
| 121 | Bit32ucxx . . $ Bit32u# op_statecxx . . $ operator_struct#op_state.; // current state of operator (attack/decay/sustain/release/off) |
| 122 | Bit32ucxx . . $ Bit32u# toffcxx . . $ operator_struct#toff.; |
| 123 | Bit32scxx . . $ Bit32s# freq_highcxx . . $ operator_struct#freq_high.; // highest three bits of the frequency, used for vibrato calculations |
| 124 | Bit16scxx . . $ Bit16s#* cur_wformcxx . . $ operator_struct#cur_wform.; // start of selected waveform |
| 125 | Bit32ucxx . . $ Bit32u# cur_wmaskcxx . . $ operator_struct#cur_wmask.; // mask for selected waveform |
| 126 | Bit32ucxx . . $ Bit32u# act_statecxx . . $ operator_struct#act_state.; // activity state (regular, percussion) |
| 127 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! sus_keepcxx . . $ operator_struct#sus_keep.; // keep sustain level when decay finished |
| 128 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! vibratocxx . . $ operator_struct#vibrato.,tremolocxx . . $ operator_struct#tremolo.; // vibrato/tremolo enable bits |
| 129 | |
| 130 | // variables used to provide non-continuous envelopes |
| 131 | Bit32ucxx . . $ Bit32u# generator_poscxx . . $ operator_struct#generator_pos.; // for non-standard sample rates we need to determine how many samples have passed |
| 132 | Bitscxx . . $ Bits# cur_env_stepcxx . . $ operator_struct#cur_env_step.; // current (standardized) sample position |
| 133 | Bitscxx . . $ Bits# env_step_acxx . . $ operator_struct#env_step_a.,env_step_dcxx . . $ operator_struct#env_step_d.,env_step_rcxx . . $ operator_struct#env_step_r.; // number of std samples of one step (for attack/decay/release mode) |
| 134 | Bit8ucxx . . $ Bit8u# step_skip_pos_acxx . . $ operator_struct#step_skip_pos_a.; // position of 8-cyclic step skipping (always 2^x to check against mask) |
| 135 | Bitscxx . . $ Bits# env_step_skip_acxx . . $ operator_struct#env_step_skip_a.; // bitmask that determines if a step is skipped (respective bit is zero then) |
| 136 | |
| 137 | #if defined(OPLTYPE_IS_OPL3) |
| 138 | bool is_4op,is_4op_attached; // base of a 4op channel/part of a 4op channel |
| 139 | Bit32s left_pan,right_pan; // opl3 stereo panning amount |
| 140 | #endif |
| 141 | } op_typecxx . . $ op_type#; |
| 142 | |
| 143 | // per-chip variables |
| 144 | static op_typecxx . . $ op_type# opcxx . . $ op.[MAXOPERATORScxx . . $ `src/opl.c:48:9`!]; |
| 145 | |
| 146 | static Bitscxx . . $ Bits# int_sampleratecxx . . $ int_samplerate.; |
| 147 | |
| 148 | static Bit8ucxx . . $ Bit8u# statuscxx . . $ status.; |
| 149 | static Bit32ucxx . . $ Bit32u# opl_indexcxx . . $ opl_index.; |
| 150 | #if defined(OPLTYPE_IS_OPL3) |
| 151 | static Bit8u adlibreg[512]; // adlib register set (including second set) |
| 152 | static Bit8u wave_sel[44]; // waveform selection |
| 153 | #else |
| 154 | static Bit8ucxx . . $ Bit8u# adlibregcxx . . $ adlibreg.[256]; // adlib register set |
| 155 | static Bit8ucxx . . $ Bit8u# wave_selcxx . . $ wave_sel.[22]; // waveform selection |
| 156 | #endif |
| 157 | |
| 158 | |
| 159 | // vibrato/tremolo increment/counter |
| 160 | static Bit32ucxx . . $ Bit32u# vibtab_poscxx . . $ vibtab_pos.; |
| 161 | static Bit32ucxx . . $ Bit32u# vibtab_addcxx . . $ vibtab_add.; |
| 162 | static Bit32ucxx . . $ Bit32u# tremtab_poscxx . . $ tremtab_pos.; |
| 163 | static Bit32ucxx . . $ Bit32u# tremtab_addcxx . . $ tremtab_add.; |
| 164 | |
| 165 | |
| 166 | // enable an operator |
| 167 | void enable_operatorcxx . . $ enable_operator(adfaf86712d24310).(Bitucxx . . $ Bitu# regbase, op_typecxx . . $ op_type#* op_pt, Bit32ucxx . . $ Bit32u# act_type); |
| 168 | |
| 169 | // functions to change parameters of an operator |
| 170 | void change_frequencycxx . . $ change_frequency(cf77c00c7ba6fbcb).(Bitucxx . . $ Bitu# chanbase, Bitucxx . . $ Bitu# regbase, op_typecxx . . $ op_type#* op_pt); |
| 171 | |
| 172 | void change_attackratecxx . . $ change_attackrate(c7b2edb2b789faa1).(Bitucxx . . $ Bitu# regbase, op_typecxx . . $ op_type#* op_pt); |
| 173 | void change_decayratecxx . . $ change_decayrate(c7b2edb2b789faa1).(Bitucxx . . $ Bitu# regbase, op_typecxx . . $ op_type#* op_pt); |
| 174 | void change_releaseratecxx . . $ change_releaserate(c7b2edb2b789faa1).(Bitucxx . . $ Bitu# regbase, op_typecxx . . $ op_type#* op_pt); |
| 175 | void change_sustainlevelcxx . . $ change_sustainlevel(c7b2edb2b789faa1).(Bitucxx . . $ Bitu# regbase, op_typecxx . . $ op_type#* op_pt); |
| 176 | void change_waveformcxx . . $ change_waveform(c7b2edb2b789faa1).(Bitucxx . . $ Bitu# regbase, op_typecxx . . $ op_type#* op_pt); |
| 177 | void change_keepsustaincxx . . $ change_keepsustain(c7b2edb2b789faa1).(Bitucxx . . $ Bitu# regbase, op_typecxx . . $ op_type#* op_pt); |
| 178 | void change_vibratocxx . . $ change_vibrato(c7b2edb2b789faa1).(Bitucxx . . $ Bitu# regbase, op_typecxx . . $ op_type#* op_pt); |
| 179 | void change_feedbackcxx . . $ change_feedback(c7b2edb2b789faa1).(Bitucxx . . $ Bitu# chanbase, op_typecxx . . $ op_type#* op_pt); |
| 180 | |
| 181 | |
| 182 | static Bit32ucxx . . $ Bit32u# generator_addcxx . . $ generator_add.; // should be a chip parameter |
| 183 | |
| 184 | static fltypecxx . . $ `src/opl.c:33:9`! recipsampcxx . . $ recipsamp.; // inverse of sampling rate |
| 185 | static Bit16scxx . . $ Bit16s# wavtablecxx . . $ wavtable.[WAVEPRECcxx . . $ `src/opl.c:59:9`!*3]; // wave form table |
| 186 | |
| 187 | // vibrato/tremolo tables |
| 188 | static Bit32scxx . . $ Bit32s# vib_tablecxx . . $ vib_table.[VIBTAB_SIZEcxx . . $ `src/opl.c:93:9`!]; |
| 189 | static Bit32scxx . . $ Bit32s# trem_tablecxx . . $ trem_table.[TREMTAB_SIZEcxx . . $ `src/opl.c:97:9`!*2]; |
| 190 | |
| 191 | static Bit32scxx . . $ Bit32s# vibval_constcxx . . $ vibval_const.[BLOCKBUF_SIZEcxx . . $ `src/opl.c:89:9`!]; |
| 192 | static Bit32scxx . . $ Bit32s# tremval_constcxx . . $ tremval_const.[BLOCKBUF_SIZEcxx . . $ `src/opl.c:89:9`!]; |
| 193 | |
| 194 | // vibrato value tables (used per-operator) |
| 195 | static Bit32scxx . . $ Bit32s# vibval_var1cxx . . $ vibval_var1.[BLOCKBUF_SIZEcxx . . $ `src/opl.c:89:9`!]; |
| 196 | static Bit32scxx . . $ Bit32s# vibval_var2cxx . . $ vibval_var2.[BLOCKBUF_SIZEcxx . . $ `src/opl.c:89:9`!]; |
| 197 | //static Bit32s vibval_var3[BLOCKBUF_SIZE]; |
| 198 | //static Bit32s vibval_var4[BLOCKBUF_SIZE]; |
| 199 | |
| 200 | // vibrato/trmolo value table pointers |
| 201 | static Bit32scxx . . $ Bit32s# *vibval1cxx . . $ vibval1., *vibval2cxx . . $ vibval2., *vibval3cxx . . $ vibval3., *vibval4cxx . . $ vibval4.; |
| 202 | static Bit32scxx . . $ Bit32s# *tremval1cxx . . $ tremval1., *tremval2cxx . . $ tremval2., *tremval3cxx . . $ tremval3., *tremval4cxx . . $ tremval4.; |
| 203 | |
| 204 | |
| 205 | // key scale level lookup table |
| 206 | static const fltypecxx . . $ `src/opl.c:33:9`! kslmulcxx . . $ kslmul.[4] = { |
| 207 | 0.0, 0.5, 0.25, 1.0 // -> 0, 3, 1.5, 6 dB/oct |
| 208 | }; |
| 209 | |
| 210 | // frequency multiplicator lookup table |
| 211 | static const fltypecxx . . $ `src/opl.c:33:9`! frqmul_tabcxx . . $ frqmul_tab.[16] = { |
| 212 | 0.5,1,2,3,4,5,6,7,8,9,10,10,12,12,15,15 |
| 213 | }; |
| 214 | // calculated frequency multiplication values (depend on sampling rate) |
| 215 | static fltypecxx . . $ `src/opl.c:33:9`! frqmulcxx . . $ frqmul.[16]; |
| 216 | |
| 217 | // key scale levels |
| 218 | static Bit8ucxx . . $ Bit8u# kslevcxx . . $ kslev.[8][16]; |
| 219 | |
| 220 | // map a channel number to the register offset of the modulator (=register base) |
| 221 | static const Bit8ucxx . . $ Bit8u# modulatorbasecxx . . $ modulatorbase.[9] = { |
| 222 | 0,1,2, |
| 223 | 8,9,10, |
| 224 | 16,17,18 |
| 225 | }; |
| 226 | |
| 227 | // map a register base to a modulator operator number or operator number |
| 228 | #if defined(OPLTYPE_IS_OPL3) |
| 229 | static const Bit8u regbase2modop[44] = { |
| 230 | 0,1,2,0,1,2,0,0,3,4,5,3,4,5,0,0,6,7,8,6,7,8, // first set |
| 231 | 18,19,20,18,19,20,0,0,21,22,23,21,22,23,0,0,24,25,26,24,25,26 // second set |
| 232 | }; |
| 233 | static const Bit8u regbase2op[44] = { |
| 234 | 0,1,2,9,10,11,0,0,3,4,5,12,13,14,0,0,6,7,8,15,16,17, // first set |
| 235 | 18,19,20,27,28,29,0,0,21,22,23,30,31,32,0,0,24,25,26,33,34,35 // second set |
| 236 | }; |
| 237 | #else |
| 238 | static const Bit8ucxx . . $ Bit8u# regbase2modopcxx . . $ regbase2modop.[22] = { |
| 239 | 0,1,2,0,1,2,0,0,3,4,5,3,4,5,0,0,6,7,8,6,7,8 |
| 240 | }; |
| 241 | static const Bit8ucxx . . $ Bit8u# regbase2opcxx . . $ regbase2op.[22] = { |
| 242 | 0,1,2,9,10,11,0,0,3,4,5,12,13,14,0,0,6,7,8,15,16,17 |
| 243 | }; |
| 244 | #endif |
| 245 | |
| 246 | |
| 247 | // start of the waveform |
| 248 | static const Bit32ucxx . . $ Bit32u# waveformcxx . . $ waveform.[8] = { |
| 249 | WAVEPRECcxx . . $ `src/opl.c:59:9`!, |
| 250 | WAVEPRECcxx . . $ `src/opl.c:59:9`!>>1, |
| 251 | WAVEPRECcxx . . $ `src/opl.c:59:9`!, |
| 252 | (WAVEPRECcxx . . $ `src/opl.c:59:9`!*3)>>2, |
| 253 | 0, |
| 254 | 0, |
| 255 | (WAVEPRECcxx . . $ `src/opl.c:59:9`!*5)>>2, |
| 256 | WAVEPRECcxx . . $ `src/opl.c:59:9`!<<1 |
| 257 | }; |
| 258 | |
| 259 | // length of the waveform as mask |
| 260 | static const Bit32ucxx . . $ Bit32u# wavemaskcxx . . $ wavemask.[8] = { |
| 261 | WAVEPRECcxx . . $ `src/opl.c:59:9`!-1, |
| 262 | WAVEPRECcxx . . $ `src/opl.c:59:9`!-1, |
| 263 | (WAVEPRECcxx . . $ `src/opl.c:59:9`!>>1)-1, |
| 264 | (WAVEPRECcxx . . $ `src/opl.c:59:9`!>>1)-1, |
| 265 | WAVEPRECcxx . . $ `src/opl.c:59:9`!-1, |
| 266 | ((WAVEPRECcxx . . $ `src/opl.c:59:9`!*3)>>2)-1, |
| 267 | WAVEPRECcxx . . $ `src/opl.c:59:9`!>>1, |
| 268 | WAVEPRECcxx . . $ `src/opl.c:59:9`!-1 |
| 269 | }; |
| 270 | |
| 271 | // where the first entry resides |
| 272 | static const Bit32ucxx . . $ Bit32u# wavestartcxx . . $ wavestart.[8] = { |
| 273 | 0, |
| 274 | WAVEPRECcxx . . $ `src/opl.c:59:9`!>>1, |
| 275 | 0, |
| 276 | WAVEPRECcxx . . $ `src/opl.c:59:9`!>>2, |
| 277 | 0, |
| 278 | 0, |
| 279 | 0, |
| 280 | WAVEPRECcxx . . $ `src/opl.c:59:9`!>>3 |
| 281 | }; |
| 282 | |
| 283 | // envelope generator function constants |
| 284 | static const fltypecxx . . $ `src/opl.c:33:9`! attackconstcxx . . $ attackconst.[4] = { |
| 285 | (fltypecxx . . $ `src/opl.c:33:9`!)(1/2.82624), |
| 286 | (fltypecxx . . $ `src/opl.c:33:9`!)(1/2.25280), |
| 287 | (fltypecxx . . $ `src/opl.c:33:9`!)(1/1.88416), |
| 288 | (fltypecxx . . $ `src/opl.c:33:9`!)(1/1.59744) |
| 289 | }; |
| 290 | static const fltypecxx . . $ `src/opl.c:33:9`! decrelconstcxx . . $ decrelconst.[4] = { |
| 291 | (fltypecxx . . $ `src/opl.c:33:9`!)(1/39.28064), |
| 292 | (fltypecxx . . $ `src/opl.c:33:9`!)(1/31.41608), |
| 293 | (fltypecxx . . $ `src/opl.c:33:9`!)(1/26.17344), |
| 294 | (fltypecxx . . $ `src/opl.c:33:9`!)(1/22.44608) |
| 295 | }; |
| 296 | |
| 297 | |
| 298 | void operator_advancecxx . . $ operator_advance(90c6108e829b6b0c).(op_typecxx . . $ op_type#* op_pt, Bit32scxx . . $ Bit32s# vib) { |
| 299 | op_pt->wfposcxx . . $ operator_struct#wfpos. = op_pt->tcountcxx . . $ operator_struct#tcount.; // waveform position |
| 300 | |
| 301 | // advance waveform time |
| 302 | op_pt->tcountcxx . . $ operator_struct#tcount. += op_pt->tinccxx . . $ operator_struct#tinc.; |
| 303 | op_pt->tcountcxx . . $ operator_struct#tcount. += (Bit32scxx . . $ Bit32s#)(op_pt->tinccxx . . $ operator_struct#tinc.)*vib/FIXEDPTcxx . . $ `src/opl.c:56:9`!; |
| 304 | |
| 305 | op_pt->generator_poscxx . . $ operator_struct#generator_pos. += generator_addcxx . . $ generator_add.; |
| 306 | } |
| 307 | |
| 308 | void operator_advance_drumscxx . . $ operator_advance_drums(5f5b30606dbf8fe8).(op_typecxx . . $ op_type#* op_pt1, Bit32scxx . . $ Bit32s# vib1, op_typecxx . . $ op_type#* op_pt2, Bit32scxx . . $ Bit32s# vib2, op_typecxx . . $ op_type#* op_pt3, Bit32scxx . . $ Bit32s# vib3) { |
| 309 | Bit32ucxx . . $ Bit32u# c1 = op_pt1->tcountcxx . . $ operator_struct#tcount./FIXEDPTcxx . . $ `src/opl.c:56:9`!; |
| 310 | Bit32ucxx . . $ Bit32u# c3 = op_pt3->tcountcxx . . $ operator_struct#tcount./FIXEDPTcxx . . $ `src/opl.c:56:9`!; |
| 311 | Bit32ucxx . . $ Bit32u# phasebit = (((c1 & 0x88) ^ ((c1<<5) & 0x80)) | ((c3 ^ (c3<<2)) & 0x20)) ? 0x02 : 0x00; |
| 312 | |
| 313 | Bit32ucxx . . $ Bit32u# noisebit = randcxx . . $ rand(b126dc7c1de90089).()&1; |
| 314 | |
| 315 | Bit32ucxx . . $ Bit32u# snare_phase_bit = (((Bitucxx . . $ Bitu#)((op_pt1->tcountcxx . . $ operator_struct#tcount./FIXEDPTcxx . . $ `src/opl.c:56:9`!) / 0x100))&1); |
| 316 | |
| 317 | //Hihat |
| 318 | Bit32ucxx . . $ Bit32u# inttm = (phasebit<<8) | (0x34<<(phasebit ^ (noisebit<<1))); |
| 319 | op_pt1->wfposcxx . . $ operator_struct#wfpos. = inttm*FIXEDPTcxx . . $ `src/opl.c:56:9`!; // waveform position |
| 320 | // advance waveform time |
| 321 | op_pt1->tcountcxx . . $ operator_struct#tcount. += op_pt1->tinccxx . . $ operator_struct#tinc.; |
| 322 | op_pt1->tcountcxx . . $ operator_struct#tcount. += (Bit32scxx . . $ Bit32s#)(op_pt1->tinccxx . . $ operator_struct#tinc.)*vib1/FIXEDPTcxx . . $ `src/opl.c:56:9`!; |
| 323 | op_pt1->generator_poscxx . . $ operator_struct#generator_pos. += generator_addcxx . . $ generator_add.; |
| 324 | |
| 325 | //Snare |
| 326 | inttm = ((1+snare_phase_bit) ^ noisebit)<<8; |
| 327 | op_pt2->wfposcxx . . $ operator_struct#wfpos. = inttm*FIXEDPTcxx . . $ `src/opl.c:56:9`!; // waveform position |
| 328 | // advance waveform time |
| 329 | op_pt2->tcountcxx . . $ operator_struct#tcount. += op_pt2->tinccxx . . $ operator_struct#tinc.; |
| 330 | op_pt2->tcountcxx . . $ operator_struct#tcount. += (Bit32scxx . . $ Bit32s#)(op_pt2->tinccxx . . $ operator_struct#tinc.)*vib2/FIXEDPTcxx . . $ `src/opl.c:56:9`!; |
| 331 | op_pt2->generator_poscxx . . $ operator_struct#generator_pos. += generator_addcxx . . $ generator_add.; |
| 332 | |
| 333 | //Cymbal |
| 334 | inttm = (1+phasebit)<<8; |
| 335 | op_pt3->wfposcxx . . $ operator_struct#wfpos. = inttm*FIXEDPTcxx . . $ `src/opl.c:56:9`!; // waveform position |
| 336 | // advance waveform time |
| 337 | op_pt3->tcountcxx . . $ operator_struct#tcount. += op_pt3->tinccxx . . $ operator_struct#tinc.; |
| 338 | op_pt3->tcountcxx . . $ operator_struct#tcount. += (Bit32scxx . . $ Bit32s#)(op_pt3->tinccxx . . $ operator_struct#tinc.)*vib3/FIXEDPTcxx . . $ `src/opl.c:56:9`!; |
| 339 | op_pt3->generator_poscxx . . $ operator_struct#generator_pos. += generator_addcxx . . $ generator_add.; |
| 340 | } |
| 341 | |
| 342 | |
| 343 | // output level is sustained, mode changes only when operator is turned off (->release) |
| 344 | // or when the keep-sustained bit is turned off (->sustain_nokeep) |
| 345 | void operator_outputcxx . . $ operator_output(4521a3a0338f20a).(op_typecxx . . $ op_type#* op_pt, Bit32scxx . . $ Bit32s# modulator, Bit32scxx . . $ Bit32s# trem) { |
| 346 | if (op_pt->op_statecxx . . $ operator_struct#op_state. != OF_TYPE_OFFcxx . . $ `src/opl.c:69:9`!) { |
| 347 | op_pt->lastcvalcxx . . $ operator_struct#lastcval. = op_pt->cvalcxx . . $ operator_struct#cval.; |
| 348 | Bit32ucxx . . $ Bit32u# i = (Bit32ucxx . . $ Bit32u#)((op_pt->wfposcxx . . $ operator_struct#wfpos.+modulator)/FIXEDPTcxx . . $ `src/opl.c:56:9`!); |
| 349 | |
| 350 | // wform: -16384 to 16383 (0x4000) |
| 351 | // trem : 32768 to 65535 (0x10000) |
| 352 | // step_amp: 0.0 to 1.0 |
| 353 | // vol : 1/2^14 to 1/2^29 (/0x4000; /1../0x8000) |
| 354 | |
| 355 | op_pt->cvalcxx . . $ operator_struct#cval. = (Bit32scxx . . $ Bit32s#)(op_pt->step_ampcxx . . $ operator_struct#step_amp.*op_pt->volcxx . . $ operator_struct#vol.*op_pt->cur_wformcxx . . $ operator_struct#cur_wform.[i&op_pt->cur_wmaskcxx . . $ operator_struct#cur_wmask.]*trem/16.0); |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | |
| 360 | // no action, operator is off |
| 361 | void operator_offcxx . . $ operator_off(168d5bc4fc3638e).(op_typecxx . . $ op_type#* op_pt) { |
| 362 | (void) op_pt; |
| 363 | } |
| 364 | |
| 365 | // output level is sustained, mode changes only when operator is turned off (->release) |
| 366 | // or when the keep-sustained bit is turned off (->sustain_nokeep) |
| 367 | void operator_sustaincxx . . $ operator_sustain(168d5bc4fc3638e).(op_typecxx . . $ op_type#* op_pt) { |
| 368 | Bit32ucxx . . $ Bit32u# num_steps_add = op_pt->generator_poscxx . . $ operator_struct#generator_pos./FIXEDPTcxx . . $ `src/opl.c:56:9`!; // number of (standardized) samples |
| 369 | for (Bit32ucxx . . $ Bit32u# ct=0; ct<num_steps_add; ct++) { |
| 370 | op_pt->cur_env_stepcxx . . $ operator_struct#cur_env_step.++; |
| 371 | } |
| 372 | op_pt->generator_poscxx . . $ operator_struct#generator_pos. -= num_steps_add*FIXEDPTcxx . . $ `src/opl.c:56:9`!; |
| 373 | } |
| 374 | |
| 375 | // operator in release mode, if output level reaches zero the operator is turned off |
| 376 | void operator_releasecxx . . $ operator_release(168d5bc4fc3638e).(op_typecxx . . $ op_type#* op_pt) { |
| 377 | // ??? boundary? |
| 378 | if (op_pt->ampcxx . . $ operator_struct#amp. > 0.00000001) { |
| 379 | // release phase |
| 380 | op_pt->ampcxx . . $ operator_struct#amp. *= op_pt->releasemulcxx . . $ operator_struct#releasemul.; |
| 381 | } |
| 382 | |
| 383 | Bit32ucxx . . $ Bit32u# num_steps_add = op_pt->generator_poscxx . . $ operator_struct#generator_pos./FIXEDPTcxx . . $ `src/opl.c:56:9`!; // number of (standardized) samples |
| 384 | for (Bit32ucxx . . $ Bit32u# ct=0; ct<num_steps_add; ct++) { |
| 385 | op_pt->cur_env_stepcxx . . $ operator_struct#cur_env_step.++; // sample counter |
| 386 | if ((op_pt->cur_env_stepcxx . . $ operator_struct#cur_env_step. & op_pt->env_step_rcxx . . $ operator_struct#env_step_r.)==0) { |
| 387 | if (op_pt->ampcxx . . $ operator_struct#amp. <= 0.00000001) { |
| 388 | // release phase finished, turn off this operator |
| 389 | op_pt->ampcxx . . $ operator_struct#amp. = 0.0; |
| 390 | if (op_pt->op_statecxx . . $ operator_struct#op_state. == OF_TYPE_RELcxx . . $ `src/opl.c:66:9`!) { |
| 391 | op_pt->op_statecxx . . $ operator_struct#op_state. = OF_TYPE_OFFcxx . . $ `src/opl.c:69:9`!; |
| 392 | } |
| 393 | } |
| 394 | op_pt->step_ampcxx . . $ operator_struct#step_amp. = op_pt->ampcxx . . $ operator_struct#amp.; |
| 395 | } |
| 396 | } |
| 397 | op_pt->generator_poscxx . . $ operator_struct#generator_pos. -= num_steps_add*FIXEDPTcxx . . $ `src/opl.c:56:9`!; |
| 398 | } |
| 399 | |
| 400 | // operator in decay mode, if sustain level is reached the output level is either |
| 401 | // kept (sustain level keep enabled) or the operator is switched into release mode |
| 402 | void operator_decaycxx . . $ operator_decay(168d5bc4fc3638e).(op_typecxx . . $ op_type#* op_pt) { |
| 403 | if (op_pt->ampcxx . . $ operator_struct#amp. > op_pt->sustain_levelcxx . . $ operator_struct#sustain_level.) { |
| 404 | // decay phase |
| 405 | op_pt->ampcxx . . $ operator_struct#amp. *= op_pt->decaymulcxx . . $ operator_struct#decaymul.; |
| 406 | } |
| 407 | |
| 408 | Bit32ucxx . . $ Bit32u# num_steps_add = op_pt->generator_poscxx . . $ operator_struct#generator_pos./FIXEDPTcxx . . $ `src/opl.c:56:9`!; // number of (standardized) samples |
| 409 | for (Bit32ucxx . . $ Bit32u# ct=0; ct<num_steps_add; ct++) { |
| 410 | op_pt->cur_env_stepcxx . . $ operator_struct#cur_env_step.++; |
| 411 | if ((op_pt->cur_env_stepcxx . . $ operator_struct#cur_env_step. & op_pt->env_step_dcxx . . $ operator_struct#env_step_d.)==0) { |
| 412 | if (op_pt->ampcxx . . $ operator_struct#amp. <= op_pt->sustain_levelcxx . . $ operator_struct#sustain_level.) { |
| 413 | // decay phase finished, sustain level reached |
| 414 | if (op_pt->sus_keepcxx . . $ operator_struct#sus_keep.) { |
| 415 | // keep sustain level (until turned off) |
| 416 | op_pt->op_statecxx . . $ operator_struct#op_state. = OF_TYPE_SUScxx . . $ `src/opl.c:67:9`!; |
| 417 | op_pt->ampcxx . . $ operator_struct#amp. = op_pt->sustain_levelcxx . . $ operator_struct#sustain_level.; |
| 418 | } else { |
| 419 | // next: release phase |
| 420 | op_pt->op_statecxx . . $ operator_struct#op_state. = OF_TYPE_SUS_NOKEEPcxx . . $ `src/opl.c:68:9`!; |
| 421 | } |
| 422 | } |
| 423 | op_pt->step_ampcxx . . $ operator_struct#step_amp. = op_pt->ampcxx . . $ operator_struct#amp.; |
| 424 | } |
| 425 | } |
| 426 | op_pt->generator_poscxx . . $ operator_struct#generator_pos. -= num_steps_add*FIXEDPTcxx . . $ `src/opl.c:56:9`!; |
| 427 | } |
| 428 | |
| 429 | // operator in attack mode, if full output level is reached, |
| 430 | // the operator is switched into decay mode |
| 431 | void operator_attackcxx . . $ operator_attack(168d5bc4fc3638e).(op_typecxx . . $ op_type#* op_pt) { |
| 432 | op_pt->ampcxx . . $ operator_struct#amp. = ((op_pt->a3cxx . . $ operator_struct#a3.*op_pt->ampcxx . . $ operator_struct#amp. + op_pt->a2cxx . . $ operator_struct#a2.)*op_pt->ampcxx . . $ operator_struct#amp. + op_pt->a1cxx . . $ operator_struct#a1.)*op_pt->ampcxx . . $ operator_struct#amp. + op_pt->a0cxx . . $ operator_struct#a0.; |
| 433 | |
| 434 | Bit32ucxx . . $ Bit32u# num_steps_add = op_pt->generator_poscxx . . $ operator_struct#generator_pos./FIXEDPTcxx . . $ `src/opl.c:56:9`!; // number of (standardized) samples |
| 435 | for (Bit32ucxx . . $ Bit32u# ct=0; ct<num_steps_add; ct++) { |
| 436 | op_pt->cur_env_stepcxx . . $ operator_struct#cur_env_step.++; // next sample |
| 437 | if ((op_pt->cur_env_stepcxx . . $ operator_struct#cur_env_step. & op_pt->env_step_acxx . . $ operator_struct#env_step_a.)==0) { // check if next step already reached |
| 438 | if (op_pt->ampcxx . . $ operator_struct#amp. > 1.0) { |
| 439 | // attack phase finished, next: decay |
| 440 | op_pt->op_statecxx . . $ operator_struct#op_state. = OF_TYPE_DECcxx . . $ `src/opl.c:65:9`!; |
| 441 | op_pt->ampcxx . . $ operator_struct#amp. = 1.0; |
| 442 | op_pt->step_ampcxx . . $ operator_struct#step_amp. = 1.0; |
| 443 | } |
| 444 | op_pt->step_skip_pos_acxx . . $ operator_struct#step_skip_pos_a. <<= 1; |
| 445 | if (op_pt->step_skip_pos_acxx . . $ operator_struct#step_skip_pos_a.==0) op_pt->step_skip_pos_acxx . . $ operator_struct#step_skip_pos_a. = 1; |
| 446 | if (op_pt->step_skip_pos_acxx . . $ operator_struct#step_skip_pos_a. & op_pt->env_step_skip_acxx . . $ operator_struct#env_step_skip_a.) { // check if required to skip next step |
| 447 | op_pt->step_ampcxx . . $ operator_struct#step_amp. = op_pt->ampcxx . . $ operator_struct#amp.; |
| 448 | } |
| 449 | } |
| 450 | } |
| 451 | op_pt->generator_poscxx . . $ operator_struct#generator_pos. -= num_steps_add*FIXEDPTcxx . . $ `src/opl.c:56:9`!; |
| 452 | } |
| 453 | |
| 454 | |
| 455 | typedef void (*optype_fptrcxx . . $ optype_fptr#)(op_typecxx . . $ op_type#*); |
| 456 | |
| 457 | const optype_fptrcxx . . $ optype_fptr# opfuncscxx . . $ opfuncs.[6] = { |
| 458 | operator_attackcxx . . $ operator_attack(168d5bc4fc3638e)., |
| 459 | operator_decaycxx . . $ operator_decay(168d5bc4fc3638e)., |
| 460 | operator_releasecxx . . $ operator_release(168d5bc4fc3638e)., |
| 461 | operator_sustaincxx . . $ operator_sustain(168d5bc4fc3638e)., // sustain phase (keeping level) |
| 462 | operator_releasecxx . . $ operator_release(168d5bc4fc3638e)., // sustain_nokeep phase (release-style) |
| 463 | operator_offcxx . . $ operator_off(168d5bc4fc3638e). |
| 464 | }; |
| 465 | |
| 466 | void change_attackratecxx . . $ change_attackrate(c7b2edb2b789faa1).(Bitucxx . . $ Bitu# regbase, op_typecxx . . $ op_type#* op_pt) { |
| 467 | Bitscxx . . $ Bits# attackrate = adlibregcxx . . $ adlibreg.[ARC_ATTR_DECRcxx . . $ `src/opl.c:74:9`!+regbase]>>4; |
| 468 | if (attackrate) { |
| 469 | fltypecxx . . $ `src/opl.c:33:9`! f = (fltypecxx . . $ `src/opl.c:33:9`!)(powcxx . . $ pow(d8e7e0733fa41c87).(FL2cxx . . $ `src/opl.c:52:9`!,(fltypecxx . . $ `src/opl.c:33:9`!)attackrate+(op_pt->toffcxx . . $ operator_struct#toff.>>2)-1)*attackconstcxx . . $ attackconst.[op_pt->toffcxx . . $ operator_struct#toff.&3]*recipsampcxx . . $ recipsamp.); |
| 470 | // attack rate coefficients |
| 471 | op_pt->a0cxx . . $ operator_struct#a0. = (fltypecxx . . $ `src/opl.c:33:9`!)(0.0377*f); |
| 472 | op_pt->a1cxx . . $ operator_struct#a1. = (fltypecxx . . $ `src/opl.c:33:9`!)(10.73*f+1); |
| 473 | op_pt->a2cxx . . $ operator_struct#a2. = (fltypecxx . . $ `src/opl.c:33:9`!)(-17.57*f); |
| 474 | op_pt->a3cxx . . $ operator_struct#a3. = (fltypecxx . . $ `src/opl.c:33:9`!)(7.42*f); |
| 475 | |
| 476 | Bitscxx . . $ Bits# step_skip = attackrate*4 + op_pt->toffcxx . . $ operator_struct#toff.; |
| 477 | Bitscxx . . $ Bits# steps = step_skip >> 2; |
| 478 | op_pt->env_step_acxx . . $ operator_struct#env_step_a. = (1<<(steps<=12?12-steps:0))-1; |
| 479 | |
| 480 | Bitscxx . . $ Bits# step_num = (step_skip<=48)?(4-(step_skip&3)):0; |
| 481 | static const Bit8ucxx . . $ Bit8u# step_skip_mask[5] = {0xff, 0xfe, 0xee, 0xba, 0xaa}; |
| 482 | op_pt->env_step_skip_acxx . . $ operator_struct#env_step_skip_a. = step_skip_mask[step_num]; |
| 483 | |
| 484 | #if defined(OPLTYPE_IS_OPL3) |
| 485 | if (step_skip>=60) { |
| 486 | #else |
| 487 | if (step_skip>=62) { |
| 488 | #endif |
| 489 | op_pt->a0cxx . . $ operator_struct#a0. = (fltypecxx . . $ `src/opl.c:33:9`!)(2.0); // something that triggers an immediate transition to amp:=1.0 |
| 490 | op_pt->a1cxx . . $ operator_struct#a1. = (fltypecxx . . $ `src/opl.c:33:9`!)(0.0); |
| 491 | op_pt->a2cxx . . $ operator_struct#a2. = (fltypecxx . . $ `src/opl.c:33:9`!)(0.0); |
| 492 | op_pt->a3cxx . . $ operator_struct#a3. = (fltypecxx . . $ `src/opl.c:33:9`!)(0.0); |
| 493 | } |
| 494 | } else { |
| 495 | // attack disabled |
| 496 | op_pt->a0cxx . . $ operator_struct#a0. = 0.0; |
| 497 | op_pt->a1cxx . . $ operator_struct#a1. = 1.0; |
| 498 | op_pt->a2cxx . . $ operator_struct#a2. = 0.0; |
| 499 | op_pt->a3cxx . . $ operator_struct#a3. = 0.0; |
| 500 | op_pt->env_step_acxx . . $ operator_struct#env_step_a. = 0; |
| 501 | op_pt->env_step_skip_acxx . . $ operator_struct#env_step_skip_a. = 0; |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | void change_decayratecxx . . $ change_decayrate(c7b2edb2b789faa1).(Bitucxx . . $ Bitu# regbase, op_typecxx . . $ op_type#* op_pt) { |
| 506 | Bitscxx . . $ Bits# decayrate = adlibregcxx . . $ adlibreg.[ARC_ATTR_DECRcxx . . $ `src/opl.c:74:9`!+regbase]&15; |
| 507 | // decaymul should be 1.0 when decayrate==0 |
| 508 | if (decayrate) { |
| 509 | fltypecxx . . $ `src/opl.c:33:9`! f = (fltypecxx . . $ `src/opl.c:33:9`!)(-7.4493*decrelconstcxx . . $ decrelconst.[op_pt->toffcxx . . $ operator_struct#toff.&3]*recipsampcxx . . $ recipsamp.); |
| 510 | op_pt->decaymulcxx . . $ operator_struct#decaymul. = (fltypecxx . . $ `src/opl.c:33:9`!)(powcxx . . $ pow(d8e7e0733fa41c87).(FL2cxx . . $ `src/opl.c:52:9`!,f*powcxx . . $ pow(d8e7e0733fa41c87).(FL2cxx . . $ `src/opl.c:52:9`!,(fltypecxx . . $ `src/opl.c:33:9`!)(decayrate+(op_pt->toffcxx . . $ operator_struct#toff.>>2))))); |
| 511 | Bitscxx . . $ Bits# steps = (decayrate*4 + op_pt->toffcxx . . $ operator_struct#toff.) >> 2; |
| 512 | op_pt->env_step_dcxx . . $ operator_struct#env_step_d. = (1<<(steps<=12?12-steps:0))-1; |
| 513 | } else { |
| 514 | op_pt->decaymulcxx . . $ operator_struct#decaymul. = 1.0; |
| 515 | op_pt->env_step_dcxx . . $ operator_struct#env_step_d. = 0; |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | void change_releaseratecxx . . $ change_releaserate(c7b2edb2b789faa1).(Bitucxx . . $ Bitu# regbase, op_typecxx . . $ op_type#* op_pt) { |
| 520 | Bitscxx . . $ Bits# releaserate = adlibregcxx . . $ adlibreg.[ARC_SUSL_RELRcxx . . $ `src/opl.c:75:9`!+regbase]&15; |
| 521 | // releasemul should be 1.0 when releaserate==0 |
| 522 | if (releaserate) { |
| 523 | fltypecxx . . $ `src/opl.c:33:9`! f = (fltypecxx . . $ `src/opl.c:33:9`!)(-7.4493*decrelconstcxx . . $ decrelconst.[op_pt->toffcxx . . $ operator_struct#toff.&3]*recipsampcxx . . $ recipsamp.); |
| 524 | op_pt->releasemulcxx . . $ operator_struct#releasemul. = (fltypecxx . . $ `src/opl.c:33:9`!)(powcxx . . $ pow(d8e7e0733fa41c87).(FL2cxx . . $ `src/opl.c:52:9`!,f*powcxx . . $ pow(d8e7e0733fa41c87).(FL2cxx . . $ `src/opl.c:52:9`!,(fltypecxx . . $ `src/opl.c:33:9`!)(releaserate+(op_pt->toffcxx . . $ operator_struct#toff.>>2))))); |
| 525 | Bitscxx . . $ Bits# steps = (releaserate*4 + op_pt->toffcxx . . $ operator_struct#toff.) >> 2; |
| 526 | op_pt->env_step_rcxx . . $ operator_struct#env_step_r. = (1<<(steps<=12?12-steps:0))-1; |
| 527 | } else { |
| 528 | op_pt->releasemulcxx . . $ operator_struct#releasemul. = 1.0; |
| 529 | op_pt->env_step_rcxx . . $ operator_struct#env_step_r. = 0; |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | void change_sustainlevelcxx . . $ change_sustainlevel(c7b2edb2b789faa1).(Bitucxx . . $ Bitu# regbase, op_typecxx . . $ op_type#* op_pt) { |
| 534 | Bitscxx . . $ Bits# sustainlevel = adlibregcxx . . $ adlibreg.[ARC_SUSL_RELRcxx . . $ `src/opl.c:75:9`!+regbase]>>4; |
| 535 | // sustainlevel should be 0.0 when sustainlevel==15 (max) |
| 536 | if (sustainlevel<15) { |
| 537 | op_pt->sustain_levelcxx . . $ operator_struct#sustain_level. = (fltypecxx . . $ `src/opl.c:33:9`!)(powcxx . . $ pow(d8e7e0733fa41c87).(FL2cxx . . $ `src/opl.c:52:9`!,(fltypecxx . . $ `src/opl.c:33:9`!)sustainlevel * (-FL05cxx . . $ `src/opl.c:51:9`!))); |
| 538 | } else { |
| 539 | op_pt->sustain_levelcxx . . $ operator_struct#sustain_level. = 0.0; |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | void change_waveformcxx . . $ change_waveform(c7b2edb2b789faa1).(Bitucxx . . $ Bitu# regbase, op_typecxx . . $ op_type#* op_pt) { |
| 544 | #if defined(OPLTYPE_IS_OPL3) |
| 545 | if (regbase>=ARC_SECONDSET) regbase -= (ARC_SECONDSET-22); // second set starts at 22 |
| 546 | #endif |
| 547 | // waveform selection |
| 548 | op_pt->cur_wmaskcxx . . $ operator_struct#cur_wmask. = wavemaskcxx . . $ wavemask.[wave_selcxx . . $ wave_sel.[regbase]]; |
| 549 | op_pt->cur_wformcxx . . $ operator_struct#cur_wform. = &wavtablecxx . . $ wavtable.[waveformcxx . . $ waveform.[wave_selcxx . . $ wave_sel.[regbase]]]; |
| 550 | // (might need to be adapted to waveform type here...) |
| 551 | } |
| 552 | |
| 553 | void change_keepsustaincxx . . $ change_keepsustain(c7b2edb2b789faa1).(Bitucxx . . $ Bitu# regbase, op_typecxx . . $ op_type#* op_pt) { |
| 554 | op_pt->sus_keepcxx . . $ operator_struct#sus_keep. = (adlibregcxx . . $ adlibreg.[ARC_TVS_KSR_MULcxx . . $ `src/opl.c:72:9`!+regbase]&0x20)>0; |
| 555 | if (op_pt->op_statecxx . . $ operator_struct#op_state.==OF_TYPE_SUScxx . . $ `src/opl.c:67:9`!) { |
| 556 | if (!op_pt->sus_keepcxx . . $ operator_struct#sus_keep.) op_pt->op_statecxx . . $ operator_struct#op_state. = OF_TYPE_SUS_NOKEEPcxx . . $ `src/opl.c:68:9`!; |
| 557 | } else if (op_pt->op_statecxx . . $ operator_struct#op_state.==OF_TYPE_SUS_NOKEEPcxx . . $ `src/opl.c:68:9`!) { |
| 558 | if (op_pt->sus_keepcxx . . $ operator_struct#sus_keep.) op_pt->op_statecxx . . $ operator_struct#op_state. = OF_TYPE_SUScxx . . $ `src/opl.c:67:9`!; |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // enable/disable vibrato/tremolo LFO effects |
| 563 | void change_vibratocxx . . $ change_vibrato(c7b2edb2b789faa1).(Bitucxx . . $ Bitu# regbase, op_typecxx . . $ op_type#* op_pt) { |
| 564 | op_pt->vibratocxx . . $ operator_struct#vibrato. = (adlibregcxx . . $ adlibreg.[ARC_TVS_KSR_MULcxx . . $ `src/opl.c:72:9`!+regbase]&0x40)!=0; |
| 565 | op_pt->tremolocxx . . $ operator_struct#tremolo. = (adlibregcxx . . $ adlibreg.[ARC_TVS_KSR_MULcxx . . $ `src/opl.c:72:9`!+regbase]&0x80)!=0; |
| 566 | } |
| 567 | |
| 568 | // change amount of self-feedback |
| 569 | void change_feedbackcxx . . $ change_feedback(c7b2edb2b789faa1).(Bitucxx . . $ Bitu# chanbase, op_typecxx . . $ op_type#* op_pt) { |
| 570 | Bitscxx . . $ Bits# feedback = adlibregcxx . . $ adlibreg.[ARC_FEEDBACKcxx . . $ `src/opl.c:79:9`!+chanbase]&14; |
| 571 | if (feedback) op_pt->mfbicxx . . $ operator_struct#mfbi. = (Bit32scxx . . $ Bit32s#)(powcxx . . $ pow(d8e7e0733fa41c87).(FL2cxx . . $ `src/opl.c:52:9`!,(fltypecxx . . $ `src/opl.c:33:9`!)((feedback>>1)+8))); |
| 572 | else op_pt->mfbicxx . . $ operator_struct#mfbi. = 0; |
| 573 | } |
| 574 | |
| 575 | void change_frequencycxx . . $ change_frequency(cf77c00c7ba6fbcb).(Bitucxx . . $ Bitu# chanbase, Bitucxx . . $ Bitu# regbase, op_typecxx . . $ op_type#* op_pt) { |
| 576 | // frequency |
| 577 | Bit32ucxx . . $ Bit32u# frn = ((((Bit32ucxx . . $ Bit32u#)adlibregcxx . . $ adlibreg.[ARC_KON_BNUMcxx . . $ `src/opl.c:77:9`!+chanbase])&3)<<8) + (Bit32ucxx . . $ Bit32u#)adlibregcxx . . $ adlibreg.[ARC_FREQ_NUMcxx . . $ `src/opl.c:76:9`!+chanbase]; |
| 578 | // block number/octave |
| 579 | Bit32ucxx . . $ Bit32u# oct = ((((Bit32ucxx . . $ Bit32u#)adlibregcxx . . $ adlibreg.[ARC_KON_BNUMcxx . . $ `src/opl.c:77:9`!+chanbase])>>2)&7); |
| 580 | op_pt->freq_highcxx . . $ operator_struct#freq_high. = (Bit32scxx . . $ Bit32s#)((frn>>7)&7); |
| 581 | |
| 582 | // keysplit |
| 583 | Bit32ucxx . . $ Bit32u# note_sel = (adlibregcxx . . $ adlibreg.[8]>>6)&1; |
| 584 | op_pt->toffcxx . . $ operator_struct#toff. = ((frn>>9)&(note_sel^1)) | ((frn>>8)¬e_sel); |
| 585 | op_pt->toffcxx . . $ operator_struct#toff. += (oct<<1); |
| 586 | |
| 587 | // envelope scaling (KSR) |
| 588 | if (!(adlibregcxx . . $ adlibreg.[ARC_TVS_KSR_MULcxx . . $ `src/opl.c:72:9`!+regbase]&0x10)) op_pt->toffcxx . . $ operator_struct#toff. >>= 2; |
| 589 | |
| 590 | // 20+a0+b0: |
| 591 | op_pt->tinccxx . . $ operator_struct#tinc. = (Bit32ucxx . . $ Bit32u#)((((fltypecxx . . $ `src/opl.c:33:9`!)(frn<<oct))*frqmulcxx . . $ frqmul.[adlibregcxx . . $ adlibreg.[ARC_TVS_KSR_MULcxx . . $ `src/opl.c:72:9`!+regbase]&15])); |
| 592 | // 40+a0+b0: |
| 593 | fltypecxx . . $ `src/opl.c:33:9`! vol_in = (fltypecxx . . $ `src/opl.c:33:9`!)((fltypecxx . . $ `src/opl.c:33:9`!)(adlibregcxx . . $ adlibreg.[ARC_KSL_OUTLEVcxx . . $ `src/opl.c:73:9`!+regbase]&63) + |
| 594 | kslmulcxx . . $ kslmul.[adlibregcxx . . $ adlibreg.[ARC_KSL_OUTLEVcxx . . $ `src/opl.c:73:9`!+regbase]>>6]*kslevcxx . . $ kslev.[oct][frn>>6]); |
| 595 | op_pt->volcxx . . $ operator_struct#vol. = (fltypecxx . . $ `src/opl.c:33:9`!)(powcxx . . $ pow(d8e7e0733fa41c87).(FL2cxx . . $ `src/opl.c:52:9`!,(fltypecxx . . $ `src/opl.c:33:9`!)(vol_in * -0.125 - 14))); |
| 596 | |
| 597 | // operator frequency changed, care about features that depend on it |
| 598 | change_attackratecxx . . $ change_attackrate(c7b2edb2b789faa1).(regbase,op_pt); |
| 599 | change_decayratecxx . . $ change_decayrate(c7b2edb2b789faa1).(regbase,op_pt); |
| 600 | change_releaseratecxx . . $ change_releaserate(c7b2edb2b789faa1).(regbase,op_pt); |
| 601 | } |
| 602 | |
| 603 | void enable_operatorcxx . . $ enable_operator(adfaf86712d24310).(Bitucxx . . $ Bitu# regbase, op_typecxx . . $ op_type#* op_pt, Bit32ucxx . . $ Bit32u# act_type) { |
| 604 | // check if this is really an off-on transition |
| 605 | if (op_pt->act_statecxx . . $ operator_struct#act_state. == OP_ACT_OFFcxx . . $ `src/opl.c:85:9`!) { |
| 606 | Bitscxx . . $ Bits# wselbase = regbase; |
| 607 | if (wselbase>=ARC_SECONDSETcxx . . $ `src/opl.c:82:9`!) wselbase -= (ARC_SECONDSETcxx . . $ `src/opl.c:82:9`!-22); // second set starts at 22 |
| 608 | |
| 609 | op_pt->tcountcxx . . $ operator_struct#tcount. = wavestartcxx . . $ wavestart.[wave_selcxx . . $ wave_sel.[wselbase]]*FIXEDPTcxx . . $ `src/opl.c:56:9`!; |
| 610 | |
| 611 | // start with attack mode |
| 612 | op_pt->op_statecxx . . $ operator_struct#op_state. = OF_TYPE_ATTcxx . . $ `src/opl.c:64:9`!; |
| 613 | op_pt->act_statecxx . . $ operator_struct#act_state. |= act_type; |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | void disable_operatorcxx . . $ disable_operator(556949c3686164d).(op_typecxx . . $ op_type#* op_pt, Bit32ucxx . . $ Bit32u# act_type) { |
| 618 | // check if this is really an on-off transition |
| 619 | if (op_pt->act_statecxx . . $ operator_struct#act_state. != OP_ACT_OFFcxx . . $ `src/opl.c:85:9`!) { |
| 620 | op_pt->act_statecxx . . $ operator_struct#act_state. &= (~act_type); |
| 621 | if (op_pt->act_statecxx . . $ operator_struct#act_state. == OP_ACT_OFFcxx . . $ `src/opl.c:85:9`!) { |
| 622 | if (op_pt->op_statecxx . . $ operator_struct#op_state. != OF_TYPE_OFFcxx . . $ `src/opl.c:69:9`!) op_pt->op_statecxx . . $ operator_struct#op_state. = OF_TYPE_RELcxx . . $ `src/opl.c:66:9`!; |
| 623 | } |
| 624 | } |
| 625 | } |
| 626 | |
| 627 | void adlib_initcxx . . $ adlib_init(cb2f890c2fdad230).(Bit32ucxx . . $ Bit32u# samplerate) { |
| 628 | Bitscxx . . $ Bits# i, j, oct; |
| 629 | |
| 630 | int_sampleratecxx . . $ int_samplerate. = samplerate; |
| 631 | |
| 632 | generator_addcxx . . $ generator_add. = (Bit32ucxx . . $ Bit32u#)(INTFREQUcxx . . $ `src/opl.c:61:9`!*FIXEDPTcxx . . $ `src/opl.c:56:9`!/int_sampleratecxx . . $ int_samplerate.); |
| 633 | |
| 634 | |
| 635 | memsetcxx . . $ memset(d1de1e4fb215f1c6).((void *)adlibregcxx . . $ adlibreg.,0,sizeof(adlibregcxx . . $ adlibreg.)); |
| 636 | memsetcxx . . $ memset(d1de1e4fb215f1c6).((void *)opcxx . . $ op.,0,sizeof(op_typecxx . . $ op_type#)*MAXOPERATORScxx . . $ `src/opl.c:48:9`!); |
| 637 | memsetcxx . . $ memset(d1de1e4fb215f1c6).((void *)wave_selcxx . . $ wave_sel.,0,sizeof(wave_selcxx . . $ wave_sel.)); |
| 638 | |
| 639 | for (i=0;i<MAXOPERATORScxx . . $ `src/opl.c:48:9`!;i++) { |
| 640 | opcxx . . $ op.[i].op_statecxx . . $ operator_struct#op_state. = OF_TYPE_OFFcxx . . $ `src/opl.c:69:9`!; |
| 641 | opcxx . . $ op.[i].act_statecxx . . $ operator_struct#act_state. = OP_ACT_OFFcxx . . $ `src/opl.c:85:9`!; |
| 642 | opcxx . . $ op.[i].ampcxx . . $ operator_struct#amp. = 0.0; |
| 643 | opcxx . . $ op.[i].step_ampcxx . . $ operator_struct#step_amp. = 0.0; |
| 644 | opcxx . . $ op.[i].volcxx . . $ operator_struct#vol. = 0.0; |
| 645 | opcxx . . $ op.[i].tcountcxx . . $ operator_struct#tcount. = 0; |
| 646 | opcxx . . $ op.[i].tinccxx . . $ operator_struct#tinc. = 0; |
| 647 | opcxx . . $ op.[i].toffcxx . . $ operator_struct#toff. = 0; |
| 648 | opcxx . . $ op.[i].cur_wmaskcxx . . $ operator_struct#cur_wmask. = wavemaskcxx . . $ wavemask.[0]; |
| 649 | opcxx . . $ op.[i].cur_wformcxx . . $ operator_struct#cur_wform. = &wavtablecxx . . $ wavtable.[waveformcxx . . $ waveform.[0]]; |
| 650 | opcxx . . $ op.[i].freq_highcxx . . $ operator_struct#freq_high. = 0; |
| 651 | |
| 652 | opcxx . . $ op.[i].generator_poscxx . . $ operator_struct#generator_pos. = 0; |
| 653 | opcxx . . $ op.[i].cur_env_stepcxx . . $ operator_struct#cur_env_step. = 0; |
| 654 | opcxx . . $ op.[i].env_step_acxx . . $ operator_struct#env_step_a. = 0; |
| 655 | opcxx . . $ op.[i].env_step_dcxx . . $ operator_struct#env_step_d. = 0; |
| 656 | opcxx . . $ op.[i].env_step_rcxx . . $ operator_struct#env_step_r. = 0; |
| 657 | opcxx . . $ op.[i].step_skip_pos_acxx . . $ operator_struct#step_skip_pos_a. = 0; |
| 658 | opcxx . . $ op.[i].env_step_skip_acxx . . $ operator_struct#env_step_skip_a. = 0; |
| 659 | |
| 660 | #if defined(OPLTYPE_IS_OPL3) |
| 661 | op[i].is_4op = false; |
| 662 | op[i].is_4op_attached = false; |
| 663 | op[i].left_pan = 1; |
| 664 | op[i].right_pan = 1; |
| 665 | #endif |
| 666 | } |
| 667 | |
| 668 | recipsampcxx . . $ recipsamp. = 1.0 / (fltypecxx . . $ `src/opl.c:33:9`!)int_sampleratecxx . . $ int_samplerate.; |
| 669 | for (i=15;i>=0;i--) { |
| 670 | frqmulcxx . . $ frqmul.[i] = (fltypecxx . . $ `src/opl.c:33:9`!)(frqmul_tabcxx . . $ frqmul_tab.[i]*INTFREQUcxx . . $ `src/opl.c:61:9`!/(fltypecxx . . $ `src/opl.c:33:9`!)WAVEPRECcxx . . $ `src/opl.c:59:9`!*(fltypecxx . . $ `src/opl.c:33:9`!)FIXEDPTcxx . . $ `src/opl.c:56:9`!*recipsampcxx . . $ recipsamp.); |
| 671 | } |
| 672 | |
| 673 | statuscxx . . $ status. = 0; |
| 674 | opl_indexcxx . . $ opl_index. = 0; |
| 675 | |
| 676 | |
| 677 | // create vibrato table |
| 678 | vib_tablecxx . . $ vib_table.[0] = 8; |
| 679 | vib_tablecxx . . $ vib_table.[1] = 4; |
| 680 | vib_tablecxx . . $ vib_table.[2] = 0; |
| 681 | vib_tablecxx . . $ vib_table.[3] = -4; |
| 682 | for (i=4; i<VIBTAB_SIZEcxx . . $ `src/opl.c:93:9`!; i++) vib_tablecxx . . $ vib_table.[i] = vib_tablecxx . . $ vib_table.[i-4]*-1; |
| 683 | |
| 684 | // vibrato at ~6.1 ?? (opl3 docs say 6.1, opl4 docs say 6.0, y8950 docs say 6.4) |
| 685 | vibtab_addcxx . . $ vibtab_add. = (Bit32ucxx . . $ Bit32u#)(VIBTAB_SIZEcxx . . $ `src/opl.c:93:9`!*FIXEDPT_LFOcxx . . $ `src/opl.c:57:9`!/8192*INTFREQUcxx . . $ `src/opl.c:61:9`!/int_sampleratecxx . . $ int_samplerate.); |
| 686 | vibtab_poscxx . . $ vibtab_pos. = 0; |
| 687 | |
| 688 | for (i=0; i<BLOCKBUF_SIZEcxx . . $ `src/opl.c:89:9`!; i++) vibval_constcxx . . $ vibval_const.[i] = 0; |
| 689 | |
| 690 | |
| 691 | // create tremolo table |
| 692 | Bit32scxx . . $ Bit32s# trem_table_int[TREMTAB_SIZEcxx . . $ `src/opl.c:97:9`!]; |
| 693 | for (i=0; i<14; i++) trem_table_int[i] = i-13; // upwards (13 to 26 -> -0.5/6 to 0) |
| 694 | for (i=14; i<41; i++) trem_table_int[i] = -i+14; // downwards (26 to 0 -> 0 to -1/6) |
| 695 | for (i=41; i<53; i++) trem_table_int[i] = i-40-26; // upwards (1 to 12 -> -1/6 to -0.5/6) |
| 696 | |
| 697 | for (i=0; i<TREMTAB_SIZEcxx . . $ `src/opl.c:97:9`!; i++) { |
| 698 | // 0.0 .. -26/26*4.8/6 == [0.0 .. -0.8], 4/53 steps == [1 .. 0.57] |
| 699 | fltypecxx . . $ `src/opl.c:33:9`! trem_val1=(fltypecxx . . $ `src/opl.c:33:9`!)(((fltypecxx . . $ `src/opl.c:33:9`!)trem_table_int[i])*4.8/26.0/6.0); // 4.8db |
| 700 | fltypecxx . . $ `src/opl.c:33:9`! trem_val2=(fltypecxx . . $ `src/opl.c:33:9`!)((fltypecxx . . $ `src/opl.c:33:9`!)((Bit32scxx . . $ Bit32s#)(trem_table_int[i]/4))*1.2/6.0/6.0); // 1.2db (larger stepping) |
| 701 | |
| 702 | trem_tablecxx . . $ trem_table.[i] = (Bit32scxx . . $ Bit32s#)(powcxx . . $ pow(d8e7e0733fa41c87).(FL2cxx . . $ `src/opl.c:52:9`!,trem_val1)*FIXEDPTcxx . . $ `src/opl.c:56:9`!); |
| 703 | trem_tablecxx . . $ trem_table.[TREMTAB_SIZEcxx . . $ `src/opl.c:97:9`!+i] = (Bit32scxx . . $ Bit32s#)(powcxx . . $ pow(d8e7e0733fa41c87).(FL2cxx . . $ `src/opl.c:52:9`!,trem_val2)*FIXEDPTcxx . . $ `src/opl.c:56:9`!); |
| 704 | } |
| 705 | |
| 706 | // tremolo at 3.7hz |
| 707 | tremtab_addcxx . . $ tremtab_add. = (Bit32ucxx . . $ Bit32u#)((fltypecxx . . $ `src/opl.c:33:9`!)TREMTAB_SIZEcxx . . $ `src/opl.c:97:9`! * TREM_FREQcxx . . $ `src/opl.c:98:9`! * FIXEDPT_LFOcxx . . $ `src/opl.c:57:9`! / (fltypecxx . . $ `src/opl.c:33:9`!)int_sampleratecxx . . $ int_samplerate.); |
| 708 | tremtab_poscxx . . $ tremtab_pos. = 0; |
| 709 | |
| 710 | for (i=0; i<BLOCKBUF_SIZEcxx . . $ `src/opl.c:89:9`!; i++) tremval_constcxx . . $ tremval_const.[i] = FIXEDPTcxx . . $ `src/opl.c:56:9`!; |
| 711 | |
| 712 | |
| 713 | static Bitucxx . . $ Bitu# initfirstime = 0; |
| 714 | if (!initfirstime) { |
| 715 | initfirstime = 1; |
| 716 | |
| 717 | // create waveform tables |
| 718 | for (i=0;i<(WAVEPRECcxx . . $ `src/opl.c:59:9`!>>1);i++) { |
| 719 | wavtablecxx . . $ wavtable.[(i<<1) +WAVEPRECcxx . . $ `src/opl.c:59:9`!] = (Bit16scxx . . $ Bit16s#)(16384*sincxx . . $ sin(447c67c6676f75c3).((fltypecxx . . $ `src/opl.c:33:9`!)((i<<1) )*PIcxx . . $ `src/opl.c:53:9`!*2/WAVEPRECcxx . . $ `src/opl.c:59:9`!)); |
| 720 | wavtablecxx . . $ wavtable.[(i<<1)+1+WAVEPRECcxx . . $ `src/opl.c:59:9`!] = (Bit16scxx . . $ Bit16s#)(16384*sincxx . . $ sin(447c67c6676f75c3).((fltypecxx . . $ `src/opl.c:33:9`!)((i<<1)+1)*PIcxx . . $ `src/opl.c:53:9`!*2/WAVEPRECcxx . . $ `src/opl.c:59:9`!)); |
| 721 | wavtablecxx . . $ wavtable.[i] = wavtablecxx . . $ wavtable.[(i<<1) +WAVEPRECcxx . . $ `src/opl.c:59:9`!]; |
| 722 | // alternative: (zero-less) |
| 723 | /* wavtable[(i<<1) +WAVEPREC] = (Bit16s)(16384*sin((fltype)((i<<2)+1)*PI/WAVEPREC)); |
| 724 | wavtable[(i<<1)+1+WAVEPREC] = (Bit16s)(16384*sin((fltype)((i<<2)+3)*PI/WAVEPREC)); |
| 725 | wavtable[i] = wavtable[(i<<1)-1+WAVEPREC]; */ |
| 726 | } |
| 727 | for (i=0;i<(WAVEPRECcxx . . $ `src/opl.c:59:9`!>>3);i++) { |
| 728 | wavtablecxx . . $ wavtable.[i+(WAVEPRECcxx . . $ `src/opl.c:59:9`!<<1)] = wavtablecxx . . $ wavtable.[i+(WAVEPRECcxx . . $ `src/opl.c:59:9`!>>3)]-16384; |
| 729 | wavtablecxx . . $ wavtable.[i+((WAVEPRECcxx . . $ `src/opl.c:59:9`!*17)>>3)] = wavtablecxx . . $ wavtable.[i+(WAVEPRECcxx . . $ `src/opl.c:59:9`!>>2)]+16384; |
| 730 | } |
| 731 | |
| 732 | // key scale level table verified ([table in book]*8/3) |
| 733 | kslevcxx . . $ kslev.[7][0] = 0; kslevcxx . . $ kslev.[7][1] = 24; kslevcxx . . $ kslev.[7][2] = 32; kslevcxx . . $ kslev.[7][3] = 37; |
| 734 | kslevcxx . . $ kslev.[7][4] = 40; kslevcxx . . $ kslev.[7][5] = 43; kslevcxx . . $ kslev.[7][6] = 45; kslevcxx . . $ kslev.[7][7] = 47; |
| 735 | kslevcxx . . $ kslev.[7][8] = 48; |
| 736 | for (i=9;i<16;i++) kslevcxx . . $ kslev.[7][i] = (Bit8ucxx . . $ Bit8u#)(i+41); |
| 737 | for (j=6;j>=0;j--) { |
| 738 | for (i=0;i<16;i++) { |
| 739 | oct = (Bitscxx . . $ Bits#)kslevcxx . . $ kslev.[j+1][i]-8; |
| 740 | if (oct < 0) oct = 0; |
| 741 | kslevcxx . . $ kslev.[j][i] = (Bit8ucxx . . $ Bit8u#)oct; |
| 742 | } |
| 743 | } |
| 744 | } |
| 745 | |
| 746 | } |
| 747 | |
| 748 | |
| 749 | |
| 750 | void adlib_writecxx . . $ adlib_write(802fe934043824c).(Bitucxx . . $ Bitu# idx, Bit8ucxx . . $ Bit8u# val) { |
| 751 | Bit32ucxx . . $ Bit32u# second_set = idx&0x100; |
| 752 | adlibregcxx . . $ adlibreg.[idx] = val; |
| 753 | |
| 754 | switch (idx&0xf0) { |
| 755 | case ARC_CONTROLcxx . . $ `src/opl.c:71:9`!: |
| 756 | // here we check for the second set registers, too: |
| 757 | switch (idx) { |
| 758 | case 0x02: // timer1 counter |
| 759 | case 0x03: // timer2 counter |
| 760 | break; |
| 761 | case 0x04: |
| 762 | // IRQ reset, timer mask/start |
| 763 | if (val&0x80) { |
| 764 | // clear IRQ bits in status register |
| 765 | statuscxx . . $ status. &= ~0x60; |
| 766 | } else { |
| 767 | statuscxx . . $ status. = 0; |
| 768 | } |
| 769 | break; |
| 770 | #if defined(OPLTYPE_IS_OPL3) |
| 771 | case 0x04|ARC_SECONDSET: |
| 772 | // 4op enable/disable switches for each possible channel |
| 773 | op[0].is_4op = (val&1)>0; |
| 774 | op[3].is_4op_attached = op[0].is_4op; |
| 775 | op[1].is_4op = (val&2)>0; |
| 776 | op[4].is_4op_attached = op[1].is_4op; |
| 777 | op[2].is_4op = (val&4)>0; |
| 778 | op[5].is_4op_attached = op[2].is_4op; |
| 779 | op[18].is_4op = (val&8)>0; |
| 780 | op[21].is_4op_attached = op[18].is_4op; |
| 781 | op[19].is_4op = (val&16)>0; |
| 782 | op[22].is_4op_attached = op[19].is_4op; |
| 783 | op[20].is_4op = (val&32)>0; |
| 784 | op[23].is_4op_attached = op[20].is_4op; |
| 785 | break; |
| 786 | case 0x05|ARC_SECONDSET: |
| 787 | break; |
| 788 | #endif |
| 789 | case 0x08: |
| 790 | // CSW, note select |
| 791 | break; |
| 792 | default: |
| 793 | break; |
| 794 | } |
| 795 | break; |
| 796 | case ARC_TVS_KSR_MULcxx . . $ `src/opl.c:72:9`!: |
| 797 | case ARC_TVS_KSR_MULcxx . . $ `src/opl.c:72:9`!+0x10: { |
| 798 | // tremolo/vibrato/sustain keeping enabled; key scale rate; frequency multiplication |
| 799 | int num = idx&7; |
| 800 | Bitucxx . . $ Bitu# base = (idx-ARC_TVS_KSR_MULcxx . . $ `src/opl.c:72:9`!)&0xff; |
| 801 | if ((num<6) && (base<22)) { |
| 802 | Bitucxx . . $ Bitu# modop = regbase2modopcxx . . $ regbase2modop.[second_set?(base+22):base]; |
| 803 | Bitucxx . . $ Bitu# regbase = base+second_set; |
| 804 | Bitucxx . . $ Bitu# chanbase = second_set?(modop-18+ARC_SECONDSETcxx . . $ `src/opl.c:82:9`!):modop; |
| 805 | |
| 806 | // change tremolo/vibrato and sustain keeping of this operator |
| 807 | op_typecxx . . $ op_type#* op_ptr = &opcxx . . $ op.[modop+((num<3) ? 0 : 9)]; |
| 808 | change_keepsustaincxx . . $ change_keepsustain(c7b2edb2b789faa1).(regbase,op_ptr); |
| 809 | change_vibratocxx . . $ change_vibrato(c7b2edb2b789faa1).(regbase,op_ptr); |
| 810 | |
| 811 | // change frequency calculations of this operator as |
| 812 | // key scale rate and frequency multiplicator can be changed |
| 813 | #if defined(OPLTYPE_IS_OPL3) |
| 814 | if ((adlibreg[0x105]&1) && (op[modop].is_4op_attached)) { |
| 815 | // operator uses frequency of channel |
| 816 | change_frequency(chanbase-3,regbase,op_ptr); |
| 817 | } else { |
| 818 | change_frequency(chanbase,regbase,op_ptr); |
| 819 | } |
| 820 | #else |
| 821 | change_frequencycxx . . $ change_frequency(cf77c00c7ba6fbcb).(chanbase,base,op_ptr); |
| 822 | #endif |
| 823 | } |
| 824 | } |
| 825 | break; |
| 826 | case ARC_KSL_OUTLEVcxx . . $ `src/opl.c:73:9`!: |
| 827 | case ARC_KSL_OUTLEVcxx . . $ `src/opl.c:73:9`!+0x10: { |
| 828 | // key scale level; output rate |
| 829 | int num = idx&7; |
| 830 | Bitucxx . . $ Bitu# base = (idx-ARC_KSL_OUTLEVcxx . . $ `src/opl.c:73:9`!)&0xff; |
| 831 | if ((num<6) && (base<22)) { |
| 832 | Bitucxx . . $ Bitu# modop = regbase2modopcxx . . $ regbase2modop.[second_set?(base+22):base]; |
| 833 | Bitucxx . . $ Bitu# chanbase = second_set?(modop-18+ARC_SECONDSETcxx . . $ `src/opl.c:82:9`!):modop; |
| 834 | |
| 835 | // change frequency calculations of this operator as |
| 836 | // key scale level and output rate can be changed |
| 837 | op_typecxx . . $ op_type#* op_ptr = &opcxx . . $ op.[modop+((num<3) ? 0 : 9)]; |
| 838 | #if defined(OPLTYPE_IS_OPL3) |
| 839 | Bitu regbase = base+second_set; |
| 840 | if ((adlibreg[0x105]&1) && (op[modop].is_4op_attached)) { |
| 841 | // operator uses frequency of channel |
| 842 | change_frequency(chanbase-3,regbase,op_ptr); |
| 843 | } else { |
| 844 | change_frequency(chanbase,regbase,op_ptr); |
| 845 | } |
| 846 | #else |
| 847 | change_frequencycxx . . $ change_frequency(cf77c00c7ba6fbcb).(chanbase,base,op_ptr); |
| 848 | #endif |
| 849 | } |
| 850 | } |
| 851 | break; |
| 852 | case ARC_ATTR_DECRcxx . . $ `src/opl.c:74:9`!: |
| 853 | case ARC_ATTR_DECRcxx . . $ `src/opl.c:74:9`!+0x10: { |
| 854 | // attack/decay rates |
| 855 | int num = idx&7; |
| 856 | Bitucxx . . $ Bitu# base = (idx-ARC_ATTR_DECRcxx . . $ `src/opl.c:74:9`!)&0xff; |
| 857 | if ((num<6) && (base<22)) { |
| 858 | Bitucxx . . $ Bitu# regbase = base+second_set; |
| 859 | |
| 860 | // change attack rate and decay rate of this operator |
| 861 | op_typecxx . . $ op_type#* op_ptr = &opcxx . . $ op.[regbase2opcxx . . $ regbase2op.[second_set?(base+22):base]]; |
| 862 | change_attackratecxx . . $ change_attackrate(c7b2edb2b789faa1).(regbase,op_ptr); |
| 863 | change_decayratecxx . . $ change_decayrate(c7b2edb2b789faa1).(regbase,op_ptr); |
| 864 | } |
| 865 | } |
| 866 | break; |
| 867 | case ARC_SUSL_RELRcxx . . $ `src/opl.c:75:9`!: |
| 868 | case ARC_SUSL_RELRcxx . . $ `src/opl.c:75:9`!+0x10: { |
| 869 | // sustain level; release rate |
| 870 | int num = idx&7; |
| 871 | Bitucxx . . $ Bitu# base = (idx-ARC_SUSL_RELRcxx . . $ `src/opl.c:75:9`!)&0xff; |
| 872 | if ((num<6) && (base<22)) { |
| 873 | Bitucxx . . $ Bitu# regbase = base+second_set; |
| 874 | |
| 875 | // change sustain level and release rate of this operator |
| 876 | op_typecxx . . $ op_type#* op_ptr = &opcxx . . $ op.[regbase2opcxx . . $ regbase2op.[second_set?(base+22):base]]; |
| 877 | change_releaseratecxx . . $ change_releaserate(c7b2edb2b789faa1).(regbase,op_ptr); |
| 878 | change_sustainlevelcxx . . $ change_sustainlevel(c7b2edb2b789faa1).(regbase,op_ptr); |
| 879 | } |
| 880 | } |
| 881 | break; |
| 882 | case ARC_FREQ_NUMcxx . . $ `src/opl.c:76:9`!: { |
| 883 | // 0xa0-0xa8 low8 frequency |
| 884 | Bitucxx . . $ Bitu# base = (idx-ARC_FREQ_NUMcxx . . $ `src/opl.c:76:9`!)&0xff; |
| 885 | if (base<9) { |
| 886 | Bitscxx . . $ Bits# opbase = second_set?(base+18):base; |
| 887 | #if defined(OPLTYPE_IS_OPL3) |
| 888 | if ((adlibreg[0x105]&1) && op[opbase].is_4op_attached) break; |
| 889 | #endif |
| 890 | // regbase of modulator: |
| 891 | Bitscxx . . $ Bits# modbase = modulatorbasecxx . . $ modulatorbase.[base]+second_set; |
| 892 | |
| 893 | Bitucxx . . $ Bitu# chanbase = base+second_set; |
| 894 | |
| 895 | change_frequencycxx . . $ change_frequency(cf77c00c7ba6fbcb).(chanbase,modbase,&opcxx . . $ op.[opbase]); |
| 896 | change_frequencycxx . . $ change_frequency(cf77c00c7ba6fbcb).(chanbase,modbase+3,&opcxx . . $ op.[opbase+9]); |
| 897 | #if defined(OPLTYPE_IS_OPL3) |
| 898 | // for 4op channels all four operators are modified to the frequency of the channel |
| 899 | if ((adlibreg[0x105]&1) && op[second_set?(base+18):base].is_4op) { |
| 900 | change_frequency(chanbase,modbase+8,&op[opbase+3]); |
| 901 | change_frequency(chanbase,modbase+3+8,&op[opbase+3+9]); |
| 902 | } |
| 903 | #endif |
| 904 | } |
| 905 | } |
| 906 | break; |
| 907 | case ARC_KON_BNUMcxx . . $ `src/opl.c:77:9`!: { |
| 908 | if (idx == ARC_PERC_MODEcxx . . $ `src/opl.c:78:9`!) { |
| 909 | #if defined(OPLTYPE_IS_OPL3) |
| 910 | if (second_set) return; |
| 911 | #endif |
| 912 | |
| 913 | if ((val&0x30) == 0x30) { // BassDrum active |
| 914 | enable_operatorcxx . . $ enable_operator(adfaf86712d24310).(16,&opcxx . . $ op.[6],OP_ACT_PERCcxx . . $ `src/opl.c:87:9`!); |
| 915 | change_frequencycxx . . $ change_frequency(cf77c00c7ba6fbcb).(6,16,&opcxx . . $ op.[6]); |
| 916 | enable_operatorcxx . . $ enable_operator(adfaf86712d24310).(16+3,&opcxx . . $ op.[6+9],OP_ACT_PERCcxx . . $ `src/opl.c:87:9`!); |
| 917 | change_frequencycxx . . $ change_frequency(cf77c00c7ba6fbcb).(6,16+3,&opcxx . . $ op.[6+9]); |
| 918 | } else { |
| 919 | disable_operatorcxx . . $ disable_operator(556949c3686164d).(&opcxx . . $ op.[6],OP_ACT_PERCcxx . . $ `src/opl.c:87:9`!); |
| 920 | disable_operatorcxx . . $ disable_operator(556949c3686164d).(&opcxx . . $ op.[6+9],OP_ACT_PERCcxx . . $ `src/opl.c:87:9`!); |
| 921 | } |
| 922 | if ((val&0x28) == 0x28) { // Snare active |
| 923 | enable_operatorcxx . . $ enable_operator(adfaf86712d24310).(17+3,&opcxx . . $ op.[16],OP_ACT_PERCcxx . . $ `src/opl.c:87:9`!); |
| 924 | change_frequencycxx . . $ change_frequency(cf77c00c7ba6fbcb).(7,17+3,&opcxx . . $ op.[16]); |
| 925 | } else { |
| 926 | disable_operatorcxx . . $ disable_operator(556949c3686164d).(&opcxx . . $ op.[16],OP_ACT_PERCcxx . . $ `src/opl.c:87:9`!); |
| 927 | } |
| 928 | if ((val&0x24) == 0x24) { // TomTom active |
| 929 | enable_operatorcxx . . $ enable_operator(adfaf86712d24310).(18,&opcxx . . $ op.[8],OP_ACT_PERCcxx . . $ `src/opl.c:87:9`!); |
| 930 | change_frequencycxx . . $ change_frequency(cf77c00c7ba6fbcb).(8,18,&opcxx . . $ op.[8]); |
| 931 | } else { |
| 932 | disable_operatorcxx . . $ disable_operator(556949c3686164d).(&opcxx . . $ op.[8],OP_ACT_PERCcxx . . $ `src/opl.c:87:9`!); |
| 933 | } |
| 934 | if ((val&0x22) == 0x22) { // Cymbal active |
| 935 | enable_operatorcxx . . $ enable_operator(adfaf86712d24310).(18+3,&opcxx . . $ op.[8+9],OP_ACT_PERCcxx . . $ `src/opl.c:87:9`!); |
| 936 | change_frequencycxx . . $ change_frequency(cf77c00c7ba6fbcb).(8,18+3,&opcxx . . $ op.[8+9]); |
| 937 | } else { |
| 938 | disable_operatorcxx . . $ disable_operator(556949c3686164d).(&opcxx . . $ op.[8+9],OP_ACT_PERCcxx . . $ `src/opl.c:87:9`!); |
| 939 | } |
| 940 | if ((val&0x21) == 0x21) { // Hihat active |
| 941 | enable_operatorcxx . . $ enable_operator(adfaf86712d24310).(17,&opcxx . . $ op.[7],OP_ACT_PERCcxx . . $ `src/opl.c:87:9`!); |
| 942 | change_frequencycxx . . $ change_frequency(cf77c00c7ba6fbcb).(7,17,&opcxx . . $ op.[7]); |
| 943 | } else { |
| 944 | disable_operatorcxx . . $ disable_operator(556949c3686164d).(&opcxx . . $ op.[7],OP_ACT_PERCcxx . . $ `src/opl.c:87:9`!); |
| 945 | } |
| 946 | |
| 947 | break; |
| 948 | } |
| 949 | // regular 0xb0-0xb8 |
| 950 | Bitucxx . . $ Bitu# base = (idx-ARC_KON_BNUMcxx . . $ `src/opl.c:77:9`!)&0xff; |
| 951 | if (base<9) { |
| 952 | Bitscxx . . $ Bits# opbase = second_set?(base+18):base; |
| 953 | #if defined(OPLTYPE_IS_OPL3) |
| 954 | if ((adlibreg[0x105]&1) && op[opbase].is_4op_attached) break; |
| 955 | #endif |
| 956 | // regbase of modulator: |
| 957 | Bitscxx . . $ Bits# modbase = modulatorbasecxx . . $ modulatorbase.[base]+second_set; |
| 958 | |
| 959 | if (val&32) { |
| 960 | // operator switched on |
| 961 | enable_operatorcxx . . $ enable_operator(adfaf86712d24310).(modbase,&opcxx . . $ op.[opbase],OP_ACT_NORMALcxx . . $ `src/opl.c:86:9`!); // modulator (if 2op) |
| 962 | enable_operatorcxx . . $ enable_operator(adfaf86712d24310).(modbase+3,&opcxx . . $ op.[opbase+9],OP_ACT_NORMALcxx . . $ `src/opl.c:86:9`!); // carrier (if 2op) |
| 963 | #if defined(OPLTYPE_IS_OPL3) |
| 964 | // for 4op channels all four operators are switched on |
| 965 | if ((adlibreg[0x105]&1) && op[opbase].is_4op) { |
| 966 | // turn on chan+3 operators as well |
| 967 | enable_operator(modbase+8,&op[opbase+3],OP_ACT_NORMAL); |
| 968 | enable_operator(modbase+3+8,&op[opbase+3+9],OP_ACT_NORMAL); |
| 969 | } |
| 970 | #endif |
| 971 | } else { |
| 972 | // operator switched off |
| 973 | disable_operatorcxx . . $ disable_operator(556949c3686164d).(&opcxx . . $ op.[opbase],OP_ACT_NORMALcxx . . $ `src/opl.c:86:9`!); |
| 974 | disable_operatorcxx . . $ disable_operator(556949c3686164d).(&opcxx . . $ op.[opbase+9],OP_ACT_NORMALcxx . . $ `src/opl.c:86:9`!); |
| 975 | #if defined(OPLTYPE_IS_OPL3) |
| 976 | // for 4op channels all four operators are switched off |
| 977 | if ((adlibreg[0x105]&1) && op[opbase].is_4op) { |
| 978 | // turn off chan+3 operators as well |
| 979 | disable_operator(&op[opbase+3],OP_ACT_NORMAL); |
| 980 | disable_operator(&op[opbase+3+9],OP_ACT_NORMAL); |
| 981 | } |
| 982 | #endif |
| 983 | } |
| 984 | |
| 985 | Bitucxx . . $ Bitu# chanbase = base+second_set; |
| 986 | |
| 987 | // change frequency calculations of modulator and carrier (2op) as |
| 988 | // the frequency of the channel has changed |
| 989 | change_frequencycxx . . $ change_frequency(cf77c00c7ba6fbcb).(chanbase,modbase,&opcxx . . $ op.[opbase]); |
| 990 | change_frequencycxx . . $ change_frequency(cf77c00c7ba6fbcb).(chanbase,modbase+3,&opcxx . . $ op.[opbase+9]); |
| 991 | #if defined(OPLTYPE_IS_OPL3) |
| 992 | // for 4op channels all four operators are modified to the frequency of the channel |
| 993 | if ((adlibreg[0x105]&1) && op[second_set?(base+18):base].is_4op) { |
| 994 | // change frequency calculations of chan+3 operators as well |
| 995 | change_frequency(chanbase,modbase+8,&op[opbase+3]); |
| 996 | change_frequency(chanbase,modbase+3+8,&op[opbase+3+9]); |
| 997 | } |
| 998 | #endif |
| 999 | } |
| 1000 | } |
| 1001 | break; |
| 1002 | case ARC_FEEDBACKcxx . . $ `src/opl.c:79:9`!: { |
| 1003 | // 0xc0-0xc8 feedback/modulation type (AM/FM) |
| 1004 | Bitucxx . . $ Bitu# base = (idx-ARC_FEEDBACKcxx . . $ `src/opl.c:79:9`!)&0xff; |
| 1005 | if (base<9) { |
| 1006 | Bitscxx . . $ Bits# opbase = second_set?(base+18):base; |
| 1007 | Bitucxx . . $ Bitu# chanbase = base+second_set; |
| 1008 | change_feedbackcxx . . $ change_feedback(c7b2edb2b789faa1).(chanbase,&opcxx . . $ op.[opbase]); |
| 1009 | #if defined(OPLTYPE_IS_OPL3) |
| 1010 | // OPL3 panning |
| 1011 | op[opbase].left_pan = ((val&0x10)>>4); |
| 1012 | op[opbase].right_pan = ((val&0x20)>>5); |
| 1013 | #endif |
| 1014 | } |
| 1015 | } |
| 1016 | break; |
| 1017 | case ARC_WAVE_SELcxx . . $ `src/opl.c:80:9`!: |
| 1018 | case ARC_WAVE_SELcxx . . $ `src/opl.c:80:9`!+0x10: { |
| 1019 | int num = idx&7; |
| 1020 | Bitucxx . . $ Bitu# base = (idx-ARC_WAVE_SELcxx . . $ `src/opl.c:80:9`!)&0xff; |
| 1021 | if ((num<6) && (base<22)) { |
| 1022 | #if defined(OPLTYPE_IS_OPL3) |
| 1023 | Bits wselbase = second_set?(base+22):base; // for easier mapping onto wave_sel[] |
| 1024 | // change waveform |
| 1025 | if (adlibreg[0x105]&1) wave_sel[wselbase] = val&7; // opl3 mode enabled, all waveforms accessible |
| 1026 | else wave_sel[wselbase] = val&3; |
| 1027 | op_type* op_ptr = &op[regbase2modop[wselbase]+((num<3) ? 0 : 9)]; |
| 1028 | change_waveform(wselbase,op_ptr); |
| 1029 | #else |
| 1030 | if (adlibregcxx . . $ adlibreg.[0x01]&0x20) { |
| 1031 | // wave selection enabled, change waveform |
| 1032 | wave_selcxx . . $ wave_sel.[base] = val&3; |
| 1033 | op_typecxx . . $ op_type#* op_ptr = &opcxx . . $ op.[regbase2modopcxx . . $ regbase2modop.[base]+((num<3) ? 0 : 9)]; |
| 1034 | change_waveformcxx . . $ change_waveform(c7b2edb2b789faa1).(base,op_ptr); |
| 1035 | } |
| 1036 | #endif |
| 1037 | } |
| 1038 | } |
| 1039 | break; |
| 1040 | default: |
| 1041 | break; |
| 1042 | } |
| 1043 | } |
| 1044 | |
| 1045 | |
| 1046 | Bitucxx . . $ Bitu# adlib_reg_readcxx . . $ adlib_reg_read(ecdaa1632f49f591).(Bitucxx . . $ Bitu# port) { |
| 1047 | #if defined(OPLTYPE_IS_OPL3) |
| 1048 | // opl3-detection routines require ret&6 to be zero |
| 1049 | if ((port&1)==0) { |
| 1050 | return status; |
| 1051 | } |
| 1052 | return 0x00; |
| 1053 | #else |
| 1054 | // opl2-detection routines require ret&6 to be 6 |
| 1055 | if ((port&1)==0) { |
| 1056 | return statuscxx . . $ status.|6; |
| 1057 | } |
| 1058 | return 0xff; |
| 1059 | #endif |
| 1060 | } |
| 1061 | |
| 1062 | void adlib_write_indexcxx . . $ adlib_write_index(802fe934043824c).(Bitucxx . . $ Bitu# port, Bit8ucxx . . $ Bit8u# val) { |
| 1063 | (void) port; |
| 1064 | opl_indexcxx . . $ opl_index. = val; |
| 1065 | #if defined(OPLTYPE_IS_OPL3) |
| 1066 | if ((port&3)!=0) { |
| 1067 | // possibly second set |
| 1068 | if (((adlibreg[0x105]&1)!=0) || (opl_index==5)) opl_index |= ARC_SECONDSET; |
| 1069 | } |
| 1070 | #endif |
| 1071 | } |
| 1072 | |
| 1073 | OPL_INLINEcxx . . $ `src/opl.c:38:9`! static void clipit16cxx . . $ clipit16(4c4d8747bb7d9d45).(Bit32scxx . . $ Bit32s# ival, Bit16scxx . . $ Bit16s#* outval) { |
| 1074 | if (ival<32768) { |
| 1075 | if (ival>-32769) { |
| 1076 | *outval=(Bit16scxx . . $ Bit16s#)ival; |
| 1077 | } else { |
| 1078 | *outval = -32768; |
| 1079 | } |
| 1080 | } else { |
| 1081 | *outval = 32767; |
| 1082 | } |
| 1083 | } |
| 1084 | |
| 1085 | |
| 1086 | |
| 1087 | // be careful with this |
| 1088 | // uses cptr and chanval, outputs into outbufl(/outbufr) |
| 1089 | // for opl3 check if opl3-mode is enabled (which uses stereo panning) |
| 1090 | #undef CHANVAL_OUT |
| 1091 | #if defined(OPLTYPE_IS_OPL3) |
| 1092 | #define CHANVAL_OUT \ |
| 1093 | if (adlibreg[0x105]&1) { \ |
| 1094 | outbufl[i] += chanval*cptr[0].left_pan; \ |
| 1095 | outbufr[i] += chanval*cptr[0].right_pan; \ |
| 1096 | } else { \ |
| 1097 | outbufl[i] += chanval; \ |
| 1098 | } |
| 1099 | #else |
| 1100 | #define CHANVAL_OUTcxx . . $ `src/opl.c:1100:9`! \ |
| 1101 | outbufl[i] += chanval; |
| 1102 | #endif |
| 1103 | |
| 1104 | void adlib_getsamplecxx . . $ adlib_getsample(f9643a6d2bb7d59).(Bit16scxx . . $ Bit16s#* sndptr, Bitscxx . . $ Bits# numsamples) { |
| 1105 | Bitscxx . . $ Bits# i, endsamples; |
| 1106 | op_typecxx . . $ op_type#* cptr; |
| 1107 | |
| 1108 | Bit32scxx . . $ Bit32s# outbufl[BLOCKBUF_SIZEcxx . . $ `src/opl.c:89:9`!]; |
| 1109 | #if defined(OPLTYPE_IS_OPL3) |
| 1110 | // second output buffer (right channel for opl3 stereo) |
| 1111 | Bit32s outbufr[BLOCKBUF_SIZE]; |
| 1112 | #endif |
| 1113 | |
| 1114 | // vibrato/tremolo lookup tables (global, to possibly be used by all operators) |
| 1115 | Bit32scxx . . $ Bit32s# vib_lut[BLOCKBUF_SIZEcxx . . $ `src/opl.c:89:9`!]; |
| 1116 | Bit32scxx . . $ Bit32s# trem_lut[BLOCKBUF_SIZEcxx . . $ `src/opl.c:89:9`!]; |
| 1117 | |
| 1118 | Bitscxx . . $ Bits# samples_to_process = numsamples; |
| 1119 | |
| 1120 | for (Bitscxx . . $ Bits# cursmp=0; cursmp<samples_to_process; cursmp+=endsamples) { |
| 1121 | endsamples = samples_to_process-cursmp; |
| 1122 | if (endsamples>BLOCKBUF_SIZEcxx . . $ `src/opl.c:89:9`!) endsamples = BLOCKBUF_SIZEcxx . . $ `src/opl.c:89:9`!; |
| 1123 | |
| 1124 | memsetcxx . . $ memset(d1de1e4fb215f1c6).((void*)&outbufl,0,endsamples*sizeof(Bit32scxx . . $ Bit32s#)); |
| 1125 | #if defined(OPLTYPE_IS_OPL3) |
| 1126 | // clear second output buffer (opl3 stereo) |
| 1127 | if (adlibreg[0x105]&1) memset((void*)&outbufr,0,endsamples*sizeof(Bit32s)); |
| 1128 | #endif |
| 1129 | |
| 1130 | // calculate vibrato/tremolo lookup tables |
| 1131 | Bit32scxx . . $ Bit32s# vib_tshift = ((adlibregcxx . . $ adlibreg.[ARC_PERC_MODEcxx . . $ `src/opl.c:78:9`!]&0x40)==0) ? 1 : 0; // 14cents/7cents switching |
| 1132 | for (i=0;i<endsamples;i++) { |
| 1133 | // cycle through vibrato table |
| 1134 | vibtab_poscxx . . $ vibtab_pos. += vibtab_addcxx . . $ vibtab_add.; |
| 1135 | if (vibtab_poscxx . . $ vibtab_pos./FIXEDPT_LFOcxx . . $ `src/opl.c:57:9`!>=VIBTAB_SIZEcxx . . $ `src/opl.c:93:9`!) vibtab_poscxx . . $ vibtab_pos.-=VIBTAB_SIZEcxx . . $ `src/opl.c:93:9`!*FIXEDPT_LFOcxx . . $ `src/opl.c:57:9`!; |
| 1136 | vib_lut[i] = vib_tablecxx . . $ vib_table.[vibtab_poscxx . . $ vibtab_pos./FIXEDPT_LFOcxx . . $ `src/opl.c:57:9`!]>>vib_tshift; // 14cents (14/100 of a semitone) or 7cents |
| 1137 | |
| 1138 | // cycle through tremolo table |
| 1139 | tremtab_poscxx . . $ tremtab_pos. += tremtab_addcxx . . $ tremtab_add.; |
| 1140 | if (tremtab_poscxx . . $ tremtab_pos./FIXEDPT_LFOcxx . . $ `src/opl.c:57:9`!>=TREMTAB_SIZEcxx . . $ `src/opl.c:97:9`!) tremtab_poscxx . . $ tremtab_pos.-=TREMTAB_SIZEcxx . . $ `src/opl.c:97:9`!*FIXEDPT_LFOcxx . . $ `src/opl.c:57:9`!; |
| 1141 | if (adlibregcxx . . $ adlibreg.[ARC_PERC_MODEcxx . . $ `src/opl.c:78:9`!]&0x80) trem_lut[i] = trem_tablecxx . . $ trem_table.[tremtab_poscxx . . $ tremtab_pos./FIXEDPT_LFOcxx . . $ `src/opl.c:57:9`!]; |
| 1142 | else trem_lut[i] = trem_tablecxx . . $ trem_table.[TREMTAB_SIZEcxx . . $ `src/opl.c:97:9`!+tremtab_poscxx . . $ tremtab_pos./FIXEDPT_LFOcxx . . $ `src/opl.c:57:9`!]; |
| 1143 | } |
| 1144 | |
| 1145 | if (adlibregcxx . . $ adlibreg.[ARC_PERC_MODEcxx . . $ `src/opl.c:78:9`!]&0x20) { |
| 1146 | //BassDrum |
| 1147 | cptr = &opcxx . . $ op.[6]; |
| 1148 | if (adlibregcxx . . $ adlibreg.[ARC_FEEDBACKcxx . . $ `src/opl.c:79:9`!+6]&1) { |
| 1149 | // additive synthesis |
| 1150 | if (cptr[9].op_statecxx . . $ operator_struct#op_state. != OF_TYPE_OFFcxx . . $ `src/opl.c:69:9`!) { |
| 1151 | if (cptr[9].vibratocxx . . $ operator_struct#vibrato.) { |
| 1152 | vibval1cxx . . $ vibval1. = vibval_var1cxx . . $ vibval_var1.; |
| 1153 | for (i=0;i<endsamples;i++) |
| 1154 | vibval1cxx . . $ vibval1.[i] = (Bit32scxx . . $ Bit32s#)((vib_lut[i]*cptr[9].freq_highcxx . . $ operator_struct#freq_high./8)*FIXEDPTcxx . . $ `src/opl.c:56:9`!*VIBFACcxx . . $ `src/opl.c:94:9`!); |
| 1155 | } else vibval1cxx . . $ vibval1. = vibval_constcxx . . $ vibval_const.; |
| 1156 | if (cptr[9].tremolocxx . . $ operator_struct#tremolo.) tremval1cxx . . $ tremval1. = trem_lut; // tremolo enabled, use table |
| 1157 | else tremval1cxx . . $ tremval1. = tremval_constcxx . . $ tremval_const.; |
| 1158 | |
| 1159 | // calculate channel output |
| 1160 | for (i=0;i<endsamples;i++) { |
| 1161 | operator_advancecxx . . $ operator_advance(90c6108e829b6b0c).(&cptr[9],vibval1cxx . . $ vibval1.[i]); |
| 1162 | opfuncscxx . . $ opfuncs.[cptr[9].op_statecxx . . $ operator_struct#op_state.](&cptr[9]); |
| 1163 | operator_outputcxx . . $ operator_output(4521a3a0338f20a).(&cptr[9],0,tremval1cxx . . $ tremval1.[i]); |
| 1164 | |
| 1165 | Bit32scxx . . $ Bit32s# chanval = cptr[9].cvalcxx . . $ operator_struct#cval.*2; |
| 1166 | CHANVAL_OUTcxx . . $ `src/opl.c:1100:9`! |
| 1167 | } |
| 1168 | } |
| 1169 | } else { |
| 1170 | // frequency modulation |
| 1171 | if ((cptr[9].op_statecxx . . $ operator_struct#op_state. != OF_TYPE_OFFcxx . . $ `src/opl.c:69:9`!) || (cptr[0].op_statecxx . . $ operator_struct#op_state. != OF_TYPE_OFFcxx . . $ `src/opl.c:69:9`!)) { |
| 1172 | if ((cptr[0].vibratocxx . . $ operator_struct#vibrato.) && (cptr[0].op_statecxx . . $ operator_struct#op_state. != OF_TYPE_OFFcxx . . $ `src/opl.c:69:9`!)) { |
| 1173 | vibval1cxx . . $ vibval1. = vibval_var1cxx . . $ vibval_var1.; |
| 1174 | for (i=0;i<endsamples;i++) |
| 1175 | vibval1cxx . . $ vibval1.[i] = (Bit32scxx . . $ Bit32s#)((vib_lut[i]*cptr[0].freq_highcxx . . $ operator_struct#freq_high./8)*FIXEDPTcxx . . $ `src/opl.c:56:9`!*VIBFACcxx . . $ `src/opl.c:94:9`!); |
| 1176 | } else vibval1cxx . . $ vibval1. = vibval_constcxx . . $ vibval_const.; |
| 1177 | if ((cptr[9].vibratocxx . . $ operator_struct#vibrato.) && (cptr[9].op_statecxx . . $ operator_struct#op_state. != OF_TYPE_OFFcxx . . $ `src/opl.c:69:9`!)) { |
| 1178 | vibval2cxx . . $ vibval2. = vibval_var2cxx . . $ vibval_var2.; |
| 1179 | for (i=0;i<endsamples;i++) |
| 1180 | vibval2cxx . . $ vibval2.[i] = (Bit32scxx . . $ Bit32s#)((vib_lut[i]*cptr[9].freq_highcxx . . $ operator_struct#freq_high./8)*FIXEDPTcxx . . $ `src/opl.c:56:9`!*VIBFACcxx . . $ `src/opl.c:94:9`!); |
| 1181 | } else vibval2cxx . . $ vibval2. = vibval_constcxx . . $ vibval_const.; |
| 1182 | if (cptr[0].tremolocxx . . $ operator_struct#tremolo.) tremval1cxx . . $ tremval1. = trem_lut; // tremolo enabled, use table |
| 1183 | else tremval1cxx . . $ tremval1. = tremval_constcxx . . $ tremval_const.; |
| 1184 | if (cptr[9].tremolocxx . . $ operator_struct#tremolo.) tremval2cxx . . $ tremval2. = trem_lut; // tremolo enabled, use table |
| 1185 | else tremval2cxx . . $ tremval2. = tremval_constcxx . . $ tremval_const.; |
| 1186 | |
| 1187 | // calculate channel output |
| 1188 | for (i=0;i<endsamples;i++) { |
| 1189 | operator_advancecxx . . $ operator_advance(90c6108e829b6b0c).(&cptr[0],vibval1cxx . . $ vibval1.[i]); |
| 1190 | opfuncscxx . . $ opfuncs.[cptr[0].op_statecxx . . $ operator_struct#op_state.](&cptr[0]); |
| 1191 | operator_outputcxx . . $ operator_output(4521a3a0338f20a).(&cptr[0],(cptr[0].lastcvalcxx . . $ operator_struct#lastcval.+cptr[0].cvalcxx . . $ operator_struct#cval.)*cptr[0].mfbicxx . . $ operator_struct#mfbi./2,tremval1cxx . . $ tremval1.[i]); |
| 1192 | |
| 1193 | operator_advancecxx . . $ operator_advance(90c6108e829b6b0c).(&cptr[9],vibval2cxx . . $ vibval2.[i]); |
| 1194 | opfuncscxx . . $ opfuncs.[cptr[9].op_statecxx . . $ operator_struct#op_state.](&cptr[9]); |
| 1195 | operator_outputcxx . . $ operator_output(4521a3a0338f20a).(&cptr[9],cptr[0].cvalcxx . . $ operator_struct#cval.*FIXEDPTcxx . . $ `src/opl.c:56:9`!,tremval2cxx . . $ tremval2.[i]); |
| 1196 | |
| 1197 | Bit32scxx . . $ Bit32s# chanval = cptr[9].cvalcxx . . $ operator_struct#cval.*2; |
| 1198 | CHANVAL_OUTcxx . . $ `src/opl.c:1100:9`! |
| 1199 | } |
| 1200 | } |
| 1201 | } |
| 1202 | |
| 1203 | //TomTom (j=8) |
| 1204 | if (opcxx . . $ op.[8].op_statecxx . . $ operator_struct#op_state. != OF_TYPE_OFFcxx . . $ `src/opl.c:69:9`!) { |
| 1205 | cptr = &opcxx . . $ op.[8]; |
| 1206 | if (cptr[0].vibratocxx . . $ operator_struct#vibrato.) { |
| 1207 | vibval3cxx . . $ vibval3. = vibval_var1cxx . . $ vibval_var1.; |
| 1208 | for (i=0;i<endsamples;i++) |
| 1209 | vibval3cxx . . $ vibval3.[i] = (Bit32scxx . . $ Bit32s#)((vib_lut[i]*cptr[0].freq_highcxx . . $ operator_struct#freq_high./8)*FIXEDPTcxx . . $ `src/opl.c:56:9`!*VIBFACcxx . . $ `src/opl.c:94:9`!); |
| 1210 | } else vibval3cxx . . $ vibval3. = vibval_constcxx . . $ vibval_const.; |
| 1211 | |
| 1212 | if (cptr[0].tremolocxx . . $ operator_struct#tremolo.) tremval3cxx . . $ tremval3. = trem_lut; // tremolo enabled, use table |
| 1213 | else tremval3cxx . . $ tremval3. = tremval_constcxx . . $ tremval_const.; |
| 1214 | |
| 1215 | // calculate channel output |
| 1216 | for (i=0;i<endsamples;i++) { |
| 1217 | operator_advancecxx . . $ operator_advance(90c6108e829b6b0c).(&cptr[0],vibval3cxx . . $ vibval3.[i]); |
| 1218 | opfuncscxx . . $ opfuncs.[cptr[0].op_statecxx . . $ operator_struct#op_state.](&cptr[0]); //TomTom |
| 1219 | operator_outputcxx . . $ operator_output(4521a3a0338f20a).(&cptr[0],0,tremval3cxx . . $ tremval3.[i]); |
| 1220 | Bit32scxx . . $ Bit32s# chanval = cptr[0].cvalcxx . . $ operator_struct#cval.*2; |
| 1221 | CHANVAL_OUTcxx . . $ `src/opl.c:1100:9`! |
| 1222 | } |
| 1223 | } |
| 1224 | |
| 1225 | //Snare/Hihat (j=7), Cymbal (j=8) |
| 1226 | if ((opcxx . . $ op.[7].op_statecxx . . $ operator_struct#op_state. != OF_TYPE_OFFcxx . . $ `src/opl.c:69:9`!) || (opcxx . . $ op.[16].op_statecxx . . $ operator_struct#op_state. != OF_TYPE_OFFcxx . . $ `src/opl.c:69:9`!) || |
| 1227 | (opcxx . . $ op.[17].op_statecxx . . $ operator_struct#op_state. != OF_TYPE_OFFcxx . . $ `src/opl.c:69:9`!)) { |
| 1228 | cptr = &opcxx . . $ op.[7]; |
| 1229 | if ((cptr[0].vibratocxx . . $ operator_struct#vibrato.) && (cptr[0].op_statecxx . . $ operator_struct#op_state. != OF_TYPE_OFFcxx . . $ `src/opl.c:69:9`!)) { |
| 1230 | vibval1cxx . . $ vibval1. = vibval_var1cxx . . $ vibval_var1.; |
| 1231 | for (i=0;i<endsamples;i++) |
| 1232 | vibval1cxx . . $ vibval1.[i] = (Bit32scxx . . $ Bit32s#)((vib_lut[i]*cptr[0].freq_highcxx . . $ operator_struct#freq_high./8)*FIXEDPTcxx . . $ `src/opl.c:56:9`!*VIBFACcxx . . $ `src/opl.c:94:9`!); |
| 1233 | } else vibval1cxx . . $ vibval1. = vibval_constcxx . . $ vibval_const.; |
| 1234 | if ((cptr[9].vibratocxx . . $ operator_struct#vibrato.) && (cptr[9].op_statecxx . . $ operator_struct#op_state. == OF_TYPE_OFFcxx . . $ `src/opl.c:69:9`!)) { |
| 1235 | vibval2cxx . . $ vibval2. = vibval_var2cxx . . $ vibval_var2.; |
| 1236 | for (i=0;i<endsamples;i++) |
| 1237 | vibval2cxx . . $ vibval2.[i] = (Bit32scxx . . $ Bit32s#)((vib_lut[i]*cptr[9].freq_highcxx . . $ operator_struct#freq_high./8)*FIXEDPTcxx . . $ `src/opl.c:56:9`!*VIBFACcxx . . $ `src/opl.c:94:9`!); |
| 1238 | } else vibval2cxx . . $ vibval2. = vibval_constcxx . . $ vibval_const.; |
| 1239 | |
| 1240 | if (cptr[0].tremolocxx . . $ operator_struct#tremolo.) tremval1cxx . . $ tremval1. = trem_lut; // tremolo enabled, use table |
| 1241 | else tremval1cxx . . $ tremval1. = tremval_constcxx . . $ tremval_const.; |
| 1242 | if (cptr[9].tremolocxx . . $ operator_struct#tremolo.) tremval2cxx . . $ tremval2. = trem_lut; // tremolo enabled, use table |
| 1243 | else tremval2cxx . . $ tremval2. = tremval_constcxx . . $ tremval_const.; |
| 1244 | |
| 1245 | cptr = &opcxx . . $ op.[8]; |
| 1246 | if ((cptr[9].vibratocxx . . $ operator_struct#vibrato.) && (cptr[9].op_statecxx . . $ operator_struct#op_state. == OF_TYPE_OFFcxx . . $ `src/opl.c:69:9`!)) { |
| 1247 | vibval4cxx . . $ vibval4. = vibval_var2cxx . . $ vibval_var2.; |
| 1248 | for (i=0;i<endsamples;i++) |
| 1249 | vibval4cxx . . $ vibval4.[i] = (Bit32scxx . . $ Bit32s#)((vib_lut[i]*cptr[9].freq_highcxx . . $ operator_struct#freq_high./8)*FIXEDPTcxx . . $ `src/opl.c:56:9`!*VIBFACcxx . . $ `src/opl.c:94:9`!); |
| 1250 | } else vibval4cxx . . $ vibval4. = vibval_constcxx . . $ vibval_const.; |
| 1251 | |
| 1252 | if (cptr[9].tremolocxx . . $ operator_struct#tremolo.) tremval4cxx . . $ tremval4. = trem_lut; // tremolo enabled, use table |
| 1253 | else tremval4cxx . . $ tremval4. = tremval_constcxx . . $ tremval_const.; |
| 1254 | |
| 1255 | // calculate channel output |
| 1256 | for (i=0;i<endsamples;i++) { |
| 1257 | operator_advance_drumscxx . . $ operator_advance_drums(5f5b30606dbf8fe8).(&opcxx . . $ op.[7],vibval1cxx . . $ vibval1.[i],&opcxx . . $ op.[7+9],vibval2cxx . . $ vibval2.[i],&opcxx . . $ op.[8+9],vibval4cxx . . $ vibval4.[i]); |
| 1258 | |
| 1259 | opfuncscxx . . $ opfuncs.[opcxx . . $ op.[7].op_statecxx . . $ operator_struct#op_state.](&opcxx . . $ op.[7]); //Hihat |
| 1260 | operator_outputcxx . . $ operator_output(4521a3a0338f20a).(&opcxx . . $ op.[7],0,tremval1cxx . . $ tremval1.[i]); |
| 1261 | |
| 1262 | opfuncscxx . . $ opfuncs.[opcxx . . $ op.[7+9].op_statecxx . . $ operator_struct#op_state.](&opcxx . . $ op.[7+9]); //Snare |
| 1263 | operator_outputcxx . . $ operator_output(4521a3a0338f20a).(&opcxx . . $ op.[7+9],0,tremval2cxx . . $ tremval2.[i]); |
| 1264 | |
| 1265 | opfuncscxx . . $ opfuncs.[opcxx . . $ op.[8+9].op_statecxx . . $ operator_struct#op_state.](&opcxx . . $ op.[8+9]); //Cymbal |
| 1266 | operator_outputcxx . . $ operator_output(4521a3a0338f20a).(&opcxx . . $ op.[8+9],0,tremval4cxx . . $ tremval4.[i]); |
| 1267 | |
| 1268 | Bit32scxx . . $ Bit32s# chanval = (opcxx . . $ op.[7].cvalcxx . . $ operator_struct#cval. + opcxx . . $ op.[7+9].cvalcxx . . $ operator_struct#cval. + opcxx . . $ op.[8+9].cvalcxx . . $ operator_struct#cval.)*2; |
| 1269 | CHANVAL_OUTcxx . . $ `src/opl.c:1100:9`! |
| 1270 | } |
| 1271 | } |
| 1272 | } |
| 1273 | |
| 1274 | Bitucxx . . $ Bitu# max_channel = NUM_CHANNELScxx . . $ `src/opl.c:45:9`!; |
| 1275 | #if defined(OPLTYPE_IS_OPL3) |
| 1276 | if ((adlibreg[0x105]&1)==0) max_channel = NUM_CHANNELS/2; |
| 1277 | #endif |
| 1278 | for (Bitscxx . . $ Bits# cur_ch=max_channel-1; cur_ch>=0; cur_ch--) { |
| 1279 | // skip drum/percussion operators |
| 1280 | if ((adlibregcxx . . $ adlibreg.[ARC_PERC_MODEcxx . . $ `src/opl.c:78:9`!]&0x20) && (cur_ch >= 6) && (cur_ch < 9)) continue; |
| 1281 | |
| 1282 | Bitucxx . . $ Bitu# k = cur_ch; |
| 1283 | #if defined(OPLTYPE_IS_OPL3) |
| 1284 | if (cur_ch < 9) { |
| 1285 | cptr = &op[cur_ch]; |
| 1286 | } else { |
| 1287 | cptr = &op[cur_ch+9]; // second set is operator18-operator35 |
| 1288 | k += (-9+256); // second set uses registers 0x100 onwards |
| 1289 | } |
| 1290 | // check if this operator is part of a 4-op |
| 1291 | if ((adlibreg[0x105]&1) && cptr->is_4op_attached) continue; |
| 1292 | #else |
| 1293 | cptr = &opcxx . . $ op.[cur_ch]; |
| 1294 | #endif |
| 1295 | |
| 1296 | // check for FM/AM |
| 1297 | if (adlibregcxx . . $ adlibreg.[ARC_FEEDBACKcxx . . $ `src/opl.c:79:9`!+k]&1) { |
| 1298 | #if defined(OPLTYPE_IS_OPL3) |
| 1299 | if ((adlibreg[0x105]&1) && cptr->is_4op) { |
| 1300 | if (adlibreg[ARC_FEEDBACK+k+3]&1) { |
| 1301 | // AM-AM-style synthesis (op1[fb] + (op2 * op3) + op4) |
| 1302 | if (cptr[0].op_state != OF_TYPE_OFF) { |
| 1303 | if (cptr[0].vibrato) { |
| 1304 | vibval1 = vibval_var1; |
| 1305 | for (i=0;i<endsamples;i++) |
| 1306 | vibval1[i] = (Bit32s)((vib_lut[i]*cptr[0].freq_high/8)*FIXEDPT*VIBFAC); |
| 1307 | } else vibval1 = vibval_const; |
| 1308 | if (cptr[0].tremolo) tremval1 = trem_lut; // tremolo enabled, use table |
| 1309 | else tremval1 = tremval_const; |
| 1310 | |
| 1311 | // calculate channel output |
| 1312 | for (i=0;i<endsamples;i++) { |
| 1313 | operator_advance(&cptr[0],vibval1[i]); |
| 1314 | opfuncs[cptr[0].op_state](&cptr[0]); |
| 1315 | operator_output(&cptr[0],(cptr[0].lastcval+cptr[0].cval)*cptr[0].mfbi/2,tremval1[i]); |
| 1316 | |
| 1317 | Bit32s chanval = cptr[0].cval; |
| 1318 | CHANVAL_OUT |
| 1319 | } |
| 1320 | } |
| 1321 | |
| 1322 | if ((cptr[3].op_state != OF_TYPE_OFF) || (cptr[9].op_state != OF_TYPE_OFF)) { |
| 1323 | if ((cptr[9].vibrato) && (cptr[9].op_state != OF_TYPE_OFF)) { |
| 1324 | vibval1 = vibval_var1; |
| 1325 | for (i=0;i<endsamples;i++) |
| 1326 | vibval1[i] = (Bit32s)((vib_lut[i]*cptr[9].freq_high/8)*FIXEDPT*VIBFAC); |
| 1327 | } else vibval1 = vibval_const; |
| 1328 | if (cptr[9].tremolo) tremval1 = trem_lut; // tremolo enabled, use table |
| 1329 | else tremval1 = tremval_const; |
| 1330 | if (cptr[3].tremolo) tremval2 = trem_lut; // tremolo enabled, use table |
| 1331 | else tremval2 = tremval_const; |
| 1332 | |
| 1333 | // calculate channel output |
| 1334 | for (i=0;i<endsamples;i++) { |
| 1335 | operator_advance(&cptr[9],vibval1[i]); |
| 1336 | opfuncs[cptr[9].op_state](&cptr[9]); |
| 1337 | operator_output(&cptr[9],0,tremval1[i]); |
| 1338 | |
| 1339 | operator_advance(&cptr[3],0); |
| 1340 | opfuncs[cptr[3].op_state](&cptr[3]); |
| 1341 | operator_output(&cptr[3],cptr[9].cval*FIXEDPT,tremval2[i]); |
| 1342 | |
| 1343 | Bit32s chanval = cptr[3].cval; |
| 1344 | CHANVAL_OUT |
| 1345 | } |
| 1346 | } |
| 1347 | |
| 1348 | if (cptr[3+9].op_state != OF_TYPE_OFF) { |
| 1349 | if (cptr[3+9].tremolo) tremval1 = trem_lut; // tremolo enabled, use table |
| 1350 | else tremval1 = tremval_const; |
| 1351 | |
| 1352 | // calculate channel output |
| 1353 | for (i=0;i<endsamples;i++) { |
| 1354 | operator_advance(&cptr[3+9],0); |
| 1355 | opfuncs[cptr[3+9].op_state](&cptr[3+9]); |
| 1356 | operator_output(&cptr[3+9],0,tremval1[i]); |
| 1357 | |
| 1358 | Bit32s chanval = cptr[3+9].cval; |
| 1359 | CHANVAL_OUT |
| 1360 | } |
| 1361 | } |
| 1362 | } else { |
| 1363 | // AM-FM-style synthesis (op1[fb] + (op2 * op3 * op4)) |
| 1364 | if (cptr[0].op_state != OF_TYPE_OFF) { |
| 1365 | if (cptr[0].vibrato) { |
| 1366 | vibval1 = vibval_var1; |
| 1367 | for (i=0;i<endsamples;i++) |
| 1368 | vibval1[i] = (Bit32s)((vib_lut[i]*cptr[0].freq_high/8)*FIXEDPT*VIBFAC); |
| 1369 | } else vibval1 = vibval_const; |
| 1370 | if (cptr[0].tremolo) tremval1 = trem_lut; // tremolo enabled, use table |
| 1371 | else tremval1 = tremval_const; |
| 1372 | |
| 1373 | // calculate channel output |
| 1374 | for (i=0;i<endsamples;i++) { |
| 1375 | operator_advance(&cptr[0],vibval1[i]); |
| 1376 | opfuncs[cptr[0].op_state](&cptr[0]); |
| 1377 | operator_output(&cptr[0],(cptr[0].lastcval+cptr[0].cval)*cptr[0].mfbi/2,tremval1[i]); |
| 1378 | |
| 1379 | Bit32s chanval = cptr[0].cval; |
| 1380 | CHANVAL_OUT |
| 1381 | } |
| 1382 | } |
| 1383 | |
| 1384 | if ((cptr[9].op_state != OF_TYPE_OFF) || (cptr[3].op_state != OF_TYPE_OFF) || (cptr[3+9].op_state != OF_TYPE_OFF)) { |
| 1385 | if ((cptr[9].vibrato) && (cptr[9].op_state != OF_TYPE_OFF)) { |
| 1386 | vibval1 = vibval_var1; |
| 1387 | for (i=0;i<endsamples;i++) |
| 1388 | vibval1[i] = (Bit32s)((vib_lut[i]*cptr[9].freq_high/8)*FIXEDPT*VIBFAC); |
| 1389 | } else vibval1 = vibval_const; |
| 1390 | if (cptr[9].tremolo) tremval1 = trem_lut; // tremolo enabled, use table |
| 1391 | else tremval1 = tremval_const; |
| 1392 | if (cptr[3].tremolo) tremval2 = trem_lut; // tremolo enabled, use table |
| 1393 | else tremval2 = tremval_const; |
| 1394 | if (cptr[3+9].tremolo) tremval3 = trem_lut; // tremolo enabled, use table |
| 1395 | else tremval3 = tremval_const; |
| 1396 | |
| 1397 | // calculate channel output |
| 1398 | for (i=0;i<endsamples;i++) { |
| 1399 | operator_advance(&cptr[9],vibval1[i]); |
| 1400 | opfuncs[cptr[9].op_state](&cptr[9]); |
| 1401 | operator_output(&cptr[9],0,tremval1[i]); |
| 1402 | |
| 1403 | operator_advance(&cptr[3],0); |
| 1404 | opfuncs[cptr[3].op_state](&cptr[3]); |
| 1405 | operator_output(&cptr[3],cptr[9].cval*FIXEDPT,tremval2[i]); |
| 1406 | |
| 1407 | operator_advance(&cptr[3+9],0); |
| 1408 | opfuncs[cptr[3+9].op_state](&cptr[3+9]); |
| 1409 | operator_output(&cptr[3+9],cptr[3].cval*FIXEDPT,tremval3[i]); |
| 1410 | |
| 1411 | Bit32s chanval = cptr[3+9].cval; |
| 1412 | CHANVAL_OUT |
| 1413 | } |
| 1414 | } |
| 1415 | } |
| 1416 | continue; |
| 1417 | } |
| 1418 | #endif |
| 1419 | // 2op additive synthesis |
| 1420 | if ((cptr[9].op_statecxx . . $ operator_struct#op_state. == OF_TYPE_OFFcxx . . $ `src/opl.c:69:9`!) && (cptr[0].op_statecxx . . $ operator_struct#op_state. == OF_TYPE_OFFcxx . . $ `src/opl.c:69:9`!)) continue; |
| 1421 | if ((cptr[0].vibratocxx . . $ operator_struct#vibrato.) && (cptr[0].op_statecxx . . $ operator_struct#op_state. != OF_TYPE_OFFcxx . . $ `src/opl.c:69:9`!)) { |
| 1422 | vibval1cxx . . $ vibval1. = vibval_var1cxx . . $ vibval_var1.; |
| 1423 | for (i=0;i<endsamples;i++) |
| 1424 | vibval1cxx . . $ vibval1.[i] = (Bit32scxx . . $ Bit32s#)((vib_lut[i]*cptr[0].freq_highcxx . . $ operator_struct#freq_high./8)*FIXEDPTcxx . . $ `src/opl.c:56:9`!*VIBFACcxx . . $ `src/opl.c:94:9`!); |
| 1425 | } else vibval1cxx . . $ vibval1. = vibval_constcxx . . $ vibval_const.; |
| 1426 | if ((cptr[9].vibratocxx . . $ operator_struct#vibrato.) && (cptr[9].op_statecxx . . $ operator_struct#op_state. != OF_TYPE_OFFcxx . . $ `src/opl.c:69:9`!)) { |
| 1427 | vibval2cxx . . $ vibval2. = vibval_var2cxx . . $ vibval_var2.; |
| 1428 | for (i=0;i<endsamples;i++) |
| 1429 | vibval2cxx . . $ vibval2.[i] = (Bit32scxx . . $ Bit32s#)((vib_lut[i]*cptr[9].freq_highcxx . . $ operator_struct#freq_high./8)*FIXEDPTcxx . . $ `src/opl.c:56:9`!*VIBFACcxx . . $ `src/opl.c:94:9`!); |
| 1430 | } else vibval2cxx . . $ vibval2. = vibval_constcxx . . $ vibval_const.; |
| 1431 | if (cptr[0].tremolocxx . . $ operator_struct#tremolo.) tremval1cxx . . $ tremval1. = trem_lut; // tremolo enabled, use table |
| 1432 | else tremval1cxx . . $ tremval1. = tremval_constcxx . . $ tremval_const.; |
| 1433 | if (cptr[9].tremolocxx . . $ operator_struct#tremolo.) tremval2cxx . . $ tremval2. = trem_lut; // tremolo enabled, use table |
| 1434 | else tremval2cxx . . $ tremval2. = tremval_constcxx . . $ tremval_const.; |
| 1435 | |
| 1436 | // calculate channel output |
| 1437 | for (i=0;i<endsamples;i++) { |
| 1438 | // carrier1 |
| 1439 | operator_advancecxx . . $ operator_advance(90c6108e829b6b0c).(&cptr[0],vibval1cxx . . $ vibval1.[i]); |
| 1440 | opfuncscxx . . $ opfuncs.[cptr[0].op_statecxx . . $ operator_struct#op_state.](&cptr[0]); |
| 1441 | operator_outputcxx . . $ operator_output(4521a3a0338f20a).(&cptr[0],(cptr[0].lastcvalcxx . . $ operator_struct#lastcval.+cptr[0].cvalcxx . . $ operator_struct#cval.)*cptr[0].mfbicxx . . $ operator_struct#mfbi./2,tremval1cxx . . $ tremval1.[i]); |
| 1442 | |
| 1443 | // carrier2 |
| 1444 | operator_advancecxx . . $ operator_advance(90c6108e829b6b0c).(&cptr[9],vibval2cxx . . $ vibval2.[i]); |
| 1445 | opfuncscxx . . $ opfuncs.[cptr[9].op_statecxx . . $ operator_struct#op_state.](&cptr[9]); |
| 1446 | operator_outputcxx . . $ operator_output(4521a3a0338f20a).(&cptr[9],0,tremval2cxx . . $ tremval2.[i]); |
| 1447 | |
| 1448 | Bit32scxx . . $ Bit32s# chanval = cptr[9].cvalcxx . . $ operator_struct#cval. + cptr[0].cvalcxx . . $ operator_struct#cval.; |
| 1449 | CHANVAL_OUTcxx . . $ `src/opl.c:1100:9`! |
| 1450 | } |
| 1451 | } else { |
| 1452 | #if defined(OPLTYPE_IS_OPL3) |
| 1453 | if ((adlibreg[0x105]&1) && cptr->is_4op) { |
| 1454 | if (adlibreg[ARC_FEEDBACK+k+3]&1) { |
| 1455 | // FM-AM-style synthesis ((op1[fb] * op2) + (op3 * op4)) |
| 1456 | if ((cptr[0].op_state != OF_TYPE_OFF) || (cptr[9].op_state != OF_TYPE_OFF)) { |
| 1457 | if ((cptr[0].vibrato) && (cptr[0].op_state != OF_TYPE_OFF)) { |
| 1458 | vibval1 = vibval_var1; |
| 1459 | for (i=0;i<endsamples;i++) |
| 1460 | vibval1[i] = (Bit32s)((vib_lut[i]*cptr[0].freq_high/8)*FIXEDPT*VIBFAC); |
| 1461 | } else vibval1 = vibval_const; |
| 1462 | if ((cptr[9].vibrato) && (cptr[9].op_state != OF_TYPE_OFF)) { |
| 1463 | vibval2 = vibval_var2; |
| 1464 | for (i=0;i<endsamples;i++) |
| 1465 | vibval2[i] = (Bit32s)((vib_lut[i]*cptr[9].freq_high/8)*FIXEDPT*VIBFAC); |
| 1466 | } else vibval2 = vibval_const; |
| 1467 | if (cptr[0].tremolo) tremval1 = trem_lut; // tremolo enabled, use table |
| 1468 | else tremval1 = tremval_const; |
| 1469 | if (cptr[9].tremolo) tremval2 = trem_lut; // tremolo enabled, use table |
| 1470 | else tremval2 = tremval_const; |
| 1471 | |
| 1472 | // calculate channel output |
| 1473 | for (i=0;i<endsamples;i++) { |
| 1474 | operator_advance(&cptr[0],vibval1[i]); |
| 1475 | opfuncs[cptr[0].op_state](&cptr[0]); |
| 1476 | operator_output(&cptr[0],(cptr[0].lastcval+cptr[0].cval)*cptr[0].mfbi/2,tremval1[i]); |
| 1477 | |
| 1478 | operator_advance(&cptr[9],vibval2[i]); |
| 1479 | opfuncs[cptr[9].op_state](&cptr[9]); |
| 1480 | operator_output(&cptr[9],cptr[0].cval*FIXEDPT,tremval2[i]); |
| 1481 | |
| 1482 | Bit32s chanval = cptr[9].cval; |
| 1483 | CHANVAL_OUT |
| 1484 | } |
| 1485 | } |
| 1486 | |
| 1487 | if ((cptr[3].op_state != OF_TYPE_OFF) || (cptr[3+9].op_state != OF_TYPE_OFF)) { |
| 1488 | if (cptr[3].tremolo) tremval1 = trem_lut; // tremolo enabled, use table |
| 1489 | else tremval1 = tremval_const; |
| 1490 | if (cptr[3+9].tremolo) tremval2 = trem_lut; // tremolo enabled, use table |
| 1491 | else tremval2 = tremval_const; |
| 1492 | |
| 1493 | // calculate channel output |
| 1494 | for (i=0;i<endsamples;i++) { |
| 1495 | operator_advance(&cptr[3],0); |
| 1496 | opfuncs[cptr[3].op_state](&cptr[3]); |
| 1497 | operator_output(&cptr[3],0,tremval1[i]); |
| 1498 | |
| 1499 | operator_advance(&cptr[3+9],0); |
| 1500 | opfuncs[cptr[3+9].op_state](&cptr[3+9]); |
| 1501 | operator_output(&cptr[3+9],cptr[3].cval*FIXEDPT,tremval2[i]); |
| 1502 | |
| 1503 | Bit32s chanval = cptr[3+9].cval; |
| 1504 | CHANVAL_OUT |
| 1505 | } |
| 1506 | } |
| 1507 | |
| 1508 | } else { |
| 1509 | // FM-FM-style synthesis (op1[fb] * op2 * op3 * op4) |
| 1510 | if ((cptr[0].op_state != OF_TYPE_OFF) || (cptr[9].op_state != OF_TYPE_OFF) || |
| 1511 | (cptr[3].op_state != OF_TYPE_OFF) || (cptr[3+9].op_state != OF_TYPE_OFF)) { |
| 1512 | if ((cptr[0].vibrato) && (cptr[0].op_state != OF_TYPE_OFF)) { |
| 1513 | vibval1 = vibval_var1; |
| 1514 | for (i=0;i<endsamples;i++) |
| 1515 | vibval1[i] = (Bit32s)((vib_lut[i]*cptr[0].freq_high/8)*FIXEDPT*VIBFAC); |
| 1516 | } else vibval1 = vibval_const; |
| 1517 | if ((cptr[9].vibrato) && (cptr[9].op_state != OF_TYPE_OFF)) { |
| 1518 | vibval2 = vibval_var2; |
| 1519 | for (i=0;i<endsamples;i++) |
| 1520 | vibval2[i] = (Bit32s)((vib_lut[i]*cptr[9].freq_high/8)*FIXEDPT*VIBFAC); |
| 1521 | } else vibval2 = vibval_const; |
| 1522 | if (cptr[0].tremolo) tremval1 = trem_lut; // tremolo enabled, use table |
| 1523 | else tremval1 = tremval_const; |
| 1524 | if (cptr[9].tremolo) tremval2 = trem_lut; // tremolo enabled, use table |
| 1525 | else tremval2 = tremval_const; |
| 1526 | if (cptr[3].tremolo) tremval3 = trem_lut; // tremolo enabled, use table |
| 1527 | else tremval3 = tremval_const; |
| 1528 | if (cptr[3+9].tremolo) tremval4 = trem_lut; // tremolo enabled, use table |
| 1529 | else tremval4 = tremval_const; |
| 1530 | |
| 1531 | // calculate channel output |
| 1532 | for (i=0;i<endsamples;i++) { |
| 1533 | operator_advance(&cptr[0],vibval1[i]); |
| 1534 | opfuncs[cptr[0].op_state](&cptr[0]); |
| 1535 | operator_output(&cptr[0],(cptr[0].lastcval+cptr[0].cval)*cptr[0].mfbi/2,tremval1[i]); |
| 1536 | |
| 1537 | operator_advance(&cptr[9],vibval2[i]); |
| 1538 | opfuncs[cptr[9].op_state](&cptr[9]); |
| 1539 | operator_output(&cptr[9],cptr[0].cval*FIXEDPT,tremval2[i]); |
| 1540 | |
| 1541 | operator_advance(&cptr[3],0); |
| 1542 | opfuncs[cptr[3].op_state](&cptr[3]); |
| 1543 | operator_output(&cptr[3],cptr[9].cval*FIXEDPT,tremval3[i]); |
| 1544 | |
| 1545 | operator_advance(&cptr[3+9],0); |
| 1546 | opfuncs[cptr[3+9].op_state](&cptr[3+9]); |
| 1547 | operator_output(&cptr[3+9],cptr[3].cval*FIXEDPT,tremval4[i]); |
| 1548 | |
| 1549 | Bit32s chanval = cptr[3+9].cval; |
| 1550 | CHANVAL_OUT |
| 1551 | } |
| 1552 | } |
| 1553 | } |
| 1554 | continue; |
| 1555 | } |
| 1556 | #endif |
| 1557 | // 2op frequency modulation |
| 1558 | if ((cptr[9].op_statecxx . . $ operator_struct#op_state. == OF_TYPE_OFFcxx . . $ `src/opl.c:69:9`!) && (cptr[0].op_statecxx . . $ operator_struct#op_state. == OF_TYPE_OFFcxx . . $ `src/opl.c:69:9`!)) continue; |
| 1559 | if ((cptr[0].vibratocxx . . $ operator_struct#vibrato.) && (cptr[0].op_statecxx . . $ operator_struct#op_state. != OF_TYPE_OFFcxx . . $ `src/opl.c:69:9`!)) { |
| 1560 | vibval1cxx . . $ vibval1. = vibval_var1cxx . . $ vibval_var1.; |
| 1561 | for (i=0;i<endsamples;i++) |
| 1562 | vibval1cxx . . $ vibval1.[i] = (Bit32scxx . . $ Bit32s#)((vib_lut[i]*cptr[0].freq_highcxx . . $ operator_struct#freq_high./8)*FIXEDPTcxx . . $ `src/opl.c:56:9`!*VIBFACcxx . . $ `src/opl.c:94:9`!); |
| 1563 | } else vibval1cxx . . $ vibval1. = vibval_constcxx . . $ vibval_const.; |
| 1564 | if ((cptr[9].vibratocxx . . $ operator_struct#vibrato.) && (cptr[9].op_statecxx . . $ operator_struct#op_state. != OF_TYPE_OFFcxx . . $ `src/opl.c:69:9`!)) { |
| 1565 | vibval2cxx . . $ vibval2. = vibval_var2cxx . . $ vibval_var2.; |
| 1566 | for (i=0;i<endsamples;i++) |
| 1567 | vibval2cxx . . $ vibval2.[i] = (Bit32scxx . . $ Bit32s#)((vib_lut[i]*cptr[9].freq_highcxx . . $ operator_struct#freq_high./8)*FIXEDPTcxx . . $ `src/opl.c:56:9`!*VIBFACcxx . . $ `src/opl.c:94:9`!); |
| 1568 | } else vibval2cxx . . $ vibval2. = vibval_constcxx . . $ vibval_const.; |
| 1569 | if (cptr[0].tremolocxx . . $ operator_struct#tremolo.) tremval1cxx . . $ tremval1. = trem_lut; // tremolo enabled, use table |
| 1570 | else tremval1cxx . . $ tremval1. = tremval_constcxx . . $ tremval_const.; |
| 1571 | if (cptr[9].tremolocxx . . $ operator_struct#tremolo.) tremval2cxx . . $ tremval2. = trem_lut; // tremolo enabled, use table |
| 1572 | else tremval2cxx . . $ tremval2. = tremval_constcxx . . $ tremval_const.; |
| 1573 | |
| 1574 | // calculate channel output |
| 1575 | for (i=0;i<endsamples;i++) { |
| 1576 | // modulator |
| 1577 | operator_advancecxx . . $ operator_advance(90c6108e829b6b0c).(&cptr[0],vibval1cxx . . $ vibval1.[i]); |
| 1578 | opfuncscxx . . $ opfuncs.[cptr[0].op_statecxx . . $ operator_struct#op_state.](&cptr[0]); |
| 1579 | operator_outputcxx . . $ operator_output(4521a3a0338f20a).(&cptr[0],(cptr[0].lastcvalcxx . . $ operator_struct#lastcval.+cptr[0].cvalcxx . . $ operator_struct#cval.)*cptr[0].mfbicxx . . $ operator_struct#mfbi./2,tremval1cxx . . $ tremval1.[i]); |
| 1580 | |
| 1581 | // carrier |
| 1582 | operator_advancecxx . . $ operator_advance(90c6108e829b6b0c).(&cptr[9],vibval2cxx . . $ vibval2.[i]); |
| 1583 | opfuncscxx . . $ opfuncs.[cptr[9].op_statecxx . . $ operator_struct#op_state.](&cptr[9]); |
| 1584 | operator_outputcxx . . $ operator_output(4521a3a0338f20a).(&cptr[9],cptr[0].cvalcxx . . $ operator_struct#cval.*FIXEDPTcxx . . $ `src/opl.c:56:9`!,tremval2cxx . . $ tremval2.[i]); |
| 1585 | |
| 1586 | Bit32scxx . . $ Bit32s# chanval = cptr[9].cvalcxx . . $ operator_struct#cval.; |
| 1587 | CHANVAL_OUTcxx . . $ `src/opl.c:1100:9`! |
| 1588 | } |
| 1589 | } |
| 1590 | } |
| 1591 | |
| 1592 | #if defined(OPLTYPE_IS_OPL3) |
| 1593 | if (adlibreg[0x105]&1) { |
| 1594 | // convert to 16bit samples (stereo) |
| 1595 | for (i=0;i<endsamples;i++) { |
| 1596 | clipit16(outbufl[i],sndptr++); |
| 1597 | clipit16(outbufr[i],sndptr++); |
| 1598 | } |
| 1599 | } else { |
| 1600 | // convert to 16bit samples (mono) |
| 1601 | for (i=0;i<endsamples;i++) { |
| 1602 | clipit16(outbufl[i],sndptr++); |
| 1603 | clipit16(outbufl[i],sndptr++); |
| 1604 | } |
| 1605 | } |
| 1606 | #else |
| 1607 | // convert to 16bit samples |
| 1608 | for (i=0;i<endsamples;i++) |
| 1609 | clipit16cxx . . $ clipit16(4c4d8747bb7d9d45).(outbufl[i],sndptr++); |
| 1610 | #endif |
| 1611 | |
| 1612 | } |
| 1613 | } |