Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"anser": "^2.3.5",
"buttplug": "^3.2.2",
"buttplug-wasm": "^2.0.1",
"cacophony": "^0.40.0",
"cacophony": "^0.41.0",
"dompurify": "^3.4.1",
"eventemitter3": "^5.0.4",
"jzz": "^1.9.6",
Expand Down
14 changes: 12 additions & 2 deletions src/audio/earlyReflections.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,20 @@ describe('reflectionImages: box room', () => {
});

it('skips a plane the source is behind', () => {
const images = reflectionImages(room(), wa([6, 0, 1]), wa([0, 0, 1]), UNITY, inverse);
expect([...byMooPosition(images).keys()]).not.toContain('4,0,1');
// At 1.5 m the floor and ceiling images are 2 ms late, clear of the 1 ms fusion cut.
const images = reflectionImages(room(), wa([6, 0, 1.5]), wa([0, 0, 1.5]), UNITY, inverse);
expect([...byMooPosition(images).keys()]).not.toContain('4,0,1.5');
expect(images).toHaveLength(5);
});

it('leaves an image less than 1 ms behind the direct sound to the direct (ears 0.15 m from a wall)', () => {
// A footstep at the listener's feet, 0.15 m from the wall x=-5: that wall's
// image is 0.08 ms late; the ceiling and the far walls stay.
const images = reflectionImages(room(), wa([-4.85, 0, 0.01]), wa([-4.85, 0, 1.7]), UNITY, inverse);
expect([...byMooPosition(images).keys()]).not.toContain('-5.15,0,0.01');
expect(images.every((image) => image.delay >= 0.001)).toBe(true);
expect(images).toHaveLength(4);
});
});

describe('reflectionImages: outdoors', () => {
Expand Down
5 changes: 5 additions & 0 deletions src/audio/earlyReflections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ export function reflectionImages(
if (u < 0 || u > 1) continue;
}
const path = length(sub(image, l));
// An image less than 1 ms behind the direct sound (a listener or source
// almost touching the plane) fuses with it; rendered as its own point it
// comes from a wrong direction (Chromium's HRTF clamps elevations below
// -45 degrees) and combs the direct sound. Leave it to the direct.
if (path - direct < 0.001 * room.speedOfSound) continue;
images.push({
position: mongooseToWebAudioVector(image)!,
delay: Math.min(MAX_REFLECTION_DELAY, Math.max(0, (path - direct) / room.speedOfSound)),
Expand Down
2 changes: 1 addition & 1 deletion src/audio/effects/MediaEffects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ describe('buildEffectsSupport', () => {
expect(s.types).toContain('lowpass');
expect(s.types).not.toContain('biquad'); // V8: never advertise a non-wire name
expect(s.types).not.toContain('echo'); // alias, not advertised
expect(s.reverbAlgorithms).toEqual(['fdn', 'plate']);
expect(s.reverbAlgorithms).toEqual(['fdn', 'plate', 'diffuse']);
expect(s.chains).toBe(true);
expect(s.automation).toBe(true);
});
Expand Down
2 changes: 1 addition & 1 deletion src/audio/effects/MediaEffects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const MAX_EFFECTS_PER_CHAIN = 8;
export function buildEffectsSupport(voice: unknown = Playback.prototype): EffectsSupport {
return {
types: ADVERTISED_EFFECT_TYPES,
reverbAlgorithms: ['fdn', 'plate'],
reverbAlgorithms: ['fdn', 'plate', 'diffuse'],
presets: Object.keys(CHAIN_PRESETS),
automation: true,
chains: true,
Expand Down
2 changes: 2 additions & 0 deletions src/audio/effects/buildEffect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export function buildEffect(cacophony: Cacophony, resolved: ResolvedEffect): Bui
switch (resolved.factory) {
case 'createFdnReverb':
return cacophony.createFdnReverb(o as OptionsOf<'createFdnReverb'>);
case 'createDiffuseReverb':
return cacophony.createDiffuseReverb(o as OptionsOf<'createDiffuseReverb'>);
case 'createReverb':
return cacophony.createReverb(o as OptionsOf<'createReverb'>);
case 'createDelay':
Expand Down
25 changes: 25 additions & 0 deletions src/audio/effects/resolveEffect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,31 @@ describe('resolveEffect — type → factory mapping', () => {
});
});

describe('resolveEffect — diffuse reverb', () => {
it('maps the room vocabulary to createDiffuseReverb, without diffusion', () => {
const r = worklet(
resolveEffect({
type: 'reverb',
algorithm: 'diffuse',
params: {
decayTimes: [0.7, 0.83, 0.85, 0.95, 0.91, 0.7, 0.48, 0.34],
preDelay: 0,
minDelay: 0.0102,
diffusion: 0.5,
mix: 1,
},
}),
);
expect(r.factory).toBe('createDiffuseReverb');
expect(r.options).toEqual({
decayTimes: [0.7, 0.83, 0.85, 0.95, 0.91, 0.7, 0.48, 0.34],
preDelay: 0,
minDelay: 0.0102,
mix: 1,
});
});
});

describe('resolveEffect — FDN reverb', () => {
it('passes the neutral vocabulary through 1:1, with one T60 per octave band', () => {
const r = worklet(
Expand Down
12 changes: 12 additions & 0 deletions src/audio/effects/resolveEffect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ function resolveFdnReverb(p: EffectParams): EffectParams {
return o;
}

/**
* Diffuse (decaying-noise) room reverb: the FDN's room vocabulary without
* `diffusion` (a noise tail is fully diffuse). Same clamps as the FDN.
*/
function resolveDiffuseReverb(p: EffectParams): EffectParams {
const { diffusion: _diffusion, ...rest } = resolveFdnReverb(p);
return rest;
}

/**
* Plate (Dattorro) reverb: the option set is disjoint from FDN, so the neutral
* vocabulary is translated and APPROXIMATED (design §4 reverb note):
Expand Down Expand Up @@ -272,6 +281,9 @@ export function resolveEffect(

switch (type) {
case 'reverb': {
if (spec.algorithm === 'diffuse') {
return { kind: 'worklet', factory: 'createDiffuseReverb', options: resolveDiffuseReverb(p) };
}
const plate = spec.algorithm === 'plate';
return {
kind: 'worklet',
Expand Down
5 changes: 3 additions & 2 deletions src/audio/effects/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type EffectParamValue = number | string | readonly number[];
export type EffectParams = Record<string, EffectParamValue>;

/** Reverb algorithm discriminator (protocol-level, NOT a `params` key). */
export type ReverbAlgorithm = 'fdn' | 'plate';
export type ReverbAlgorithm = 'fdn' | 'plate' | 'diffuse';

/** Tremolo / auto-pan LFO waveform. Maps to cacophony's `shape` string alias. */
export type Waveform = 'sine' | 'triangle' | 'square';
Expand Down Expand Up @@ -78,7 +78,7 @@ export interface EffectSpec {
type: string;
/** Optional. Names this effect for automation targeting within a chain. */
id?: string;
/** Optional. Reverb only: `"fdn"` (default) or `"plate"`. */
/** Optional. Reverb only: `"fdn"` (default), `"plate"` or `"diffuse"` (decaying-noise room tail). */
algorithm?: string;
/** Optional. Per-effect preset name; explicit `params` override preset values. */
preset?: string;
Expand All @@ -105,6 +105,7 @@ export interface ChainSpec {
/** cacophony factory names this client builds worklet effects through. */
export type WorkletFactory =
| 'createFdnReverb'
| 'createDiffuseReverb'
| 'createReverb'
| 'createDelay'
| 'createChorus'
Expand Down