From 6a44936a7c41fb8a630be52889307396e0b18c6a Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 5 Jan 2020 22:44:52 -0500 Subject: [PATCH] Ensures programmatic volume level 0 is completely off. --- Components/AY38910/AY38910.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Components/AY38910/AY38910.cpp b/Components/AY38910/AY38910.cpp index 5ed753bf5..c5544b21a 100644 --- a/Components/AY38910/AY38910.cpp +++ b/Components/AY38910/AY38910.cpp @@ -77,6 +77,7 @@ void AY38910::set_sample_volume_range(std::int16_t range) { for(int v = 0; v < 32; v++) { volumes_[v] = int(max_volume / powf(root_two, float(v ^ 0x1f) / 2.0f)); } + volumes_[0] = 0; // Tie level 0 to silence. evaluate_output_volume(); } @@ -161,10 +162,20 @@ void AY38910::evaluate_output_volume() { }; #undef level + // This remapping table seeks to map 'channel volumes', i.e. the levels produced from the + // 16-step progammatic volumes set per channel to 'envelope volumes', i.e. the 32-step + // volumes that are produced by the envelope generators (on a YM at least). My reading of + // the data sheet is that '0' is still off, but 15 should be as loud as peak envelope. So + // I've thrown in the discontinuity at the low end, where it'll be very quiet. + const int channel_volumes[] = { + 0, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31 + }; + static_assert(sizeof(channel_volumes) == 16*sizeof(int)); + // Channel volume is a simple selection: if the bit at 0x10 is set, use the envelope volume; otherwise use the lower four bits, // mapped to the range 1–31 in case this is a YM. #define channel_volume(c) \ - ((output_registers_[c] >> 4)&1) * envelope_volume + (((output_registers_[c] >> 4)&1)^1) * (((output_registers_[c]&0xf) << 1) + 1) + ((output_registers_[c] >> 4)&1) * envelope_volume + (((output_registers_[c] >> 4)&1)^1) * channel_volumes[output_registers_[c]&0xf] const int volumes[3] = { channel_volume(8),