From 6347b8262afcf6e8202476a0a55d852a956de10b Mon Sep 17 00:00:00 2001 From: Valiantsin Dzerakh Date: Sat, 14 Nov 2026 22:28:42 +0300 Subject: [PATCH] The audio output device can be chosen on the Sound tab and in totk.ini (audio_device), and a change moves the sound to it while the game runs (#1014) TOTK_AUDIO_DEVICE names the device as SDL lists it; unset, empty or default keeps the system default and the same open as before. audio_mixer.c output_open opens the named device, or the default with one log line when it is not connected. Once a device is chosen, an output worker thread (output_worker) owns the SDL stream: on a cfg change and once a second it resolves the name again and output_switch opens the new device with the same spec, destroys the old stream (which waits for its callback), restarts the prefill and resumes. The render thread only wakes or starts the worker (output_watch), so the game's audio never waits for a device open. A chosen device that disappears falls back to the system default and comes back within a second of being plugged in again. TOTK_AUDIO_CHANNELS=auto reads the channels of the device chosen at start. Co-Authored-By: Claude Opus 5.5 --- runtime/audio_mixer.c | 169 ++++++++++++++++++++++++++++++++++++------ runtime/audren.h | 4 + runtime/cfg.c | 4 +- runtime/ui/menu.cpp | 31 ++++++++ runtime/ui_text.c | 19 +++++ runtime/ui_text.h | 1 + totk.ini.example | 4 + 7 files changed, 210 insertions(+), 22 deletions(-) diff --git a/runtime/audio_mixer.c b/runtime/audio_mixer.c index a71008bc..a4d63048 100644 --- a/runtime/audio_mixer.c +++ b/runtime/audio_mixer.c @@ -53,7 +53,10 @@ typedef struct Mixer { float *buf; int nbuf, frame; int *offset; // first mix buffer of each mix id SplitInfo *split; int nsplit; SplitDest *dest; int ndest; - SDL_AudioStream *stream; int device_ok, rate; + SDL_AudioStream *stream; int device_ok, rate; // stream: output_open's, then the output worker's alone + SDL_AudioDeviceID open_id, failed_id; // the device the stream plays on; the last one that failed to open + PlatThread *worker; PlatEvent wake; // output_worker, NULL until a device is chosen; wake: a cfg change + _Atomic int worker_quit; unsigned watch_ver; // watch_ver: the render thread's last cfg_version (output_watch) int channels; // output channels, 2 or 6 (output_channels) float ring[RING_FRAMES * OUT_MAX]; _Atomic uint64_t wr, rd, underruns, overruns, missing_frames, callback_frames, callback_nonzero, skipped_frames; @@ -167,8 +170,41 @@ static int prefill_blocks_for(const char *e) { return (int)ceil(ms / 5.0); } +// TOTK_AUDIO_DEVICE: the playback device by the name SDL reports (SDL_GetAudioDeviceName), since SDL's device ids +// change between runs. Unset, empty or "default": the system default, which SDL follows when Windows changes it. +static int device_is_default(const char *want) { return !want || !*want || !strcmp(want, "default"); } + +// The device for `want`: the first playback device of that name, *found 1; else the system default, *found 0 for a name +// SDL does not list (unplugged). The default asks SDL nothing. +static SDL_AudioDeviceID device_pick(const char *want, int *found) { + *found = 1; + if (device_is_default(want)) return SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK; + int n = 0; + SDL_AudioDeviceID *ids = SDL_GetAudioPlaybackDevices(&n), id = 0; + for (int i = 0; ids && i < n && !id; i++) { + const char *name = SDL_GetAudioDeviceName(ids[i]); + if (name && !strcmp(name, want)) id = ids[i]; + } + SDL_free(ids); + *found = id != 0; + return id ? id : SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK; +} + +int audio_output_devices(char (*names)[AUDIO_DEVICE_NAME_MAX], int max) { + if (!SDL_WasInit(SDL_INIT_AUDIO)) return 0; // TOTK_AUDIO=none or no output: nothing to pick + int n = 0, k = 0; + SDL_AudioDeviceID *ids = SDL_GetAudioPlaybackDevices(&n); + for (int i = 0; ids && i < n && k < max; i++) { + const char *name = SDL_GetAudioDeviceName(ids[i]); + if (name && *name && strlen(name) < AUDIO_DEVICE_NAME_MAX) snprintf(names[k++], AUDIO_DEVICE_NAME_MAX, "%s", name); + } + SDL_free(ids); + return k; +} + // TOTK_AUDIO_CHANNELS: the output channels of this run, decided once. stereo gives 2; 5.1 gives 6 (FL FR C LFE RL RR, -// the device sink's order and SDL's); auto gives 6 when the default playback device has at least six channels (a 5.1 +// the device sink's order and SDL's); auto gives 6 when the chosen playback device (TOTK_AUDIO_DEVICE at start, the +// system default without one) has at least six channels (a 5.1 // or 7.1 speaker setup in Windows; SDL places 5.1 on 7.1) and 2 otherwise. IAudioDevice reports the same count to the // game (GetActiveChannelCount), which picks its sink layout from it. TOTK_AUDIO=none: 2, without touching SDL. static int output_channels(void) { @@ -181,10 +217,12 @@ static int output_channels(void) { else if (!strcmp(want, "stereo")) n = 2; else { SDL_AudioSpec dev = {0}; - n = SDL_InitSubSystem(SDL_INIT_AUDIO) && SDL_GetAudioDeviceFormat(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &dev, NULL) && - dev.channels >= 6 ? 6 : 2; - rt_log("audio: TOTK_AUDIO_CHANNELS=auto: the default device has %d channels, output %s", dev.channels, - n == 6 ? "5.1" : "stereo"); + int found, ok = SDL_InitSubSystem(SDL_INIT_AUDIO); + SDL_AudioDeviceID id = ok ? device_pick(cfg_get("TOTK_AUDIO_DEVICE"), &found) : 0; + n = ok && SDL_GetAudioDeviceFormat(id, &dev, NULL) && dev.channels >= 6 ? 6 : 2; + const char *name = ok ? SDL_GetAudioDeviceName(id) : NULL; + rt_log("audio: TOTK_AUDIO_CHANNELS=auto: device '%s' has %d channels, output %s", name ? name : "?", + dev.channels, n == 6 ? "5.1" : "stereo"); } int expected = 0; return atomic_compare_exchange_strong(&decided, &expected, n) ? n : expected; @@ -266,6 +304,28 @@ static void SDLCALL sdl_pull(void *user, SDL_AudioStream *stream, int additional } } +// The pacing figures of the stream's device: its period, the output target and the stall time. Set before the stream +// is resumed; the render thread reads target and stall_ns while a switch sets them (audio_mixer_pace_ns). +static void output_timing(Mixer *m, SDL_AudioSpec *dev) { + int period = 0; + if (!SDL_GetAudioDeviceFormat(SDL_GetAudioStreamDevice(m->stream), dev, &period) || period <= 0) period = m->frame; + m->period = period; + int target = m->frame * m->prefill > 2 * period ? m->frame * m->prefill : 2 * period; + __atomic_store_n(&m->target, target > RING_FRAMES / 2 ? RING_FRAMES / 2 : target, __ATOMIC_RELAXED); + uint64_t period_ns = (uint64_t)period * 1000000000ull / (uint64_t)m->rate; + __atomic_store_n(&m->stall_ns, 4 * period_ns > STALL_MS * 1000000ull ? 4 * period_ns : STALL_MS * 1000000ull, + __ATOMIC_RELAXED); +} + +static void output_log(Mixer *m, const char *what, const SDL_AudioSpec *dev) { + const char *name = SDL_GetAudioDeviceName(SDL_GetAudioStreamDevice(m->stream)); + rt_log("audio: SDL device '%s' %s, %d Hz %s float (device %d channels), prefill %d ms, device period %d frames; " + "the device paces rendering at %.1f ms queued", name ? name : "?", what, m->rate, + m->channels == 6 ? "5.1" : "stereo", dev->channels, m->prefill * 5, m->period, m->target * 1000.0 / m->rate); +} + +static void output_worker_start(Mixer *m); + static void output_open(Mixer *m, int rate) { const char *mode = cfg_get("TOTK_AUDIO"); if ((mode && !strcmp(mode, "none")) || cfg_get("TOTK_AUDIO_OFF")) { @@ -276,12 +336,18 @@ static void output_open(Mixer *m, int rate) { rt_log("audio: SDL audio init failed (%s): mixing without sound", SDL_GetError()); return; } + const char *want = cfg_get("TOTK_AUDIO_DEVICE"); + int found; + m->open_id = device_pick(want, &found); + if (!found) rt_log("audio: TOTK_AUDIO_DEVICE '%s' is not connected: the system default plays", want); SDL_AudioSpec spec = {SDL_AUDIO_F32, m->channels, rate}; - m->stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &spec, sdl_pull, m); + m->stream = SDL_OpenAudioDeviceStream(m->open_id, &spec, sdl_pull, m); if (!m->stream) { rt_log("audio: no output device (%s): mixing without sound", SDL_GetError()); return; } + SDL_AudioSpec dev = {0}; + output_timing(m, &dev); if (!SDL_ResumeAudioStreamDevice(m->stream)) { rt_log("audio: starting the output failed (%s): mixing without sound", SDL_GetError()); SDL_DestroyAudioStream(m->stream); @@ -289,28 +355,84 @@ static void output_open(Mixer *m, int rate) { return; } m->device_ok = 1; + output_log(m, "opened", &dev); + m->watch_ver = cfg_version(); + if (!device_is_default(want)) output_worker_start(m); // watches the chosen device from the start +} + +// ---- switching the output device while the game plays (TOTK_AUDIO_DEVICE is live) +// One worker thread per mixer, started when a device is first chosen, owns the stream from then on: it opens the new +// device (tens of ms) off the render thread, so the game's audio never waits for it. Once a second, and at once when +// cfg changes, it resolves the setting again: a chosen device that disappears falls back to the system default, and the +// output returns to it within a second of it being plugged in again. SDL's device events are not used: on Windows +// nothing pumps SDL's event queue (the window is Win32, gfx_window_win.c), while SDL's device list stays current. + +// Moves the output to device `id` with the same spec; SDL converts to the device's own format and channels. +static void output_switch(Mixer *m, SDL_AudioDeviceID id) { + SDL_AudioSpec spec = {SDL_AUDIO_F32, m->channels, m->rate}; + SDL_AudioStream *s = SDL_OpenAudioDeviceStream(id, &spec, sdl_pull, m); // opens paused: no callback yet + if (!s) { + const char *name = SDL_GetAudioDeviceName(id); + rt_log("audio: opening device '%s' failed (%s): the output stays where it was", name ? name : "?", + SDL_GetError()); + m->failed_id = id; // not tried again until the setting or the device list leads elsewhere + return; + } + SDL_DestroyAudioStream(m->stream); // closes the old device; returns once its callback has finished + m->stream = s; + m->open_id = id; + m->failed_id = 0; + // No callback runs until the resume: its prefill starts over, and the render thread paces by its timer (pulled_ns + // 0) until the new device asks for audio. The ring and the game go on; ring_pull trims what piled up meanwhile. + m->ready = 0; + atomic_store_explicit(&m->pulled_ns, 0, memory_order_release); SDL_AudioSpec dev = {0}; - int period = 0; - if (!SDL_GetAudioDeviceFormat(SDL_GetAudioStreamDevice(m->stream), &dev, &period) || period <= 0) period = m->frame; - m->period = period; - m->target = m->frame * m->prefill > 2 * period ? m->frame * m->prefill : 2 * period; - if (m->target > RING_FRAMES / 2) m->target = RING_FRAMES / 2; - uint64_t period_ns = (uint64_t)period * 1000000000ull / (uint64_t)rate; - m->stall_ns = 4 * period_ns > STALL_MS * 1000000ull ? 4 * period_ns : STALL_MS * 1000000ull; - const char *name = SDL_GetAudioDeviceName(SDL_GetAudioStreamDevice(m->stream)); - rt_log("audio: SDL device '%s' opened, %d Hz %s float (device %d channels), prefill %d ms, device period %d frames; " - "the device paces rendering at %.1f ms queued", name ? name : "?", rate, m->channels == 6 ? "5.1" : "stereo", - dev.channels, m->prefill * 5, period, m->target * 1000.0 / rate); + output_timing(m, &dev); + if (!SDL_ResumeAudioStreamDevice(s)) rt_log("audio: starting the output failed (%s)", SDL_GetError()); + output_log(m, "switched to", &dev); +} + +static void output_worker(void *p) { + Mixer *m = p; + while (!atomic_load(&m->worker_quit)) { + const char *want = cfg_get("TOTK_AUDIO_DEVICE"); + int found; + SDL_AudioDeviceID id = device_pick(want, &found); + if (id != m->open_id && id != m->failed_id) { + if (!found) rt_log("audio: TOTK_AUDIO_DEVICE '%s' is not connected: switching to the system default", want); + output_switch(m, id); + } + if (id == m->open_id) m->failed_id = 0; + plat_event_wait_ns(&m->wake, 1000000000ull); + } +} + +static void output_worker_start(Mixer *m) { + plat_event_init(&m->wake, 0, 0); + m->worker = plat_thread_new(output_worker, m, "audio-out"); + if (!m->worker) rt_log("audio: no output worker thread: the device stays as it is until the next start"); +} + +// Render thread: wakes the worker when cfg changed, or starts it when a device is chosen for the first time. Until the +// worker runs the stream plays on the system default (output_open), so an unset setting costs this check alone. +static void output_watch(Mixer *m) { + unsigned ver = cfg_version(); + if (ver == m->watch_ver) return; + m->watch_ver = ver; + if (m->worker) plat_event_set(&m->wake); + else if (!device_is_default(cfg_get("TOTK_AUDIO_DEVICE"))) output_worker_start(m); } int64_t audio_mixer_pace_ns(AudioRenderer *r, uint64_t now) { Mixer *m = r->mixer; + if (m && m->device_ok) output_watch(m); if (!m || !m->device_ok || !atomic_load_explicit(&m->playing, memory_order_acquire)) return -1; uint64_t pulled = atomic_load_explicit(&m->pulled_ns, memory_order_acquire); - if (!pulled || (now > pulled && now - pulled > m->stall_ns)) return -1; + if (!pulled || (now > pulled && now - pulled > __atomic_load_n(&m->stall_ns, __ATOMIC_RELAXED))) return -1; uint64_t have = atomic_load(&m->wr) - atomic_load_explicit(&m->rd, memory_order_acquire); - if (have < (uint64_t)m->target) return 0; - int64_t ns = (int64_t)((have - (uint64_t)m->target + 1) * 1000000000ull / (uint64_t)m->rate); + uint64_t target = (uint64_t)__atomic_load_n(&m->target, __ATOMIC_RELAXED); + if (have < target) return 0; + int64_t ns = (int64_t)((have - target + 1) * 1000000000ull / (uint64_t)m->rate); return ns < 500000 ? 500000 : ns; // until the device has taken it below the target } @@ -438,6 +560,11 @@ void audio_mixer_set_running(AudioRenderer *r, int running) { void audio_mixer_close(AudioRenderer *r) { Mixer *m = r->mixer; if (!m) return; + if (m->worker) { // the render thread is joined: nothing wakes or starts the worker any more + atomic_store(&m->worker_quit, 1); + plat_event_set(&m->wake); + plat_thread_join(m->worker); + } if (m->stream) { // destroying the stream closes the device and waits for the callback to finish SDL_DestroyAudioStream(m->stream); SDL_QuitSubSystem(SDL_INIT_AUDIO); diff --git a/runtime/audren.h b/runtime/audren.h index 159f9af4..7b3172fb 100644 --- a/runtime/audren.h +++ b/runtime/audren.h @@ -186,6 +186,10 @@ void audio_mixer_render(AudioRenderer *r, double seconds); // after audio_voic // many ns (the ring is at its target), -1 leaves the pace to the render thread's timer (no device, renderer stopped, // device stalled). int64_t audio_mixer_pace_ns(AudioRenderer *r, uint64_t now); +// The playback devices SDL lists now, by name (TOTK_AUDIO_DEVICE takes one), at most max; 0 while SDL audio is not up +// (TOTK_AUDIO=none). Any thread; the Sound tab of the menu lists them. +enum { AUDIO_DEVICE_NAME_MAX = 256 }; +int audio_output_devices(char (*names)[AUDIO_DEVICE_NAME_MAX], int max); uint64_t audio_voice_consumed(const AudioRenderer *r, ServerVoice *v, int frames); // source samples over one frame; advances v->fraction int audio_buffer_empty(const AudrenWaveBuffer *b); // no samples to decode: played as soon as it is reached void audio_device_handler(IpcSession *s, const IpcRequest *rq, IpcResponse *rs); // IAudioDevice diff --git a/runtime/cfg.c b/runtime/cfg.c index bcbaadc3..9d0aafe5 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -32,7 +32,7 @@ static int save_ok = 1; // the last cfg_save_to wrote (o // logged as unknown. A new variable goes here too, or its ini key logs a harmless "unknown key" line, and gets a // description in totk.ini.example or docs/settings.md (tests/settings_doc_check.py checks both). static const char *const known[] = { - "AB", "ABILITY_GUARD", "AMIIBO_DIR", "ANISO", "APP_POOL", "ASPECT", "ASPECT_PATCH", "ASSUME_FOCUS", "ASTC", "ASTC_BC", "ASTC_TIME", "ASYNC_PREEMPT", "AUDIO", "AUDIO_CHANNELS", "AUDIO_OFF", "AUDIO_PREFILL_MS", + "AB", "ABILITY_GUARD", "AMIIBO_DIR", "ANISO", "APP_POOL", "ASPECT", "ASPECT_PATCH", "ASSUME_FOCUS", "ASTC", "ASTC_BC", "ASTC_TIME", "ASYNC_PREEMPT", "AUDIO", "AUDIO_CHANNELS", "AUDIO_DEVICE", "AUDIO_OFF", "AUDIO_PREFILL_MS", "BACKGROUND_WINDOW", "BIND_A", "BIND_B", "BIND_DOWN", "BIND_L", "BIND_LCLICK", "BIND_LEFT", "BIND_LSTICK_DOWN", "BIND_LSTICK_LEFT", "BIND_LSTICK_RIGHT", "BIND_LSTICK_UP", "BIND_MINUS", "BIND_PLUS", "BIND_R", "BIND_RCLICK", "BIND_RIGHT", "BIND_RSTICK_DOWN", "BIND_RSTICK_LEFT", "BIND_RSTICK_RIGHT", "BIND_RSTICK_UP", @@ -91,6 +91,7 @@ static const struct { const char *key, *section; } sections[] = { {"TEX_HEAP_EXTRA_MB", "mods"}, {"MENU_LANG", "language"}, {"MENU_FONT_FONTCONFIG", "language"}, {"LANG", "language"}, {"OPERATION_MODE", "language"}, {"VOLUME", "audio"}, {"VOLUME_MUSIC", "audio"}, {"VOLUME_SFX", "audio"}, {"VOLUME_VOICE", "audio"}, {"AUDIO_CHANNELS", "audio"}, + {"AUDIO_DEVICE", "audio"}, {"MOTION", "input"}, {"RUMBLE_STRENGTH", "input"}, {"RUMBLE_CURVE", "input"}, {"RUMBLE_TRIGGERS", "input"}, {"PAD_LAYOUT", "input"}, {"PROMPTS", "input"}, {"STICK_DEADZONE", "input"}, {"LSTICK_DEADZONE", "input"}, {"RSTICK_DEADZONE", "input"}, {"STICK_SENS", "input"}, @@ -162,6 +163,7 @@ static const CfgMeta metas[] = { {"ASSUME_FOCUS", "1", "0|1", LIVE}, // read on every focus change (ov_system.c) // Sound, Controls, Menu {"VOLUME", "100", "0..100", LIVE}, {"VOLUME_MUSIC", "100", "0..100", LIVE}, {"VOLUME_SFX", "100", "0..100", LIVE}, {"VOLUME_VOICE", "100", "0..100", LIVE}, {"AUDIO_CHANNELS", "stereo", "auto|stereo|5.1", RESTART}, + {"AUDIO_DEVICE", "", NULL, LIVE}, // audio_mixer.c output_worker: a device name, empty for the system default {"MOTION", "1", "0|1", LIVE}, {"RUMBLE_STRENGTH", "130", "0..300", LIVE}, {"RUMBLE_CURVE", "0.6", "0.2..1.5", LIVE}, {"RUMBLE_TRIGGERS", "0", "0|1", LIVE}, {"PAD_LAYOUT", "auto", "auto|nintendo|xbox", LIVE}, {"PROMPTS", "nintendo", "nintendo|xbox|pc", RESTART}, diff --git a/runtime/ui/menu.cpp b/runtime/ui/menu.cpp index 44031fcd..ec9fbec4 100644 --- a/runtime/ui/menu.cpp +++ b/runtime/ui/menu.cpp @@ -58,6 +58,9 @@ extern const int rt_game_version; extern const char rt_port_version[]; void cheats_frame(uint64_t frame); // cheats.c bool tab_cheats(float scale); // ui/cheats_tab.cpp; true: restart into the rebuild +// audren.h pulls in cpu.h through host.h: the one call the Sound tab needs from it, as declared there. +enum { AUDIO_DEVICE_NAME_MAX = 256 }; +int audio_output_devices(char (*names)[AUDIO_DEVICE_NAME_MAX], int max); int playtime_get(uint64_t *total_s, uint64_t *session_s); // playtime.c bool amiibo_check_font_rebuild(void); // ui/amiibo_page.cpp; check and clear font rebuild request } @@ -768,6 +771,33 @@ static void tab_game(float scale) { opt_end(); } +// The output device row: System default (TOTK_AUDIO_DEVICE unset) and the playback devices SDL lists, by name. The list +// is read again when the tab comes into view and once a second while it shows, so a device plugged in or out appears +// without reopening the menu. A chosen device that is unplugged keeps its name as the value; the mixer plays on the +// system default meanwhile (audio_mixer.c output_worker). +enum { MAX_AUDIO_DEVICES = 16 }; +static char g_audio_names[MAX_AUDIO_DEVICES][AUDIO_DEVICE_NAME_MAX]; +static int g_audio_n; + +static void row_audio_device(void) { + static int last_frame = -2; + static double next_list; + int frame = ImGui::GetFrameCount(); + double now = ImGui::GetTime(); + if (frame != last_frame + 1 || now >= next_list) { + g_audio_n = audio_output_devices(g_audio_names, MAX_AUDIO_DEVICES); + next_list = now + 1.0; + } + last_frame = frame; + const char *vals[MAX_AUDIO_DEVICES + 1], *names[MAX_AUDIO_DEVICES + 1]; + vals[0] = ""; + names[0] = menu_text(UI_MENU_AUDIO_DEVICE_DEFAULT); + for (int i = 0; i < g_audio_n; i++) vals[i + 1] = names[i + 1] = g_audio_names[i]; + int cur = strcmp(cfg_value("TOTK_AUDIO_DEVICE"), "default") ? -1 : 0; // "default" in totk.ini is the first row + opt_choice_list("TOTK_AUDIO_DEVICE", UI_MENU_AUDIO_DEVICE, vals, names, g_audio_n + 1, UI_MENU_AUDIO_DEVICE_DESC, + cur); +} + static void tab_sound(float scale) { opt_begin("##sound", scale); opt_slider("TOTK_VOLUME", UI_MENU_VOLUME, 0, 100, UI_MENU_VOLUME_DESC, 5, "%.0f %%"); @@ -776,6 +806,7 @@ static void tab_sound(float scale) { opt_slider("TOTK_VOLUME_VOICE", UI_MENU_VOLUME_VOICE, 0, 100, UI_MENU_VOLUME_VOICE_DESC, 5, "%.0f %%"); static const UiTextId channels[] = {UI_MENU_CHANNELS_AUTO, UI_MENU_CHANNELS_STEREO, UI_MENU_CHANNELS_51}; opt_choice("TOTK_AUDIO_CHANNELS", UI_MENU_AUDIO_CHANNELS, channels, 3, UI_MENU_AUDIO_CHANNELS_DESC); + row_audio_device(); opt_end(); } diff --git a/runtime/ui_text.c b/runtime/ui_text.c index 3fe121c3..d3392591 100644 --- a/runtime/ui_text.c +++ b/runtime/ui_text.c @@ -249,6 +249,11 @@ static const char *const text_en[UI_TEXT_COUNT] = { [UI_MENU_AUDIO_CHANNELS_DESC] = "Stereo or 5.1 surround output. Automatic picks 5.1 when the Windows speaker setup " "has six or more channels. Applies after a restart.", [UI_MENU_CHANNELS_AUTO] = "Automatic", [UI_MENU_CHANNELS_STEREO] = "Stereo", [UI_MENU_CHANNELS_51] = "5.1 surround", + [UI_MENU_AUDIO_DEVICE] = "Output device", + [UI_MENU_AUDIO_DEVICE_DESC] = "Where the sound plays. System default follows the Windows default device. A chosen " + "device that is unplugged falls back to the system default until it is back. " + "Applies at once.", + [UI_MENU_AUDIO_DEVICE_DEFAULT] = "System default", [UI_MENU_MOTION] = "Motion controls", [UI_MENU_MOTION_DESC] = "Aiming with the controller's gyroscope.", [UI_MENU_RUMBLE_STRENGTH] = "Vibration strength", @@ -781,6 +786,11 @@ static const char *const text_ru[UI_TEXT_COUNT] = { [UI_MENU_AUDIO_CHANNELS_DESC] = "Стерео или объёмный звук 5.1. Автоматически выбирается 5.1, если в Windows " "настроено шесть каналов или больше. Применяется после перезапуска.", [UI_MENU_CHANNELS_AUTO] = "Автоматически", [UI_MENU_CHANNELS_STEREO] = "Стерео", [UI_MENU_CHANNELS_51] = "Объёмный 5.1", + [UI_MENU_AUDIO_DEVICE] = "Устройство вывода", + [UI_MENU_AUDIO_DEVICE_DESC] = "Куда выводится звук. Системное по умолчанию следует за устройством по умолчанию " + "в Windows. Если выбранное устройство отключить, звук идёт на системное, пока оно " + "не вернётся. Применяется сразу.", + [UI_MENU_AUDIO_DEVICE_DEFAULT] = "Системное по умолчанию", [UI_MENU_MOTION] = "Управление движением", [UI_MENU_MOTION_DESC] = "Прицеливание гироскопом контроллера.", [UI_MENU_RUMBLE_STRENGTH] = "Сила вибрации", @@ -1232,6 +1242,11 @@ static const char *const text_pt_br[UI_TEXT_COUNT] = { [UI_MENU_AUDIO_CHANNELS_DESC] = "Saída estéreo ou surround 5.1. Automático escolhe 5.1 quando a configuração de " "alto-falantes do Windows tem seis canais ou mais. Vale após reiniciar.", [UI_MENU_CHANNELS_AUTO] = "Automático", [UI_MENU_CHANNELS_STEREO] = "Estéreo", [UI_MENU_CHANNELS_51] = "Surround 5.1", + [UI_MENU_AUDIO_DEVICE] = "Dispositivo de saída", + [UI_MENU_AUDIO_DEVICE_DESC] = "Onde o som toca. Padrão do sistema segue o dispositivo padrão do Windows. Um " + "dispositivo escolhido que for desconectado volta ao padrão do sistema até " + "reaparecer. Vale na hora.", + [UI_MENU_AUDIO_DEVICE_DEFAULT] = "Padrão do sistema", [UI_MENU_MOTION] = "Controles de movimento", [UI_MENU_MOTION_DESC] = "Mirar com o giroscópio do controle.", [UI_MENU_RUMBLE_STRENGTH] = "Intensidade da vibração", @@ -1846,6 +1861,10 @@ static const char *const text_zh_hans[UI_TEXT_COUNT] = { [UI_MENU_AUDIO_CHANNELS] = "扬声器", [UI_MENU_AUDIO_CHANNELS_DESC] = "立体声或 5.1 环绕声输出。选择自动时,若 Windows 扬声器设置有六个或更多声道则使用 5.1。重启后生效。", [UI_MENU_CHANNELS_AUTO] = "自动", [UI_MENU_CHANNELS_STEREO] = "立体声", [UI_MENU_CHANNELS_51] = "5.1 环绕声", + [UI_MENU_AUDIO_DEVICE] = "输出设备", + [UI_MENU_AUDIO_DEVICE_DESC] = "声音从哪个设备播放。系统默认跟随 Windows 的默认设备。所选设备被拔出时改用系统默认," + "设备重新连接后恢复。立即生效。", + [UI_MENU_AUDIO_DEVICE_DEFAULT] = "系统默认", [UI_MENU_MOTION] = "体感操作", [UI_MENU_MOTION_DESC] = "用手柄的陀螺仪瞄准。", [UI_MENU_RUMBLE_STRENGTH] = "振动强度", diff --git a/runtime/ui_text.h b/runtime/ui_text.h index daec1848..1077e0dd 100644 --- a/runtime/ui_text.h +++ b/runtime/ui_text.h @@ -103,6 +103,7 @@ typedef enum { UI_MENU_VOLUME_SFX, UI_MENU_VOLUME_SFX_DESC, UI_MENU_VOLUME_VOICE, UI_MENU_VOLUME_VOICE_DESC, UI_MENU_AUDIO_CHANNELS, UI_MENU_AUDIO_CHANNELS_DESC, UI_MENU_CHANNELS_AUTO, UI_MENU_CHANNELS_STEREO, UI_MENU_CHANNELS_51, + UI_MENU_AUDIO_DEVICE, UI_MENU_AUDIO_DEVICE_DESC, UI_MENU_AUDIO_DEVICE_DEFAULT, // Controls UI_MENU_MOTION, UI_MENU_MOTION_DESC, diff --git a/totk.ini.example b/totk.ini.example index 90c66f2a..4cc20269 100644 --- a/totk.ini.example +++ b/totk.ini.example @@ -339,6 +339,10 @@ # Speakers: stereo, 5.1 or auto (5.1 when the Windows speaker setup has six or more channels, stereo otherwise). The # game is told the same channel count and mixes for it. Takes effect at the next start. # audio_channels = stereo +# Output device: its name as the Sound tab of the menu lists it (SDL's name, e.g. Speakers (Realtek(R) Audio)), or +# empty / default for the system default device, which follows the Windows default. A named device that is not +# connected plays on the system default until it is back. Changes while the game runs take effect at once. +# audio_device = default [input] # Gamepad motion controls (0 = off) and vibration (0 = off).