Skip to content

Commit

Permalink
修改 WAudio 模块部分写法
Browse files Browse the repository at this point in the history
  • Loading branch information
MisaLiu committed Apr 11, 2023
1 parent 515bf5c commit 16c1668
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 20 deletions.
17 changes: 6 additions & 11 deletions src/audio/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@ import { number as verifyNum } from '@/verify';

const AudioCtx = window.AudioContext || window.webkitAudioContext;
const GlobalAudioCtx = (new Audio().canPlayType('audio/ogg') == '') ? new oggmentedAudioContext() : new AudioCtx();
var GlobalAudioLatency = 0;

GlobalAudioCtx.addEventListener('statechange', () =>
{
if (GlobalAudioCtx.state === 'running')
{
GlobalAudioLatency = (!isNaN(GlobalAudioCtx.baseLatency) ? GlobalAudioCtx.baseLatency : 0) + (!isNaN(GlobalAudioCtx.outputLatency) ? GlobalAudioCtx.outputLatency : 0);

window.removeEventListener('click', ResumeGlobalAudioContext);
window.removeEventListener('touchend', ResumeGlobalAudioContext);
window.removeEventListener('mousemove', ResumeGlobalAudioContext);
Expand All @@ -23,7 +20,7 @@ GlobalAudioCtx.addEventListener('statechange', () =>



class WAudio
export default class WAudio
{
constructor(src, loop = false, volume = 1, speed = 1, onend = undefined)
{
Expand Down Expand Up @@ -162,6 +159,11 @@ class WAudio
if (this._timer) this._timer.speed = this._speed;
if (this._buffer) this._buffer.playbackRate.value = this._speed;
}

static get globalLatency()
{
return (!isNaN(GlobalAudioCtx.baseLatency) ? GlobalAudioCtx.baseLatency : 0) + (!isNaN(GlobalAudioCtx.outputLatency) ? GlobalAudioCtx.outputLatency : 0);
}
}


Expand All @@ -180,10 +182,3 @@ async function ResumeGlobalAudioContext()
{
if (GlobalAudioCtx.state === 'suspended') await GlobalAudioCtx.resume();
}



export {
WAudio,
GlobalAudioLatency as audioLatency
};
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ doms.startBtn.addEventListener('click', async () => {
bgDim: doms.settings.bgDim.value,
noteScale: 10000 - doms.settings.noteScale.value,

audioOffset: doms.settings.offset.value / 1000 + (doms.settings.useBrowserLatency.checked ? PhiChartRender.audioLatency : 0),
audioOffset: doms.settings.offset.value / 1000 + (doms.settings.useBrowserLatency.checked ? PhiChartRender.WAudio.globalLatency : 0),
speed: doms.settings.speed.value,

hitsound: doms.settings.hitsound.checked,
Expand Down
11 changes: 3 additions & 8 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import Game from './game';
import Chart from './chart';
export { default as Game } from './game';
export { default as Chart } from './chart';

export * from './audio';
export { default as WAudio } from './audio';
export { default as Effect } from './effect';
export { default as Shader } from './effect/shader';

export {
Game,
Chart
};

0 comments on commit 16c1668

Please sign in to comment.