gambatte: make overall output volume more comparable to other cores?

This commit is contained in:
nattthebear 2017-06-25 12:33:03 -04:00
parent 49d067a665
commit 13c3dafd8a
1 changed files with 116 additions and 116 deletions

View File

@ -1,116 +1,116 @@
using System; using System;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Nintendo.Gameboy namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
{ {
public partial class Gameboy : ISoundProvider public partial class Gameboy : ISoundProvider
{ {
public bool CanProvideAsync => false; public bool CanProvideAsync => false;
public void DiscardSamples() public void DiscardSamples()
{ {
_soundoutbuffcontains = 0; _soundoutbuffcontains = 0;
} }
public void GetSamplesSync(out short[] samples, out int nsamp) public void GetSamplesSync(out short[] samples, out int nsamp)
{ {
samples = _soundoutbuff; samples = _soundoutbuff;
nsamp = _soundoutbuffcontains; nsamp = _soundoutbuffcontains;
} }
public void SetSyncMode(SyncSoundMode mode) public void SetSyncMode(SyncSoundMode mode)
{ {
if (mode == SyncSoundMode.Async) if (mode == SyncSoundMode.Async)
{ {
throw new NotSupportedException("Async mode is not supported."); throw new NotSupportedException("Async mode is not supported.");
} }
} }
public SyncSoundMode SyncMode => SyncSoundMode.Sync; public SyncSoundMode SyncMode => SyncSoundMode.Sync;
public void GetSamplesAsync(short[] samples) public void GetSamplesAsync(short[] samples)
{ {
throw new InvalidOperationException("Async mode is not supported."); throw new InvalidOperationException("Async mode is not supported.");
} }
internal bool Muted => _settings.Muted; internal bool Muted => _settings.Muted;
// sample pairs before resampling // sample pairs before resampling
private readonly short[] _soundbuff = new short[(35112 + 2064) * 2]; private readonly short[] _soundbuff = new short[(35112 + 2064) * 2];
private int _soundoutbuffcontains = 0; private int _soundoutbuffcontains = 0;
private readonly short[] _soundoutbuff = new short[2048]; private readonly short[] _soundoutbuff = new short[2048];
private int _latchL = 0; private int _latchL = 0;
private int _latchR = 0; private int _latchR = 0;
private BlipBuffer _blipL, _blipR; private BlipBuffer _blipL, _blipR;
private uint _blipAccumulate; private uint _blipAccumulate;
private void ProcessSound(int nsamp) private void ProcessSound(int nsamp)
{ {
for (uint i = 0; i < nsamp; i++) for (uint i = 0; i < nsamp; i++)
{ {
int curr = _soundbuff[i * 2]; int curr = _soundbuff[i * 2];
if (curr != _latchL) if (curr != _latchL)
{ {
int diff = _latchL - curr; int diff = _latchL - curr;
_latchL = curr; _latchL = curr;
_blipL.AddDelta(_blipAccumulate, diff); _blipL.AddDelta(_blipAccumulate, diff >> 2);
} }
curr = _soundbuff[(i * 2) + 1]; curr = _soundbuff[(i * 2) + 1];
if (curr != _latchR) if (curr != _latchR)
{ {
int diff = _latchR - curr; int diff = _latchR - curr;
_latchR = curr; _latchR = curr;
_blipR.AddDelta(_blipAccumulate, diff); _blipR.AddDelta(_blipAccumulate, diff >> 2);
} }
_blipAccumulate++; _blipAccumulate++;
} }
} }
private void ProcessSoundEnd() private void ProcessSoundEnd()
{ {
_blipL.EndFrame(_blipAccumulate); _blipL.EndFrame(_blipAccumulate);
_blipR.EndFrame(_blipAccumulate); _blipR.EndFrame(_blipAccumulate);
_blipAccumulate = 0; _blipAccumulate = 0;
_soundoutbuffcontains = _blipL.SamplesAvailable(); _soundoutbuffcontains = _blipL.SamplesAvailable();
if (_soundoutbuffcontains != _blipR.SamplesAvailable()) if (_soundoutbuffcontains != _blipR.SamplesAvailable())
{ {
throw new InvalidOperationException("Audio processing error"); throw new InvalidOperationException("Audio processing error");
} }
_blipL.ReadSamplesLeft(_soundoutbuff, _soundoutbuffcontains); _blipL.ReadSamplesLeft(_soundoutbuff, _soundoutbuffcontains);
_blipR.ReadSamplesRight(_soundoutbuff, _soundoutbuffcontains); _blipR.ReadSamplesRight(_soundoutbuff, _soundoutbuffcontains);
} }
private void InitSound() private void InitSound()
{ {
_blipL = new BlipBuffer(1024); _blipL = new BlipBuffer(1024);
_blipL.SetRates(TICKSPERSECOND, 44100); _blipL.SetRates(TICKSPERSECOND, 44100);
_blipR = new BlipBuffer(1024); _blipR = new BlipBuffer(1024);
_blipR.SetRates(TICKSPERSECOND, 44100); _blipR.SetRates(TICKSPERSECOND, 44100);
} }
private void DisposeSound() private void DisposeSound()
{ {
if (_blipL != null) if (_blipL != null)
{ {
_blipL.Dispose(); _blipL.Dispose();
_blipL = null; _blipL = null;
} }
if (_blipR != null) if (_blipR != null)
{ {
_blipR.Dispose(); _blipR.Dispose();
_blipR = null; _blipR = null;
} }
} }
} }
} }