Debian Codegraph @

src/engine/platform/sound/c64_fp/Dac.h

raw
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 * Copyright 2004,2010 Dag Lem <[email protected]>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 */
22
23 #ifndef DAC_H
24 #define DAC_H
25
26 #include "siddefs-fp.h"
27
28 namespace reSIDfp
29 {
30
31 /**
32 * Estimate DAC nonlinearity.
33 * The SID DACs are built up as R-2R ladder as follows:
34 *
35 * n n-1 2 1 0 VGND
36 * | | | | | | Termination
37 * 2R 2R 2R 2R 2R 2R only for
38 * | | | | | | MOS 8580
39 * Vo -o-R-o-R-...-o-R-o-R-- --+
40 *
41 *
42 * All MOS 6581 DACs are missing a termination resistor at bit 0. This causes
43 * pronounced errors for the lower 4 - 5 bits (e.g. the output for bit 0 is
44 * actually equal to the output for bit 1), resulting in DAC discontinuities
45 * for the lower bits.
46 * In addition to this, the 6581 DACs exhibit further severe discontinuities
47 * for higher bits, which may be explained by a less than perfect match between
48 * the R and 2R resistors, or by output impedance in the NMOS transistors
49 * providing the bit voltages. A good approximation of the actual DAC output is
50 * achieved for 2R/R ~ 2.20.
51 *
52 * The MOS 8580 DACs, on the other hand, do not exhibit any discontinuities.
53 * These DACs include the correct termination resistor, and also seem to have
54 * very accurately matched R and 2R resistors (2R/R = 2.00).
55 *
56 * On the 6581 the output of the waveform and envelope DACs go through
57 * a voltage follower built with two NMOS:
58 *
59 * Vdd
60 *
61 * |
62 * |-+
63 * Vin -------| T1 (enhancement-mode)
64 * |-+
65 * |
66 * o-------- Vout
67 * |
68 * |-+
69 * +---| T2 (depletion-mode)
70 * | |-+
71 * | |
72 *
73 * GND GND
74 */
75 class Dac
76 {
77 private:
78 /// analog values
79 double * const dac;
80
81 /// the dac array length
82 const unsigned int dacLength;
83
84 public:
85 /**
86 * Initialize DAC model.
87 *
88 * @param bits the number of input bits
89 */
90 Dac(unsigned int bits);
91 ~Dac();
92
93 /**
94 * Build DAC model for specific chip.
95 *
96 * @param chipModel 6581 or 8580
97 */
98 void kinkedDac(ChipModel chipModel);
99
100 /**
101 * Get the Vo output for a given combination of input bits.
102 *
103 * @param input the digital input
104 * @return the analog output value
105 */
106 double getOutput(unsigned int input) const;
107 };
108
109 } // namespace reSIDfp
110
111 #endif