This commit is contained in:
Miloslav Ciz 2021-12-18 22:13:09 -06:00
parent 8b8025384f
commit 1635d3e68b
3 changed files with 70 additions and 0 deletions

View file

@ -18,3 +18,4 @@ Examples of beautiful things include:
- **Euler's identity**, an equation often cited as the most beautiful in mathematics: *e^{i*pi} + 1 = 0*. It is simple and contains many of the most important numbers: *e*, *pi*, *i* 1 and 0.
- **[minimalist software](suckless.md)**, **[Unix philosophy](unix_philosophy.md)**
- [fractals](fractal.md) TODO
- [bytebeat](bytebeat.md)

68
bytebeat.md Normal file
View file

@ -0,0 +1,68 @@
# Bytebeat
Bytebeat is a procedural [chiptune](chiptune.md)/8bit style music generated by a short expression in a programming language; it was discovered/highlighted in 2011 by [Viznut](viznut.md) (author of [countercomplex](countercomplex.md) blog) and the technique capable of producing quite impressive music by single-line code has since caught the attention of many programmers, especially in [demoscene](demoscene.md). There has even been a [paper](https://arxiv.org/abs/1112.1368) written about bytebeat.
This is a [beautiful](beauty.md) [hack](hacking.md) for [LRS](lrs.md)/[suckless](suckless.md) programmers because it takes quite a tiny amount of code, space and effort to produce nice music, e.g. for [games](game.md) (done e.g. by [Anarch](anarch.md)).
8bit samples corresponding to `unsigned char` are typically used with bytebeat. The formulas take advantage of [overflows](overflow.md) 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 musical samples).
## How to
Quick experiments with bytebeat can be performed with online tools that are easy to find on the [web](www.md), these usually use [JavaScript](javascript.md).
Nevertheless, traditionally we use [C](c.md) 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 <stdio.h>
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/substraction 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 [copyright](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 [free](free_culture.md) [licenses](license.md) such as [CC-BY-SA](cc-by-sa.md), 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.
## Examples
A super-simple example can be just a simple:
- `i / 16`
The following more complex examples come from the [LRS](lrs.md) game [Anarch](anarch.md) (these are legally safe even in case copyright can apply to bytebeat as Anarch is released under [CC0](cc0.md)):
- 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)`

View file

@ -26,5 +26,6 @@ And if you just want something more obscure and fun, check out these:
- [open consoles](open_console.md)
- [brain software](brain_software.md)
- [C obfuscation contest](ioccc.md)
- [bytebeat](bytebeat.md)
- [Netstalking](netstalking.md)
- [shit](shit.md)