11'use strict' ;
22
3- define ( function ( require ) {
3+ define ( function ( require ) {
44 var p5sound = require ( 'master' ) ;
55
66 /**
@@ -93,7 +93,7 @@ define(function (require) {
9393 this . input = this . analyser = p5sound . audiocontext . createAnalyser ( ) ;
9494
9595 Object . defineProperties ( this , {
96- ' bins' : {
96+ bins : {
9797 get : function ( ) {
9898 return this . analyser . fftSize / 2 ;
9999 } ,
@@ -103,7 +103,7 @@ define(function (require) {
103103 configurable : true ,
104104 enumerable : true
105105 } ,
106- ' smoothing' : {
106+ smoothing : {
107107 get : function ( ) {
108108 return this . analyser . smoothingTimeConstant ;
109109 } ,
@@ -193,14 +193,13 @@ define(function (require) {
193193 } else {
194194 timeToInt ( this , this . timeDomain ) ;
195195 this . analyser . getByteTimeDomainData ( this . timeDomain ) ;
196- var normalArray = new Array ( ) ;
196+ var normalArray = new Array ( ) ;
197197 for ( var j = 0 ; j < this . timeDomain . length ; j ++ ) {
198198 var scaled = p5 . prototype . map ( this . timeDomain [ j ] , 0 , 255 , - 1 , 1 ) ;
199199 normalArray . push ( scaled ) ;
200200 }
201201 return normalArray ;
202202 }
203-
204203 } ;
205204
206205 /**
@@ -291,17 +290,16 @@ define(function (require) {
291290 } else {
292291 freqToInt ( this , this . freqDomain ) ;
293292 this . analyser . getByteFrequencyData ( this . freqDomain ) ;
294- var normalArray = Array . apply ( [ ] , this . freqDomain ) ;
293+ var normalArray = Array . apply ( [ ] , this . freqDomain ) ;
295294 normalArray . length === this . analyser . fftSize ;
296295 normalArray . constructor === Array ;
297296 return normalArray ;
298297 }
299-
300298 } ;
301299
302300 /**
303301 * Returns the amount of energy (volume) at a specific
304- * <a href="en.wikipedia.org/wiki/Audio_frequency" target="_blank">
302+ * <a href="https:// en.wikipedia.org/wiki/Audio_frequency" target="_blank">
305303 * frequency</a>, or the average amount of energy between two
306304 * frequencies. Accepts Number(s) corresponding
307305 * to frequency (in Hz), or a String corresponding to predefined
@@ -328,7 +326,7 @@ define(function (require) {
328326 *
329327 */
330328 p5 . FFT . prototype . getEnergy = function ( frequency1 , frequency2 ) {
331- var nyquist = p5sound . audiocontext . sampleRate / 2 ;
329+ var nyquist = p5sound . audiocontext . sampleRate / 2 ;
332330
333331 if ( frequency1 === 'bass' ) {
334332 frequency1 = this . bass [ 0 ] ;
@@ -349,37 +347,32 @@ define(function (require) {
349347
350348 if ( typeof frequency1 !== 'number' ) {
351349 throw 'invalid input for getEnergy()' ;
352- }
353-
354- // if only one parameter:
355- else if ( ! frequency2 ) {
356- var index = Math . round ( frequency1 / nyquist * this . freqDomain . length ) ;
350+ } else if ( ! frequency2 ) {
351+ // if only one parameter:
352+ var index = Math . round ( frequency1 / nyquist * this . freqDomain . length ) ;
357353 return this . freqDomain [ index ] ;
358- }
359-
360- // if two parameters:
361- else if ( frequency1 && frequency2 ) {
354+ } else if ( frequency1 && frequency2 ) {
355+ // if two parameters:
362356 // if second is higher than first
363357 if ( frequency1 > frequency2 ) {
364358 var swap = frequency2 ;
365359 frequency2 = frequency1 ;
366360 frequency1 = swap ;
367361 }
368- var lowIndex = Math . round ( frequency1 / nyquist * this . freqDomain . length ) ;
369- var highIndex = Math . round ( frequency2 / nyquist * this . freqDomain . length ) ;
362+ var lowIndex = Math . round ( frequency1 / nyquist * this . freqDomain . length ) ;
363+ var highIndex = Math . round ( frequency2 / nyquist * this . freqDomain . length ) ;
370364
371365 var total = 0 ;
372366 var numFrequencies = 0 ;
373367 // add up all of the values for the frequencies
374- for ( var i = lowIndex ; i <= highIndex ; i ++ ) {
368+ for ( var i = lowIndex ; i <= highIndex ; i ++ ) {
375369 total += this . freqDomain [ i ] ;
376370 numFrequencies += 1 ;
377371 }
378372 // divide by total number of frequencies
379- var toReturn = total / numFrequencies ;
373+ var toReturn = total / numFrequencies ;
380374 return toReturn ;
381- }
382- else {
375+ } else {
383376 throw 'invalid input for getEnergy()' ;
384377 }
385378 } ;
@@ -458,24 +451,23 @@ define(function (require) {
458451 * </code></div>
459452 */
460453 p5 . FFT . prototype . getCentroid = function ( ) {
461- var nyquist = p5sound . audiocontext . sampleRate / 2 ;
454+ var nyquist = p5sound . audiocontext . sampleRate / 2 ;
462455 var cumulative_sum = 0 ;
463456 var centroid_normalization = 0 ;
464457
465- for ( var i = 0 ; i < this . freqDomain . length ; i ++ )
466- {
458+ for ( var i = 0 ; i < this . freqDomain . length ; i ++ ) {
467459 cumulative_sum += i * this . freqDomain [ i ] ;
468460 centroid_normalization += this . freqDomain [ i ] ;
469461 }
470462
471463 var mean_freq_index = 0 ;
472464
473- if ( centroid_normalization !== 0 )
474- {
465+ if ( centroid_normalization !== 0 ) {
475466 mean_freq_index = cumulative_sum / centroid_normalization ;
476467 }
477468
478- var spec_centroid_freq = mean_freq_index * ( nyquist / this . freqDomain . length ) ;
469+ var spec_centroid_freq =
470+ mean_freq_index * ( nyquist / this . freqDomain . length ) ;
479471 return spec_centroid_freq ;
480472 } ;
481473
@@ -526,10 +518,10 @@ define(function (require) {
526518 var groupIndex = 0 ;
527519
528520 for ( var specIndex = 0 ; specIndex < spectrumLength ; specIndex ++ ) {
529-
530- linearAverages [ groupIndex ] = linearAverages [ groupIndex ] !== undefined
531- ? ( linearAverages [ groupIndex ] + spectrum [ specIndex ] ) / 2
532- : spectrum [ specIndex ] ;
521+ linearAverages [ groupIndex ] =
522+ linearAverages [ groupIndex ] !== undefined
523+ ? ( linearAverages [ groupIndex ] + spectrum [ specIndex ] ) / 2
524+ : spectrum [ specIndex ] ;
533525
534526 // Increase the group index when the last element of the group is processed
535527 if ( specIndex % spectrumStep === spectrumStep - 1 ) {
@@ -563,16 +555,19 @@ define(function (require) {
563555 var octaveIndex = 0 ;
564556
565557 for ( var specIndex = 0 ; specIndex < spectrumLength ; specIndex ++ ) {
566- var specIndexFrequency = Math . round ( specIndex * nyquist / this . freqDomain . length ) ;
558+ var specIndexFrequency = Math . round (
559+ specIndex * nyquist / this . freqDomain . length
560+ ) ;
567561
568562 // Increase the group index if the current frequency exceeds the limits of the band
569563 if ( specIndexFrequency > octaveBands [ octaveIndex ] . hi ) {
570564 octaveIndex ++ ;
571565 }
572566
573- logAverages [ octaveIndex ] = logAverages [ octaveIndex ] !== undefined
574- ? ( logAverages [ octaveIndex ] + spectrum [ specIndex ] ) / 2
575- : spectrum [ specIndex ] ;
567+ logAverages [ octaveIndex ] =
568+ logAverages [ octaveIndex ] !== undefined
569+ ? ( logAverages [ octaveIndex ] + spectrum [ specIndex ] ) / 2
570+ : spectrum [ specIndex ] ;
576571 }
577572
578573 return logAverages ;
@@ -592,24 +587,23 @@ define(function (require) {
592587 * @return {Array } octaveBands Array of octave band objects with their bounds
593588 */
594589 p5 . FFT . prototype . getOctaveBands = function ( N , fCtr0 ) {
595- var N = N || 3 ; // Default to 1/3 Octave Bands
596- var fCtr0 = fCtr0 || 15.625 ; // Minimum central frequency, defaults to 15.625Hz
590+ var N = N || 3 ; // Default to 1/3 Octave Bands
591+ var fCtr0 = fCtr0 || 15.625 ; // Minimum central frequency, defaults to 15.625Hz
597592
598593 var octaveBands = [ ] ;
599594 var lastFrequencyBand = {
600- lo : fCtr0 / Math . pow ( 2 , 1 / ( 2 * N ) ) ,
595+ lo : fCtr0 / Math . pow ( 2 , 1 / ( 2 * N ) ) ,
601596 ctr : fCtr0 ,
602- hi : fCtr0 * Math . pow ( 2 , 1 / ( 2 * N ) ) ,
597+ hi : fCtr0 * Math . pow ( 2 , 1 / ( 2 * N ) )
603598 } ;
604599 octaveBands . push ( lastFrequencyBand ) ;
605600
606601 var nyquist = p5sound . audiocontext . sampleRate / 2 ;
607602 while ( lastFrequencyBand . hi < nyquist ) {
608-
609603 var newFrequencyBand = { } ;
610604 newFrequencyBand . lo = lastFrequencyBand . hi ;
611605 newFrequencyBand . ctr = lastFrequencyBand . ctr * Math . pow ( 2 , 1 / N ) ;
612- newFrequencyBand . hi = newFrequencyBand . ctr * Math . pow ( 2 , 1 / ( 2 * N ) ) ;
606+ newFrequencyBand . hi = newFrequencyBand . ctr * Math . pow ( 2 , 1 / ( 2 * N ) ) ;
613607
614608 octaveBands . push ( newFrequencyBand ) ;
615609 lastFrequencyBand = newFrequencyBand ;
@@ -619,26 +613,24 @@ define(function (require) {
619613 } ;
620614
621615 // helper methods to convert type from float (dB) to int (0-255)
622- var freqToFloat = function ( fft ) {
616+ var freqToFloat = function ( fft ) {
623617 if ( fft . freqDomain instanceof Float32Array === false ) {
624618 fft . freqDomain = new Float32Array ( fft . analyser . frequencyBinCount ) ;
625619 }
626620 } ;
627- var freqToInt = function ( fft ) {
621+ var freqToInt = function ( fft ) {
628622 if ( fft . freqDomain instanceof Uint8Array === false ) {
629623 fft . freqDomain = new Uint8Array ( fft . analyser . frequencyBinCount ) ;
630624 }
631625 } ;
632- var timeToFloat = function ( fft ) {
626+ var timeToFloat = function ( fft ) {
633627 if ( fft . timeDomain instanceof Float32Array === false ) {
634628 fft . timeDomain = new Float32Array ( fft . analyser . frequencyBinCount ) ;
635629 }
636630 } ;
637- var timeToInt = function ( fft ) {
631+ var timeToInt = function ( fft ) {
638632 if ( fft . timeDomain instanceof Uint8Array === false ) {
639633 fft . timeDomain = new Uint8Array ( fft . analyser . frequencyBinCount ) ;
640634 }
641635 } ;
642-
643-
644636} ) ;
0 commit comments