Save over 40% when you secure your tickets today to TNW Conference 💥 Prices will increase on November 22 →

This article was published on September 16, 2020

How to compose music with just a single line of code


How to compose music with just a single line of code Image by: Unsplash: Max Duzij

So you like TNW? Then join our upcoming online event, TNW2020, you don’t want to miss it.

This article was originally published on .cult by Mynah Marie. .cult is a Berlin-based community platform for developers. We write about all things career-related, make original documentaries and share heaps of other untold developer stories from around the world.

In 2011, a programmer going by the name of Viznut published the following video on YouTube:

Accompanying the video were various articles written by him and published on his blog. In them, he describes how he accidentally discovered that by running a simple C program outputting single characters and piping them into the audio interface of a computer, it’s possible to encode these bytes and turn them into not just sounds, but music.

The video and article created an uproar in the Demoscene community. People started experimenting with basic C programs and coming up with interesting melodies. Soon, Viznut published a more academic paper explaining the theory behind how to compose elaborate music compositions using this technique.

A new subgenre of electronic music was born: bytebeat.

Discovering the powerful capabilities of one-liner C programs

In its essence, a bytebeat program is a small C program consisting of an infinite loop, outputting to the terminal an endless string of ASCII characters. These chars can then be piped to another program and interpreted as raw audio output.

By influencing a variable t through bitwise operations at each loop iteration, we assure ourselves that the output of the formula will always be a different character, so different combinations of sounds will be heard.

The beauty of a bytebeat program comes from its simplicity. With one line of code, the programmer has the ability to create complex audio pieces only by manipulating a single variable.

When reading Viznut’s first articles on the subject, it’s interesting to note his own feeling of bewilderment when discovering that something so simple never seemed to have caught anyone’s attention before.

“A Bytebeat formula is a simple arrangement of digital-arithmetic operations that have been elementary to computers since the very beginning. It is apparently something that should have been discovered decades ago, but it wasn’t. […]

It is mind-boggling to think that the space of very short programs remains so uncharted that random excursions there can churn out new interesting structures even after seventy years.” — ViznutBringing magic back to technology

Bringing back a sense of “magic” in today’s fast-paced technological world

“One definition of magic […] is that it breaks people’s preconceptions of what is possible. In order to challenge and ridicule today’s technological bloat, we should particularly aim at discoveries that are far too simple and random to work but still do,” Viznut, Bringing magic back to technology.

Photos-from-Lobotomia-02
VIZNUT, TIC AND LD0D AT LOBOTOMIA, ’02 | HTTPS://WWW.FIIKUS.NET/?LOBO02

In computer history’s infancy, the term “magic” was often used to describe a program that works but with an obscure reason as to why. Engineers were constantly dabbling in uncharted territories and each new discovery had the potential to create magic, a process so clever and fascinating that its mechanism is difficult to grasp.

Computer scientists at the MIT AI Lab started to write down and share their personal notes on findings they would stumble upon and collect, in Guy L. Steele’s words, “a bizarre and eclectic potpourri of technical trivia”.

These notes are now known as the HACKMEM (short for hack memos) and, even though they are not being referred to as much today, they are an incredible record of insights into the minds of influential engineers from that period.

The MIT AI Lab also participated in the creation of the Jargon File, a glossary of slang words and expressions used by computer programmers.

When looking at the definition of “magic” and in the Jargon files, here’s what we find: magic

1. adj. As yet unexplained, or too complicated to explain; compare automagically and (Arthur C.) Clarke’s Third Law: “Any sufficiently advanced technology is indistinguishable from magic.” “TTY echoing is controlled by a large number of magic bits.” “This routine magically computes the parity of an 8-bit byte in three instructions.”

2. adj. Characteristic of something that works although no one really understands why (this is especially called black magic).

3. n. [Stanford] A feature not generally publicized that allows something otherwise impossible, or a feature formerly in that category but now unveiled.

4. n. The ultimate goal of all engineering & development, elegance in the extreme; from the first corollary to Clarke’s Third Law: “Any technology distinguishable from magic is insufficiently advanced”.

Definition of magic, The Jargon File

In relation to bytebeat, another term found in the Jargon File stands out: hack value: n.

Often adduced as the reason or motivation for expending effort toward a seemingly useless goal, the point being that the accomplished goal is a hack. For example, MacLISP had features for reading and printing Roman numerals, which were installed purely for hack value. […] this cannot really be explained, only experienced. As Louis Armstrong once said when asked to explain jazz: “Man, if you gotta ask you’ll never know.”

— Definition of hack value, The Jargon File

Possibly one of the reasons bytebeat took the Demoscene and hacker community by storm is because of its high hack value.

In the Demoscene, artists and programmers get together to create sometimes extremely small programs producing an artistic outcome. Demos are then presented at various competitions and winners are chosen according to the hack value of their demo: a balance between extremely efficient code, impressive artistic results, and the program’s simplicity and elegance.

Eyes towards The future

Though bytebeat is an underground movement, it’s still alive in 2020. Some programmers and researchers have been investing energy into developing various programs around bytebeat theory.

One such modern applications of bytebeat worth mentioning is Rampcode: a live coding system built on top of PureData, created by Argentinian philosophy professor, musician, and creative coder Gabriel Vinazza (a.k.a. GEDE).

Final thoughts

Maybe the fact that so few people have yet to experiment with bytebeat means there are still many interesting discoveries to be done on the subject. After all, its concept serves as a reminder that, no matter how far technology goes, there’s beauty and, yes, magic, to be found in the simplest things.

Get the TNW newsletter

Get the most important tech news in your inbox each week.

Also tagged with


Published
Back to top