Use target smoothing for continuous spatial audio
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
// Maintainer-controlled web client version.
|
// Maintainer-controlled web client version.
|
||||||
// Format: YYYY.MM.DD Rn (example: 2026.02.20 R2)
|
// Format: YYYY.MM.DD Rn (example: 2026.02.20 R2)
|
||||||
window.CHGRID_WEB_VERSION = "2026.02.22 R191";
|
window.CHGRID_WEB_VERSION = "2026.02.22 R192";
|
||||||
// Optional display timezone for timestamps. Falls back to America/Detroit if unset/invalid.
|
// Optional display timezone for timestamps. Falls back to America/Detroit if unset/invalid.
|
||||||
window.CHGRID_TIME_ZONE = "America/Detroit";
|
window.CHGRID_TIME_ZONE = "America/Detroit";
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ type SoundSpec = {
|
|||||||
|
|
||||||
type OutputMode = 'stereo' | 'mono';
|
type OutputMode = 'stereo' | 'mono';
|
||||||
const SPATIAL_RAMP_SECONDS = 0.2;
|
const SPATIAL_RAMP_SECONDS = 0.2;
|
||||||
|
const SPATIAL_TIME_CONSTANT_SECONDS = SPATIAL_RAMP_SECONDS / 3;
|
||||||
|
|
||||||
export class AudioEngine {
|
export class AudioEngine {
|
||||||
private audioCtx: AudioContext | null = null;
|
private audioCtx: AudioContext | null = null;
|
||||||
@@ -301,7 +302,7 @@ export class AudioEngine {
|
|||||||
const gainValue = mix?.gain ?? 0;
|
const gainValue = mix?.gain ?? 0;
|
||||||
const listenGain = Number.isFinite(peer.listenGain) ? Math.max(0, peer.listenGain as number) : 1;
|
const listenGain = Number.isFinite(peer.listenGain) ? Math.max(0, peer.listenGain as number) : 1;
|
||||||
const panValue = mix?.pan ?? 0;
|
const panValue = mix?.pan ?? 0;
|
||||||
peer.gain.gain.linearRampToValueAtTime(gainValue * listenGain, this.audioCtx.currentTime + SPATIAL_RAMP_SECONDS);
|
peer.gain.gain.setTargetAtTime(gainValue * listenGain, this.audioCtx.currentTime, SPATIAL_TIME_CONSTANT_SECONDS);
|
||||||
if (peer.panner) {
|
if (peer.panner) {
|
||||||
const resolvedPan = this.outputMode === 'mono' ? 0 : Math.max(-1, Math.min(1, panValue));
|
const resolvedPan = this.outputMode === 'mono' ? 0 : Math.max(-1, Math.min(1, panValue));
|
||||||
peer.panner.pan.setValueAtTime(resolvedPan, this.audioCtx.currentTime);
|
peer.panner.pan.setValueAtTime(resolvedPan, this.audioCtx.currentTime);
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ const ITEM_EMIT_BASE_GAIN = 1;
|
|||||||
const SUBSCRIBE_PRELOAD_SQUARES = 5;
|
const SUBSCRIBE_PRELOAD_SQUARES = 5;
|
||||||
const UNSUBSCRIBE_HYSTERESIS_SQUARES = 8;
|
const UNSUBSCRIBE_HYSTERESIS_SQUARES = 8;
|
||||||
const SPATIAL_RAMP_SECONDS = 0.2;
|
const SPATIAL_RAMP_SECONDS = 0.2;
|
||||||
|
const SPATIAL_TIME_CONSTANT_SECONDS = SPATIAL_RAMP_SECONDS / 3;
|
||||||
|
|
||||||
/** Maps a 0-100 speed control to playback-rate range used by emitted audio. */
|
/** Maps a 0-100 speed control to playback-rate range used by emitted audio. */
|
||||||
function resolveEmitPlaybackRate(raw: unknown): number {
|
function resolveEmitPlaybackRate(raw: unknown): number {
|
||||||
@@ -224,10 +225,10 @@ export class ItemEmitRuntime {
|
|||||||
const gainValue = mix?.gain ?? 0;
|
const gainValue = mix?.gain ?? 0;
|
||||||
const panValue = mix?.pan ?? 0;
|
const panValue = mix?.pan ?? 0;
|
||||||
const emitVolume = volumePercentToGain(item.params.emitVolume, 100);
|
const emitVolume = volumePercentToGain(item.params.emitVolume, 100);
|
||||||
output.gain.gain.linearRampToValueAtTime(gainValue * emitVolume, audioCtx.currentTime + SPATIAL_RAMP_SECONDS);
|
output.gain.gain.setTargetAtTime(gainValue * emitVolume, audioCtx.currentTime, SPATIAL_TIME_CONSTANT_SECONDS);
|
||||||
if (output.panner) {
|
if (output.panner) {
|
||||||
const resolvedPan = this.audio.getOutputMode() === 'mono' ? 0 : Math.max(-1, Math.min(1, panValue));
|
const resolvedPan = this.audio.getOutputMode() === 'mono' ? 0 : Math.max(-1, Math.min(1, panValue));
|
||||||
output.panner.pan.linearRampToValueAtTime(resolvedPan, audioCtx.currentTime + SPATIAL_RAMP_SECONDS);
|
output.panner.pan.setTargetAtTime(resolvedPan, audioCtx.currentTime, SPATIAL_TIME_CONSTANT_SECONDS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -166,6 +166,7 @@ type RadioSpatialConfig = {
|
|||||||
const SUBSCRIBE_PRELOAD_SQUARES = 5;
|
const SUBSCRIBE_PRELOAD_SQUARES = 5;
|
||||||
const UNSUBSCRIBE_HYSTERESIS_SQUARES = 8;
|
const UNSUBSCRIBE_HYSTERESIS_SQUARES = 8;
|
||||||
const SPATIAL_RAMP_SECONDS = 0.2;
|
const SPATIAL_RAMP_SECONDS = 0.2;
|
||||||
|
const SPATIAL_TIME_CONSTANT_SECONDS = SPATIAL_RAMP_SECONDS / 3;
|
||||||
|
|
||||||
export class RadioStationRuntime {
|
export class RadioStationRuntime {
|
||||||
private readonly sharedRadioSources = new Map<string, SharedRadioSource>();
|
private readonly sharedRadioSources = new Map<string, SharedRadioSource>();
|
||||||
@@ -296,10 +297,10 @@ export class RadioStationRuntime {
|
|||||||
});
|
});
|
||||||
const gainValue = mix?.gain ?? 0;
|
const gainValue = mix?.gain ?? 0;
|
||||||
const panValue = mix?.pan ?? 0;
|
const panValue = mix?.pan ?? 0;
|
||||||
output.gain.gain.linearRampToValueAtTime(gainValue, audioCtx.currentTime + SPATIAL_RAMP_SECONDS);
|
output.gain.gain.setTargetAtTime(gainValue, audioCtx.currentTime, SPATIAL_TIME_CONSTANT_SECONDS);
|
||||||
if (output.panner) {
|
if (output.panner) {
|
||||||
const resolvedPan = this.audio.getOutputMode() === 'mono' ? 0 : Math.max(-1, Math.min(1, panValue));
|
const resolvedPan = this.audio.getOutputMode() === 'mono' ? 0 : Math.max(-1, Math.min(1, panValue));
|
||||||
output.panner.pan.linearRampToValueAtTime(resolvedPan, audioCtx.currentTime + SPATIAL_RAMP_SECONDS);
|
output.panner.pan.setTargetAtTime(resolvedPan, audioCtx.currentTime, SPATIAL_TIME_CONSTANT_SECONDS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user