// audio-demo.el - Drive the native audio surface: render a tone per instrument // from its LEARNED signature, then render a small meaning-phrase "piece". // Entry point: top-level statement calls main() (same convention as the // examples' top-level println(run_test())). fn micros_to_str(xs: [Int]) -> String { let n: Int = native_list_len(xs) let out: String = "" let i: Int = 0 while i < n { if i > 0 { let out: String = out + "," } let out: String = out + int_to_str(native_list_get(xs, i)) let i: Int = i + 1 } return out } // Render a 1.0s A4 (midi 69) tone from a signature file, print the parsed // partials (proving the numbers came from the engram .sig), write the WAV. fn render_tone(name: String, sigpath: String, outpath: String, table: [Int]) -> Int { let lines: [String] = sig_load(sigpath) let partials: [Int] = parse_micros(sig_field(lines, "partials")) println("[" + name + "] partials_n=" + sig_field(lines, "partials_n") + " parsed_partials_micro(scale 1e6)=" + micros_to_str(partials)) println("[" + name + "] raw partials line from .sig = " + sig_field(lines, "partials")) let freq: Int = freq_of_midi(69) let note: [Int] = synth_from_sig(lines, freq, 1000, 900, 44100, table) let n: Int = native_list_len(note) let ok: Int = wav_write(outpath, note, n, 44100) println("[" + name + "] rendered " + int_to_str(n) + " samples -> " + outpath + " (write_ok=" + int_to_str(ok) + ")") return n } fn run_demo() -> Int { let table: [Int] = sin_table() fs_mkdir("/Users/will/Development/neuron-technologies/foundation/el/.claude/worktrees/agent-aaf04b0a9714c4070/elp/faculty/out") println("=== TONES: render A4 (midi 69) from each learned signature ===") render_tone("flute", "/Users/will/Development/neuron-technologies/foundation/el/.claude/worktrees/agent-aaf04b0a9714c4070/elp/faculty/sig/flute.sig", "/Users/will/Development/neuron-technologies/foundation/el/.claude/worktrees/agent-aaf04b0a9714c4070/elp/faculty/out/tone-flute.wav", table) render_tone("clarinet", "/Users/will/Development/neuron-technologies/foundation/el/.claude/worktrees/agent-aaf04b0a9714c4070/elp/faculty/sig/clarinet.sig", "/Users/will/Development/neuron-technologies/foundation/el/.claude/worktrees/agent-aaf04b0a9714c4070/elp/faculty/out/tone-clarinet.wav", table) render_tone("violin", "/Users/will/Development/neuron-technologies/foundation/el/.claude/worktrees/agent-aaf04b0a9714c4070/elp/faculty/sig/violin.sig", "/Users/will/Development/neuron-technologies/foundation/el/.claude/worktrees/agent-aaf04b0a9714c4070/elp/faculty/out/tone-violin.wav", table) render_tone("piano", "/Users/will/Development/neuron-technologies/foundation/el/.claude/worktrees/agent-aaf04b0a9714c4070/elp/faculty/sig/piano.sig", "/Users/will/Development/neuron-technologies/foundation/el/.claude/worktrees/agent-aaf04b0a9714c4070/elp/faculty/out/tone-piano.wav", table) render_tone("organ", "/Users/will/Development/neuron-technologies/foundation/el/.claude/worktrees/agent-aaf04b0a9714c4070/elp/faculty/sig/organ.sig", "/Users/will/Development/neuron-technologies/foundation/el/.claude/worktrees/agent-aaf04b0a9714c4070/elp/faculty/out/tone-organ.wav", table) println("") println("=== PIECE: a 6-frame meaning phrase (incl. a NEG frame) ===") let frames: [[String]] = native_list_empty() let frames: [[String]] = native_list_append(frames, audio_frame("agent", "aff", "0.9", "0.8", "0", "s1")) let frames: [[String]] = native_list_append(frames, audio_frame("theme", "aff", "0.7", "0.6", "0", "s2")) let frames: [[String]] = native_list_append(frames, audio_frame("cause", "aff", "0.8", "0.9", "1", "s3")) let frames: [[String]] = native_list_append(frames, audio_frame("negation", "neg", "0.85", "0.7", "0", "s4")) let frames: [[String]] = native_list_append(frames, audio_frame("goal", "aff", "0.6", "0.5", "1", "s5")) let frames: [[String]] = native_list_append(frames, audio_frame("result", "aff", "0.95", "1.0", "0", "s6")) // Print the plan so the NEG frame's minor third (+3) vs major (+4) is visible. let nf: Int = native_list_len(frames) let fi: Int = 0 while fi < nf { let frame: [String] = native_list_get(frames, fi) let plan: [Int] = plan_note(frame) let pol: String = surface_get(frame, "polarity") let third_name: String = "major(+4)" if str_eq(pol, "neg") { let third_name: String = "MINOR(+3)" } println("frame " + int_to_str(fi) + " relation=" + surface_get(frame, "relation") + " polarity=" + pol + " -> midi=" + int_to_str(native_list_get(plan, 0)) + " dur_ms=" + int_to_str(native_list_get(plan, 1)) + " amp_pm=" + int_to_str(native_list_get(plan, 2)) + " third=" + third_name) let fi: Int = fi + 1 } let piano_lines: [String] = sig_load("/Users/will/Development/neuron-technologies/foundation/el/.claude/worktrees/agent-aaf04b0a9714c4070/elp/faculty/sig/piano.sig") let total: Int = realize_audio(frames, piano_lines, "/Users/will/Development/neuron-technologies/foundation/el/.claude/worktrees/agent-aaf04b0a9714c4070/elp/faculty/out/piece.wav", 44100, table) println("PIECE rendered " + int_to_str(total) + " samples -> /Users/will/Development/neuron-technologies/foundation/el/.claude/worktrees/agent-aaf04b0a9714c4070/elp/faculty/out/piece.wav") return total } println("audio-demo main returned samples=" + int_to_str(run_demo()))