From 7f20da42e65bb6f9f4aaa9a33b3c29b58a74cd2d Mon Sep 17 00:00:00 2001 From: sin365 <353374337@qq.com> Date: Mon, 17 Nov 2025 23:22:26 +0800 Subject: [PATCH] =?UTF-8?q?Essgee:GAMEBOY=20DMGAudio=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=8E=89=E6=8E=A5=E5=8F=A3=E8=AE=BF=E9=97=AE=E5=99=A8=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E9=9F=B3=E9=87=8F=E7=9A=84=E5=81=9A=E6=B3=95=EF=BC=8C?= =?UTF-8?q?=E9=81=BF=E5=85=8D=E6=AF=8F=E5=B8=A714=E4=B8=87=E6=AC=A1?= =?UTF-8?q?=E7=9A=84volume=E8=AE=BF=E9=97=AE=E5=99=A8=E5=A0=86=E6=A0=88?= =?UTF-8?q?=E8=80=97=E8=B4=B9=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Emulation/Audio/CGBAudio.Wave.cs | 3 +- .../Emulation/Audio/DMGAudio.Noise.cs | 22 +++++----- .../Emulation/Audio/DMGAudio.Square.cs | 22 +++++----- .../Emulation/Audio/DMGAudio.Wave.cs | 22 +++++----- .../Emulation/Audio/IDMGAudioChannel.cs | 42 ++++++++++++------- 5 files changed, 63 insertions(+), 48 deletions(-) diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio/CGBAudio.Wave.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio/CGBAudio.Wave.cs index da9eb68e..b80bf49a 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio/CGBAudio.Wave.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio/CGBAudio.Wave.cs @@ -2,7 +2,8 @@ { public partial class CGBAudio { - public class CGBWave : Wave, IDMGAudioChannel + //本身wave就继承了IDMGAudioChannel + public class CGBWave : Wave//, IDMGAudioChannel { public override void Reset() { diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio/DMGAudio.Noise.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio/DMGAudio.Noise.cs index db82aa59..ba36a8f7 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio/DMGAudio.Noise.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio/DMGAudio.Noise.cs @@ -39,16 +39,16 @@ namespace Essgee.Emulation.Audio bool isChannelEnabled, isDacEnabled; int lengthCounter; - public int OutputVolume { get; private set; } + //public int OutputVolume { get; private set; } - public bool IsActive { get { return lengthCounter != 0; } } + public override bool IsActive { get { return lengthCounter != 0; } } public Noise() { // } - public void Reset() + public override void Reset() { noiseCounter = 0; lfsr = 0; @@ -63,7 +63,7 @@ namespace Essgee.Emulation.Audio OutputVolume = volume; } - public void LengthCounterClock() + public override void LengthCounterClock() { if (lengthCounter > 0 && lengthEnable) { @@ -73,12 +73,12 @@ namespace Essgee.Emulation.Audio } } - public void SweepClock() + public override void SweepClock() { throw new Exception("Channel type does not support sweep"); } - public void VolumeEnvelopeClock() + public override void VolumeEnvelopeClock() { envelopeCounter--; if (envelopeCounter == 0) @@ -99,7 +99,7 @@ namespace Essgee.Emulation.Audio } } - public void Step() + public override void Step() { if (!isChannelEnabled) return; @@ -132,7 +132,7 @@ namespace Essgee.Emulation.Audio lfsr = 0x7FFF; } - public void WritePort(byte port, byte value) + public override void WritePort(byte port, byte value) { switch (port) { @@ -168,7 +168,7 @@ namespace Essgee.Emulation.Audio } } - public byte ReadPort(byte port) + public override byte ReadPort(byte port) { switch (port) { @@ -200,12 +200,12 @@ namespace Essgee.Emulation.Audio } } - public void WriteWaveRam(byte offset, byte value) + public override void WriteWaveRam(byte offset, byte value) { throw new Exception("Channel type does have Wave RAM"); } - public byte ReadWaveRam(byte offset) + public override byte ReadWaveRam(byte offset) { throw new Exception("Channel type does have Wave RAM"); } diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio/DMGAudio.Square.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio/DMGAudio.Square.cs index fe255c89..01cfc0b5 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio/DMGAudio.Square.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio/DMGAudio.Square.cs @@ -74,16 +74,16 @@ namespace Essgee.Emulation.Audio bool isChannelEnabled, isDacEnabled; int lengthCounter, dutyCounter; - public int OutputVolume { get; private set; } + //public int OutputVolume { get; private set; } - public bool IsActive { get { return lengthCounter != 0; } } + public override bool IsActive { get { return lengthCounter != 0; } } public Square(bool hasSweep) { channelSupportsSweep = hasSweep; } - public void Reset() + public override void Reset() { isSweepEnabled = false; sweepCounter = sweepFreqShadow = 0; @@ -100,7 +100,7 @@ namespace Essgee.Emulation.Audio OutputVolume = volume; } - public void LengthCounterClock() + public override void LengthCounterClock() { if (lengthCounter > 0 && lengthEnable) { @@ -110,7 +110,7 @@ namespace Essgee.Emulation.Audio } } - public void SweepClock() + public override void SweepClock() { if (!channelSupportsSweep) return; @@ -133,7 +133,7 @@ namespace Essgee.Emulation.Audio } } - public void VolumeEnvelopeClock() + public override void VolumeEnvelopeClock() { envelopeCounter--; if (envelopeCounter == 0) @@ -154,7 +154,7 @@ namespace Essgee.Emulation.Audio } } - public void Step() + public override void Step() { if (!isChannelEnabled) return; @@ -202,7 +202,7 @@ namespace Essgee.Emulation.Audio return newFrequency; } - public void WritePort(byte port, byte value) + public override void WritePort(byte port, byte value) { switch (port) { @@ -244,7 +244,7 @@ namespace Essgee.Emulation.Audio } } - public byte ReadPort(byte port) + public override byte ReadPort(byte port) { switch (port) { @@ -281,12 +281,12 @@ namespace Essgee.Emulation.Audio } } - public void WriteWaveRam(byte offset, byte value) + public override void WriteWaveRam(byte offset, byte value) { throw new Exception("Channel type does have Wave RAM"); } - public byte ReadWaveRam(byte offset) + public override byte ReadWaveRam(byte offset) { throw new Exception("Channel type does have Wave RAM"); } diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio/DMGAudio.Wave.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio/DMGAudio.Wave.cs index 6448d3e7..a4cf721a 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio/DMGAudio.Wave.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio/DMGAudio.Wave.cs @@ -30,16 +30,16 @@ namespace Essgee.Emulation.Audio bool isChannelEnabled; int lengthCounter; - public int OutputVolume { get; private set; } + //public int OutputVolume { get; private set; } - public bool IsActive { get { return isDacEnabled; } } // TODO: correct? lengthCounter check makes Zelda Oracle games hang + public override bool IsActive { get { return isDacEnabled; } } // TODO: correct? lengthCounter check makes Zelda Oracle games hang public Wave() { sampleBuffer = new byte[16]; } - public virtual void Reset() + public override void Reset() { for (var i = 0; i < sampleBuffer.Length; i++) sampleBuffer[i] = (byte)EmuStandInfo.Random.Next(255); frequencyCounter = positionCounter = 0; @@ -51,7 +51,7 @@ namespace Essgee.Emulation.Audio OutputVolume = volume; } - public void LengthCounterClock() + public override void LengthCounterClock() { if (lengthCounter > 0 && lengthEnable) { @@ -61,17 +61,17 @@ namespace Essgee.Emulation.Audio } } - public void SweepClock() + public override void SweepClock() { throw new Exception("Channel type does not support sweep"); } - public void VolumeEnvelopeClock() + public override void VolumeEnvelopeClock() { throw new Exception("Channel type does not support envelope"); } - public void Step() + public override void Step() { if (!isChannelEnabled) return; @@ -105,7 +105,7 @@ namespace Essgee.Emulation.Audio positionCounter = 0; } - public void WritePort(byte port, byte value) + public override void WritePort(byte port, byte value) { switch (port) { @@ -137,7 +137,7 @@ namespace Essgee.Emulation.Audio } } - public byte ReadPort(byte port) + public override byte ReadPort(byte port) { switch (port) { @@ -166,7 +166,7 @@ namespace Essgee.Emulation.Audio // TODO: more details on behavior on access w/ channel enabled - public void WriteWaveRam(byte offset, byte value) + public override void WriteWaveRam(byte offset, byte value) { if (!isDacEnabled) sampleBuffer[offset & (sampleBuffer.Length - 1)] = value; @@ -174,7 +174,7 @@ namespace Essgee.Emulation.Audio sampleBuffer[positionCounter & (sampleBuffer.Length - 1)] = value; } - public byte ReadWaveRam(byte offset) + public override byte ReadWaveRam(byte offset) { if (!isDacEnabled) return sampleBuffer[offset & (sampleBuffer.Length - 1)]; diff --git a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio/IDMGAudioChannel.cs b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio/IDMGAudioChannel.cs index 5de0da69..774f054e 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio/IDMGAudioChannel.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/Essgee.Unity/Emulation/Audio/IDMGAudioChannel.cs @@ -1,19 +1,33 @@ namespace Essgee.Emulation.Audio { - public interface IDMGAudioChannel + //public interface IDMGAudioChannel + // { + // int OutputVolume { get; } + // bool IsActive { get; } + + // void Reset(); + // void LengthCounterClock(); + // void SweepClock(); + // void VolumeEnvelopeClock(); + // void Step(); + + // void WritePort(byte port, byte value); + // byte ReadPort(byte port); + // void WriteWaveRam(byte offset, byte value); + // byte ReadWaveRam(byte offset); + //} + public abstract class IDMGAudioChannel { - int OutputVolume { get; } - bool IsActive { get; } - - void Reset(); - void LengthCounterClock(); - void SweepClock(); - void VolumeEnvelopeClock(); - void Step(); - - void WritePort(byte port, byte value); - byte ReadPort(byte port); - void WriteWaveRam(byte offset, byte value); - byte ReadWaveRam(byte offset); + public int OutputVolume; + public abstract bool IsActive { get; } + public abstract void Reset(); + public abstract void LengthCounterClock(); + public abstract void SweepClock(); + public abstract void VolumeEnvelopeClock(); + public abstract void Step(); + public abstract void WritePort(byte port, byte value); + public abstract byte ReadPort(byte port); + public abstract void WriteWaveRam(byte offset, byte value); + public abstract byte ReadWaveRam(byte offset); } }