SpectrumAnalyzer

class SpectrumAnalyzer(fftSize: Int = 0, val bandCount: Int = 40, hop: Int = 0, scopePoints: Int = 256, sampleRate: Int, stereoPoints: Int = 512)

Causal, sample-timed audio analysis with per-channel power and one shared display gain.

Feed sanitised or borrowed interleaved samples from one analysis thread. Short spectra use a Hann window, per-channel power averaging and fractional ERB integration. Programme loudness uses an independently timed 400 ms K-weighted channel sum. All energy display drivers share its bounded causal or fixed-song reference and their fast/slow envelopes advance in media time. Mono mixing is only for the decorative scope; opposite channel polarities retain their energy.

Each analysis publishes new snapshot storage. Readers may retain an old frame while analysis continues. The recognition helpers are separate from the calibrated power and display paths.

Constructors

Link copied to clipboard
constructor(fftSize: Int = 0, bandCount: Int = 40, hop: Int = 0, scopePoints: Int = 256, sampleRate: Int, stereoPoints: Int = 512)

Properties

Link copied to clipboard

How many bars to draw.

Link copied to clipboard
Link copied to clipboard
val hop: Int
Link copied to clipboard

The newest analysis. Read it from the drawing thread as often as you like.

Link copied to clipboard

Called for every analysis, on the feeding thread, before latest changes.

Link copied to clipboard

Number of non-finite or beyond-headroom samples sanitised by direct PCM input.

Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
fun feed(interleaved: FloatArray, frames: Int, format: AudioFormat, ptsMicros: Long? = null)

PCM with explicit layout metadata. Its sample rate must match this analyser. Reset before changing channels or layout; a different sample rate needs a new analyser. Inputs are floats regardless of AudioFormat.sampleFormat. Non-finite values become zero and finite values are limited to amplitude +/-16, with each change counted in sanitizedSamples.

fun feed(interleaved: FloatArray, frames: Int, channels: Int, ptsMicros: Long? = null)

Takes frames sample frames of channels-channel interleaved audio and analyses whatever it can. ptsMicros is the media timestamp of the first frame, or null when unknown. Zero and negative positions are valid timestamps.

Link copied to clipboard
fun reset()

Drops carried values and advances local continuity. Pair with SpectrumTimeline.clear.

fun reset(generation: Generation, analysisRevision: Long)

Resets into an explicitly supplied timeline identity. Call on the feeding thread, then publish into a timeline with matching SpectrumTimeline.generation and SpectrumTimeline.revision. This does not itself reset that timeline.

Link copied to clipboard

A complete-song reference in linear K-weighted programme power. Positive finite values transition the one shared gain over two media seconds. Null resumes the causal reference. Call on the feeding thread. Reset retains this value for seeks; clear it for another song.