1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-12-25 03:32:01 +00:00

Made an attempt to eliminate conditionals (running before I can walk?) and started edging towards an envelope generator.

This commit is contained in:
Thomas Harte 2016-10-17 08:03:38 -04:00
parent cc0b70828b
commit 43612e1ca2
2 changed files with 17 additions and 8 deletions

View File

@ -10,7 +10,7 @@
using namespace GI;
AY38910::AY38910() : _selected_register(0), _channel_ouput{0, 0, 0}
AY38910::AY38910() : _selected_register(0), _channel_ouput{0, 0, 0}, _channel_dividers{0, 0, 0}, _tone_generator_controls{0, 0, 0}
{
_output_registers[8] = _output_registers[9] = _output_registers[10] = 0;
}
@ -20,13 +20,6 @@ void AY38910::set_clock_rate(double clock_rate)
set_input_rate((float)clock_rate);
}
#define step(c) \
_channel_dividers[c] -= resulting_steps; \
if(!_channel_dividers[c]) \
{ \
_channel_dividers[c] = (int)_tone_generator_controls[c] + 1; \
_channel_ouput[c] ^= 1; \
}
void AY38910::get_samples(unsigned int number_of_samples, int16_t *target)
{
@ -38,10 +31,24 @@ void AY38910::get_samples(unsigned int number_of_samples, int16_t *target)
int resulting_steps = ((_master_divider ^ former_master_divider) >> 4) & 1;
// from that the three channels count down
#define step(c) \
_channel_dividers[c] -= resulting_steps; \
_channel_ouput[c] ^= (_channel_dividers[c] >> 15); \
_channel_dividers[c] = ((_channel_dividers[c] >> 15) * _tone_generator_controls[c]) + ((_channel_dividers[c] >> 15)^1) * _channel_dividers[c];
step(0);
step(1);
step(2);
#undef step
// ... as does the envelope generator
_envelope_divider -= resulting_steps;
if(!_envelope_divider)
{
_envelope_divider = _envelope_period;
}
*target++ = (int16_t)((
((_output_registers[8]&0xf) * _channel_ouput[0]) +
((_output_registers[9]&0xf) * _channel_ouput[1]) +

View File

@ -36,6 +36,8 @@ class AY38910: public ::Outputs::Filter<AY38910> {
int _master_divider;
int _channel_dividers[3];
int _envelope_divider;
int _evelope_volume;
int _channel_ouput[3];
};