Smooth spatial transitions with 0.2s ramps

This commit is contained in:
Jage9
2026-02-22 21:23:16 -05:00
parent ad2cd532be
commit 3d741b358a
5 changed files with 11 additions and 7 deletions

View File

@@ -27,6 +27,7 @@ type EmitSpatialConfig = {
const ITEM_EMIT_BASE_GAIN = 1;
const SUBSCRIBE_PRELOAD_SQUARES = 5;
const UNSUBSCRIBE_HYSTERESIS_SQUARES = 8;
const SPATIAL_RAMP_SECONDS = 0.2;
/** Maps a 0-100 speed control to playback-rate range used by emitted audio. */
function resolveEmitPlaybackRate(raw: unknown): number {
@@ -223,10 +224,10 @@ export class ItemEmitRuntime {
const gainValue = mix?.gain ?? 0;
const panValue = mix?.pan ?? 0;
const emitVolume = volumePercentToGain(item.params.emitVolume, 100);
output.gain.gain.linearRampToValueAtTime(gainValue * emitVolume, audioCtx.currentTime + 0.1);
output.gain.gain.linearRampToValueAtTime(gainValue * emitVolume, audioCtx.currentTime + SPATIAL_RAMP_SECONDS);
if (output.panner) {
const resolvedPan = this.audio.getOutputMode() === 'mono' ? 0 : Math.max(-1, Math.min(1, panValue));
output.panner.pan.linearRampToValueAtTime(resolvedPan, audioCtx.currentTime + 0.1);
output.panner.pan.linearRampToValueAtTime(resolvedPan, audioCtx.currentTime + SPATIAL_RAMP_SECONDS);
}
}
}