FFT - nesbox/TIC-80 GitHub Wiki

FFT support was added in version 1.2; the raw fftr/fftrs variants and the VQT family followed in 1.3.

FFT is short for Fast Fourier Transform, which lets us turn music into data. Its primary use in TIC-80 is Byte Jams, Byte Battles and general livecoding.

This feature is off by default; you have to launch TIC-80 with the --fft CLI parameter. Usually you want to capture the loopback, i.e. whatever's playing on your computer.

On Windows, use --fftcaptureplaybackdevices to do so. Double-check the console output you're not accidentally capturing your microphone when running without it.

On Mac, you'll need something like BlackHole, as it's not built-in.

On Linux, in theory you should have loopback by default, in practice it varies a lot.

Use --fftlist to print the available capture devices and --fftdevice=<str> to pick one by name. The full list of the FFT startup options is on the command line page.

API

The FFT family maps the audible spectrum onto 1024 buckets. Each value is roughly 0..1, based on the intensity of the sound at that frequency at that time.

Function Returns
fft(start_freq, end_freq=-1) The magnitude of one bucket, or the sum of all values in the range. Amplified and peak-normalized.
ffts(start_freq, end_freq=-1) The same with smoothing applied between frames.
fftr(start_freq, end_freq=-1) The raw magnitude before amplification and peak normalization.
fftrs(start_freq, end_freq=-1) The smoothed raw magnitude.

start_freq and end_freq are bucket indexes. Without end_freq you get a single bucket; with it, you get the sum over the range.

function TIC()
    cls(0)
    for i = 0, 63 do
        local v = fft(i * 16, i * 16 + 15)
        rect(i * 3, 136 - v * 100, 2, v * 100, 12)
    end
end

For musical analysis, the VQT family offers 120 logarithmically spaced bins instead of the linear FFT buckets.

⚠️ **GitHub.com Fallback** ⚠️