vqt - nesbox/TIC-80 GitHub Wiki

VQT

Added in 1.3. Requires TIC-80 started with --fft; see FFT.

The Variable-Q Transform maps the spectrum onto 120 logarithmically spaced bins — 10 octaves of 12 notes. Bin frequency is 19.445 * 2^(bin/12) Hz; bin 0 is D#0/Eb0. The normalized variants return a value roughly 0..1 for their bin; the raw variants are not peak-normalized, so their scale depends on the input.

Every variant answers one question: normalized or raw, smoothed or not, whitened or not.

Function Peak-normalized Smoothed Whitened Notes
vqt(bin) yes no no the everyday magnitude
vqts(bin) yes yes no steadier for visuals
vqtr(bin) no no no raw magnitude
vqtrs(bin) no yes no raw and smoothed
vqtw(bin) yes no yes notes stand out from the spectral envelope
vqtsw(bin) yes yes yes whitened and steadier
vqtrw(bin) no no yes whitened without auto-gain
vqtrsw(bin) no yes yes raw, smoothed and whitened

bin is 0..119. A value outside the range reads as zero.

Example

-- one bar per octave, using the smoothed normalized magnitude
function TIC()
    cls(0)

    for octave = 0, 9 do
        local sum = 0
        for note = 0, 11 do
            sum = sum + vqts(octave * 12 + note)
        end

        local h = sum / 12 * 100
        rect(10 + octave * 22, 120 - h, 16, h, 12)
    end
end

Use FFT when you want linear buckets instead of musical notes.