Files
breeze/tests/voice_audio_play_behavior.zi
waoziandClaude Opus 5.5 054a29f02c Remove raylib: run every host on Kryon and Ziran
Breeze builds and runs with no raylib anywhere, on Ziran 7fbc8152 and
Kryon b5a61b37, with plot, entity, apps, css and game2d pinned to that
Kryon, so the lock has one Kryon and no raylib package.

- Linux and Windows run on Kryon's SDL2 and Cairo desktop host; WebP
  decodes with the linked libwebp (KRYON_WEBP_LINKED).
- Android owns its NativeActivity loop on Kryon's android_runtime:
  Pixmap on the activity's surface, android_touch input and Android's
  typefaces, paced to the app's frame target. The CMake build drops
  breeze_raylib, GLES and the raylib link wraps, and links Kryon's fopen
  wrapper.
- The browser reaches Kryon's canvas modules directly.
- Audio is Ziran's std audio: its mixer, the SDL, AAudio and OpenSL ES
  sinks, the WAV, MP3 and Vorbis decoders and the audio package's Opus.
  The MP3 and Vorbis archives come from Ziran's own codec recipes. The
  browser keeps Kryon's Web Audio.
- Host modules choose the desktop host, Android, the canvas or, for
  native tests that select none, a headless host with no window, input
  or audio device. host_keys.zi and text_input_host.zi replace
  raylib_host.zi and raylib_text_input.zi; the log is one implementation,
  with logcat on Android and the C runtime's open flags on Windows.
- The Makefile, Click packaging, CI and release workflows build no raylib.
- Tests: radio, app log, asset files, DPI, legacy sessions, sync recovery
  and the Android JNI bridge run without raylib stubs; voice playback is
  a Ziran test of real Ogg Opus narration through Ziran's mixer. Tests
  that only exercised raylib internals are removed.
- AppsControllerSha256 is the controller built from Apps b96d9afe on
  this graph.

Local tests: Linux desktop window, Habits UI and the Ziran and native
tests above pass on a private Xvfb; the Android debug APK runs on a
Pixel 4a; the Windows package runs under Wine on a private Xvfb.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-18 13:16:23 -03:00

80 lines
3.1 KiB
Ziran

// Real Ogg Opus narration and Lumi guide lines play to their end through
// Ziran's mixer and the audio package's Opus decoder, as voice_audio's
// provider plays them: each clip renders its full encoded length with finite,
// audible samples, and a pause holds its place until it resumes.
//
// voice_audio_play_behavior CLIP.ogg...
Mixer :: #import "std/audio";
#import "audio/decode_opus"
#import "std/file"
#import "std/byte_text_linux"
#import, file "../src/app/ogg_length.zi";
// Ten milliseconds of mixed stereo at the mixer's rate.
BLOCK_FRAMES :: 480
// Renders blocks until VOICE stops playing; the frames it rendered while
// playing, or -1 when a sample is not finite or out of range.
PlayToEnd :: (voice: Mixer.AudioVoice, limit: s64, energy: *float64) -> s64 {
output: [BLOCK_FRAMES * 2]float32
frames: s64 = 0
while Mixer.AudioPlaying(voice) && frames < limit {
Mixer.AudioRender(output[:], BLOCK_FRAMES)
for sample: output {
if sample != sample || sample > 1.000001 || sample < -1.000001 {
return -1
}
energy.* += ifx sample < 0.0 then cast(float64)-sample else cast(float64)sample
}
frames += BLOCK_FRAMES
}
return frames
}
// The clip at PATH plays to its end with a pause in the middle; 0 when it
// does, or the failed check.
PlayClip :: (path: string) -> s32 {
bytes, ok := ReadEntireFile(path)
if !ok || bytes.count == 0 { return 2 }
expected := OggClipMilliseconds(bytes)
if expected < 200 { return 3 }
voice := Mixer.AudioLoad(bytes, true)
if voice.slot < 0 { return 4 }
defer { Mixer.AudioUnload(voice) }
if !Mixer.AudioPlay(voice) { return 5 }
limit := cast(s64)expected * cast(s64)Mixer.AUDIO_RATE / 1000 * 2
energy: float64 = 0.0
// A quarter of the clip, then a pause that renders nothing of it.
first := PlayToEnd(voice, cast(s64)expected * cast(s64)Mixer.AUDIO_RATE / 4000, *energy)
if first < 0 { return 6 }
Mixer.AudioPause(voice)
if Mixer.AudioState(voice) != .Paused { return 7 }
held := Mixer.AudioPosition(voice)
silence: [BLOCK_FRAMES * 2]float32
for round: 0..9 {
unused round
Mixer.AudioRender(silence[:], BLOCK_FRAMES)
}
if Mixer.AudioPosition(voice) != held { return 8 }
Mixer.AudioResume(voice)
rest := PlayToEnd(voice, limit, *energy)
if rest < 0 { return 9 }
if Mixer.AudioState(voice) != .Finished { return 10 }
played := (first + rest) * 1000 / cast(s64)Mixer.AUDIO_RATE
// The last block may run past the end; the decoder's pre-skip trims the
// start. Both stay within a few blocks of the encoded length.
if played < cast(s64)expected - 40 || played > cast(s64)expected + 40 { return 11 }
if energy / cast(float64)((first + rest) * 2) < 0.0005 { return 12 }
return 0
}
#program_export
main :: (argc: s32, argv: **u8) -> s32 {
if argc < 2 { return 1 }
for index: cast(s32)1..argc - 1 {
failed := PlayClip(TextFromCString(argv[index]))
if failed != 0 { return failed * 100 + index }
}
return 0
}