add 'none' input device

This commit is contained in:
MihailRis 2025-11-21 21:43:29 +03:00
parent 96bc395561
commit 8cfff09c0b
4 changed files with 23 additions and 11 deletions

View File

@ -59,7 +59,9 @@ function on_open()
.."<container id='input_volume_inner' color='#00FF00FF' pos='1' size='2'/>"
.."</container>")
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})

View File

@ -109,6 +109,7 @@ settings.Conflict=Найдены возможные конфликты
settings.Windowed=Оконный
settings.Borderless=Безрамочный
settings.Microphone=Микрофон
settings.microphone.None=Нет
# Управление
chunks.reload=Перезагрузить Чанки

View File

@ -23,6 +23,7 @@ namespace {
std::unordered_map<speakerid_t, std::shared_ptr<Stream>> streams;
std::vector<std::unique_ptr<Channel>> channels;
util::ObjectsKeeper objects_keeper {};
std::unique_ptr<InputDevice> input_device = nullptr;
}
Channel::Channel(std::string name) : name(std::move(name)) {
@ -151,8 +152,6 @@ public:
}
};
static std::unique_ptr<InputDevice> 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<std::string> 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();
}
}

View File

@ -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