\ mold playground. fill three buffers, read four knobs; the page \ plays the audio, draws the pixels, and wires the sliders. \ \ host calls: \ init(sr) once at start and on reset. \ render(n) fills audio-buf-l/r with n stereo samples (n = 128). \ frame(t) fills pix with a 64 x 64 RGBA frame. t bumps every frame. \ \ the page writes four f32 sliders in [0, 1] into ctrl[0..3]; use as you like. import-memory 0 byte 65536 buffer audio-buf-l 512 \ 128 f32 left samples. buffer audio-buf-r 512 \ 128 f32 right samples. buffer pix 16384 \ 64 x 64 RGBA bytes. buffer ctrl 16 \ 4 f32 knobs. : buf-ptr ( -- i32 ) audio-buf-l ; export : buf-r-ptr ( -- i32 ) audio-buf-r ; export : pix-ptr ( -- i32 ) pix ; export : ctrl-ptr ( -- i32 ) ctrl ; export var sr 48000 var phase 0 : f32@ ( i32 -- f32 ) f32 open @ close ; : f32! ( f32 i32 -- ) f32 open ! close ; : knob ( i32 -- f32 ) 4 * ctrl + f32@ ; : knob-byte ( i32 -- i32 ) knob f32 open 255.0 * close trunc_sat_f32_s ; : knob-pitch ( i32 -- i32 ) knob f32 open 2000.0 * 1.0 + close trunc_sat_f32_s ; \ AUDIO - square wave; knob 0 sets pitch. : render ( i32 -- ) { n } 0 knob-pitch { inc } 0 { i } begin i n < while phase @ inc + dup phase ! 0xFFFF & 0x8000 < if 0.2 else -0.2 then { s } s audio-buf-l i 4 * + f32! s audio-buf-r i 4 * + f32! i 1 + to i repeat ; export \ PIXELS - scrolling XOR plasma; knobs 1 and 2 tint red and blue. : frame ( i32 -- ) { t } 1 knob-byte { r } 2 knob-byte { b } 0 { y } begin y 64 < while 0 { x } begin x 64 < while y 64 * x + 2 << pix + { p } x y ^ t + 0xFF & r & p c! x y ^ 0xFF & p 1 + c! x y ^ t - 0xFF & b & p 2 + c! 0xFF p 3 + c! x 1 + to x repeat y 1 + to y repeat ; export : init ( i32 -- ) sr ! 0 phase ! ; export