extfilt.cc 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // ---------------------------------------------------------------------------
  2. // This file is part of reSID, a MOS6581 SID emulator engine.
  3. // Copyright (C) 2004 Dag Lem <resid@nimrod.no>
  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. #define __EXTFILT_CC__
  20. #include "extfilt.h"
  21. // ----------------------------------------------------------------------------
  22. // Constructor.
  23. // ----------------------------------------------------------------------------
  24. ExternalFilter::ExternalFilter()
  25. {
  26. reset();
  27. enable_filter(true);
  28. set_chip_model(MOS6581);
  29. // Low-pass: R = 10kOhm, C = 1000pF; w0l = 1/RC = 1/(1e4*1e-9) = 100000
  30. // High-pass: R = 1kOhm, C = 10uF; w0h = 1/RC = 1/(1e3*1e-5) = 100
  31. // Multiply with 1.048576 to facilitate division by 1 000 000 by right-
  32. // shifting 20 times (2 ^ 20 = 1048576).
  33. w0lp = 104858;
  34. w0hp = 105;
  35. }
  36. // ----------------------------------------------------------------------------
  37. // Enable filter.
  38. // ----------------------------------------------------------------------------
  39. void ExternalFilter::enable_filter(bool enable)
  40. {
  41. enabled = enable;
  42. }
  43. // ----------------------------------------------------------------------------
  44. // Set chip model.
  45. // ----------------------------------------------------------------------------
  46. void ExternalFilter::set_chip_model(chip_model model)
  47. {
  48. if (model == MOS6581) {
  49. // Maximum mixer DC output level; to be removed if the external
  50. // filter is turned off: ((wave DC + voice DC)*voices + mixer DC)*volume
  51. // See voice.cc and filter.cc for an explanation of the values.
  52. mixer_DC = ((((0x800 - 0x380) + 0x800)*0xff*3 - 0xfff*0xff/18) >> 7)*0x0f;
  53. }
  54. else {
  55. // No DC offsets in the MOS8580.
  56. mixer_DC = 0;
  57. }
  58. }
  59. // ----------------------------------------------------------------------------
  60. // SID reset.
  61. // ----------------------------------------------------------------------------
  62. void ExternalFilter::reset()
  63. {
  64. // State of filter.
  65. Vlp = 0;
  66. Vhp = 0;
  67. Vo = 0;
  68. }