getEnergy(frequency1, frequency2) {
    var nyquist = p5sound.audiocontext.sampleRate / 2;

    if (frequency1 === 'bass') {
      frequency1 = this.bass[0];
      frequency2 = this.bass[1];
    } else if (frequency1 === 'lowMid') {
      frequency1 = this.lowMid[0];
      frequency2 = this.lowMid[1];
    } else if (frequency1 === 'mid') {
      frequency1 = this.mid[0];
      frequency2 = this.mid[1];
    } else if (frequency1 === 'highMid') {
      frequency1 = this.highMid[0];
      frequency2 = this.highMid[1];
    } else if (frequency1 === 'treble') {
      frequency1 = this.treble[0];
      frequency2 = this.treble[1];
    }

    if (typeof frequency1 !== 'number') {
      throw 'invalid input for getEnergy()';
    }
    if (typeof frequency2 !== 'number') {
      // if only one parameter:
      var index = Math.round((frequency1 / nyquist) * this.freqDomain.length);
      return this.freqDomain[index];
    }
    if (frequency1 < 0 || frequency2 < 0) {
      throw 'invalid input for getEnergy(), frequency cannot be a negative number';
    }
    // if two parameters:
    // if second is higher than first
    if (frequency1 > frequency2) {
      var swap = frequency2;
      frequency2 = frequency1;
      frequency1 = swap;
    }
    var lowIndex = Math.round((frequency1 / nyquist) * this.freqDomain.length);
    var highIndex = Math.round((frequency2 / nyquist) * this.freqDomain.length);

    var total = 0;
    var numFrequencies = 0;
    // add up all of the values for the frequencies
    for (var i = lowIndex; i <= highIndex; i++) {
      total += this.freqDomain[i];
      numFrequencies += 1;
    }
    // divide by total number of frequencies
    var toReturn = total / numFrequencies;
    return toReturn;
  }
Returns the amount of energy (volume) at a specific
 <a href="https://en.wikipedia.org/wiki/Audio_frequency" target="_blank">
 frequency</a>, or the average amount of energy between two
 frequencies. Accepts Number(s) corresponding
 to frequency (in Hz) (frequency must be >= 0), or a "string" corresponding to predefined
 frequency ranges ("bass", "lowMid", "mid", "highMid", "treble").
 Returns a range between 0 (no energy/volume at that frequency) and
 255 (maximum energy).
 <em>NOTE: analyze() must be called prior to getEnergy(). analyze()
 tells the FFT to analyze frequency data, and getEnergy() uses
 the results to determine the value at a specific frequency or
 range of frequencies.</em></p>

 @method  getEnergy
 @for p5.FFT
 @param  {Number|String} frequency1   Will return a value representing
                               energy at this frequency. Alternately,
                               the strings "bass", "lowMid" "mid",
                               "highMid", and "treble" will return
                               predefined frequency ranges.
 @param  {Number} [frequency2] If a second frequency is given,
                               will return average amount of
                               energy that exists between the
                               two frequencies.
 @return {Number}  Energy (volume/amplitude) from
                   0 and 255.