Removed AudioBuffer wrapper.
This commit is contained in:
parent
fc58537974
commit
a50a0d67ae
7 changed files with 26 additions and 31 deletions
|
@ -1,5 +0,0 @@
|
|||
const MamiAudioBuffer = function(ctx, buffer) {
|
||||
return {
|
||||
createSource: () => ctx.createSource(buffer),
|
||||
};
|
||||
};
|
|
@ -1,5 +1,4 @@
|
|||
#include utility.js
|
||||
#include audio/buffer.js
|
||||
#include audio/source.js
|
||||
|
||||
const MamiAudioContext = function() {
|
||||
|
@ -63,15 +62,14 @@ const MamiAudioContext = function() {
|
|||
|
||||
pub.createBuffer = async url => {
|
||||
if(ctx === undefined)
|
||||
return new MamiAudioBuffer(pub);
|
||||
return undefined;
|
||||
|
||||
const result = await $x.get(url, { type: 'arraybuffer' });
|
||||
const buffer = await ctx.decodeAudioData(result.body());
|
||||
return new MamiAudioBuffer(pub, buffer);
|
||||
return await ctx.decodeAudioData(result.body());
|
||||
};
|
||||
|
||||
pub.createSource = buffer => {
|
||||
if(ctx === undefined)
|
||||
if(ctx === undefined || buffer === undefined)
|
||||
return new MamiAudioSourceDummy;
|
||||
|
||||
const gain = ctx.createGain();
|
||||
|
|
|
@ -31,8 +31,7 @@ const MamiContext = function(targetBody) {
|
|||
pub.getSoundPackPlayer = () => sndPckPlay;
|
||||
|
||||
pub.playLibrarySound = async (name, volume, rate) => {
|
||||
const buffer = await soundMgr.load(soundLib.getSoundSources(name));
|
||||
const source = buffer.createSource();
|
||||
const source = await soundMgr.loadSource(soundLib.getSoundSources(name));
|
||||
|
||||
if(typeof volume === 'number')
|
||||
source.setVolume(volume);
|
||||
|
|
|
@ -106,13 +106,14 @@ Umi.Protocol.SockChat.Protocol = function(views, settings) {
|
|||
};
|
||||
const playBannedBgm = async preload => {
|
||||
const soundMgr = mami.getSound();
|
||||
const soundLib = mami.getSoundLibrary();
|
||||
const sources = mami.getSoundLibrary().getSoundSources('touhou:th10score');
|
||||
|
||||
const buffer = await soundMgr.load(soundLib.getSoundSources('touhou:th10score'));
|
||||
if(preload)
|
||||
if(preload) {
|
||||
await soundMgr.loadBuffer(sources);
|
||||
return;
|
||||
}
|
||||
|
||||
const source = buffer.createSource();
|
||||
const source = await soundMgr.loadSource(sources);
|
||||
source.setLoop(true, 10.512, 38.074);
|
||||
await source.play();
|
||||
};
|
||||
|
|
|
@ -45,8 +45,7 @@ const MamiSoundManager = function(context) {
|
|||
const loaded = new Map;
|
||||
context.onReset(() => loaded.clear());
|
||||
|
||||
return {
|
||||
load: async urls => {
|
||||
const loadBuffer = async urls => {
|
||||
const url = extractUrl(urls);
|
||||
|
||||
if(loaded.has(url))
|
||||
|
@ -56,7 +55,11 @@ const MamiSoundManager = function(context) {
|
|||
loaded.set(url, buffer);
|
||||
|
||||
return buffer;
|
||||
},
|
||||
};
|
||||
|
||||
return {
|
||||
loadBuffer: loadBuffer,
|
||||
loadSource: async urls => context.createSource(await loadBuffer(urls)),
|
||||
unload: urls => {
|
||||
loaded.delete(extractUrl(urls));
|
||||
},
|
||||
|
|
|
@ -80,9 +80,9 @@ const MamiSoundPackPlayer = function(soundMgr, sndLibrary) {
|
|||
return;
|
||||
|
||||
const info = sndLibrary.getSound(pack.getEventSound(eventName));
|
||||
const buffer = await soundMgr.load(info.getSources());
|
||||
const source = await soundMgr.loadSource(info.getSources());
|
||||
|
||||
await buffer.createSource().play();
|
||||
await source.play();
|
||||
};
|
||||
|
||||
return pub;
|
||||
|
|
|
@ -26,9 +26,8 @@ const MamiYouAreAnIdiot = function() {
|
|||
|
||||
try {
|
||||
const sources = mami.getSoundLibrary().getSoundSources('misc:youare');
|
||||
const buffer = await soundMgr.load(sources);
|
||||
|
||||
soundSrc = buffer.createSource();
|
||||
soundSrc = soundMgr.loadSource(sources);
|
||||
soundSrc.setMuted(true);
|
||||
soundSrc.setLoop(true, 0.21, 5);
|
||||
soundSrc.play();
|
||||
|
|
Loading…
Reference in a new issue