sid.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. #ifndef __SID_H__
  20. #define __SID_H__
  21. #include "siddefs.h"
  22. #include "voice.h"
  23. #include "filter.h"
  24. #include "extfilt.h"
  25. #include "pot.h"
  26. class cSID
  27. {
  28. public:
  29. cSID();
  30. ~cSID();
  31. void set_chip_model(chip_model model);
  32. void enable_filter(bool enable);
  33. void enable_external_filter(bool enable);
  34. bool set_sampling_parameters(double clock_freq, sampling_method method,
  35. double sample_freq, double pass_freq = -1,
  36. double filter_scale = 0.97);
  37. void adjust_sampling_frequency(double sample_freq);
  38. void fc_default(const fc_point*& points, int& count);
  39. PointPlotter<sound_sample> fc_plotter();
  40. void clock();
  41. void clock(cycle_count delta_t);
  42. int clock(cycle_count& delta_t, short* buf, int n, int interleave = 1);
  43. void reset();
  44. // Read/write registers.
  45. reg8 read(reg8 offset);
  46. void write(reg8 offset, reg8 value);
  47. // Read/write state.
  48. class State
  49. {
  50. public:
  51. State();
  52. char sid_register[0x20];
  53. reg8 bus_value;
  54. cycle_count bus_value_ttl;
  55. reg24 accumulator[3];
  56. reg24 shift_register[3];
  57. reg16 rate_counter[3];
  58. reg16 rate_counter_period[3];
  59. reg16 exponential_counter[3];
  60. reg16 exponential_counter_period[3];
  61. reg8 envelope_counter[3];
  62. EnvelopeGenerator::State envelope_state[3];
  63. bool hold_zero[3];
  64. };
  65. State read_state();
  66. void write_state(const State& state);
  67. // 16-bit input (EXT IN).
  68. void input(int sample);
  69. // 16-bit output (AUDIO OUT).
  70. int output();
  71. // n-bit output.
  72. int output(int bits);
  73. protected:
  74. static double I0(double x);
  75. RESID_INLINE int clock_fast(cycle_count& delta_t, short* buf, int n,
  76. int interleave);
  77. RESID_INLINE int clock_interpolate(cycle_count& delta_t, short* buf, int n,
  78. int interleave);
  79. RESID_INLINE int clock_resample_interpolate(cycle_count& delta_t, short* buf,
  80. int n, int interleave);
  81. RESID_INLINE int clock_resample_fast(cycle_count& delta_t, short* buf,
  82. int n, int interleave);
  83. Voice voice[3];
  84. Filter filter;
  85. ExternalFilter extfilt;
  86. Potentiometer potx;
  87. Potentiometer poty;
  88. reg8 bus_value;
  89. cycle_count bus_value_ttl;
  90. double clock_frequency;
  91. // External audio input.
  92. int ext_in;
  93. // Resampling constants.
  94. // The error in interpolated lookup is bounded by 1.234/L^2,
  95. // while the error in non-interpolated lookup is bounded by
  96. // 0.7854/L + 0.4113/L^2, see
  97. // http://www-ccrma.stanford.edu/~jos/resample/Choice_Table_Size.html
  98. // For a resolution of 16 bits this yields L >= 285 and L >= 51473,
  99. // respectively.
  100. static const int FIR_N;
  101. static const int FIR_RES_INTERPOLATE;
  102. static const int FIR_RES_FAST;
  103. static const int FIR_SHIFT;
  104. static const int RINGSIZE;
  105. // Fixpoint constants (16.16 bits).
  106. static const int FIXP_SHIFT;
  107. static const int FIXP_MASK;
  108. // Sampling variables.
  109. sampling_method sampling;
  110. cycle_count cycles_per_sample;
  111. cycle_count sample_offset;
  112. int sample_index;
  113. short sample_prev;
  114. int fir_N;
  115. int fir_RES;
  116. // Ring buffer with overflow for contiguous storage of RINGSIZE samples.
  117. short* sample;
  118. // FIR_RES filter tables (FIR_N*FIR_RES).
  119. short* fir;
  120. };
  121. #endif // not __SID_H__