1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-01-12 15:31:09 +00:00

Made an attempt to tidy up.

This commit is contained in:
Thomas Harte 2016-10-19 21:43:18 -04:00
parent 5e2b0aa901
commit 101f168ea4

View File

@ -79,60 +79,56 @@ void AY38910::get_samples(unsigned int number_of_samples, int16_t *target)
_master_divider++; _master_divider++;
int resulting_steps = ((_master_divider ^ former_master_divider) >> 4) & 1; int resulting_steps = ((_master_divider ^ former_master_divider) >> 4) & 1;
// from that the three channels count down
int did_underflow; int did_underflow;
#define step(c) \ #define shift(x, r) \
_channel_dividers[c] -= resulting_steps; \ x -= resulting_steps; \
did_underflow = (_channel_dividers[c] >> 15)&1; \ did_underflow = (x >> 15)&1; \
_channel_output[c] ^= did_underflow; \ x = did_underflow * r + (did_underflow^1) * x;
_channel_dividers[c] = did_underflow * _tone_generator_controls[c] + (did_underflow^1) * _channel_dividers[c];
step(0); #define step_channel(c) \
step(1); shift(_channel_dividers[c], _tone_generator_controls[c]); \
step(2); _channel_output[c] ^= did_underflow;
#undef step // update the tone channels
step_channel(0);
step_channel(1);
step_channel(2);
// ... as does the noise generator // ... the noise generator
_noise_divider -= resulting_steps; shift(_noise_divider, _output_registers[6]&0x1f);
did_underflow = (_noise_divider >> 15)&1;
_noise_divider = did_underflow * (_output_registers[6]&0x1f) + (did_underflow^1) * _noise_divider;
_noise_output ^= did_underflow&_noise_shift_register&1; _noise_output ^= did_underflow&_noise_shift_register&1;
_noise_shift_register |= ((_noise_shift_register ^ (_noise_shift_register >> 3))&1) << 17; _noise_shift_register |= ((_noise_shift_register ^ (_noise_shift_register >> 3))&1) << 17;
_noise_shift_register >>= did_underflow; _noise_shift_register >>= did_underflow;
// ... and the envelope generator // ... and the envelope generator
_envelope_divider -= resulting_steps; shift(_envelope_divider, _envelope_period);
did_underflow = (_envelope_divider >> 15)&1;
_envelope_divider = did_underflow * _envelope_period + (did_underflow^1) * _envelope_divider;
_envelope_position += did_underflow; _envelope_position += did_underflow;
// if(_output_registers[13] == 13)
// {
// printf("[%d] %d", _envelope_divider, _envelope_position);
// }
int refill = _envelope_overflow_masks[_output_registers[13]] * (_envelope_position >> 5); int refill = _envelope_overflow_masks[_output_registers[13]] * (_envelope_position >> 5);
_envelope_position = (_envelope_position & 0x1f) | refill; _envelope_position = (_envelope_position & 0x1f) | refill;
int envelope_volume = _envelope_shapes[_output_registers[13]][_envelope_position & 0xf]; int envelope_volume = _envelope_shapes[_output_registers[13]][_envelope_position & 0xf];
// if(_output_registers[13] == 13) #undef step_channel
// { #undef shift
// printf(": %d\n", envelope_volume);
// } #define level(c, tb, nb) \
(((((_output_registers[7] >> tb)&1)^1) & _channel_output[c]) | ((((_output_registers[7] >> nb)&1)^1) & _noise_output)) ^ 1
int channel_levels[3] = { int channel_levels[3] = {
(((((_output_registers[7] >> 0)&1)^1) & _channel_output[0]) | ((((_output_registers[7] >> 1)&1)^1) & _noise_output)) ^ 1, level(0, 0, 1),
(((((_output_registers[7] >> 2)&1)^1) & _channel_output[1]) | ((((_output_registers[7] >> 3)&1)^1) & _noise_output)) ^ 1, level(1, 2, 3),
(((((_output_registers[7] >> 4)&1)^1) & _channel_output[2]) | ((((_output_registers[7] >> 5)&1)^1) & _noise_output)) ^ 1, level(2, 4, 5),
}; };
#undef level
#define channel_volume(c) \
((_output_registers[c] >> 4)&1) * envelope_volume + (((_output_registers[c] >> 4)&1)^1) * (_output_registers[c]&0x1f)
int volumes[3] = { int volumes[3] = {
((_output_registers[8] >> 4)&1) * envelope_volume + (((_output_registers[8] >> 4)&1)^1) * (_output_registers[8]&0x1f), channel_volume(8),
((_output_registers[9] >> 4)&1) * envelope_volume + (((_output_registers[9] >> 4)&1)^1) * (_output_registers[9]&0x1f), channel_volume(9),
((_output_registers[10] >> 4)&1) * envelope_volume + (((_output_registers[10] >> 4)&1)^1) * (_output_registers[10]&0x1f), channel_volume(10)
}; };
#undef channel_volume
target[c] = (int16_t)(( target[c] = (int16_t)((
volumes[0] * channel_levels[0] + volumes[0] * channel_levels[0] +