how to make your cross-platform audio engine bloat free in 5 easy steps: https://garten.salat.dev/135-clang-wasm-audio/ (i almost fell off the chair when i saw step 4). shoutout to @sqx
🌱 clang wasm audio

@froos i've since found simple replacements for the remaining stuff i usually miss from libc:

qsort: i turned this macrofied qsort back into a stdlib.h-compatible one: https://github.com/nothings/stb/blob/31c1ad37456438565541f4919958214b6e762fb4/deprecated/stb.h#L8721-L8846

malloc/free: turns out the original K&R book ("The C Programming Language") chapter 8.7 has an elegant malloc, meant as a teaching example, but it works: https://github.com/noncombatant/kr-malloc/blob/main/original_kr_malloc.c

stb/deprecated/stb.h at 31c1ad37456438565541f4919958214b6e762fb4 · nothings/stb

stb single-file public domain libraries for C/C++. Contribute to nothings/stb development by creating an account on GitHub.

GitHub
@froos probably best to avoid malloc/free as much as you can, like the static mem stuff in dough.c, but in audio engines you have samples and delay buffers as these things that can have any size, and may come and go… i'm thinking k&r malloc might be fine for those
@sqx @froos im curious, would it not be possible to use something like wasi-libc here? or is it considered bloat 😅
@ahihi @froos ooh, i'm not familiar with it, but C dependencies tend to be a pain unless they can be vendored. we used to compile with emscripten which provides libc/libm/etc, but ended up doing the nostdlib clang thing because it felt better i guess :) (also, a personal excuse is that emscripten works poorly on freebsd)
@ahihi @sqx thanks for the tip, could be a good option as well! i have almost no idea what i'm doing. will check it out.

@froos

bad sines only ♥️

@froos on the topic of bad sines: how cheap is a triangle function as opposed to taking x and x^2?

I wonder how much (computational) effort it is to approximate a sine with a few triangles (or mix in a square wave, idk). It dawns on me that I am talking about additive synthesis... 🤔

@fleuron triangle is very cheap, as its 2 linear functions, but it has an edge, so i wonder how you would eliminate that to make it more sinish. a triangle can be made out of sines: https://garten.salat.dev/069-the-fourier-series-II/ but haven't seen the other way around. i think you should do it
🌱 the fourier series II

@froos

Does kabelsalat (or strudel?) have a way to do a phase shift?

Since tri has a lot of overtones (odd multiples of the base frequency, with alternating signs and with magnitude 1/1, 1/9, 1/25, 1/49... ) one needs some higher order tri waves to cancel these out.

I think tri(x) + 1/9 tri (3x) - 1/25 tri (5x) might be interesting as a start, but idk how to do the minus (ie phase shift). Interesting things might happen for 9x because these are the first overtones of the 2nd tri.