code wiki / _hdl_build / nx_media_audio_page.nx
nx_media_audio_page.nx source
↩ module page · 87 lines · 6518 B
1// nx_media_audio_page.nx -- nishifamily.com/media AUDIO TAB (operator 2026-06-23: "where can I listen to your
2// output -- get nishifamily.com/media to have an audio tab and generate to it"). Emits a SELF-CONTAINED, sovereign
3// HTML page: each generated audio file is read from disk and EMBEDDED as a base64 data-URI inside an <audio controls>
4// element (the nx_audio_web pattern) -> the page PLAYS in any browser with NO separate file + NO server (data URI).
5// Open it locally to listen now; published to sites/nishifamily/media/audio.html for nishifamily.com/media.
6// Sovereign: our own base64 + our own WAV (the audio was made by our own modal synth). license_tier: ORIGINAL expect_exit: 0
7import "nx_base64.nx"
8import "nx_syscalls.nx"
9const K_MAGIC_2097152: i64 = 2097152
10const K_MAGIC_1048576: i64 = 1048576
11const K_MAGIC_1572864: i64 = 1572864
12
13const MLOG: *u8 = "knowledge/status/media_audio.log"
14const OUTP: *u8 = "web_assets/media_audio.html"
15
16func mp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
17func mpn(v: i64) -> i64 {
18 let b: *u8 = sys_mmap(28); var x: i64=v
19 if x<0 { b[0]=45; sys_write(1,b,1); x=0-x }
20 if x==0 { b[0]=48; sys_write(1,b,1); return 0 }
21 var d: i64=0; var y: i64=x; while y>0 { d=d+1; y=y/10 }
22 var i: i64=d-1; y=x; while i>=0 { b[i]=(48+(y%10)) as u8; y=y/10; i=i-1 }
23 sys_write(1,b,d); return 0
24}
25func app(out: *u8, off: *i64, s: *u8) -> i64 { var i: i64=0; while s[i]!=(0 as u8){ out[off[0]]=s[i]; off[0]=off[0]+1; i=i+1 } return 0 }
26func read_file(path: *u8, buf: *u8, cap: i64) -> i64 {
27 let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 - 1 }
28 var total: i64 = 0; var r: i64 = sys_read(fd, buf, cap)
29 while r > 0 { total = total + r; if total >= cap { r = 0 } else { r = sys_read(fd, (buf + total) as *u8, cap - total) } }
30 sys_close(fd); return total
31}
32
33// append one audio track CARD: title + desc + an <audio controls> with the wav embedded as a base64 data-URI.
34// returns the wav byte length read (0 if the file is absent = track skipped).
35func add_track(out: *u8, off: *i64, title: *u8, desc: *u8, wavpath: *u8, wavbuf: *u8, wavcap: i64, b64buf: *u8) -> i64 {
36 let wl: i64 = read_file(wavpath, wavbuf, wavcap)
37 if wl <= 0 { return 0 }
38 let bn: i64 = b64_encode(wavbuf, wl, b64buf)
39 app(out, off, "<div class=trk><h3>" as *u8); app(out, off, title); app(out, off, "</h3><p>" as *u8); app(out, off, desc); app(out, off, "</p>" as *u8)
40 // base64 data-URI src is unquoted-safe (no spaces); ends at '>'
41 app(out, off, "<audio controls preload=none src=data:audio/wav;base64," as *u8)
42 var i: i64 = 0
43 while i < bn { out[off[0]] = b64buf[i]; off[0] = off[0] + 1; i = i + 1 }
44 app(out, off, "></audio></div>\n" as *u8)
45 return wl
46}
47
48func main() -> i64 {
49 mp("nx_media_audio_page: nishifamily.com/media AUDIO TAB (self-contained, base64-embedded, sovereign)\n" as *u8)
50 let out: *u8 = sys_mmap(K_MAGIC_2097152) // 2 MiB page buffer (room for several embedded tracks)
51 let wavbuf: *u8 = sys_mmap(K_MAGIC_1048576) // 1 MiB per-wav read buffer
52 let b64buf: *u8 = sys_mmap(K_MAGIC_1572864) // ~1.5 MiB base64 buffer
53 let off: *i64 = sys_mmap(8) as *i64; off[0] = 0
54
55 app(out, off, "<!doctype html><html lang=en><head><meta charset=utf-8><meta name=viewport content=\x22width=device-width,initial-scale=1\x22><title>Nishi Media — Audio</title>" as *u8)
56 app(out, off, "<style>body{font-family:-apple-system,Segoe UI,Roboto,sans-serif;background:#0f1117;color:#e8eef8;max-width:880px;margin:0 auto;padding:0 18px 7vh}h1{font-size:1.7rem;margin:1.2rem 0 .3rem}nav{display:flex;gap:.5rem;margin:.6rem 0 1.4rem}nav a{padding:.4rem .9rem;border-radius:999px;background:#1b1f2b;color:#9ecbff;text-decoration:none;font-size:.9rem}nav a.on{background:#2a4d8f;color:#fff}.trk{background:#161a24;border:1px solid #232838;border-radius:12px;padding:14px 16px;margin:.8rem 0}.trk h3{margin:0 0 .2rem;font-size:1.05rem}.trk p{margin:0 0 .6rem;color:#9aa6bd;font-size:.85rem}audio{width:100%}.foot{margin-top:1.6rem;color:#6b7793;font-size:.8rem;border-top:1px solid #232838;padding-top:1rem}</style></head><body>" as *u8)
57 app(out, off, "<h1>Nishi Media</h1><nav><a href=/media/>Gallery</a><a href=/media/video.html>Video</a><a class=on href=/media/audio.html>Audio</a></nav>" as *u8)
58 app(out, off, "<p style=\x22color:#9aa6bd;font-size:.9rem;margin-top:-.4rem\x22>Generated entirely by the Nishi audio engine — sovereign modal synthesis + binaural, no third-party. Headphones recommended for binaural.</p>" as *u8)
59
60 var ntr: i64 = 0
61 let b1: i64 = add_track(out, off, "Tibetan Singing Bowl — exact binaural" as *u8,
62 "5 inharmonic resonant modes (2nd-order resonators) placed to your right via ITD + ILD. Rendered to lossless 16-bit stereo by our own RIFF writer." as *u8,
63 "web_assets/ng_singing_bowl_binaural.wav\x00" as *u8, wavbuf, K_MAGIC_1048576, b64buf)
64 if b1 > 0 { ntr = ntr + 1; mp(" + track: singing bowl (" as *u8); mpn(b1); mp(" wav bytes)\n" as *u8) }
65 let b2: i64 = add_track(out, off, "Binaural Beats — 7Hz theta (relaxation / self-hypnosis)" as *u8,
66 "Pure 200Hz (left) + 207Hz (right) sustained tones; the brain perceives a 7Hz theta beat — a self-hypnosis / deep-relaxation aid. Headphones required." as *u8,
67 "web_assets/ng_binaural_beats_theta.wav\x00" as *u8, wavbuf, K_MAGIC_1048576, b64buf)
68 if b2 > 0 { ntr = ntr + 1; mp(" + track: binaural beats (" as *u8); mpn(b2); mp(" wav bytes)\n" as *u8) }
69
70 app(out, off, "<p class=foot>Tracks generate here as the audio ecosystem grows (audiobooks in chosen voices, own-voice translation, self-hypnosis soundscapes). Published via the Nishi Publisher; no link-rot via the library.</p></body></html>\n" as *u8)
71 out[off[0]] = 0 as u8
72
73 let wfd: i64 = sys_openat_wr(OUTP, 420)
74 var wrote: i64 = 0
75 if wfd >= 0 { sys_write(wfd, out, off[0]); sys_close(wfd); wrote = 1 }
76
77 mp(" tracks=" as *u8); mpn(ntr); mp(" page bytes=" as *u8); mpn(off[0]); mp(" wrote=" as *u8); mpn(wrote); mp(" -> " as *u8); mp(OUTP); mp("\n" as *u8)
78
79 var ok: i64 = 1
80 if ntr < 1 { ok = 0 }
81 if off[0] < 1000 { ok = 0 }
82 if wrote != 1 { ok = 0 }
83 mp(" verdict=" as *u8)
84 if ok == 1 { mp("GREEN (self-contained playable audio tab emitted; OPEN web_assets/media_audio.html to listen)\n" as *u8); sys_exit(0); return 0 }
85 mp("RED\n" as *u8)
86 sys_exit(1); return 1
87}