diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/SoundOuput/AY38912.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/SoundOuput/AY38912.cs index f003ddd6f2..62c3d7829b 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/SoundOuput/AY38912.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/SoundOuput/AY38912.cs @@ -2,8 +2,6 @@ using BizHawk.Common; using BizHawk.Emulation.Common; using System; -using System.Collections.Generic; -using System.Linq; namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum { @@ -69,9 +67,6 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum public void UpdateSound(int currentFrameCycle) { - //if (currentFrameCycle >= _tStatesPerFrame) - //currentFrameCycle = _tStatesPerFrame; - for (int i = 0; i < (currentFrameCycle / AY_SAMPLE_RATE) - _AYCount; i++) { Update(); @@ -113,11 +108,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum // the stereo _samples buffer should already have been processed as a part of // ISoundProvider at the end of the last frame - //_samples = new short[_samplesPerFrame * 2]; - //_nsamp = _samplesPerFrame; _sampleCounter = 0; - - //Init(44100, _tStatesPerFrame); } public void EndFrame() @@ -447,15 +438,25 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum private void EndSampleAY() { - averagedChannelSamples[0] = (short)((averagedChannelSamples[ChannelLeft] + averagedChannelSamples[ChannelCenter]) / soundSampleCounter); - averagedChannelSamples[1] = (short)((averagedChannelSamples[ChannelRight] + averagedChannelSamples[ChannelCenter]) / soundSampleCounter); + //averagedChannelSamples[0] = (short)((averagedChannelSamples[ChannelLeft] + + // averagedChannelSamples[ChannelCenter] + + // averagedChannelSamples[ChannelRight]) + // / soundSampleCounter); + + // averagedChannelSamples[1] = (short)((averagedChannelSamples[ChannelLeft] + + // averagedChannelSamples[ChannelCenter] + + // averagedChannelSamples[ChannelRight]) + // / soundSampleCounter); + + averagedChannelSamples[0] = (short)((averagedChannelSamples[ChannelLeft] + averagedChannelSamples[ChannelCenter] / 1.5) / soundSampleCounter); + averagedChannelSamples[1] = (short)((averagedChannelSamples[ChannelRight] + averagedChannelSamples[ChannelCenter] / 1.5) / soundSampleCounter); soundSampleCounter = 0; } private void SampleAY() { - int ah; + int ah; ah = regs[AY_ENABLE]; diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/SoundOuput/Buzzer.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/SoundOuput/Buzzer.cs index 0e98c67c29..667fe519be 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/SoundOuput/Buzzer.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Hardware/SoundOuput/Buzzer.cs @@ -236,7 +236,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum if (_tapeMode) samples[sampleIndex++] = pulse.State ? (short)(short.MaxValue / 6) : (short)0; else - samples[sampleIndex++] = pulse.State ? (short)(short.MaxValue / 2) : (short)0; + samples[sampleIndex++] = pulse.State ? (short)(short.MaxValue / 3) : (short)0; } currentEnd += pulse.Length; diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.cs index 258af9f579..bc4f9952bf 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.cs @@ -146,7 +146,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum PollInput(); - while (CurrentFrameCycle < ULADevice.FrameLength) // UlaFrameCycleCount) + while (CurrentFrameCycle < ULADevice.FrameLength) { // check for interrupt ULADevice.CheckForInterrupt(CurrentFrameCycle); @@ -157,8 +157,10 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum // update AY if (_renderSound) { - if (AYDevice != null) - AYDevice.UpdateSound(CurrentFrameCycle); + if (AYDevice != null && CPU.RegPC != 1523) + { + AYDevice.UpdateSound(CurrentFrameCycle); + } } } diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/SoundProviderMixer.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/SoundProviderMixer.cs index 1b2e37b835..303eda38b7 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/SoundProviderMixer.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/SoundProviderMixer.cs @@ -45,6 +45,22 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum EqualizeVolumes(); } + public SoundProviderMixer(short maxVolume, params ISoundProvider[] soundProviders) + { + SoundProviders = new List(); + + foreach (var s in soundProviders) + { + SoundProviders.Add(new Provider + { + SoundProvider = s, + MaxVolume = maxVolume, + }); + } + + EqualizeVolumes(); + } + public void AddSource(ISoundProvider source) { SoundProviders.Add(new Provider @@ -56,6 +72,17 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum EqualizeVolumes(); } + public void AddSource(ISoundProvider source, short maxVolume) + { + SoundProviders.Add(new Provider + { + SoundProvider = source, + MaxVolume = maxVolume + }); + + EqualizeVolumes(); + } + public void DisableSource(ISoundProvider source) { var sp = SoundProviders.Where(a => a.SoundProvider == source); diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.cs index cb294a8146..edab502824 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.cs @@ -99,7 +99,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum ser.Register(_cpu); ser.Register(_machine.ULADevice); - SoundMixer = new SoundProviderMixer((ISoundProvider)_machine.BuzzerDevice); + SoundMixer = new SoundProviderMixer((int)(32767 / 10), (ISoundProvider)_machine.BuzzerDevice); if (_machine.AYDevice != null) SoundMixer.AddSource(_machine.AYDevice);