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

Audio.setFilters()

The setFilters() method is a function in Three.js that allows users to apply a set of custom filters to an Audio object. This enables you to modify the sound wave in real-time, resulting in a more immersive listening experience for your users.

Syntax

audio.setFilters(filters);

Parameters

  • filters (Array): An array of AudioNode objects representing the filters to be applied to the Audio object.

Return Value

This method does not return a value.

Examples

// Create an AudioContext
const context = new AudioContext();

// Create an oscillator node
const oscillator = context.createOscillator();
oscillator.frequency.value = 440;

// Create a low-pass filter node
const lowPassFilter = context.createBiquadFilter();
lowPassFilter.type = 'lowpass';
lowPassFilter.frequency.value = 2000;
 
// Create a high-pass filter node
const highPassFilter = context.createBiquadFilter();
highPassFilter.type = 'highpass';
highPassFilter.frequency.value = 500;

// Create an Audio object with the oscillator as the source
const audio = new THREE.Audio(context);
audio.setNodeSource(oscillator);

// Apply the filters to the Audio object
audio.setFilters([lowPassFilter, highPassFilter]);

In this example, we create an AudioContext and an OscillatorNode to generate a simple sound wave. We create two BiquadFilterNodes to serve as filters, one low-pass and one high-pass. We then create a new Audio object and set its node source to the OscillatorNode using the setNodeSource() method.

Finally, we apply the filters to the Audio object using the setFilters() method, passing in an array of the two filter nodes created earlier.

Notes

  • The setFilters() method should be called after you have set the source node for the Audio object using the setNodeSource() method.
  • The order in which you add the filter nodes to the array passed to the setFilters() method will affect the order in which they are applied to the sound wave. For example, if you want to apply a low-pass filter followed by a high-pass filter, you should add the low-pass filter node to the array before the high-pass filter node.
  • You can create your own custom filter nodes using the createScriptProcessor() method of the AudioContext object. This allows you to apply complex signal processing algorithms to your sound wave in real-time.