From 9db68e7d3928f93d2ab2c7ffa1d5e248394b6fa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20L=C3=B3pez=20Guimaraes?= Date: Wed, 31 Jul 2024 01:31:14 +0100 Subject: [PATCH] cellMic: Handle value 0 on CELLMIC_DEVATTR_CHANVOL If arg1 is zero, all channels of the device are affected. --- rpcs3/Emu/Cell/Modules/cellMic.cpp | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/rpcs3/Emu/Cell/Modules/cellMic.cpp b/rpcs3/Emu/Cell/Modules/cellMic.cpp index dd36e32933..da4fa5930f 100644 --- a/rpcs3/Emu/Cell/Modules/cellMic.cpp +++ b/rpcs3/Emu/Cell/Modules/cellMic.cpp @@ -8,6 +8,8 @@ #include #include +#include + LOG_CHANNEL(cellMic); template<> @@ -863,9 +865,19 @@ error_code cellMicGetDeviceAttr(s32 dev_num, CellMicDeviceAttr deviceAttributes, switch (deviceAttributes) { case CELLMIC_DEVATTR_CHANVOL: - if (*arg1 == 0 || *arg1 > 2 || !arg2) + if (*arg1 > 2 || !arg2) return CELL_MICIN_ERROR_PARAM; - *arg2 = ::at32(device.attr_chanvol, *arg1 - 1); + + if (*arg1 == 0) + { + // Calculate average volume of the channels + *arg2 = std::accumulate(device.attr_chanvol.begin(), device.attr_chanvol.end(), 0) / device.attr_chanvol.size(); + } + else + { + *arg2 = ::at32(device.attr_chanvol, *arg1 - 1); + } + break; case CELLMIC_DEVATTR_LED: *arg1 = device.attr_led; break; case CELLMIC_DEVATTR_GAIN: *arg1 = device.attr_gain; break; @@ -897,9 +909,18 @@ error_code cellMicSetDeviceAttr(s32 dev_num, CellMicDeviceAttr deviceAttributes, { case CELLMIC_DEVATTR_CHANVOL: // Used by SingStar to set the volume of each mic - if (arg1 == 0 || arg1 > 2) + if (arg1 > 2) return CELL_MICIN_ERROR_PARAM; - ::at32(device.attr_chanvol, arg1 - 1) = arg2; + + if (arg1 == 0) + { + device.attr_chanvol.fill(arg2); + } + else + { + ::at32(device.attr_chanvol, arg1 - 1) = arg2; + } + break; case CELLMIC_DEVATTR_LED: device.attr_led = arg1; break; case CELLMIC_DEVATTR_GAIN: device.attr_gain = arg1; break;