Xbox Cloud Gaming app for PS5 Homebrew
C
v0.9.5: Voice chat, DualSense hardware microphone integration and VU meter
Rafael Abud Ferreira07584c2d261b
diff --git a/CMakeLists.txt b/CMakeLists.txtindex 6212dd0..91fb71c 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -1,7 +1,7 @@# SPDX-License-Identifier: GPL-3.0-or-later# Copyright (C) 2026 RafaelNGPcmake_minimum_required(VERSION 3.20)-project(xcloud_ps5 VERSION 0.9.4 LANGUAGES C CXX)+project(xcloud_ps5 VERSION 0.9.5 LANGUAGES C CXX)set(CMAKE_CXX_STANDARD 20)set(CMAKE_CXX_STANDARD_REQUIRED ON)@@ -54,7 +54,7 @@ endif()# --- Media: H.264 / Opus decoding -------------------------------------------include(cmake/deps/ffmpeg.cmake)-add_library(xcloud_media STATIC src/media/decoder.cpp src/media/audio_out.cpp)+add_library(xcloud_media STATIC src/media/decoder.cpp src/media/audio_out.cpp src/media/audio_in.cpp src/media/audio_encoder.cpp)target_link_libraries(xcloud_media PUBLIC xcloud_core PRIVATE xc_ffmpeg)# --- Menus: software-rendered UI, Game Pass library ---------------------------@@ -106,6 +106,6 @@ else()enable_testing()add_executable(xcloud-tests tests/test_main.cpp)- target_link_libraries(xcloud-tests PRIVATE xcloud_stream xcloud_ui)+ target_link_libraries(xcloud-tests PRIVATE xcloud_stream xcloud_media xcloud_ui xc_ffmpeg)add_test(NAME unit COMMAND xcloud-tests)endif()diff --git a/ROADMAP.md b/ROADMAP.mdindex c230804..ac82d99 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -4,7 +4,7 @@ Where PSBox Cloud Gaming goes next, most valuable first. Each item says why itmatters, what "done" looks like, and how it is measured on the console.Status: **next** (being worked on), **planned**, **later**, **dropped**.-Last update: 2026-10-10, after v0.9.4.+Last update: 2026-10-10, after v0.9.5.## Now@@ -162,12 +162,21 @@ is rolled back at the next start), then the app restarts itself- Presence pill badge positioned in the bottom-left corner of cards in the friends row; redundant "GAME PASS" badge removed across all cards.- Solid uniform 360° Gamerscore circle rendering via `Canvas::strokeCircle(...)` and pixel-perfect centering of the `'G'` glyph.+### Voice chat & DualSense hardware microphone integration — done (v0.9.5)+- Native PS5 audio input capture (`libSceAudioIn`) bound to active user ID (`input::padUserId`) at 48 kHz mono S16.+- Physical DualSense hardware mute button integration (`sceAudioInGetSilentState`): orange LED hardware muting controls audio transmission and in-game UI state in real-time.+- Real-time in-game VU meter: rounded sound-level pill in the `StreamMenu` with perceptual scaling and studio ballistic decay (~350 ms falloff) displaying live green voice activity, matching orange mute status when muted on the controller.+- DualSense vibration suppression during mic capture (`scePadSetVibrationTriggerEffectWeakWhileEmbeddedMicInUse`) prevents motor rumble noise bleed.+- Native FFmpeg Opus voice encoder (48 kHz, 1 ch, 24 kbps, 20 ms frames) streamed via WebRTC audio packets to cloud session.+- Fixed audio output muting by locking to primary `SCE_AUDIO_OUT_PORT_TYPE_MAIN` (port 0).+- Cleaned up StreamMenu: removed obsolete manual microphone and audio routing toggles.+## Next| Item | Why | Size || --- | --- | --- |-| Voice chat (microphone) | xCloud WebRTC `chatV1` channel; requires PS5 audio capture (`libSceAudioIn`) and Opus encoding | large || USB keyboard & mouse + badges (v1.0+) | Some xCloud games accept native keyboard and mouse input; deferred to v1.0+ | medium |+| Dedicated voice chat output routing | Route voice chat audio independently to DualSense controller speaker or headset while keeping game audio on TV (if xCloud exposes separate voice track) | medium |## Dropped (and why)diff --git a/ps5/sce_sys/param.json b/ps5/sce_sys/param.jsonindex 77f1c3d..a493d86 100644--- a/ps5/sce_sys/param.json+++ b/ps5/sce_sys/param.json@@ -10,7 +10,7 @@"conceptId": "99810","contentBadgeType": 1,"contentId": "UP9000-PPSA99810_00-XCLOUDPS5CLI0000",- "contentVersion": "00.904.000",+ "contentVersion": "00.905.000","downloadDataSize": 256,"gameIntent": {"permittedIntents": [diff --git a/ps5/stubs/libSceAudioIn.c b/ps5/stubs/libSceAudioIn.cindex 2d4173c..a7f32b7 100644--- a/ps5/stubs/libSceAudioIn.c+++ b/ps5/stubs/libSceAudioIn.c@@ -20,8 +20,8 @@ int sceAudioInClose(int handle) {return -1;}-int sceAudioInGetStatus(int handle, unsigned int *status) {- (void)handle; (void)status;+int sceAudioInGetSilentState(int handle) {+ (void)handle;return -1;}diff --git a/src/app/autoplay.cpp b/src/app/autoplay.cppindex b647a5b..4dd8b43 100644--- a/src/app/autoplay.cpp+++ b/src/app/autoplay.cpp@@ -6,9 +6,11 @@#include "app/ps5_app.h"#include "display/display.h"#include "display/gpu.h"+#include "media/audio_in.h"#include "media/decoder.h"#include "platform/platform.h"#include "ui/canvas.h"+#include "ui/stream_menu.h"#include "util/log.h"#include <cmath>@@ -92,6 +94,7 @@ void loadAutoplay() {if (opt == "gamesettingstest") g_autoplay.gameSettingsTest = true;if (opt == "publishertest") g_autoplay.publisherTest = true;if (opt == "friendstest") g_autoplay.friendsTest = true;+ if (opt == "streammenutest") g_autoplay.streamMenuTest = true;if (opt == "norestart") g_autoplay.noRestart = true;if (opt.rfind("threads=", 0) == 0) g_autoplay.decodeThreads = std::atoi(opt.c_str() + 8);}@@ -648,6 +651,76 @@ void autoplayScreens(const ui::Canvas& canvas, uint64_t now) {XC_LOGI("AUTOPLAY END: friends test");}}+ if (g_autoplay.streamMenuTest && uiSaved) {+ static uint64_t since = 0;+ static int step = 0;+ if (!since) since = now;+ if (step == 0 && now - since > 2000) {+ static media::AudioIn s_audioInProbe;+ bool ok = s_audioInProbe.open([](const int16_t*, size_t){});+ XC_LOGI("AUTOPLAY: AudioIn probe open result: %s (recording: %s)",+ ok ? "SUCCESS" : "FAILED", s_audioInProbe.isRecording() ? "YES" : "NO");++ ui::StreamMenu menu(g_ui->fonts());+ menu.open(0, false, 1, 1, 0, false, true, false, 2, 15, false, 0.65f, false);+ ui::StreamInfo info;+ info.region = "East US";+ info.rttMs = 18;+ info.fps = 60.0;+ info.mbps = 14.5;+ info.lossPct = 0.0;+ info.decodeMs = 2.1;+ info.onScreenMs = 12.4;+ info.width = 1920;+ info.height = 1080;+ ui::PadSlots pads{};+ pads[0].connected = true;+ pads[0].name = "Player 1";+ menu.setPads(pads);+ ui::Canvas menuCanvas = menu.renderMenu(info);+ std::string ppm = "P6\n" + std::to_string(menuCanvas.width()) + " " + std::to_string(menuCanvas.height()) + "\n255\n";+ ppm.reserve(ppm.size() + static_cast<size_t>(menuCanvas.width() * menuCanvas.height() * 3));+ for (size_t i = 0; i < static_cast<size_t>(menuCanvas.width() * menuCanvas.height()); ++i) {+ uint32_t p = menuCanvas.data()[i];+ ppm += static_cast<char>(p & 0xFF);+ ppm += static_cast<char>((p >> 8) & 0xFF);+ ppm += static_cast<char>((p >> 16) & 0xFF);+ }+ platform::writeFileAtomic(platform::dataDir() + "/stream_menu.ppm", ppm);+ XC_LOGI("AUTOPLAY: stream_menu.ppm saved");+ ++step;+ } else if (step == 1 && now - since > 4000) {+ ui::StreamMenu menu(g_ui->fonts());+ menu.open(0, false, 1, 1, 0, false, true, false, 2, 15, false, 0.0f, true);+ ui::StreamInfo info;+ info.region = "East US";+ info.rttMs = 18;+ info.fps = 60.0;+ info.mbps = 14.5;+ info.lossPct = 0.0;+ info.decodeMs = 2.1;+ info.onScreenMs = 12.4;+ info.width = 1920;+ info.height = 1080;+ ui::PadSlots pads{};+ pads[0].connected = true;+ pads[0].name = "Player 1";+ menu.setPads(pads);+ ui::Canvas menuCanvas = menu.renderMenu(info);+ std::string ppm = "P6\n" + std::to_string(menuCanvas.width()) + " " + std::to_string(menuCanvas.height()) + "\n255\n";+ ppm.reserve(ppm.size() + static_cast<size_t>(menuCanvas.width() * menuCanvas.height() * 3));+ for (size_t i = 0; i < static_cast<size_t>(menuCanvas.width() * menuCanvas.height()); ++i) {+ uint32_t p = menuCanvas.data()[i];+ ppm += static_cast<char>(p & 0xFF);+ ppm += static_cast<char>((p >> 8) & 0xFF);+ ppm += static_cast<char>((p >> 16) & 0xFF);+ }+ platform::writeFileAtomic(platform::dataDir() + "/stream_menu_muted.ppm", ppm);+ g_autoplay.streamMenuTest = false;+ XC_LOGI("AUTOPLAY END: stream menu test");+ ++step;+ }+ }if (pickerShot) {saveCanvas(pickerShot);if (std::string(pickerShot) == "settings.ppm") XC_LOGI("AUTOPLAY END: picker test");diff --git a/src/app/autoplay.h b/src/app/autoplay.hindex 9c53249..a67a4f5 100644--- a/src/app/autoplay.h+++ b/src/app/autoplay.h@@ -75,6 +75,7 @@ struct Autoplay {bool gameSettingsTest = false; // gamesettingstest: test details and game settings modalbool publisherTest = false; // publishertest: test publisher filter dropdown and search resultsbool friendsTest = false; // friendstest: test friends playing row and card badge+ bool streamMenuTest = false; // streammenutest: render StreamMenu with mic and audio route options};extern Autoplay g_autoplay;extern std::atomic<bool> g_syntheticA; // A held down for the gamediff --git a/src/app/settings.cpp b/src/app/settings.cppindex ad15bc4..67a9177 100644--- a/src/app/settings.cpp+++ b/src/app/settings.cpp@@ -48,6 +48,9 @@ bool Settings::load(const std::string& path) {lightBarColour = 0xFF000000u | (rgb >> 16 & 0xFF) | (rgb & 0xFF00) | (rgb & 0xFF) << 16;}gestureHints = static_cast<int>((*j)["gestureHints"].asInt(gestureHints));+ micEnabled = (*j)["micEnabled"].asBool(micEnabled);+ micGain = static_cast<int>(std::clamp<int64_t>((*j)["micGain"].asInt(micGain), 0, 2));+ audioRoute = static_cast<int>(std::clamp<int64_t>((*j)["audioRoute"].asInt(audioRoute), 0, 1));skippedUpdate = (*j)["skippedUpdate"].str();maxHeightCloud = static_cast<int>((*j)["maxHeightCloud"].asInt(0));maxHeightHome = static_cast<int>((*j)["maxHeightHome"].asInt(0));@@ -148,6 +151,9 @@ bool Settings::save(const std::string& path) const {static_cast<unsigned>(lightBarColour >> 8 & 0xFF), static_cast<unsigned>(lightBarColour >> 16 & 0xFF));v.set("lightBarColour", std::string(hex));v.set("gestureHints", gestureHints);+ v.set("micEnabled", micEnabled);+ v.set("micGain", micGain);+ v.set("audioRoute", audioRoute);v.set("skippedUpdate", skippedUpdate);v.set("maxHeightCloud", maxHeightCloud);v.set("maxHeightHome", maxHeightHome);diff --git a/src/app/settings.h b/src/app/settings.hindex f0fadf3..a491adc 100644--- a/src/app/settings.h+++ b/src/app/settings.h@@ -65,6 +65,10 @@ struct Settings {int lightBarMode = 0;uint32_t lightBarColour = 0xFFDC7000; // as ui::Color: 0xAABBGGRR, opaque (blue)int gestureHints = 0;+ // Voice chat & Audio routing+ bool micEnabled = true;+ int micGain = 1; // 0: 50%, 1: 100%, 2: 150%+ int audioRoute = 0; // 0: TV/HDMI (Main), 1: DualSense Speaker / Headset (Pad)// The release the user said "Not now" to: not offered again on start.std::string skippedUpdate;// The tallest picture each kind of stream delivered when asked for itsdiff --git a/src/app/stream_player.cpp b/src/app/stream_player.cppindex 75076ef..ef39712 100644--- a/src/app/stream_player.cpp+++ b/src/app/stream_player.cpp@@ -5,6 +5,8 @@#include "display/display.h"#include "input/controller.h"#include "media/audio_out.h"+#include "media/audio_in.h"+#include "media/audio_encoder.h"#include "media/decoder.h"#include "media/hw_decoder.h"#include "platform/platform.h"@@ -99,9 +101,48 @@ struct StreamPlayer::Impl {std::deque<stream::TextInputRequest> textRequests;std::set<std::string> textWithdrawn;+ media::AudioIn audioIn;+ media::AudioEncoder audioEncoder;+ std::atomic<bool> micEnabled{true};+ std::atomic<bool> micMuted{false};+ std::atomic<float> micGain{1.0f};+ std::atomic<uint32_t> audioSendTimestamp{0};+ bool encoderInitialized = false;++ void updateMicState() {+ if (!running) return;+ if (!audioIn.isRecording()) {+ if (!encoderInitialized) {+ encoderInitialized = audioEncoder.init(24000);+ if (!encoderInitialized) {+ XC_LOGW("audio encoder: Opus init failed, mic input & meter will still operate");+ }+ }+ audioIn.setMuted(micMuted.load());+ audioIn.setGain(micGain.load());+ audioIn.open([this](const int16_t* pcmFrames, size_t samples) {+ if (!running) return;+ if (!encoderInitialized) return;+ auto s = current();+ if (!s || !s->isOpen()) return;+ std::vector<uint8_t> opus;+ if (audioEncoder.encode(pcmFrames, samples, opus)) {+ uint32_t ts = audioSendTimestamp.fetch_add(static_cast<uint32_t>(samples));+ s->sendAudio(opus.data(), opus.size(), ts);+ }+ });+ input::setEmbeddedMicActive(true);+ } else {+ audioIn.setMuted(micMuted.load());+ audioIn.setGain(micGain.load());+ }+ }+explicit Impl(xcloud::GssvClient& g) : gssv(g) {}void end(const std::string& reason) {+ audioIn.close();+ input::setEmbeddedMicActive(false);{std::lock_guard<std::mutex> lock(mutex);if (endReason.empty()) endReason = reason;@@ -408,6 +449,7 @@ struct StreamPlayer::Impl {end(err);return false;}+ updateMicState();return true;}@@ -459,6 +501,7 @@ struct StreamPlayer::Impl {std::lock_guard<std::mutex> lock(sessionMutex);session = next;}+ updateMicState();XC_LOGI("reconnected after %d attempt(s)", reconnectAttempts);reconnectAttempts = 0;silentTicks = 0;@@ -555,6 +598,8 @@ struct StreamPlayer::Impl {std::lock_guard<std::mutex> lock(sessionMutex);session.reset();}+ audioIn.close();+ input::setEmbeddedMicActive(false);media::audioStop();for (int i = 0; i < input::kMaxPads; ++i) {input::setRumble(0, 0, 0, i);@@ -714,4 +759,39 @@ StreamPlayer::Stats StreamPlayer::stats() const {return st;}+void StreamPlayer::setMicEnabled(bool enabled) {+ impl_->micEnabled = enabled;+ impl_->updateMicState();+}++bool StreamPlayer::micEnabled() const {+ return impl_->micEnabled;+}++void StreamPlayer::setMicMuted(bool muted) {+ impl_->micMuted = muted;+ impl_->audioIn.setMuted(muted);+}++bool StreamPlayer::micMuted() const {+ return impl_->micMuted;+}++bool StreamPlayer::isMicHardwareMuted() const {+ return impl_ ? impl_->audioIn.isHardwareMuted() : false;+}++void StreamPlayer::setMicGain(float gain) {+ impl_->micGain = gain;+ impl_->audioIn.setGain(gain);+}++float StreamPlayer::micGain() const {+ return impl_->micGain;+}++float StreamPlayer::micLevel() const {+ return impl_ ? impl_->audioIn.level() : 0.0f;+}+} // namespace xc::appdiff --git a/src/app/stream_player.h b/src/app/stream_player.hindex 928e038..06080de 100644--- a/src/app/stream_player.h+++ b/src/app/stream_player.h@@ -56,6 +56,15 @@ public:void dumpVideo(const std::string& path, int seconds);// Writes the next decoded picture, half size, as a binary PPM.void requestSnapshot(const std::string& path);+ // Voice chat / microphone controls+ void setMicEnabled(bool enabled);+ bool micEnabled() const;+ void setMicMuted(bool muted);+ bool micMuted() const;+ bool isMicHardwareMuted() const;+ void setMicGain(float gain);+ float micGain() const;+ float micLevel() const;struct Stats {uint64_t videoFrames = 0, decodedFrames = 0, droppedFrames = 0, audioPackets = 0;diff --git a/src/app/stream_screen.cpp b/src/app/stream_screen.cppindex c2dcb73..5bea351 100644--- a/src/app/stream_screen.cpp+++ b/src/app/stream_screen.cpp@@ -7,6 +7,7 @@#include "app/ps5_app.h"#include "app/stream_player.h"#include "display/display.h"+#include "media/audio_out.h"#include "platform/platform.h"#include "ui/strings.h"#include "util/log.h"@@ -122,6 +123,11 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, binput::setCircleConfirms(prof.circleConfirms);if (g_ui) g_ui->setCircleConfirms(prof.circleConfirms);+ media::audioSetRoute(static_cast<media::AudioRoute>(g_settings.audioRoute));+ if (g_player) {+ g_player->setMicGain(g_settings.micGain);+ }+overlaySeq_ = 0;}if (g_player) {@@ -136,9 +142,11 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, bstd::lock_guard<std::mutex> settingsLock(g_settingsMutex);allow1440 = allow1440Locked();}+ float micLvl = g_player ? g_player->micLevel() : 0.0f;+ bool micMuted = g_player ? (g_player->micMuted() || g_player->isMicHardwareMuted()) : false;menu_.setDebandInUse(autoDeband_.level());menu_.open(streamResolution_, showStats_, sharpness_, deband_, upscaler_, g_playingHome, allow1440,- hasCustomProfile_, triggerStrength_, deadzone_, circleConfirms_);+ hasCustomProfile_, triggerStrength_, deadzone_, circleConfirms_, micLvl, micMuted);overlaySeq_ = 0;} else if (wasOpen) {switch (menu_.handle(nav)) {@@ -358,14 +366,21 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, bXC_LOGI("block smoothing auto: %s at %.1f Mbps", level == 2 ? "high" : level == 1 ? "low" : "off", mbps);}}- if (overlaySeq_ != seq + 1) {+ uint64_t nowMs = platform::nowMs();+ bool menuRedraw = menu_.isOpen() && (nowMs - lastMenuRedrawMs_ >= 40);+ if (overlaySeq_ != seq + 1 || menuRedraw) {overlaySeq_ = seq + 1;+ if (menuRedraw) lastMenuRedrawMs_ = nowMs;ui::StreamInfo info;{std::lock_guard<std::mutex> infoLock(g_infoMutex);info = g_streamInfo;}if (menu_.isOpen()) {+ float micLvl = g_player ? g_player->micLevel() : 0.0f;+ bool micMuted = g_player ? (g_player->micMuted() || g_player->isMicHardwareMuted()) : false;+ menu_.setMicLevel(micLvl);+ menu_.setMicMuted(micMuted);ui::Canvas c = menu_.renderMenu(info);display::setOverlay(c.data(), ui::StreamMenu::kMenuX, ui::StreamMenu::kMenuY, c.width(), c.height(), 235);} else if (showStats_ && seq) {diff --git a/src/app/stream_screen.h b/src/app/stream_screen.hindex 857c77b..b794f77 100644--- a/src/app/stream_screen.h+++ b/src/app/stream_screen.h@@ -59,6 +59,7 @@ private:int deadzone_ = 15;bool circleConfirms_ = false;bool wasStreaming_ = false;+ uint64_t lastMenuRedrawMs_ = 0;};} // namespace xc::appdiff --git a/src/app/worker.cpp b/src/app/worker.cppindex 36a7646..2304dab 100644--- a/src/app/worker.cpp+++ b/src/app/worker.cpp@@ -10,6 +10,7 @@#include "app/update_check.h"#include "app/updater.h"#include "auth/auth_manager.h"+#include "media/audio_out.h"#include "platform/platform.h"#include "ui/strings.h"#include "util/log.h"@@ -61,6 +62,11 @@ std::string stream(xcloud::GssvClient& gssv) {if (g_autoplay.dump) player.dumpVideo(platform::dataDir() + "/stream.aus", 20);player.setDecodeThreads(g_autoplay.decodeThreads);player.setHwDecodeProbe(g_autoplay.hwDecode);+ {+ std::lock_guard<std::mutex> lock(g_settingsMutex);+ player.setMicGain(g_settings.micGain);+ media::audioSetRoute(static_cast<media::AudioRoute>(g_settings.audioRoute));+ }std::string err;if (!player.start(err)) return "ERROR: " + ui::trf(ui::Str::StreamFailed, err);{diff --git a/src/input/controller.cpp b/src/input/controller.cppindex 16a0a38..f0c863a 100644--- a/src/input/controller.cpp+++ b/src/input/controller.cpp@@ -96,6 +96,7 @@ struct ScePadColor {};int scePadSetLightBar(int32_t handle, const ScePadColor* color);int scePadResetLightBar(int32_t handle);+int scePadSetVibrationTriggerEffectWeakWhileEmbeddedMicInUse(int32_t handle, bool enable);}namespace xc::input {@@ -303,6 +304,17 @@ std::string padUserName(int index) {return index >= 0 && index < kMaxPads && g_pads[index].handle >= 0 ? g_pads[index].name : "";}+int32_t padUserId(int index) {+ if (index >= 0 && index < kMaxPads && g_pads[index].handle >= 0 && g_pads[index].userId >= 0) {+ return g_pads[index].userId;+ }+ int32_t uid = -1;+ if (sceUserServiceGetInitialUser(&uid) == 0 && uid >= 0) {+ return uid;+ }+ return -1;+}+void setTriggerFeel(int strength, int hzIndex, int resistance, bool pulses) {g_triggerStrength = std::clamp(strength, 0, kTriggerStrengths - 1);g_triggerHz = std::clamp(hzIndex, 0, 2);@@ -432,6 +444,19 @@ bool pollPad(int index, ControllerState& out) {return true;}+void setEmbeddedMicActive(bool active, int pad) {+ if (pad < 0 || pad >= kMaxPads) return;+ int32_t handle = g_pads[pad].handle;+ if (handle >= 0) {+ int rc = scePadSetVibrationTriggerEffectWeakWhileEmbeddedMicInUse(handle, active);+ if (rc < 0) {+ XC_LOGW("scePadSetVibrationTriggerEffectWeakWhileEmbeddedMicInUse: 0x%08x", static_cast<unsigned>(rc));+ } else {+ XC_LOGI("pad %d embedded mic vibration suppression: %s", pad, active ? "enabled" : "disabled");+ }+ }+}+} // namespace xc::input#else@@ -456,9 +481,11 @@ void setLightBar(uint8_t, uint8_t, uint8_t, int) {}void resetLightBar(int) {}bool padConnected(int index) { return index == 0; }std::string padUserName(int index) { return index == 0 ? "Player" : ""; }+int32_t padUserId(int) { return 0; }void setTriggerFeel(int, int, int, bool) {}void setTriggerLogging(bool) {}void setTriggerResistanceActive(bool) {}+void setEmbeddedMicActive(bool, int) {}} // namespace xc::input#endifdiff --git a/src/input/controller.h b/src/input/controller.hindex f7cfe22..9d06eea 100644--- a/src/input/controller.h+++ b/src/input/controller.h@@ -64,6 +64,7 @@ void refreshPads();// (empty when the slot is free).bool padConnected(int index);std::string padUserName(int index);+int32_t padUserId(int index = 0);// Rumble, 0..255 per motor (large = low frequency, small = high frequency),// for `durationMs` (0 = until changed). Any thread; polling applies it.void setRumble(uint8_t large, uint8_t small, uint32_t durationMs, int pad = 0);@@ -91,5 +92,7 @@ void setTriggerResistanceActive(bool on);// system (the player's colour). Any thread; polling applies it.void setLightBar(uint8_t r, uint8_t g, uint8_t b, int pad = 0);void resetLightBar(int pad = 0);+// DualSense: suppresses vibration and trigger effect bleed while embedded mic is active+void setEmbeddedMicActive(bool active, int pad = 0);} // namespace xc::inputdiff --git a/src/media/audio_encoder.cpp b/src/media/audio_encoder.cppnew file mode 100644index 0000000..bfe14d7--- /dev/null+++ b/src/media/audio_encoder.cpp@@ -0,0 +1,124 @@+// SPDX-License-Identifier: GPL-3.0-or-later+// Copyright (C) 2026 RafaelNGP+#include "media/audio_encoder.h"++#include "util/log.h"++extern "C" {+#include <libavcodec/avcodec.h>+#include <libavutil/channel_layout.h>+#include <libavutil/error.h>+#include <libavutil/opt.h>+}++#include <algorithm>+#include <cstring>+#include <string>++namespace xc::media {++namespace {++std::string averr(int rc) {+ char buf[AV_ERROR_MAX_STRING_SIZE];+ av_strerror(rc, buf, sizeof buf);+ return buf;+}++} // namespace++AudioEncoder::AudioEncoder() = default;++AudioEncoder::~AudioEncoder() {+ if (ctx_) avcodec_free_context(&ctx_);+ if (frame_) av_frame_free(&frame_);+ if (packet_) av_packet_free(&packet_);+}++bool AudioEncoder::init(int bitrate) {+ const AVCodec* codec = avcodec_find_encoder(AV_CODEC_ID_OPUS);+ if (!codec) {+ XC_LOGE("audio encoder: Opus encoder not found in FFmpeg build");+ return false;+ }++ ctx_ = avcodec_alloc_context3(codec);+ if (!ctx_) return false;++ ctx_->sample_rate = kSampleRate;+ ctx_->sample_fmt = AV_SAMPLE_FMT_FLTP;+ av_channel_layout_default(&ctx_->ch_layout, kChannels);+ ctx_->bit_rate = bitrate;+ ctx_->time_base = AVRational{1, kSampleRate};+ ctx_->flags |= AV_CODEC_FLAG_LOW_DELAY;++ ctx_->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;+ av_opt_set_double(ctx_->priv_data, "opus_delay", 20.0, 0);++ int rc = avcodec_open2(ctx_, codec, nullptr);+ if (rc < 0) {+ XC_LOGE("audio encoder: avcodec_open2 failed: %s", averr(rc).c_str());+ avcodec_free_context(&ctx_);+ return false;+ }++ constexpr int kSubframeSize = 120; // Native Opus encoder frame_size is 120 (2.5 ms)+ frame_ = av_frame_alloc();+ if (!frame_) return false;+ frame_->nb_samples = kSubframeSize;+ frame_->format = ctx_->sample_fmt;+ frame_->sample_rate = ctx_->sample_rate;+ av_channel_layout_copy(&frame_->ch_layout, &ctx_->ch_layout);++ rc = av_frame_get_buffer(frame_, 0);+ if (rc < 0) {+ XC_LOGE("audio encoder: av_frame_get_buffer failed: %s", averr(rc).c_str());+ return false;+ }++ packet_ = av_packet_alloc();+ if (!packet_) return false;++ XC_LOGI("audio encoder: Opus encoder initialized (%d Hz, %d ch, %d bps, 20ms frames)",+ kSampleRate, kChannels, bitrate);+ return true;+}++bool AudioEncoder::encode(const int16_t* pcm, size_t samples, std::vector<uint8_t>& out) {+ if (!ctx_ || !frame_ || !packet_ || !pcm || samples < kFrameSize) return false;++ constexpr int kSubframeSize = 120;+ constexpr float kInv32768 = 1.0f / 32768.0f;+ bool gotPacket = false;++ // Feed 8 subframes of 120 samples (8 * 120 = 960 samples = 20 ms)+ for (size_t offset = 0; offset < kFrameSize; offset += kSubframeSize) {+ int rc = av_frame_make_writable(frame_);+ if (rc < 0) return false;++ float* dst = reinterpret_cast<float*>(frame_->data[0]);+ for (int i = 0; i < kSubframeSize; ++i) {+ dst[i] = static_cast<float>(pcm[offset + i]) * kInv32768;+ }++ frame_->pts = pts_;+ pts_ += kSubframeSize;++ rc = avcodec_send_frame(ctx_, frame_);+ if (rc < 0) {+ XC_LOGW("audio encoder: avcodec_send_frame failed: %s", averr(rc).c_str());+ return false;+ }++ rc = avcodec_receive_packet(ctx_, packet_);+ if (rc == 0) {+ out.assign(packet_->data, packet_->data + packet_->size);+ av_packet_unref(packet_);+ gotPacket = true;+ }+ }++ return gotPacket;+}++} // namespace xc::mediadiff --git a/src/media/audio_encoder.h b/src/media/audio_encoder.hnew file mode 100644index 0000000..3b09cb6--- /dev/null+++ b/src/media/audio_encoder.h@@ -0,0 +1,41 @@+// SPDX-License-Identifier: GPL-3.0-or-later+// Copyright (C) 2026 RafaelNGP+#pragma once++#include <cstddef>+#include <cstdint>+#include <vector>++struct AVCodecContext;+struct AVFrame;+struct AVPacket;++namespace xc::media {++class AudioEncoder {+public:+ static constexpr int kSampleRate = 48000;+ static constexpr int kChannels = 1;+ static constexpr int kFrameSize = 960; // 20 ms @ 48 kHz++ AudioEncoder();+ ~AudioEncoder();++ AudioEncoder(const AudioEncoder&) = delete;+ AudioEncoder& operator=(const AudioEncoder&) = delete;++ // Initializes native Opus encoder (default 24 kbps VoIP)+ bool init(int bitrate = 24000);++ // Encodes one 20 ms frame (960 mono S16 samples).+ // Fills `out` with the encoded Opus packet bytes.+ bool encode(const int16_t* pcm, size_t samples, std::vector<uint8_t>& out);++private:+ AVCodecContext* ctx_ = nullptr;+ AVFrame* frame_ = nullptr;+ AVPacket* packet_ = nullptr;+ int64_t pts_ = 0;+};++} // namespace xc::mediadiff --git a/src/media/audio_in.cpp b/src/media/audio_in.cppnew file mode 100644index 0000000..1ac4416--- /dev/null+++ b/src/media/audio_in.cpp@@ -0,0 +1,186 @@+// SPDX-License-Identifier: GPL-3.0-or-later+// Copyright (C) 2026 RafaelNGP+#include "media/audio_in.h"+#include "input/controller.h"+#include "util/log.h"++#include <algorithm>+#include <cmath>+#include <cstring>+#include <thread>+#include <vector>++#if defined(XCLOUD_PS5)+extern "C" {+struct SceUserServiceInitializeParams {+ uint32_t priority;+};+int sceUserServiceInitialize(const SceUserServiceInitializeParams* param);+int sceUserServiceGetInitialUser(int* userId);+int sceAudioInInit(void);+int sceAudioInOpen(int userId, int type, int index, unsigned len, unsigned freq, unsigned param);+int sceAudioInInput(int handle, void* dest);+int sceAudioInClose(int handle);+int sceAudioInGetSilentState(int handle);+int sceAudioInSetGain(int handle, int gain);+}+#endif++namespace xc::media {++struct AudioIn::Impl {+ std::thread thread;+#if defined(XCLOUD_PS5)+ int handle = -1;+#endif+};++AudioIn::AudioIn() : impl_(std::make_unique<Impl>()) {}++AudioIn::~AudioIn() {+ close();+}++bool AudioIn::open(AudioCallback cb) {+ if (running_) return true;+ callback_ = std::move(cb);++#if defined(XCLOUD_PS5)+ static bool initialised = false;+ if (!initialised) {+ int rc = sceAudioInInit();+ if (rc < 0 && rc != static_cast<int>(0x8026000C) && rc != static_cast<int>(0x8026000E)) {+ XC_LOGW("sceAudioInInit: 0x%08x", static_cast<unsigned>(rc));+ }+ initialised = true;+ }++ int userId = input::padUserId(0);+ if (userId < 0) {+ int rc = sceUserServiceGetInitialUser(&userId);+ if (rc < 0) {+ SceUserServiceInitializeParams param{0x2FF};+ sceUserServiceInitialize(¶m);+ rc = sceUserServiceGetInitialUser(&userId);+ }+ if (rc < 0) {+ XC_LOGW("sceUserServiceGetInitialUser: 0x%08x", static_cast<unsigned>(rc));+ }+ }+ XC_LOGI("audio in: opening port for user 0x%08x (%d)...", static_cast<unsigned>(userId), userId);++ constexpr unsigned kGrain = 256;+ // type 0 = VoiceChat (or type 1 = General); param 0 = S16 mono+ impl_->handle = sceAudioInOpen(userId, 0, 0, kGrain, kSampleRate, 0);+ if (impl_->handle < 0) {+ XC_LOGW("sceAudioInOpen(user 0x%x, type 0) failed: 0x%08x, trying type 1...",+ (unsigned)userId, static_cast<unsigned>(impl_->handle));+ impl_->handle = sceAudioInOpen(userId, 1, 0, kGrain, kSampleRate, 0);+ }+ if (impl_->handle < 0 && userId != 0) {+ XC_LOGW("trying sceAudioInOpen with user 0...");+ impl_->handle = sceAudioInOpen(0, 0, 0, kGrain, kSampleRate, 0);+ }+ if (impl_->handle < 0) {+ XC_LOGE("sceAudioInOpen failed: 0x%08x", static_cast<unsigned>(impl_->handle));+ return false;+ }+ running_ = true;++ impl_->thread = std::thread([this]() {+ constexpr unsigned kGrain = 256;+ std::vector<int16_t> grain(kGrain);+ std::vector<int16_t> accumulated;+ accumulated.reserve(kFrameSize + kGrain);+ unsigned lastStatus = 0xFFFFFFFF;+ uint64_t loopCount = 0;++ while (running_) {+ int rc = sceAudioInInput(impl_->handle, grain.data());+ if (rc < 0) {+ XC_LOGE("sceAudioInInput error: 0x%08x", static_cast<unsigned>(rc));+ break;+ }+ if (++loopCount == 1) {+ XC_LOGI("audio in: first input buffer received (%u samples)", kGrain);+ }++ int silentState = sceAudioInGetSilentState(impl_->handle);+ if (silentState != static_cast<int>(lastStatus)) {+ XC_LOGI("audio in: silent state changed to 0x%08x", static_cast<unsigned>(silentState));+ lastStatus = static_cast<unsigned>(silentState);+ }+ if (silentState >= 0) {+ // ORBIS_AUDIO_IN_SILENT_STATE_USER_SETTING (0x4) or DEVICE_NONE (0x1)+ bool hwMuted = (silentState & 0x00000004) != 0 || (silentState & 0x00000001) != 0;+ hardwareMuted_.store(hwMuted, std::memory_order_relaxed);+ }++ bool isMuted = muted_.load(std::memory_order_relaxed) || hardwareMuted_.load(std::memory_order_relaxed);+ float currentGain = gain_.load(std::memory_order_relaxed);++ float peak = 0.0f;+ if (isMuted) {+ std::fill(grain.begin(), grain.end(), 0);+ } else {+ for (auto& s : grain) {+ if (std::fabs(currentGain - 1.0f) > 0.01f) {+ float scaled = static_cast<float>(s) * currentGain;+ scaled = std::clamp(scaled, -32768.0f, 32767.0f);+ s = static_cast<int16_t>(scaled);+ }+ float a = std::abs(static_cast<float>(s)) / 32768.0f;+ if (a > peak) peak = a;+ }+ }++ // Perceptual scale: speech in DualSense typically has 500..6000 amplitude+ float scaledPeak = std::clamp(std::sqrt(peak * 3.5f), 0.0f, 1.0f);++ float prev = level_.load(std::memory_order_relaxed);+ // Smooth natural VU decay (~350ms falloff)+ float nextLevel = (scaledPeak >= prev) ? scaledPeak : (prev * 0.96f);+ if (nextLevel < 0.01f) nextLevel = 0.0f;+ level_.store(nextLevel, std::memory_order_relaxed);++ accumulated.insert(accumulated.end(), grain.begin(), grain.end());++ while (accumulated.size() >= kFrameSize) {+ if (callback_) {+ callback_(accumulated.data(), kFrameSize);+ }+ accumulated.erase(accumulated.begin(), accumulated.begin() + static_cast<long>(kFrameSize));+ }+ }+ });++ XC_LOGI("audio in: PS5 audio input opened (handle %d, 48 kHz mono S16)", impl_->handle);+ return true;+#else+ running_ = true;+ XC_LOGI("audio in: host audio input stub started");+ return true;+#endif+}++void AudioIn::close() {+ if (!running_) return;+ running_ = false;+ level_.store(0.0f, std::memory_order_relaxed);+ hardwareMuted_.store(false, std::memory_order_relaxed);++ if (impl_->thread.joinable()) {+ impl_->thread.join();+ }++#if defined(XCLOUD_PS5)+ if (impl_->handle >= 0) {+ sceAudioInClose(impl_->handle);+ impl_->handle = -1;+ }+#endif+ callback_ = nullptr;+ XC_LOGI("audio in: closed");+}++} // namespace xc::mediadiff --git a/src/media/audio_in.h b/src/media/audio_in.hnew file mode 100644index 0000000..fc38121--- /dev/null+++ b/src/media/audio_in.h@@ -0,0 +1,50 @@+// SPDX-License-Identifier: GPL-3.0-or-later+// Copyright (C) 2026 RafaelNGP+#pragma once++#include <atomic>+#include <cstddef>+#include <cstdint>+#include <functional>+#include <memory>+#include <vector>++namespace xc::media {++class AudioIn {+public:+ static constexpr int kSampleRate = 48000;+ static constexpr int kChannels = 1;+ static constexpr size_t kFrameSize = 960; // 20 ms @ 48 kHz++ using AudioCallback = std::function<void(const int16_t* pcm, size_t frames)>;++ AudioIn();+ ~AudioIn();++ AudioIn(const AudioIn&) = delete;+ AudioIn& operator=(const AudioIn&) = delete;++ bool open(AudioCallback cb);+ void close();++ bool isRecording() const { return running_; }+ void setMuted(bool mute) { muted_ = mute; }+ bool isMuted() const { return muted_; }+ bool isHardwareMuted() const { return hardwareMuted_.load(std::memory_order_relaxed); }+ void setGain(float gain) { gain_ = gain; }+ float gain() const { return gain_; }+ float level() const { return level_.load(std::memory_order_relaxed); }++private:+ struct Impl;+ std::unique_ptr<Impl> impl_;+ std::atomic<bool> running_{false};+ std::atomic<bool> muted_{false};+ std::atomic<bool> hardwareMuted_{false};+ std::atomic<float> gain_{1.0f};+ std::atomic<float> level_{0.0f};+ AudioCallback callback_;+};++} // namespace xc::mediadiff --git a/src/media/audio_out.cpp b/src/media/audio_out.cppindex f907a71..af01408 100644--- a/src/media/audio_out.cpp+++ b/src/media/audio_out.cpp@@ -35,6 +35,7 @@ std::thread g_thread;#if defined(XCLOUD_PS5)int g_handle = -1;+std::atomic<AudioRoute> g_route{AudioRoute::Main};void loop() {std::vector<float> grain(kGrain * 2);@@ -46,14 +47,22 @@ void loop() {g_queue.erase(g_queue.begin(), g_queue.begin() + static_cast<long>(n));std::fill(grain.begin() + static_cast<long>(n), grain.end(), 0.0f);}+ int h = g_handle;+ if (h < 0) {+ std::this_thread::sleep_for(std::chrono::milliseconds(5));+ continue;+ }// Blocks until the hardware wants the next grain (5.3 ms).- int rc = sceAudioOutOutput(g_handle, grain.data());+ int rc = sceAudioOutOutput(h, grain.data());if (rc < 0) {- XC_LOGE("sceAudioOutOutput: 0x%08x", static_cast<unsigned>(rc));- break;+ XC_LOGW("sceAudioOutOutput: 0x%08x", static_cast<unsigned>(rc));+ std::this_thread::sleep_for(std::chrono::milliseconds(5));+ if (!g_running) break;}}}+#else+std::atomic<AudioRoute> g_route{AudioRoute::Main};#endif} // namespace@@ -72,7 +81,8 @@ bool audioStart() {}initialised = true;}- // The system user (0xFF), MAIN port, float stereo.+ // Port 0 (MAIN): primary system output. PS5 OS automatically routes+ // to HDMI/TV or connected headphones (DualSense 3.5mm / USB / Bluetooth).g_handle = sceAudioOutOpen(0xFF, 0, 0, kGrain, kRate, 4);if (g_handle < 0) {XC_LOGE("sceAudioOutOpen: 0x%08x", static_cast<unsigned>(g_handle));@@ -80,13 +90,21 @@ bool audioStart() {}g_running = true;g_thread = std::thread(loop);- XC_LOGI("audio output open (48 kHz float stereo)");+ XC_LOGI("audio output open (48 kHz float stereo, handle %d)", g_handle);#elseg_running = true;#endifreturn true;}+void audioSetRoute(AudioRoute route) {+ g_route.store(route);+}++AudioRoute audioRoute() {+ return g_route.load();+}+void audioStop() {if (!g_running) return;g_running = false;diff --git a/src/media/audio_out.h b/src/media/audio_out.hindex 5a1e321..cbe714c 100644--- a/src/media/audio_out.h+++ b/src/media/audio_out.h@@ -8,8 +8,15 @@namespace xc::media {+enum class AudioRoute {+ Main = 0, // TV / HDMI / Default output+ Pad = 1 // DualSense Controller Speaker / Headset+};+bool audioStart();void audioStop();+void audioSetRoute(AudioRoute route);+AudioRoute audioRoute();// Drops the oldest samples when more than ~120 ms is queued, to keep// latency bounded when the network delivers a burst.void audioPush(const float* interleaved, size_t frames);diff --git a/src/stream/stream_session.cpp b/src/stream/stream_session.cppindex 63fec83..1d59cf4 100644--- a/src/stream/stream_session.cpp+++ b/src/stream/stream_session.cpp@@ -412,6 +412,7 @@ struct StreamSession::Impl {// Same channels, in the same order, as the web client.chat = makeChannel("chat", "chatV1");+ chat->onMessage([](rtc::message_variant m) { XC_LOGI("chat channel: %s", asText(m).c_str()); });control = makeChannel("control", "controlV1");input = makeChannel("input", "1.0");message = makeChannel("message", "messageV1");@@ -442,12 +443,20 @@ struct StreamSession::Impl {}});- // Audio: sendrecv like the browser (the send side carries chat later).+ // Audio: sendrecv like the browser (the send side carries chat).rtc::Description::Audio a("0", rtc::Description::Direction::SendRecv);a.addOpusCodec(111, "minptime=10;useinbandfec=1;stereo=1");+ a.addSSRC(1, "audio");audio = pc->addTrack(a);+auto audioDepacketizer = std::make_shared<rtc::OpusRtpDepacketizer>();audioDepacketizer->addToChain(std::make_shared<RtcpReporter>(48000, 0));++ auto rtpConfig = std::make_shared<rtc::RtpPacketizationConfig>(+ 1, "audio", 111, rtc::OpusRtpPacketizer::DefaultClockRate);+ auto audioPacketizer = std::make_shared<rtc::OpusRtpPacketizer>(rtpConfig);+ audioDepacketizer->addToChain(audioPacketizer);+audio->setMediaHandler(audioDepacketizer);audio->onFrame([this](rtc::binary data, rtc::FrameInfo info) {if (cb.audio) cb.audio(reinterpret_cast<const uint8_t*>(data.data()), data.size(), info.timestamp);@@ -653,6 +662,15 @@ void StreamSession::sendGamepad(const GamepadFrame& frame) {Impl::sendBinary(impl_->input, gamepadReport(impl_->inputSequence++, impl_->nowMs(), frame));}+void StreamSession::sendAudio(const uint8_t* opus, size_t size, uint32_t timestamp) {+ if (!impl_ || !impl_->open || !impl_->audio || !opus || size == 0) return;+ try {+ rtc::FrameInfo info(timestamp);+ impl_->audio->sendFrame(reinterpret_cast<const rtc::byte*>(opus), size, info);+ } catch (const std::exception&) {+ }+}+void StreamSession::setTouchEnabled(bool on) {if (!impl_->open) return;json::Value touch = json::Value::object();diff --git a/src/stream/stream_session.h b/src/stream/stream_session.hindex b826a06..911a1f6 100644--- a/src/stream/stream_session.h+++ b/src/stream/stream_session.h@@ -86,6 +86,8 @@ public:bool isOpen() const;void sendGamepad(const GamepadFrame& frame);+ // Voice chat: sends an encoded Opus frame to the stream server (RTP @ 48 kHz).+ void sendAudio(const uint8_t* opus, size_t size, uint32_t timestamp);// Touch input on or off (off at the start).void setTouchEnabled(bool on);// A controller at `index` (1..3; 0 is attached at the start) came or went.diff --git a/src/ui/app_ui.h b/src/ui/app_ui.hindex 63e7564..6ca5b99 100644--- a/src/ui/app_ui.h+++ b/src/ui/app_ui.h@@ -153,6 +153,8 @@ class AppUi {public:AppUi(const Fonts& fonts, ImageCache& images);+ const Fonts& fonts() const { return fonts_; }+// --- Model -------------------------------------------------------------void showSplash(const std::string& status);void showSignIn(const std::string& code, const std::string& url);diff --git a/src/ui/stream_menu.cpp b/src/ui/stream_menu.cppindex 9c68135..872b0c0 100644--- a/src/ui/stream_menu.cpp+++ b/src/ui/stream_menu.cpp@@ -45,7 +45,7 @@ void StreamMenu::setProfileValues(int resolution, int sharpness, int deband, intvoid StreamMenu::open(int resolution, bool stats, int sharpness, int deband, int upscaler, bool homeConsole,bool allow1440, bool hasCustomProfile, int triggerStrength, int deadzone,- bool circleConfirms) {+ bool circleConfirms, float micLevel, bool micMuted) {open_ = true;homeConsole_ = homeConsole;allow1440_ = allow1440;@@ -57,6 +57,8 @@ void StreamMenu::open(int resolution, bool stats, int sharpness, int deband, inttriggerStrength_ = triggerStrength;deadzone_ = deadzone;circleConfirms_ = circleConfirms;+ micLevel_ = micLevel;+ micMuted_ = micMuted;selected_ = XboxButton;resolution_ = applied_ = resolution;resolutionAsked_ = false;@@ -138,25 +140,25 @@ Canvas StreamMenu::renderMenu(const StreamInfo& info) const {fonts_.bold.draw(c, tr(Str::MenuTitle), kPad, 38, 32, kWhite);// The items: the selected one white, like the Xbox guide.- constexpr int kRowH = 46, kTop = 96, kPx = 22;+ constexpr int kRowH = 40, kTop = 84, kPx = 20;for (int i = 0; i < ItemCount; ++i) {- Rect row{kPad - 16, kTop + i * kRowH, kMenuW - 2 * (kPad - 16), kRowH - 6};+ Rect row{kPad - 16, kTop + i * kRowH, kMenuW - 2 * (kPad - 16), kRowH - 4};bool sel = i == selected_;if (sel) c.fillRect(row, kWhite, 8);Color fg = sel ? kDark : kWhite;int ty = fonts_.semibold.centeredY(row.y, row.h, kPx);- const char* label = i == XboxButton ? tr(Str::MenuXboxButton)- : i == Profile ? tr(Str::Profile)- : i == Stats ? tr(Str::MenuStats)- : i == Sharpness ? tr(Str::MenuSharpness)- : i == Deband ? tr(Str::MenuDeband)- : i == Upscaler ? tr(Str::MenuUpscaler)- : i == Resolution ? tr(Str::MenuResolution)- : i == Triggers ? tr(Str::TriggerRumble)- : i == DeadzoneItem ? tr(Str::Deadzone)- : i == ConfirmItem ? tr(Str::ConfirmButton)- : homeConsole_ ? tr(Str::MenuEndStream)- : tr(Str::MenuLeave);+ const char* label = i == XboxButton ? tr(Str::MenuXboxButton)+ : i == Profile ? tr(Str::Profile)+ : i == Stats ? tr(Str::MenuStats)+ : i == Sharpness ? tr(Str::MenuSharpness)+ : i == Deband ? tr(Str::MenuDeband)+ : i == Upscaler ? tr(Str::MenuUpscaler)+ : i == Resolution ? tr(Str::MenuResolution)+ : i == Triggers ? tr(Str::TriggerRumble)+ : i == DeadzoneItem ? tr(Str::Deadzone)+ : i == ConfirmItem ? tr(Str::ConfirmButton)+ : homeConsole_ ? tr(Str::MenuEndStream)+ : tr(Str::MenuLeave);fonts_.semibold.draw(c, label, row.x + 16, ty, kPx, fg);std::string value;if (i == Profile) {@@ -207,19 +209,19 @@ Canvas StreamMenu::renderMenu(const StreamInfo& info) const {}int y = kTop + ItemCount * kRowH + 6;if (resolutionAsked_) {- fonts_.regular.draw(c, tr(Str::ResolutionNote), kPad, y, 18, kDim);- y += 26;+ fonts_.regular.draw(c, tr(Str::ResolutionNote), kPad, y, 16, kDim);+ y += 22;}- y += 10;+ y += 6;// The connection.c.fillRect({kPad, y, kMenuW - 2 * kPad, 2}, rgba(60, 60, 60));- y += 18;+ y += 14;auto line = [&](Str label, const std::string& value) {- fonts_.regular.draw(c, tr(label), kPad, y, 20, kGray);- int w = fonts_.semibold.measure(value, 20);- fonts_.semibold.draw(c, value, kMenuW - kPad - w, y, 20, kWhite);- y += 30;+ fonts_.regular.draw(c, tr(label), kPad, y, 18, kGray);+ int w = fonts_.semibold.measure(value, 18);+ fonts_.semibold.draw(c, value, kMenuW - kPad - w, y, 18, kWhite);+ y += 24;};const std::string none = "-";line(Str::StatRegion, info.region.empty() ? none : info.region);@@ -234,45 +236,88 @@ Canvas StreamMenu::renderMenu(const StreamInfo& info) const {// The controllers: numbered pads, each connected one with its user.y += 8;- fonts_.regular.draw(c, tr(Str::Controllers), kPad, y, 22, kGray);- y += 38;+ fonts_.regular.draw(c, tr(Str::Controllers), kPad, y, 20, kGray);++ // Real-time Mic VU meter bar on the right side of the Controllers line:+ {+ int barW = 140, barH = 12;+ int barX = kMenuW - kPad - barW;+ int barY = y + 4;+ std::string micLabel = tr(Str::MenuMicrophone);+ int mw = fonts_.regular.measure(micLabel, 16);+ fonts_.regular.draw(c, micLabel, barX - mw - 10, y + 2, 16, micMuted_ ? kDim : kGray);++ // Dark background pill+ c.fillRect({barX, barY, barW, barH}, rgba(40, 40, 40), 6);+ c.strokeRect({barX, barY, barW, barH}, rgba(70, 70, 70), 1, 6);++ if (micMuted_) {+ int tw = fonts_.semibold.measure(tr(Str::MicMuted), 13);+ fonts_.semibold.draw(c, tr(Str::MicMuted), barX + (barW - tw) / 2, barY - 1, 13, rgba(230, 120, 50));+ } else {+ float lvl = std::clamp(micLevel_, 0.0f, 1.0f);+ int fillW = static_cast<int>(lvl * (barW - 4));+ if (fillW > 0) {+ // Vibrant green sound level bar+ c.fillRect({barX + 2, barY + 2, fillW, barH - 4}, rgba(30, 215, 96), 4);+ if (lvl > 0.85f) {+ // Yellow peak indicator+ int peakW = static_cast<int>((lvl - 0.85f) / 0.15f * (barW - 4));+ c.fillRect({barX + barW - 2 - peakW, barY + 2, peakW, barH - 4}, rgba(255, 204, 0), 4);+ }+ } else {+ // Minimum idle listening dot+ c.fillCircle(barX + 7, barY + barH / 2, 2.5f, rgba(30, 215, 96, 160));+ }+ }+ }++ y += 28;const int slotW = (kMenuW - 2 * kPad) / static_cast<int>(pads_.size());for (int i = 0; i < static_cast<int>(pads_.size()); ++i) {int sx = kPad + i * slotW;- constexpr int kIconW = 60;+ constexpr int kIconW = 56;drawPadIcon(c, fonts_.bold, sx + (slotW - kIconW) / 2, y, kIconW, i, pads_[i].connected, kPanel);if (!pads_[i].connected || pads_[i].name.empty()) continue;- auto name = fonts_.regular.wrap(pads_[i].name, 16, slotW - 8, 1);+ auto name = fonts_.regular.wrap(pads_[i].name, 15, slotW - 8, 1);if (!name.empty())- fonts_.regular.draw(c, name[0], sx + (slotW - fonts_.regular.measure(name[0], 16)) / 2,- y + padIconHeight(kIconW) + 4, 16, kGray);+ fonts_.regular.draw(c, name[0], sx + (slotW - fonts_.regular.measure(name[0], 15)) / 2,+ y + padIconHeight(kIconW) + 2, 15, kGray);+ if (i == 0) {+ if (micMuted_) {+ // Orange mic dot matching DualSense hardware mute LED+ c.fillCircle(sx + (slotW + kIconW) / 2 - 2, y + 8, 3.5f, rgba(230, 120, 50));+ } else {+ // Little green mic dot next to controller 1+ c.fillCircle(sx + (slotW + kIconW) / 2 - 2, y + 8, 3.5f, rgba(30, 215, 96));+ }+ }}- // Cross selects, Circle goes back to the game (swapped with Circle- // confirming).- int hy = kMenuH - 56, x = kPad;+ // Cross selects, Circle goes back to the game (swapped with Circle confirming).+ int hy = kMenuH - 50, x = kPad;{// The touchpad's gestures, small, above the button hints.- auto lines = fonts_.regular.wrap(tr(Str::MenuGestureHint), 18, kMenuW - 2 * kPad, 2);- int gy = hy - 20 - static_cast<int>(lines.size()) * 26;+ auto lines = fonts_.regular.wrap(tr(Str::MenuGestureHint), 16, kMenuW - 2 * kPad, 2);+ int gy = hy - 14 - static_cast<int>(lines.size()) * 22;for (const auto& l : lines) {- fonts_.regular.draw(c, l, kPad, gy, 18, kDim);- gy += 26;+ fonts_.regular.draw(c, l, kPad, gy, 16, kDim);+ gy += 22;}}auto icon = [&](bool cross) {- c.fillCircle(x + 14, hy + 13, 14, rgba(255, 255, 255, 40));+ c.fillCircle(x + 13, hy + 12, 13, rgba(255, 255, 255, 40));if (cross) {- c.line(x + 8, hy + 7, x + 20, hy + 19, 2.5f, rgba(124, 178, 232));- c.line(x + 20, hy + 7, x + 8, hy + 19, 2.5f, rgba(124, 178, 232));+ c.line(x + 7, hy + 6, x + 19, hy + 18, 2.5f, rgba(124, 178, 232));+ c.line(x + 19, hy + 6, x + 7, hy + 18, 2.5f, rgba(124, 178, 232));} else {- c.strokeArc(x + 14, hy + 13, 6.5f, 2.5f, 0, 6.2832f, rgba(255, 102, 102));+ c.strokeArc(x + 13, hy + 12, 6.0f, 2.5f, 0, 6.2832f, rgba(255, 102, 102));}};icon(!circleConfirms_);- x = fonts_.semibold.draw(c, tr(Str::Select), x + 38, hy, 22, kGray) + 36;+ x = fonts_.semibold.draw(c, tr(Str::Select), x + 34, hy, 20, kGray) + 32;icon(circleConfirms_);- fonts_.semibold.draw(c, tr(Str::Back), x + 38, hy, 22, kGray);+ fonts_.semibold.draw(c, tr(Str::Back), x + 34, hy, 20, kGray);return c;}@@ -282,6 +327,7 @@ Canvas StreamMenu::renderStats(const StreamInfo& info) const {text += fmt("%.0f fps", info.fps) + " " + fmt("%.1f Mbps", info.mbps);if (info.rttMs > 0) text += " " + std::to_string(info.rttMs) + " ms";text += " " + fmt("%.1f%%", info.lossPct);+ if (!micMuted_) text += " MIC";constexpr int kPx = 20, kH = 36;int w = fonts_.semibold.measure(text, kPx) + 28;Canvas c(w, kH);diff --git a/src/ui/stream_menu.h b/src/ui/stream_menu.hindex 0f2f521..4f01ef9 100644--- a/src/ui/stream_menu.h+++ b/src/ui/stream_menu.h@@ -26,7 +26,7 @@ struct StreamInfo {// Close: the menu went away (Circle, OPTIONS, or the Xbox button): a fresh key frame is asked for.enum class MenuAction {None, Close, Leave, Resolution, Stats, Sharpness, Deband, Upscaler, XboxButton,- ProfileToggle, Triggers, Deadzone, ConfirmButton+ ProfileToggle, Triggers, Deadzone, ConfirmButton, MicToggle};class StreamMenu {@@ -45,7 +45,7 @@ public:// `allow1440`: offered only once a stream delivered it.void open(int resolution, bool stats, int sharpness = 0, int deband = 1, int upscaler = 0, bool homeConsole = false,bool allow1440 = true, bool hasCustomProfile = false, int triggerStrength = 2, int deadzone = 15,- bool circleConfirms = false);+ bool circleConfirms = false, float micLevel = 0.0f, bool micMuted = false);void close() { open_ = false; }bool isOpen() const { return open_; }MenuAction handle(const NavInput& in);@@ -62,6 +62,10 @@ public:void setDeadzone(int deadzone) { deadzone_ = deadzone; }bool circleConfirms() const { return circleConfirms_; }void setCircleConfirms(bool cc) { circleConfirms_ = cc; }+ bool micMuted() const { return micMuted_; }+ void setMicMuted(bool muted) { micMuted_ = muted; }+ float micLevel() const { return micLevel_; }+ void setMicLevel(float lvl) { micLevel_ = lvl; }// The block smoothing level "auto" picked for the bitrate (shown as "Auto (low)").void setDebandInUse(int level) { debandInUse_ = level; }// Circle confirms: the hints swap their buttons.@@ -102,6 +106,8 @@ private:bool hasCustomProfile_ = false;int triggerStrength_ = 2;int deadzone_ = 15;+ bool micMuted_ = false;+ float micLevel_ = 0.0f;PadSlots pads_{};};diff --git a/src/ui/strings.cpp b/src/ui/strings.cppindex 9c21ff6..c64fc56 100644--- a/src/ui/strings.cpp+++ b/src/ui/strings.cpp@@ -235,6 +235,12 @@ constexpr Column kEnglish = {"All publishers", // PublisherAll"Indies & Others", // PublisherIndies"Friends playing now", // FriendsPlayingNow+ "Microphone", // MenuMicrophone+ "Muted", // MicMuted+ "Active", // MicActive+ "Audio output", // MenuAudioOutput+ "TV", // AudioRouteTv+ "DualSense Speaker", // AudioRoutePad};constexpr Column kPortugueseBR = {@@ -440,6 +446,12 @@ constexpr Column kPortugueseBR = {"Todas as editoras","Indies & Outras","Amigos jogando agora",+ "Microfone",+ "Mutado",+ "Ativo",+ "Saída de áudio",+ "TV",+ "Alto-falante do controle",};constexpr Column kSpanish = {@@ -645,6 +657,12 @@ constexpr Column kSpanish = {"Todas las distribuidoras","Indies y otras","Amigos jugando ahora",+ "Micrófono",+ "Silenciado",+ "Activo",+ "Salida de audio",+ "TV",+ "Altavoz del mando",};constexpr Column kFrench = {@@ -850,6 +868,12 @@ constexpr Column kFrench = {"Tous les éditeurs","Indépendants et autres","Amis en train de jouer",+ "Microphone",+ "Coupé",+ "Actif",+ "Sortie audio",+ "TV",+ "Haut-parleur de la manette",};constexpr Column kGerman = {@@ -1055,6 +1079,12 @@ constexpr Column kGerman = {"Alle Publisher","Indies & Andere","Freunde spielen jetzt",+ "Mikrofon",+ "Stumm",+ "Aktiv",+ "Audioausgabe",+ "TV",+ "Controller-Lautsprecher",};constexpr Column kItalian = {@@ -1260,6 +1290,12 @@ constexpr Column kItalian = {"Tutti gli editori","Indie e altri","Amici che giocano ora",+ "Microfono",+ "Disattivato",+ "Attivo",+ "Uscita audio",+ "TV",+ "Altoparlante del controller",};constexpr std::array<const Column*, kLangs> kTable = {&kEnglish, &kPortugueseBR, &kSpanish,diff --git a/src/ui/strings.h b/src/ui/strings.hindex dca7e5c..8f44378 100644--- a/src/ui/strings.h+++ b/src/ui/strings.h@@ -212,6 +212,12 @@ enum class Str {PublisherAll,PublisherIndies,FriendsPlayingNow, // "Friends playing now"+ MenuMicrophone, // "Microphone"+ MicMuted, // "Muted"+ MicActive, // "Active"+ MenuAudioOutput, // "Audio output"+ AudioRouteTv, // "TV"+ AudioRoutePad, // "DualSense Speaker"Count};diff --git a/tests/test_main.cpp b/tests/test_main.cppindex 3cfe8ed..aa871d6 100644--- a/tests/test_main.cpp+++ b/tests/test_main.cpp@@ -5,6 +5,7 @@#include "app/settings.h"#include "app/update_check.h"#include "app/updater.h"+#include "media/audio_encoder.h"#include "input/tuning.h"#include "net/http.h"#include "platform/platform.h"@@ -529,7 +530,26 @@ static void testAutoDeband() {for (int s = 1; s <= 5; ++s) CHECK(!a.update(1.0)); // a new stream: the first 5 s again}+static void testAudioEncoder() {+ xc::media::AudioEncoder enc;+ CHECK(enc.init(24000));+ CHECK(xc::media::AudioEncoder::kFrameSize == 960);++ // 960 samples of 440 Hz tone+ std::vector<int16_t> pcm(960);+ for (size_t i = 0; i < pcm.size(); ++i) {+ pcm[i] = static_cast<int16_t>(10000.0 * std::sin(2.0 * M_PI * 440.0 * i / 48000.0));+ }+ for (int frame = 0; frame < 10; ++frame) {+ std::vector<uint8_t> opus;+ CHECK(enc.encode(pcm.data(), pcm.size(), opus));+ CHECK(!opus.empty());+ CHECK(opus.size() > 5 && opus.size() < 1000);+ }+}+int main() {+ testAudioEncoder();testAutoDeband();testControllerTuning();testUpdater();