Glitch is an algorithmic synthesizer. It creates music with math.
Music is a function f(t) where t is increasing in time.
Glitch increases t at 8000/sec rate and it can be a real number if your hardware sample rate is higher. Expression result is expected to be in range [0..255] otherwise overflow occurs.
Example: t*14 - sawtooth wave at 437 Hz.
Music expression is evaluated once for each audio frame. You can use numbers, math operators, variables and functions to compose more complex expressions.
Basic: + - * / % (modulo) ** (power)
Bitwise: & | ^ (xor or bitwise not) << >>
Compare: == != < <= > >= (return 1 or 0)
Grouping: ( ) , (separates expressions or function arguments)
Conditional: && || (short-circuit operators)
Assignment: = (left side must be a variable)
Bitwise operators truncate numbers to integer values.
Example: x=6,(y=x+1,x*y) - returns 42
Example: t*5&(t>>7)|t*3&(t*4>>10) - bytebeat music
r(n): random number in the range [0..n]
s(i): sine wave amplitude [0..255] at phase i=[0..255]
Example: s(t*14) - sine wave at 437Hz
Sequencers are used to describe melodies, rhythmic patterns or other parts of your song.
a(i, x0, x1, x2, ...) returns x[i] value for the given i
seq(bpm, x0, x1, x2, ...) returns x[i] value where i increases at given tempo.
Values can be numeric constants, variables or expressions. Values are evaluated once per beat and the result is cached.
Value can be a pair of numbers like (2,3) then the first number is relative step duration and the second one is actual value. This means value 3 will be returned for 2 beats.
Value can be a group of more than 2 numbers. The the first number is relative step duration, and other values are gradually slided, e.g. (0.5,2,4,2) is a value changed from 2 to 4 back to 2 and the step duration is half of a beat.
loop(bpm, x0, x1, x2, ...) evaluates x[i] increasing i at given tempo. Unlike seq, loop evaluates x[i] for every audio frame, so other functions can be used as loop values.
seq is often used to change pitch or volume, loop is often used to schedule inner sequences/loops.
seq and loop return NaN at the beginning of each step. NaN value is used by the instruments to detect the start of a new note.
Oscillators are the building blocks of synthesizers. Oscillator phase is managed internally, only frequency must be provided (in Hz).
sin(freq) = sine wave
tri(freq) = triangular wave
saw(freq) = saw-tooth wave
sqr(freq, pwm) = square wave of given pulse width, default pwm=0.5
More advanced instruments:
fm(freq, mf1, ma1, mf2, ma2, mf3, ma3) is a 3-operator FM synthesizer, mf is operator frequency ratio, ma operator amplification. M2 and M1 are sequential, M3 is parallel.
tr808(instr, volume) is TR808 drum kit. 0 = kick, 1 = snare, 2 = tom, 3 = crash, 4 = rimshot, 5 = clap, 6 = cowbell, 7 = open hat, 8 = closed hat.
Example: tr808(1,seq(240,1,0.2)) plays simple snare rhythm
env(r, x) wraps signal x with very short attack and given release time r
env(a, r, x) wraps signal x with given attack and release time
env(a, i1, a1, i2, a2, ..., x) wraps signal x with given attack time and amplitude values for each time interval i.
hz(note) returns note frequency
scale(i, mode) returns node at position i in the given scale.
Example: tri(hz(scale(seq(480,r(5))))) plays random notes from the major scale
mix(v1, v2, ...) mixes voices to avoid overflow.
Voice can be a single value or a pair of (volume,voice) values. Volume must be in the range [0..1].
lpf(signal, cutoff) low-pass filter
Any word can be a variable name if there is no function with such name. Variables keep their values between evaluations.
t is time, increased from 0 to infinity by 8000 for each second.
x and y are current mouse cursor position in the range [0..1].
bpm (if set) applies user input on the next beat to keep the tempo.