96 rc_matrix_t model_wave;
97 rc_matrix_t model_pulldown;
99 int16_t* wave =
nullptr;
100 int16_t* pulldown =
nullptr;
105 uint32_t shift_register = 0;
108 uint32_t shift_latch = 0;
111 int shift_pipeline = 0;
113 uint32_t ring_msb_mask = 0;
114 uint32_t no_noise = 0;
115 uint32_t noise_output = 0;
116 uint32_t no_noise_or_noise_output = 0;
117 uint32_t no_pulse = 0;
118 uint32_t pulse_output = 0;
120 uint32_t waveform_output = 0;
123 uint32_t accumulator = 0x555555;
129 uint32_t tri_saw_pipeline = 0x555;
135 unsigned int shift_register_reset = 0;
138 unsigned int floating_output_ttl = 0;
141 uint8_t waveform = 0;
153 bool msb_rising =
false;
164 void shift_phase2(uint8_t waveform_old, uint8_t waveform_new);
166 void write_shift_register();
168 void set_noise_output();
170 void set_no_noise_or_noise_output();
174 void shiftregBitfade();
176 inline void setWave() { wave = (*model_wave)[waveform & 0x3]; }
178 inline void setPulldown()
182 switch (waveform & 0x7)
185 pulldown = (*model_pulldown)[0];
188 pulldown = (waveform & 0x8) ? (*model_pulldown)[4] :
nullptr;
191 pulldown = (*model_pulldown)[1];
194 pulldown = (*model_pulldown)[2];
197 pulldown = (*model_pulldown)[3];
205 void setWaveformModels(rc_matrix_t models);
206 void setPulldownModels(rc_matrix_t models);
220 void setModel(
bool new_is6581) { is6581 = new_is6581; }
239 void writeFREQ_LO(uint8_t freq_lo) { freq = (freq & 0xff00) | (freq_lo & 0xff); }
246 void writeFREQ_HI(uint8_t freq_hi) { freq = (freq_hi << 8 & 0xff00) | (freq & 0xff); }
253 void writePW_LO(uint8_t pw_lo) { pw = (pw & 0xf00) | (pw_lo & 0x0ff); }
260 void writePW_HI(uint8_t pw_hi) { pw = (pw_hi << 8 & 0xf00) | (pw & 0x0ff); }
284 uint8_t
readOSC()
const {
return static_cast<uint8_t
>(osc3 >> 4); }
319 if (unlikely(shift_register_reset != 0) && unlikely(--shift_register_reset == 0))
322 std::cout <<
"shiftregBitfade" << std::endl;
325 shift_latch = shift_register;
332 test_or_reset =
true;
335 pulse_output = 0xfff;
340 const uint32_t accumulator_old = accumulator;
341 accumulator = (accumulator + freq) & 0xffffff;
344 const uint32_t accumulator_bits_set = ~accumulator_old & accumulator;
347 msb_rising = (accumulator_bits_set & 0x800000) != 0;
351 if (unlikely((accumulator_bits_set & 0x080000) != 0))
356 else if (unlikely(shift_pipeline != 0))
358 switch (--shift_pipeline)
362 std::cout <<
"shift phase 2" << std::endl;
364 shift_phase2(waveform, waveform);
368 std::cout <<
"shift phase 1" << std::endl;
371 test_or_reset =
false;
372 shift_latch = shift_register;
383 if (likely(waveform != 0))
385 const uint32_t ix = (accumulator ^ (~prevVoice->accumulator & ring_msb_mask)) >> 12;
389 waveform_output = wave[ix] & (no_pulse | pulse_output) & no_noise_or_noise_output;
390 if (pulldown !=
nullptr)
391 waveform_output = pulldown[waveform_output];
396 if ((waveform & 3) && !is6581)
398 osc3 = tri_saw_pipeline & (no_pulse | pulse_output) & no_noise_or_noise_output;
399 if (pulldown !=
nullptr)
400 osc3 = pulldown[osc3];
401 tri_saw_pipeline = wave[ix];
405 osc3 = waveform_output;
410 if (is6581 && (waveform & 0x2) && ((waveform_output & 0x800) == 0))
413 accumulator &= 0x7fffff;
416 write_shift_register();
421 if (likely(floating_output_ttl != 0) && unlikely(--floating_output_ttl == 0))
439 pulse_output = ((accumulator >> 12) >= pw) ? 0xfff : 0x000;
441 return waveform_output;