game-audio by opusgamelabs/game-creator
npx skills add https://github.com/opusgamelabs/game-creator --skill game-audio你是一名专业的游戏音频工程师。你使用 Web Audio API 来处理背景音乐(循环音序器)和一次性音效。零依赖——所有功能都内置于浏览器中。
详细参考请查看此目录中的配套文件:
sequencer-pattern.md — BGM 音序器函数 parsePattern()、示例模式、防重复技术sfx-engine.md — playTone()、playNotes()、playNoise(),所有 SFX 预设mute-button.md — 静音状态管理、、UIScene 按钮、localStorage 持久化广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
drawMuteIcon()bgm-patterns.md — Strudel BGM 模式示例strudel-reference.md — Strudel.cc API 参考mixing-guide.md — 各流派的音量级别表和风格指南| 用途 | 引擎 | 包 |
|---|---|---|
| 背景音乐 | Web Audio API 音序器 | 内置于浏览器 |
| 音效 | Web Audio API 一次性播放 | 内置于浏览器 |
| 合成器 | OscillatorNode(方波、三角波、锯齿波、正弦波) | — |
| 效果器 | GainNode、BiquadFilterNode、ConvolverNode、DelayNode | — |
无需外部音频文件或 npm 包——所有声音都是程序化生成的。
src/
├── audio/
│ ├── AudioManager.js # AudioContext 初始化,BGM 音序器,播放/停止
│ ├── AudioBridge.js # 连接 EventBus → 音频播放
│ ├── music.js # BGM 模式(音序器音符数组)
│ └── sfx.js # SFX(一次性振荡器 + 增益 + 滤波器)
AudioManager 拥有 AudioContext(为遵守自动播放策略,在首次用户交互时创建)并运行一个简单的步进音序器来播放 BGM 循环。
// AudioManager.js — Web Audio API BGM 音序器 + SFX 上下文
class AudioManager {
constructor() {
this.ctx = null;
this.currentBgm = null; // { stop() }
this.masterGain = null;
}
init() {
if (this.ctx) return;
this.ctx = new (window.AudioContext || window.webkitAudioContext)();
this.masterGain = this.ctx.createGain();
this.masterGain.connect(this.ctx.destination);
}
getCtx() {
if (!this.ctx) this.init();
return this.ctx;
}
getMaster() {
if (!this.masterGain) this.init();
return this.masterGain;
}
playMusic(patternFn) {
this.stopMusic();
try {
this.currentBgm = patternFn(this.getCtx(), this.getMaster());
} catch (e) {
console.warn('[Audio] BGM error:', e);
}
}
stopMusic() {
if (this.currentBgm) {
try { this.currentBgm.stop(); } catch (_) {}
this.currentBgm = null;
}
}
setMuted(muted) {
if (this.masterGain) {
this.masterGain.gain.value = muted ? 0 : 1;
}
}
}
export const audioManager = new AudioManager();
完整的音序器函数 parsePattern()、BGM 模式示例和防重复技术,请参见 sequencer-pattern.md。
playTone()、playNotes()、playNoise() 以及所有常见游戏 SFX 预设(得分、跳跃、死亡、点击、强化、击中、呼啸、选择),请参见 sfx-engine.md。
import { eventBus, Events } from '../core/EventBus.js';
import { audioManager } from './AudioManager.js';
import { gameplayBGM, gameOverTheme } from './music.js';
import { scoreSfx, deathSfx, clickSfx } from './sfx.js';
export function initAudioBridge() {
// 在首次用户交互时初始化 AudioContext(浏览器自动播放策略)
eventBus.on(Events.AUDIO_INIT, () => audioManager.init());
// BGM 切换
eventBus.on(Events.MUSIC_GAMEPLAY, () => audioManager.playMusic(gameplayBGM));
eventBus.on(Events.MUSIC_GAMEOVER, () => audioManager.playMusic(gameOverTheme));
eventBus.on(Events.MUSIC_STOP, () => audioManager.stopMusic());
// SFX(一次性播放)
eventBus.on(Events.SCORE_CHANGED, () => scoreSfx());
eventBus.on(Events.PLAYER_DIED, () => deathSfx());
}
静音切换事件处理、drawMuteIcon() Phaser Graphics 实现、UIScene 按钮创建以及 localStorage 持久化,请参见 mute-button.md。
src/audio/AudioManager.js — AudioContext + 音序器 + 主增益src/audio/music.js — BGM 模式(音符数组 + 音序器调用)src/audio/sfx.js — 使用 Web Audio API 的 SFX(振荡器 + 增益 + 滤波器)src/audio/AudioBridge.js — 将 EventBus 事件连接到音频main.js 中连接 initAudioBridge()AUDIO_INIT 事件(浏览器自动播放策略)MUSIC_GAMEPLAY、MUSIC_GAMEOVER、MUSIC_STOP 事件AUDIO_TOGGLE_MUTE 事件、UI 按钮、M 键快捷键AUDIO_INIT 事件处理此问题。gain.value = 0 可立即静音所有音频。为了获得更丰富、支持模式语言的程序化 BGM,你可以选择安装 @strudel/web:
npm install @strudel/web
注意:Strudel 使用 AGPL-3.0 许可证——使用它的项目必须是开源的。Strudel 特定的模式请参见此目录中的 strudel-reference.md 和 bgm-patterns.md。
Strudel 升级仅替换 BGM 的 Web Audio 音序器。SFX 始终直接使用 Web Audio API。
每周安装量
105
代码仓库
GitHub 星标
26
首次出现
2026年2月21日
安全审计
安装于
claude-code84
opencode57
cursor55
github-copilot55
amp55
codex55
You are an expert game audio engineer. You use the Web Audio API for both background music (looping sequencer) and one-shot sound effects. Zero dependencies — everything is built into the browser.
For detailed reference, see companion files in this directory:
sequencer-pattern.md — BGM sequencer function, parsePattern(), example patterns, anti-repetition techniquessfx-engine.md — playTone(), playNotes(), playNoise(), all SFX presetsmute-button.md — Mute state management, drawMuteIcon(), UIScene button, localStorage persistencebgm-patterns.md — Strudel BGM pattern examplesstrudel-reference.md — Strudel.cc API referencemixing-guide.md — Volume levels table and style guidelines per genre| Purpose | Engine | Package |
|---|---|---|
| Background music | Web Audio API sequencer | Built into browsers |
| Sound effects | Web Audio API one-shot | Built into browsers |
| Synths | OscillatorNode (square, triangle, sawtooth, sine) | — |
| Effects | GainNode, BiquadFilterNode, ConvolverNode, DelayNode | — |
No external audio files or npm packages needed — all sounds are procedural.
src/
├── audio/
│ ├── AudioManager.js # AudioContext init, BGM sequencer, play/stop
│ ├── AudioBridge.js # Wires EventBus → audio playback
│ ├── music.js # BGM patterns (sequencer note arrays)
│ └── sfx.js # SFX (one-shot oscillator + gain + filter)
The AudioManager owns the AudioContext (created on first user interaction for autoplay policy) and runs a simple step sequencer for BGM loops.
// AudioManager.js — Web Audio API BGM sequencer + SFX context
class AudioManager {
constructor() {
this.ctx = null;
this.currentBgm = null; // { stop() }
this.masterGain = null;
}
init() {
if (this.ctx) return;
this.ctx = new (window.AudioContext || window.webkitAudioContext)();
this.masterGain = this.ctx.createGain();
this.masterGain.connect(this.ctx.destination);
}
getCtx() {
if (!this.ctx) this.init();
return this.ctx;
}
getMaster() {
if (!this.masterGain) this.init();
return this.masterGain;
}
playMusic(patternFn) {
this.stopMusic();
try {
this.currentBgm = patternFn(this.getCtx(), this.getMaster());
} catch (e) {
console.warn('[Audio] BGM error:', e);
}
}
stopMusic() {
if (this.currentBgm) {
try { this.currentBgm.stop(); } catch (_) {}
this.currentBgm = null;
}
}
setMuted(muted) {
if (this.masterGain) {
this.masterGain.gain.value = muted ? 0 : 1;
}
}
}
export const audioManager = new AudioManager();
See sequencer-pattern.md for the full sequencer function, parsePattern(), example BGM patterns, and anti-repetition techniques.
See sfx-engine.md for playTone(), playNotes(), playNoise(), and all common game SFX presets (score, jump, death, click, powerUp, hit, whoosh, select).
import { eventBus, Events } from '../core/EventBus.js';
import { audioManager } from './AudioManager.js';
import { gameplayBGM, gameOverTheme } from './music.js';
import { scoreSfx, deathSfx, clickSfx } from './sfx.js';
export function initAudioBridge() {
// Init AudioContext on first user interaction (browser autoplay policy)
eventBus.on(Events.AUDIO_INIT, () => audioManager.init());
// BGM transitions
eventBus.on(Events.MUSIC_GAMEPLAY, () => audioManager.playMusic(gameplayBGM));
eventBus.on(Events.MUSIC_GAMEOVER, () => audioManager.playMusic(gameOverTheme));
eventBus.on(Events.MUSIC_STOP, () => audioManager.stopMusic());
// SFX (one-shot)
eventBus.on(Events.SCORE_CHANGED, () => scoreSfx());
eventBus.on(Events.PLAYER_DIED, () => deathSfx());
}
See mute-button.md for mute toggle event handling, drawMuteIcon() Phaser Graphics implementation, UIScene button creation, and localStorage persistence.
src/audio/AudioManager.js — AudioContext + sequencer + master gainsrc/audio/music.js — BGM patterns as note arrays + sequencer callssrc/audio/sfx.js — SFX using Web Audio API (oscillator + gain + filter)src/audio/AudioBridge.js — wire EventBus events to audioinitAudioBridge() in main.jsAUDIO_INIT on first user click (browser autoplay policy)MUSIC_GAMEPLAY, MUSIC_GAMEOVER, MUSIC_STOP at scene transitionsAUDIO_INIT event handles this.gain.value = 0 mutes all audio instantly.For richer procedural BGM with pattern language support, you can optionally install @strudel/web:
npm install @strudel/web
Note : Strudel is AGPL-3.0 — projects using it must be open source. See strudel-reference.md and bgm-patterns.md in this directory for Strudel-specific patterns.
The Strudel upgrade replaces the Web Audio sequencer for BGM only. SFX always use Web Audio API directly.
Weekly Installs
105
Repository
GitHub Stars
26
First Seen
Feb 21, 2026
Security Audits
Gen Agent Trust HubWarnSocketPassSnykPass
Installed on
claude-code84
opencode57
cursor55
github-copilot55
amp55
codex55
AI播客创作工具 - 使用inference.sh CLI快速生成AI驱动播客和音频内容
7,700 周安装
AUDIO_TOGGLE_MUTE event, UI button, M key shortcut