Debian Codegraph @

src/engine/platform/sound/sid2/sid.h

raw
1 // ---------------------------------------------------------------------------
2 // This file is part of reSID, a MOS6581_2 SID2 emulator engine.
3 // Copyright (C) 2004 Dag Lem <[email protected]>
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 #include "siddefs.h"
21 #include "voice.h"
22 #include "filter.h"
23
24 class SID2
25 {
26 public:
27 SID2();
28 ~SID2();
29
30 sound_sample last_chan_out[3];
31
32 void set_is_muted(int ch, bool val);
33 void set_chip_model(chip_model2 model);
34 void enable_filter(bool enable);
35 void enable_external_filter(bool enable);
36
37 void fc_default(const fc_point*& points, int& count);
38 PointPlotter2<sound_sample> fc_plotter();
39
40 void clock();
41 void reset();
42
43 // Read/write registers.
44 reg8 read(reg8 offset);
45 void write(reg8 offset, reg8 value);
46
47 // Read/write state.
48 class State
49 {
50 public:
51 State();
52
53 char sid_register[0x20];
54
55 reg8 bus_value;
56 cycle_count bus_value_ttl;
57
58 reg24 accumulator[3];
59 reg24 shift_register[3];
60 reg16 rate_counter[3];
61 reg16 rate_counter_period[3];
62 reg16 exponential_counter[3];
63 reg16 exponential_counter_period[3];
64 reg8 envelope_counter[3];
65 EnvelopeGenerator2::State envelope_state[3];
66 bool hold_zero[3];
67 };
68
69 // 16-bit output (AUDIO OUT).
70 int output();
71
72 int chan_out[3];
73
74 protected:
75
76 Voice2 voice[3];
77 Filter2 filter[3];
78
79 bool isMuted[3];
80
81 reg8 bus_value;
82 cycle_count bus_value_ttl;
83
84 double clock_frequency;
85
86 // External audio input.
87 int ext_in;
88
89 // Resampling constants.
90 // The error in interpolated lookup is bounded by 1.234/L^2,
91 // while the error in non-interpolated lookup is bounded by
92 // 0.7854/L + 0.4113/L^2, see
93 // http://www-ccrma.stanford.edu/~jos/resample/Choice_Table_Size.html
94 // For a resolution of 16 bits this yields L >= 285 and L >= 51473,
95 // respectively.
96 static const int FIR_N = 125;
97 static const int FIR_RES_INTERPOLATE = 285;
98 static const int FIR_RES_FAST = 51473;
99 static const int FIR_SHIFT = 15;
100 static const int RINGSIZE = 16384;
101
102 // Fixpoint constants (16.16 bits).
103 static const int FIXP_SHIFT = 16;
104 static const int FIXP_MASK = 0xffff;
105
106 // Sampling variables.
107 sampling_method2 sampling;
108 cycle_count cycles_per_sample;
109 cycle_count sample_offset;
110 int sample_index;
111 short sample_prev;
112 int fir_N;
113 int fir_RES;
114
115 // Ring buffer with overflow for contiguous storage of RINGSIZE samples.
116 short* sample;
117
118 // FIR_RES filter tables (FIR_N*FIR_RES).
119 short* fir;
120 };
121