Merge task/padaudio: the DualSense touchpad click is a bindable button, and the audio output device can be chosen in the menu and switches while the game runs (#482, #1014)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Valiantsin DzerakhandClaude Opus 5.5 committed 2026-11-14 22:54:36 +03:00
commit 9d05ccd920
13 files changed
+235 -31

No files matched your search

+1 -1
View File
@@ -94,7 +94,7 @@ The *Controls* tab of the settings menu lists, under the button layout, every Sw
The tab writes `totk.ini` lines, one per Switch button or stick direction: `bind_<button> = <entry>, <entry>, ...`. The button is `A B X Y L R ZL ZR PLUS MINUS LEFT UP RIGHT DOWN LCLICK RCLICK`, or a stick direction `LSTICK_LEFT LSTICK_UP LSTICK_RIGHT LSTICK_DOWN` (movement, W A S D by default) and `RSTICK_...` (camera, the arrow keys), or `SHAKE` (keys only, G by default). An entry is `pad:<name>` or `key:<name>`:
- pad names: `south east west north l r zl zr start back lstick rstick dpad_left dpad_up dpad_right dpad_down lpaddle1 rpaddle1 lpaddle2 rpaddle2` (`zl`, `zr` are the triggers; the paddles are the back buttons of an Xbox Elite, DualSense Edge or Steam Controller, upper pair 1, lower pair 2, and no Switch button has them by default)
- pad names: `south east west north l r zl zr start back lstick rstick dpad_left dpad_up dpad_right dpad_down lpaddle1 rpaddle1 lpaddle2 rpaddle2 touchpad` (`zl`, `zr` are the triggers; the paddles are the back buttons of an Xbox Elite, DualSense Edge or Steam Controller, upper pair 1, lower pair 2; `touchpad` is the touchpad click of a DualSense or DualShock 4; no Switch button has the paddles or the touchpad by default)
- key names: `a` to `z`, `0` to `9`, `f2` to `f7`, `f9`, `f12`, `num0` to `num9`, `space tab enter backspace lshift rshift lctrl rctrl lalt capslock insert delete home end pageup pagedown up down left right`, `num_add num_sub num_mul num_div num_decimal`, `minus equals lbracket rbracket semicolon apostrophe comma period slash backslash grave`, `mouse_l mouse_r mouse_m mouse_x1 mouse_x2`
- `key:default` and `pad:default` keep that part's defaults (`pad:default` is each layout's own button).
- `none` leaves the button unbound.
+148 -21
View File
@@ -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);
+4
View File
@@ -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
+3 -1
View File
@@ -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},
+8
View File
@@ -392,6 +392,14 @@ int probe_cfg(void) {
input_map_pad_buttons((uint8_t[PAD_COUNT]){[PAD_ZL] = 1}, PAD_LAYOUT_NINTENDO) == 1ull << B_ZL,
"bind: pad:rpaddle1 adds a back paddle, pad:default keeps the trigger");
input_map_reset();
CHECK(input_map_pad_buttons((uint8_t[PAD_COUNT]){[PAD_TOUCHPAD] = 1}, PAD_LAYOUT_NINTENDO) == 0 &&
input_map_pad_buttons((uint8_t[PAD_COUNT]){[PAD_TOUCHPAD] = 1}, PAD_LAYOUT_XBOX) == 0,
"pad layout: the touchpad click is unbound by default");
CHECK(input_map_bind("MINUS", "pad:default, pad:touchpad") &&
input_map_pad_buttons((uint8_t[PAD_COUNT]){[PAD_TOUCHPAD] = 1}, PAD_LAYOUT_XBOX) == 1ull << B_MINUS &&
input_map_pad_buttons((uint8_t[PAD_COUNT]){[PAD_BACK] = 1}, PAD_LAYOUT_XBOX) == 1ull << B_MINUS,
"bind: pad:touchpad adds the touchpad click, pad:default keeps the button");
input_map_reset();
// Bind lines for stick directions and default parts; the remapping rows' edits (input_map.c)
memset(dn, 0, sizeof dn);
dn[KEY_I] = 1;
+2 -1
View File
@@ -57,6 +57,7 @@ static const SDL_GamepadButton pad_sdl[PAD_COUNT] = {
[PAD_DPAD_RIGHT] = SDL_GAMEPAD_BUTTON_DPAD_RIGHT, [PAD_DPAD_DOWN] = SDL_GAMEPAD_BUTTON_DPAD_DOWN,
[PAD_LPADDLE1] = SDL_GAMEPAD_BUTTON_LEFT_PADDLE1, [PAD_RPADDLE1] = SDL_GAMEPAD_BUTTON_RIGHT_PADDLE1,
[PAD_LPADDLE2] = SDL_GAMEPAD_BUTTON_LEFT_PADDLE2, [PAD_RPADDLE2] = SDL_GAMEPAD_BUTTON_RIGHT_PADDLE2,
[PAD_TOUCHPAD] = SDL_GAMEPAD_BUTTON_TOUCHPAD,
};
// TOTK_INPUT_SCRIPT=<file>: lines "<frame> <button> [hold]", "<frame> LSTICK|RSTICK <x> <y> [hold]", "<frame> MOUSE
@@ -651,7 +652,7 @@ static int pad_physical(uint8_t pd[PAD_COUNT]) {
for (int p = PAD_SOUTH; p < PAD_ZL; p++) pd[p] = SDL_GetGamepadButton(pad, pad_sdl[p]);
pd[PAD_ZL] = SDL_GetGamepadAxis(pad, SDL_GAMEPAD_AXIS_LEFT_TRIGGER) > TRIGGER_ON;
pd[PAD_ZR] = SDL_GetGamepadAxis(pad, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER) > TRIGGER_ON;
for (int p = PAD_ZR + 1; p < PAD_COUNT; p++) pd[p] = SDL_GetGamepadButton(pad, pad_sdl[p]); // false without paddles
for (int p = PAD_ZR + 1; p < PAD_COUNT; p++) pd[p] = SDL_GetGamepadButton(pad, pad_sdl[p]); // false without paddles or touchpad
return 1;
}
+2 -1
View File
@@ -44,7 +44,8 @@ static const char *const action_names[ACTION_COUNT] = {
"LSTICK_LEFT", "LSTICK_UP", "LSTICK_RIGHT", "LSTICK_DOWN", "RSTICK_LEFT", "RSTICK_UP", "RSTICK_RIGHT", "RSTICK_DOWN", "SHAKE"};
static const char *const pad_names[PAD_COUNT] = {
NULL, "south", "east", "west", "north", "lstick", "rstick", "l", "r", "start", "back",
"dpad_left", "dpad_up", "dpad_right", "dpad_down", "zl", "zr", "lpaddle1", "rpaddle1", "lpaddle2", "rpaddle2"};
"dpad_left", "dpad_up", "dpad_right", "dpad_down", "zl", "zr", "lpaddle1", "rpaddle1", "lpaddle2", "rpaddle2",
"touchpad"};
static const char *const key_names[KEY_COUNT] = { // each group starts at its id; the ids of a group are consecutive
[KEY_A] = "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u",
"v", "w", "x", "y", "z",
+4 -3
View File
@@ -37,13 +37,14 @@ enum {
// Gamepad inputs by position (Nintendo layout, as SDL names them), platform-neutral like the key ids. ZL and ZR are the
// analog triggers; input_win.c translates SDL buttons and axes to these (one place). The paddles are the back buttons
// of an Xbox Elite, DualSense Edge or Steam Controller (SDL's LEFT_PADDLE1 and so on); no Switch button has them by
// default, a bind line or the remapping rows add them.
// of an Xbox Elite, DualSense Edge or Steam Controller (SDL's LEFT_PADDLE1 and so on), the touchpad is the click of a
// DualSense or DualShock 4 touchpad (SDL's TOUCHPAD); no Switch button has them by default, a bind line or the
// remapping rows add them. A pad without one never reports it held.
enum {
PAD_NONE = 0,
PAD_SOUTH, PAD_EAST, PAD_WEST, PAD_NORTH, PAD_LSTICK, PAD_RSTICK, PAD_L, PAD_R, PAD_START, PAD_BACK,
PAD_DPAD_LEFT, PAD_DPAD_UP, PAD_DPAD_RIGHT, PAD_DPAD_DOWN, PAD_ZL, PAD_ZR,
PAD_LPADDLE1, PAD_RPADDLE1, PAD_LPADDLE2, PAD_RPADDLE2,
PAD_LPADDLE1, PAD_RPADDLE1, PAD_LPADDLE2, PAD_RPADDLE2, PAD_TOUCHPAD,
PAD_COUNT
};
+1 -1
View File
@@ -21,7 +21,7 @@ void rt_log(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
static_assert(UI_BIND_SHAKE - UI_BIND_A == ACTION_COUNT - 1 && B_SHAKE == ACTION_COUNT - 1, "UI_BIND_* follow the actions");
static_assert(UI_BIND_DESC_MINUS - UI_BIND_DESC_A == B_MINUS, "UI_BIND_DESC_* follow the actions");
static_assert(UI_KEY_PAGEDOWN - UI_KEY_SPACE == KEY_PAGEDOWN - KEY_SPACE, "UI_KEY_* follow the key ids");
static_assert(UI_PAD_RPADDLE2 - UI_PAD_SOUTH == PAD_RPADDLE2 - PAD_SOUTH && PAD_RPADDLE2 == PAD_COUNT - 1,
static_assert(UI_PAD_TOUCHPAD - UI_PAD_SOUTH == PAD_TOUCHPAD - PAD_SOUTH && PAD_TOUCHPAD == PAD_COUNT - 1,
"UI_PAD_* follow the pad ids");
enum { CAPTURE_SECONDS = 5 };
+31
View File
@@ -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();
}
+23
View File
@@ -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",
@@ -394,6 +399,7 @@ static const char *const text_en[UI_TEXT_COUNT] = {
[UI_PAD_DPAD_DOWN] = "D-pad down", [UI_PAD_ZL] = "Left trigger", [UI_PAD_ZR] = "Right trigger",
[UI_PAD_LPADDLE1] = "Left back button", [UI_PAD_RPADDLE1] = "Right back button",
[UI_PAD_LPADDLE2] = "Left back button 2", [UI_PAD_RPADDLE2] = "Right back button 2",
[UI_PAD_TOUCHPAD] = "Touchpad click",
[UI_PAD_CROSS] = "Cross", [UI_PAD_CIRCLE] = "Circle", [UI_PAD_SQUARE] = "Square", [UI_PAD_TRIANGLE] = "Triangle",
[UI_MENU_AMIIBO_DIR] = "Amiibo folder",
@@ -780,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] = "Сила вибрации",
@@ -929,6 +940,7 @@ static const char *const text_ru[UI_TEXT_COUNT] = {
[UI_PAD_ZR] = "Правый курок",
[UI_PAD_LPADDLE1] = "Левая задняя кнопка", [UI_PAD_RPADDLE1] = "Правая задняя кнопка",
[UI_PAD_LPADDLE2] = "Левая задняя кнопка 2", [UI_PAD_RPADDLE2] = "Правая задняя кнопка 2",
[UI_PAD_TOUCHPAD] = "Нажатие на тачпад",
[UI_PAD_CROSS] = "Крест", [UI_PAD_CIRCLE] = "Круг", [UI_PAD_SQUARE] = "Квадрат", [UI_PAD_TRIANGLE] = "Треугольник",
[UI_MENU_AMIIBO_DIR] = "Папка amiibo",
@@ -1230,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",
@@ -1312,6 +1329,7 @@ static const char *const text_pt_br[UI_TEXT_COUNT] = {
[UI_PAD_ZL] = "Gatilho esquerdo", [UI_PAD_ZR] = "Gatilho direito",
[UI_PAD_LPADDLE1] = "Botão traseiro esquerdo", [UI_PAD_RPADDLE1] = "Botão traseiro direito",
[UI_PAD_LPADDLE2] = "Botão traseiro esquerdo 2", [UI_PAD_RPADDLE2] = "Botão traseiro direito 2",
[UI_PAD_TOUCHPAD] = "Clique do touchpad",
[UI_PAD_CROSS] = "Cruz", [UI_PAD_CIRCLE] = "Círculo", [UI_PAD_SQUARE] = "Quadrado", [UI_PAD_TRIANGLE] = "Triângulo",
[UI_MENU_AMIIBO_DIR] = "Pasta de amiibo",
@@ -1843,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] = "振动强度",
@@ -1975,6 +1997,7 @@ static const char *const text_zh_hans[UI_TEXT_COUNT] = {
[UI_PAD_RPADDLE1] = "右背键",
[UI_PAD_LPADDLE2] = "左背键 2",
[UI_PAD_RPADDLE2] = "右背键 2",
[UI_PAD_TOUCHPAD] = "触摸板按下",
[UI_PAD_CROSS] = "叉键",
[UI_PAD_CIRCLE] = "圆圈键",
[UI_PAD_SQUARE] = "方块键",
+3 -2
View File
@@ -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,
@@ -169,10 +170,10 @@ typedef enum {
UI_KEY_ENTER, UI_KEY_BACKSPACE, UI_KEY_RSHIFT, UI_KEY_RCTRL, UI_KEY_LALT, UI_KEY_CAPSLOCK, UI_KEY_INSERT,
UI_KEY_DELETE, UI_KEY_HOME, UI_KEY_END, UI_KEY_PAGEUP, UI_KEY_PAGEDOWN,
UI_KEY_NUM_FMT, // "Num %s": a numpad key
// gamepad buttons, in pad id order PAD_SOUTH .. PAD_RPADDLE2, then the PlayStation face labels
// gamepad buttons, in pad id order PAD_SOUTH .. PAD_TOUCHPAD, then the PlayStation face labels
UI_PAD_SOUTH, UI_PAD_EAST, UI_PAD_WEST, UI_PAD_NORTH, UI_PAD_LSTICK, UI_PAD_RSTICK, UI_PAD_L, UI_PAD_R,
UI_PAD_START, UI_PAD_BACK, UI_PAD_DPAD_LEFT, UI_PAD_DPAD_UP, UI_PAD_DPAD_RIGHT, UI_PAD_DPAD_DOWN, UI_PAD_ZL,
UI_PAD_ZR, UI_PAD_LPADDLE1, UI_PAD_RPADDLE1, UI_PAD_LPADDLE2, UI_PAD_RPADDLE2,
UI_PAD_ZR, UI_PAD_LPADDLE1, UI_PAD_RPADDLE1, UI_PAD_LPADDLE2, UI_PAD_RPADDLE2, UI_PAD_TOUCHPAD,
UI_PAD_CROSS, UI_PAD_CIRCLE, UI_PAD_SQUARE, UI_PAD_TRIANGLE,
// Amiibo tab (ui/amiibo_page.cpp): the dump folder and its files, the emulated NFC reader and its state, the
+5
View File
@@ -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).
@@ -419,6 +423,7 @@
# SHAKE take keys only. Invalid entries are logged and skipped. Changes while the game runs take effect at once.
# pad names: south east west north l r zl zr start back lstick rstick dpad_left dpad_up dpad_right dpad_down
# lpaddle1 rpaddle1 lpaddle2 rpaddle2 (the back buttons of an Xbox Elite, DualSense Edge or Steam Controller)
# touchpad (the touchpad click of a DualSense or DualShock 4)
# key names: a-z 0-9 f2-f7 f9 f12 num0-num9 space tab enter backspace lshift rshift lctrl rctrl lalt capslock insert
# delete home end pageup pagedown up down left right num_add num_sub num_mul num_div num_decimal minus equals
# lbracket rbracket semicolon apostrophe comma period slash backslash grave mouse_l mouse_r mouse_m mouse_x1 mouse_x2