Class: AudioAnalyzer
Defined in: src/audio/AudioAnalyzer.ts:126
Reads a live frequency spectrum and feeds it into manim-web animations.
Constructors
Constructor
new AudioAnalyzer(
options):AudioAnalyzer
Defined in: src/audio/AudioAnalyzer.ts:135
Parameters
options
AudioAnalyzerOptions = {}
Returns
AudioAnalyzer
Accessors
analyser
Get Signature
get analyser():
SpectrumAnalyser
Defined in: src/audio/AudioAnalyzer.ts:346
The connected analyser, or null when unavailable.
Returns
connected
Get Signature
get connected():
boolean
Defined in: src/audio/AudioAnalyzer.ts:336
Whether an analyser is connected (reads return live data).
Returns
boolean
frequencyBinCount
Get Signature
get frequencyBinCount():
number
Defined in: src/audio/AudioAnalyzer.ts:341
The number of frequency bins the spectrum reads produce.
Returns
number
Methods
bindToTracker()
bindToTracker(
tracker,read,options):UpdaterFunction
Defined in: src/audio/AudioAnalyzer.ts:304
Drive a ValueTracker from an audio read each frame.
Adds an updater to the tracker that sets its value to
offset + read() * scale on every update(dt). Other mobjects follow the
tracker through their own updaters.
Parameters
tracker
The tracker to drive
read
() => number
Audio read to sample (defaults to getLevel)
options
Scale and offset applied to the read
Returns
The updater, so it can be removed with tracker.removeUpdater
connectMediaElement()
connectMediaElement(
element):this
Defined in: src/audio/AudioAnalyzer.ts:183
Tap an <audio> / <video> element. Creates an owned AudioContext.
Parameters
element
HTMLMediaElement
Returns
this
this for chaining
connectSource()
connectSource(
node):this
Defined in: src/audio/AudioAnalyzer.ts:204
Tap an existing AudioNode (for example a BufferSource or GainNode).
The node's own AudioContext is used; no new context is created.
Parameters
node
AudioNode
Returns
this
this for chaining
createUpdater()
createUpdater<
M>(apply):UpdaterFunction
Defined in: src/audio/AudioAnalyzer.ts:325
Build an updater that maps the spectrum onto any mobject property.
The returned updater passes the mobject, this analyzer, and dt to
apply, so apply can read bands and set any property. Add it with
mobject.addUpdater(analyzer.createUpdater(...)).
Type Parameters
M
M extends Mobject
Parameters
apply
(mobject, analyzer, dt) => void
Returns
dispose()
dispose():
void
Defined in: src/audio/AudioAnalyzer.ts:351
Release the owned AudioContext, if this analyzer created one.
Returns
void
getBand()
getBand(
lowHz,highHz):number
Defined in: src/audio/AudioAnalyzer.ts:242
Average the normalized energy [0, 1] across the band [lowHz, highHz].
Returns 0 when no analyser is connected or the band is empty.
Parameters
lowHz
number
highHz
number
Returns
number
getBass()
getBass():
number
Defined in: src/audio/AudioAnalyzer.ts:257
Normalized bass energy [0, 1] (20-250 Hz).
Returns
number
getByteFrequencyData()
getByteFrequencyData(
target?):Uint8Array
Defined in: src/audio/AudioAnalyzer.ts:220
Fill target (or an internal buffer) with the byte frequency spectrum.
Returns a zero-filled buffer when no analyser is connected.
Parameters
target?
Uint8Array
Returns
Uint8Array
The buffer that was written
getFrequencyData()
getFrequencyData():
Uint8Array
Defined in: src/audio/AudioAnalyzer.ts:234
Alias of getByteFrequencyData that returns the internal buffer.
Returns
Uint8Array
getLevel()
getLevel():
number
Defined in: src/audio/AudioAnalyzer.ts:275
Overall loudness as the RMS [0, 1] of the time-domain waveform. Returns 0 when no analyser is connected.
Returns
number
getMid()
getMid():
number
Defined in: src/audio/AudioAnalyzer.ts:262
Normalized mid energy [0, 1] (250-4000 Hz).
Returns
number
getTreble()
getTreble():
number
Defined in: src/audio/AudioAnalyzer.ts:267
Normalized treble energy [0, 1] (4000-20000 Hz).
Returns
number
fromAudioManager()
staticfromAudioManager(manager,options?):AudioAnalyzer
Defined in: src/audio/AudioAnalyzer.ts:163
Create an analyzer tapping the master output of an AudioManager. No-op (silent, returns zeros) when Web Audio is unavailable.
Parameters
manager
options?
Returns
AudioAnalyzer
fromMediaElement()
staticfromMediaElement(element,options?):AudioAnalyzer
Defined in: src/audio/AudioAnalyzer.ts:152
Create an analyzer tapping an <audio> / <video> element.
The element stays audible (the analyser is wired to the destination).
No-op (silent, returns zeros) when Web Audio is unavailable.
Parameters
element
HTMLMediaElement
options?
Returns
AudioAnalyzer