1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-02 20:30:00 +00:00

Takes a shot at key-level scaling. Testing to come.

This commit is contained in:
Thomas Harte 2020-04-21 00:09:42 -04:00
parent 475d75c16a
commit bdce1c464a
2 changed files with 51 additions and 2 deletions

View File

@ -27,7 +27,7 @@ void Operator::set_sustain_release(uint8_t value) {
}
void Operator::set_scaling_output(uint8_t value) {
level_key_scaling_ = value >> 6;
key_level_scaling_ = value >> 6;
attenuation_ = value & 0x3f;
}
@ -174,6 +174,55 @@ void Operator::update(OperatorState &state, bool key_on, int channel_period, int
state.time_in_phase_ = 0;
}
// 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] = {
#define _ 0
{
{_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _},
{_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _},
{_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _},
{_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _},
{_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _},
{_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _},
{_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _},
{_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _},
},
{
{_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _},
{_, _, _, _, _, _, _, _, _, 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},
},
{
{_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _},
{_, _, _, _, _, _, _, _, _, 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},
},
{
{_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _},
{_, _, _, _, _, _, _, _, _, 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 _
};
state.attenuation.log += key_level_scales[key_level_scaling_][channel_octave][channel_period >> 6] << 7;
// Combine the ADSR attenuation and overall channel attenuation.
if(overrides) {
// Overrides here represent per-channel volume on an OPLL. The bits are defined to represent

View File

@ -114,7 +114,7 @@ class Operator {
bool key_scaling_rate_ = false;
/// Selects attenuation that is applied as a function of interval. Cf. p14.
int level_key_scaling_ = 0;
int key_level_scaling_ = 0;
/// Sets the ADSR rates. These all provide the top four bits of a six-bit number;
/// the bottom two bits... are 'RL'?