diff options
Diffstat (limited to '')
| -rw-r--r-- | src/core/hle/service/am/am.cpp | 70 | ||||
| -rw-r--r-- | src/core/hle/service/am/am.h | 16 |
2 files changed, 73 insertions, 13 deletions
diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index 3f009d2b7..c750d70ac 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp | |||
| @@ -2,10 +2,10 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <algorithm> | ||
| 5 | #include <array> | 6 | #include <array> |
| 6 | #include <cinttypes> | 7 | #include <cinttypes> |
| 7 | #include <cstring> | 8 | #include <cstring> |
| 8 | #include <stack> | ||
| 9 | #include "audio_core/audio_renderer.h" | 9 | #include "audio_core/audio_renderer.h" |
| 10 | #include "core/core.h" | 10 | #include "core/core.h" |
| 11 | #include "core/file_sys/savedata_factory.h" | 11 | #include "core/file_sys/savedata_factory.h" |
| @@ -93,38 +93,84 @@ void IWindowController::AcquireForegroundRights(Kernel::HLERequestContext& ctx) | |||
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | IAudioController::IAudioController() : ServiceFramework("IAudioController") { | 95 | IAudioController::IAudioController() : ServiceFramework("IAudioController") { |
| 96 | // clang-format off | ||
| 96 | static const FunctionInfo functions[] = { | 97 | static const FunctionInfo functions[] = { |
| 97 | {0, &IAudioController::SetExpectedMasterVolume, "SetExpectedMasterVolume"}, | 98 | {0, &IAudioController::SetExpectedMasterVolume, "SetExpectedMasterVolume"}, |
| 98 | {1, &IAudioController::GetMainAppletExpectedMasterVolume, | 99 | {1, &IAudioController::GetMainAppletExpectedMasterVolume, "GetMainAppletExpectedMasterVolume"}, |
| 99 | "GetMainAppletExpectedMasterVolume"}, | 100 | {2, &IAudioController::GetLibraryAppletExpectedMasterVolume, "GetLibraryAppletExpectedMasterVolume"}, |
| 100 | {2, &IAudioController::GetLibraryAppletExpectedMasterVolume, | 101 | {3, &IAudioController::ChangeMainAppletMasterVolume, "ChangeMainAppletMasterVolume"}, |
| 101 | "GetLibraryAppletExpectedMasterVolume"}, | 102 | {4, &IAudioController::SetTransparentAudioRate, "SetTransparentVolumeRate"}, |
| 102 | {3, nullptr, "ChangeMainAppletMasterVolume"}, | ||
| 103 | {4, nullptr, "SetTransparentVolumeRate"}, | ||
| 104 | }; | 103 | }; |
| 104 | // clang-format on | ||
| 105 | |||
| 105 | RegisterHandlers(functions); | 106 | RegisterHandlers(functions); |
| 106 | } | 107 | } |
| 107 | 108 | ||
| 108 | IAudioController::~IAudioController() = default; | 109 | IAudioController::~IAudioController() = default; |
| 109 | 110 | ||
| 110 | void IAudioController::SetExpectedMasterVolume(Kernel::HLERequestContext& ctx) { | 111 | void IAudioController::SetExpectedMasterVolume(Kernel::HLERequestContext& ctx) { |
| 111 | LOG_WARNING(Service_AM, "(STUBBED) called"); | 112 | IPC::RequestParser rp{ctx}; |
| 113 | const float main_applet_volume_tmp = rp.Pop<float>(); | ||
| 114 | const float library_applet_volume_tmp = rp.Pop<float>(); | ||
| 115 | |||
| 116 | LOG_DEBUG(Service_AM, "called. main_applet_volume={}, library_applet_volume={}", | ||
| 117 | main_applet_volume_tmp, library_applet_volume_tmp); | ||
| 118 | |||
| 119 | // Ensure the volume values remain within the 0-100% range | ||
| 120 | main_applet_volume = std::clamp(main_applet_volume_tmp, min_allowed_volume, max_allowed_volume); | ||
| 121 | library_applet_volume = | ||
| 122 | std::clamp(library_applet_volume_tmp, min_allowed_volume, max_allowed_volume); | ||
| 123 | |||
| 112 | IPC::ResponseBuilder rb{ctx, 2}; | 124 | IPC::ResponseBuilder rb{ctx, 2}; |
| 113 | rb.Push(RESULT_SUCCESS); | 125 | rb.Push(RESULT_SUCCESS); |
| 114 | } | 126 | } |
| 115 | 127 | ||
| 116 | void IAudioController::GetMainAppletExpectedMasterVolume(Kernel::HLERequestContext& ctx) { | 128 | void IAudioController::GetMainAppletExpectedMasterVolume(Kernel::HLERequestContext& ctx) { |
| 117 | LOG_WARNING(Service_AM, "(STUBBED) called"); | 129 | LOG_DEBUG(Service_AM, "called. main_applet_volume={}", main_applet_volume); |
| 118 | IPC::ResponseBuilder rb{ctx, 3}; | 130 | IPC::ResponseBuilder rb{ctx, 3}; |
| 119 | rb.Push(RESULT_SUCCESS); | 131 | rb.Push(RESULT_SUCCESS); |
| 120 | rb.Push(volume); | 132 | rb.Push(main_applet_volume); |
| 121 | } | 133 | } |
| 122 | 134 | ||
| 123 | void IAudioController::GetLibraryAppletExpectedMasterVolume(Kernel::HLERequestContext& ctx) { | 135 | void IAudioController::GetLibraryAppletExpectedMasterVolume(Kernel::HLERequestContext& ctx) { |
| 124 | LOG_WARNING(Service_AM, "(STUBBED) called"); | 136 | LOG_DEBUG(Service_AM, "called. library_applet_volume={}", library_applet_volume); |
| 125 | IPC::ResponseBuilder rb{ctx, 3}; | 137 | IPC::ResponseBuilder rb{ctx, 3}; |
| 126 | rb.Push(RESULT_SUCCESS); | 138 | rb.Push(RESULT_SUCCESS); |
| 127 | rb.Push(volume); | 139 | rb.Push(library_applet_volume); |
| 140 | } | ||
| 141 | |||
| 142 | void IAudioController::ChangeMainAppletMasterVolume(Kernel::HLERequestContext& ctx) { | ||
| 143 | struct Parameters { | ||
| 144 | float volume; | ||
| 145 | s64 fade_time_ns; | ||
| 146 | }; | ||
| 147 | static_assert(sizeof(Parameters) == 16); | ||
| 148 | |||
| 149 | IPC::RequestParser rp{ctx}; | ||
| 150 | const auto parameters = rp.PopRaw<Parameters>(); | ||
| 151 | |||
| 152 | LOG_DEBUG(Service_AM, "called. volume={}, fade_time_ns={}", parameters.volume, | ||
| 153 | parameters.fade_time_ns); | ||
| 154 | |||
| 155 | main_applet_volume = std::clamp(parameters.volume, min_allowed_volume, max_allowed_volume); | ||
| 156 | fade_time_ns = std::chrono::nanoseconds{parameters.fade_time_ns}; | ||
| 157 | |||
| 158 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 159 | rb.Push(RESULT_SUCCESS); | ||
| 160 | } | ||
| 161 | |||
| 162 | void IAudioController::SetTransparentAudioRate(Kernel::HLERequestContext& ctx) { | ||
| 163 | IPC::RequestParser rp{ctx}; | ||
| 164 | const float transparent_volume_rate_tmp = rp.Pop<float>(); | ||
| 165 | |||
| 166 | LOG_DEBUG(Service_AM, "called. transparent_volume_rate={}", transparent_volume_rate_tmp); | ||
| 167 | |||
| 168 | // Clamp volume range to 0-100%. | ||
| 169 | transparent_volume_rate = | ||
| 170 | std::clamp(transparent_volume_rate_tmp, min_allowed_volume, max_allowed_volume); | ||
| 171 | |||
| 172 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 173 | rb.Push(RESULT_SUCCESS); | ||
| 128 | } | 174 | } |
| 129 | 175 | ||
| 130 | IDisplayController::IDisplayController() : ServiceFramework("IDisplayController") { | 176 | IDisplayController::IDisplayController() : ServiceFramework("IDisplayController") { |
diff --git a/src/core/hle/service/am/am.h b/src/core/hle/service/am/am.h index b6113cfdd..565dd8e9e 100644 --- a/src/core/hle/service/am/am.h +++ b/src/core/hle/service/am/am.h | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <chrono> | ||
| 7 | #include <memory> | 8 | #include <memory> |
| 8 | #include <queue> | 9 | #include <queue> |
| 9 | #include "core/hle/kernel/writable_event.h" | 10 | #include "core/hle/kernel/writable_event.h" |
| @@ -81,8 +82,21 @@ private: | |||
| 81 | void SetExpectedMasterVolume(Kernel::HLERequestContext& ctx); | 82 | void SetExpectedMasterVolume(Kernel::HLERequestContext& ctx); |
| 82 | void GetMainAppletExpectedMasterVolume(Kernel::HLERequestContext& ctx); | 83 | void GetMainAppletExpectedMasterVolume(Kernel::HLERequestContext& ctx); |
| 83 | void GetLibraryAppletExpectedMasterVolume(Kernel::HLERequestContext& ctx); | 84 | void GetLibraryAppletExpectedMasterVolume(Kernel::HLERequestContext& ctx); |
| 85 | void ChangeMainAppletMasterVolume(Kernel::HLERequestContext& ctx); | ||
| 86 | void SetTransparentAudioRate(Kernel::HLERequestContext& ctx); | ||
| 84 | 87 | ||
| 85 | u32 volume{100}; | 88 | static constexpr float min_allowed_volume = 0.0f; |
| 89 | static constexpr float max_allowed_volume = 1.0f; | ||
| 90 | |||
| 91 | float main_applet_volume{0.25f}; | ||
| 92 | float library_applet_volume{max_allowed_volume}; | ||
| 93 | float transparent_volume_rate{min_allowed_volume}; | ||
| 94 | |||
| 95 | // Volume transition fade time in nanoseconds. | ||
| 96 | // e.g. If the main applet volume was 0% and was changed to 50% | ||
| 97 | // with a fade of 50ns, then over the course of 50ns, | ||
| 98 | // the volume will gradually fade up to 50% | ||
| 99 | std::chrono::nanoseconds fade_time_ns{0}; | ||
| 86 | }; | 100 | }; |
| 87 | 101 | ||
| 88 | class IDisplayController final : public ServiceFramework<IDisplayController> { | 102 | class IDisplayController final : public ServiceFramework<IDisplayController> { |