@@ -298,7 +298,7 @@ class FFT {
298
298
* <a href="https://en.wikipedia.org/wiki/Audio_frequency" target="_blank">
299
299
* frequency</a>, or the average amount of energy between two
300
300
* frequencies. Accepts Number(s) corresponding
301
- * to frequency (in Hz), or a "string" corresponding to predefined
301
+ * to frequency (in Hz) (frequency must be >= 0) , or a "string" corresponding to predefined
302
302
* frequency ranges ("bass", "lowMid", "mid", "highMid", "treble").
303
303
* Returns a range between 0 (no energy/volume at that frequency) and
304
304
* 255 (maximum energy).
@@ -318,8 +318,8 @@ class FFT {
318
318
* will return average amount of
319
319
* energy that exists between the
320
320
* two frequencies.
321
- * @return {Number } Energy Energy (volume/amplitude) from
322
- * 0 and 255.
321
+ * @return {Number } Energy (volume/amplitude) from
322
+ * 0 and 255.
323
323
*
324
324
*/
325
325
getEnergy ( frequency1 , frequency2 ) {
@@ -350,7 +350,9 @@ class FFT {
350
350
var index = Math . round ( ( frequency1 / nyquist ) * this . freqDomain . length ) ;
351
351
return this . freqDomain [ index ] ;
352
352
}
353
-
353
+ if ( frequency1 < 0 || frequency2 < 0 ) {
354
+ throw 'invalid input for getEnergy(), frequency cannot be a negative number' ;
355
+ }
354
356
// if two parameters:
355
357
// if second is higher than first
356
358
if ( frequency1 > frequency2 ) {
0 commit comments