20 #ifndef RESID_ENVELOPE_H
21 #define RESID_ENVELOPE_H
23 #include "resid-config.h"
42 enum State { ATTACK, DECAY_SUSTAIN, RELEASE };
44 void set_chip_model(chip_model model);
47 void clock(cycle_count delta_t);
50 void writeCONTROL_REG(reg8);
51 void writeATTACK_DECAY(reg8);
52 void writeSUSTAIN_RELEASE(reg8);
59 void set_exponential_counter();
63 reg8 exponential_counter;
64 reg8 exponential_counter_period;
65 reg8 envelope_counter;
67 cycle_count envelope_pipeline;
83 static reg16 rate_counter_period[];
86 static reg8 sustain_level[];
89 static unsigned short model_dac[2][1 << 8];
101 #if RESID_INLINING || defined(RESID_ENVELOPE_CC)
107 void EnvelopeGenerator::clock()
111 if (unlikely(envelope_pipeline)) {
113 envelope_pipeline = 0;
115 set_exponential_counter();
125 if (unlikely(++rate_counter & 0x8000)) {
126 ++rate_counter &= 0x7fff;
129 if (likely(rate_counter != rate_period)) {
138 if (state == ATTACK || ++exponential_counter == exponential_counter_period)
141 exponential_counter = 0;
144 if (unlikely(hold_zero)) {
155 ++envelope_counter &= 0xff;
156 if (unlikely(envelope_counter == 0xff)) {
157 state = DECAY_SUSTAIN;
158 rate_period = rate_counter_period[decay];
162 if (likely(envelope_counter == sustain_level[sustain])) {
165 if (exponential_counter_period != 1) {
168 envelope_pipeline = 1;
180 if (exponential_counter_period != 1) {
183 envelope_pipeline = 1;
186 --envelope_counter &= 0xff;
191 set_exponential_counter();
200 void EnvelopeGenerator::clock(cycle_count delta_t)
214 int rate_step = rate_period - rate_counter;
215 if (unlikely(rate_step <= 0)) {
220 if (delta_t < rate_step) {
222 rate_counter += delta_t;
223 if (unlikely(rate_counter & 0x8000)) {
224 ++rate_counter &= 0x7fff;
230 delta_t -= rate_step;
235 if (state == ATTACK || ++exponential_counter == exponential_counter_period)
238 exponential_counter = 0;
241 if (unlikely(hold_zero)) {
242 rate_step = rate_period;
253 ++envelope_counter &= 0xff;
254 if (unlikely(envelope_counter == 0xff)) {
255 state = DECAY_SUSTAIN;
256 rate_period = rate_counter_period[decay];
260 if (likely(envelope_counter == sustain_level[sustain])) {
272 --envelope_counter &= 0xff;
277 set_exponential_counter();
280 rate_step = rate_period;
289 short EnvelopeGenerator::output()
293 return model_dac[sid_model][envelope_counter];
297 void EnvelopeGenerator::set_exponential_counter()
300 switch (envelope_counter) {
302 exponential_counter_period = 1;
305 exponential_counter_period = 2;
308 exponential_counter_period = 4;
311 exponential_counter_period = 8;
314 exponential_counter_period = 16;
317 exponential_counter_period = 30;
323 exponential_counter_period = 1;
332 #endif // RESID_INLINING || defined(RESID_ENVELOPE_CC)
336 #endif // not RESID_ENVELOPE_H
Definition: envelope.h:37