BYTEBEAT

1. TIME

Bytebeat¹ outputs unsigned 8-bit audio at 8000Hz. The variable t increments by 1 for every sample. The environment truncate output to 8 bits, values above 255 wrap back to 0 creating a sawtooth wave.

IntegerBinaryTruncatedDecimal
254001111111011111110254
255001111111111111111255
2560100000000000000000
t

2. ARITHMETICS

Arithmetic directly alters the phase and frequency of the wrapping sawtooth wave.

+ ADD - SUB

t + 128 shifts phase. -t flips the wave slope.

* MULT / DIV

t * 2 = octave up. t / 2 = octave down.

% MODULO

Forces early wraps.t%128 halves volume.

! = > < COMPARISONS

Yields 1 or 0. Acts as a boolean gate.

Example of operators:

t % 8000<4000 ? t : t*5

3. BITWISE

Bitwise operators act as logic mixers and toggles values on and off to sculpt complex timbres and melodies.

& AND

Masking: t & 128 isolates the top bit, outputting a pure square wave. Acts as a volume gate.

| OR

Mixing: t | (t >> 2) preserves high bits of both signals, smearing harmonics for lo-fi chords.

^ XOR

Exclusive logic. Yields metallic phase-distortion and ring-modulation effects.

~ NOT

Inversion. Mirrors the binary waveform exactly.

Example of operators:

t>>3 | (t>>6) * t & t + (t>>14&4)
Bitshift vs. Arithmetic

Bitwise operations are computationally identical to arithmetic operations. Bitshiftting is multiplying or dividing by powers of 2. For array looping, bitwise & acts as an ultra-fast modulo for array lengths that are exact powers of 2 (2, 4, 8, ...).

BitshitArithmeticEffect / Usage
t << 1t * 2+1 Octave Up (Double freq)
t >> 1t / 2-1 Octave Down (Halve freq)
x & 7x % 8Array loop (Only for 2^n length)
x & 3x % 4Array loop (Only for 2^n length)
~t-t-1Phase inversion

4. RHYTHM

Binary Clocks

Bitshifting t scales time. t>>11 is the standard demoscene master clock advancing approximately every 0.25 seconds. To trigger rhythm sections: (t>>11)&3 creates a 4-step sequence.

s=[1,2,3,4], t * s[t>>11&3]
BPM Syncing

For exact tempo control, use integer division instead of bitshifting. Calculate Samples Per Beat (Sample Rate * 60 / BPM). For 120 BPM at 8000Hz, SPB is 4000 divide by t and use | 0 to floor the value.

s=[1,2,3], t * s[(t/4000|0)%3]

5. TUNING

Whole integer multipliers t * 2, t * 3 jump entirely different octaves. To sequence a normal diatonic scale within a single octave, multiply t by specific fractions between 1.0 and 2.0. To change the root note, apply a base multiplier before the fraction, for example t*1.5 shifts root to G.

NoteIntervalFracNoteIntervalFrac
CUnison1GPerf 5th3/2
DMaj 2nd9/8AMaj 6th5/3
EMaj 3rd5/4BMaj 7th15/8
FPerf 4th4/3C'Octave2
s=[1, 9/8, 5/4, 4/3, 3/2, 5/3, 15/8, 2], t * s[(t/2000|0)%8]

6. EXAMPLES

The original bytebeat

The first bytebeat formula created by viznut.

t*((t>>12|t>>8)&63&t>>4)

The 42 melody

The classic melodic bytebeat melody discovered by many.

t*(42&t>>10)

Pulse Width Modulation (PWM)

Secondary counter dynamically shrinks the square duty cycle.

(t%100>=t/200%100)*255

Triangle wave

The -1 offset realigns phase, -t-1 is same as ~t.

v=t*6, (v&511)>255 ? v : ~v
[1] https://countercomplex.blogspot.com/2011/10/algorithmic-symphonies-from-one-line-of.html

FLOATBEAT

1. TIME

Floatbeat outputs a signed 32-bit float strictly between -1.0 and +1.0. The variable t increments infinitely. Raw values outside these bounds result in hard-clipped silence.

Manual Sawtooth

Modulo wraps the infinite counter.

t%100/50-1.0

Trigonometric Phase

Scaling time into a smooth sine oscillator.

sin(t/20)

2. CORE FUNCTIONS

Continuous mathematical operations are the primary tools used to shape floating-point audio.

SIN / COS

Primary smooth oscillators. Phase must be divided down (t/20).

TAN

Distorted harmonics due to infinite periodic peaks.

EXP

Exponential curves for volume decays, like: exp(0.0-t/1000)

LOG / LOG2

Log curves. Ideal for sharp percussive transients.

ABS / SQRT

Non-linear wave shapers.

MIN / MAX

Clamps signals like: max(0, x)

3. ENVELOPES

Abrupt phase resets via modulo create loud DC clicks. Applying an exp() or log() decay dampens the amplitude to 0.0 before the cycle restarts, ensuring clean transients.

Exponential Decay

Dampens completely over a fixed sample duration with a smooth tail.

b=t%16000, sin(b/20)*exp(0.0-b/2000)

Logarithmic Decay

Creates a highly percussive, sharp initial drop. max() clamps the tail.

b=t%16000, sin(b/20)*max(0, 1-log(b/100+1)/5)

Dynamic Envelope

Loop and decay scale seamlessly with the sample rate.

b=t%(sr/3), sin(b/20)*exp(0.0-b/(sr/24))

4. MATH & TEMPO

12-TET MIDI Formula

To compose using exact western tuning (where MIDI Note 69 = A440), the following formula can be used:

f=(n)=>440 * 2 ** ((n-69) / 12), sin(t * f(72) * 6.28 / 48000)
BPM Sync

To sequence melodies accurately calculate samples per beat: (CurrentSample Rate * 60 / BPM). For 120 BPM: 24000 samples.

TempoMath (SR * 60 / BPM)48kHz SPB
120 BPM48000 * (60/120)24,000
140 BPM48000 * (60/140)20,571
b = t % 24000,
sin(b/20) * exp(0.0 - b/2000)

5. EXAMPLES

Basic FM

Classic single line FM.

m=t/10,sin(m+sin(m*2.0)*2.0)

Bass Kick

Decay applied inside the phase array for a rapid pitch drop.

b=t%16000,
sin(b*exp(0.0-b/1500)/15)*exp(0.1-b/4000)

Phase Lead

Dense multi-oscillator chords using an array lookup grid.

gc=t/(t/[12,14,16][(t>>14)%3]),
(sin(t/gc)+sin(t/20)+tan(sin(t/t-t/(gc+.01))))/4

String Pluck

Clean, repeating physical model with exact damping curve.

b=t%8000,
sin(b/25)*exp(0.0-b/1800)

Bell Tone

Metallic decay with a complex inharmonic spectrum.

b=t%16000,e=exp(-b/2000),sin(b/5+e*4*sin(b/4))*e
Formula Copied