class Audio {

    /**
	 * @constructor
	 * @param {object} season - The season
	 */
    constructor(season) {

        this.season = season;
        this.soundPath = this.season.soundPath;

        const constructor = window.AudioContext || window.webkitAudioContext;
        this.audioCtx = new constructor();
        this.analyser = this.audioCtx.createAnalyser();
        this.frequencyData = new Uint8Array(this.analyser.frequencyBinCount);

    }

    /**
	 * @method
	 * @name loadSound
	 * @description Load the sound
	 */
    loadSound() {

        let request = new XMLHttpRequest();
        request.open('GET', this.soundPath, true);
        request.responseType = 'arraybuffer';

        // Decode asynchronously
        request.onload = function() {

            this.audioCtx.decodeAudioData(request.response, function(buffer) {

                // Success callback
                this.audioBuffer = buffer;

                // Create sound from buffer
                this.audioSource = this.audioCtx.createBufferSource();
                this.audioSource.buffer = this.audioBuffer;

                // Connect the audio source to context's output
                this.audioSource.connect(this.analyser);
                this.analyser.connect(this.audioCtx.destination);

                // Play sound
                this.audioSource.start(this.audioCtx.currentTime);

            }.bind(this), function() {

                // Error callback

            });

        }.bind(this);

        request.send();

    }

    /**
	 * @method
	 * @name getFrequencyData
	 * @return {array} frequencyData
	 */
    getFrequencyData() {

        this.analyser.getByteFrequencyData(this.frequencyData);
        return this.frequencyData;

    }

    /**
	 * @method
	 * @name getAverage
	 * @return {number} average
	 */
    getAverage() {

        let amplitudes = 0;

        for (let amplitude of this.frequencyData) {
            amplitudes += amplitude;
        }

        let average = (amplitudes / this.frequencyData.length) * this.season.factor;

        if (average <= 0) {
            average = .01; // Never = 0
        }

        return average;

    }

}

export default Audio

@@ -198,17 +198,17 @@
   const 
-c
+C
 onstruct
@@ -290,17 +290,17 @@
 x = new 
-c
+C
 onstruct
@@ -551,18 +551,20 @@
         
-le
+cons
 t reques
@@ -745,26 +745,21 @@
 nload = 
-function()
+() =%3E
  %7B%0A%0A    
@@ -818,24 +818,16 @@
 se, 
-function
 (buffer)
  %7B%0A%0A
@@ -822,16 +822,19 @@
 (buffer)
+ =%3E
  %7B%0A%0A    
@@ -853,66 +853,23 @@
 // S
-uccess callback%0A                this.audioBuffer = buffer;
+UCCESS CALLBACK
 %0A%0A  
@@ -910,16 +910,59 @@
  buffer%0A
+                this.audioBuffer = buffer;%0A
         
@@ -1269,24 +1269,124 @@
 tination);%0A%0A
+                // Audio source params%0A                this.audioSource.crossOrigin = 'anonymous';%0A%0A
             
@@ -1488,31 +1488,20 @@
    %7D
-.bind(this), function()
+, (error) =%3E
  %7B%0A%0A
@@ -1524,21 +1524,95 @@
 // E
-rror callback
+RROR CALLBACK%0A                console.info(%60The following error occured : %5Cn$%7Berror%7D%60);
 %0A%0A  
@@ -1639,20 +1639,8 @@
    %7D
-.bind(this);
 %0A%0A  

Update Audio