summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Liam2024-02-11 19:20:41 -0500
committerGravatar Liam2024-02-11 21:59:33 -0500
commit590e86792c496366fd4811c530a20ee91f6bfa8d (patch)
treed19686fbc0bb8e9e9eae67748c857c768ed960ad /src
parentam: rewrite ISystemAppletProxy (diff)
downloadyuzu-590e86792c496366fd4811c530a20ee91f6bfa8d.tar.gz
yuzu-590e86792c496366fd4811c530a20ee91f6bfa8d.tar.xz
yuzu-590e86792c496366fd4811c530a20ee91f6bfa8d.zip
am: rewrite IAudioController
Diffstat (limited to 'src')
-rw-r--r--src/core/CMakeLists.txt4
-rw-r--r--src/core/hle/service/am/audio_controller.cpp91
-rw-r--r--src/core/hle/service/am/audio_controller.h36
-rw-r--r--src/core/hle/service/am/service/application_proxy.cpp2
-rw-r--r--src/core/hle/service/am/service/audio_controller.cpp69
-rw-r--r--src/core/hle/service/am/service/audio_controller.h37
-rw-r--r--src/core/hle/service/am/service/library_applet_proxy.cpp2
-rw-r--r--src/core/hle/service/am/service/system_applet_proxy.cpp2
8 files changed, 111 insertions, 132 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index 4486a355c..8e4928e08 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -429,8 +429,6 @@ add_library(core STATIC
429 hle/service/am/application_creator.h 429 hle/service/am/application_creator.h
430 hle/service/am/application_functions.cpp 430 hle/service/am/application_functions.cpp
431 hle/service/am/application_functions.h 431 hle/service/am/application_functions.h
432 hle/service/am/audio_controller.cpp
433 hle/service/am/audio_controller.h
434 hle/service/am/common_state_getter.cpp 432 hle/service/am/common_state_getter.cpp
435 hle/service/am/common_state_getter.h 433 hle/service/am/common_state_getter.h
436 hle/service/am/debug_functions.cpp 434 hle/service/am/debug_functions.cpp
@@ -471,6 +469,8 @@ add_library(core STATIC
471 hle/service/am/service/application_proxy_service.h 469 hle/service/am/service/application_proxy_service.h
472 hle/service/am/service/application_proxy.cpp 470 hle/service/am/service/application_proxy.cpp
473 hle/service/am/service/application_proxy.h 471 hle/service/am/service/application_proxy.h
472 hle/service/am/service/audio_controller.cpp
473 hle/service/am/service/audio_controller.h
474 hle/service/am/service/library_applet_proxy.cpp 474 hle/service/am/service/library_applet_proxy.cpp
475 hle/service/am/service/library_applet_proxy.h 475 hle/service/am/service/library_applet_proxy.h
476 hle/service/am/service/system_applet_proxy.cpp 476 hle/service/am/service/system_applet_proxy.cpp
diff --git a/src/core/hle/service/am/audio_controller.cpp b/src/core/hle/service/am/audio_controller.cpp
deleted file mode 100644
index ae75db174..000000000
--- a/src/core/hle/service/am/audio_controller.cpp
+++ /dev/null
@@ -1,91 +0,0 @@
1// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#include "core/hle/service/am/audio_controller.h"
5#include "core/hle/service/ipc_helpers.h"
6
7namespace Service::AM {
8
9IAudioController::IAudioController(Core::System& system_)
10 : ServiceFramework{system_, "IAudioController"} {
11 // clang-format off
12 static const FunctionInfo functions[] = {
13 {0, &IAudioController::SetExpectedMasterVolume, "SetExpectedMasterVolume"},
14 {1, &IAudioController::GetMainAppletExpectedMasterVolume, "GetMainAppletExpectedMasterVolume"},
15 {2, &IAudioController::GetLibraryAppletExpectedMasterVolume, "GetLibraryAppletExpectedMasterVolume"},
16 {3, &IAudioController::ChangeMainAppletMasterVolume, "ChangeMainAppletMasterVolume"},
17 {4, &IAudioController::SetTransparentAudioRate, "SetTransparentVolumeRate"},
18 };
19 // clang-format on
20
21 RegisterHandlers(functions);
22}
23
24IAudioController::~IAudioController() = default;
25
26void IAudioController::SetExpectedMasterVolume(HLERequestContext& ctx) {
27 IPC::RequestParser rp{ctx};
28 const float main_applet_volume_tmp = rp.Pop<float>();
29 const float library_applet_volume_tmp = rp.Pop<float>();
30
31 LOG_DEBUG(Service_AM, "called. main_applet_volume={}, library_applet_volume={}",
32 main_applet_volume_tmp, library_applet_volume_tmp);
33
34 // Ensure the volume values remain within the 0-100% range
35 main_applet_volume = std::clamp(main_applet_volume_tmp, min_allowed_volume, max_allowed_volume);
36 library_applet_volume =
37 std::clamp(library_applet_volume_tmp, min_allowed_volume, max_allowed_volume);
38
39 IPC::ResponseBuilder rb{ctx, 2};
40 rb.Push(ResultSuccess);
41}
42
43void IAudioController::GetMainAppletExpectedMasterVolume(HLERequestContext& ctx) {
44 LOG_DEBUG(Service_AM, "called. main_applet_volume={}", main_applet_volume);
45 IPC::ResponseBuilder rb{ctx, 3};
46 rb.Push(ResultSuccess);
47 rb.Push(main_applet_volume);
48}
49
50void IAudioController::GetLibraryAppletExpectedMasterVolume(HLERequestContext& ctx) {
51 LOG_DEBUG(Service_AM, "called. library_applet_volume={}", library_applet_volume);
52 IPC::ResponseBuilder rb{ctx, 3};
53 rb.Push(ResultSuccess);
54 rb.Push(library_applet_volume);
55}
56
57void IAudioController::ChangeMainAppletMasterVolume(HLERequestContext& ctx) {
58 struct Parameters {
59 float volume;
60 s64 fade_time_ns;
61 };
62 static_assert(sizeof(Parameters) == 16);
63
64 IPC::RequestParser rp{ctx};
65 const auto parameters = rp.PopRaw<Parameters>();
66
67 LOG_DEBUG(Service_AM, "called. volume={}, fade_time_ns={}", parameters.volume,
68 parameters.fade_time_ns);
69
70 main_applet_volume = std::clamp(parameters.volume, min_allowed_volume, max_allowed_volume);
71 fade_time_ns = std::chrono::nanoseconds{parameters.fade_time_ns};
72
73 IPC::ResponseBuilder rb{ctx, 2};
74 rb.Push(ResultSuccess);
75}
76
77void IAudioController::SetTransparentAudioRate(HLERequestContext& ctx) {
78 IPC::RequestParser rp{ctx};
79 const float transparent_volume_rate_tmp = rp.Pop<float>();
80
81 LOG_DEBUG(Service_AM, "called. transparent_volume_rate={}", transparent_volume_rate_tmp);
82
83 // Clamp volume range to 0-100%.
84 transparent_volume_rate =
85 std::clamp(transparent_volume_rate_tmp, min_allowed_volume, max_allowed_volume);
86
87 IPC::ResponseBuilder rb{ctx, 2};
88 rb.Push(ResultSuccess);
89}
90
91} // namespace Service::AM
diff --git a/src/core/hle/service/am/audio_controller.h b/src/core/hle/service/am/audio_controller.h
deleted file mode 100644
index a47e3bad8..000000000
--- a/src/core/hle/service/am/audio_controller.h
+++ /dev/null
@@ -1,36 +0,0 @@
1// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#pragma once
5
6#include "core/hle/service/service.h"
7
8namespace Service::AM {
9
10class IAudioController final : public ServiceFramework<IAudioController> {
11public:
12 explicit IAudioController(Core::System& system_);
13 ~IAudioController() override;
14
15private:
16 void SetExpectedMasterVolume(HLERequestContext& ctx);
17 void GetMainAppletExpectedMasterVolume(HLERequestContext& ctx);
18 void GetLibraryAppletExpectedMasterVolume(HLERequestContext& ctx);
19 void ChangeMainAppletMasterVolume(HLERequestContext& ctx);
20 void SetTransparentAudioRate(HLERequestContext& ctx);
21
22 static constexpr float min_allowed_volume = 0.0f;
23 static constexpr float max_allowed_volume = 1.0f;
24
25 float main_applet_volume{0.25f};
26 float library_applet_volume{max_allowed_volume};
27 float transparent_volume_rate{min_allowed_volume};
28
29 // Volume transition fade time in nanoseconds.
30 // e.g. If the main applet volume was 0% and was changed to 50%
31 // with a fade of 50ns, then over the course of 50ns,
32 // the volume will gradually fade up to 50%
33 std::chrono::nanoseconds fade_time_ns{0};
34};
35
36} // namespace Service::AM
diff --git a/src/core/hle/service/am/service/application_proxy.cpp b/src/core/hle/service/am/service/application_proxy.cpp
index d1f87709e..d28321a4a 100644
--- a/src/core/hle/service/am/service/application_proxy.cpp
+++ b/src/core/hle/service/am/service/application_proxy.cpp
@@ -3,7 +3,6 @@
3 3
4#include "core/hle/service/am/applet_common_functions.h" 4#include "core/hle/service/am/applet_common_functions.h"
5#include "core/hle/service/am/application_functions.h" 5#include "core/hle/service/am/application_functions.h"
6#include "core/hle/service/am/audio_controller.h"
7#include "core/hle/service/am/common_state_getter.h" 6#include "core/hle/service/am/common_state_getter.h"
8#include "core/hle/service/am/debug_functions.h" 7#include "core/hle/service/am/debug_functions.h"
9#include "core/hle/service/am/display_controller.h" 8#include "core/hle/service/am/display_controller.h"
@@ -12,6 +11,7 @@
12#include "core/hle/service/am/process_winding_controller.h" 11#include "core/hle/service/am/process_winding_controller.h"
13#include "core/hle/service/am/self_controller.h" 12#include "core/hle/service/am/self_controller.h"
14#include "core/hle/service/am/service/application_proxy.h" 13#include "core/hle/service/am/service/application_proxy.h"
14#include "core/hle/service/am/service/audio_controller.h"
15#include "core/hle/service/am/window_controller.h" 15#include "core/hle/service/am/window_controller.h"
16#include "core/hle/service/cmif_serialization.h" 16#include "core/hle/service/cmif_serialization.h"
17 17
diff --git a/src/core/hle/service/am/service/audio_controller.cpp b/src/core/hle/service/am/service/audio_controller.cpp
new file mode 100644
index 000000000..ad731c7bd
--- /dev/null
+++ b/src/core/hle/service/am/service/audio_controller.cpp
@@ -0,0 +1,69 @@
1// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#include "core/hle/service/am/service/audio_controller.h"
5#include "core/hle/service/cmif_serialization.h"
6
7namespace Service::AM {
8
9IAudioController::IAudioController(Core::System& system_)
10 : ServiceFramework{system_, "IAudioController"} {
11 // clang-format off
12 static const FunctionInfo functions[] = {
13 {0, D<&IAudioController::SetExpectedMasterVolume>, "SetExpectedMasterVolume"},
14 {1, D<&IAudioController::GetMainAppletExpectedMasterVolume>, "GetMainAppletExpectedMasterVolume"},
15 {2, D<&IAudioController::GetLibraryAppletExpectedMasterVolume>, "GetLibraryAppletExpectedMasterVolume"},
16 {3, D<&IAudioController::ChangeMainAppletMasterVolume>, "ChangeMainAppletMasterVolume"},
17 {4, D<&IAudioController::SetTransparentVolumeRate>, "SetTransparentVolumeRate"},
18 };
19 // clang-format on
20
21 RegisterHandlers(functions);
22}
23
24IAudioController::~IAudioController() = default;
25
26Result IAudioController::SetExpectedMasterVolume(f32 main_applet_volume,
27 f32 library_applet_volume) {
28 LOG_DEBUG(Service_AM, "called. main_applet_volume={}, library_applet_volume={}",
29 main_applet_volume, library_applet_volume);
30
31 // Ensure the volume values remain within the 0-100% range
32 m_main_applet_volume = std::clamp(main_applet_volume, MinAllowedVolume, MaxAllowedVolume);
33 m_library_applet_volume = std::clamp(library_applet_volume, MinAllowedVolume, MaxAllowedVolume);
34
35 R_SUCCEED();
36}
37
38Result IAudioController::GetMainAppletExpectedMasterVolume(Out<f32> out_main_applet_volume) {
39 LOG_DEBUG(Service_AM, "called. main_applet_volume={}", m_main_applet_volume);
40 *out_main_applet_volume = m_main_applet_volume;
41 R_SUCCEED();
42}
43
44Result IAudioController::GetLibraryAppletExpectedMasterVolume(Out<f32> out_library_applet_volume) {
45 LOG_DEBUG(Service_AM, "called. library_applet_volume={}", m_library_applet_volume);
46 *out_library_applet_volume = m_library_applet_volume;
47 R_SUCCEED();
48}
49
50Result IAudioController::ChangeMainAppletMasterVolume(f32 volume, s64 fade_time_ns) {
51 LOG_DEBUG(Service_AM, "called. volume={}, fade_time_ns={}", volume, fade_time_ns);
52
53 m_main_applet_volume = std::clamp(volume, MinAllowedVolume, MaxAllowedVolume);
54 m_fade_time_ns = std::chrono::nanoseconds{fade_time_ns};
55
56 R_SUCCEED();
57}
58
59Result IAudioController::SetTransparentVolumeRate(f32 transparent_volume_rate) {
60 LOG_DEBUG(Service_AM, "called. transparent_volume_rate={}", transparent_volume_rate);
61
62 // Clamp volume range to 0-100%.
63 m_transparent_volume_rate =
64 std::clamp(transparent_volume_rate, MinAllowedVolume, MaxAllowedVolume);
65
66 R_SUCCEED();
67}
68
69} // namespace Service::AM
diff --git a/src/core/hle/service/am/service/audio_controller.h b/src/core/hle/service/am/service/audio_controller.h
new file mode 100644
index 000000000..4b0f3f9ae
--- /dev/null
+++ b/src/core/hle/service/am/service/audio_controller.h
@@ -0,0 +1,37 @@
1// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#pragma once
5
6#include "core/hle/service/cmif_types.h"
7#include "core/hle/service/service.h"
8
9namespace Service::AM {
10
11class IAudioController final : public ServiceFramework<IAudioController> {
12public:
13 explicit IAudioController(Core::System& system_);
14 ~IAudioController() override;
15
16private:
17 Result SetExpectedMasterVolume(f32 main_applet_volume, f32 library_applet_volume);
18 Result GetMainAppletExpectedMasterVolume(Out<f32> out_main_applet_volume);
19 Result GetLibraryAppletExpectedMasterVolume(Out<f32> out_library_applet_volume);
20 Result ChangeMainAppletMasterVolume(f32 volume, s64 fade_time_ns);
21 Result SetTransparentVolumeRate(f32 transparent_volume_rate);
22
23 static constexpr float MinAllowedVolume = 0.0f;
24 static constexpr float MaxAllowedVolume = 1.0f;
25
26 float m_main_applet_volume{0.25f};
27 float m_library_applet_volume{MaxAllowedVolume};
28 float m_transparent_volume_rate{MinAllowedVolume};
29
30 // Volume transition fade time in nanoseconds.
31 // e.g. If the main applet volume was 0% and was changed to 50%
32 // with a fade of 50ns, then over the course of 50ns,
33 // the volume will gradually fade up to 50%
34 std::chrono::nanoseconds m_fade_time_ns{0};
35};
36
37} // namespace Service::AM
diff --git a/src/core/hle/service/am/service/library_applet_proxy.cpp b/src/core/hle/service/am/service/library_applet_proxy.cpp
index 9a0d363ac..dd0f8ff11 100644
--- a/src/core/hle/service/am/service/library_applet_proxy.cpp
+++ b/src/core/hle/service/am/service/library_applet_proxy.cpp
@@ -2,7 +2,6 @@
2// SPDX-License-Identifier: GPL-2.0-or-later 2// SPDX-License-Identifier: GPL-2.0-or-later
3 3
4#include "core/hle/service/am/applet_common_functions.h" 4#include "core/hle/service/am/applet_common_functions.h"
5#include "core/hle/service/am/audio_controller.h"
6#include "core/hle/service/am/common_state_getter.h" 5#include "core/hle/service/am/common_state_getter.h"
7#include "core/hle/service/am/debug_functions.h" 6#include "core/hle/service/am/debug_functions.h"
8#include "core/hle/service/am/display_controller.h" 7#include "core/hle/service/am/display_controller.h"
@@ -12,6 +11,7 @@
12#include "core/hle/service/am/library_applet_self_accessor.h" 11#include "core/hle/service/am/library_applet_self_accessor.h"
13#include "core/hle/service/am/process_winding_controller.h" 12#include "core/hle/service/am/process_winding_controller.h"
14#include "core/hle/service/am/self_controller.h" 13#include "core/hle/service/am/self_controller.h"
14#include "core/hle/service/am/service/audio_controller.h"
15#include "core/hle/service/am/service/library_applet_proxy.h" 15#include "core/hle/service/am/service/library_applet_proxy.h"
16#include "core/hle/service/am/window_controller.h" 16#include "core/hle/service/am/window_controller.h"
17#include "core/hle/service/cmif_serialization.h" 17#include "core/hle/service/cmif_serialization.h"
diff --git a/src/core/hle/service/am/service/system_applet_proxy.cpp b/src/core/hle/service/am/service/system_applet_proxy.cpp
index 0a69d1502..cc1f83fef 100644
--- a/src/core/hle/service/am/service/system_applet_proxy.cpp
+++ b/src/core/hle/service/am/service/system_applet_proxy.cpp
@@ -3,7 +3,6 @@
3 3
4#include "core/hle/service/am/applet_common_functions.h" 4#include "core/hle/service/am/applet_common_functions.h"
5#include "core/hle/service/am/application_creator.h" 5#include "core/hle/service/am/application_creator.h"
6#include "core/hle/service/am/audio_controller.h"
7#include "core/hle/service/am/common_state_getter.h" 6#include "core/hle/service/am/common_state_getter.h"
8#include "core/hle/service/am/debug_functions.h" 7#include "core/hle/service/am/debug_functions.h"
9#include "core/hle/service/am/display_controller.h" 8#include "core/hle/service/am/display_controller.h"
@@ -13,6 +12,7 @@
13#include "core/hle/service/am/library_applet_self_accessor.h" 12#include "core/hle/service/am/library_applet_self_accessor.h"
14#include "core/hle/service/am/process_winding_controller.h" 13#include "core/hle/service/am/process_winding_controller.h"
15#include "core/hle/service/am/self_controller.h" 14#include "core/hle/service/am/self_controller.h"
15#include "core/hle/service/am/service/audio_controller.h"
16#include "core/hle/service/am/service/system_applet_proxy.h" 16#include "core/hle/service/am/service/system_applet_proxy.h"
17#include "core/hle/service/am/window_controller.h" 17#include "core/hle/service/am/window_controller.h"
18#include "core/hle/service/cmif_serialization.h" 18#include "core/hle/service/cmif_serialization.h"