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.setFilter()

The setFilter() method of the AudioListener class in Three.js sets the AudioListener's filter property to the provided filter parameter. The filter parameter should be either a null value or an instance of the AudioNode interface.

setFilter(filter: AudioNode | null): AudioListener;

Parameters

  • filter: AudioNode | null - The filter to set for the AudioListener. This can be null or an instance of the AudioNode interface.

Return value

  • AudioListener - The AudioListener object.

Description

The AudioListener object represents the listener, or the person who is listening to the audio. When a sound is played in Three.js, it is connected to an AudioNode, which represents the individual sound source. This AudioNode is then connected to the AudioListener's filter, which applies audio effects to the sound before it reaches the listener's ears.

The setFilter() method allows you to set the filter property of the AudioListener. If you provide a null value, the filter will be removed and the sound will play without any effects. If you provide an instance of the AudioNode interface, the sound will be played with the effects applied by the specified filter.

Examples

Here is an example of how to use the setFilter() method:

const listener = new THREE.AudioListener();
const sound = new THREE.Audio(listener);
const audioLoader = new THREE.AudioLoader();
audioLoader.load('sound.mp3', function(buffer) {
    sound.setBuffer(buffer);
    sound.setLoop(true);
    sound.setVolume(0.5);
    const filter = new THREE.BiquadFilterNode(listener.context, {
        type: 'lowpass',
        frequency: 1000,
        Q: 10
    });
    listener.setFilter(filter);
});

In this example, an AudioListener object is created, as well as an Audio object which plays the sound loaded from the 'sound.mp3' file. The setBuffer(), setLoop(), and setVolume() methods of the Audio object are used to set the sound's buffer, loop setting, and volume, respectively.

A BiquadFilterNode object is created with a 'lowpass' filter type, a frequency of 1000, and a Q factor of 10. The setFilter() method of the AudioListener object is then called with the filter parameter set to the BiquadFilterNode object. This applies the low-pass filter to the sound before it is played back to the listener.