Browse Source

Merge pull request #19975 from ianpurvis/audio-analyser-es6-class

AudioAnalyser: Convert to es6 class
Mr.doob 5 years ago
parent
commit
7353094e87
1 changed files with 12 additions and 11 deletions
  1. 12 11
      src/audio/AudioAnalyser.js

+ 12 - 11
src/audio/AudioAnalyser.js

@@ -1,25 +1,26 @@
-function AudioAnalyser( audio, fftSize ) {
+class AudioAnalyser {
 
-	this.analyser = audio.context.createAnalyser();
-	this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
+	constructor( audio, fftSize ) {
 
-	this.data = new Uint8Array( this.analyser.frequencyBinCount );
+		this.analyser = audio.context.createAnalyser();
+		this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
 
-	audio.getOutput().connect( this.analyser );
+		this.data = new Uint8Array( this.analyser.frequencyBinCount );
 
-}
+		audio.getOutput().connect( this.analyser );
+
+	}
 
-Object.assign( AudioAnalyser.prototype, {
 
-	getFrequencyData: function () {
+	getFrequencyData() {
 
 		this.analyser.getByteFrequencyData( this.data );
 
 		return this.data;
 
-	},
+	}
 
-	getAverageFrequency: function () {
+	getAverageFrequency() {
 
 		let value = 0;
 		const data = this.getFrequencyData();
@@ -34,6 +35,6 @@ Object.assign( AudioAnalyser.prototype, {
 
 	}
 
-} );
+}
 
 export { AudioAnalyser };