code wiki / (root) / nx_audio_fx.nx

nx_audio_fx.nx source

↩ module page · 34 lines · 1109 B

1// nx_audio_fx.nx -- SOVEREIGN AUDIO ENGINE rung R5: effects (filter + delay). 2// 3// fx_lowpass: one-pole low-pass (y += alpha*(x-y), Q8 alpha; 256 = passthrough) -- 4// smooths high frequencies / harshness, the basis of tone shaping. 5// fx_delay: feedback echo (out[n] += fb*out[n-delay]) -- the basis of echo/reverb 6// and a space sense. 7// Pure integer recursion, reuses ae_clamp (R0). license_tier: ORIGINAL. 8 9import "nx_syscalls.nx" 10import "nx_audio_mix.nx" 11 12// one-pole low-pass in place; alpha Q8 in (0,256], 256 = no filtering 13func fx_lowpass(buf: *i64, n: i64, alpha: i64) -> i64 { 14 var prev: i64 = 0 15 var i: i64 = 0 16 while i < n { 17 let y: i64 = prev + (alpha * (buf[i] - prev)) / 256 18 buf[i] = ae_clamp(y) 19 prev = buf[i] 20 i = i + 1 21 } 22 return n 23} 24 25// feedback delay/echo in place; fb Q8 (e.g. 128 = 0.5 feedback) 26func fx_delay(buf: *i64, n: i64, delay: i64, fb: i64) -> i64 { 27 if delay < 1 { return n } 28 var i: i64 = delay 29 while i < n { 30 buf[i] = ae_clamp(buf[i] + (fb * buf[i - delay]) / 256) 31 i = i + 1 32 } 33 return n 34}