From c70c5b15946c38e6e1facfae8bb4177d3e90bff7 Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Fri, 16 Jun 2023 11:28:41 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E7=AB=8B=E4=BD=93=E5=A3=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/audio/sound.ts | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/core/audio/sound.ts b/src/core/audio/sound.ts index b7bb1c4..764f434 100644 --- a/src/core/audio/sound.ts +++ b/src/core/audio/sound.ts @@ -2,6 +2,10 @@ import { has } from '../../plugin/utils'; import { AudioPlayer } from './audio'; import resource from '../../data/resource.json'; +type Panner = { + [P in SelectKey]: number; +}; + export class SoundEffect extends AudioPlayer { static playIndex = 0; @@ -15,6 +19,13 @@ export class SoundEffect extends AudioPlayer { panner: PannerNode | null = null; merger: ChannelMergerNode | null = null; + set volumn(value: number) { + this.gain.gain.value = value; + } + get volumn(): number { + return this.gain.gain.value; + } + constructor(data: ArrayBuffer, stereo: boolean = false) { super(data); @@ -95,6 +106,17 @@ export class SoundEffect extends AudioPlayer { this.playing[index]?.stop(); delete this.playing[index]; } + + /** + * 设置立体声信息 + * @param panner 立体声信息 + */ + setPanner(panner: Partial) { + if (!this.panner) return; + for (const [key, value] of Object.entries(panner)) { + this.panner[key as keyof Panner].value = value; + } + } } class SoundController { @@ -111,7 +133,7 @@ class SoundController { const stereo = resource.stereoSE.includes(uri); const se = new SoundEffect(data, stereo); if (this.list[uri]) { - console.warn(`Repeated sound effect: ${uri}.`); + console.warn(`Repeated sound effect: '${uri}'.`); } return (this.list[uri] = se); }