Fix the volume calculation

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

View file

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

View file

@ -83,9 +83,9 @@ namespace Ryujinx.Audio
public float GetVolume() => _volume; 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() public void Dispose()

View file

@ -272,16 +272,12 @@ namespace Ryujinx.Audio
/// <summary> /// <summary>
/// Set playback volume /// Set playback volume
/// </summary> /// </summary>
/// <param name="gain">The gain of the playback</param> /// <param name="volume">The volume of the playback</param>
public void SetVolume(float gain) public void SetVolume(float volume)
{ {
if (!_volumeChanged) if (!_volumeChanged)
{ {
// Games send a gain value here, so we need to apply it on the current volume value. _volume = volume;
// 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);
_volumeChanged = true; _volumeChanged = true;
} }
} }

View file

@ -193,16 +193,12 @@ namespace Ryujinx.Audio
/// <summary> /// <summary>
/// Set playback volume /// Set playback volume
/// </summary> /// </summary>
/// <param name="gain">The gain of the playback</param> /// <param name="volume">The volume of the playback</param>
public void SetVolume(float gain) public void SetVolume(float volume)
{ {
if (!_volumeChanged) if (!_volumeChanged)
{ {
// Games send a gain value here, so we need to apply it on the current volume value. _volume = volume;
// 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);
_volumeChanged = true; _volumeChanged = true;
} }
} }

View file

@ -151,9 +151,13 @@ namespace Ryujinx.HLE.HOS.Services.Audio.AudioOutManager
// SetAudioOutVolume(s32) // SetAudioOutVolume(s32)
public ResultCode SetAudioOutVolume(ServiceCtx context) 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; return ResultCode.Success;
} }