JavaScript/TypeScript Room Acoustics API
Room-acoustics measurement and synthesis calls of the libsonare JavaScript/TypeScript package; the audio effects and editing DSP are on Effects API.
Room Acoustics
These functions describe or apply the recording space rather than the song itself. Background: Reverberation time, Room geometry and Spaced receivers.
| Goal | Use |
|---|---|
| Measure a clean impulse response | analyzeImpulseResponse(...) |
| Estimate room decay from ordinary audio | detectAcoustic(...) |
| Fit a practical room model from audio | estimateRoom(...) |
Turn that estimate into synthesizeRir input | roomGeometryFromEstimate(...) |
| Create a mono room impulse response from dimensions | synthesizeRir(...) |
| Add a target-room character as an effect | roomMorph(...) |
| Add the same character to a stereo recording, heard at two spaced receivers | roomMorphStereo({ left, right, sampleRate, ... }) |
RIR and room morphing
RIR means room impulse response: samples that describe how a room reacts to a short sound. roomMorph(...) is a creative effect, not dereverberation.
function analyzeImpulseResponse(request: AnalyzeImpulseResponseRequest): AcousticResult
function analyzeImpulseResponse(
samples: Float32Array,
sampleRate: number,
options?: OptionsOf<AnalyzeImpulseResponseRequest>,
): AcousticResult
function detectAcoustic(request: DetectAcousticRequest): AcousticResult
function detectAcoustic(
samples: Float32Array,
sampleRate: number,
options?: OptionsOf<DetectAcousticRequest>,
): AcousticResult
function estimateRoom(request: EstimateRoomRequest): RoomEstimateResult
function estimateRoom(
samples: Float32Array,
sampleRate: number,
options?: RoomEstimateOptions,
): RoomEstimateResult
function roomGeometryFromEstimate(request: RoomGeometryFromEstimateRequest): RoomGeometry // request form only
function synthesizeRir(request: SynthesizeRirRequest): RirResult // request form only
function roomMorph(request: RoomMorphRequest): RoomMorphResult
function roomMorph(
samples: Float32Array,
sampleRate: number,
options?: RoomMorphOptions,
): RoomMorphResult
function roomMorphStereo(request: RoomMorphStereoRequest): RoomMorphStereoResult // request form only
interface AnalyzeImpulseResponseRequest extends SampleInput {
nOctaveBands?: number; // Octave bands; default 6.
minDecayDb?: number; // Minimum decay range in dB for a valid RT60 fit; default 30.
}
interface AcousticOptions {
nOctaveBands?: number; // Number of octave bands. Default 6.
nThirdOctaveSubbands?: number; // Number of 1/3-octave sub-bands. Default 24.
minDecayDb?: number; // Minimum decay range (dB) for a valid RT60 fit. Default 30.
noiseFloorMarginDb?: number; // Margin (dB) above the noise floor for the decay fit. Default 10.
}
interface RoomEstimateOptions {
aspectHintLw?: number; // Length/width ratio hint of the room. Omit for no hint; an explicit 0 is refused.
aspectHintLh?: number; // Length/height ratio hint of the room. Omit for no hint; an explicit 0 is refused.
referenceAbsorption?: number; // Mean-absorption prior anchoring the volume scale. Omit for the library default, 0.15; a given value must lie in `[0.01, 0.99]`, and one outside it (0 included) is refused.
preferEyring?: boolean; // Use the Eyring statistical late-tail model (default true); false = Sabine.
nOctaveBands?: number; // Octave bands analysed. Omit for the library default; an explicit 0 is refused.
mode?: AcousticModeName; // Analyzer routing, by name: `'auto'`, `'blind'`, `'impulseResponse'`.
minDecayDb?: number; // Analyzer decay-fit span in dB. Omit for the library default; an explicit 0 is refused.
noiseFloorMarginDb?: number; // Analyzer noise-floor margin in dB. Omit for the library default; an explicit 0 is refused.
}
interface RoomGeometryFromEstimateRequest {
estimate: RoomGeometryEstimate; // The room estimate to read the geometry from.
source?: RoomPlacement; // Replaces the source placement scaled into the estimated room.
listener?: RoomPlacement; // Replaces the listener placement scaled into the estimated room.
}
interface SynthesizeRirRequest extends RoomGeometry {
sampleRate: number; // Sample rate in Hz, an integer in `[8000, 384000]`; there is no default.
preferEyring?: boolean; // Use the Eyring statistical late-tail model (default true); false = Sabine.
mixingTimeMs?: number; // Early/late crossover in ms. Omit for auto (~sqrt(V) ms); an explicit 0 is refused.
crossfadeMs?: number; // Equal-power crossfade width around the mixing time in ms. Omit for 5 ms; 0 is a hard switch.
}
interface RoomMorphOptions extends RoomGeometry {
wet?: number; // Wet level of the target room.
sourceTailSuppression?: number; // How far the source recording's own room tail is suppressed.
preferEyring?: boolean; // Use the Eyring statistical late-tail model for the target room (default true); false = Sabine.
mixingTimeMs?: number; // Early/late crossover in ms. Omit for auto (~sqrt(V) ms); an explicit 0 is refused.
crossfadeMs?: number; // Equal-power crossfade width around the mixing time in ms. Omit for 5 ms; 0 is a hard switch.
}
interface RoomMorphStereoRequest extends RoomMorphOptions {
left: Float32Array; // Left channel samples.
right: Float32Array; // Right channel samples; same length as `left`.
sampleRate: number; // Sample rate in Hz, an integer in `[8000, 384000]`; there is no default.
receiverSpacingM?: number; // Receiver spacing in metres, in (0, 4]; omitted = 0.5 m if it fits, otherwise the largest spacing that fits.
}
interface AcousticResult {
rt60?: number; // Broadband reverberation time (RT60) in seconds; absent when no decay was fitted.
edt?: number; // Early decay time in seconds; absent when `isBlind` or not fitted.
c50?: number; // Clarity C50 in dB; absent when `isBlind` or not measurable.
c80?: number; // Clarity C80 in dB; absent when `isBlind` or not measurable.
d50?: number; // Definition D50 (early-to-total energy ratio); absent when `isBlind` or not measurable.
rt60Bands?: Float32Array; // Per-octave-band RT60; NaN for a band not fitted.
edtBands?: Float32Array; // Per-octave-band early decay time; absent when `isBlind`, NaN for an unfit band.
c50Bands?: Float32Array; // Per-octave-band C50; absent when `isBlind`, NaN for an unmeasured band.
c80Bands?: Float32Array; // Per-octave-band C80; absent when `isBlind`, NaN for an unmeasured band.
confidence: number; // Support for the estimate, in [0, 1].
isBlind: boolean; // True when measured from a blind recording rather than an impulse response.
}
interface RoomEstimateResult {
volume?: number; // Equivalent volume (m^3); absent with the dimensions when no broadband decay was measurable.
lengthM?: number; // Representative room length in metres; absent when no decay is measurable.
widthM?: number; // Representative room width in metres; absent when no decay is measurable.
heightM?: number; // Representative room height in metres; absent when no decay is measurable.
drrDb?: number; // Direct-to-reverberant ratio; absent when it was not measurable.
confidence: number; // Support for the estimate, in [0, 1].
bandAbsorption?: Float32Array; // Per-octave-band mean wall absorption.
rt60Bands?: Float32Array; // Per-octave-band RT60 in seconds.
}
interface RirResult {
rir: Float32Array; // Impulse response samples.
sampleRate: number; // Sample rate of `rir` in Hz.
diagnostics: RirDiagnostic[]; // Every diagnostic the synthesizer reported, in order. A refused synthesis throws instead, so every entry is a warning — a `maxSec` clamp that cut the tail is one, and is otherwise indistinguishable from an untruncated RIR.
}
interface RoomMorphResult {
audio: Float32Array; // Morphed samples: input length plus the target room's reverb tail.
sampleRate: number; // Sample rate of `audio` in Hz.
diagnostics: RirDiagnostic[]; // Every diagnostic the target-room synthesis reported, in order.
}
interface RoomMorphStereoResult {
left: Float32Array; // Morphed left samples: input length plus the target room's reverb tail.
right: Float32Array; // Morphed right samples, the same length as `left`.
sampleRate: number; // Sample rate of `left` and `right` in Hz.
diagnostics: RirDiagnostic[]; // Target-room synthesis diagnostics, with the same codes as {@link RoomMorphResult.diagnostics}.
}
interface RoomGeometry {
lengthM?: number; // Room length in metres.
widthM?: number; // Room width in metres.
heightM?: number; // Room height in metres.
absorption?: number; // Uniform wall absorption in [0, 1], used when no band absorption or preset is given; a value outside is refused, and the model holds a wall at most 0.999 absorbent. Defaults to 0.2.
bandAbsorption?: Float32Array | number[]; // Optional per-octave-band wall absorption (125/250/500/1k/2k/4k..
bandScattering?: Float32Array | number[]; // Optional per-band wall scattering; missing bands default to 0.
materialPreset?: MaterialPresetName; // Wall-material preset, by name (`'none'`, `'concrete'`, `'wood'`, `'curtain'`, `'carpet'`, `'glass'`).
source?: RoomPlacement; // Source position in metres. Default: the 7 x 5 x 3 room's default placement scaled into the room.
listener?: RoomPlacement; // Listener position in metres. Default: the default placement scaled into the room.
ismOrder?: number; // Image-source reflection order; clamped to the safe maximum.
seed?: number; // Seed of the diffuse tail, a uint32. Omit for the default seed 1; 0 is a seed like any other.
maxSec?: number; // Maximum RIR length in seconds. Omit for the natural length (no cap); an explicit 0 is refused.
airAbsorptionEnabled?: boolean; // Add the ISO 9613-1 atmospheric-absorption term to the late tail's per-band RT60. On by default; it mainly shortens the high bands of a large room.
airTemperatureC?: number; // Air temperature in degrees Celsius. Omit for the ISO reference climate's 20 degC; 0 is 0 degC.
airHumidityPercent?: number; // Relative humidity in percent. Omit for the ISO reference climate's 50 %; 0 is dry air.
}
interface RoomPlacement {
x: number; // X coordinate in metres.
y: number; // Y coordinate in metres.
z: number; // Z coordinate in metres.
}const ir = analyzeImpulseResponse(impulseResponseSamples, sampleRate, { nOctaveBands: 6, minDecayDb: 30 });
console.log(ir.rt60, ir.edt, ir.c50, ir.c80, ir.confidence);
const blind = detectAcoustic(roomRecording, sampleRate, {
nOctaveBands: 6,
nThirdOctaveSubbands: 24,
minDecayDb: 30,
noiseFloorMarginDb: 10,
});
console.log(blind.isBlind, blind.rt60Bands);
const estimate = estimateRoom(roomRecording, sampleRate, {
referenceAbsorption: 0.15,
nOctaveBands: 6,
});
console.log(estimate.volume, estimate.lengthM, estimate.widthM, estimate.heightM);
console.log(estimate.drrDb, estimate.confidence, estimate.bandAbsorption);
if (typeof estimate.lengthM !== 'number' || typeof estimate.widthM !== 'number' || typeof estimate.heightM !== 'number') {
throw new Error('Room dimensions were not measured');
}
// Throws a RangeError naming the refused value and its range (e.g. source.x) for unusable geometry.
const rir = synthesizeRir({ sampleRate, lengthM: 7, widthM: 5, heightM: 3, absorption: 0.2, materialPreset: 'none' });
console.log(rir.sampleRate, rir.rir.length, rir.diagnostics);
// An estimate already uses synthesizeRir's names; after the dimension check above, the helper adds a placement scaled into the estimated room; source and listener override it.
const geometry = roomGeometryFromEstimate({
estimate,
source: { x: 1, y: 1, z: 1.2 },
listener: { x: 2, y: 1.5, z: 1.5 },
});
const resynth = synthesizeRir({ ...geometry, sampleRate });
const morphed = roomMorph(samples, sampleRate, { lengthM: 12, widthM: 9, heightM: 4, wet: 0.6 });
// morphed.audio is the processed signal; morphed.sampleRate and morphed.diagnostics come with itanalyzeImpulseResponse(samples, sampleRate, { nOctaveBands?, minDecayDb? }) uses minDecayDb to set the decay-fit threshold (default 30).
estimateRoom's referenceAbsorption is the mean-absorption prior that anchors the volume scale. Omit it for the library default (0.15); a given value must lie in [0.01, 0.99], and one outside it, an explicit 0 included, is a RangeError rather than a clamp. The reported volume scales with the cube of the prior.
materialPreset ('none' | 'concrete' | 'wood' | 'curtain' | 'carpet' | 'glass', type MaterialPresetName) and the estimateRoom mode option ('auto' | 'blind' | 'impulseResponse', type AcousticModeName) take names only: a number is a TypeError, an unknown name a RangeError. roomGeometryFromEstimate({ estimate, source?, listener? }) (request form only) takes RoomPlacement ({ x, y, z } in meters) positions and returns RoomGeometry, with the default placement scaled into the estimated room (each position given replaces it) and absorption as the mean of the finite bands; it throws a RangeError for an estimate with no measurable dimensions.
See Room Acoustics for how to interpret RT60, EDT, C50, C80, D50, band arrays, room estimates, generated RIRs, and confidence.