mirror of
https://github.com/unanmed/HumanBreak.git
synced 2025-01-19 12:49:25 +08:00
立体声
This commit is contained in:
parent
bdaf37cb0c
commit
6a251f7e71
@ -1,54 +0,0 @@
|
||||
///<reference path="../../src/types/core.d.ts" />
|
||||
|
||||
/*
|
||||
extensions.js:负责拓展插件
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
function extensions() {}
|
||||
|
||||
extensions.prototype._load = function (callback) {
|
||||
if (main.replayChecking) return callback();
|
||||
if (!window.fs) {
|
||||
this._loadJs(
|
||||
'_server/fs.js',
|
||||
function () {
|
||||
core.extensions._listExtensions(callback);
|
||||
},
|
||||
callback
|
||||
);
|
||||
} else this._listExtensions(callback);
|
||||
};
|
||||
|
||||
extensions.prototype._loadJs = function (file, callback, onerror) {
|
||||
var script = document.createElement('script');
|
||||
script.src = file + '?v=' + main.version;
|
||||
script.onload = callback;
|
||||
script.onerror = onerror;
|
||||
main.dom.body.appendChild(script);
|
||||
};
|
||||
|
||||
extensions.prototype._listExtensions = function (callback) {
|
||||
if (!window.fs) return callback();
|
||||
fs.readdir('extensions', function (error, data) {
|
||||
if (error || !(data instanceof Array)) return callback();
|
||||
var list = [];
|
||||
data.forEach(function (name) {
|
||||
if (/^[\w.-]+\.js$/.test(name)) {
|
||||
list.push(name);
|
||||
}
|
||||
});
|
||||
list.sort();
|
||||
core.extensions._loadExtensions(list, callback);
|
||||
});
|
||||
};
|
||||
|
||||
extensions.prototype._loadExtensions = function (list, callback) {
|
||||
var i = 0;
|
||||
var load = function () {
|
||||
if (i == list.length) return callback();
|
||||
core.extensions._loadJs('extensions/' + list[i++], load, load);
|
||||
};
|
||||
load();
|
||||
};
|
@ -92,7 +92,6 @@ function main() {
|
||||
'actions',
|
||||
'data',
|
||||
'ui',
|
||||
'extensions',
|
||||
'core'
|
||||
];
|
||||
this.pureData = [
|
||||
|
@ -1,30 +1,62 @@
|
||||
import { has } from '../../plugin/utils';
|
||||
import { AudioPlayer } from './audio';
|
||||
import resource from '../../data/resource.json';
|
||||
|
||||
export class SoundEffect extends AudioPlayer {
|
||||
static playIndex = 0;
|
||||
|
||||
private playing: Record<string, AudioBufferSourceNode> = {};
|
||||
private _stopingAll: boolean = false;
|
||||
private playMap: Map<AudioBufferSourceNode, number> = new Map();
|
||||
|
||||
stereo: boolean = false;
|
||||
|
||||
gain: GainNode = AudioPlayer.ac.createGain();
|
||||
panner: PannerNode | null = null;
|
||||
merger: ChannelMergerNode | null = null;
|
||||
|
||||
constructor(data: ArrayBuffer, stereo: boolean = false) {
|
||||
super(data);
|
||||
|
||||
this.on('end', node => {
|
||||
if (this._stopingAll) return;
|
||||
const entry = Object.entries(this.playing);
|
||||
const index = entry.find(v => node === v[1])?.[0];
|
||||
const index = this.playMap.get(node);
|
||||
if (!index) return;
|
||||
delete this.playing[index];
|
||||
});
|
||||
this.initAudio(stereo);
|
||||
this.on('update', () => {
|
||||
this.initAudio(this.stereo);
|
||||
});
|
||||
|
||||
this.stereo = stereo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置音频路由线路
|
||||
* @param stereo 是否启用立体声
|
||||
*/
|
||||
protected initAudio(stereo: boolean = false) {}
|
||||
protected initAudio(stereo: boolean = false) {
|
||||
const channel = this.buffer?.numberOfChannels;
|
||||
const ac = AudioPlayer.ac;
|
||||
if (!channel) return;
|
||||
if (stereo) {
|
||||
this.panner = ac.createPanner();
|
||||
this.panner.connect(this.gain);
|
||||
if (channel === 1) {
|
||||
this.merger = ac.createChannelMerger();
|
||||
this.merger.connect(this.panner);
|
||||
this.baseNode = [
|
||||
{ node: this.merger, channel: 0 },
|
||||
{ node: this.merger, channel: 1 }
|
||||
];
|
||||
} else {
|
||||
this.baseNode = [{ node: this.panner }];
|
||||
}
|
||||
} else {
|
||||
this.baseNode = [{ node: this.gain }];
|
||||
}
|
||||
this.gain.connect(this.getDestination());
|
||||
}
|
||||
|
||||
/**
|
||||
* 播放音频
|
||||
@ -35,6 +67,7 @@ export class SoundEffect extends AudioPlayer {
|
||||
if (!node) return;
|
||||
const index = SoundEffect.playIndex++;
|
||||
this.playing[index] = node;
|
||||
this.playMap.set(node, index);
|
||||
return index;
|
||||
}
|
||||
|
||||
@ -71,7 +104,8 @@ class SoundController {
|
||||
* @param data 音频的ArrayBuffer信息,会被解析为AudioBuffer
|
||||
*/
|
||||
add(uri: string, data: ArrayBuffer) {
|
||||
const se = new SoundEffect(data);
|
||||
const stereo = resource.stereoSE.includes(uri);
|
||||
const se = new SoundEffect(data, stereo);
|
||||
if (this.list[uri]) {
|
||||
console.warn(`Repeated sound effect: ${uri}.`);
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import { Resource, getTypeByResource } from './resource';
|
||||
const info = resource;
|
||||
|
||||
export function readyAllResource() {
|
||||
info.forEach(v => {
|
||||
info.resource.forEach(v => {
|
||||
const type = getTypeByResource(v);
|
||||
if (type === 'zip') {
|
||||
ancTe.zipResource.set(v, new Resource(v, 'zip'));
|
||||
|
@ -1,3 +1,8 @@
|
||||
[
|
||||
{
|
||||
"resource": [
|
||||
""
|
||||
],
|
||||
"stereoSE": [
|
||||
""
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user