Add separate Music, SFX, and Voice volume sliders (#722)

Add volume_music, volume_sfx, and volume_voice sliders under the Sound tab
in the F1 settings menu and in totk.ini to control background music, sound
effects, and character voices independently.

Classifies audio streams by file path in RomFS, parses BARS and BWAV headers
for ADPCM coefficient tables and stream formats, tags decompressed Opus streams
from nn::codec, and applies per-category gain factors in the audio mixer
during voice rendering.

Localized across English, Russian, Brazilian Portuguese, and Simplified Chinese.
Documented in totk.ini.example.
This commit is contained in:
0xEmz committed 2026-11-12 17:25:33 +02:00
1 parent 7a37fc3c34
commit 1f224dc0f9
11 files changed
+539 -5

No files matched your search

+18
View File
@@ -38,6 +38,7 @@
#include "mods.h"
#include "romfs_config.h"
#include "romfs_path.h"
#include "audio_cat.h"
#include "platform/platform.h"
#include "restbl.h"
#include "sha256.h"
@@ -69,6 +70,7 @@ static PlatMutex lock = PLAT_MUTEX_INIT;
static uint64_t handles[NH]; // file index + 1; 0 is free
static uint32_t handle_ovl[NH]; // overlay slot + 1 of an open handle, 0 = original
static PlatFile *handle_file[NH]; // the handle's open overlay file, when handle_ovl is set
static uint8_t handle_audio_cat[NH];
static Overlay *overlays; // sorted by RomFS index after overlay_init
static size_t noverlay, overlay_cap;
static char **added; // RomFS paths of the added files, sorted; added[k] is index file_count + k
@@ -1249,12 +1251,20 @@ uint32_t romfs_open(uint64_t *out, const char *path, int mode) {
if (!f || memcmp(&id, &o->id, sizeof id))
rt_fatal("RomFS overlay %s is missing or changed since the start check (restart the game)", o->path);
}
int cat = audio_cat_from_path(p);
if (cat != AUDIO_CAT_UNKNOWN && !ov && image_map && i != UINT64_MAX) {
Entry e = entry(i);
if (e.size >= 0x40) {
audio_cat_scan_bwav(image_map + e.offset, e.size < 4096 ? e.size : 4096, cat);
}
}
plat_mutex_lock(&lock);
for (unsigned j = 1; j < NH; j++)
if (!handles[j]) {
handles[j] = i + 1;
handle_ovl[j] = ov;
handle_file[j] = f;
handle_audio_cat[j] = (uint8_t)cat;
*out = ROMFS_HANDLE_BASE + j;
plat_mutex_unlock(&lock);
return 0;
@@ -1304,6 +1314,13 @@ uint32_t romfs_read(uint64_t *out, uint64_t h, int64_t offset, void *buffer, uin
done += (uint64_t)r;
}
*out = done;
uint64_t j = h - ROMFS_HANDLE_BASE;
if (j < NH && handle_audio_cat[j] != AUDIO_CAT_UNKNOWN && buffer && done > 0) {
if (offset == 0 && done >= 0x40) {
audio_cat_scan_bwav(buffer, done, handle_audio_cat[j]);
}
audio_cat_tag_range((uint64_t)(uintptr_t)buffer, done, handle_audio_cat[j]);
}
return 0;
}
@@ -1326,6 +1343,7 @@ void romfs_close(uint64_t h) {
handles[j] = 0;
handle_ovl[j] = 0;
handle_file[j] = NULL;
handle_audio_cat[j] = 0;
plat_mutex_unlock(&lock);
if (of) plat_file_close(of);
}