Fix the volume calculation

This commit is contained in:
Ac_K 2019-10-01 02:28:46 +02:00
parent dd308c3494
commit 5fd2785926
5 changed files with 15 additions and 19 deletions

View file

@ -20,7 +20,7 @@ namespace Ryujinx.Audio
float GetVolume();
void SetVolume(float gain);
void SetVolume(float volume);
PlaybackState GetState(int trackId);
}

View file

@ -83,9 +83,9 @@ namespace Ryujinx.Audio
public float GetVolume() => _volume;
public void SetVolume(float gain)
public void SetVolume(float volume)
{
_volume = Math.Clamp(_volume - (_volume * gain), 0.0f, 1.0f);
_volume = volume;
}
public void Dispose()

View file

@ -272,16 +272,12 @@ namespace Ryujinx.Audio
/// <summary>
/// Set playback volume
/// </summary>
/// <param name="gain">The gain of the playback</param>
public void SetVolume(float gain)
/// <param name="volume">The volume of the playback</param>
public void SetVolume(float volume)
{
if (!_volumeChanged)
{
// Games send a gain value here, so we need to apply it on the current volume value.
// In that way we have to multiply the gain by the volume to get the real gain value.
// And then we substract the real gain value to our current volume value.
_volume = Math.Clamp(_volume - (_volume * gain), 0.0f, 1.0f);
_volume = volume;
_volumeChanged = true;
}
}

View file

@ -193,16 +193,12 @@ namespace Ryujinx.Audio
/// <summary>
/// Set playback volume
/// </summary>
/// <param name="gain">The gain of the playback</param>
public void SetVolume(float gain)
/// <param name="volume">The volume of the playback</param>
public void SetVolume(float volume)
{
if (!_volumeChanged)
{
// Games send a gain value here, so we need to apply it on the current volume value.
// In that way we have to multiply the gain by the volume to get the real gain value.
// And then we substract the real gain value to our current volume value.
_volume = Math.Clamp(_volume - (_volume * gain), 0.0f, 1.0f);
_volume = volume;
_volumeChanged = true;
}
}

View file

@ -151,9 +151,13 @@ namespace Ryujinx.HLE.HOS.Services.Audio.AudioOutManager
// SetAudioOutVolume(s32)
public ResultCode SetAudioOutVolume(ServiceCtx context)
{
float volume = context.RequestData.ReadSingle();
// Games send a gain value here, so we need to apply it on the current volume value.
_audioOut.SetVolume(volume);
float gain = context.RequestData.ReadSingle();
float currentVolume = _audioOut.GetVolume();
float newVolume = Math.Clamp(currentVolume + gain, 0.0f, 1.0f);
_audioOut.SetVolume(newVolume);
return ResultCode.Success;
}