mirror of
https://github.com/unanmed/HumanBreak.git
synced 2025-01-31 23:29:27 +08:00
设置立体声
This commit is contained in:
parent
abdcecc75e
commit
c70c5b1594
@ -2,6 +2,10 @@ import { has } from '../../plugin/utils';
|
|||||||
import { AudioPlayer } from './audio';
|
import { AudioPlayer } from './audio';
|
||||||
import resource from '../../data/resource.json';
|
import resource from '../../data/resource.json';
|
||||||
|
|
||||||
|
type Panner = {
|
||||||
|
[P in SelectKey<PannerNode, AudioParam>]: number;
|
||||||
|
};
|
||||||
|
|
||||||
export class SoundEffect extends AudioPlayer {
|
export class SoundEffect extends AudioPlayer {
|
||||||
static playIndex = 0;
|
static playIndex = 0;
|
||||||
|
|
||||||
@ -15,6 +19,13 @@ export class SoundEffect extends AudioPlayer {
|
|||||||
panner: PannerNode | null = null;
|
panner: PannerNode | null = null;
|
||||||
merger: ChannelMergerNode | 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) {
|
constructor(data: ArrayBuffer, stereo: boolean = false) {
|
||||||
super(data);
|
super(data);
|
||||||
|
|
||||||
@ -95,6 +106,17 @@ export class SoundEffect extends AudioPlayer {
|
|||||||
this.playing[index]?.stop();
|
this.playing[index]?.stop();
|
||||||
delete this.playing[index];
|
delete this.playing[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置立体声信息
|
||||||
|
* @param panner 立体声信息
|
||||||
|
*/
|
||||||
|
setPanner(panner: Partial<Panner>) {
|
||||||
|
if (!this.panner) return;
|
||||||
|
for (const [key, value] of Object.entries(panner)) {
|
||||||
|
this.panner[key as keyof Panner].value = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class SoundController {
|
class SoundController {
|
||||||
@ -111,7 +133,7 @@ class SoundController {
|
|||||||
const stereo = resource.stereoSE.includes(uri);
|
const stereo = resource.stereoSE.includes(uri);
|
||||||
const se = new SoundEffect(data, stereo);
|
const se = new SoundEffect(data, stereo);
|
||||||
if (this.list[uri]) {
|
if (this.list[uri]) {
|
||||||
console.warn(`Repeated sound effect: ${uri}.`);
|
console.warn(`Repeated sound effect: '${uri}'.`);
|
||||||
}
|
}
|
||||||
return (this.list[uri] = se);
|
return (this.list[uri] = se);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user