Skip to content

Instantly share code, notes, and snippets.

@phiresky
Last active April 5, 2023 00:51
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phiresky/dfc72f596216739a7a669ca30db0098d to your computer and use it in GitHub Desktop.
Save phiresky/dfc72f596216739a7a669ca30db0098d to your computer and use it in GitHub Desktop.
guitar synthesizer in 96 characters of C

tiny guitar synth in 96 chars of C

works by starting with a array filled with white noise (from /dev/urandom), then continuously modulating it with a low pass filter of the desired frequency.

this results in a sound pretty similar to a guitar with steel or nylon strings.

# minimal
echo "int s=8e3/82;main(i){unsigned char v[s];read(0,v,s);for(;;)putchar(v[i%s]=(v[i%s]+v[++i%s])/2);}" |
gcc -x c - && ./a.out < /dev/urandom | aplay -d 2
# multiple notes
for i in 110 123 131 147; do
echo "int s=44100/$i;main(i){unsigned char v[s];read(0,v,s);for(;;)putchar(v[i%s]=(v[i%s]+v[++i%s])/2);}" |
gcc -x c - && ./a.out</dev/urandom | head -c 22050
done | ffmpeg -f u8 -ar 44100 -i - -f mp3 - | vlc -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment