├── play ├── esp.c ├── funtime.c ├── squares.c ├── gripper.c ├── floater.c ├── tube.c ├── creeper.c ├── 42_melody.c ├── future.c ├── sample.c ├── soundtrack.c ├── errie_error.c └── README.md /play: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ./$1 | sox -traw -r8000 -b8 -e unsigned-integer - -tcoreaudio gain -6 4 | -------------------------------------------------------------------------------- /esp.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | for(int t=0;;t++) { 5 | putchar( t*(t>>8) ); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /funtime.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | for(int t=0; 1; t++) 5 | putchar( t*(t>>9|t>>13) ); 6 | } 7 | -------------------------------------------------------------------------------- /squares.c: -------------------------------------------------------------------------------- 1 | // bytebeat 2 | 3 | #include 4 | 5 | int main() { 6 | for(int i=0; 1; i++) 7 | putchar(i&i>>8); 8 | } 9 | -------------------------------------------------------------------------------- /gripper.c: -------------------------------------------------------------------------------- 1 | // 8bit, 8kHz 2 | 3 | #include 4 | 5 | int main() { 6 | for(t = 0;;t++) { 7 | putchar(t*((t>>9|t>>13)&25&t>>6)); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /floater.c: -------------------------------------------------------------------------------- 1 | // 8bit, 8kHz 2 | 3 | #include 4 | 5 | int main() { 6 | for(int t=0;;t++) { 7 | putchar( (t*(t>>5|t>>8))>>(t>>16) ); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tube.c: -------------------------------------------------------------------------------- 1 | // bytebeat 2 | 3 | #include 4 | 5 | int main() { 6 | int t = 0; 7 | 8 | while(1) { 9 | t++; 10 | putchar( (t*5&t>>7)|(t*3&t>>10) ); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /creeper.c: -------------------------------------------------------------------------------- 1 | // 8bit, 8kHz 2 | 3 | #include 4 | 5 | int main() { 6 | for(int t=0;;t++) { 7 | putchar( (int)(t/1e7*t*t+t)%127 | t>>4 | t>>5 | t%127 + (t>>16) | t ); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /42_melody.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int t, value; 5 | while(1) { 6 | t++; 7 | //value = t*(42&t>>10); 8 | value = t*((42&t>>10)%14); 9 | putchar(value); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /future.c: -------------------------------------------------------------------------------- 1 | // from: kb 2 | // 8bit, 44.1kHz 3 | 4 | #include 5 | 6 | int main() { 7 | for(int t=0;;t++) { 8 | putchar( ((t/2*(15&(0x234568a0>>(t>>8&28)))) | t/2 >>(t>>11)^t>>12) + (t/16&t&24) ); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /sample.c: -------------------------------------------------------------------------------- 1 | // bytebeat 2 | 3 | #include 4 | 5 | int main() { 6 | int i = 0; 7 | int value; 8 | 9 | while(1) { 10 | i++; 11 | value = i*(((i>>12)|(i>>8))&(63&(i>>4))); 12 | putchar(value); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /soundtrack.c: -------------------------------------------------------------------------------- 1 | // from: ryg 2 | // 8bit, 44.1kHz 3 | 4 | #include 5 | 6 | int main() { 7 | for(int t=0;;t++) { 8 | putchar( ((t*("36364689"[t>>13&7]&15))/12&128)+(((((t<<12)^(t>>12)-2)%11*t)/4|t>>13)%127) ); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /errie_error.c: -------------------------------------------------------------------------------- 1 | // from: stephth 2 | // 8bit, 44.1kHz 3 | 4 | #include 5 | 6 | int main() { 7 | for(int t=0;;t++) { 8 | // initial 9 | //putchar( (((t*9)&(t>>4))|(t*5&t>>7)|(t*3&t/1024)) ); 10 | 11 | // percussive 12 | //putchar( (((t*9)&(t>>4))|(t*5&t>>7)|(t*3&t/1024))-1 ); 13 | 14 | // magical 15 | putchar( (((t*9)&(t>>4))|(t*5&t>>7)|(t*3&t/1024)-1) ); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Bytebeat 2 | 3 | Create interesting sounds by shifting bits around. 4 | 5 | For example, here is a simple C program that creates a repeating audio pattern when piped to /dev/audio: 6 | 7 | ``` 8 | #include 9 | 10 | int main() { 11 | int i = 0; 12 | 13 | while(1) { 14 | i++; 15 | putchar(i&i>>8); 16 | } 17 | } 18 | ``` 19 | 20 | ## OSX Instructions 21 | 22 | First, `brew install sox` in order to have a way to pipe data to the sound system. 23 | 24 | Next, compile one of the .c files: `gcc -o 42_melody 42_melody.c`. 25 | 26 | Pipe the output of the program to sox: `./42_melody | sox -traw -r8000 -b8 -e unsigned-integer - -tcoreaudio`. Or, use the handy bash script: `./play squares`. 27 | 28 | `CTRL+C` to stop the music. 29 | 30 | Experiment! 31 | 32 | ## References 33 | 34 | * [Algorithmic symphonies from one line of code](http://countercomplex.blogspot.com/2011/10/algorithmic-symphonies-from-one-line-of.html) 35 | * [Deep analysis of one-line music programs](http://countercomplex.blogspot.com/2011/10/some-deep-analysis-of-one-line-music.html) 36 | * [(youtube) Experimental music from very short C programs](https://www.youtube.com/watch?v=GtQdIYUtAHg) 37 | * [(youtube) Experimental one-line algorithmic music (2nd iteration)](https://www.youtube.com/watch?v=qlrs2Vorw2Y) 38 | * [(youtube) Music from very short programs (3rd iteration)](https://www.youtube.com/watch?v=tCRPUv8V22o) 39 | * [Javascript Bytebeat Generator](http://wurstcaptures.untergrund.net/music/) 40 | * [IBNIZ](https://github.com/viznut/IBNIZ/tree/master/src) 41 | * [/r/bytebeat on reddit](http://www.reddit.com/r/bytebeat/) 42 | * [Bytebeat on canonical.org](http://web.archive.org/web/20140209022048/http://canonical.org/~kragen/bytebeat/) 43 | * [viznut-music on github](https://github.com/kragen/viznut-music) 44 | * [Hacker News Discussion](https://news.ycombinator.com/item?id=3063359) 45 | * [Collection of Interesting Bytebeat Formulae](http://pelulamu.net/countercomplex/music_formula_collection.txt) 46 | 47 | ## Notes 48 | 49 | Most of these programs are from [@viznut's](http://www.twitter.com/viznut) videos. All credit goes to him and the original authors. 50 | --------------------------------------------------------------------------------