This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Second-order IIR filter with arbitrary coefficient configurations | |
class IIRFilter { | |
constructor(a0, a1, a2, b1, b2) { | |
this.recalcCoeffs(a0, a1, a2, b1, b2); | |
} | |
recalcCoeffs(a0 = 0, a1 = 0, a2 = 0, b1 = 0, b2 = 0) { | |
this.a0 = a0; | |
this.a1 = a1; | |
this.a2 = a2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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() | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TriggerBasedShake { | |
constructor( | |
returnSpeed = 0.1, | |
displacementThreshold = 4, | |
waveDuration = Math.PI/8, | |
movementAmount = 1, | |
maxShakeIntensity = 1, | |
maxShakeDisplacement = 4, | |
minShakeScalar = 0.9, | |
maxShakeScalar = 1.6, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 |