1
0
mirror of https://github.com/TomHarte/CLK.git synced 2026-04-26 19:17:52 +00:00

Treat sustain as a volume; start second prescaler table.

This commit is contained in:
Thomas Harte
2025-11-11 12:43:48 -05:00
parent b0b82782ad
commit 8c2294fc0d
2 changed files with 28 additions and 2 deletions
+1 -1
View File
@@ -50,7 +50,7 @@ void SID::write(const Numeric::SizedInt<5> address, const uint8_t value) {
adsr().set_phase(adsr().phase);
break;
case 0x06: case 0x0d: case 0x14:
adsr().sustain = value >> 4;
adsr().sustain = (value >> 4) | (value & 0xf0);
adsr().release = value;
adsr().set_phase(adsr().phase);
break;
+27 -1
View File
@@ -83,9 +83,10 @@ private:
// Programmer inputs.
Numeric::SizedInt<4> attack;
Numeric::SizedInt<4> decay;
Numeric::SizedInt<4> sustain;
Numeric::SizedInt<4> release;
Numeric::SizedInt<8> sustain;
// State.
enum class Phase {
Attack,
@@ -94,6 +95,7 @@ private:
} phase = Phase::Release;
Numeric::SizedInt<15> rate_counter;
Numeric::SizedInt<15> rate_counter_target;
Numeric::SizedInt<8> envelope_counter;
void set_phase(const Phase new_phase) {
static constexpr uint16_t rate_prescaler[] = {
@@ -139,6 +141,30 @@ private:
adsr.rate_counter = 0;
// TODO: second prescaler?
static constexpr uint8_t envelope_counter_rates[] = {
1, // 0
30, 30, 30, 30, 30, 30, // 16
16, 16, 16, 16, 16, 16, 16, 16, // 714
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, // 1526
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, // 2754
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
};
static_assert(envelope_counter_rates[0] == 1);
static_assert(envelope_counter_rates[1] == 30);
static_assert(envelope_counter_rates[6] == 30);
static_assert(envelope_counter_rates[7] == 16);
static_assert(envelope_counter_rates[14] == 16);
static_assert(envelope_counter_rates[15] == 8);
static_assert(envelope_counter_rates[26] == 8);
static_assert(envelope_counter_rates[27] == 4);
static_assert(envelope_counter_rates[54] == 4);
static_assert(envelope_counter_rates[55] == 2);
// static_assert(envelope_counter_rates[94] == 2);
// static_assert(envelope_counter_rates[95] == 1);
// static_assert(envelope_counter_rates[255] == 1);
// envelope_counter;
}
}