Rename radio media params and add widget emit effects
This commit is contained in:
@@ -1,11 +1,17 @@
|
||||
import { HEARING_RADIUS, type WorldItem } from '../state/gameState';
|
||||
import { AudioEngine } from './audioEngine';
|
||||
import { connectEffectChain, disconnectEffectRuntime, type EffectId, type EffectRuntime } from './effects';
|
||||
import { normalizeRadioEffect, normalizeRadioEffectValue } from './radioStationRuntime';
|
||||
import { resolveSpatialMix } from './spatial';
|
||||
|
||||
type EmitOutput = {
|
||||
soundUrl: string;
|
||||
element: HTMLAudioElement;
|
||||
source: MediaElementAudioSourceNode;
|
||||
effectInput: GainNode;
|
||||
effectRuntime: EffectRuntime | null;
|
||||
effect: EffectId;
|
||||
effectValue: number;
|
||||
gain: GainNode;
|
||||
panner: StereoPannerNode | null;
|
||||
};
|
||||
@@ -34,6 +40,8 @@ export class ItemEmitRuntime {
|
||||
output.element.pause();
|
||||
output.element.src = '';
|
||||
output.source.disconnect();
|
||||
output.effectInput.disconnect();
|
||||
disconnectEffectRuntime(output.effectRuntime);
|
||||
output.gain.disconnect();
|
||||
output.panner?.disconnect();
|
||||
this.outputs.delete(itemId);
|
||||
@@ -85,17 +93,21 @@ export class ItemEmitRuntime {
|
||||
element.preload = 'none';
|
||||
element.crossOrigin = 'anonymous';
|
||||
const source = audioCtx.createMediaElementSource(element);
|
||||
const effectInput = audioCtx.createGain();
|
||||
const gain = audioCtx.createGain();
|
||||
gain.gain.value = 0;
|
||||
let panner: StereoPannerNode | null = null;
|
||||
source.connect(gain);
|
||||
source.connect(effectInput);
|
||||
const effect = normalizeRadioEffect(item.params.emitEffect);
|
||||
const effectValue = normalizeRadioEffectValue(item.params.emitEffectValue);
|
||||
const effectRuntime = connectEffectChain(audioCtx, effectInput, gain, effect, effectValue);
|
||||
if (this.audio.supportsStereoPanner()) {
|
||||
panner = audioCtx.createStereoPanner();
|
||||
gain.connect(panner).connect(audioCtx.destination);
|
||||
} else {
|
||||
gain.connect(audioCtx.destination);
|
||||
}
|
||||
this.outputs.set(item.id, { soundUrl, element, source, gain, panner });
|
||||
this.outputs.set(item.id, { soundUrl, element, source, effectInput, effectRuntime, effect, effectValue, gain, panner });
|
||||
void element.play().catch(() => undefined);
|
||||
}
|
||||
|
||||
@@ -117,6 +129,15 @@ export class ItemEmitRuntime {
|
||||
output.gain.gain.linearRampToValueAtTime(0, audioCtx.currentTime + 0.05);
|
||||
continue;
|
||||
}
|
||||
const effect = normalizeRadioEffect(item.params.emitEffect);
|
||||
const effectValue = normalizeRadioEffectValue(item.params.emitEffectValue);
|
||||
if (output.effect !== effect || output.effectValue !== effectValue) {
|
||||
output.effectInput.disconnect();
|
||||
disconnectEffectRuntime(output.effectRuntime);
|
||||
output.effectRuntime = connectEffectChain(audioCtx, output.effectInput, output.gain, effect, effectValue);
|
||||
output.effect = effect;
|
||||
output.effectValue = effectValue;
|
||||
}
|
||||
const spatialConfig = this.getSpatialConfig(item);
|
||||
const mix = resolveSpatialMix({
|
||||
dx: item.x - playerPosition.x,
|
||||
|
||||
@@ -205,8 +205,8 @@ export class RadioStationRuntime {
|
||||
const enabled = item.params.enabled !== false;
|
||||
const mediaVolume = Number(item.params.mediaVolume ?? 50);
|
||||
const normalizedVolume = Number.isFinite(mediaVolume) ? Math.max(0, Math.min(100, mediaVolume)) / 100 : 0.5;
|
||||
const effect = normalizeRadioEffect(item.params.effect);
|
||||
const effectValue = normalizeRadioEffectValue(item.params.effectValue);
|
||||
const effect = normalizeRadioEffect(item.params.mediaEffect);
|
||||
const effectValue = normalizeRadioEffectValue(item.params.mediaEffectValue);
|
||||
this.applyEffect(output, audioCtx, effect, effectValue);
|
||||
if (!streamUrl || !enabled) {
|
||||
output.gain.gain.linearRampToValueAtTime(0, audioCtx.currentTime + 0.05);
|
||||
@@ -299,7 +299,7 @@ export class RadioStationRuntime {
|
||||
const audioCtx = this.audio.context;
|
||||
if (!audioCtx) return;
|
||||
|
||||
const channel = normalizeRadioChannel(item.params.channel);
|
||||
const channel = normalizeRadioChannel(item.params.mediaChannel);
|
||||
const existing = this.itemRadioOutputs.get(item.id);
|
||||
if (existing && existing.streamUrl === streamUrl && existing.channel === channel) {
|
||||
return;
|
||||
@@ -315,8 +315,8 @@ export class RadioStationRuntime {
|
||||
gain.gain.value = 0;
|
||||
const effectInput = audioCtx.createGain();
|
||||
const channelSource = connectRadioChannelSource(audioCtx, shared.source, channel, effectInput);
|
||||
const effect = normalizeRadioEffect(item.params.effect);
|
||||
const effectValue = normalizeRadioEffectValue(item.params.effectValue);
|
||||
const effect = normalizeRadioEffect(item.params.mediaEffect);
|
||||
const effectValue = normalizeRadioEffectValue(item.params.mediaEffectValue);
|
||||
const effectRuntime = connectEffectChain(audioCtx, effectInput, gain, effect, effectValue);
|
||||
let panner: StereoPannerNode | null = null;
|
||||
if (this.audio.supportsStereoPanner()) {
|
||||
|
||||
Reference in New Issue
Block a user