Load cue sounds when wanted and restart stale sync pages
The breath and bell cues are Practices assets. Startup loaded them while Practices was still opening, so the lookup failed once and the cues stayed silent. Cues now load when first played and retry after the asset generation changes. Background sync kept failing with result 6 because a paged download resumed from a cursor older than since_server_version, which Daochi rejects with 400. daochi-client now restarts such a page.
This commit is contained in:
1 parent
39df1dffc8
commit
a21f90b858
9 files changed
+165
-39
No files matched your search
@@ -12,6 +12,8 @@
|
||||
- Pictures in a practice no longer flicker while its narration downloads.
|
||||
- Sun Salutation narration speaks every pose and names the leg in each lunge.
|
||||
- Sun Salutation guides each pose with a form cue, the leg that steps back and the next pose, settles in before the first round and rests after the last.
|
||||
- Breath and bell cues play even when Practices is still loading at startup.
|
||||
- Sync recovers when an earlier full download stopped partway.
|
||||
|
||||
## [2.1.61] - 2026-10-29
|
||||
|
||||
|
||||
+48
-7
@@ -151,10 +151,11 @@ app_play_breath_cue :: (app: *InnerBreeze, dir: s32) {
|
||||
return
|
||||
}
|
||||
app_audio_ensure_ready(app)
|
||||
sound = app.breath_out_sound
|
||||
cue: s32 = AUDIO_CUE_BREATH_OUT
|
||||
if dir == 0 {
|
||||
sound = app.breath_in_sound
|
||||
cue = AUDIO_CUE_BREATH_IN
|
||||
}
|
||||
sound = app_audio_cue_sound(app, cue)
|
||||
app_play_sound_pitch(app, sound, scale, app_breath_cue_pitch(app))
|
||||
}
|
||||
|
||||
@@ -164,7 +165,7 @@ app_play_bell_cue :: (app: *InnerBreeze, scale: float32) {
|
||||
return
|
||||
}
|
||||
app_audio_ensure_ready(app)
|
||||
app_play_sound(app, app.bell_sound, scale)
|
||||
app_play_sound(app, app_audio_cue_sound(app, AUDIO_CUE_BELL), scale)
|
||||
}
|
||||
|
||||
#program_export
|
||||
@@ -189,6 +190,9 @@ app_audio_output_level :: (app: *InnerBreeze) -> float32 {
|
||||
return app.audio_meter_level
|
||||
}
|
||||
|
||||
// The asset generation, plus one, of each cue's last load; zero when none.
|
||||
cue_sound_attempts: [AUDIO_CUE_COUNT]u64;
|
||||
|
||||
#program_export
|
||||
unload_cue_sounds :: (app: *InnerBreeze) {
|
||||
empty: SoundHandle
|
||||
@@ -202,6 +206,9 @@ unload_cue_sounds :: (app: *InnerBreeze) {
|
||||
app.breath_in_sound = empty
|
||||
app.breath_out_sound = empty
|
||||
app.bell_sound = empty
|
||||
for cue: cast(s32)0..AUDIO_CUE_COUNT - 1 {
|
||||
cue_sound_attempts[cue] = 0
|
||||
}
|
||||
}
|
||||
|
||||
load_cue_sound :: (app: *InnerBreeze, cue: s32) -> SoundHandle {
|
||||
@@ -219,15 +226,50 @@ load_cue_sound :: (app: *InnerBreeze, cue: s32) -> SoundHandle {
|
||||
return load_sound_asset(app_audio_cue_default_asset(cue))
|
||||
}
|
||||
|
||||
cue_sound_slot :: (app: *InnerBreeze, cue: s32) -> *SoundHandle {
|
||||
if cue == AUDIO_CUE_BREATH_IN {
|
||||
return *app.breath_in_sound
|
||||
}
|
||||
if cue == AUDIO_CUE_BREATH_OUT {
|
||||
return *app.breath_out_sound
|
||||
}
|
||||
if cue == AUDIO_CUE_BELL {
|
||||
return *app.bell_sound
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
// A cue's sound, loaded the first time it is wanted. The default cues are
|
||||
// Practices' assets, and Practices is still opening on its own thread when
|
||||
// audio starts. A cue that could not be read is read again only after the
|
||||
// assets change, as when Practices finishes opening.
|
||||
#program_export
|
||||
app_audio_cue_sound :: (app: *InnerBreeze, cue: s32) -> SoundHandle {
|
||||
empty: SoundHandle
|
||||
if app == null || app.audio_ready == 0 || cue < 0 || cue >= AUDIO_CUE_COUNT {
|
||||
return empty
|
||||
}
|
||||
slot := cue_sound_slot(app, cue)
|
||||
if slot == null {
|
||||
return empty
|
||||
}
|
||||
if slot.frame_count == 0 {
|
||||
attempt := AssetGeneration() + 1
|
||||
if cue_sound_attempts[cue] != attempt {
|
||||
cue_sound_attempts[cue] = attempt
|
||||
slot.* = load_cue_sound(app, cue)
|
||||
}
|
||||
}
|
||||
return slot.*
|
||||
}
|
||||
|
||||
// A changed cue choice loads when the cue is next wanted.
|
||||
#program_export
|
||||
app_audio_reload_cue_sounds :: (app: *InnerBreeze) {
|
||||
if app == null || app.audio_ready == 0 {
|
||||
return
|
||||
}
|
||||
unload_cue_sounds(app)
|
||||
app.breath_in_sound = load_cue_sound(app, AUDIO_CUE_BREATH_IN)
|
||||
app.breath_out_sound = load_cue_sound(app, AUDIO_CUE_BREATH_OUT)
|
||||
app.bell_sound = load_cue_sound(app, AUDIO_CUE_BELL)
|
||||
}
|
||||
|
||||
#program_export
|
||||
@@ -243,7 +285,6 @@ init_audio :: (app: *InnerBreeze) {
|
||||
return
|
||||
}
|
||||
AudioTrace(LOG_INFO, "AUDIO: Audio device initialized")
|
||||
app_audio_reload_cue_sounds(app)
|
||||
audio_attach_mixed_processor(audio_mixed_meter)
|
||||
app.audio_meter_attached = 1
|
||||
}
|
||||
|
||||
@@ -174,24 +174,6 @@ settings_audio_dialog_finish :: (app: *InnerBreeze) -> s32 {
|
||||
return action
|
||||
}
|
||||
|
||||
settings_audio_cue_sound :: (app: *InnerBreeze, cue: s32) -> SoundHandle {
|
||||
empty: SoundHandle = .{0 }
|
||||
|
||||
if app == null {
|
||||
return empty
|
||||
}
|
||||
if cue == AUDIO_CUE_BREATH_IN {
|
||||
return app.breath_in_sound
|
||||
}
|
||||
if cue == AUDIO_CUE_BREATH_OUT {
|
||||
return app.breath_out_sound
|
||||
}
|
||||
if cue == AUDIO_CUE_BELL {
|
||||
return app.bell_sound
|
||||
}
|
||||
return empty
|
||||
}
|
||||
|
||||
#program_export
|
||||
settings_audio_stop_preview :: (app: *InnerBreeze) {
|
||||
if app != null {
|
||||
@@ -242,7 +224,7 @@ settings_audio_music_volume :: (app: *InnerBreeze) -> float32 {
|
||||
}
|
||||
|
||||
settings_audio_preview_cue_playing :: (app: *InnerBreeze, cue: s32) -> s32 {
|
||||
sound := settings_audio_cue_sound(app, cue)
|
||||
sound := app_audio_cue_sound(app, cue)
|
||||
if app == null || app.audio_ready == 0 || sound.frame_count == 0 {
|
||||
return 0
|
||||
}
|
||||
@@ -264,7 +246,7 @@ settings_audio_preview_music_playing :: (index: s32) -> s32 {
|
||||
}
|
||||
|
||||
settings_audio_toggle_cue_preview :: (app: *InnerBreeze, cue: s32) {
|
||||
sound := settings_audio_cue_sound(app, cue)
|
||||
sound := app_audio_cue_sound(app, cue)
|
||||
|
||||
if app == null || app.audio_ready == 0 || sound.frame_count == 0 {
|
||||
settings_screen_set_status_error(LocaleText("audio_preview_failed"))
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
|
||||
bin=${1:-"$root/build/ziran-toolchain/bin"}
|
||||
work=$root/build/audio-cue-assets
|
||||
generated=$work/generated
|
||||
mkdir -p "$generated"
|
||||
"$bin/ziran" build --target=c --define PLATFORM_DESKTOP --root "$root/tests" \
|
||||
--module-path "$root/src" --module-path "$root/build/packages/kryon/src/ui" \
|
||||
--module-path "$root/build/packages/kryon/src/backend" --module-path "$root/build/packages/ziran/std" \
|
||||
--module-path "$root/build/packages/daochi-client" --module-path "$root/build/packages/kss/src" \
|
||||
--module-path "$root/build/packages/game2d/src" $(sh "$root/scripts/package-paths.sh" "$root/build/packages") \
|
||||
-o "$generated" "$root/tests/audio_cue_assets_test.zi"
|
||||
# No embedded sounds: the cues come only from the Practices package.
|
||||
python3 "$root/scripts/embed-app-assets.py" "$work/assets.c"
|
||||
"${CC:-cc}" -std=c11 -O0 -ffunction-sections -fdata-sections \
|
||||
-I"$root/build/packages/ziran/include" -I"$generated" -I"$root/src/app" \
|
||||
"$generated"/*.c "$work/assets.c" "$root/tests/audio_first_cue_host.c" \
|
||||
-Wl,--gc-sections -lm -o "$work/test"
|
||||
env -u DISPLAY -u WAYLAND_DISPLAY -u XAUTHORITY -u DBUS_SESSION_BUS_ADDRESS "$work/test"
|
||||
echo 'Cue sounds load when wanted and again once Practices finishes opening'
|
||||
@@ -0,0 +1,56 @@
|
||||
#import, file "../src/app/audio.zi";
|
||||
#import, file "../src/app/app_types.zi";
|
||||
#import, file "../src/app/assets.zi";
|
||||
#import, file "../src/platform/media_types.zi";
|
||||
#import, file "../src/core/breath_timing.zi";
|
||||
c :: #system_library "c";
|
||||
AudioErrorCount :: () -> s32 #foreign c;
|
||||
PlayedCount :: () -> s32 #foreign c;
|
||||
|
||||
// Practices supplies the cue sounds; it is still opening when audio starts.
|
||||
practices_open: bool;
|
||||
cue_reads: s32;
|
||||
|
||||
PracticesAsset :: (path: string) -> AssetView {
|
||||
if path.count < 14 || path[:14] != "assets/sounds/" {
|
||||
return AssetView.{}
|
||||
}
|
||||
cue_reads += 1
|
||||
if !practices_open {
|
||||
return AssetView.{}
|
||||
}
|
||||
return AssetView.{.data = "OggS cue", .mime = "audio/ogg", .found = true}
|
||||
}
|
||||
|
||||
#program_export
|
||||
main :: () -> s32 {
|
||||
AssetBindProvider(PracticesAsset)
|
||||
app: InnerBreeze
|
||||
app.sound_volume = 100
|
||||
app.breathing.speed_level = 1
|
||||
init_audio(*app)
|
||||
if app.audio_ready == 0 { return 1 }
|
||||
// Starting audio reads no cue, so nothing is missing at startup.
|
||||
if cue_reads != 0 || AudioErrorCount() != 0 { return 2 }
|
||||
if app.bell_sound.frame_count != 0 { return 3 }
|
||||
// A cue wanted before Practices opens is read once per asset change.
|
||||
if app_audio_cue_sound(*app, AUDIO_CUE_BELL).frame_count != 0 { return 4 }
|
||||
if app_audio_cue_sound(*app, AUDIO_CUE_BELL).frame_count != 0 { return 5 }
|
||||
if cue_reads != 1 || AudioErrorCount() != 1 { return 6 }
|
||||
// Practices opened: the next request reads it again and plays.
|
||||
practices_open = true
|
||||
AssetNotifyAvailable()
|
||||
app_play_bell_cue(*app, 1.0)
|
||||
if cue_reads != 2 || app.bell_sound.frame_count == 0 || PlayedCount() != 1 { return 7 }
|
||||
// A loaded cue is not read again.
|
||||
app_play_bell_cue(*app, 1.0)
|
||||
if cue_reads != 2 || PlayedCount() != 2 { return 8 }
|
||||
// A changed cue choice loads when next wanted.
|
||||
app_audio_reload_cue_sounds(*app)
|
||||
if app.bell_sound.frame_count != 0 || cue_reads != 2 { return 9 }
|
||||
app_play_breath_cue(*app, 0)
|
||||
if cue_reads != 3 || app.breath_in_sound.frame_count == 0 || PlayedCount() != 3 { return 10 }
|
||||
if AudioErrorCount() != 1 { return 11 }
|
||||
app_audio_shutdown(*app)
|
||||
return 0
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <string.h>
|
||||
|
||||
static bool ready;
|
||||
static int errors;
|
||||
static int initialized;
|
||||
static int played;
|
||||
static unsigned int played_frames;
|
||||
@@ -123,8 +124,13 @@ void app_audio_trace(int level, String message)
|
||||
{
|
||||
if(level >= 5) {
|
||||
fprintf(stderr, "%.*s\n", (int)message.length, message.data);
|
||||
errors++;
|
||||
}
|
||||
assert(level < 5);
|
||||
}
|
||||
|
||||
int AudioErrorCount(void)
|
||||
{
|
||||
return errors;
|
||||
}
|
||||
|
||||
void app_audio_trace_frames(int level, String message, int frames)
|
||||
@@ -162,5 +168,11 @@ bool app_audio_file_readable(Slice path)
|
||||
|
||||
int CheckSound(SoundHandle sound)
|
||||
{
|
||||
return sound.frame_count > 0 && played == initialized && played_frames == sound.frame_count;
|
||||
return errors == 0 && sound.frame_count > 0 && played == initialized &&
|
||||
played_frames == sound.frame_count;
|
||||
}
|
||||
|
||||
int PlayedCount(void)
|
||||
{
|
||||
return played;
|
||||
}
|
||||
@@ -23,3 +23,4 @@ trap 'rm -rf "$work"' EXIT HUP INT TERM
|
||||
-o "$work/test"
|
||||
"$work/test"
|
||||
sh "$root/tests/audio_first_cue_test.sh" "$bin"
|
||||
sh "$root/tests/audio_cue_assets_test.sh" "$bin"
|
||||
@@ -48,6 +48,7 @@
|
||||
#import, file "../src/storage/sync_session.zi";
|
||||
#import, file "../src/storage/sync_page_store.zi";
|
||||
#import "sync_flow"
|
||||
#import "c_string"
|
||||
#import "auth"
|
||||
#import "file_linux"
|
||||
|
||||
@@ -516,6 +517,16 @@ Check :: () -> s32 {
|
||||
unused idle
|
||||
check_int("unchanged paged sync succeeds", SyncStoredAccount(url), 0)
|
||||
}
|
||||
// A download that began at a lower position, as a repair from version
|
||||
// zero does, can leave its cursor behind this device's position. The
|
||||
// node refuses such a cursor; the next sync starts the download again.
|
||||
stale_page := SyncPageState.{.enabled = true, .pending = true}
|
||||
check_true("save a cursor behind the position",
|
||||
CopyCString("{\"version\":1,\"collection\":\"private.inbe.v1.habits\",\"id\":\"stale\"}",
|
||||
stale_page.cursor[:]) && SaveStoredSyncPage(url, *stale_page))
|
||||
check_int("a cursor behind the position restarts the download", SyncStoredAccount(url), 0)
|
||||
check_true("the restarted download completes",
|
||||
LoadStoredSyncPage(url, *stale_page) && !stale_page.pending && stale_page.cursor[0] == cast(u8)0)
|
||||
storage_set_setting_text("sync_server_url", url)
|
||||
storage_set_sync_enabled(1)
|
||||
check_int("register alias", RegisterAliasStored(url, alias), 0)
|
||||
|
||||
+10
-10
@@ -60,14 +60,6 @@
|
||||
"ref": "master",
|
||||
"url": "https://github.com/ziranlang/oqs.git"
|
||||
},
|
||||
{
|
||||
"commit": "8250ece58a03f4d9c07cd8434780d659b54f5d7f",
|
||||
"dependencies": {"crypto": "pc23fbf455e97614d", "oqs": "p7098ac9cd92f7e5f"},
|
||||
"id": "p7de54c8ad98fe034",
|
||||
"name": "DaochiClient",
|
||||
"ref": "master",
|
||||
"url": "https://github.com/ziranlang/daochi-client.git"
|
||||
},
|
||||
{
|
||||
"commit": "f5f0a19a5dc6c14a49adb3cd63ea79a60f6ba77b",
|
||||
"dependencies": {},
|
||||
@@ -77,6 +69,14 @@
|
||||
"source": true,
|
||||
"url": "https://github.com/LoupVaillant/Monocypher.git"
|
||||
},
|
||||
{
|
||||
"commit": "256fe6ff049d48a25dfe2a8b0db7ad84477fd282",
|
||||
"dependencies": {"crypto": "pc23fbf455e97614d", "oqs": "p7098ac9cd92f7e5f"},
|
||||
"id": "p89503086b39ba0fb",
|
||||
"name": "DaochiClient",
|
||||
"ref": "master",
|
||||
"url": "https://github.com/ziranlang/daochi-client.git"
|
||||
},
|
||||
{
|
||||
"commit": "39074d35643e055e36b1ffdd90586d65736222d0",
|
||||
"dependencies": {"raylib": "p5a77c9c35110e925"},
|
||||
@@ -103,7 +103,7 @@
|
||||
},
|
||||
{
|
||||
"commit": "33e54462886507cfb355f86e6d2d93cef7b2331c",
|
||||
"dependencies": {"daochi_client": "p7de54c8ad98fe034", "kryon": "p9606a2a69b380df3", "monocypher": "p809b4d31a48625a3", "qrcode": "p0dfa70137405b096"},
|
||||
"dependencies": {"daochi_client": "p89503086b39ba0fb", "kryon": "p9606a2a69b380df3", "monocypher": "p809b4d31a48625a3", "qrcode": "p0dfa70137405b096"},
|
||||
"id": "pb6d17ac2aeb5844f",
|
||||
"name": "Entity",
|
||||
"ref": "master",
|
||||
@@ -154,7 +154,7 @@
|
||||
}
|
||||
],
|
||||
"root": {
|
||||
"dependencies": {"apps": "p9928fc15e7b93288", "crypto": "pc23fbf455e97614d", "curl": "pd4bcd11b7d623073", "daochi_client": "p7de54c8ad98fe034", "entity": "pb6d17ac2aeb5844f", "game2d": "p20eb23d3e6db3711", "kryon": "p9606a2a69b380df3", "kss": "p1b13dda539ed2a39", "liboqs": "p1aaef6f156781e69", "mingcute": "pe1027b9d16704793", "monocypher": "p809b4d31a48625a3", "oqs": "p7098ac9cd92f7e5f", "plot": "pab5377a2950368a2", "practices": "pf4bd8f55c0c2ab4b", "qrcode": "p0dfa70137405b096", "rini": "p09fa77e94b0dfc6c", "sqlite": "peaa43c4b7ef72edf"},
|
||||
"dependencies": {"apps": "p9928fc15e7b93288", "crypto": "pc23fbf455e97614d", "curl": "pd4bcd11b7d623073", "daochi_client": "p89503086b39ba0fb", "entity": "pb6d17ac2aeb5844f", "game2d": "p20eb23d3e6db3711", "kryon": "p9606a2a69b380df3", "kss": "p1b13dda539ed2a39", "liboqs": "p1aaef6f156781e69", "mingcute": "pe1027b9d16704793", "monocypher": "p809b4d31a48625a3", "oqs": "p7098ac9cd92f7e5f", "plot": "pab5377a2950368a2", "practices": "pf4bd8f55c0c2ab4b", "qrcode": "p0dfa70137405b096", "rini": "p09fa77e94b0dfc6c", "sqlite": "peaa43c4b7ef72edf"},
|
||||
"name": "Inbe"
|
||||
},
|
||||
"toolchain": {
|
||||
|
||||
Reference in new issue
Block a user