home *** CD-ROM | disk | FTP | other *** search
/ Large Pack of OldSkool DOS MOD Trackers / goattracker_2.65.zip / src / resid / sid.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-03-19  |  4.2 KB  |  147 lines

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