Removed AudioBuffer wrapper.

This commit is contained in:
flash 2024-02-10 02:52:02 +00:00
parent fc58537974
commit a50a0d67ae
7 changed files with 26 additions and 31 deletions

View file

@ -1,5 +0,0 @@
const MamiAudioBuffer = function(ctx, buffer) {
return {
createSource: () => ctx.createSource(buffer),
};
};

View file

@ -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();

View file

@ -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);

View file

@ -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();
};

View file

@ -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));
},

View file

@ -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;

View file

@ -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();