mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-22 12:33:29 +00:00
Collapses key-level scaling to a single 2d table.
I dare imagine I can do better; the columns in particular look like arithmetic progressions.
This commit is contained in:
parent
40424ac38b
commit
2886dd1dae
@ -177,53 +177,23 @@ void Operator::update(OperatorState &state, bool key_on, int channel_period, int
|
||||
// Calculate key-level scaling. Table is as per p14 of the YM3812 application manual,
|
||||
// converted into a fixed-point scheme. Compare with https://www.smspower.org/Development/RE12
|
||||
// and apologies for the highly ad hoc indentation.
|
||||
constexpr int key_level_scales[4][8][16] = {
|
||||
constexpr int key_level_scale_shifts[4] = {7, 1, 2, 0}; // '7' is just a number large enough to render all the numbers below as 0.
|
||||
constexpr int key_level_scales[8][16] = {
|
||||
#define _ 0
|
||||
{ // 0 db of attenuation.
|
||||
{_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _},
|
||||
{_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _},
|
||||
{_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _},
|
||||
{_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _},
|
||||
{_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _},
|
||||
{_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _},
|
||||
{_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _},
|
||||
{_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _},
|
||||
},
|
||||
{ // 3 db.
|
||||
{_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _},
|
||||
{_, _, _, _, _, _, _, _, _, 2, 3, 4, 5, 6, 7, 8},
|
||||
{_, _, _, _, _, 3, 5, 7, 8, 10, 11, 12, 13, 14, 15, 16},
|
||||
{_, _, _, 5, 8, 11, 13, 15, 16, 18, 19, 20, 21, 22, 23, 24},
|
||||
{_, _, 8, 13, 16, 19, 21, 23, 24, 26, 27, 28, 29, 30, 31, 32},
|
||||
{_, 8, 16, 21, 24, 27, 29, 31, 32, 34, 35, 36, 37, 38, 39, 40},
|
||||
{_, 16, 24, 29, 32, 35, 37, 39, 40, 42, 43, 44, 45, 46, 47, 48},
|
||||
{_, 24, 32, 37, 40, 43, 45, 47, 48, 50, 51, 52, 53, 54, 55, 56},
|
||||
},
|
||||
{ // 1.5 db.
|
||||
{_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _},
|
||||
{_, _, _, _, _, _, _, _, _, 1, 1, 2, 2, 3, 3, 4},
|
||||
{_, _, _, _, _, 1, 2, 3, 4, 5, 5, 6, 6, 7, 7, 8},
|
||||
{_, _, _, 2, 4, 5, 6, 7, 8, 9, 9, 10, 10, 11, 11, 12},
|
||||
{_, _, 4, 6, 8, 9, 10, 11, 12, 13, 13, 14, 14, 15, 15, 16},
|
||||
{_, 4, 8, 10, 12, 13, 14, 15, 16, 17, 17, 18, 18, 19, 19, 20},
|
||||
{_, 8, 12, 14, 16, 17, 18, 19, 20, 21, 21, 22, 22, 23, 23, 24},
|
||||
{_, 12, 16, 18, 20, 21, 22, 23, 24, 25, 25, 26, 26, 27, 27, 28},
|
||||
},
|
||||
{ // 6 db.
|
||||
{_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _},
|
||||
{_, _, _, _, _, _, _, _, _, 4, 6, 8, 10, 12, 14, 16},
|
||||
{_, _, _, _, _, 6, 10, 14, 16, 20, 22, 24, 26, 28, 30, 32},
|
||||
{_, _, _, 10, 16, 22, 26, 30, 32, 36, 38, 40, 42, 44, 46, 48},
|
||||
{_, _, 16, 26, 32, 38, 42, 46, 48, 52, 54, 56, 58, 60, 62, 64},
|
||||
{_, 16, 32, 42, 48, 54, 58, 62, 64, 68, 70, 72, 74, 76, 78, 80},
|
||||
{_, 32, 48, 58, 64, 70, 74, 78, 80, 84, 86, 88, 90, 92, 94, 96},
|
||||
{_, 48, 64, 74, 80, 86, 90, 94, 96, 100, 102, 104, 106, 108, 110, 112},
|
||||
},
|
||||
// 6 db attenuations.
|
||||
{_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _},
|
||||
{_, _, _, _, _, _, _, _, _, 4, 6, 8, 10, 12, 14, 16},
|
||||
{_, _, _, _, _, 6, 10, 14, 16, 20, 22, 24, 26, 28, 30, 32},
|
||||
{_, _, _, 10, 16, 22, 26, 30, 32, 36, 38, 40, 42, 44, 46, 48},
|
||||
{_, _, 16, 26, 32, 38, 42, 46, 48, 52, 54, 56, 58, 60, 62, 64},
|
||||
{_, 16, 32, 42, 48, 54, 58, 62, 64, 68, 70, 72, 74, 76, 78, 80},
|
||||
{_, 32, 48, 58, 64, 70, 74, 78, 80, 84, 86, 88, 90, 92, 94, 96},
|
||||
{_, 48, 64, 74, 80, 86, 90, 94, 96, 100, 102, 104, 106, 108, 110, 112},
|
||||
#undef _
|
||||
};
|
||||
assert((channel_period >> 6) < 4);
|
||||
assert((channel_period >> 6) < 16);
|
||||
assert(channel_octave < 8);
|
||||
state.attenuation.log += key_level_scales[key_level_scaling_][channel_octave][channel_period >> 6] << 7;
|
||||
state.attenuation.log += (key_level_scales[channel_octave][channel_period >> 6] >> key_level_scale_shifts[key_level_scaling_]) << 7;
|
||||
|
||||
// Combine the ADSR attenuation and overall channel attenuation.
|
||||
if(overrides) {
|
||||
|
Loading…
Reference in New Issue
Block a user