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

AudioAnalyser.getAverageFrequency()

描述

该方法是three.js中AudioAnalyser的一个方法,用于获取当前音频信号的平均频率值。

语法

.getAverageFrequency()

返回值

返回一个number类型的数值,表示当前音频信号的平均频率值。

示例

const audio = new Audio('/path/to/my/audio.mp3');
const listener = new THREE.AudioListener();
const analyser = new THREE.AudioAnalyser(listener, 1024);

const sound = new THREE.Audio(listener);
sound.setMediaElementSource(audio);
sound.connect(analyser.input);

// 获取当前音频信号的平均频率值
const averageFrequency = analyser.getAverageFrequency();

注意事项

  • 调用该方法前需要先调用AudioAnalyser.getFrequencyData()方法,对音频信号进行分析。
  • 该方法返回的数值在0到1之间,可以通过将该值乘以自定义系数,转换为更合适的数值范围。
  • 如果想获取具体某一频段的值,可以通过调用AudioAnalyser.getFrequencyData()方法获取到所有频段的数值后,自行计算出具体频段的数值。

参考文献