comparison src/console/Spc_Dsp.h @ 12:3da1b8942b8b trunk

[svn] - remove src/Input src/Output src/Effect src/General src/Visualization src/Container
author nenolod
date Mon, 18 Sep 2006 03:14:20 -0700
parents src/Input/console/Spc_Dsp.h@13389e613d67
children fb513e10174e
comparison
equal deleted inserted replaced
11:cff1d04026ae 12:3da1b8942b8b
1
2 // Super Nintendo (SNES) SPC DSP emulator
3
4 // Game_Music_Emu 0.3.0
5
6 #ifndef SPC_DSP_H
7 #define SPC_DSP_H
8
9 #include "blargg_common.h"
10
11 class Spc_Dsp {
12 typedef BOOST::int8_t int8_t;
13 typedef BOOST::uint8_t uint8_t;
14 public:
15
16 // Keeps pointer to 64K ram
17 Spc_Dsp( uint8_t* ram );
18
19 // Mute voice n if bit n (1 << n) of mask is clear.
20 enum { voice_count = 8 };
21 void mute_voices( int mask );
22
23 // Clear state and silence everything.
24 void reset();
25
26 // Set gain, where 1.0 is normal. When greater than 1.0, output is clamped to
27 // the 16-bit sample range.
28 void set_gain( double );
29
30 // If true, prevent channels and global volumes from being phase-negated
31 void disable_surround( bool disable );
32
33 // Read/write register 'n', where n ranges from 0 to register_count - 1.
34 enum { register_count = 128 };
35 int read ( int n );
36 void write( int n, int );
37
38 // Run DSP for 'count' samples. Write resulting samples to 'buf' if not NULL.
39 void run( long count, short* buf = NULL );
40
41
42 // End of public interface
43 private:
44
45 struct raw_voice_t {
46 int8_t left_vol;
47 int8_t right_vol;
48 uint8_t rate [2];
49 uint8_t waveform;
50 uint8_t adsr [2]; // envelope rates for attack, decay, and sustain
51 uint8_t gain; // envelope gain (if not using ADSR)
52 int8_t envx; // current envelope level
53 int8_t outx; // current sample
54 int8_t unused [6];
55 };
56
57 union {
58 raw_voice_t voice [voice_count];
59
60 uint8_t reg [register_count];
61
62 struct {
63 int8_t unused1 [12];
64 int8_t left_volume; // 0C Main Volume Left (-.7)
65 int8_t echo_feedback; // 0D Echo Feedback (-.7)
66 int8_t unused2 [14];
67 int8_t right_volume; // 1C Main Volume Right (-.7)
68 int8_t unused3 [15];
69 int8_t left_echo_volume; // 2C Echo Volume Left (-.7)
70 uint8_t pitch_mods; // 2D Pitch Modulation on/off for each voice
71 int8_t unused4 [14];
72 int8_t right_echo_volume; // 3C Echo Volume Right (-.7)
73 uint8_t noise_enables; // 3D Noise output on/off for each voice
74 int8_t unused5 [14];
75 uint8_t key_ons; // 4C Key On for each voice
76 uint8_t echo_ons; // 4D Echo on/off for each voice
77 int8_t unused6 [14];
78 uint8_t key_offs; // 5C key off for each voice (instantiates release mode)
79 uint8_t wave_page; // 5D source directory (wave table offsets)
80 int8_t unused7 [14];
81 uint8_t flags; // 6C flags and noise freq
82 uint8_t echo_page; // 6D
83 int8_t unused8 [14];
84 uint8_t wave_ended; // 7C
85 uint8_t echo_delay; // 7D ms >> 4
86 char unused9 [2];
87 } g;
88 };
89
90 uint8_t* const ram;
91
92 // Cache of echo FIR values for faster access
93 short fir_coeff [voice_count];
94
95 // fir_buf [i + 8] == fir_buf [i], to avoid wrap checking in FIR code
96 short fir_buf [16] [2];
97 int fir_offset; // (0 to 7)
98
99 enum { emu_gain_bits = 8 };
100 int emu_gain;
101
102 int keyed_on; // 8-bits for 8 voices
103 int keys;
104
105 int echo_ptr;
106 int noise_amp;
107 int noise;
108 int noise_count;
109
110 int surround_threshold;
111
112 static const BOOST::int16_t gauss [];
113
114 enum state_t {
115 state_attack,
116 state_decay,
117 state_sustain,
118 state_release
119 };
120
121 struct voice_t {
122 short volume [2];
123 short fraction;// 12-bit fractional position
124 short interp3; // most recent four decoded samples
125 short interp2;
126 short interp1;
127 short interp0;
128 short block_remain; // number of nybbles remaining in current block
129 unsigned short addr;
130 short block_header; // header byte from current block
131 short envcnt;
132 short envx;
133 short on_cnt;
134 short enabled; // 7 if enabled, 31 if disabled
135 short envstate;
136 short unused; // pad to power of 2
137 };
138
139 voice_t voice_state [voice_count];
140
141 int clock_envelope( int );
142 };
143
144 inline void Spc_Dsp::disable_surround( bool disable ) { surround_threshold = disable ? 0 : -0x7FFF; }
145
146 inline void Spc_Dsp::set_gain( double v ) { emu_gain = (int) (v * (1 << emu_gain_bits)); }
147
148 inline int Spc_Dsp::read( int i )
149 {
150 assert( (unsigned) i < register_count );
151 return reg [i];
152 }
153
154 #endif
155