Skip to content

Instantly share code, notes, and snippets.

@scottjbarr
Created December 7, 2018 06:29
Show Gist options
  • Save scottjbarr/6d44eabf11a95f840ca4810796d74add to your computer and use it in GitHub Desktop.
Save scottjbarr/6d44eabf11a95f840ca4810796d74add to your computer and use it in GitHub Desktop.
Generate music from code, and gcc
#!/bin/bash
#
# Generate music from code and gcc.
#
# This actually sounds pretty good!
#
# I am not the original author of this code, it was tweeted by
# @kr094_ . See https://twitter.com/kr094_/status/928038531125207040
#
# Author : Scott Barr
# Date : 7 Dec 2018
#
echo "g(i,x,t,o){return((3&x&(i*((3&i>>16?\"BY}6YB6%\":\"Qj}6jQ6%\")[t%8]+51)>>o))<<4);};main(i,n,s){for(i=0;;i++)putchar(g(i,1,n=i>>14,12)+g(i,s=i>>17,n^i>>13,10)+g(i,s/3,n+((i>>11)%3),10)+g(i,s/5,8+n-((i>>10)%3),9));}" | gcc -xc - && ./a.out | aplay
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment