From 8cfff09c0b7d6f0e251b9a5a24d8fad5ba770916 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Fri, 21 Nov 2025 21:43:29 +0300 Subject: [PATCH] add 'none' input device --- res/layouts/pages/settings_audio.xml.lua | 4 +++- res/texts/ru_RU.txt | 1 + src/audio/audio.cpp | 27 +++++++++++++++--------- src/audio/audio.hpp | 2 ++ 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/res/layouts/pages/settings_audio.xml.lua b/res/layouts/pages/settings_audio.xml.lua index 95166930..f0073098 100644 --- a/res/layouts/pages/settings_audio.xml.lua +++ b/res/layouts/pages/settings_audio.xml.lua @@ -59,7 +59,9 @@ function on_open() .."" .."") local selectbox = document.input_device_select - local devices = {} + local devices = { + {value="none", text=gui.str("None", "settings.microphone")}, + } local names = audio.__get_input_devices_names() for i, name in ipairs(names) do table.insert(devices, {value=name, text=name}) diff --git a/res/texts/ru_RU.txt b/res/texts/ru_RU.txt index 82bece38..1461f854 100644 --- a/res/texts/ru_RU.txt +++ b/res/texts/ru_RU.txt @@ -109,6 +109,7 @@ settings.Conflict=Найдены возможные конфликты settings.Windowed=Оконный settings.Borderless=Безрамочный settings.Microphone=Микрофон +settings.microphone.None=Нет # Управление chunks.reload=Перезагрузить Чанки diff --git a/src/audio/audio.cpp b/src/audio/audio.cpp index 0069ff12..436fa1da 100644 --- a/src/audio/audio.cpp +++ b/src/audio/audio.cpp @@ -23,6 +23,7 @@ namespace { std::unordered_map> streams; std::vector> channels; util::ObjectsKeeper objects_keeper {}; + std::unique_ptr input_device = nullptr; } Channel::Channel(std::string name) : name(std::move(name)) { @@ -151,8 +152,6 @@ public: } }; -static std::unique_ptr input_device = nullptr; - void audio::initialize(bool enabled, AudioSettings& settings) { enabled = enabled && settings.enabled.get(); if (enabled) { @@ -183,9 +182,9 @@ void audio::initialize(bool enabled, AudioSettings& settings) { }, true)); } - input_device = backend->openInputDevice("", 44100, 1, 16); - if (input_device) { - input_device->startCapture(); + ::input_device = backend->openInputDevice("", 44100, 1, 16); + if (::input_device) { + ::input_device->startCapture(); } } @@ -270,18 +269,26 @@ std::vector audio::get_output_devices_names() { } void audio::set_input_device(const std::string& deviceName) { + logger.info() << "setting input device to " << deviceName; + if (deviceName == audio::DEVICE_NONE) { + if (::input_device) { + ::input_device->stopCapture(); + } + ::input_device = nullptr; + return; + } auto newDevice = backend->openInputDevice(deviceName, 44100, 1, 16); if (newDevice == nullptr) { logger.error() << "could not open input device: " << deviceName; return; } - if (input_device) { - input_device->stopCapture(); + if (::input_device) { + ::input_device->stopCapture(); } - input_device = std::move(newDevice); - if (input_device) { - input_device->startCapture(); + ::input_device = std::move(newDevice); + if (::input_device) { + ::input_device->startCapture(); } } diff --git a/src/audio/audio.hpp b/src/audio/audio.hpp index 2cd8c127..0ccd51f3 100644 --- a/src/audio/audio.hpp +++ b/src/audio/audio.hpp @@ -26,6 +26,8 @@ namespace audio { constexpr inline size_t MAX_INPUT_SAMPLES = 22050; + inline std::string_view DEVICE_NONE = "none"; + class Speaker; /// @brief Audio speaker states