| 1 |
/* |
| 2 |
* This file is part of libsidplayfp, a SID player engine. |
| 3 |
* |
| 4 |
* Copyright 2011-2016 Leandro Nini <[email protected]> |
| 5 |
* Copyright 2007-2010 Antti Lankila |
| 6 |
* |
| 7 |
* This program is free software; you can redistribute it and/or modify |
| 8 |
* it under the terms of the GNU General Public License as published by |
| 9 |
* the Free Software Foundation; either version 2 of the License, or |
| 10 |
* (at your option) any later version. |
| 11 |
* |
| 12 |
* This program is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
* GNU General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU General Public License |
| 18 |
* along with this program; if not, write to the Free Software |
| 19 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 20 |
*/ |
| 21 |
|
| 22 |
#ifndef WAVEFORMCALCULATOR_h |
| 23 |
#define WAVEFORMCALCULATOR_h |
| 24 |
|
| 25 |
#include <map> |
| 26 |
|
| 27 |
#include "array.h" |
| 28 |
#include "sidcxx11.h" |
| 29 |
#include "siddefs-fp.h" |
| 30 |
|
| 31 |
|
| 32 |
namespace reSIDfp |
| 33 |
{ |
| 34 |
|
| 35 |
/** |
| 36 |
* Combined waveform model parameters. |
| 37 |
*/ |
| 38 |
typedef struct |
| 39 |
{ |
| 40 |
float bias; |
| 41 |
float pulsestrength; |
| 42 |
float topbit; |
| 43 |
float distance1; |
| 44 |
float distance2; |
| 45 |
float stmix; |
| 46 |
} CombinedWaveformConfig; |
| 47 |
|
| 48 |
/** |
| 49 |
* Combined waveform calculator for WaveformGenerator. |
| 50 |
* By combining waveforms, the bits of each waveform are effectively short |
| 51 |
* circuited. A zero bit in one waveform will result in a zero output bit |
| 52 |
* (thus the infamous claim that the waveforms are AND'ed). |
| 53 |
* However, a zero bit in one waveform may also affect the neighboring bits |
| 54 |
* in the output. |
| 55 |
* |
| 56 |
* Example: |
| 57 |
* |
| 58 |
* 1 1 |
| 59 |
* Bit # 1 0 9 8 7 6 5 4 3 2 1 0 |
| 60 |
* ----------------------- |
| 61 |
* Sawtooth 0 0 0 1 1 1 1 1 1 0 0 0 |
| 62 |
* |
| 63 |
* Triangle 0 0 1 1 1 1 1 1 0 0 0 0 |
| 64 |
* |
| 65 |
* AND 0 0 0 1 1 1 1 1 0 0 0 0 |
| 66 |
* |
| 67 |
* Output 0 0 0 0 1 1 1 0 0 0 0 0 |
| 68 |
* |
| 69 |
* |
| 70 |
* Re-vectorized die photographs reveal the mechanism behind this behavior. |
| 71 |
* Each waveform selector bit acts as a switch, which directly connects |
| 72 |
* internal outputs into the waveform DAC inputs as follows: |
| 73 |
* |
| 74 |
* - Noise outputs the shift register bits to DAC inputs as described above. |
| 75 |
* Each output is also used as input to the next bit when the shift register |
| 76 |
* is shifted. Lower four bits are grounded. |
| 77 |
* - Pulse connects a single line to all DAC inputs. The line is connected to |
| 78 |
* either 5V (pulse on) or 0V (pulse off) at bit 11, and ends at bit 0. |
| 79 |
* - Triangle connects the upper 11 bits of the (MSB EOR'ed) accumulator to the |
| 80 |
* DAC inputs, so that DAC bit 0 = 0, DAC bit n = accumulator bit n - 1. |
| 81 |
* - Sawtooth connects the upper 12 bits of the accumulator to the DAC inputs, |
| 82 |
* so that DAC bit n = accumulator bit n. Sawtooth blocks out the MSB from |
| 83 |
* the EOR used to generate the triangle waveform. |
| 84 |
* |
| 85 |
* We can thus draw the following conclusions: |
| 86 |
* |
| 87 |
* - The shift register may be written to by combined waveforms. |
| 88 |
* - The pulse waveform interconnects all bits in combined waveforms via the |
| 89 |
* pulse line. |
| 90 |
* - The combination of triangle and sawtooth interconnects neighboring bits |
| 91 |
* of the sawtooth waveform. |
| 92 |
* |
| 93 |
* Also in the 6581 the MSB of the oscillator, used as input for the |
| 94 |
* triangle xor logic and the pulse adder's last bit, is connected directly |
| 95 |
* to the waveform selector, while in the 8580 it is latched at sid_clk2 |
| 96 |
* before being forwarded to the selector. Thus in the 6581 if the sawtooth MSB |
| 97 |
* is pulled down it might affect the oscillator's adder |
| 98 |
* driving the top bit low. |
| 99 |
* |
| 100 |
*/ |
| 101 |
class WaveformCalculator |
| 102 |
{ |
| 103 |
private: |
| 104 |
typedef std::map<const CombinedWaveformConfig*, matrix_t> cw_cache_t; |
| 105 |
|
| 106 |
private: |
| 107 |
cw_cache_t CACHE; |
| 108 |
|
| 109 |
WaveformCalculator() DEFAULT; |
| 110 |
|
| 111 |
public: |
| 112 |
/** |
| 113 |
* Get the singleton instance. |
| 114 |
*/ |
| 115 |
static WaveformCalculator* getInstance(); |
| 116 |
|
| 117 |
/** |
| 118 |
* Build waveform tables for use by WaveformGenerator. |
| 119 |
* |
| 120 |
* @param model Chip model to use |
| 121 |
* @return Waveform table |
| 122 |
*/ |
| 123 |
matrix_t* buildTable(ChipModel model); |
| 124 |
}; |
| 125 |
|
| 126 |
} // namespace reSIDfp |
| 127 |
|
| 128 |
#endif |