Skip to content

Instantly share code, notes, and snippets.

@auxiliary-character
Created November 20, 2016 00:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save auxiliary-character/6dac6160bcbfd5615e78bff854883408 to your computer and use it in GitHub Desktop.
Save auxiliary-character/6dac6160bcbfd5615e78bff854883408 to your computer and use it in GitHub Desktop.
#include <string.h>
#include <stdio.h>
static const float scale[] = {
0, //rest
11.175303405856125,
13.289750322558245,
15.804265640195972,
16.74403617923831,
17.739688382519812,
19.91212695821318
};
static const char melody[] =
"10000040"
"34343040"
"20001000"
"00102040"
"50002000"
"50006000"
"40504050"
"40000000";
//outputs 8-bit PCM audio to stdout
//pipe into /dev/dsp, aplay, or a file for audacity
int main(){
for(int t;(t>>9)<strlen(melody); ++t){
putchar((char)(t*scale[melody[t>>9]-'0']));
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment