Bytebeat Bytebeat is a [1]procedural [2]chiptune/8bit style music generated by a short expression in a [3]programming language; it was discovered/highlighted in 2011 by [4]Viznut (author of [5]countercomplex blog) and others, and the technique capable of producing quite impressive music by single-line code has since caught the attention of many programmers, especially in [6]demoscene. There has even been a [7]paper written about bytebeat. Bytebeat can produce music similar (though a lot simpler) to that created e.g. with [8]music trackers but with a lot less complexity and effort. This is a [9]beautiful [10]hack for [11]LRS/[12]suckless programmers because it takes quite a tiny amount of code, space and effort to produce nice music, e.g. for [13]games (done e.g. by [14]Anarch). 8bit samples corresponding to unsigned char are typically used with bytebeat. The formulas take advantage of [15]overflows that create rhythmical patterns with potential other operations such as multiplication, division, addition, squaring, bitwise/logical operators and conditions adding more interesting effects. Bytebeat also looks kind of cool when rendered as an image (outputting pixels instead of audio samples). How To Quick experiments with bytebeat can be performed with online tools that are easy to find on the [16]web, these usually use [17]JavaScript. Nevertheless, traditionally we use [18]C for bytebeat. We simply create a loop with a time variable (i) and inside the loop body we create our bytebeat expression with the variable to compute a char that we output. A simple "workflow" for bytebeat "development" can be set up as follows. Firstly write a C program: #include int main(void) { for (int i = 0; i < 10000; ++i) putchar( i / 3 // < bytebeat formula here ); return 0; } Now compile the program and play its output e.g. like this: gcc program.c && ./a.out | aplay Now we can just start experimenting and invent new music by fiddling with the formula indicated by the comment. General tips/tricks and observations are these: * Outputting the variable i creates a periodical saw-shaped beat, multiplication/division decreases/increases the speed, addition/subtraction shifts the phase backward/forward. * Squaring (and other powers) create a wah-wah effect. * Crazier patterns can be achieved by using the variable in places of numerical constants, e.g. i << ((i / 512) % 8) (shifting by a value that depends on the variable). * Modulo (%) increases the frequency and decreases volume (limits the wave peak). * So called Sierpinski harmonies are often used melodic expressions of the form i*N & i >> M. * Bitwise and (&) can add distortion (create steps in the wave). * A macro structure of the song (silent/louds parts, verse/chorus, ...) can be achieved by combining multiple patterns with some low-frequency pattern, e.g. this alternates a slower and faster beat: int cond = (i & 0x8000) == 0;, cond * (i / 16) + !cond * (i / 32) * Extra variables can add more complexity (e.g. precompute some variable a which will subsequently be used multiple times in the final formula). Copyright It is not exactly clear whether, how and to what extent [19]copyright can apply to bytebeat: on one hand we have a short formula that's uncopyrightable (just like mathematical formulas), on the other hand we have music, an artistic expression. Many authors of bytebeat "release" their creations under [20]free [21]licenses such as [22]CC-BY-SA, but such licenses are of course not applicable if copyright can't even arise. We believe copyright doesn't and SHOULDN'T apply to bytebeat. To ensure this, it is good to stick [23]CC0 to any released bytebeat just in case. Examples A super-simple example can be just a simple: * i / 16 The following more complex examples come from the [24]LRS game [25]Anarch (these are legally safe even in case copyright can apply to bytebeat as Anarch is released under [26]CC0): * distortion guitar rhythmical beat: ~((((i >> ((i >> 2) % 32)) | (i >> ((i >> 5) % 32))) & 0x12) << 1) | (i >> 11) * electronic/techno: ((0x47 >> ((i >> 9) % 32)) & (i >> (i % 32))) | (0x57 >> ((i >> 7) % 32)) | (0x06 >> ((i >> ((((i * 11) >> 14) & 0x0e) % 32)) % 32)) * main theme, uses an extra variable: (((i) & 65536) ? (a & (((i * 2) >> 16) & 0x09)) : ~a), where uint32_t a = ((i >> 7) | (i >> 9) | (~i << 1) | i) Here is an [27]ASCII visualization of the first track: ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, M'''''''''''''''M'''''''''''''''k'M'''''''''''''k'M''''''''''''' c;xxxxxxxxxxxxxxc;cxxxxxxxxxxxxx,;xxxxxxxxxxxxxx,;cxxxxxxxxxxxxx . ;.:;;;;;;;;;;;. ;.:;;;;;;;;;;;0 . :;;;;;;;;;;;0 . :;;;;;;;;;;; okokokkkkkkkkkkklklkokkkkkkkkkkkokokokkkkkkkkkkklklkokkkkkkkkkkk xkX0000000000000ckX0000000000000xkXK000000000000ckXK000000000000 oMKMKMMMMMMMMMMMlMkMKMMMMMMMMMMMoMKMKMMMMMMMMMMMlMkMKMMMMMMMMMMM xK00KWWWWWWWWWWWcKX0KWWWWWWWWWW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WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW xxxxxxxxKKKKKKKKMMMMMMMMWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW See Also * [28]music tracker * [29]databending * [30]MIDI * [31]beatbox Links: 1. procgen.md 2. chiptune.md 3. programming_language.md 4. viznut.md 5. countercomplex.md 6. demoscene.md 7. https://arxiv.org/abs/1112.1368 8. music_tracker.md 9. beauty.md 10. hacking.md 11. lrs.md 12. suckless.md 13. game.md 14. anarch.md 15. overflow.md 16. www.md 17. javascript.md 18. c.md 19. copyright 20. free_culture.md 21. license.md 22. cc-by-sa.md 23. cc0.md 24. lrs.md 25. anarch.md 26. cc0.md 27. ascii_art.md 28. music_tracker.md 29. databending.md 30. midi.md 31. beatbox.md