| 1 | // ---------------------------------------------------------------------------cxx . . $ `<file>/src/resid/wave.h`/ |
| 2 | // This file is part of reSID, a MOS6581 SID emulator engine. |
| 3 | // Copyright (C) 2004 Dag Lem <[email protected]> |
| 4 | // |
| 5 | // This program is free software; you can redistribute it and/or modify |
| 6 | // it under the terms of the GNU General Public License as published by |
| 7 | // the Free Software Foundation; either version 2 of the License, or |
| 8 | // (at your option) any later version. |
| 9 | // |
| 10 | // This program is distributed in the hope that it will be useful, |
| 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | // GNU General Public License for more details. |
| 14 | // |
| 15 | // You should have received a copy of the GNU General Public License |
| 16 | // along with this program; if not, write to the Free Software |
| 17 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | // --------------------------------------------------------------------------- |
| 19 | |
| 20 | #ifndef __WAVE_H__ |
| 21 | #define __WAVE_H__cxx . . $ `src/resid/wave.h:21:9`! |
| 22 | |
| 23 | #include "siddefs.h"cxx . . $ `<file>/src/resid/siddefs.h`/ |
| 24 | |
| 25 | // ---------------------------------------------------------------------------- |
| 26 | // A 24 bit accumulator is the basis for waveform generation. FREQ is added to |
| 27 | // the lower 16 bits of the accumulator each cycle. |
| 28 | // The accumulator is set to zero when TEST is set, and starts counting |
| 29 | // when TEST is cleared. |
| 30 | // The noise waveform is taken from intermediate bits of a 23 bit shift |
| 31 | // register. This register is clocked by bit 19 of the accumulator. |
| 32 | // ---------------------------------------------------------------------------- |
| 33 | class WaveformGeneratorcxx . . $ WaveformGenerator# |
| 34 | { |
| 35 | public: |
| 36 | WaveformGeneratorcxx . . $ WaveformGenerator#WaveformGenerator(49f6e7a06ebc5aa8).(); |
| 37 | |
| 38 | void set_sync_sourcecxx . . $ WaveformGenerator#set_sync_source(567819d4c5355d59).(WaveformGeneratorcxx . . $ WaveformGenerator#*); |
| 39 | void set_chip_modelcxx . . $ WaveformGenerator#set_chip_model(cea143c94d31b99f).(chip_modelcxx . . $ chip_model# model); |
| 40 | |
| 41 | RESID_INLINEcxx . . $ `src/resid/siddefs.h:70:9`! void clockcxx . . $ WaveformGenerator#clock(49f6e7a06ebc5aa8).(); |
| 42 | RESID_INLINEcxx . . $ `src/resid/siddefs.h:70:9`! void clockcxx . . $ WaveformGenerator#clock(d4f767463ce0a6b3).(cycle_countcxx . . $ cycle_count# delta_t); |
| 43 | RESID_INLINEcxx . . $ `src/resid/siddefs.h:70:9`! void synchronizecxx . . $ WaveformGenerator#synchronize(49f6e7a06ebc5aa8).(); |
| 44 | void resetcxx . . $ WaveformGenerator#reset(49f6e7a06ebc5aa8).(); |
| 45 | |
| 46 | void writeFREQ_LOcxx . . $ WaveformGenerator#writeFREQ_LO(cb2f890c2fdad230).(reg8cxx . . $ reg8#); |
| 47 | void writeFREQ_HIcxx . . $ WaveformGenerator#writeFREQ_HI(cb2f890c2fdad230).(reg8cxx . . $ reg8#); |
| 48 | void writePW_LOcxx . . $ WaveformGenerator#writePW_LO(cb2f890c2fdad230).(reg8cxx . . $ reg8#); |
| 49 | void writePW_HIcxx . . $ WaveformGenerator#writePW_HI(cb2f890c2fdad230).(reg8cxx . . $ reg8#); |
| 50 | void writeCONTROL_REGcxx . . $ WaveformGenerator#writeCONTROL_REG(cb2f890c2fdad230).(reg8cxx . . $ reg8#); |
| 51 | reg8cxx . . $ reg8# readOSCcxx . . $ WaveformGenerator#readOSC(db52760e79bf9054).(); |
| 52 | |
| 53 | // 12-bit waveform output. |
| 54 | RESID_INLINEcxx . . $ `src/resid/siddefs.h:70:9`! reg12cxx . . $ reg12# outputcxx . . $ WaveformGenerator#output(db52760e79bf9054).(); |
| 55 | |
| 56 | protected: |
| 57 | const WaveformGeneratorcxx . . $ WaveformGenerator#* sync_sourcecxx . . $ WaveformGenerator#sync_source.; |
| 58 | WaveformGeneratorcxx . . $ WaveformGenerator#* sync_destcxx . . $ WaveformGenerator#sync_dest.; |
| 59 | |
| 60 | // Tell whether the accumulator MSB was set high on this cycle. |
| 61 | bool msb_risingcxx . . $ WaveformGenerator#msb_rising.; |
| 62 | |
| 63 | reg24cxx . . $ reg24# accumulatorcxx . . $ WaveformGenerator#accumulator.; |
| 64 | reg24cxx . . $ reg24# shift_registercxx . . $ WaveformGenerator#shift_register.; |
| 65 | |
| 66 | // Fout = (Fn*Fclk/16777216)Hz |
| 67 | reg16cxx . . $ reg16# freqcxx . . $ WaveformGenerator#freq.; |
| 68 | // PWout = (PWn/40.95)% |
| 69 | reg12cxx . . $ reg12# pwcxx . . $ WaveformGenerator#pw.; |
| 70 | |
| 71 | // The control register right-shifted 4 bits; used for output function |
| 72 | // table lookup. |
| 73 | reg8cxx . . $ reg8# waveformcxx . . $ WaveformGenerator#waveform.; |
| 74 | |
| 75 | // The remaining control register bits. |
| 76 | reg8cxx . . $ reg8# testcxx . . $ WaveformGenerator#test.; |
| 77 | reg8cxx . . $ reg8# ring_modcxx . . $ WaveformGenerator#ring_mod.; |
| 78 | reg8cxx . . $ reg8# synccxx . . $ WaveformGenerator#sync.; |
| 79 | // The gate bit is handled by the EnvelopeGenerator. |
| 80 | |
| 81 | // 16 possible combinations of waveforms. |
| 82 | RESID_INLINEcxx . . $ `src/resid/siddefs.h:70:9`! reg12cxx . . $ reg12# output____cxx . . $ WaveformGenerator#output____(db52760e79bf9054).(); |
| 83 | RESID_INLINEcxx . . $ `src/resid/siddefs.h:70:9`! reg12cxx . . $ reg12# output___Tcxx . . $ WaveformGenerator#output___T(db52760e79bf9054).(); |
| 84 | RESID_INLINEcxx . . $ `src/resid/siddefs.h:70:9`! reg12cxx . . $ reg12# output__S_cxx . . $ WaveformGenerator#output__S_(db52760e79bf9054).(); |
| 85 | RESID_INLINEcxx . . $ `src/resid/siddefs.h:70:9`! reg12cxx . . $ reg12# output__STcxx . . $ WaveformGenerator#output__ST(db52760e79bf9054).(); |
| 86 | RESID_INLINEcxx . . $ `src/resid/siddefs.h:70:9`! reg12cxx . . $ reg12# output_P__cxx . . $ WaveformGenerator#output_P__(db52760e79bf9054).(); |
| 87 | RESID_INLINEcxx . . $ `src/resid/siddefs.h:70:9`! reg12cxx . . $ reg12# output_P_Tcxx . . $ WaveformGenerator#output_P_T(db52760e79bf9054).(); |
| 88 | RESID_INLINEcxx . . $ `src/resid/siddefs.h:70:9`! reg12cxx . . $ reg12# output_PS_cxx . . $ WaveformGenerator#output_PS_(db52760e79bf9054).(); |
| 89 | RESID_INLINEcxx . . $ `src/resid/siddefs.h:70:9`! reg12cxx . . $ reg12# output_PSTcxx . . $ WaveformGenerator#output_PST(db52760e79bf9054).(); |
| 90 | RESID_INLINEcxx . . $ `src/resid/siddefs.h:70:9`! reg12cxx . . $ reg12# outputN___cxx . . $ WaveformGenerator#outputN___(db52760e79bf9054).(); |
| 91 | RESID_INLINEcxx . . $ `src/resid/siddefs.h:70:9`! reg12cxx . . $ reg12# outputN__Tcxx . . $ WaveformGenerator#outputN__T(db52760e79bf9054).(); |
| 92 | RESID_INLINEcxx . . $ `src/resid/siddefs.h:70:9`! reg12cxx . . $ reg12# outputN_S_cxx . . $ WaveformGenerator#outputN_S_(db52760e79bf9054).(); |
| 93 | RESID_INLINEcxx . . $ `src/resid/siddefs.h:70:9`! reg12cxx . . $ reg12# outputN_STcxx . . $ WaveformGenerator#outputN_ST(db52760e79bf9054).(); |
| 94 | RESID_INLINEcxx . . $ `src/resid/siddefs.h:70:9`! reg12cxx . . $ reg12# outputNP__cxx . . $ WaveformGenerator#outputNP__(db52760e79bf9054).(); |
| 95 | RESID_INLINEcxx . . $ `src/resid/siddefs.h:70:9`! reg12cxx . . $ reg12# outputNP_Tcxx . . $ WaveformGenerator#outputNP_T(db52760e79bf9054).(); |
| 96 | RESID_INLINEcxx . . $ `src/resid/siddefs.h:70:9`! reg12cxx . . $ reg12# outputNPS_cxx . . $ WaveformGenerator#outputNPS_(db52760e79bf9054).(); |
| 97 | RESID_INLINEcxx . . $ `src/resid/siddefs.h:70:9`! reg12cxx . . $ reg12# outputNPSTcxx . . $ WaveformGenerator#outputNPST(db52760e79bf9054).(); |
| 98 | |
| 99 | // Sample data for combinations of waveforms. |
| 100 | static reg8cxx . . $ reg8# wave6581__STcxx . . $ WaveformGenerator#wave6581__ST.[]; |
| 101 | static reg8cxx . . $ reg8# wave6581_P_Tcxx . . $ WaveformGenerator#wave6581_P_T.[]; |
| 102 | static reg8cxx . . $ reg8# wave6581_PS_cxx . . $ WaveformGenerator#wave6581_PS_.[]; |
| 103 | static reg8cxx . . $ reg8# wave6581_PSTcxx . . $ WaveformGenerator#wave6581_PST.[]; |
| 104 | |
| 105 | static reg8cxx . . $ reg8# wave8580__STcxx . . $ WaveformGenerator#wave8580__ST.[]; |
| 106 | static reg8cxx . . $ reg8# wave8580_P_Tcxx . . $ WaveformGenerator#wave8580_P_T.[]; |
| 107 | static reg8cxx . . $ reg8# wave8580_PS_cxx . . $ WaveformGenerator#wave8580_PS_.[]; |
| 108 | static reg8cxx . . $ reg8# wave8580_PSTcxx . . $ WaveformGenerator#wave8580_PST.[]; |
| 109 | |
| 110 | reg8cxx . . $ reg8#* wave__STcxx . . $ WaveformGenerator#wave__ST.; |
| 111 | reg8cxx . . $ reg8#* wave_P_Tcxx . . $ WaveformGenerator#wave_P_T.; |
| 112 | reg8cxx . . $ reg8#* wave_PS_cxx . . $ WaveformGenerator#wave_PS_.; |
| 113 | reg8cxx . . $ reg8#* wave_PSTcxx . . $ WaveformGenerator#wave_PST.; |
| 114 | |
| 115 | friend class Voicecxx . . $ Voice#; |
| 116 | friend class SIDcxx . . $ SID#; |
| 117 | }; |
| 118 | |
| 119 | |
| 120 | // ---------------------------------------------------------------------------- |
| 121 | // Inline functions. |
| 122 | // The following functions are defined inline because they are called every |
| 123 | // time a sample is calculated. |
| 124 | // ---------------------------------------------------------------------------- |
| 125 | |
| 126 | #if RESID_INLININGcxx . . $ `src/resid/siddefs.h:69:9`! || defined(__WAVE_CC__cxx . . $ `src/resid/wave.cpp:20:9`!) |
| 127 | |
| 128 | // ---------------------------------------------------------------------------- |
| 129 | // SID clocking - 1 cycle. |
| 130 | // ---------------------------------------------------------------------------- |
| 131 | RESID_INLINEcxx . . $ `src/resid/siddefs.h:70:9`! |
| 132 | void WaveformGeneratorcxx . . $ WaveformGenerator#::clockcxx . . $ WaveformGenerator#clock(49f6e7a06ebc5aa8).() |
| 133 | { |
| 134 | // No operation if test bit is set. |
| 135 | if (testcxx . . $ WaveformGenerator#test.) { |
| 136 | return; |
| 137 | } |
| 138 | |
| 139 | reg24cxx . . $ reg24# accumulator_prev = accumulatorcxx . . $ WaveformGenerator#accumulator.; |
| 140 | |
| 141 | // Calculate new accumulator value; |
| 142 | accumulatorcxx . . $ WaveformGenerator#accumulator. += freqcxx . . $ WaveformGenerator#freq.; |
| 143 | accumulatorcxx . . $ WaveformGenerator#accumulator. &= 0xffffff; |
| 144 | |
| 145 | // Check whether the MSB is set high. This is used for synchronization. |
| 146 | msb_risingcxx . . $ WaveformGenerator#msb_rising. = !(accumulator_prev & 0x800000) && (accumulatorcxx . . $ WaveformGenerator#accumulator. & 0x800000); |
| 147 | |
| 148 | // Shift noise register once for each time accumulator bit 19 is set high. |
| 149 | if (!(accumulator_prev & 0x080000) && (accumulatorcxx . . $ WaveformGenerator#accumulator. & 0x080000)) { |
| 150 | reg24cxx . . $ reg24# bit0 = ((shift_registercxx . . $ WaveformGenerator#shift_register. >> 22) ^ (shift_registercxx . . $ WaveformGenerator#shift_register. >> 17)) & 0x1; |
| 151 | shift_registercxx . . $ WaveformGenerator#shift_register. <<= 1; |
| 152 | shift_registercxx . . $ WaveformGenerator#shift_register. &= 0x7fffff; |
| 153 | shift_registercxx . . $ WaveformGenerator#shift_register. |= bit0; |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | // ---------------------------------------------------------------------------- |
| 158 | // SID clocking - delta_t cycles. |
| 159 | // ---------------------------------------------------------------------------- |
| 160 | RESID_INLINEcxx . . $ `src/resid/siddefs.h:70:9`! |
| 161 | void WaveformGeneratorcxx . . $ WaveformGenerator#::clockcxx . . $ WaveformGenerator#clock(d4f767463ce0a6b3).(cycle_countcxx . . $ cycle_count# delta_t) |
| 162 | { |
| 163 | // No operation if test bit is set. |
| 164 | if (testcxx . . $ WaveformGenerator#test.) { |
| 165 | return; |
| 166 | } |
| 167 | |
| 168 | reg24cxx . . $ reg24# accumulator_prev = accumulatorcxx . . $ WaveformGenerator#accumulator.; |
| 169 | |
| 170 | // Calculate new accumulator value; |
| 171 | reg24cxx . . $ reg24# delta_accumulator = delta_t*freqcxx . . $ WaveformGenerator#freq.; |
| 172 | accumulatorcxx . . $ WaveformGenerator#accumulator. += delta_accumulator; |
| 173 | accumulatorcxx . . $ WaveformGenerator#accumulator. &= 0xffffff; |
| 174 | |
| 175 | // Check whether the MSB is set high. This is used for synchronization. |
| 176 | msb_risingcxx . . $ WaveformGenerator#msb_rising. = !(accumulator_prev & 0x800000) && (accumulatorcxx . . $ WaveformGenerator#accumulator. & 0x800000); |
| 177 | |
| 178 | // Shift noise register once for each time accumulator bit 19 is set high. |
| 179 | // Bit 19 is set high each time 2^20 (0x100000) is added to the accumulator. |
| 180 | reg24cxx . . $ reg24# shift_period = 0x100000; |
| 181 | |
| 182 | while (delta_accumulator) { |
| 183 | if (delta_accumulator < shift_period) { |
| 184 | shift_period = delta_accumulator; |
| 185 | // Determine whether bit 19 is set on the last period. |
| 186 | // NB! Requires two's complement integer. |
| 187 | if (shift_period <= 0x080000) { |
| 188 | // Check for flip from 0 to 1. |
| 189 | if (((accumulatorcxx . . $ WaveformGenerator#accumulator. - shift_period) & 0x080000) || !(accumulatorcxx . . $ WaveformGenerator#accumulator. & 0x080000)) |
| 190 | { |
| 191 | break; |
| 192 | } |
| 193 | } |
| 194 | else { |
| 195 | // Check for flip from 0 (to 1 or via 1 to 0) or from 1 via 0 to 1. |
| 196 | if (((accumulatorcxx . . $ WaveformGenerator#accumulator. - shift_period) & 0x080000) && !(accumulatorcxx . . $ WaveformGenerator#accumulator. & 0x080000)) |
| 197 | { |
| 198 | break; |
| 199 | } |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | // Shift the noise/random register. |
| 204 | // NB! The shift is actually delayed 2 cycles, this is not modeled. |
| 205 | reg24cxx . . $ reg24# bit0 = ((shift_registercxx . . $ WaveformGenerator#shift_register. >> 22) ^ (shift_registercxx . . $ WaveformGenerator#shift_register. >> 17)) & 0x1; |
| 206 | shift_registercxx . . $ WaveformGenerator#shift_register. <<= 1; |
| 207 | shift_registercxx . . $ WaveformGenerator#shift_register. &= 0x7fffff; |
| 208 | shift_registercxx . . $ WaveformGenerator#shift_register. |= bit0; |
| 209 | |
| 210 | delta_accumulator -= shift_period; |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | |
| 215 | // ---------------------------------------------------------------------------- |
| 216 | // Synchronize oscillators. |
| 217 | // This must be done after all the oscillators have been clock()'ed since the |
| 218 | // oscillators operate in parallel. |
| 219 | // Note that the oscillators must be clocked exactly on the cycle when the |
| 220 | // MSB is set high for hard sync to operate correctly. See SID::clock(). |
| 221 | // ---------------------------------------------------------------------------- |
| 222 | RESID_INLINEcxx . . $ `src/resid/siddefs.h:70:9`! |
| 223 | void WaveformGeneratorcxx . . $ WaveformGenerator#::synchronizecxx . . $ WaveformGenerator#synchronize(49f6e7a06ebc5aa8).() |
| 224 | { |
| 225 | // A special case occurs when a sync source is synced itself on the same |
| 226 | // cycle as when its MSB is set high. In this case the destination will |
| 227 | // not be synced. This has been verified by sampling OSC3. |
| 228 | if (msb_risingcxx . . $ WaveformGenerator#msb_rising. && sync_destcxx . . $ WaveformGenerator#sync_dest.->synccxx . . $ WaveformGenerator#sync. && !(synccxx . . $ WaveformGenerator#sync. && sync_sourcecxx . . $ WaveformGenerator#sync_source.->msb_risingcxx . . $ WaveformGenerator#msb_rising.)) { |
| 229 | sync_destcxx . . $ WaveformGenerator#sync_dest.->accumulatorcxx . . $ WaveformGenerator#accumulator. = 0; |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | |
| 234 | // ---------------------------------------------------------------------------- |
| 235 | // Output functions. |
| 236 | // NB! The output from SID 8580 is delayed one cycle compared to SID 6581, |
| 237 | // this is not modeled. |
| 238 | // ---------------------------------------------------------------------------- |
| 239 | |
| 240 | // No waveform: |
| 241 | // Zero output. |
| 242 | // |
| 243 | RESID_INLINEcxx . . $ `src/resid/siddefs.h:70:9`! |
| 244 | reg12cxx . . $ reg12# WaveformGeneratorcxx . . $ WaveformGenerator#::output____cxx . . $ WaveformGenerator#output____(db52760e79bf9054).() |
| 245 | { |
| 246 | return 0x000; |
| 247 | } |
| 248 | |
| 249 | // Triangle: |
| 250 | // The upper 12 bits of the accumulator are used. |
| 251 | // The MSB is used to create the falling edge of the triangle by inverting |
| 252 | // the lower 11 bits. The MSB is thrown away and the lower 11 bits are |
| 253 | // left-shifted (half the resolution, full amplitude). |
| 254 | // Ring modulation substitutes the MSB with MSB EOR sync_source MSB. |
| 255 | // |
| 256 | RESID_INLINEcxx . . $ `src/resid/siddefs.h:70:9`! |
| 257 | reg12cxx . . $ reg12# WaveformGeneratorcxx . . $ WaveformGenerator#::output___Tcxx . . $ WaveformGenerator#output___T(db52760e79bf9054).() |
| 258 | { |
| 259 | reg24cxx . . $ reg24# msb = (ring_modcxx . . $ WaveformGenerator#ring_mod. ? accumulatorcxx . . $ WaveformGenerator#accumulator. ^ sync_sourcecxx . . $ WaveformGenerator#sync_source.->accumulatorcxx . . $ WaveformGenerator#accumulator. : accumulatorcxx . . $ WaveformGenerator#accumulator.) |
| 260 | & 0x800000; |
| 261 | return ((msb ? ~accumulatorcxx . . $ WaveformGenerator#accumulator. : accumulatorcxx . . $ WaveformGenerator#accumulator.) >> 11) & 0xfff; |
| 262 | } |
| 263 | |
| 264 | // Sawtooth: |
| 265 | // The output is identical to the upper 12 bits of the accumulator. |
| 266 | // |
| 267 | RESID_INLINEcxx . . $ `src/resid/siddefs.h:70:9`! |
| 268 | reg12cxx . . $ reg12# WaveformGeneratorcxx . . $ WaveformGenerator#::output__S_cxx . . $ WaveformGenerator#output__S_(db52760e79bf9054).() |
| 269 | { |
| 270 | return accumulatorcxx . . $ WaveformGenerator#accumulator. >> 12; |
| 271 | } |
| 272 | |
| 273 | // Pulse: |
| 274 | // The upper 12 bits of the accumulator are used. |
| 275 | // These bits are compared to the pulse width register by a 12 bit digital |
| 276 | // comparator; output is either all one or all zero bits. |
| 277 | // NB! The output is actually delayed one cycle after the compare. |
| 278 | // This is not modeled. |
| 279 | // |
| 280 | // The test bit, when set to one, holds the pulse waveform output at 0xfff |
| 281 | // regardless of the pulse width setting. |
| 282 | // |
| 283 | RESID_INLINEcxx . . $ `src/resid/siddefs.h:70:9`! |
| 284 | reg12cxx . . $ reg12# WaveformGeneratorcxx . . $ WaveformGenerator#::output_P__cxx . . $ WaveformGenerator#output_P__(db52760e79bf9054).() |
| 285 | { |
| 286 | return (testcxx . . $ WaveformGenerator#test. || (accumulatorcxx . . $ WaveformGenerator#accumulator. >> 12) >= pwcxx . . $ WaveformGenerator#pw.) ? 0xfff : 0x000; |
| 287 | } |
| 288 | |
| 289 | // Noise: |
| 290 | // The noise output is taken from intermediate bits of a 23-bit shift register |
| 291 | // which is clocked by bit 19 of the accumulator. |
| 292 | // NB! The output is actually delayed 2 cycles after bit 19 is set high. |
| 293 | // This is not modeled. |
| 294 | // |
| 295 | // Operation: Calculate EOR result, shift register, set bit 0 = result. |
| 296 | // |
| 297 | // ----------------------->--------------------- |
| 298 | // | | |
| 299 | // ----EOR---- | |
| 300 | // | | | |
| 301 | // 2 2 2 1 1 1 1 1 1 1 1 1 1 | |
| 302 | // Register bits: 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 <--- |
| 303 | // | | | | | | | | |
| 304 | // OSC3 bits : 7 6 5 4 3 2 1 0 |
| 305 | // |
| 306 | // Since waveform output is 12 bits the output is left-shifted 4 times. |
| 307 | // |
| 308 | RESID_INLINEcxx . . $ `src/resid/siddefs.h:70:9`! |
| 309 | reg12cxx . . $ reg12# WaveformGeneratorcxx . . $ WaveformGenerator#::outputN___cxx . . $ WaveformGenerator#outputN___(db52760e79bf9054).() |
| 310 | { |
| 311 | return |
| 312 | ((shift_registercxx . . $ WaveformGenerator#shift_register. & 0x400000) >> 11) | |
| 313 | ((shift_registercxx . . $ WaveformGenerator#shift_register. & 0x100000) >> 10) | |
| 314 | ((shift_registercxx . . $ WaveformGenerator#shift_register. & 0x010000) >> 7) | |
| 315 | ((shift_registercxx . . $ WaveformGenerator#shift_register. & 0x002000) >> 5) | |
| 316 | ((shift_registercxx . . $ WaveformGenerator#shift_register. & 0x000800) >> 4) | |
| 317 | ((shift_registercxx . . $ WaveformGenerator#shift_register. & 0x000080) >> 1) | |
| 318 | ((shift_registercxx . . $ WaveformGenerator#shift_register. & 0x000010) << 1) | |
| 319 | ((shift_registercxx . . $ WaveformGenerator#shift_register. & 0x000004) << 2); |
| 320 | } |
| 321 | |
| 322 | // Combined waveforms: |
| 323 | // By combining waveforms, the bits of each waveform are effectively short |
| 324 | // circuited. A zero bit in one waveform will result in a zero output bit |
| 325 | // (thus the infamous claim that the waveforms are AND'ed). |
| 326 | // However, a zero bit in one waveform will also affect the neighboring bits |
| 327 | // in the output. The reason for this has not been determined. |
| 328 | // |
| 329 | // Example: |
| 330 | // |
| 331 | // 1 1 |
| 332 | // Bit # 1 0 9 8 7 6 5 4 3 2 1 0 |
| 333 | // ----------------------- |
| 334 | // Sawtooth 0 0 0 1 1 1 1 1 1 0 0 0 |
| 335 | // |
| 336 | // Triangle 0 0 1 1 1 1 1 1 0 0 0 0 |
| 337 | // |
| 338 | // AND 0 0 0 1 1 1 1 1 0 0 0 0 |
| 339 | // |
| 340 | // Output 0 0 0 0 1 1 1 0 0 0 0 0 |
| 341 | // |
| 342 | // |
| 343 | // This behavior would be quite difficult to model exactly, since the SID |
| 344 | // in this case does not act as a digital state machine. Tests show that minor |
| 345 | // (1 bit) differences can actually occur in the output from otherwise |
| 346 | // identical samples from OSC3 when waveforms are combined. To further |
| 347 | // complicate the situation the output changes slightly with time (more |
| 348 | // neighboring bits are successively set) when the 12-bit waveform |
| 349 | // registers are kept unchanged. |
| 350 | // |
| 351 | // It is probably possible to come up with a valid model for the |
| 352 | // behavior, however this would be far too slow for practical use since it |
| 353 | // would have to be based on the mutual influence of individual bits. |
| 354 | // |
| 355 | // The output is instead approximated by using the upper bits of the |
| 356 | // accumulator as an index to look up the combined output in a table |
| 357 | // containing actual combined waveform samples from OSC3. |
| 358 | // These samples are 8 bit, so 4 bits of waveform resolution is lost. |
| 359 | // All OSC3 samples are taken with FREQ=0x1000, adding a 1 to the upper 12 |
| 360 | // bits of the accumulator each cycle for a sample period of 4096 cycles. |
| 361 | // |
| 362 | // Sawtooth+Triangle: |
| 363 | // The sawtooth output is used to look up an OSC3 sample. |
| 364 | // |
| 365 | // Pulse+Triangle: |
| 366 | // The triangle output is right-shifted and used to look up an OSC3 sample. |
| 367 | // The sample is output if the pulse output is on. |
| 368 | // The reason for using the triangle output as the index is to handle ring |
| 369 | // modulation. Only the first half of the sample is used, which should be OK |
| 370 | // since the triangle waveform has half the resolution of the accumulator. |
| 371 | // |
| 372 | // Pulse+Sawtooth: |
| 373 | // The sawtooth output is used to look up an OSC3 sample. |
| 374 | // The sample is output if the pulse output is on. |
| 375 | // |
| 376 | // Pulse+Sawtooth+Triangle: |
| 377 | // The sawtooth output is used to look up an OSC3 sample. |
| 378 | // The sample is output if the pulse output is on. |
| 379 | // |
| 380 | RESID_INLINEcxx . . $ `src/resid/siddefs.h:70:9`! |
| 381 | reg12cxx . . $ reg12# WaveformGeneratorcxx . . $ WaveformGenerator#::output__STcxx . . $ WaveformGenerator#output__ST(db52760e79bf9054).() |
| 382 | { |
| 383 | return wave__STcxx . . $ WaveformGenerator#wave__ST.[output__S_cxx . . $ WaveformGenerator#output__S_(db52760e79bf9054).()] << 4; |
| 384 | } |
| 385 | |
| 386 | RESID_INLINEcxx . . $ `src/resid/siddefs.h:70:9`! |
| 387 | reg12cxx . . $ reg12# WaveformGeneratorcxx . . $ WaveformGenerator#::output_P_Tcxx . . $ WaveformGenerator#output_P_T(db52760e79bf9054).() |
| 388 | { |
| 389 | return (wave_P_Tcxx . . $ WaveformGenerator#wave_P_T.[output___Tcxx . . $ WaveformGenerator#output___T(db52760e79bf9054).() >> 1] << 4) & output_P__cxx . . $ WaveformGenerator#output_P__(db52760e79bf9054).(); |
| 390 | } |
| 391 | |
| 392 | RESID_INLINEcxx . . $ `src/resid/siddefs.h:70:9`! |
| 393 | reg12cxx . . $ reg12# WaveformGeneratorcxx . . $ WaveformGenerator#::output_PS_cxx . . $ WaveformGenerator#output_PS_(db52760e79bf9054).() |
| 394 | { |
| 395 | return (wave_PS_cxx . . $ WaveformGenerator#wave_PS_.[output__S_cxx . . $ WaveformGenerator#output__S_(db52760e79bf9054).()] << 4) & output_P__cxx . . $ WaveformGenerator#output_P__(db52760e79bf9054).(); |
| 396 | } |
| 397 | |
| 398 | RESID_INLINEcxx . . $ `src/resid/siddefs.h:70:9`! |
| 399 | reg12cxx . . $ reg12# WaveformGeneratorcxx . . $ WaveformGenerator#::output_PSTcxx . . $ WaveformGenerator#output_PST(db52760e79bf9054).() |
| 400 | { |
| 401 | return (wave_PSTcxx . . $ WaveformGenerator#wave_PST.[output__S_cxx . . $ WaveformGenerator#output__S_(db52760e79bf9054).()] << 4) & output_P__cxx . . $ WaveformGenerator#output_P__(db52760e79bf9054).(); |
| 402 | } |
| 403 | |
| 404 | // Combined waveforms including noise: |
| 405 | // All waveform combinations including noise output zero after a few cycles. |
| 406 | // NB! The effects of such combinations are not fully explored. It is claimed |
| 407 | // that the shift register may be filled with zeroes and locked up, which |
| 408 | // seems to be true. |
| 409 | // We have not attempted to model this behavior, suffice to say that |
| 410 | // there is very little audible output from waveform combinations including |
| 411 | // noise. We hope that nobody is actually using it. |
| 412 | // |
| 413 | RESID_INLINEcxx . . $ `src/resid/siddefs.h:70:9`! |
| 414 | reg12cxx . . $ reg12# WaveformGeneratorcxx . . $ WaveformGenerator#::outputN__Tcxx . . $ WaveformGenerator#outputN__T(db52760e79bf9054).() |
| 415 | { |
| 416 | return 0; |
| 417 | } |
| 418 | |
| 419 | RESID_INLINEcxx . . $ `src/resid/siddefs.h:70:9`! |
| 420 | reg12cxx . . $ reg12# WaveformGeneratorcxx . . $ WaveformGenerator#::outputN_S_cxx . . $ WaveformGenerator#outputN_S_(db52760e79bf9054).() |
| 421 | { |
| 422 | return 0; |
| 423 | } |
| 424 | |
| 425 | RESID_INLINEcxx . . $ `src/resid/siddefs.h:70:9`! |
| 426 | reg12cxx . . $ reg12# WaveformGeneratorcxx . . $ WaveformGenerator#::outputN_STcxx . . $ WaveformGenerator#outputN_ST(db52760e79bf9054).() |
| 427 | { |
| 428 | return 0; |
| 429 | } |
| 430 | |
| 431 | RESID_INLINEcxx . . $ `src/resid/siddefs.h:70:9`! |
| 432 | reg12cxx . . $ reg12# WaveformGeneratorcxx . . $ WaveformGenerator#::outputNP__cxx . . $ WaveformGenerator#outputNP__(db52760e79bf9054).() |
| 433 | { |
| 434 | return 0; |
| 435 | } |
| 436 | |
| 437 | RESID_INLINEcxx . . $ `src/resid/siddefs.h:70:9`! |
| 438 | reg12cxx . . $ reg12# WaveformGeneratorcxx . . $ WaveformGenerator#::outputNP_Tcxx . . $ WaveformGenerator#outputNP_T(db52760e79bf9054).() |
| 439 | { |
| 440 | return 0; |
| 441 | } |
| 442 | |
| 443 | RESID_INLINEcxx . . $ `src/resid/siddefs.h:70:9`! |
| 444 | reg12cxx . . $ reg12# WaveformGeneratorcxx . . $ WaveformGenerator#::outputNPS_cxx . . $ WaveformGenerator#outputNPS_(db52760e79bf9054).() |
| 445 | { |
| 446 | return 0; |
| 447 | } |
| 448 | |
| 449 | RESID_INLINEcxx . . $ `src/resid/siddefs.h:70:9`! |
| 450 | reg12cxx . . $ reg12# WaveformGeneratorcxx . . $ WaveformGenerator#::outputNPSTcxx . . $ WaveformGenerator#outputNPST(db52760e79bf9054).() |
| 451 | { |
| 452 | return 0; |
| 453 | } |
| 454 | |
| 455 | // ---------------------------------------------------------------------------- |
| 456 | // Select one of 16 possible combinations of waveforms. |
| 457 | // ---------------------------------------------------------------------------- |
| 458 | RESID_INLINEcxx . . $ `src/resid/siddefs.h:70:9`! |
| 459 | reg12cxx . . $ reg12# WaveformGeneratorcxx . . $ WaveformGenerator#::outputcxx . . $ WaveformGenerator#output(db52760e79bf9054).() |
| 460 | { |
| 461 | // It may seem cleaner to use an array of member functions to return |
| 462 | // waveform output; however a switch with inline functions is faster. |
| 463 | |
| 464 | switch (waveformcxx . . $ WaveformGenerator#waveform.) { |
| 465 | default: |
| 466 | case 0x0: |
| 467 | return output____cxx . . $ WaveformGenerator#output____(db52760e79bf9054).(); |
| 468 | case 0x1: |
| 469 | return output___Tcxx . . $ WaveformGenerator#output___T(db52760e79bf9054).(); |
| 470 | case 0x2: |
| 471 | return output__S_cxx . . $ WaveformGenerator#output__S_(db52760e79bf9054).(); |
| 472 | case 0x3: |
| 473 | return output__STcxx . . $ WaveformGenerator#output__ST(db52760e79bf9054).(); |
| 474 | case 0x4: |
| 475 | return output_P__cxx . . $ WaveformGenerator#output_P__(db52760e79bf9054).(); |
| 476 | case 0x5: |
| 477 | return output_P_Tcxx . . $ WaveformGenerator#output_P_T(db52760e79bf9054).(); |
| 478 | case 0x6: |
| 479 | return output_PS_cxx . . $ WaveformGenerator#output_PS_(db52760e79bf9054).(); |
| 480 | case 0x7: |
| 481 | return output_PSTcxx . . $ WaveformGenerator#output_PST(db52760e79bf9054).(); |
| 482 | case 0x8: |
| 483 | return outputN___cxx . . $ WaveformGenerator#outputN___(db52760e79bf9054).(); |
| 484 | case 0x9: |
| 485 | return outputN__Tcxx . . $ WaveformGenerator#outputN__T(db52760e79bf9054).(); |
| 486 | case 0xa: |
| 487 | return outputN_S_cxx . . $ WaveformGenerator#outputN_S_(db52760e79bf9054).(); |
| 488 | case 0xb: |
| 489 | return outputN_STcxx . . $ WaveformGenerator#outputN_ST(db52760e79bf9054).(); |
| 490 | case 0xc: |
| 491 | return outputNP__cxx . . $ WaveformGenerator#outputNP__(db52760e79bf9054).(); |
| 492 | case 0xd: |
| 493 | return outputNP_Tcxx . . $ WaveformGenerator#outputNP_T(db52760e79bf9054).(); |
| 494 | case 0xe: |
| 495 | return outputNPS_cxx . . $ WaveformGenerator#outputNPS_(db52760e79bf9054).(); |
| 496 | case 0xf: |
| 497 | return outputNPSTcxx . . $ WaveformGenerator#outputNPST(db52760e79bf9054).(); |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | #endif // RESID_INLINING || defined(__WAVE_CC__) |
| 502 | |
| 503 | #endif // not __WAVE_H__ |