DEV Community

Discussion on: What are the amazing things you do with the terminal?

Collapse
 
tbodt profile image
tbodt

Play procedurally generated music! Here's a cool command I found earlier today:

echo "g(i,x,t,o){return((3&x&(i*((3&i>>16?\"BY}6YB6%\":\"Qj}6jQ6%\")[t%8]+51)>>o))<<4);};main(){int 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

(It also works on Mac, but you have to install something called "sox" (brew install sox) and replace aplay with play -c1 -b8 -eunsigned -traw -r8k -.)

Collapse
 
jarxg profile image
@jarxg

What sorcery is this. Care to explain what is going on? :O

Collapse
 
tbodt profile image
tbodt • Edited

I am honestly not too sure, but the basic idea is there's an infinite loop with i starting at 0 and incrementing each time, and each byte of audio data is somehow derived from i.