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