Add directional emit model and per-type emit range defaults
This commit is contained in:
@@ -113,12 +113,21 @@ function freshStreamUrl(streamUrl: string): string {
|
||||
return `${streamUrl}${separator}chgrid_start=${Date.now()}`;
|
||||
}
|
||||
|
||||
type RadioSpatialConfig = {
|
||||
range: number;
|
||||
directional: boolean;
|
||||
facingDeg: number;
|
||||
};
|
||||
|
||||
export class RadioStationRuntime {
|
||||
private readonly sharedRadioSources = new Map<string, SharedRadioSource>();
|
||||
private readonly itemRadioOutputs = new Map<string, ItemRadioOutput>();
|
||||
private layerEnabled = true;
|
||||
|
||||
constructor(private readonly audio: AudioEngine) {}
|
||||
constructor(
|
||||
private readonly audio: AudioEngine,
|
||||
private readonly getSpatialConfig: (item: WorldItem) => RadioSpatialConfig,
|
||||
) {}
|
||||
|
||||
cleanup(itemId: string): void {
|
||||
const output = this.itemRadioOutputs.get(itemId);
|
||||
@@ -203,14 +212,21 @@ export class RadioStationRuntime {
|
||||
output.gain.gain.linearRampToValueAtTime(0, audioCtx.currentTime + 0.05);
|
||||
continue;
|
||||
}
|
||||
const spatialConfig = this.getSpatialConfig(item);
|
||||
const mix = resolveSpatialMix({
|
||||
dx: item.x - playerPosition.x,
|
||||
dy: item.y - playerPosition.y,
|
||||
range: HEARING_RADIUS,
|
||||
range: Math.max(1, spatialConfig.range || HEARING_RADIUS),
|
||||
baseGain: normalizedVolume,
|
||||
nearFieldDistance: 1,
|
||||
nearFieldGain: 1,
|
||||
nearFieldCenterPan: true,
|
||||
directional: {
|
||||
enabled: spatialConfig.directional,
|
||||
facingDeg: spatialConfig.facingDeg,
|
||||
coneDeg: 120,
|
||||
rearGain: 0.5,
|
||||
},
|
||||
});
|
||||
const gainValue = mix?.gain ?? 0;
|
||||
const panValue = mix?.pan ?? 0;
|
||||
|
||||
Reference in New Issue
Block a user