ConstRead the track's BPM tag; the host does not detect tempo. Resolves
success: false with code: 'NOT_FOUND' when the tag is missing or is
not a number between 0 and 500 (exclusive).
ExperimentalcancelDecodePcm: (taskId: string) => Promise<AudioCancelDecodePcmResponse>Cancel a pending audio.decodePcm task by its taskId. The SDK's
audio.decodePcm does this for you on abort and timeout; call it
directly only for tasks started with a raw invoke. cancelled: false
means the task has already settled, does not exist or belongs to another
page.
Cancel a pending audio.generateFullWaveform request by the
taskId of its pending answer. Only the caller that made the
request can cancel it: cancelled: false means the task has already
settled, does not exist or belongs to another caller. A cancelled
task receives one audio:fullWaveformFailed with
code: 'CANCELLED', which may arrive before this answer.
ExperimentaldecodePcm: (path: string, opts?: DecodePcmOptions) => Promise<PcmBuffer>Decode a track, or a range of it, into float32 PCM and resolve with a PcmBuffer that reads the samples in place.
The samples live in read-only shared memory: writing through
getChannelView() crashes the renderer process, so copy them with
toAudioBuffer() when you need to change them, and call release() when
done. One task decodes at a time and the rest queue; identical requests
in flight share one decode.
Rejects with PcmDecodeError carrying the host's code when the host
refuses the request (INVALID_PARAMS also covers a range too large for
one buffer: 256 MiB in 64-bit foobar2000, 64 MiB in 32-bit) or the task
fails later; NOT_SUPPORTED outside a WebView2 host. opts.signal and
opts.timeoutMs (default 120 s, 0 waits forever) cancel the host task
and reject, with an AbortError DOMException and code TIMEOUT
respectively.
Generate a full-track waveform. Resolves synchronously on cache
hit; otherwise awaits the
audio:fullWaveformReady / audio:fullWaveformFailed events.
opts.timeout (default 60 s, 0 waits forever) and opts.signal
end the wait early and cancel the host task through
audio.cancelFullWaveform; neither is sent to the host. An
aborted signal rejects with a DOMException named AbortError, a
timeout with { success: false, error: 'TIMEOUT' }. A cache hit
resolves whatever the signal does.
Failures take three shapes: a request the host refuses up front
(bad path, permission, shutdown) resolves with
{ success: false, error, code }; a decode that fails later rejects
with the audio:fullWaveformFailed payload; a bridge-level error
rejects with an Error. The host decodes two tracks at a time and
queues the rest; time spent in its queue counts toward the timeout.
Report foobar2000's volume and output information.
ExperimentalgetPcmDebugState: () => Promise<AudioGetPcmDebugStateResponse>Shared-buffer support of this page and the state of the decode queue, for tests and diagnostics.
Single-shot poll of the spectrum; requires at least one active
audio.subscribeSpectrum subscription on the host side. With
subscriptionId the frame uses that subscription's parameters.
Paused or stopped playback answers with a silence frame; a stream
that has not produced data yet answers success: false.
Report the spectrum runtime state as the host sees it, for diagnostics.
Report the audio format of the playing track.
Short-window waveform of the current playback stream. Accepts
either (opts) (preferred) or (path, opts) (deprecated form;
the path is ignored because the host always uses the active
stream).
Report whether foobar2000 provides an active visualization stream.
Choose the channels of the visualisation stream behind spectrum frames and
getWaveform; what is heard does not change.
Subscribe to a real-time spectrum stream. The callback receives this subscription's frames only; other subscriptions on the same event name get their own.
With output: 'bins' the callback receives the FFT's linear bins as
power in dB (see SpectrumOutput); band output is kept for
compatibility. A host without bin output registers band output
instead: ready then reports output: 'bands' and the callback
receives nothing.
Returns an unsubscribe callback that detaches the listener and removes
the subscription on the host. Its ready promise settles with the
host's answer to the registration (ok: false with INVALID_PARAMS
for rejected parameters) and never rejects.
const stop = fb.audio.subscribeSpectrum((frame) => {
const values = frame.channels === 'stereo' ? frame.left : frame.spectrum;
draw(frame.firstBin, values);
}, { output: 'bins', fftSize: 16384, backgroundThrottle: false });
const outcome = await stop.ready;
if (!outcome.ok || outcome.output !== 'bins') console.warn('no bin output');
ExperimentalsubscribeStream: (opts?: PcmStreamOptions) => PcmStreamSubscribe to the audio foobar2000 is playing and get a PcmStream to poll for frames.
The samples are what the DSP chain produces, before ReplayGain and the
volume control, so they differ from audio:spectrum in not including
ReplayGain. They live in read-only shared memory; read() copies them
out per channel and reports frames the ring overwrote before they were
read. Nothing arrives while playback is stopped or paused. Poll from
requestAnimationFrame or a timer and call unsubscribe() when done.
opts.interval asks the core for a callback interval in seconds; the
core rounds it to about 16 ms steps, never exceeds 200 ms (its default),
and applies the shortest interval any subscription in the component
asked for. opts.bufferSeconds sizes the ring (default 1 s; the first
chunk after playback starts can hold up to 0.8 s of audio).
The handle's ready resolves with the host's answer and never rejects;
code is NOT_SUPPORTED outside a WebView2 host or on a runtime without
shared buffers, OPERATION_FAILED when the page already has 8 stream
subscriptions.
ExperimentalunsubscribeStream: (subscriptionId?: string) => Promise<AudioUnsubscribeStreamResponse>Remove this page's stream subscriptions on the host: the one with
subscriptionId, or all of them when omitted. PcmStream.unsubscribe
does this for its own subscription; call this directly only for
subscriptions made with a raw invoke. Resolves with the number removed.
audio— real-time audio analysis namespace.Spectrum / waveform subscriptions return an unsubscribe callback; call it to stop receiving callbacks and notify the host so the underlying compute pipeline is torn down.
audio.generateFullWaveform resolves either synchronously (cache hit) or asynchronously by listening for the
audio:fullWaveformReady/audio:fullWaveformFailedevents with a client-side timeout; a timeout or an abortedsignalalso cancels the host task.