@e9g/buffered-audio-nodes-utils
v0.1.3
Published
Shared DSP utilities for the buffered-audio-nodes ecosystem.
Downloads
191
Readme
@e9g/buffered-audio-nodes-utils
Shared DSP utilities for the buffered-audio-nodes ecosystem.
Install
npm install @e9g/buffered-audio-nodes-utilsPeer dependency: @e9g/buffered-audio-nodes-core
API
STFT / FFT
import { stft, istft, fft, ifft, hanningWindow, MixedRadixFft } from "@e9g/buffered-audio-nodes-utils";| Function | Description |
| --- | --- |
| stft(signal, fftSize, hopSize, window?) | Short-Time Fourier Transform with tiered backend dispatch |
| istft(frames, fftSize, hopSize, window?) | Inverse STFT (overlap-add reconstruction) |
| fft(real, imag) | Forward FFT (Cooley-Tukey radix-2, in-place) |
| ifft(real, imag) | Inverse FFT (in-place) |
| hanningWindow(size) | Generate a Hann window of the given size |
| MixedRadixFft | FFT class for non-power-of-2 sizes |
| createFftWorkspace(size) | Allocate reusable FFT scratch buffers |
| bitReverse(...) | Bit-reversal permutation |
| butterflyStages(...) | Radix-2 butterfly computation |
const window = hanningWindow(2048);
const frames = stft(signal, 2048, 512, window);
// ... process frames ...
const reconstructed = istft(frames, 2048, 512, window);FFT Backend
import { initFftBackend, detectFftBackend, getFftAddon } from "@e9g/buffered-audio-nodes-utils";
import type { FftBackend, FftBackendConfig } from "@e9g/buffered-audio-nodes-utils";| Function | Description |
| --- | --- |
| initFftBackend(config) | Initialize the native FFT backend |
| detectFftBackend(config) | Auto-detect the best available backend |
| getFftAddon(config) | Get the loaded native addon |
The FFT backend uses tiered dispatch to select the fastest available implementation:
- VkFFT (GPU via Vulkan) -- highest throughput for large transforms
- FFTW (native CPU) -- optimized native fallback
- JavaScript -- pure JS fallback, always available
stft and istft automatically use the best initialized backend.
await initFftBackend({ backend: "vkfft" });Native addon repositories:
Biquad Filters
import {
biquadFilter,
zeroPhaseBiquadFilter,
highPassCoefficients,
lowPassCoefficients,
bandPassCoefficients,
preFilterCoefficients,
rlbFilterCoefficients,
bandpass,
} from "@e9g/buffered-audio-nodes-utils";
import type { BiquadCoefficients } from "@e9g/buffered-audio-nodes-utils";| Function | Description |
| --- | --- |
| biquadFilter(samples, coefficients, state) | Apply a biquad IIR filter |
| zeroPhaseBiquadFilter(samples, coefficients) | Zero-phase (forward-backward) biquad filter |
| highPassCoefficients(frequency, sampleRate, Q?) | Design a high-pass biquad filter |
| lowPassCoefficients(frequency, sampleRate, Q?) | Design a low-pass biquad filter |
| bandPassCoefficients(frequency, sampleRate, Q?) | Design a band-pass biquad filter |
| preFilterCoefficients(sampleRate) | BS.1770-4 pre-filter (high shelf at ~1500 Hz) |
| rlbFilterCoefficients(sampleRate) | BS.1770-4 RLB weighting filter |
| bandpass(signal, low, high, sampleRate) | Convenience bandpass using cascaded biquads |
const coeffs = lowPassCoefficients(1000, 48000);
const state = { x1: 0, x2: 0, y1: 0, y2: 0 };
const filtered = biquadFilter(samples, coeffs, state);Channel Operations
import { interleave, deinterleaveBuffer, replaceChannel } from "@e9g/buffered-audio-nodes-utils";| Function | Description |
| --- | --- |
| interleave(channels) | Interleave per-channel arrays into a single buffer |
| deinterleaveBuffer(buffer, channelCount) | Deinterleave a buffer into per-channel arrays |
| replaceChannel(samples, channelIndex, replacement) | Replace a single channel in an interleaved buffer |
Level Conversion
import { dbToLinear, linearToDb } from "@e9g/buffered-audio-nodes-utils";| Function | Description |
| --- | --- |
| dbToLinear(db) | Convert decibels to linear amplitude |
| linearToDb(linear) | Convert linear amplitude to decibels |
Envelope / Resampling
import { smoothEnvelope, resampleDirect } from "@e9g/buffered-audio-nodes-utils";| Function | Description |
| --- | --- |
| smoothEnvelope(signal, attackSamples, releaseSamples) | Attack/release envelope follower |
| resampleDirect(signal, fromRate, toRate) | Sample rate conversion via direct resampling |
License
ISC
