From 06201a1c4f958b31b33aa7d6239bb61f1eba7485 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Sun, 31 Dec 2017 17:30:35 -0500 Subject: [PATCH] C64: Fix voume based audio sampling, fix some state bugs --- .../Commodore64/C64.IMemoryDomains.cs | 2 +- .../Commodore64/Cassette/TapeDrive.cs | 18 ++++++++++++++++-- .../Computers/Commodore64/MOS/Sid.Registers.cs | 5 +++-- .../Commodore64/MOS/Sid.SoundProvider.cs | 4 ++-- .../Computers/Commodore64/MOS/Sid.cs | 3 +++ 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/BizHawk.Emulation.Cores/Computers/Commodore64/C64.IMemoryDomains.cs b/BizHawk.Emulation.Cores/Computers/Commodore64/C64.IMemoryDomains.cs index 9f7dab9541..b89b26709b 100644 --- a/BizHawk.Emulation.Cores/Computers/Commodore64/C64.IMemoryDomains.cs +++ b/BizHawk.Emulation.Cores/Computers/Commodore64/C64.IMemoryDomains.cs @@ -34,7 +34,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64 }); } - if (tapeDriveEnabled) + if (tapeDriveEnabled && (_board.TapeDrive.TapeDataDomain != null)) { domains.AddRange(new[] { diff --git a/BizHawk.Emulation.Cores/Computers/Commodore64/Cassette/TapeDrive.cs b/BizHawk.Emulation.Cores/Computers/Commodore64/Cassette/TapeDrive.cs index e5ef8a1e67..f41258ce44 100644 --- a/BizHawk.Emulation.Cores/Computers/Commodore64/Cassette/TapeDrive.cs +++ b/BizHawk.Emulation.Cores/Computers/Commodore64/Cassette/TapeDrive.cs @@ -32,7 +32,8 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cassette public override void SyncState(Serializer ser) { - _tape.SyncState(ser); + + if (_tape != null) { _tape.SyncState(ser); } } public void Insert(Tape tape) @@ -46,6 +47,19 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cassette } // Exposed for memory domains, should not be used for actual emulation implementation - public override byte[] TapeDataDomain => _tape.TapeDataDomain; + public override byte[] TapeDataDomain + { + get + { + if (_tape != null) + { + return _tape.TapeDataDomain; + } + else + { + return null; + } + } + } } } diff --git a/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Sid.Registers.cs b/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Sid.Registers.cs index fe1fbc9d56..860df3e7b6 100644 --- a/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Sid.Registers.cs +++ b/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Sid.Registers.cs @@ -138,12 +138,13 @@ // we want to only flush the filter when the filter is actually changed, that way // the FFT will not be impacted by small sample sizes from other changes - if (addr == 15 || addr == 16 || addr==17) + if ((addr == 0x15) || (addr == 0x16) || (addr == 0x17)) { Flush(true); } - else if (addr==18) + else if (addr == 0x18) { + // note: we only want to flush the filter here if the filter components are changing bool temp1 = (val & 0x10) != 0; bool temp2 = (val & 0x20) != 0; diff --git a/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Sid.SoundProvider.cs b/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Sid.SoundProvider.cs index b5a431a523..d5d4d337dd 100644 --- a/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Sid.SoundProvider.cs +++ b/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Sid.SoundProvider.cs @@ -49,8 +49,8 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS { _mixer = _outputBuffer_not_filtered[i] + _outputBuffer_filtered[i]; _mixer = _mixer >> 7; - _mixer = (_mixer * _volume) >> 4; - _mixer -= _volume << 8; + _mixer = (_mixer * _volume_at_sample_time[i]) >> 4; + _mixer -= _volume_at_sample_time[i] << 8; if (_mixer > 0x7FFF) { diff --git a/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Sid.cs b/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Sid.cs index f31731177a..781cfa569c 100644 --- a/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Sid.cs +++ b/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Sid.cs @@ -41,6 +41,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS private short[] _outputBuffer; private int[] _outputBuffer_filtered; private int[] _outputBuffer_not_filtered; + private int[] _volume_at_sample_time; private int _outputBufferIndex; private int filter_index; private int last_filtered_value; @@ -93,6 +94,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS _outputBuffer_filtered = new int[sampleRate]; _outputBuffer_not_filtered = new int[sampleRate]; + _volume_at_sample_time = new int[sampleRate]; } // ------------------------------------ @@ -190,6 +192,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS { _outputBuffer_not_filtered[_outputBufferIndex] = temp_not_filtered; _outputBuffer_filtered[_outputBufferIndex] = temp_filtered; + _volume_at_sample_time[_outputBufferIndex] = _volume; _outputBufferIndex++; } }