DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/hardware/reSID/extfilt.cpp
00001 //  ---------------------------------------------------------------------------
00002 //  This file is part of reSID, a MOS6581 SID emulator engine.
00003 //  Copyright (C) 2004  Dag Lem <resid@nimrod.no>
00004 //
00005 //  This program is free software; you can redistribute it and/or modify
00006 //  it under the terms of the GNU General Public License as published by
00007 //  the Free Software Foundation; either version 2 of the License, or
00008 //  (at your option) any later version.
00009 //
00010 //  This program is distributed in the hope that it will be useful,
00011 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 //  GNU General Public License for more details.
00014 //
00015 //  You should have received a copy of the GNU General Public License along
00016 //  with this program; if not, write to the Free Software Foundation, Inc.,
00017 //  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018 //  ---------------------------------------------------------------------------
00019 
00020 #define __EXTFILT_CC__
00021 #include "extfilt.h"
00022 
00023 
00024 // ----------------------------------------------------------------------------
00025 // Constructor.
00026 // ----------------------------------------------------------------------------
00027 ExternalFilter::ExternalFilter()
00028 {
00029   reset();
00030   enable_filter(true);
00031   set_chip_model(MOS6581);
00032 
00033   // Low-pass:  R = 10kOhm, C = 1000pF; w0l = 1/RC = 1/(1e4*1e-9) = 100000
00034   // High-pass: R =  1kOhm, C =   10uF; w0h = 1/RC = 1/(1e3*1e-5) =    100
00035   // Multiply with 1.048576 to facilitate division by 1 000 000 by right-
00036   // shifting 20 times (2 ^ 20 = 1048576).
00037 
00038   w0lp = 104858;
00039   w0hp = 105;
00040 }
00041 
00042 
00043 // ----------------------------------------------------------------------------
00044 // Enable filter.
00045 // ----------------------------------------------------------------------------
00046 void ExternalFilter::enable_filter(bool enable)
00047 {
00048   enabled = enable;
00049 }
00050 
00051 
00052 // ----------------------------------------------------------------------------
00053 // Set chip model.
00054 // ----------------------------------------------------------------------------
00055 void ExternalFilter::set_chip_model(chip_model model)
00056 {
00057   if (model == MOS6581) {
00058     // Maximum mixer DC output level; to be removed if the external
00059     // filter is turned off: ((wave DC + voice DC)*voices + mixer DC)*volume
00060     // See voice.cc and filter.cc for an explanation of the values.
00061     mixer_DC = ((((0x800 - 0x380) + 0x800)*0xff*3 - 0xfff*0xff/18) >> 7)*0x0f;
00062   }
00063   else {
00064     // No DC offsets in the MOS8580.
00065     mixer_DC = 0;
00066   }
00067 }
00068 
00069 
00070 // ----------------------------------------------------------------------------
00071 // SID reset.
00072 // ----------------------------------------------------------------------------
00073 void ExternalFilter::reset()
00074 {
00075   // State of filter.
00076   Vlp = 0;
00077   Vhp = 0;
00078   Vo = 0;
00079 }
00080