Skip to content

Instantly share code, notes, and snippets.

@TF3RDL
TF3RDL / Sb-sDFT.js
Last active January 15, 2024 07:45
Variable-Q sliding DFT algorithm
/**
* Single file implementation of variable-Q sliding DFT (VQ-sDFT)
*
* The frequency bands data is formatted like:
* {lo: lowerBound,
* ctr: center,
* hi: higherBound}
*
* where lo and hi are used for calculating the necessary bandwidth for variable-Q/constant-Q transform spectrum analysis and ctr for center frequency. This is generated using functions like generateFreqBands()
*
@TF3RDL
TF3RDL / cameraShake.js
Created May 26, 2023 08:35
Trigger-based shake effect from musicvid.org
class TriggerBasedShake {
constructor(
returnSpeed = 0.1,
displacementThreshold = 4,
waveDuration = Math.PI/8,
movementAmount = 1,
maxShakeIntensity = 1,
maxShakeDisplacement = 4,
minShakeScalar = 0.9,
maxShakeScalar = 1.6,
@TF3RDL
TF3RDL / analog-style-analyzer.js
Last active February 29, 2024 23:12
Implementation of the sliding windowed infinite Fourier transform with functionality to cascade sDFTs serially as well as the analog-style spectrum analyzer implementation
/**
* Single file implementation of analog-style spectrum analyzer using cascaded biquad bandpass filter bank (works best on truly-logarithmic frequency scale and constant-Q resolution)
*
* The frequency bands data is formatted like:
* {lo: lowerBound,
* ctr: center,
* hi: higherBound}
*
* where lo and hi are used for calculating the necessary bandwidth for variable-Q transform spectrum visualizations and ctr for center frequency. This is generated using functions like generateFreqBands
* Note: This one uses its own biquad filter routine for calculating biquad bandpass filter instead of WebAudio API provided BiquadFilterNode, so it allows visualization of data that isn't WebAudio and no OfflineAudioContext is needed
@TF3RDL
TF3RDL / audio-analyzer.js
Last active January 7, 2024 02:43
A collection of audio analysis algorithms and some helper functions
/**
* A collection of audio analysis algorithms and some helper functions
*/
// p5.js map function
function map(x, min, max, targetMin, targetMax) {
return (x - min) / (max - min) * (targetMax - targetMin) + targetMin;
}
function clamp(x, min, max) {
@TF3RDL
TF3RDL / cqt.js
Last active June 16, 2023 22:02
Constant-Q transform using Goertzel algorithm
/**
* Constant-Q Transform (CQT) calculated using Goertzel algorithm
*
* This by itself doesn't need Web Audio API in order to work but it is necessary for real-time visualizations
*
* Real-time usage:
* analyserNode.getFloatTimeDomainData(dataArray);
* const spectrum = cqt(dataArray, freqBands, audioCtx.sampleRate, bandwidthOffset, windowFunction);
*
* Note: the implementation of this CQT is slow compared to FFT