Klasse WaveformGenerator

java.lang.Object
builder.resid.residfp.WaveformGenerator

public final class WaveformGenerator extends Object
A 24 bit accumulator is the basis for waveform generation. FREQ is added to the lower 16 bits of the accumulator each cycle. The accumulator is set to zero when TEST is set, and starts counting when TEST is cleared. The noise waveform is taken from intermediate bits of a 23 bit shift register. This register is clocked by bit 19 of the accumulator.
Autor:
Ken Händel
  • Felddetails

    • wftable

      private float[][] wftable
    • wfdigital

      private byte[][] wfdigital
    • dac

      private float[] dac
    • accumulator

      private int accumulator
      Current and previous accumulator value.
    • accumulator_prev

      private int accumulator_prev
      Current and previous accumulator value.
    • noiseShiftRegister

      private int noiseShiftRegister
      Value in noise XOR register.
    • noiseShiftRegisterTtl

      private int noiseShiftRegisterTtl
      Time until Noise XOR register is overwritten.
    • previous

      private byte previous
      Cached digital value of OSC3.
    • previous_dac

      private float previous_dac
      Cached analog value of OSC3
    • freq

      private int freq
      Fout = (Fn*Fclk/16777216)Hz
    • pw

      private int pw
      PWout = (PWn/40.95)%
    • waveform

      private int waveform
      The control register right-shifted 4 bits; used for output function table lookup.
    • test

      private boolean test
      The control register bits. Gate is handled by EnvelopeGenerator.
    • ring

      private boolean ring
      The control register bits. Gate is handled by EnvelopeGenerator.
    • sync

      private boolean sync
      The control register bits. Gate is handled by EnvelopeGenerator.
  • Konstruktordetails

    • WaveformGenerator

      protected WaveformGenerator()
      Constructor.
  • Methodendetails

    • setWftable

      protected void setWftable(float[][] newWftable, float[] newDac, byte[][] newWfdigital)
    • clock

      protected void clock()
      SID clocking - 1 cycle.
    • synchronize

      protected void synchronize(WaveformGenerator syncDest, WaveformGenerator syncSource)
      Synchronize oscillators. This must be done after all the oscillators have been clock()'ed since the oscillators operate in parallel. Note that the oscillators must be clocked exactly on the cycle when the MSB is set high for hard sync to operate correctly. See SID.clock().
      Parameter:
      syncDest - The oscillator I am syncing
      syncSource - The oscillator syncing me.
    • output

      public float output(WaveformGenerator ring_modulator)
      12-bit waveform output. Select one of 16 possible combinations of waveforms.
      Parameter:
      ring_modulator - The oscillator ring-modulating me.
      Gibt zurück:
      output from waveformgenerator
    • writeFREQ_LO

      protected void writeFREQ_LO(byte freq_lo)
      Register functions.
      Parameter:
      freq_lo - low 8 bits of frequency
    • writeFREQ_HI

      protected void writeFREQ_HI(byte freq_hi)
      Register functions.
      Parameter:
      freq_hi - high 8 bits of frequency
    • writePW_LO

      protected void writePW_LO(byte pw_lo)
      Register functions. The original form was (acc >> 12) >= pw, where truth value is not affected by the contents of the low 12 bits. Therefore the lowest bits must be zero in the new formulation acc >= (pw << 12).
      Parameter:
      pw_lo - low 8 bits of pulse width
    • writePW_HI

      protected void writePW_HI(byte pw_hi)
      Register functions.
      Parameter:
      pw_hi - high 8 bits of pulse width
    • writeCONTROL_REG

      protected void writeCONTROL_REG(WaveformGenerator ring_modulator, byte control)
      Register functions.
      Parameter:
      ring_modulator - ring-modulator modulating me.
      control - control register value
    • readOSC6581

      protected byte readOSC6581(WaveformGenerator ring_modulator)
      Read OSC3 value (6581, not latched/delayed version)
      Parameter:
      ring_modulator - The ring modulating partner of this waveform
      Gibt zurück:
      OSC3 value
    • readOSC8580

      protected byte readOSC8580(WaveformGenerator ring_modulator)
      Read OSC3 value (8580, 1-clock latched version). Waveforms 0 and 8 and above are not appropriately delayed by 1 clock. It should not be noticeable for 0 and > 8, but noise is not correctly delayed.
      Parameter:
      ring_modulator - The ring modulating partner of this waveform
      Gibt zurück:
      OSC3 value
    • readOSC

      public byte readOSC(ChipModel model)
    • readOSC

      private byte readOSC(int ringAccumulator, int myAccumulator)
      Calculate OSC3 bitstate from the analog values.
    • clockNoise

      private void clockNoise(boolean clock)
    • calculateCurrentNoiseValue

      private byte calculateCurrentNoiseValue()
      Noise: The noise output is taken from intermediate bits of a 23-bit shift register which is clocked by bit 19 of the accumulator. NB! The output is actually delayed 2 cycles after bit 19 is set high. This is not modeled.

      Operation: Calculate EOR result, shift register, set bit 0 = result.

                               ------------------------>--------------------
                               |                                            |
                          ----EOR----                                       |
                          |         |                                       |
                          2 2 2 1 1 1 1 1 1 1 1 1 1                         |
        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 <---
                          |   |       |     |   |       |     |   |
        OSC3 bits  :      7   6       5     4   3       2     1   0
       
      Since waveform output is 12 bits the output is left-shifted 4 times.
    • reset

      protected void reset()
      SID reset.
    • getZeroLevel

      public float getZeroLevel()
      Return the waveform offset. The zero level is ideally 0x800.
      Gibt zurück:
      the waveform offset