From 009d9aa1e9d38b313f1ce5e7c339765ed91225c4 Mon Sep 17 00:00:00 2001 From: Jarod Brennfleck Date: Fri, 16 Jun 2017 17:35:39 +0930 Subject: [PATCH] Take FULL advantage of getters and setters Thanks @therewasaguy and @GoToLoop! --- src/fft.js | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/src/fft.js b/src/fft.js index a6df7576..9ab04a7e 100644 --- a/src/fft.js +++ b/src/fft.js @@ -91,28 +91,38 @@ define(function (require) { * */ p5.FFT = function(smoothing, bins) { - Object.defineProperty(this, 'bins', { - get: function () { - return this.analyser.fftSize / 2; - }, - set: function (b) { - this.analyser.fftSize = b * 2; + this.input = this.analyser = p5sound.audiocontext.createAnalyser(); + + Object.defineProperties(this, { + 'bins': { + get: function() { + return this.analyser.fftSize / 2; + }, + set: function(b) { + this.analyser.fftSize = (b * 2) || 1024; + }, + configurable: true, + enumerable: true }, - configurable: true, - enumerable: true + 'smoothing': { + get: function() { + return this.analyser.smoothing; + }, + set: function(s) { + this.analyser.smoothingTimeConstant = s || 0.8; + }, + configurable: true, + enumerable: true + } }); - this.smoothing = smoothing || 0.8; - this.bins = bins || 1024; - var FFT_SIZE = bins*2 || 2048; - this.input = this.analyser = p5sound.audiocontext.createAnalyser(); + // + this.smoothing = smoothing; + this.bins = bins; // default connections to p5sound fftMeter p5sound.fftMeter.connect(this.analyser); - this.analyser.smoothingTimeConstant = this.smoothing; - this.analyser.fftSize = FFT_SIZE; - this.freqDomain = new Uint8Array(this.analyser.frequencyBinCount); this.timeDomain = new Uint8Array(this.analyser.frequencyBinCount);