Skip to content

Synthesize a Room Impulse Response ​

To create a room impulse response, pass shoebox dimensions, one wall absorption and the source and listener positions to synthesizeRir (synthesize_rir in Python). It returns a reproducible mono response, built from image-source early reflections and a seeded statistical late tail, that you can convolve with a dry recording. roomMorph does the whole job on a recording in one call: it builds the same target room and adds its character as an offline effect.

This is the constructive half of room acoustics. Measuring a response or estimating a room from a recording is Measure Room Acoustics, and an estimateRoom result feeds straight into the synthesizer (see From an estimate to a synthesized RIR).

InputUseWhat you get
Shoebox dimensions and source/listener positionssynthesizeRir(...) / synthesize_rir(...)A mono RirResult: the rir samples plus any diagnostics warnings
A dry or existing mono recording and a target roomroomMorph(...) / room_morph(...)A RoomMorphResult: the morphed audio and the diagnostics of its target room
A stereo recording and a target roomroomMorphStereo(...) / room_morph_stereo(...)Left and right channels, each through its own receiver
An estimateRoom(...) resultroomGeometryFromEstimate(...)Geometry you can pass straight to the synthesizer

sampleRate is required on these calls.

Usage ​

typescript
import { init, synthesizeRir, roomMorph } from '@libraz/libsonare';

await init();

// Throws a RangeError naming the refused value and its range (e.g. source.x) for unusable geometry.
const { rir, diagnostics: rirWarnings } = synthesizeRir({
  lengthM: 7,
  widthM: 5,
  heightM: 3,
  source: { x: 1, y: 1, z: 1.2 },
  listener: { x: 5, y: 4, z: 1.7 },
  absorption: 0.2,
  sampleRate,
});

const { audio: morphed, diagnostics } = roomMorph(dryVoice, sampleRate, {
  lengthM: 12,
  widthM: 9,
  heightM: 4,
  wet: 0.6,
});
typescript
import { synthesizeRir, roomMorph } from '@libraz/libsonare-native';

// Throws a RangeError naming the refused value and its range (e.g. source.x) for unusable geometry.
const { rir, diagnostics: rirWarnings } = synthesizeRir({
  lengthM: 7,
  widthM: 5,
  heightM: 3,
  source: { x: 1, y: 1, z: 1.2 },
  listener: { x: 5, y: 4, z: 1.7 },
  absorption: 0.2,
  sampleRate,
});

const { audio: morphed, diagnostics } = roomMorph(dryVoice, sampleRate, {
  lengthM: 12,
  widthM: 9,
  heightM: 4,
  wet: 0.6,
});
python
import libsonare as sonare

audio = sonare.Audio.from_file("dry.wav")

rir = sonare.synthesize_rir(7.0, 5.0, 3.0, absorption=0.2, sample_rate=audio.sample_rate)
print(rir.sample_rate, len(rir.rir), rir.diagnostics)

morphed = sonare.room_morph(
    audio.data,
    audio.sample_rate,
    12.0,
    9.0,
    4.0,
    wet=0.6,
)
bash
# synthesize a mono room impulse response from geometry
sonare synthesize-rir --length 7 --width 5 --height 3 -o room-ir.wav

# morph a recording toward a target room
sonare room-morph dry.wav --length 12 --width 9 --height 4 --wet 0.6 -o morphed.wav

Geometric room acoustics ​

From a recording to a synthesized room
estimateRoomroomGeometryFromEstimatesynthesizeRirsynthesizeRirroomMorph /roomMorphStereoRecordingRoom estimateRoom geometryYour own geometryRoom impulse responseMorphed audio
Geometry can come from an estimate or be written by hand; either one feeds the synthesizer and the morph.

synthesizeRir(...) builds a mono RIR from a rectangular room. You provide dimensions in meters, one wall-absorption value, and source/listener coordinates inside the room. Unusable geometry, such as a source or listener outside the room, throws a RangeError whose message names the refused value and the range it must lie in (for a 7 m long room, synthesizeRir: source.x must be finite and in [0, 7]); Python raises SonareValueError (see the error contract). A call that returns carries only warnings on diagnostics.

roomMorph(...) is an offline creative effect. It adds a synthesized target-room character and may soften part of the existing tail. Do not treat or present its output as dereverberation: it adds room character, it does not remove existing reverb.

Reading the room-morph result ​

roomMorph(...) returns RoomMorphResult: the morphed samples on audio (the input length plus the target room's reverb tail, so the added reverberation is never cut off), the sampleRate they are at, and diagnostics, the list of what the target-room synthesis had to change to produce them. The morph builds its target room with the same code as synthesizeRir(...), so it can report the same warnings, and every one of them means the morph went through a room other than the one you described. The audio does not tell you that; the list does.

codeWhat happenedWhat to do
acoustic.ism_order_clampedismOrder was above the safe maximum of 12 and was reduced to it.Request 12 or less so the render matches the request.
acoustic.rir_length_clampedThe room's natural response was longer than the cap, so the tail was cut. The message says which cap: maxSec, or the shared RIR resource limit when maxSec was omitted.Raise maxSec if you set it. Otherwise the room decays for longer than the budget allows, so make it smaller or more absorptive.
acoustic.rir_length_flooredmaxSec ended before the direct sound could arrive, so it was extended to fit it. The result is longer than you asked for.Raise maxSec, or move the listener closer to the source.
acoustic.rir_tail_truncatedmaxSec cuts the longest-decaying band before its RT60, so a 60 dB decay cannot be measured from the RIR.Set maxSec at least as long as that band's RT60, or omit it for the natural length subject to the resource limit.
acoustic.no_late_tailThe response ends at or before the mixing time, so no diffuse tail could be added and the target room is early reflections only. A long mixingTimeMs on a strongly absorbing room (mixingTimeMs: 500 with absorption: 0.999) does it, and so does a maxSec shorter than the mixing time. Rigid or absorptive walls alone, at the default mixing time, do not.Lower mixingTimeMs, raise maxSec, or make the walls less absorptive.

Neither RoomMorphResult nor RirResult has an error flag: a morph that cannot be produced — invalid geometry, a listener outside the room, a climate outside the physical range — throws instead (synthesizeRir(...) throws the same way), so every entry in diagnostics is a warning about a result you did get. Branch on code; the message text is for humans, and the severity of every entry on a returned morph is 'warning'.

The shape is the same on every surface. Node and the browser return the RoomMorphResult described on JavaScript API Types. Python returns a RoomMorphResult dataclass whose diagnostics is a list of RirDiagnostic. The C ABI leaves the entries in sonare_last_diagnostic_count() / sonare_last_diagnostic(i, &out) after a successful sonare_room_morph, as shown on C++ API. The sonare room-morph command prints each warning to stderr as warning: <code>: <message>, while the output file and any --json summary stay on stdout.

Stereo room morph ​

roomMorphStereo({ left, right, sampleRate, ...options }) (Python room_morph_stereo(left, right, sample_rate, length_m, width_m, height_m, ...), C sonare_room_morph_stereo, and sonare room-morph on a two-channel file) morphs a stereo recording instead of a mono one. It takes every roomMorph option plus receiverSpacingM (Python receiver_spacing_m, CLI --receiver-spacing): the target room is heard at two omnidirectional receivers that distance apart across the listener. Omitted, it is 0.5 m where that pair fits around the listener and otherwise the largest spacing that fits the room, so a listener near a wall still renders. An explicit spacing that puts a receiver outside the room, a spacing outside (0, 4] m, or channels of different length, is refused with a RangeError (SonareValueError in Python).

Each channel is convolved with its own receiver's response. The early reflections differ per receiver, and the late tails follow the diffuse-field coherence of two points that far apart, so the bass stays correlated between the channels and the highs do not. The result is { left, right, sampleRate, diagnostics }: both channels are the input length plus the target room's reverb tail, and diagnostics carries the codes of the table above. The source-tail suppressor applies one gain, taken from the louder channel, to both channels, so suppression does not shift the stereo image.

typescript
const { left: wetL, right: wetR } = roomMorphStereo({
  left, right, sampleRate,
  lengthM: 12, widthM: 9, heightM: 4, wet: 0.6,
  receiverSpacingM: 0.5,
});

Summed to mono, the added room is about 3 dB lower above roughly 300 Hz than a response shared by both channels would be, because the two tails do not add coherently. The offline mono roomMorph(...) is the single-listener response and does not place a receiver pair. The effects.reverb.room and effects.acoustic.roomMorph inserts use the pair on a stereo strip, and, given an explicit receiverSpacingM, refuse a placement that puts either receiver outside the room, so a listener closer to a side wall than half that spacing is refused even on a mono strip. An omitted spacing is 0.5 m where the pair fits and otherwise the largest spacing that fits the room.

What the spacing does to the two tails, band by band, is measured on Spaced Receivers and Coherence.

From an estimate to a synthesized RIR ​

An estimateRoom(...) result uses the names synthesizeRir(...) takes (lengthM, widthM, heightM, bandAbsorption), so roomGeometryFromEstimate(...) can turn a measured estimate into usable geometry. When no broadband decay can be measured, volume and the three dimensions are absent and confidence is 0; Python uses None for those fields. Check all three dimensions before calling the helper. An estimate carries no source or listener position, so the result places them itself: the synthesizer's default source and listener, scaled per axis from the default 7 × 5 × 3 m room into the estimated dimensions (at 7 × 5 × 3 m the placement is the default one), which keeps both inside a small estimated room. Give source / listener as { x, y, z } in meters to override it. The result also carries a scalar absorption, the mean of the finite bands, and leaves bands that did not converge out of bandAbsorption.

typescript
const estimate = estimateRoom(roomRecording, sampleRate, { nOctaveBands: 6 });
if (typeof estimate.lengthM !== 'number' || typeof estimate.widthM !== 'number' || typeof estimate.heightM !== 'number') {
  throw new Error('Room dimensions were not measured');
}
const geometry = roomGeometryFromEstimate({
  estimate,
  source: { x: 1, y: 1, z: 1.2 },
  listener: { x: 2, y: 1.5, z: 1.5 },
});
const { rir } = synthesizeRir({ ...geometry, sampleRate });
python
estimate = sonare.estimate_room(audio.data, audio.sample_rate, n_octave_bands=6)
if estimate.length_m is None or estimate.width_m is None or estimate.height_m is None:
    raise ValueError("Room dimensions were not measured")
geometry = sonare.room_geometry_from_estimate(
    estimate, source=(1, 1, 1.2), listener=(2, 1.5, 1.5)
)
rir = sonare.synthesize_rir(**geometry, sample_rate=audio.sample_rate)

Wall absorption and materials ​

Both synthesizeRir(...) and roomMorph(...) accept the shared shoebox geometry, so they take the same wall-treatment fields. You can describe the walls at three levels of detail, from coarsest to finest:

FieldTypeMeaning
absorptionnumberUniform wall absorption for every band. Must be within [0, 1]; an accepted value is then clamped to [0, 0.999]. The simplest control.
bandAbsorptionFloat32Array / number[]Per-octave-band wall absorption (125 / 250 / 500 / 1k / 2k / 4k… Hz). When provided it overrides absorption, unless materialPreset is set. Python: band_absorption.
bandScatteringFloat32Array / number[]Per-band wall scattering. Missing bands default to 0. Applied to whichever wall material the absorption fields selected. Python: band_scattering.
materialPresetnameA named wall-material preset: 'concrete', 'wood', 'curtain', 'carpet' or 'glass' ('none' selects no preset). Python: material_preset. One material covers every surface, so the rooms it makes are extreme: an all-carpet room absorbs almost nothing at 125 Hz. Any preset but 'none' wins over both bandAbsorption and absorption. It does not compete with bandScattering.

Precedence decides the absorption only, highest first: a materialPreset other than 'none' wins over everything; otherwise bandAbsorption (per band) wins over absorption (uniform). So to use your own per-band absorption, leave materialPreset at 'none' (the default).

bandScattering sits outside that contest. It applies to whichever wall material the absorption precedence selected, so a preset plus a scattering array is a well-formed request: you get the preset's absorption with your roughness on top of it.

A scattering array always reaches the walls

bandScattering is never dropped, including alongside a materialPreset. Scattering diffuses energy out of the specular early reflections, which moves the mixing time and the early/late balance, so passing one changes the render. If some existing code hands synthesizeRir(...) or roomMorph(...) a scattering array it does not actually want applied, remove the array rather than relying on a preset to suppress it.

Out-of-range absorption is refused, not pulled into range

A scalar absorption that is non-finite or outside [0, 1] is refused with a RangeError. An accepted value is clamped to [0, 0.999] so the perfectly absorbing endpoint does not make the Eyring term -ln(1 - absorption) singular. bandAbsorption and bandScattering are validated the same way, so every wall-treatment field answers a bad value identically instead of one of them quietly building a different room than you asked for.

materialPreset takes names only: a number is a TypeError and an unknown name a RangeError (SonareValueError in Python), both listing the valid names. Concrete and glass are reflective and keep more high-frequency tail; curtain and carpet are absorptive and shorten it.

typescript
// A concrete shoebox: bright, long tail
const concrete = synthesizeRir({
  lengthM: 7, widthM: 5, heightM: 3,
  materialPreset: 'concrete',
  sampleRate,
});

// Custom per-band walls (six octave bands), with scattering
const custom = synthesizeRir({
  lengthM: 7, widthM: 5, heightM: 3,
  materialPreset: 'none', // no preset, so bandAbsorption decides the absorption
  bandAbsorption: [0.1, 0.15, 0.2, 0.3, 0.4, 0.5],
  bandScattering: [0.1, 0.1, 0.2, 0.2, 0.3, 0.3],
  sampleRate,
});

Late-reverb model and tail controls ​

The shared geometry also exposes the late-tail behavior. SynthesizeRirRequest and RoomMorphOptions both carry:

FieldMeaning
preferEyringSelects the statistical late-reverb model: true (default) uses Eyring, false uses Sabine.
mixingTimeMsEarly/late crossover in milliseconds. Omit it for roughly sqrt(volume) ms; an explicit 0 is refused.
crossfadeMsEqual-power crossfade width around the mixing time, in milliseconds. Omit it for 5 ms; 0 is a hard switch.
ismOrderImage-source reflection order for the early part.
seed, maxSecLate-tail random seed (omit it for seed 1; 0 is a seed like any other) and the maximum RIR length to generate. Omit maxSec for the natural length, subject to the shared limit of 13,421,772 samples for a mono RIR (about 280 s at 48 kHz); an explicit 0 is refused.
airAbsorptionEnabled, airTemperatureC, airHumidityPercentAtmospheric absorption along the reflection path, added to the late tail's per-band RT60. On by default; see Air absorption.

The mixing time is where the response transitions from discrete image-source early reflections to a statistically modeled noise tail (seeded, so it renders the same every time); the crossfade blends the two so the seam is inaudible. Sabine and Eyring are the two classical RT60 estimators behind the late tail; Eyring tends to be more accurate in highly absorptive rooms.

The tail's level is matched in a window that starts after the direct sound, so a synthesized RIR's direct-to-reverberant ratio is set by the room and the positions, not by the sample rate or by a sub-sample change in source distance.

The figure below shows where each part sits in one synthesized response.

Anatomy of a synthesized RIR
0−10−20−30−40020406080100120140160180200mixing time √V ≈ 49 ms direct soundfalls 60 dB per RT60 · RT60 = 0.93 s time after the source fires (ms)level (dB re direct sound)
  • early reflections: image sources, sparse
  • late tail: seeded noise, dense
  • equal-power crossfade 5 ms
A 20 × 15 × 8 m room with absorption 0.3, built the way synthesizeRir builds it: image-source reflections up to order 3, the automatic mixing time √V ≈ 49 ms, a 5 ms equal-power crossfade, then a seeded noise tail level-matched to the early energy around the mixing time and falling 60 dB per Eyring RT60. Level is energy per millisecond relative to the direct sound.

Sabine vs Eyring (you can usually ignore this)

Both are classic formulas that predict a room's RT60 from its size and how absorptive its surfaces are. Eyring is generally more accurate in very absorptive (well-treated) rooms; Sabine is the older, simpler one. Leave the default unless you are matching a specific reference.

What are image-source reflections?

When sound bounces off walls, each reflection can be modeled as if it came from a mirror-image copy of the source behind the wall. ismOrder sets how many bounces are computed this way: higher orders add more (but progressively weaker) early echoes at higher CPU cost. The diffuse late tail is generated separately.

Mirror sources, seen from above
mirror roomroom 7 × 5 mmirror sourcemirror sourcemirror sourcemirror sourcesourcelistener
  • direct path
  • first-order reflection
  • same length, straight from the mirror source
The library's default 7 × 5 m room, source at (1, 1) and listener at (5, 4). The straight line from each mirror source to the listener crosses the wall where the real reflection bounces, so that reflection arrives with the delay and the 1/distance level of the straight line. Higher orders mirror the mirror rooms again; floor and ceiling images lie above and below the plan.
Implementation notes for room synthesis

synthesizeRir(...) uses image-source early reflections plus a seeded, statistically modeled late tail. acoustic::RirSynthConfig exposes the reflection order, Sabine/Eyring late-tail model, seed, maximum RIR length, mixing time, crossfade width, and the optional air-absorption climate.

Air absorption ​

Air itself absorbs sound, far more at high frequencies than at low, and the loss accumulates with the distance a reflection travels. The ISO 9613-1 atmospheric-absorption model adds that loss to the late tail's per-band RT60, and it is on unless turned off; the three options below control it. They are read by synthesizeRir(...), roomMorph(...) and the geometry-driven effects.reverb.room insert. The inverse direction, estimateRoom(...), does not take them, and the CLI's synthesize-rir / room-morph commands do not expose them.

OptionDefaultAcceptedMeaning
airAbsorptionEnabledtruebooleanAdds the air term. false gives the geometry-only decay.
airTemperatureC20above −273.15 °CAir temperature. Omit it for the ISO reference 20 °C; 0 is 0 °C.
airHumidityPercent500–100Relative humidity. Omit it for the ISO reference 50 %; 0 is dry air.

The climate pair is read only while airAbsorptionEnabled is on. A non-finite or out-of-range value is refused the way the surrounding geometry checks are, not pulled into range: Both synthesizeRir(...) and roomMorph(...) throw a RangeError naming the field and its domain: airTemperatureC must be finite and greater than -273.15, airHumidityPercent must be finite and in [0, 100]. Pressure is not an input; the model is evaluated at sea-level pressure.

typescript
const hall = synthesizeRir({
  lengthM: 30, widthM: 20, heightM: 12,
  absorption: 0.2,
  airTemperatureC: 20,
  airHumidityPercent: 30,     // drier than the reference: the high bands decay sooner
  sampleRate,
});

The air term mainly shortens the high bands of a large room and leaves a small one close to where it was, because the term grows with the room's volume as well as with frequency. Drier or colder air absorbs the highs more. Which way each band moves, and by how much, is worked through on Per-Band Decay and Absorption.

It is not wall absorption

Air absorption models the loss along the propagation path, inside the air. It is not a substitute for absorption, bandAbsorption or materialPreset, which model the loss at the boundaries, and it does not touch the image-source early reflections at all — only the statistical tail's decay rates. A room whose highs ring too long because its walls are reflective needs a more absorptive wall material; humidity will not fix it, and it will never move the low bands, where the air term is negligible.