BufferGeometry
Object3D
Raycaster
Camera
CubeCamera
PerspectiveCamera
OrthographicCamera
StereoCamera
Clock
Curve
CurvePath
Path
Shape
ShapePath
ArrowHelper
AxesHelper
BoxHelper
Box3Helper
CameraHelper
DirectionalLightHelper
GridHelper
PolarGridHelper
HemisphereLightHelper
PlaneHelper
PointLightHelper
SkeletonHelper
SpotLightHelper
Light
PointLight
RectAreaLight
SpotLight
DirectionalLight
HemisphereLight
LightShadow
PointLightShadow
AnimationLoader
AudioLoader
BufferGeometryLoader
CompressedTextureLoader
CubeTextureLoader
DataTextureLoader
FileLoader
ImageBitmapLoader
ImageLoader
Loader
LoaderUtils
MaterialLoader
ObjectLoader
TextureLoader
LoadingManager
Material
Box2
Box3
Color
Cylindrical
Euler
Frustum
Interpolant
Line3
MathUtils
Matrix3
Matrix4
Plane
Quaternion
AnimationAction
AnimationClip
AnimationMixer
AnimationObjectGroup
AnimationUtils
keyframeTrack
PropertyBinding
PropertyMixer
BooleanKeyframeTrack
QuaternionKeyframeTrack
StringKeyframeTrack
Audio
AudioAnalyser
AudioContext
AudioListener
PositionalAudio

AudioListener.getInput()

The getInput() method of the AudioListener class in three.js returns the Web Audio API AnalyserNode that is connected to the input of the AudioListener.

Syntax

AudioListener.getInput()

Return Value

The getInput() method returns an instance of the AnalyserNode Web Audio API interface.

Usage

The getInput() method is used to retrieve the AnalyserNode that is connected to the input of the AudioListener. This node can be used to perform real-time frequency analysis on the audio signal that is being received by the listener.

const listener = new THREE.AudioListener();
const analyser = listener.getInput();

// Connect an audio source to the listener
const audio = new THREE.Audio( listener );
const loader = new THREE.AudioLoader();
loader.load( 'path/to/audio.mp3', function( buffer ) {
    audio.setBuffer( buffer );
    audio.play();
});

// Perform real-time frequency analysis on the input signal
const dataArray = new Float32Array( analyser.frequencyBinCount );
analyser.getFloatFrequencyData(dataArray);

Example

In this example, we create an AudioListener and retrieve the AnalyserNode for real-time frequency analysis. We then load an audio file and connect it to the listener. Finally, we use the AnalyserNode to animate a mesh based on the audio frequency data.

const listener = new THREE.AudioListener();
const analyser = listener.getInput();
const audio = new THREE.Audio( listener );
const loader = new THREE.AudioLoader();
loader.load( 'path/to/audio.mp3', function( buffer ) {
    audio.setBuffer( buffer );
    audio.play();
});

const geometry = new THREE.BoxBufferGeometry( 1, 1, 1 );
const material = new THREE.MeshStandardMaterial({ color: 0xffffff });
const mesh = new THREE.Mesh( geometry, material );
scene.add( mesh );

const dataArray = new Float32Array( analyser.frequencyBinCount );
const animate = function () {
    requestAnimationFrame( animate );
    analyser.getFloatFrequencyData(dataArray);
    
    const frequency = dataArray[0] || 0;
    mesh.scale.set( 1+frequency/100, 1+frequency/100, 1+frequency/100 );
    mesh.rotation.x += 0.01;
    mesh.rotation.y += 0.01;
    renderer.render( scene, camera );
};
animate();

Browser Compatibility

The getInput() method is supported in all modern browsers that support the Web Audio API.

Conclusion

The getInput() method of the AudioListener class in three.js is used to retrieve the AnalyserNode that is connected to the input of the listener. This node can be used to perform real-time frequency analysis on the audio signal that is being received by the listener.