| 1 | // ---------------------------------------------------------------------------cxx . . $ `<file>/src/resid/voice.cpp`/ |
| 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 | #define __VOICE_CC__cxx . . $ `src/resid/voice.cpp:20:9`! |
| 21 | #include "voice.h"cxx . . $ `<file>/src/resid/voice.h`/ |
| 22 | |
| 23 | // ---------------------------------------------------------------------------- |
| 24 | // Constructor. |
| 25 | // ---------------------------------------------------------------------------- |
| 26 | Voicecxx . . $ Voice#::Voicecxx . . $ Voice#Voice(49f6e7a06ebc5aa8).() |
| 27 | { |
| 28 | set_chip_modelcxx . . $ Voice#set_chip_model(cea143c94d31b99f).(MOS6581cxx . . $ MOS6581.); |
| 29 | } |
| 30 | |
| 31 | // ---------------------------------------------------------------------------- |
| 32 | // Set chip model. |
| 33 | // ---------------------------------------------------------------------------- |
| 34 | void Voicecxx . . $ Voice#::set_chip_modelcxx . . $ Voice#set_chip_model(cea143c94d31b99f).(chip_modelcxx . . $ chip_model# model) |
| 35 | { |
| 36 | wavecxx . . $ Voice#wave..set_chip_modelcxx . . $ WaveformGenerator#set_chip_model(cea143c94d31b99f).(model); |
| 37 | |
| 38 | if (model == MOS6581cxx . . $ MOS6581.) { |
| 39 | // The waveform D/A converter introduces a DC offset in the signal |
| 40 | // to the envelope multiplying D/A converter. The "zero" level of |
| 41 | // the waveform D/A converter can be found as follows: |
| 42 | // |
| 43 | // Measure the "zero" voltage of voice 3 on the SID audio output |
| 44 | // pin, routing only voice 3 to the mixer ($d417 = $0b, $d418 = |
| 45 | // $0f, all other registers zeroed). |
| 46 | // |
| 47 | // Then set the sustain level for voice 3 to maximum and search for |
| 48 | // the waveform output value yielding the same voltage as found |
| 49 | // above. This is done by trying out different waveform output |
| 50 | // values until the correct value is found, e.g. with the following |
| 51 | // program: |
| 52 | // |
| 53 | // lda #$08 |
| 54 | // sta $d412 |
| 55 | // lda #$0b |
| 56 | // sta $d417 |
| 57 | // lda #$0f |
| 58 | // sta $d418 |
| 59 | // lda #$f0 |
| 60 | // sta $d414 |
| 61 | // lda #$21 |
| 62 | // sta $d412 |
| 63 | // lda #$01 |
| 64 | // sta $d40e |
| 65 | // |
| 66 | // ldx #$00 |
| 67 | // lda #$38 ; Tweak this to find the "zero" level |
| 68 | //l cmp $d41b |
| 69 | // bne l |
| 70 | // stx $d40e ; Stop frequency counter - freeze waveform output |
| 71 | // brk |
| 72 | // |
| 73 | // The waveform output range is 0x000 to 0xfff, so the "zero" |
| 74 | // level should ideally have been 0x800. In the measured chip, the |
| 75 | // waveform output "zero" level was found to be 0x380 (i.e. $d41b |
| 76 | // = 0x38) at 5.94V. |
| 77 | |
| 78 | wave_zerocxx . . $ Voice#wave_zero. = 0x380; |
| 79 | |
| 80 | // The envelope multiplying D/A converter introduces another DC |
| 81 | // offset. This is isolated by the following measurements: |
| 82 | // |
| 83 | // * The "zero" output level of the mixer at full volume is 5.44V. |
| 84 | // * Routing one voice to the mixer at full volume yields |
| 85 | // 6.75V at maximum voice output (wave = 0xfff, sustain = 0xf) |
| 86 | // 5.94V at "zero" voice output (wave = any, sustain = 0x0) |
| 87 | // 5.70V at minimum voice output (wave = 0x000, sustain = 0xf) |
| 88 | // * The DC offset of one voice is (5.94V - 5.44V) = 0.50V |
| 89 | // * The dynamic range of one voice is |6.75V - 5.70V| = 1.05V |
| 90 | // * The DC offset is thus 0.50V/1.05V ~ 1/2 of the dynamic range. |
| 91 | // |
| 92 | // Note that by removing the DC offset, we get the following ranges for |
| 93 | // one voice: |
| 94 | // y > 0: (6.75V - 5.44V) - 0.50V = 0.81V |
| 95 | // y < 0: (5.70V - 5.44V) - 0.50V = -0.24V |
| 96 | // The scaling of the voice amplitude is not symmetric about y = 0; |
| 97 | // this follows from the DC level in the waveform output. |
| 98 | |
| 99 | voice_DCcxx . . $ Voice#voice_DC. = 0x800*0xff; |
| 100 | } |
| 101 | else { |
| 102 | // No DC offsets in the MOS8580. |
| 103 | wave_zerocxx . . $ Voice#wave_zero. = 0x800; |
| 104 | voice_DCcxx . . $ Voice#voice_DC. = 0; |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | // ---------------------------------------------------------------------------- |
| 109 | // Set sync source. |
| 110 | // ---------------------------------------------------------------------------- |
| 111 | void Voicecxx . . $ Voice#::set_sync_sourcecxx . . $ Voice#set_sync_source(8857d55290c79f8).(Voicecxx . . $ Voice#* source) |
| 112 | { |
| 113 | wavecxx . . $ Voice#wave..set_sync_sourcecxx . . $ WaveformGenerator#set_sync_source(567819d4c5355d59).(&source->wavecxx . . $ Voice#wave.); |
| 114 | } |
| 115 | |
| 116 | // ---------------------------------------------------------------------------- |
| 117 | // Register functions. |
| 118 | // ---------------------------------------------------------------------------- |
| 119 | void Voicecxx . . $ Voice#::writeCONTROL_REGcxx . . $ Voice#writeCONTROL_REG(cb2f890c2fdad230).(reg8cxx . . $ reg8# control) |
| 120 | { |
| 121 | wavecxx . . $ Voice#wave..writeCONTROL_REGcxx . . $ WaveformGenerator#writeCONTROL_REG(cb2f890c2fdad230).(control); |
| 122 | envelopecxx . . $ Voice#envelope..writeCONTROL_REGcxx . . $ EnvelopeGenerator#writeCONTROL_REG(cb2f890c2fdad230).(control); |
| 123 | } |
| 124 | |
| 125 | // ---------------------------------------------------------------------------- |
| 126 | // SID reset. |
| 127 | // ---------------------------------------------------------------------------- |
| 128 | void Voicecxx . . $ Voice#::resetcxx . . $ Voice#reset(49f6e7a06ebc5aa8).() |
| 129 | { |
| 130 | wavecxx . . $ Voice#wave..resetcxx . . $ WaveformGenerator#reset(49f6e7a06ebc5aa8).(); |
| 131 | envelopecxx . . $ Voice#envelope..resetcxx . . $ EnvelopeGenerator#reset(49f6e7a06ebc5aa8).(); |
| 132 | } |