Mercurial > audlegacy
comparison Plugins/Input/console/Nes_Oscs.h @ 493:c04dff121e1d trunk
[svn] hostile merge, phase 2: reimport based on new plugin code
author | nenolod |
---|---|
date | Tue, 24 Jan 2006 20:19:01 -0800 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
492:ccb68bad47b2 | 493:c04dff121e1d |
---|---|
1 | |
2 // Private oscillators used by Nes_Apu | |
3 | |
4 // Nes_Snd_Emu 0.1.7 | |
5 | |
6 #ifndef NES_OSCS_H | |
7 #define NES_OSCS_H | |
8 | |
9 #include "blargg_common.h" | |
10 #include "Blip_Buffer.h" | |
11 | |
12 class Nes_Apu; | |
13 | |
14 struct Nes_Osc | |
15 { | |
16 unsigned char regs [4]; | |
17 bool reg_written [4]; | |
18 Blip_Buffer* output; | |
19 int length_counter;// length counter (0 if unused by oscillator) | |
20 int delay; // delay until next (potential) transition | |
21 int last_amp; // last amplitude oscillator was outputting | |
22 | |
23 void clock_length( int halt_mask ); | |
24 int period() const { | |
25 return (regs [3] & 7) * 0x100 + (regs [2] & 0xff); | |
26 } | |
27 void reset() { | |
28 delay = 0; | |
29 last_amp = 0; | |
30 } | |
31 int update_amp( int amp ) { | |
32 int delta = amp - last_amp; | |
33 last_amp = amp; | |
34 return delta; | |
35 } | |
36 }; | |
37 | |
38 struct Nes_Envelope : Nes_Osc | |
39 { | |
40 int envelope; | |
41 int env_delay; | |
42 | |
43 void clock_envelope(); | |
44 int volume() const; | |
45 void reset() { | |
46 envelope = 0; | |
47 env_delay = 0; | |
48 Nes_Osc::reset(); | |
49 } | |
50 }; | |
51 | |
52 // Nes_Square | |
53 struct Nes_Square : Nes_Envelope | |
54 { | |
55 enum { negate_flag = 0x08 }; | |
56 enum { shift_mask = 0x07 }; | |
57 enum { phase_range = 8 }; | |
58 int phase; | |
59 int sweep_delay; | |
60 | |
61 typedef Blip_Synth<blip_good_quality,1> Synth; | |
62 Synth const& synth; // shared between squares | |
63 | |
64 Nes_Square( Synth const* s ) : synth( *s ) { } | |
65 | |
66 void clock_sweep( int adjust ); | |
67 void run( nes_time_t, nes_time_t ); | |
68 void reset() { | |
69 sweep_delay = 0; | |
70 Nes_Envelope::reset(); | |
71 } | |
72 }; | |
73 | |
74 // Nes_Triangle | |
75 struct Nes_Triangle : Nes_Osc | |
76 { | |
77 enum { phase_range = 16 }; | |
78 int phase; | |
79 int linear_counter; | |
80 Blip_Synth<blip_med_quality,1> synth; | |
81 | |
82 int calc_amp() const; | |
83 void run( nes_time_t, nes_time_t ); | |
84 void clock_linear_counter(); | |
85 void reset() { | |
86 linear_counter = 0; | |
87 phase = phase_range; | |
88 Nes_Osc::reset(); | |
89 } | |
90 }; | |
91 | |
92 // Nes_Noise | |
93 struct Nes_Noise : Nes_Envelope | |
94 { | |
95 int noise; | |
96 Blip_Synth<blip_med_quality,1> synth; | |
97 | |
98 void run( nes_time_t, nes_time_t ); | |
99 void reset() { | |
100 noise = 1 << 14; | |
101 Nes_Envelope::reset(); | |
102 } | |
103 }; | |
104 | |
105 // Nes_Dmc | |
106 struct Nes_Dmc : Nes_Osc | |
107 { | |
108 int address; // address of next byte to read | |
109 int period; | |
110 //int length_counter; // bytes remaining to play (already defined in Nes_Osc) | |
111 int buf; | |
112 int bits_remain; | |
113 int bits; | |
114 bool buf_full; | |
115 bool silence; | |
116 | |
117 enum { loop_flag = 0x40 }; | |
118 | |
119 int dac; | |
120 | |
121 nes_time_t next_irq; | |
122 bool irq_enabled; | |
123 bool irq_flag; | |
124 bool pal_mode; | |
125 bool nonlinear; | |
126 | |
127 int (*rom_reader)( void*, nes_addr_t ); // needs to be initialized to rom read function | |
128 void* rom_reader_data; | |
129 | |
130 Nes_Apu* apu; | |
131 | |
132 Blip_Synth<blip_med_quality,1> synth; | |
133 | |
134 void start(); | |
135 void write_register( int, int ); | |
136 void run( nes_time_t, nes_time_t ); | |
137 void recalc_irq(); | |
138 void fill_buffer(); | |
139 void reload_sample(); | |
140 void reset(); | |
141 int count_reads( nes_time_t, nes_time_t* ) const; | |
142 nes_time_t next_read_time() const; | |
143 }; | |
144 | |
145 #endif | |
146 |