Initial commit
This commit is contained in:
40
HTML/ThreeJS/node_modules/three/src/audio/AudioAnalyser.js
generated
vendored
Normal file
40
HTML/ThreeJS/node_modules/three/src/audio/AudioAnalyser.js
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
class AudioAnalyser {
|
||||
|
||||
constructor( audio, fftSize = 2048 ) {
|
||||
|
||||
this.analyser = audio.context.createAnalyser();
|
||||
this.analyser.fftSize = fftSize;
|
||||
|
||||
this.data = new Uint8Array( this.analyser.frequencyBinCount );
|
||||
|
||||
audio.getOutput().connect( this.analyser );
|
||||
|
||||
}
|
||||
|
||||
|
||||
getFrequencyData() {
|
||||
|
||||
this.analyser.getByteFrequencyData( this.data );
|
||||
|
||||
return this.data;
|
||||
|
||||
}
|
||||
|
||||
getAverageFrequency() {
|
||||
|
||||
let value = 0;
|
||||
const data = this.getFrequencyData();
|
||||
|
||||
for ( let i = 0; i < data.length; i ++ ) {
|
||||
|
||||
value += data[ i ];
|
||||
|
||||
}
|
||||
|
||||
return value / data.length;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { AudioAnalyser };
|
||||
Reference in New Issue
Block a user