@ debuffjp/ 音频
一个小型的Web音频外观:音乐和SFX巴士,第一个手势上的自動播放解锁,有投出变异的缓冲回放,以及快速占位符blips的无资产合成. 无依取相.
import { Audio } from "@debuffjp/audio";
const audio = new Audio();
await audio.decode("coin", assets.audio("coin"));
audio.play("coin", { volume: 0.8, rateJitter: 0.05 });
audio.volume("music", 0.5);
音乐和音效
用于代码制作的音乐和声音效果,使用 浮点 (单位:千美元)plonkjs:歌曲和效果是小数据,合成活生生,效果在歌曲的键中播放. 给它这个包的上下文和音乐总线 这样它就能分享游戏的音量和哑声:
import { Player } from "plonkjs";
const player = new Player({ context: audio.ctx, destination: audio.bus("music") });
player.play(theme); // a plonk Song
player.sfx({ wave: "square", decay: 0.1, sustain: 0 }, { degree: 5 }); // a pickup in the song's key
使用 play 对于声音文件 游戏船. synth 是一个单一的振荡器,有投出滑道:在游戏尚未发出声音时作为占位符是好的,但它无法制造出令人信服的硬币,爆炸或放电. 在0.29.3之前,该研究建议 synth 对SFX来说也是.
audio.synth({ freq: 660, freqEnd: 220, decay: 0.15 }); // placeholder, no file needed
API 密码
decode(id, arrayBuffer), (中文(简体) ),has(id)play(id, { bus, volume, rate, rateJitter, pan, loop })→Voicesynth({ wave, freq, freqEnd, attack, decay, volume, bus })→Voice(单位:千美元)wave: 任意OscillatorType或者说"noise"(中文(简体) )voice.stop(fadeSeconds?)stream(url, { bus, volume, loop })→Stream: 播放的长音轨<audio>元素,带有pause(), (中文(简体) ),resume(), (中文(简体) ),volume(value, fadeSeconds?)财务报告和审定财务报表stop(fadeSeconds?)。跟踪浏览器块开始于下一个手势.stop()最终;在0.31.1之前,resume()之后stop(fade)重新启动即将卸载的轨道 .bus("sfx" | "music")→GainNode,用于插入其他音频,如 plonkvolume("sfx" | "music" | "master", value), (中文(简体) ),unlocked, (中文(简体) ),ctx(基础AudioContext(中文(简体) )