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 [-1..1] otherwise it will be clipped.
To use Bytebeat audio range you can use byte function that expects the input to be in range [0..255] and performs overflow automatically
Example: byte(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.
Most of the functions keep track of time internally, so you only have to specify other arguments such as frequency.
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: byte(t*5&(t>>7)|t*3&(t*4>>10)) - bytebeat music
r(n): random number in the range [0..n]
s(i): sine wave in the rage [-1..1] at phase i in range [0..1]
Example: s(t*14/256) - 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=0.5]) = square wave of given pulse width
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 parallel, M3 is sequential to M1.
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. You may use BD, SD, MT, MA, RS, CP, CB, OH, HH instead.
Example: tr808(SD,seq(240,1,0.2)) plays simple snare rhythm
piano(freq) is a very basic sample-based piano.
Example: piano(hz(seq(240,0,2,4,5,7,5,4,2))) plays major scale notes in a loop
env(z, (t, a)...) wraps signal z with an envelope passing through the points (t, a) where t is time different and a is amplification. If the first pair (t, a) has a < 1 then a very short attack is added automatically.
Example: env(sin(seq(240,440)), (0.1, 0.3), (0.5, 0.1))
hz(note) returns note frequency
scale(i, [mode=MAJOR]) 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(z1, z2, ...) mixes signals together. It is also the only function that does not propagate NaN values.
each(vars, expr, ...) applies and adds up the same expression for each group of values. Useful to construct chords.
lpf(signal, cutoff, Q) low-pass filter
hpf(signal, cutoff, Q) high-pass filter
bpf(signal, cutoff, Q) band-pass filter
bsf(signal, cutoff, Q) band-stop filter
delay(signal, time, damp, feedback) delay effect
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.
C3, C#3, D3, D#3, E3... are note constants that can be used with hz function.
k0, k1, k2, ..., k9 are MIDI keyboard notes that are currently played. 0=A4.
v0, v1, v2, ..., v9 are MIDI keyboard note velocities.
x and y are current mouse cursor position in the range [0..1]. If MIDI keyboard is used they indicate pitch bend and modulation strengths.
bpm (if set) applies user input on the next beat to keep the tempo.