Skip to content

Commit

Permalink
Merge pull request #175 from TheBrenny/patch-1
Browse files Browse the repository at this point in the history
getters and setters for fft bins and smoothing
- change the fftSize on the fly!
  • Loading branch information
therewasaguy authored Jun 18, 2017
2 parents 9a5f5c3 + 009d9aa commit 326649c
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions src/fft.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,38 @@ define(function (require) {
* </code></div>
*/
p5.FFT = function(smoothing, bins) {
this.smoothing = smoothing || 0.8;
this.bins = bins || 1024;
var FFT_SIZE = bins*2 || 2048;
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
},
'smoothing': {
get: function() {
return this.analyser.smoothing;
},
set: function(s) {
this.analyser.smoothingTimeConstant = s || 0.8;
},
configurable: true,
enumerable: true
}
});

//
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);

Expand Down Expand Up @@ -621,4 +642,4 @@ define(function (require) {
};


});
});

0 comments on commit 326649c

Please sign in to comment.