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 __SIDFP_H__
21 #define __SIDFP_H__
22 
23 #include "siddefsfp.h"
24 #include "voicefp.h"
25 #include "filterfp.h"
26 #include "extfiltfp.h"
27 #include "potfp.h"
28 
29 class SIDFP
30 {
31 public:
32   SIDFP();
33   ~SIDFP();
34 
35   static float kinked_dac(const int x, const float nonlinearity, const int bits);
36 
37   void set_chip_model(chip_model model);
get_filter()38   FilterFP& get_filter() { return filter; }
39   void enable_filter(bool enable);
40   bool set_sampling_parameters(double clock_freq, sampling_method method,
41 			       double sample_freq, double pass_freq = 20000);
42   void set_voice_nonlinearity(float nl);
43 
44   void clock();
45   int clock(cycle_count& delta_t, short* buf, int n, int interleave = 1);
46   int clock_fast(cycle_count& delta_t, short* buf, int n, int interleave = 1);
47   void reset();
48 
49   // Read/write registers.
50   reg8 read(reg8 offset);
51   void write(reg8 offset, reg8 value);
52   void mute(reg8 channel, bool enable);
53 
54   // 16-bit input (EXT IN).
55   void input(int sample);
56 
57   // 16-bit output (AUDIO OUT).
58   float output();
59 
60 private:
61   static double I0(double x);
62   inline int clock_interpolate(cycle_count& delta_t, short* buf, int n,
63 				     int interleave);
64   inline int clock_resample_interpolate(cycle_count& delta_t, short* buf,
65 					      int n, int interleave);
66   inline void age_bus_value(cycle_count);
67 
68   VoiceFP voice[3];
69   FilterFP filter;
70   ExternalFilterFP extfilt;
71   PotentiometerFP potx;
72   PotentiometerFP poty;
73 
74   reg8 bus_value;
75   cycle_count bus_value_ttl;
76 
77   // External audio input.
78   float ext_in;
79 
80   // Sampling variables.
81   sampling_method sampling;
82   float cycles_per_sample;
83   float sample_offset;
84   int sample_index;
85   int fir_N;
86   int fir_RES;
87   /* for linear interpolation mode */
88   float sample_prev;
89 
90   // Ring buffer with overflow for contiguous storage of RINGSIZE samples.
91   float* sample;
92 
93   // FIR_RES filter tables (FIR_N*FIR_RES).
94   float* fir;
95 
96   /* analog parts are run at half the rate of digital ones. */
97   float lastsample[3];
98   unsigned char filtercyclegate;
99 };
100 
101 #endif // not __SIDFP_H__
102