From 6de0770487c0dac22f085a4c81de7088122ec207 Mon Sep 17 00:00:00 2001 From: Jarod Brennfleck Date: Sun, 11 Jun 2017 16:35:30 +0930 Subject: [PATCH] Change the fftSize on the fly! Added a function that allows users to be able to change the bin size/fftSize. --- src/fft.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/fft.js b/src/fft.js index 5a484df5..4d59b55a 100644 --- a/src/fft.js +++ b/src/fft.js @@ -472,6 +472,17 @@ define(function (require) { } this.analyser.smoothingTimeConstant = s; }; + + /** + * Changes the length of the resulting array, the bin size and in turn the fftSize of the analyser. + * + * @method setBins + * @param {Number} bins Must be a power of two between 16 and 1024. + */ + p5.FFT.prototype.setBins = function(b) { + this.bins = b; + this.analyser.fftSize = b * 2; + } p5.FFT.prototype.dispose = function() { // remove reference from soundArray @@ -621,4 +632,4 @@ define(function (require) { }; -}); \ No newline at end of file +});